diff --git a/Data.qrc b/Data.qrc deleted file mode 100644 index 0325361..0000000 --- a/Data.qrc +++ /dev/null @@ -1,24 +0,0 @@ - - - data/obj/defaultactor_LOD0.bin - data/obj/defaultactor_LOD0.cast - data/obj/defaultactor_LOD0.gltf - data/obj/defaultactor_LOD0.ma - data/obj/defaultactor_LOD0.mesh.ascii - data/obj/defaultactor_LOD0.obj - data/obj/defaultactor_LOD0.semodel - data/obj/defaultactor_LOD0.smd - data/obj/defaultactor_LOD0.XMODEL_BIN - data/obj/defaultactor_LOD0.XMODEL_EXPORT - data/obj/defaultactor_LOD0_BIND.mel - data/obj/defaultactor_LOD0_cosmetics.mel - data/obj/mtl_body_default_character.mtl - data/obj/mtl_body_default_character_images.txt - data/obj/diffusemap.png - data/obj/normalmap.png - - - data/d3dbsp/asset_viewer.d3dbsp - data/d3dbsp/barebones.d3dbsp - - diff --git a/FastFile_WaW.pro b/FastFile_WaW.pro deleted file mode 100644 index a7c6012..0000000 --- a/FastFile_WaW.pro +++ /dev/null @@ -1,35 +0,0 @@ -QT += core gui 3dcore 3drender 3dinput 3dextras - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++17 - -# INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um" -# LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.26100.0/um/x64" \ -# -ldxcompiler - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - main.cpp \ - mainwindow.cpp - -HEADERS += \ - enums.h \ - mainwindow.h \ - structs.h \ - utils.h \ - bink.h - -FORMS += \ - mainwindow.ui - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -RESOURCES += \ - Data.qrc diff --git a/FastFile_WaW.pro.user b/FastFile_WaW.pro.user deleted file mode 100644 index 4e96dc1..0000000 --- a/FastFile_WaW.pro.user +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - EnvironmentId - {40d992cb-ac11-4385-a22b-016f1b4251a7} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 0 - 80 - true - true - 1 - 0 - false - true - false - 2 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - false - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 16 - true - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.8.1 MSVC2022 64bit - Desktop Qt 6.8.1 MSVC2022 64bit - qt.qt6.681.win64_msvc2022_64_kit - 1 - 0 - 0 - - 0 - C:\Users\njohnson\Projects\FastFile_WaW\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Debug - C:/Users/njohnson/Projects/FastFile_WaW/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - C:\Users\njohnson\Projects\FastFile_WaW\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Release - C:/Users/njohnson/Projects/FastFile_WaW/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - C:\Users\njohnson\Projects\FastFile_WaW\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Profile - C:/Users/njohnson/Projects/FastFile_WaW/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - 0 - true - - 2 - - false - -e cpu-cycles --call-graph "dwarf,4096" -F 250 - - Qt4ProjectManager.Qt4RunConfiguration: - C:/Users/njohnson/Projects/FastFile_WaW/FastFile_WaW.pro - false - true - true - true - C:/Users/njohnson/Projects/FastFile_WaW/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Release - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/XPlor.pro b/XPlor.pro new file mode 100644 index 0000000..642f704 --- /dev/null +++ b/XPlor.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +SUBDIRS += libs \ + app \ + tools \ + tests diff --git a/XPlor.pro.user.40d992c b/XPlor.pro.user.40d992c new file mode 100644 index 0000000..861b133 --- /dev/null +++ b/XPlor.pro.user.40d992c @@ -0,0 +1,625 @@ + + + + + + EnvironmentId + {40d992cb-ac11-4385-a22b-016f1b4251a7} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 0 + 80 + true + true + 1 + 0 + false + true + false + 2 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + Unchecked + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 16 + true + + + + true + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.8.2 MSVC2022 64bit + Desktop Qt 6.8.2 MSVC2022 64bit + qt.qt6.682.win64_msvc2022_64_kit + 0 + 0 + 0 + + 0 + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_2_MSVC2022_64bit-Debug + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_MSVC2022_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_2_MSVC2022_64bit-Release + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_MSVC2022_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_2_MSVC2022_64bit-Profile + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_MSVC2022_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + Qt4ProjectManager.Qt4RunConfiguration: + G:/Projects/Qt/XPlor/app/app.pro + false + true + true + true + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_MSVC2022_64bit-Debug/app + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + Qt4ProjectManager.Qt4RunConfiguration: + G:/Projects/Qt/XPlor/tests/tests.pro + false + true + true + true + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_MSVC2022_64bit-Debug/tests + + 2 + + + + ProjectExplorer.Project.Target.1 + + Desktop + Desktop Qt 6.8.2 llvm-mingw 64-bit + Desktop Qt 6.8.2 llvm-mingw 64-bit + qt.qt6.682.win64_llvm_mingw_kit + 0 + 0 + 1 + + 0 + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_2_llvm_mingw_64_bit-Debug + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_llvm_mingw_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_2_llvm_mingw_64_bit-Release + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_llvm_mingw_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_2_llvm_mingw_64_bit-Profile + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_2_llvm_mingw_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + Qt4ProjectManager.Qt4RunConfiguration: + G:/Projects/Qt/XPlor/app/app.pro + false + true + true + true + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + Qt4ProjectManager.Qt4RunConfiguration: + G:/Projects/Qt/XPlor/tests/tests.pro + false + true + true + true + + 2 + + + + ProjectExplorer.Project.Target.2 + + Desktop + Desktop Qt 6.8.1 MSVC2022 64bit + Desktop Qt 6.8.1 MSVC2022 64bit + qt.qt6.681.win64_msvc2022_64_kit + 0 + 0 + 0 + + 0 + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Debug + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + G:\Projects\Qt\XPlor\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Release + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + 2 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + Qt4ProjectManager.Qt4RunConfiguration: + G:/Projects/Qt/XPlor/app/app.pro + false + true + true + true + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Debug/app + + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + Qt4ProjectManager.Qt4RunConfiguration: + G:/Projects/Qt/XPlor/tests/tests.pro + false + true + true + true + G:/Projects/Qt/XPlor/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Debug/tests + + 2 + + + + ProjectExplorer.Project.TargetCount + 3 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/LICENSE b/app/LICENSE similarity index 100% rename from LICENSE rename to app/LICENSE diff --git a/app/aboutdialog.cpp b/app/aboutdialog.cpp new file mode 100644 index 0000000..c3ba1b4 --- /dev/null +++ b/app/aboutdialog.cpp @@ -0,0 +1,14 @@ +#include "aboutdialog.h" +#include "ui_aboutdialog.h" + +AboutDialog::AboutDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::AboutDialog) +{ + ui->setupUi(this); +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} diff --git a/app/aboutdialog.h b/app/aboutdialog.h new file mode 100644 index 0000000..4474ece --- /dev/null +++ b/app/aboutdialog.h @@ -0,0 +1,22 @@ +#ifndef ABOUTDIALOG_H +#define ABOUTDIALOG_H + +#include + +namespace Ui { +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = nullptr); + ~AboutDialog(); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_H diff --git a/app/aboutdialog.ui b/app/aboutdialog.ui new file mode 100644 index 0000000..27665f5 --- /dev/null +++ b/app/aboutdialog.ui @@ -0,0 +1,241 @@ + + + AboutDialog + + + + 0 + 0 + 350 + 200 + + + + + 350 + 200 + + + + + 350 + 200 + + + + About XPlor + + + + + + + + + 80 + 80 + + + + + 80 + 80 + + + + + + + :/images/data/images/XPlor.png + + + true + + + Qt::AlignmentFlag::AlignCenter + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + 0 + 0 + + + + + Roboto + 16 + false + + + + XPlor v1.5 + + + + + + + + 0 + 0 + + + + + Roboto + + + + Copyright © 2024 RedLine Solutions LLC + + + + + + + + 0 + 0 + + + + + Roboto + + + + For more, check out redline.llc + + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Fixed + + + + 20 + 10 + + + + + + + + + 0 + 0 + + + + + Roboto + + + + With Help From: + + + + + + + + 0 + 0 + + + + + Roboto + + + + - Paging Red + + + + + + + + 0 + 0 + + + + + Roboto + + + + - ISOCheated + + + + + + + + 0 + 0 + + + + + Roboto + + + + - SureShotIan + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/app/app.ico b/app/app.ico new file mode 100644 index 0000000..68c58cd Binary files /dev/null and b/app/app.ico differ diff --git a/app/app.pro b/app/app.pro new file mode 100644 index 0000000..011daaf --- /dev/null +++ b/app/app.pro @@ -0,0 +1,122 @@ +QT += core widgets gui multimedia + +RC_ICONS = app.ico + +SUBDIRS += app + +CONFIG += c++17 + +SOURCES += \ + aboutdialog.cpp \ + ddsviewer.cpp \ + fastfileviewer.cpp \ + imagewidget.cpp \ + iwiviewer.cpp \ + localstringviewer.cpp \ + main.cpp \ + mainwindow.cpp \ + materialviewer.cpp \ + preferenceeditor.cpp \ + soundviewer.cpp \ + stringtableviewer.cpp \ + techsetviewer.cpp \ + xtreewidget.cpp \ + xtreewidgetitem.cpp \ + zonefileviewer.cpp + +HEADERS += \ + aboutdialog.h \ + d3dbsp_structs.h \ + ddsviewer.h \ + fastfileviewer.h \ + imagewidget.h \ + iwiviewer.h \ + localstringviewer.h \ + mainwindow.h \ + materialviewer.h \ + preferenceeditor.h \ + soundviewer.h \ + stringtableviewer.h \ + techsetviewer.h \ + xtreewidget.h \ + xtreewidgetitem.h \ + zonefileviewer.h + +FORMS += \ + aboutdialog.ui \ + ddsviewer.ui \ + fastfileviewer.ui \ + imagewidget.ui \ + iwiviewer.ui \ + localstringviewer.ui \ + mainwindow.ui \ + materialviewer.ui \ + modelviewer.ui \ + preferenceeditor.ui \ + soundviewer.ui \ + stringtableviewer.ui \ + techsetviewer.ui \ + zonefileviewer.ui + +RESOURCES += ../data/data.qrc + +app.depends += \ + libs/core \ + libs/compression \ + libs/encryption \ + libs/fastfile \ + libs/ddsfile \ + libs/ipakfile \ + libs/iwifile \ + libs/zonefile + +LIBS += \ + -L$$PWD/../third_party/devil_sdk/lib/ -lDevIL -lILU -lILUT \ + -L$$PWD/../third_party/zlib/lib/ -lzlib \ + -L$$PWD/../third_party/xbox_sdk/lib -lxcompress64 \ + -L$$OUT_PWD/../libs/ -lcore \ + -L$$OUT_PWD/../libs/ -lcompression \ + -L$$OUT_PWD/../libs/ -lencryption \ + -L$$OUT_PWD/../libs/ -lfastfile \ + -L$$OUT_PWD/../libs/ -lddsfile \ + -L$$OUT_PWD/../libs/ -lipakfile \ + -L$$OUT_PWD/../libs/ -liwifile \ + -L$$OUT_PWD/../libs/ -lzonefile + +INCLUDEPATH += \ + $$PWD/../third_party/devil_sdk/include/ \ + $$PWD/../third_party/zlib/include \ + $$PWD/../third_party/xbox_sdk/include \ + $$PWD/../libs/core \ + $$PWD/../libs/compression \ + $$PWD/../libs/encryption \ + $$PWD/../libs/fastfile \ + $$PWD/../libs/ddsfile \ + $$PWD/../libs/ipakfile \ + $$PWD/../libs/iwifile \ + $$PWD/../libs/zonefile + +DEPENDPATH += \ + $$PWD/../third_party/devil_sdk/include/ \ + $$PWD/../third_party/zlib/include \ + $$PWD/../third_party/xbox_sdk/include \ + $$PWD/../libs/core \ + $$PWD/../libs/compression \ + $$PWD/../libs/encryption \ + $$PWD/../libs/fastfile \ + $$PWD/../libs/ddsfile \ + $$PWD/../libs/ipakfile \ + $$PWD/../libs/iwifile \ + $$PWD/../libs/zonefile + +# Copy DLLs to Debug folder +QMAKE_POST_LINK += xcopy /Y /E /I \"G:/Projects/Qt/XPlor/third_party/devil_sdk/lib\\*.dll\" \"$$OUT_PWD/debug/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"G:/Projects/Qt/XPlor/third_party/zlib/lib\\*.dll\" \"$$OUT_PWD/debug/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"G:/Projects/Qt/XPlor/third_party/xna/lib\\*.dll\" \"$$OUT_PWD/debug/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"$$PWD/../third_party/xbox_sdk/lib\\*.dll\" \"$$OUT_PWD/debug/\" $$escape_expand(\\n\\t) + +# Copy DLLs to Release folder +QMAKE_POST_LINK += xcopy /Y /E /I \"G:/Projects/Qt/XPlor/third_party/devil_sdk/lib\\*.dll\" \"$$OUT_PWD/release/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"G:/Projects/Qt/XPlor/third_party/zlib/lib\\*.dll\" \"$$OUT_PWD/release/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"G:/Projects/Qt/XPlor/third_party/xna/lib\\*.dll\" \"$$OUT_PWD/release/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"$$PWD/../third_party/xbox_sdk/lib\\*.dll\" \"$$OUT_PWD/release/\" $$escape_expand(\\n\\t) diff --git a/structs.h b/app/d3dbsp_structs.h similarity index 88% rename from structs.h rename to app/d3dbsp_structs.h index f1f1406..33017af 100644 --- a/structs.h +++ b/app/d3dbsp_structs.h @@ -1,5 +1,5 @@ -#ifndef STRUCTS_H -#define STRUCTS_H +#ifndef D3DBSP_STRUCTS_H +#define D3DBSP_STRUCTS_H #include @@ -38,4 +38,4 @@ struct BINK { uint32_t FrameChangePercent; }; -#endif // STRUCTS_H +#endif // D3DBSP_STRUCTS_H diff --git a/app/ddsviewer.cpp b/app/ddsviewer.cpp new file mode 100644 index 0000000..c9c31c5 --- /dev/null +++ b/app/ddsviewer.cpp @@ -0,0 +1,182 @@ +#include "ddsviewer.h" +#include "enums.h" +#include "ui_ddsviewer.h" + +DDSViewer::DDSViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::DDSViewer) +{ + ui->setupUi(this); + mDDSFile = nullptr; +} + +DDSViewer::~DDSViewer() { + delete ui; +} + +void DDSViewer::SetDDSFile(std::shared_ptr aDDSFile) { + mDDSFile.swap(aDDSFile); + + ui->label_Title->setText(mDDSFile->fileStem + ".dds"); + + char magicData[5]; + magicData[0] = static_cast(mDDSFile->header.magic & 0xFF); + magicData[1] = static_cast((mDDSFile->header.magic >> 8) & 0xFF); + magicData[2] = static_cast((mDDSFile->header.magic >> 16) & 0xFF); + magicData[3] = static_cast((mDDSFile->header.magic >> 24) & 0xFF); + magicData[4] = '\0'; + + // If you’re using Qt and want a QString: + QString magicStr = QString::fromLatin1(magicData); + ui->lineEdit_Magic->setText(magicStr); + ui->spinBox_Size->setValue(mDDSFile->header.size); + + ui->checkBox_CapsValid->setChecked((mDDSFile->header.flags & DDSD_CAPS) != 0); + ui->checkBox_HeightValid->setChecked((mDDSFile->header.flags & DDSD_HEIGHT) != 0); + ui->checkBox_WidthValid->setChecked((mDDSFile->header.flags & DDSD_WIDTH) != 0); + ui->checkBox_PitchValid->setChecked((mDDSFile->header.flags & DDSD_PITCH) != 0); + ui->checkBox_PFValid->setChecked((mDDSFile->header.flags & DDSD_PIXELFORMAT) != 0); + ui->checkBox_MipmapCountValid->setChecked((mDDSFile->header.flags & DDSD_MIPMAPCOUNT) != 0); + ui->checkBox_LinearSizeValid->setChecked((mDDSFile->header.flags & DDSD_LINEARSIZE) != 0); + ui->checkBox_DepthValid->setChecked((mDDSFile->header.flags & DDSD_DEPTH) != 0); + + ui->spinBox_PLSize->setValue(mDDSFile->header.pitchOrLinearSize); + ui->spinBox_Depth->setValue(mDDSFile->header.depth); + ui->spinBox_Width->setValue(mDDSFile->header.width); + ui->spinBox_Height->setValue(mDDSFile->header.height); + ui->spinBox_MipmapCount->setValue(mDDSFile->header.mipMapCount); + + ui->spinBox_Res1->setValue(mDDSFile->header.reserved1[0]); + ui->spinBox_Res2->setValue(mDDSFile->header.reserved1[1]); + ui->spinBox_Res3->setValue(mDDSFile->header.reserved1[2]); + ui->spinBox_Res4->setValue(mDDSFile->header.reserved1[3]); + ui->spinBox_Res5->setValue(mDDSFile->header.reserved1[4]); + ui->spinBox_Res6->setValue(mDDSFile->header.reserved1[5]); + ui->spinBox_Res7->setValue(mDDSFile->header.reserved1[6]); + ui->spinBox_Res8->setValue(mDDSFile->header.reserved1[7]); + ui->spinBox_Res9->setValue(mDDSFile->header.reserved1[8]); + ui->spinBox_Res10->setValue(mDDSFile->header.reserved1[9]); + ui->spinBox_Res11->setValue(mDDSFile->header.reserved1[10]); + + ui->spinBox_Res12->setValue(mDDSFile->header.reserved2); + + ui->spinBox_PF_Size->setValue(mDDSFile->header.pixelFormat.size); + + ui->checkBox_PF_AlphaPxValid->setChecked((mDDSFile->header.pixelFormat.flags & DDPF_ALPHAPIXELS) != 0); + ui->checkBox_PF_AlphaOnlyValid->setChecked((mDDSFile->header.pixelFormat.flags & DDPF_ALPHA) != 0); + ui->checkBox_PF_FormatValid->setChecked((mDDSFile->header.pixelFormat.flags & DDPF_FOURCC) != 0); + ui->checkBox_PF_RGBValid->setChecked((mDDSFile->header.pixelFormat.flags & DDPF_RGB) != 0); + ui->checkBox_PF_YUVValid->setChecked((mDDSFile->header.pixelFormat.flags & DDPF_YUV) != 0); + ui->checkBox_PF_LuminanceValid->setChecked((mDDSFile->header.pixelFormat.flags & DDPF_LUMINANCE) != 0); + + QString formatStr = QString::number(mDDSFile->header.pixelFormat.format); + switch (mDDSFile->header.pixelFormat.format) { + case IWI_FORMAT_ARGB32: + formatStr = "ARGB32"; + break; + case IWI_FORMAT_RGB24: + formatStr = "RGB24"; + break; + case IWI_FORMAT_GA16: + formatStr = "GA16"; + break; + case IWI_FORMAT_A8: + formatStr = "A8"; + break; + case IWI_FORMAT_DXT1: + formatStr = "DXT1"; + break; + case IWI_FORMAT_DXT3: + formatStr = "DXT3"; + break; + case IWI_FORMAT_DXT5: + formatStr = "DXT5"; + break; + } + ui->lineEdit_PF_Format->setText(formatStr); + ui->spinBox_PF_RGBBitCount->setValue(mDDSFile->header.pixelFormat.rgbBitCount); + ui->spinBox_RedBitCount->setValue(mDDSFile->header.pixelFormat.rBitMask); + ui->spinBox_GreenBitCount->setValue(mDDSFile->header.pixelFormat.gBitMask); + ui->spinBox_BlueBitCount->setValue(mDDSFile->header.pixelFormat.bBitMask); + ui->spinBox_AlphaBitMask->setValue(mDDSFile->header.pixelFormat.aBitMask); + + ui->checkBox_Caps1_TextureValid->setChecked((mDDSFile->header.caps.caps1 & DDSCAPS_TEXTURE) != 0); + ui->checkBox_Caps1_ComplexValid->setChecked((mDDSFile->header.caps.caps1 & DDSCAPS_COMPLEX) != 0); + ui->checkBox_Caps1_MipmapValid->setChecked((mDDSFile->header.caps.caps1 & DDSCAPS_MIPMAP) != 0); + + ui->checkBox_Caps2_CubemapValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP) != 0); + ui->checkBox_Caps2_CMPXValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) != 0); + ui->checkBox_Caps2_CMNXValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) != 0); + ui->checkBox_Caps2_CMPYValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) != 0); + ui->checkBox_Caps2_CMNYValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) != 0); + ui->checkBox_Caps2_CMPZValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) != 0); + ui->checkBox_Caps2_CMNZValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ) != 0); + ui->checkBox_Caps2_VolumeValid->setChecked((mDDSFile->header.caps.caps2 & DDSCAPS2_VOLUME) != 0); + + ui->spinBox_Caps_DDSX->setValue(mDDSFile->header.caps.dDSX); + ui->spinBox_Caps_Res->setValue(mDDSFile->header.caps.reserved); + + ui->comboBox_Mipmap->clear(); + for (auto mipmap : mDDSFile->mipmaps) { + ui->comboBox_Mipmap->addItem(QString("%1x%2").arg(mipmap.width).arg(mipmap.height)); + } + + connect(ui->comboBox_Mipmap, &QComboBox::currentIndexChanged, this, &DDSViewer::MipmapIndexChanged); + + if (!mDDSFile->mipmaps.empty()) { + MipmapIndexChanged(0); + } +} + +void DDSViewer::MipmapIndexChanged(int aMipmapIndex) { + if (aMipmapIndex == -1) { return; } + + auto mipmaps = mDDSFile->mipmaps; + auto mipmap = mipmaps[aMipmapIndex]; + + ui->spinBox_MipmapSize->setValue(mipmap.size); + ui->spinBox_MipmapWidth->setValue(mipmap.width); + ui->spinBox_MipmapHeight->setValue(mipmap.height); + + // Validate Data + if (mipmap.size <= 0) { + qDebug() << "Error: Mipmap data is empty!"; + return; + } + if (mipmap.width <= 0 || mipmap.height <= 0) { + qDebug() << "Error: Invalid mipmap dimensions!"; + return; + } + + // Ensure data size matches expected size + int bytesPerPixel = 4; // RGBA8888 + quint32 expectedSize = mipmap.width * mipmap.height * bytesPerPixel; + if (mipmap.size < expectedSize) { + qDebug() << "Error: Mipmap data size mismatch! Expected:" << expectedSize << ", Got:" << mipmap.size; + return; + } + + // Create QImage + const unsigned char* imageData = reinterpret_cast(mipmap.data.constData()); + QImage image(reinterpret_cast(imageData), + mipmap.width, mipmap.height, + mipmap.width * bytesPerPixel, // Stride + QImage::Format_RGBA8888); + + if (image.isNull()) { + qDebug() << "Error: QImage creation failed!"; + return; + } + + // Convert to QPixmap + QPixmap pixmap = QPixmap::fromImage(image); + if (pixmap.isNull()) { + qDebug() << "Error: QPixmap conversion failed!"; + return; + } + + // Scale and display + pixmap = pixmap.scaled(ui->label_Image->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + ui->label_Image->setPixmap(pixmap); +} + diff --git a/app/ddsviewer.h b/app/ddsviewer.h new file mode 100644 index 0000000..f49bbc2 --- /dev/null +++ b/app/ddsviewer.h @@ -0,0 +1,29 @@ +#ifndef DDSVIEWER_H +#define DDSVIEWER_H + +#include "ddsfile.h" +#include + +namespace Ui { +class DDSViewer; +} + +class DDSViewer : public QWidget +{ + Q_OBJECT + +public: + explicit DDSViewer(QWidget *parent = nullptr); + ~DDSViewer(); + + void SetDDSFile(std::shared_ptr aDDSFile); + +private slots: + void MipmapIndexChanged(int aMipmapIndex); + +private: + Ui::DDSViewer *ui; + std::shared_ptr mDDSFile; +}; + +#endif // DDSVIEWER_H diff --git a/app/ddsviewer.ui b/app/ddsviewer.ui new file mode 100644 index 0000000..d7dc083 --- /dev/null +++ b/app/ddsviewer.ui @@ -0,0 +1,1712 @@ + + + DDSViewer + + + + 0 + 0 + 1326 + 876 + + + + Form + + + + + + + Roboto + 16 + true + + + + DDS File 0 + + + + + + + + + + + + Roboto + 9 + + + + Caps + + + + + + + + + Roboto + 9 + + + + D DSX: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + Roboto + 9 + + + + Reserved: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + false + + + Caps 2 Flags / Valid Data + + + + + + + 0 + 0 + + + + Cubemap Valid + + + + + + + + 0 + 0 + + + + Cubemap +X Valid + + + + + + + + 0 + 0 + + + + Cubemap -X Valid + + + + + + + + 0 + 0 + + + + Cubemap +Y Valid + + + + + + + + 0 + 0 + + + + Cubemap -Y Valid + + + + + + + + 0 + 0 + + + + Cubemap +Z Valid + + + + + + + + 0 + 0 + + + + Cubemap -Z Valid + + + + + + + + 0 + 0 + + + + Volume Valid + + + + + + + + + + false + + + Caps 1 Flags / Valid Data + + + + + + + 0 + 0 + + + + Complex Valid + + + + + + + + 0 + 0 + + + + Mipmap Valid + + + + + + + + 0 + 0 + + + + Texture Valid + + + + + + + Qt::Orientation::Vertical + + + + 20 + 78 + + + + + + + + + + + + + + + Roboto + 9 + + + + Header + + + + + + + + + + + + false + + + Properties + + + + + + + Roboto + 9 + + + + Magic: + + + + + + + false + + + + Roboto + 9 + + + + + + + + + Roboto + 9 + + + + Header Len: + + + + + + + false + + + + Roboto + 9 + + + + B + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Pitch/Linear Size: + + + + + + + + Roboto + 9 + + + + Depth: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Mipmap #: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Height: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Width: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + false + + + Flags / Valid Data + + + + + + + 0 + 0 + + + + Caps Valid + + + + + + + + 0 + 0 + + + + Height Valid + + + + + + + + 0 + 0 + + + + Width Valid + + + + + + + + 0 + 0 + + + + Pitch Valid + + + + + + + + 0 + 0 + + + + Depth Valid + + + + + + + + 0 + 0 + + + + Linear Size Valid + + + + + + + + 0 + 0 + + + + Mipmap Count Valid + + + + + + + + 0 + 0 + + + + Pixel Format Valid + + + + + + + + + + + + + Roboto + 9 + + + + Qt::Orientation::Vertical + + + + + + + + + false + + + Reserved Fields + + + + + + + Roboto + 9 + + + + Reserved 1: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 2: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 3: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 4: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 5: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 6: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 7: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 8: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 9: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 10: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 11: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Reserved 12: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Ignored + + + + 17 + 118 + + + + + + + + + + + + + + + + + + + + + Roboto + 9 + + + + Mipmaps + + + + + + + + + Roboto + 9 + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + Roboto + 9 + + + + Select Mipmap: + + + + + + + + 60 + 0 + + + + + Roboto + 9 + + + + + + + + + Roboto + 9 + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + false + + + Properties + + + + + + + + + Roboto + 9 + + + + Size: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + Roboto + 9 + + + + Height: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + Roboto + 9 + + + + Width: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + Roboto + 9 + + + + Pixel Format + + + + + + false + + + Properties + + + + + + + Roboto + 9 + + + + Size: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Format: + + + + + + + false + + + + 0 + 0 + + + + + Roboto + 9 + + + + + + + + + Roboto + 9 + + + + RGB Bit #: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Red Bit Mask: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Blue Bit Mask: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Green Bit Mask: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Alpha Bit Mask: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + Roboto + 9 + + + + Qt::Orientation::Vertical + + + + + + + false + + + Flags / Valid Data + + + + + + + 0 + 0 + + + + Alpha Pixels Valid + + + + + + + + 0 + 0 + + + + Alpha Only Valid + + + + + + + + 0 + 0 + + + + Format Valid + + + + + + + + 0 + 0 + + + + RGB Valid + + + + + + + + 0 + 0 + + + + YUV Valid + + + + + + + + 0 + 0 + + + + Luminance Valid + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + Roboto + 9 + + + + Preview + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + 600 + 600 + + + + + 600 + 600 + + + + + Roboto + 9 + + + + border: 2px solid white; + + + + + + Qt::AlignmentFlag::AlignCenter + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/app/fastfileviewer.cpp b/app/fastfileviewer.cpp new file mode 100644 index 0000000..2fb29bb --- /dev/null +++ b/app/fastfileviewer.cpp @@ -0,0 +1,27 @@ +#include "fastfileviewer.h" +#include "asset_structs.h" +#include "ui_fastfileviewer.h" + +FastFileViewer::FastFileViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::FFViewer) + , mFastFile(nullptr) +{ + ui->setupUi(this); +} + +FastFileViewer::~FastFileViewer() +{ + delete ui; +} + +void FastFileViewer::SetFastFile(std::shared_ptr aFastFile) { + mFastFile.swap(aFastFile); + + ui->label_Title->setText(mFastFile->GetStem() + ".ff"); + ui->comboBox_Company->setCurrentIndex(mFastFile->GetCompany()); + ui->comboBox_FileType->setCurrentIndex(mFastFile->GetType()); + ui->checkBox_Signed->setChecked(mFastFile->GetSignage() == SIGNAGE_SIGNED); + ui->lineEdit_Magic->setText(mFastFile->GetMagic()); + ui->spinBox_Version->setValue(mFastFile->GetVersion()); +} diff --git a/app/fastfileviewer.h b/app/fastfileviewer.h new file mode 100644 index 0000000..3fc36c1 --- /dev/null +++ b/app/fastfileviewer.h @@ -0,0 +1,26 @@ +#ifndef FASTFILEVIEWER_H +#define FASTFILEVIEWER_H + +#include "asset_structs.h" +#include "fastfile.h" +#include + +namespace Ui { +class FFViewer; +} + +class FastFileViewer : public QWidget +{ + Q_OBJECT + +public: + explicit FastFileViewer(QWidget *parent = nullptr); + ~FastFileViewer(); + + void SetFastFile(std::shared_ptr aFastFile); +private: + Ui::FFViewer *ui; + std::shared_ptr mFastFile; +}; + +#endif // FASTFILEVIEWER_H diff --git a/app/fastfileviewer.ui b/app/fastfileviewer.ui new file mode 100644 index 0000000..52e4091 --- /dev/null +++ b/app/fastfileviewer.ui @@ -0,0 +1,197 @@ + + + FFViewer + + + + 0 + 0 + 428 + 459 + + + + Form + + + + + + + Roboto + 16 + true + + + + FastFile 0 + + + + + + + + + + + + 400 + 400 + + + + + Roboto + 9 + + + + Header + + + + + + Company: + + + + + + + false + + + + None + + + + + Infinity Ward + + + + + Treyarch + + + + + Sledgehammer + + + + + Neversoft + + + + + + + + File Type: + + + + + + + false + + + + None + + + + + FastFile + + + + + + + + Signed: + + + + + + + false + + + Is signed + + + + + + + Magic: + + + + + + + + + + Version: + + + + + + + false + + + 10000 + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 1 + + + + + + + + + diff --git a/app/imagewidget.cpp b/app/imagewidget.cpp new file mode 100644 index 0000000..04af5c1 --- /dev/null +++ b/app/imagewidget.cpp @@ -0,0 +1,28 @@ +#include "imagewidget.h" +#include "ui_imagewidget.h" + +ImageWidget::ImageWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::ImageWidget) +{ + ui->setupUi(this); +} + +ImageWidget::~ImageWidget() +{ + delete ui; +} + +void ImageWidget::SetImage(std::shared_ptr aImage) +{ + mImage = aImage; + + ui->lineEdit_Name->setText(aImage->name); + ui->lineEdit_Role->setText(aImage->materialName); + ui->comboBox_Compression->setCurrentIndex(aImage->compression); +} + +std::shared_ptr ImageWidget::GetImage() +{ + return mImage; +} diff --git a/app/imagewidget.h b/app/imagewidget.h new file mode 100644 index 0000000..4de5a27 --- /dev/null +++ b/app/imagewidget.h @@ -0,0 +1,32 @@ +#ifndef IMAGEWIDGET_H +#define IMAGEWIDGET_H + +#include "enums.h" +#include "dds_structs.h" +#include "d3dbsp_structs.h" +#include "asset_structs.h" +#include "ipak_structs.h" + +#include + +namespace Ui { +class ImageWidget; +} + +class ImageWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ImageWidget(QWidget *parent = nullptr); + ~ImageWidget(); + + void SetImage(std::shared_ptr aImage); + std::shared_ptr GetImage(); + +private: + std::shared_ptr mImage; + Ui::ImageWidget *ui; +}; + +#endif // IMAGEWIDGET_H diff --git a/app/imagewidget.ui b/app/imagewidget.ui new file mode 100644 index 0000000..47b6206 --- /dev/null +++ b/app/imagewidget.ui @@ -0,0 +1,144 @@ + + + ImageWidget + + + + 0 + 0 + 589 + 422 + + + + Form + + + + + + + + + + Image Role: + + + + + + + + + + + + + + Name: + + + + + + + + + + + + + + Compression: + + + + + + + + None + + + + + DXT1 + + + + + DXT3 + + + + + DXT5 + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Orientation::Vertical + + + + + + + + + + 250 + 250 + + + + + 250 + 250 + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/app/iwiviewer.cpp b/app/iwiviewer.cpp new file mode 100644 index 0000000..1fd2268 --- /dev/null +++ b/app/iwiviewer.cpp @@ -0,0 +1,98 @@ +#include "iwiviewer.h" +#include "enums.h" +#include "ui_iwiviewer.h" + +IWIViewer::IWIViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::IWIViewer) +{ + ui->setupUi(this); +} + +IWIViewer::~IWIViewer() +{ + delete ui; +} + +void IWIViewer::SetIWIFile(std::shared_ptr aIWIFile) { + mIWIFile.swap(aIWIFile); + + ui->label_Title->setText(mIWIFile->fileStem + ".iwi"); + + // If you’re using Qt and want a QString: + QString magicStr = QString::fromLatin1(mIWIFile->header.Magic, 3); + ui->lineEdit_Magic->setText(magicStr); + + ui->spinBox_Version->setValue(mIWIFile->header.Version); + ui->spinBox_Depth->setValue(mIWIFile->info.Depth); + QString formatStr = ""; + switch (mIWIFile->info.Format) { + case IWI_FORMAT_ARGB32: + formatStr = "ARGB32"; + break; + case IWI_FORMAT_RGB24: + formatStr = "RGB24"; + break; + case IWI_FORMAT_GA16: + formatStr = "GA16"; + break; + case IWI_FORMAT_A8: + formatStr = "A8"; + break; + case IWI_FORMAT_DXT1: + formatStr = "DXT1"; + break; + case IWI_FORMAT_DXT3: + formatStr = "DXT3"; + break; + case IWI_FORMAT_DXT5: + formatStr = "DXT5"; + break; + } + ui->lineEdit_Format->setText(formatStr); + ui->spinBox_Height->setValue(mIWIFile->info.Height); + ui->spinBox_Width->setValue(mIWIFile->info.Width); + ui->spinBox_Usage->setValue(mIWIFile->info.Usage); + + ui->comboBox_Mipmap->clear(); + for (auto mipmap : mIWIFile->mipmaps) { + ui->comboBox_Mipmap->addItem(QString::number(mipmap.offset)); + } + + connect(ui->comboBox_Mipmap, &QComboBox::currentIndexChanged, this, &IWIViewer::MipmapIndexChanged); + + if (!mIWIFile->mipmaps.empty()) { + MipmapIndexChanged(0); + } +} + +void IWIViewer::MipmapIndexChanged(int aMipmapIndex) { + auto mipmaps = mIWIFile->mipmaps; + + if (aMipmapIndex == -1) { return; } + + auto mipmap = mipmaps[aMipmapIndex]; + ui->spinBox_MipmapSize->setValue(mipmap.size); + ui->spinBox_MipmapOffset->setValue(mipmap.offset); + + const unsigned char* imageData = reinterpret_cast(mipmap.data.constData()); + QImage image(reinterpret_cast(imageData), + mIWIFile->info.Width, mIWIFile->info.Height, + QImage::Format_RGBA8888); + + if (image.isNull()) { + qDebug() << "Error: QImage creation failed!"; + return; + } + + // Convert to QPixmap + QPixmap pixmap = QPixmap::fromImage(image); + if (pixmap.isNull()) { + qDebug() << "Error: QPixmap conversion failed!"; + return; + } + + // Scale and display + pixmap = pixmap.scaled(ui->label_Image->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + ui->label_Image->setPixmap(pixmap); +} diff --git a/app/iwiviewer.h b/app/iwiviewer.h new file mode 100644 index 0000000..86f5105 --- /dev/null +++ b/app/iwiviewer.h @@ -0,0 +1,27 @@ +#ifndef IWIVIEWER_H +#define IWIVIEWER_H + +#include "iwifile.h" +#include + +namespace Ui { +class IWIViewer; +} + +class IWIViewer : public QWidget +{ + Q_OBJECT + +public: + explicit IWIViewer(QWidget *parent = nullptr); + ~IWIViewer(); + + void MipmapIndexChanged(int aMipmapIndex); + + void SetIWIFile(std::shared_ptr aIWIFile); +private: + Ui::IWIViewer *ui; + std::shared_ptr mIWIFile; +}; + +#endif // IWIVIEWER_H diff --git a/app/iwiviewer.ui b/app/iwiviewer.ui new file mode 100644 index 0000000..657df71 --- /dev/null +++ b/app/iwiviewer.ui @@ -0,0 +1,548 @@ + + + IWIViewer + + + + 0 + 0 + 1246 + 909 + + + + Form + + + + + + + Roboto + 16 + true + + + + IWI File 0 + + + + + + + + + + + + Roboto + 9 + + + + Header + + + + + + + Roboto + 9 + + + + Magic: + + + + + + + false + + + + Roboto + 9 + + + + + + + + + Roboto + 9 + + + + Version: + + + + + + + false + + + + Roboto + 9 + + + + B + + + 1000000000 + + + + + + + + + + + Roboto + 9 + + + + Info + + + + + + + + + Roboto + 9 + + + + Depth: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + Roboto + 9 + + + + Format + + + + + + + false + + + + Roboto + 9 + + + + + + + + + + + + + Roboto + 9 + + + + Height: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + Roboto + 9 + + + + Width: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + Roboto + 9 + + + + Usage + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + + + + Roboto + 9 + + + + Mipmaps + + + + + + + + + Roboto + 9 + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + Roboto + 9 + + + + Select Mipmap: + + + + + + + + 60 + 0 + + + + + Roboto + 9 + + + + + + + + + Roboto + 9 + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + Roboto + 9 + + + + Size: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + Roboto + 9 + + + + Offset: + + + + + + + false + + + + Roboto + 9 + + + + 1000000000 + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + Roboto + 9 + + + + Preview + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + 600 + 600 + + + + + 600 + 600 + + + + + Roboto + 9 + + + + border: 2px solid white; + + + + + + Qt::AlignmentFlag::AlignCenter + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 116 + + + + + + + + + diff --git a/app/localstringviewer.cpp b/app/localstringviewer.cpp new file mode 100644 index 0000000..6550668 --- /dev/null +++ b/app/localstringviewer.cpp @@ -0,0 +1,59 @@ +#include "localstringviewer.h" +#include "ui_localstringviewer.h" + +LocalStringViewer::LocalStringViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::LocalStringViewer), + mVersion(), + mConfigPath(), + mFileNotes() { + ui->setupUi(this); + + ui->tableWidget_Strings->setColumnCount(2); + ui->tableWidget_Strings->setColumnWidth(0, 200); + ui->tableWidget_Strings->horizontalHeader()->setStretchLastSection(true); +} + +LocalStringViewer::~LocalStringViewer() { + delete ui; +} + +void LocalStringViewer::SetVersion(quint32 aVersion) { + mVersion = aVersion; + + ui->spinBox_Version->setValue(mVersion); +} + +void LocalStringViewer::SetConfigPath(const QString aConfigPath) { + mConfigPath = aConfigPath; + + ui->lineEdit_Config->setText(mConfigPath); +} + +void LocalStringViewer::SetFileNotes(const QString aFileNotes) { + mFileNotes = aFileNotes; + + ui->plainTextEdit_FileNotes->setPlainText(mFileNotes); +} + +void LocalStringViewer::AddLocalString(LocalString aLocalString) { + mLocalStrings << aLocalString; + + ui->tableWidget_Strings->setRowCount(mLocalStrings.size()); + + QTableWidgetItem *aliasItem = new QTableWidgetItem(aLocalString.alias); + QTableWidgetItem *stringItem = new QTableWidgetItem(aLocalString.string); + + ui->tableWidget_Strings->setItem(mLocalStrings.size() - 1, 0, aliasItem); + ui->tableWidget_Strings->setItem(mLocalStrings.size() - 1, 1, stringItem); +} + +void LocalStringViewer::SetZoneFile(std::shared_ptr aZoneFile) { + mLocalStrings.clear(); + ui->tableWidget_Strings->clear(); + + ui->label_Title->setText(aZoneFile->GetStem().section('.', 0, 0) + ".str"); + for (LocalString localStr : aZoneFile->GetAssetMap().localStrings) { + AddLocalString(localStr); + } +} diff --git a/app/localstringviewer.h b/app/localstringviewer.h new file mode 100644 index 0000000..b2c8566 --- /dev/null +++ b/app/localstringviewer.h @@ -0,0 +1,34 @@ +#ifndef LOCALSTRINGVIEWER_H +#define LOCALSTRINGVIEWER_H + +#include "asset_structs.h" +#include "zonefile.h" +#include + +namespace Ui { +class LocalStringViewer; +} + +class LocalStringViewer : public QWidget +{ + Q_OBJECT + +public: + explicit LocalStringViewer(QWidget *parent = nullptr); + ~LocalStringViewer(); + + void SetVersion(quint32 aVersion); + void SetConfigPath(const QString aConfigPath); + void SetFileNotes(const QString aFileNotes); + void AddLocalString(LocalString aLocalString); + void SetZoneFile(std::shared_ptr aZoneFile); + +private: + Ui::LocalStringViewer *ui; + quint32 mVersion; + QString mConfigPath; + QString mFileNotes; + QVector mLocalStrings; +}; + +#endif // LOCALSTRINGVIEWER_H diff --git a/app/localstringviewer.ui b/app/localstringviewer.ui new file mode 100644 index 0000000..bdd547e --- /dev/null +++ b/app/localstringviewer.ui @@ -0,0 +1,194 @@ + + + LocalStringViewer + + + + 0 + 0 + 841 + 457 + + + + + 841 + 457 + + + + Form + + + + + + + Roboto + 16 + true + + + + LocalString File 0 + + + + + + + + + + + + 325 + 398 + + + + + 325 + 16777215 + + + + + Roboto + 9 + + + + Header + + + + + + File Notes: + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + + + + + + + Version: + + + + + + + false + + + C:\cod5\cod\cod5\bin\StringEd.cfg + + + + + + + Config: + + + + + + + ... + + + + + + + false + + + 10000 + + + 1 + + + + + + + Files notes... + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + 400 + 400 + + + + + Roboto + 9 + + + + Entries + + + + + + + 0 + 0 + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 0 + + + + + + + + + diff --git a/main.cpp b/app/main.cpp similarity index 100% rename from main.cpp rename to app/main.cpp diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp new file mode 100644 index 0000000..475cb32 --- /dev/null +++ b/app/mainwindow.cpp @@ -0,0 +1,902 @@ +#include "mainwindow.h" +#include "aboutdialog.h" +#include "fastfile.h" +#include "materialviewer.h" +#include "preferenceeditor.h" +#include "soundviewer.h" +#include "stringtableviewer.h" +#include "techsetviewer.h" +#include "ui_mainwindow.h" +#include "compression.h" +#include "iwifile.h" +#include "ddsfile.h" +#include "statusbarmanager.h" +#include "ddsviewer.h" +#include "fastfileviewer.h" +#include "ipak_structs.h" +#include "iwiviewer.h" +#include "localstringviewer.h" +#include "imagewidget.h" +#include "xtreewidget.h" +#include "zonefileviewer.h" +#include "techsetviewer.h" +#include "logmanager.h" + +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), ui(new Ui::MainWindow) { + ui->setupUi(this); + + setAcceptDrops(true); + + mTypeMap = QMap(); + mTypeOrder = QStringList(); + mRawFileMap = QMap(); + mImageMap = QMap(); + mTreeMap = QMap(); + mStrTableMap = QMap>>(); + mBSPVersion = 0; + mDiskLumpCount = 0; + mDiskLumpOrder = QVector(); + mLumps = QMap(); + mTreeWidget = new XTreeWidget(this); + mLogWidget = new QPlainTextEdit(this); + + //ModelViewer *mModelViewer = new ModelViewer(container); + //mModelViewer->setAcceptDrops(false); + + mProgressBar = new QProgressBar(this); + mProgressBar->setMaximum(100); // Default max value + mProgressBar->setVisible(false); // Initially hidden + + connect(&StatusBarManager::instance(), &StatusBarManager::statusUpdated, + this, &MainWindow::HandleStatusUpdate); + + connect(&StatusBarManager::instance(), &StatusBarManager::progressUpdated, + this, &MainWindow::HandleProgressUpdate); + + connect(&LogManager::instance(), &LogManager::entryAdded, + this, &MainWindow::HandleLogEntry); + + statusBar()->addPermanentWidget(mProgressBar); + + connect(ui->actionPreferences, &QAction::triggered, this, [this](bool checked) { + Q_UNUSED(checked); + + PreferenceEditor *prefEditor = new PreferenceEditor(this); + prefEditor->exec(); + }); + + ui->tabWidget->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->tabWidget, &QTabWidget::customContextMenuRequested, this, [this](const QPoint &pos) { + if (pos.isNull()) + return; + + int tabIndex = ui->tabWidget->tabBar()->tabAt(pos); + QMenu *contextMenu = new QMenu(this); + + QAction *closeAction = new QAction("Close"); + contextMenu->addAction(closeAction); + connect(closeAction, &QAction::triggered, this, [this, &tabIndex](bool checked) { + Q_UNUSED(checked); + + ui->tabWidget->removeTab(tabIndex); + }); + + QMenu *closeMultipleAction = new QMenu("Close Multiple Tabs"); + + QAction *closeAllAction = new QAction("Close All"); + closeMultipleAction->addAction(closeAllAction); + connect(closeAllAction, &QAction::triggered, this, [this](bool checked) { + Q_UNUSED(checked); + + ui->tabWidget->clear(); + }); + + QAction *closeAllButAction = new QAction("Close All BUT This"); + closeMultipleAction->addAction(closeAllButAction); + connect(closeAllButAction, &QAction::triggered, this, [this, &tabIndex](bool checked) { + Q_UNUSED(checked); + + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (i != tabIndex) { + ui->tabWidget->removeTab(i); + } + } + }); + + QAction *closeLeftAction = new QAction("Close All to the Left"); + closeMultipleAction->addAction(closeLeftAction); + connect(closeLeftAction, &QAction::triggered, this, [this, &tabIndex](bool checked) { + Q_UNUSED(checked); + + for (int i = 0; i < tabIndex; i++) { + ui->tabWidget->removeTab(i); + } + }); + + QAction *closeRightAction = new QAction("Close All to the Right"); + closeMultipleAction->addAction(closeRightAction); + connect(closeRightAction, &QAction::triggered, this, [this, &tabIndex](bool checked) { + Q_UNUSED(checked); + + for (int i = tabIndex + 1; i < ui->tabWidget->count(); i++) { + ui->tabWidget->removeTab(i); + } + }); + + contextMenu->addMenu(closeMultipleAction); + + QPoint pt(pos); + contextMenu->exec(ui->tabWidget->mapToGlobal(pt)); + + delete contextMenu; + }); + + connect(ui->tabWidget, &QTabWidget::tabCloseRequested, this, [this](int index) { + ui->tabWidget->removeTab(index); + }); + + connect(mTreeWidget, &XTreeWidget::Cleared, this, [this]() { + ui->tabWidget->clear(); + }); + + connect(mTreeWidget, &XTreeWidget::RawFileSelected, this, [this](std::shared_ptr rawFile, const QString aParentName) { + QPlainTextEdit *scriptEditor = new QPlainTextEdit(this); + scriptEditor->setAcceptDrops(false); + scriptEditor->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + if (rawFile->contents.isEmpty()) { + scriptEditor->setPlainText("EMPTY"); + } else { + scriptEditor->setPlainText(rawFile->contents); + } + + QString fileStem = rawFile->path.split('/').last(); + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + QScrollArea *scrollArea = new QScrollArea(ui->tabWidget); + scrollArea->layout()->addWidget(scriptEditor); + + ui->tabWidget->addTab(scrollArea, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_GSCFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::ImageSelected, this, [this](std::shared_ptr image, const QString aParentName) { + ImageWidget *mImageWidget = new ImageWidget(this); + mImageWidget->setAcceptDrops(false); + mImageWidget->SetImage(image); + mImageWidget->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = image->materialName; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(mImageWidget, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_Image.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::MenuSelected, this, [](std::shared_ptr menu, const QString aParentName) { + Q_UNUSED(menu); + }); + + connect(mTreeWidget, &XTreeWidget::DDSFileSelected, this, [this](std::shared_ptr ddsFile, const QString aParentName) { + DDSViewer *ddsViewer = new DDSViewer(this); + ddsViewer->setAcceptDrops(false); + ddsViewer->SetDDSFile(ddsFile); + ddsViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = ddsFile->fileStem + ".dds"; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(ddsViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_DDSFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::MaterialSelected, this, [this](std::shared_ptr material, const QString aParentName) { + MaterialViewer *matViewer = new MaterialViewer(this); + matViewer->setAcceptDrops(false); + matViewer->SetMaterial(material); + matViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = material->name; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(matViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_Material.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::DDSFileSelected, this, [this](std::shared_ptr ddsFile, const QString aParentName) { + DDSViewer *ddsViewer = new DDSViewer(this); + ddsViewer->setAcceptDrops(false); + ddsViewer->SetDDSFile(ddsFile); + ddsViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = ddsFile->fileStem + ".dds"; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(ddsViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_DDSFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::IWIFileSelected, this, [this](std::shared_ptr iwiFile, const QString aParentName) { + IWIViewer *iwiViewer = new IWIViewer(this); + iwiViewer->setAcceptDrops(false); + iwiViewer->SetIWIFile(iwiFile); + iwiViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = iwiFile->fileStem + ".iwi"; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(iwiViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_IWIFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::FastFileSelected, this, [this](std::shared_ptr aFastFile, const QString aParentName) { + FastFileViewer *fastFileViewer = new FastFileViewer(this); + fastFileViewer->setAcceptDrops(false); + fastFileViewer->SetFastFile(aFastFile); + fastFileViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = aFastFile->GetStem() + ".ff"; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(fastFileViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_FastFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::ZoneFileSelected, this, [this](std::shared_ptr aZoneFile, const QString aParentName) { + ZoneFileViewer *zoneFileViewer = new ZoneFileViewer(this); + zoneFileViewer->setAcceptDrops(false); + zoneFileViewer->SetZoneFile(aZoneFile); + zoneFileViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = aZoneFile->GetStem() + ".zone"; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + QWidget *containerWidget = new QWidget(); + QVBoxLayout *layout = new QVBoxLayout(containerWidget); + layout->addWidget(zoneFileViewer); + containerWidget->setLayout(layout); + + // Create a scroll area and set its properties + QScrollArea *scrollArea = new QScrollArea(ui->tabWidget); + scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + scrollArea->setWidgetResizable(true); // Important to allow resizing + scrollArea->setWidget(containerWidget); + + ui->tabWidget->addTab(scrollArea, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_ZoneFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::LocalStringSelected, this, [this](std::shared_ptr aZoneFile, const QString aParentName) { + LocalStringViewer *localStrViewer = new LocalStringViewer(this); + localStrViewer->setAcceptDrops(false); + localStrViewer->SetZoneFile(aZoneFile); + localStrViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = aZoneFile->GetStem() + ".str"; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(localStrViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_String.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::TechSetSelected, this, [this](std::shared_ptr aTechSet, const QString aParentName) { + TechSetViewer *techSetViewer = new TechSetViewer(this); + techSetViewer->setAcceptDrops(false); + techSetViewer->SetTechSet(aTechSet); + techSetViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = aTechSet->name; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(techSetViewer, aTechSet->name); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_TechSetFile.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::StrTableSelected, this, [this](std::shared_ptr aStrTable, const QString aParentName) { + StringTableViewer *strTableViewer = new StringTableViewer(this); + strTableViewer->setAcceptDrops(false); + strTableViewer->SetStringTable(aStrTable); + strTableViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = aStrTable->name; + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(strTableViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_StringTable.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::SoundSelected, this, [this](std::shared_ptr aSound, const QString aParentName) { + SoundViewer *soundViewer = new SoundViewer(this); + soundViewer->setAcceptDrops(false); + soundViewer->SetSound(aSound); + soundViewer->setProperty("PARENT_NAME", QVariant::fromValue(aParentName)); + + QString fileStem = aSound->path.split('/').last(); + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == fileStem) { + return; + } + } + + ui->tabWidget->addTab(soundViewer, fileStem); + ui->tabWidget->setTabIcon(ui->tabWidget->count() - 1, QIcon(":/icons/icons/Icon_Sound.png")); + ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); + }); + + connect(mTreeWidget, &XTreeWidget::ItemSelected, this, [this](const QString itemText) { + for (int i = 0; i < ui->tabWidget->count(); i++) { + if (ui->tabWidget->tabText(i) == itemText) { + ui->tabWidget->setCurrentIndex(i); + break; + } + } + }); + + connect(mTreeWidget, &XTreeWidget::ItemClosed, this, [this](const QString itemText) { + for (int i = 0; i < ui->tabWidget->count(); i++) { + const QString parentName = ui->tabWidget->widget(i)->property("PARENT_NAME").toString(); + if (parentName == itemText) { + ui->tabWidget->removeTab(i); + break; + } + } + }); + + // Connect Help > About dialog + connect(ui->actionAbout, &QAction::triggered, this, [this](bool checked) { + Q_UNUSED(checked); + + AboutDialog *aboutDialog = new AboutDialog(this); + aboutDialog->exec(); + + delete aboutDialog; + }); + + connect(ui->actionOpen_Fast_File, &QAction::triggered, this, + [this](bool checked) { + Q_UNUSED(checked); + OpenFastFile(); + }); + connect(ui->actionOpen_Zone_File, &QAction::triggered, this, + [this](bool checked) { + Q_UNUSED(checked); + OpenZoneFile(); + }); + + QDockWidget *treeDockWidget = new QDockWidget(this); + treeDockWidget->setWidget(mTreeWidget); + treeDockWidget->setWindowTitle("Tree Browser"); + addDockWidget(Qt::LeftDockWidgetArea, treeDockWidget); + + QDockWidget *logDockWidget = new QDockWidget(this); + logDockWidget->setWidget(mLogWidget); + logDockWidget->setWindowTitle("Logs"); + addDockWidget(Qt::RightDockWidgetArea, logDockWidget); + + ui->toolBar->addAction(ui->actionNew_Fast_File); + ui->toolBar->addAction(ui->actionNew_Zone_File); + ui->toolBar->addAction(ui->actionOpen_Fast_File); + ui->toolBar->addAction(ui->actionOpen_Zone_File); + ui->toolBar->addAction(ui->actionOpen_Folder); + ui->toolBar->addAction(ui->actionSave); + ui->toolBar->addSeparator(); + ui->toolBar->addAction(ui->actionCut); + ui->toolBar->addAction(ui->actionCopy); + ui->toolBar->addAction(ui->actionPaste); + ui->toolBar->addSeparator(); + + ui->toolBar->addSeparator(); + + ui->toolBar->addSeparator(); + ui->toolBar->addAction(ui->actionFind_2); + + Reset(); +} + +MainWindow::~MainWindow() { delete ui; } + +void MainWindow::Reset() { + // Clear data tree + // mTreeWidget->clear(); + + // Reset class vars + mTypeMap.clear(); + mTypeOrder.clear(); + mTagCount = 0; + mRecordCount = 0; + mRawFileMap.clear(); + mTreeMap.clear(); + mStrTableMap.clear(); +} + +/* + OpenFastFile() + + Opens a file dialog in the steam folder, + and opens the selected file. +*/ +bool MainWindow::OpenFastFile(const QString aFastFilePath) { + const QString fastFileStem = aFastFilePath.section("/", -1, -1).section('.', 0, 0); + if (mTreeWidget->HasFastFile(fastFileStem)) { + LogManager::instance().addError("Can't add duplicate file!"); + return false; + } + + std::shared_ptr fastFile = FastFile::Open(aFastFilePath); + fastFile->SetStem(fastFileStem); + mTreeWidget->AddFastFile(fastFile); + + // Open zone file after decompressing ff and writing + return true; +} + +/* + OpenFastFile() + + Opens a file dialog in the steam folder, + and opens the selected file. +*/ +bool MainWindow::OpenFastFile() { + const QString fastFileName = Utils::GetOpenFastFileName(); + if (!OpenFastFile(fastFileName)) { + qDebug() << "Failed to open Fast file!"; + return false; + } + return true; +} + +/* + OpenZoneFile() + + Opens a file dialog in the steam folder, + and opens the selected file. +*/ +bool MainWindow::OpenZoneFile(const QString aZoneFilePath, bool fromFF) { + Q_UNUSED(aZoneFilePath); + Q_UNUSED(fromFF); + + //ZoneFile zoneFile; + //if (!zoneFile.Load(aZoneFilePath)) { + // qDebug() << "Error: Failed to load zone file!"; + // return false; + //} + //mTreeWidget->AddZoneFile(std::make_shared(zoneFile)); + + return true; +} + +bool MainWindow::OpenZoneFile() { + const QString zoneFileName = Utils::GetOpenZoneFileName(); + if (!OpenZoneFile(zoneFileName)) { + qDebug() << "Failed to open Zone file!"; + return false; + } + return true; +} + +int MainWindow::LoadFile_D3DBSP(const QString aFilePath) { + QFile file(aFilePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Error: Unable to open file" << aFilePath; + return 1; // ERR_FILE_NOT_FOUND + } + + QDataStream stream(&file); + stream.setByteOrder(QDataStream::LittleEndian); + + // Read Magic Value + quint32 magicValue; + stream >> magicValue; + if (magicValue != 'PSBI') { + qDebug() << "Error: Not a valid D3DBSP file"; + return 2; // ERR_NOT_A_D3DBSP_FILE + } + + // Read BSP Version and Lump Count + stream >> mBSPVersion; + stream >> mDiskLumpCount; + + // Assign diskLumpOrderSize + mDiskLumpOrder.resize(mDiskLumpCount); + + // Read Lump Index Entries + quint32 lumpOffset = + sizeof(quint32) * 3 + sizeof(LumpIndexEntry) * mDiskLumpCount; + + for (quint32 i = 0; i < mDiskLumpCount; i++) { + LumpIndexEntry indexEntry; + stream >> indexEntry.type >> indexEntry.length; + + mDiskLumpOrder[i] = indexEntry.type; + + Lump &lump = mLumps[indexEntry.type]; + lump.size = indexEntry.length; + lump.content.resize(indexEntry.length); + lump.isEmpty = false; + + qDebug() << "Lump Type:" + << Utils::LumpTypeToString((LUMP_TYPE)indexEntry.type) + << "Lump Size:" << indexEntry.length; + + // Handle offsets and padding + qint64 currentPos = file.pos(); + file.seek(lumpOffset); + file.read(lump.content.data(), lump.size); + file.seek(currentPos); + lumpOffset += Utils::PadInt4(indexEntry.length); + } + + file.close(); + return 0; // Success +} + +struct Command { + quint32 size = 0; + bool compressed = false; +}; +quint32 DXT1 = 0x31545844; // 'DXT1' +quint32 DXT3 = 0x33545844; // 'DXT3' +quint32 DXT5 = 0x35545844; // 'DXT5' + +int MainWindow::LoadFile_IWI(const QString aFilePath) { + mTreeWidget->AddIWIFile(std::make_shared(aFilePath)); + + return 0; +} + +int MainWindow::LoadFile_DDSFiles(const QStringList aFilePaths) { + for (const QString &filePath : aFilePaths) { + if (!filePath.endsWith(".dds", Qt::CaseInsensitive)) { + qDebug() << "Error: Invalid filename " << filePath; + return -1; + } + mTreeWidget->AddDDSFile(std::make_shared(filePath)); + } + return 0; +} + +void MainWindow::HandleLogEntry(const QString &entry) { + QString logContents = mLogWidget->toPlainText() + "\n" + entry; + if (mLogWidget->toPlainText().isEmpty()) { + logContents = entry; + } + mLogWidget->setPlainText(logContents); +} + +void MainWindow::HandleStatusUpdate(const QString &message, int timeout) { + statusBar()->showMessage(message, timeout); + mProgressBar->setVisible(false); // Hide progress bar if just a message +} + +void MainWindow::HandleProgressUpdate(const QString &message, int progress, int max) { + mProgressBar->setMaximum(max); + mProgressBar->setValue(progress); + mProgressBar->setVisible(true); + + QString progressText = QString("%1 (%2/%3)").arg(message).arg(progress).arg(max); + statusBar()->showMessage(progressText); +} + +int MainWindow::LoadFile_DDS(const QString aFilePath) { + if (!aFilePath.endsWith(".dds", Qt::CaseInsensitive)) { + qDebug() << "Error: Invalid filename " << aFilePath; + return -1; + } + mTreeWidget->AddDDSFile(std::make_shared(aFilePath)); + return 0; +} + +int MainWindow::LoadFile_XSUB(const QString aFilePath) { + QFile file(aFilePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Error: Unable to open file" << aFilePath; + return 1; // ERR_FILE_NOT_FOUND + } + + QDataStream stream(&file); + stream.setByteOrder(QDataStream::LittleEndian); + + QByteArray magic(4, Qt::Uninitialized); + stream.readRawData(magic.data(), 4); + if (magic != "KAPI") { + qDebug() << "Wrong magic, invalid XSUB file!"; + return -1; + } + qDebug() << "Magic: " << magic; + + stream.skipRawData(5 * 4); + + quint32 fileSize; + stream >> fileSize; + qDebug() << "File Size: " << fileSize; + + return 0; // Success +} + +int MainWindow::LoadFile_IPAK(const QString aFilePath) { + QFile file(aFilePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Error: Unable to open file" << aFilePath; + return 1; // ERR_FILE_NOT_FOUND + } + + QDataStream stream(&file); + stream.setByteOrder(QDataStream::BigEndian); + + IPAKHeader header; + stream >> header; + + if (header.version == "50000") { + if (header.magic == "KAPI") { + stream.setByteOrder(QDataStream::LittleEndian); + } else if (header.magic == "IPAK") { + stream.setByteOrder(QDataStream::BigEndian); + } else { + qDebug() << "Invalid IPAK file!"; + return -1; + } + } else { + qDebug() << "Invalid IPAK file version!"; + return -1; + } + + qDebug() << "IPAK File " << "\n" + << "- Platform: " << header.platform << "\n" + << "- Magic: " << header.magic << "\n" + << "- Size: " << header.size << "\n" + << "- Version: " << header.version << "\n" + << "- Sections: " << header.sectionCount; + + QDir outputFolder = QDir(QDir::currentPath() + "/output"); + outputFolder.remove(QDir::currentPath() + "/output"); + outputFolder.mkdir(QDir::currentPath() + "/output"); + + QVector metas = QVector(); + + QVector entries = QVector(); + QVector sections = QVector(header.sectionCount); + for (uint i = 0; i < header.sectionCount; i++) { + IPAKSection currentSection; + stream >> currentSection; + sections << currentSection; + + qDebug() << " - IPAK Section " << i + 1 << "\n" + << " - Type: " << currentSection.type << " -> " << currentSection.typeInt << "\n" + << " - Offset: " << currentSection.offset << "\n" + << " - Item (IWI) Count: " << currentSection.itemCount << "\n" + << " - Size: " << currentSection.size; + + qint64 sectionPos = stream.device()->pos(); + stream.device()->seek(currentSection.offset); + + QString sectionType = currentSection.type; + if (sectionType == "Data") { + IPAKDataChunkHeader chunkHeader; + stream >> chunkHeader; + qDebug() << " - Chunk Header\n" + << " - Count: " << chunkHeader.count << "\n" + << " - Offset: " << chunkHeader.offset; + + for (uint j = 0; j < 31; j++) { + IPAKDataChunkCommand command; + stream >> command; + if (!command.size) { continue; } + chunkHeader.commands << command; + qDebug() << " - Command\n" + << " - Size: " << command.size << "\n" + << " - Compressed: " << command.compressed; + + } + for (uint j = 0; j < chunkHeader.count; j++) { + auto command = chunkHeader.commands[j]; + + qDebug() << "Reading from " << stream.device()->pos(); + QByteArray data = stream.device()->read(command.size); + qDebug() << " to " << stream.device()->pos(); + + QString outputFilePath = outputFolder.filePath(QString("%1.iwi").arg(j)); + if (command.compressed) { + //data = Compression::DecompressLZO(data); + } + QFile outputFile(outputFilePath); + if (!outputFile.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to extract IPAK file."; + } + qDebug() << " - File Name: " << outputFile.fileName(); + outputFile.write(data); + outputFile.close(); + } + + + qDebug() << stream.device()->pos(); + stream.skipRawData(sizeof(quint32) * (31 - chunkHeader.count)); + qDebug() << stream.device()->pos(); + } else if (sectionType == "Index") { + for (uint j = 0; j < currentSection.itemCount; j++) { + IPAKIndexEntry entry; + stream >> entry; + + if (entry.size == 0) { continue; } + + entries << entry; + + quint64 entryPos = stream.device()->pos(); + qDebug() << " - Index Entry " << j + 1 << "\n" + << " - Name Hash: " << entry.nameHash << "\n" + << " - Data Hash: " << entry.dataHash << "\n" + << " - Offset: " << entry.offset << "\n" + << " - Size: " << entry.size; + + stream.device()->seek(entry.offset); + + QByteArray sectionData(entry.size, Qt::Uninitialized); + stream.readRawData(sectionData.data(), entry.size); + + const QString entryKey = QString::number(entry.nameHash); + QFile outputFile(outputFolder.filePath(QString("%1.dds").arg(entryKey))); + if (!outputFile.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to extract IPAK file."; + } + qDebug() << " - File Name: " << outputFile.fileName(); + outputFile.write(sectionData); + outputFile.close(); + + stream.device()->seek(entryPos); + } + } + stream.device()->seek(sectionPos); + qDebug() << stream.device()->pos(); + } + + return 0; // Success +} + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) { + const QMimeData *mimeData = event->mimeData(); + bool goodDrag = true; + if (mimeData->hasUrls()) { + foreach (const QUrl url, mimeData->urls()) { + if (!url.toString().contains(".ff") && + !url.toString().contains(".zone") && + !url.toString().contains(".ipak") && + !url.toString().contains(".d3dbsp") && + !url.toString().contains(".lzoin") && + !url.toString().contains(".xsub") && + !url.toString().contains(".iwi") && + !url.toString().contains(".dds")) { + goodDrag = false; + } + } + } else { + goodDrag = false; + } + if (goodDrag) { + event->acceptProposedAction(); + } +} + +void MainWindow::dragMoveEvent(QDragMoveEvent *event) { + Q_UNUSED(event); +} + +void MainWindow::dragLeaveEvent(QDragLeaveEvent *event) { + Q_UNUSED(event); +} + +void MainWindow::dropEvent(QDropEvent *event) { + const QMimeData *mimeData = event->mimeData(); + if (mimeData->hasUrls()) { + QStringList ddsPaths = QStringList(); + foreach (const QUrl url, mimeData->urls()) { + const QString urlStr = url.toLocalFile(); + if (urlStr.contains(".zone")) { + qDebug() << "OpenZoneFile Returned: " << OpenZoneFile(urlStr); + } else if (urlStr.contains(".ff")) { + qDebug() << "OpenFastFile Returned: " << OpenFastFile(urlStr); + } else if (urlStr.contains(".ipak")) { + qDebug() << "LoadFile_IPAK Returned: " << LoadFile_IPAK(urlStr); + } else if (urlStr.contains(".xsub")) { + qDebug() << "LoadFile_XSUB Returned: " << LoadFile_XSUB(urlStr); + } else if (urlStr.contains(".iwi")) { + qDebug() << "LoadFile_IWI Returned: " << LoadFile_IWI(urlStr); + } else if (urlStr.contains(".dds")) { + if (mimeData->urls().size() == 1) { + qDebug() << "LoadFile_DDS Returned: " << LoadFile_DDS(urlStr); + } else { + ddsPaths << urlStr; + } + } else if (urlStr.contains(".d3dbsp")) { + LoadFile_D3DBSP(urlStr); + } else if (urlStr.contains(".lzoin")) { + QFile lzoFile(urlStr); + if (!lzoFile.open(QIODevice::ReadOnly)) { + qDebug() << "LZO: Failed to read file!"; + continue; + } + QByteArray data;// = Compression::DecompressLZO(lzoFile.readAll()); + lzoFile.close(); + + if (data.isEmpty()) { + qDebug() << "LZO: Decompression gave empty result!"; + continue; + } + + QFile outputFile(url.toLocalFile().replace("lzoin", "lzoout")); + if (!outputFile.open(QIODevice::WriteOnly)) { + qDebug() << "LZO: Failed to write file!"; + continue; + } + outputFile.write(data); + outputFile.close(); + } else { + const QString ext = urlStr.split('.').last(); + ui->statusBar->showMessage( + QString("Can't display dropped file! .%1").arg(ext)); + } + } + if (ddsPaths.size() > 1) { + qDebug() << "LoadFile_DDSFiles Returned: " << LoadFile_DDSFiles(ddsPaths); + } + } else { + ui->statusBar->showMessage("Can't display dropped data!"); + } +} diff --git a/app/mainwindow.h b/app/mainwindow.h new file mode 100644 index 0000000..daa90dc --- /dev/null +++ b/app/mainwindow.h @@ -0,0 +1,79 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include "d3dbsp_structs.h" +#include "asset_structs.h" +#include "xtreewidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + void Reset(); + +private slots: + bool OpenFastFile(const QString aFastFilePath); + bool OpenFastFile(); + + bool OpenZoneFile(const QString aZoneFilePath, bool fromFF = false); + bool OpenZoneFile(); + + int LoadFile_D3DBSP(const QString aFilePath); + int LoadFile_IPAK(const QString aFilePath); + int LoadFile_XSUB(const QString aFilePath); + int LoadFile_IWI(const QString aFilePath); + int LoadFile_DDS(const QString aFilePath); + int LoadFile_DDSFiles(const QStringList aFilePaths); + + void HandleLogEntry(const QString &entry); + void HandleStatusUpdate(const QString &message, int timeout); + void HandleProgressUpdate(const QString &message, int progress, int max); + +protected: + void dragEnterEvent(QDragEnterEvent *event) override; + void dragMoveEvent(QDragMoveEvent *event) override; + void dragLeaveEvent(QDragLeaveEvent *event) override; + void dropEvent(QDropEvent *event) override; + +private: + Ui::MainWindow *ui; + QMap mTypeMap; + QStringList mTypeOrder; + quint32 mTagCount; + quint32 mRecordCount; + QMap mRawFileMap; + QMap mImageMap; + QMap mTreeMap; + QMap>> mStrTableMap; + XTreeWidget *mTreeWidget; + QPlainTextEdit *mLogWidget; + QProgressBar *mProgressBar; + + quint32 mBSPVersion; + quint32 mDiskLumpCount; + QVector mDiskLumpOrder; + QMap mLumps; +}; +#endif // MAINWINDOW_H diff --git a/app/mainwindow.ui b/app/mainwindow.ui new file mode 100644 index 0000000..1e1b164 --- /dev/null +++ b/app/mainwindow.ui @@ -0,0 +1,361 @@ + + + MainWindow + + + + 0 + 0 + 1579 + 857 + + + + + 550 + 300 + + + + XPlor + + + QMainWindow { + +} + + + + + + + -1 + + + true + + + true + + + + + + + + + 0 + 0 + 1579 + 21 + + + + + File + + + + Recent... + + + + + Import... + + + + + + + + + + + + + + + + + + + Edit + + + + Undo History... + + + + + Redo History... + + + + + + + + + + + + + + + + + + + + + + + + Help + + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + :/icons/icons/Icon_NewFile.png:/icons/icons/Icon_NewFile.png + + + New + + + + + + :/icons/icons/Icon_NewFile.png:/icons/icons/Icon_NewFile.png + + + New Fast File + + + + + + :/icons/icons/Icon_NewFile.png:/icons/icons/Icon_NewFile.png + + + New Zone File + + + + + + :/icons/icons/Icon_OpenFile.png:/icons/icons/Icon_OpenFile.png + + + Open Fast File + + + + + + :/icons/icons/Icon_OpenFile.png:/icons/icons/Icon_OpenFile.png + + + Open Zone File + + + + + + :/icons/icons/Icon_OpenFile.png:/icons/icons/Icon_OpenFile.png + + + Open Folder + + + + + + :/icons/icons/Icon_Save.png:/icons/icons/Icon_Save.png + + + Save + + + + + Save As + + + + + e + + + + + File + + + + + Folder + + + + + New File + + + + + New Fast File + + + + + New Zone File + + + + + From Clipboard + + + + + Material + + + + + Sound + + + + + Undo + + + + + Redo + + + + + + :/icons/icons/Icon_Cut.png:/icons/icons/Icon_Cut.png + + + Cut + + + + + + :/icons/icons/Icon_Copy.png:/icons/icons/Icon_Copy.png + + + Copy + + + + + + :/icons/icons/Icon_Paste.png:/icons/icons/Icon_Paste.png + + + Paste + + + + + Rename + + + + + Edit Value + + + + + Edit as Hex + + + + + Delete + + + + + d + + + + + d + + + + + Clear Undo History + + + + + Find + + + + + About + + + + + Change Icons + + + + + Check for Updates + + + + + + :/icons/icons/Icon_Find.png:/icons/icons/Icon_Find.png + + + Find + + + + + Preferences... + + + + + + + + diff --git a/app/materialviewer.cpp b/app/materialviewer.cpp new file mode 100644 index 0000000..1a97977 --- /dev/null +++ b/app/materialviewer.cpp @@ -0,0 +1,42 @@ +#include "materialviewer.h" +#include "ui_materialviewer.h" + +MaterialViewer::MaterialViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::MaterialViewer) { + ui->setupUi(this); +} + +MaterialViewer::~MaterialViewer() { + delete ui; +} + +QString ToHexStr(quint32 in) { + return QString("%1").arg(in, 8, 16, QChar('0')).toUpper(); +} + +void MaterialViewer::SetMaterial(std::shared_ptr aMaterial) { + ui->lineEdit_NamePtr->setText(ToHexStr(aMaterial->namePtr)); + ui->lineEdit_Name->setText(aMaterial->name); + ui->lineEdit_RefPtr->setText(ToHexStr(aMaterial->refNamePtr)); + ui->lineEdit_RefName->setText(aMaterial->refName); + ui->lineEdit_Unknowns->setText(ToHexStr(aMaterial->unknownA[0]) + + ToHexStr(aMaterial->unknownA[1]) + + ToHexStr(aMaterial->unknownA[2]) + + ToHexStr(aMaterial->unknownA[3]) + + ToHexStr(aMaterial->unknownA[4]) + + ToHexStr(aMaterial->unknownA[5]) + + ToHexStr(aMaterial->unknownA[6]) + + ToHexStr(aMaterial->unknownA[7]) + + ToHexStr(aMaterial->unknownA[8]) + + ToHexStr(aMaterial->unknownA[9]) + + ToHexStr(aMaterial->unknownA[10]) + + ToHexStr(aMaterial->unknownA[11])); + ui->lineEdit_StateA->setText(ToHexStr(aMaterial->stateBits[0])); + ui->lineEdit_StateA->setText(ToHexStr(aMaterial->stateBits[1])); + ui->spinBox_TextureCount->setValue(aMaterial->textureCount); + ui->spinBox_ConstCount->setValue(aMaterial->constCount); + ui->lineEdit_TechSetPtr->setText(ToHexStr(aMaterial->techSetPtr)); + ui->lineEdit_TexturePtr->setText(ToHexStr(aMaterial->texturePtr)); + ui->lineEdit_ConstantPtr->setText(ToHexStr(aMaterial->constPtr)); +} diff --git a/app/materialviewer.h b/app/materialviewer.h new file mode 100644 index 0000000..7b24deb --- /dev/null +++ b/app/materialviewer.h @@ -0,0 +1,27 @@ +#ifndef MATERIALVIEWER_H +#define MATERIALVIEWER_H + +#include "asset_structs.h" + +#include +#include + +namespace Ui { +class MaterialViewer; +} + +class MaterialViewer : public QWidget +{ + Q_OBJECT + +public: + explicit MaterialViewer(QWidget *parent = nullptr); + ~MaterialViewer(); + + void SetMaterial(std::shared_ptr aMaterial); + +private: + Ui::MaterialViewer *ui; +}; + +#endif // MATERIALVIEWER_H diff --git a/app/materialviewer.ui b/app/materialviewer.ui new file mode 100644 index 0000000..f7aa9d8 --- /dev/null +++ b/app/materialviewer.ui @@ -0,0 +1,236 @@ + + + MaterialViewer + + + + 0 + 0 + 1001 + 650 + + + + Form + + + + + + + Roboto + 16 + true + + + + Material 0 + + + + + + + + + + + + 325 + 398 + + + + + 325 + 16777215 + + + + + Roboto + 9 + + + + Header + + + + + + Name Ptr: + + + + + + + + + + Name: + + + + + + + Ref Ptr: + + + + + + + Ref Name: + + + + + + + Unknowns: + + + + + + + State A: + + + + + + + State B: + + + + + + + Texture Count: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Constant Count: + + + + + + + Tech Set Ptr: + + + + + + + Texture Ptr: + + + + + + + Constant Ptr: + + + + + + + + + + + + + + + + + + + 400 + 400 + + + + + Roboto + 9 + + + + Data + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 143 + + + + + + + + + diff --git a/app/modelviewer.cpp b/app/modelviewer.cpp new file mode 100644 index 0000000..a461223 --- /dev/null +++ b/app/modelviewer.cpp @@ -0,0 +1,14 @@ +#include "modelviewer.h" +#include "ui_modelviewer.h" + +ModelViewer::ModelViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::ModelViewer) +{ + ui->setupUi(this); +} + +ModelViewer::~ModelViewer() +{ + delete ui; +} diff --git a/app/modelviewer.h b/app/modelviewer.h new file mode 100644 index 0000000..1fa493f --- /dev/null +++ b/app/modelviewer.h @@ -0,0 +1,22 @@ +#ifndef MODELVIEWER_H +#define MODELVIEWER_H + +#include + +namespace Ui { +class ModelViewer; +} + +class ModelViewer : public QWidget +{ + Q_OBJECT + +public: + explicit ModelViewer(QWidget *parent = nullptr); + ~ModelViewer(); + +private: + Ui::ModelViewer *ui; +}; + +#endif // MODELVIEWER_H diff --git a/app/modelviewer.ui b/app/modelviewer.ui new file mode 100644 index 0000000..d321671 --- /dev/null +++ b/app/modelviewer.ui @@ -0,0 +1,624 @@ + + + ModelViewer + + + + 0 + 0 + 1001 + 897 + + + + Form + + + + + + Properties + + + + + + + + Name Pointer: + + + + + + + 1000000000 + + + + + + + Model Name: + + + + + + + + + + Tag Count: + + + + + + + tags + + + 1000000000 + + + + + + + Root Tag Count: + + + + + + + root tags + + + 1000000000 + + + + + + + Surface Count: + + + + + + + surfaces + + + 1000000000 + + + + + + + Unknown A: + + + + + + + 1000000000 + + + + + + + Bone Name Pointer: + + + + + + + 1000000000 + + + + + + + Parent List Pointer: + + + + + + + 1000000000 + + + + + + + Quats Pointer: + + + + + + + 1000000000 + + + + + + + Transformation Pointer: + + + + + + + 1000000000 + + + + + + + Classification Pointer: + + + + + + + 1000000000 + + + + + + + Base Material Pointer: + + + + + + + 1000000000 + + + + + + + Surfaces Pointer; + + + + + + + 1000000000 + + + + + + + Material Handlers Pointer: + + + + + + + 1000000000 + + + + + + + Coll Surf Pointer: + + + + + + + 1000000000 + + + + + + + Coll Surface Count: + + + + + + + 1000000000 + + + + + + + Contents: + + + + + + + 1000000000 + + + + + + + Bone Info Pointer: + + + + + + + 1000000000 + + + + + + + Radius: + + + + + + + + + + Min X: + + + + + + + + + + Min Y: + + + + + + + + + + Min Z: + + + + + + + + + + Max X: + + + + + + + + + + Max Y: + + + + + + + + + + Max Z: + + + + + + + + + + Lod Count: + + + + + + + 1000000000 + + + + + + + Coll Lod: + + + + + + + 1000000000 + + + + + + + Stream Info Pointer: + + + + + + + 1000000000 + + + + + + + Memory Usage: + + + + + + + 1000000000 + + + + + + + Flags: + + + + + + + 1000000000 + + + + + + + Phys Preset Pointer: + + + + + + + 1000000000 + + + + + + + Phys Geometry Pointer: + + + + + + + 1000000000 + + + + + + + + + + + Lod Info + + + + + + Lod Info Index: + + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + Distance: + + + + + + + + + + Surface Count: + + + + + + + 1000000000 + + + + + + + Surface Index: + + + + + + + 1000000000 + + + + + + + Part Bit 1: + + + + + + + 1000000000 + + + + + + + Part Bit 2: + + + + + + + 1000000000 + + + + + + + Part Bit 3: + + + + + + + 1000000000 + + + + + + + Part Bit 4: + + + + + + + 1000000000 + + + + + + + Part Bit 5: + + + + + + + 1000000000 + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Qt::Orientation::Vertical + + + + + + + 3D Window + + + + + + + + diff --git a/app/preferenceeditor.cpp b/app/preferenceeditor.cpp new file mode 100644 index 0000000..44b0ae1 --- /dev/null +++ b/app/preferenceeditor.cpp @@ -0,0 +1,35 @@ +#include "preferenceeditor.h" +#include "ui_preferenceeditor.h" + +PreferenceEditor::PreferenceEditor(QWidget *parent) + : QDialog(parent) + , ui(new Ui::PreferenceEditor) +{ + ui->setupUi(this); + + ui->frame_View->show(); + ui->frame_TreeWidget->hide(); + ui->frame_FileEditors->hide(); + + connect(ui->listWidget_Categories, &QListWidget::itemSelectionChanged, this, [this]() { + const QString itemText = ui->listWidget_Categories->selectedItems().first()->text(); + if (itemText == "View") { + ui->frame_View->show(); + ui->frame_TreeWidget->hide(); + ui->frame_FileEditors->hide(); + } else if (itemText == "Tree Widget") { + ui->frame_View->hide(); + ui->frame_TreeWidget->show(); + ui->frame_FileEditors->hide(); + } else if (itemText == "File Editors") { + ui->frame_View->hide(); + ui->frame_TreeWidget->hide(); + ui->frame_FileEditors->show(); + } + }); +} + +PreferenceEditor::~PreferenceEditor() +{ + delete ui; +} diff --git a/app/preferenceeditor.h b/app/preferenceeditor.h new file mode 100644 index 0000000..60ed8c0 --- /dev/null +++ b/app/preferenceeditor.h @@ -0,0 +1,22 @@ +#ifndef PREFERENCEEDITOR_H +#define PREFERENCEEDITOR_H + +#include + +namespace Ui { +class PreferenceEditor; +} + +class PreferenceEditor : public QDialog +{ + Q_OBJECT + +public: + explicit PreferenceEditor(QWidget *parent = nullptr); + ~PreferenceEditor(); + +private: + Ui::PreferenceEditor *ui; +}; + +#endif // PREFERENCEEDITOR_H diff --git a/app/preferenceeditor.ui b/app/preferenceeditor.ui new file mode 100644 index 0000000..ab80157 --- /dev/null +++ b/app/preferenceeditor.ui @@ -0,0 +1,528 @@ + + + PreferenceEditor + + + + 0 + 0 + 1118 + 861 + + + + + 703 + 512 + + + + Dialog + + + + + + + + + + false + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + Roboto + 10 + + + + Filter + + + + + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + Roboto + 10 + + + + 0 + + + + View + + + + :/icons/icons/Icon_Views.png:/icons/icons/Icon_Views.png + + + + + Tree Widget + + + + :/icons/icons/Icon_Tree.png:/icons/icons/Icon_Tree.png + + + + + File Editors + + + + :/icons/icons/Icon_Editor.png:/icons/icons/Icon_Editor.png + + + + + + + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + + + 30 + 30 + + + + + 30 + 30 + + + + + + + :/icons/icons/Icon_Views.png + + + true + + + + + + + + Roboto + 12 + true + + + + View + + + + + + + + + + Roboto + 10 + + + + 0 + + + + Font && Colors + + + + + + Font + + + + + + Family: + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + Size: + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + Zoom: + + + + + + + % + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 588 + + + + + + + + + + + + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + + + 30 + 30 + + + + + 30 + 30 + + + + + + + :/icons/icons/Icon_Tree.png + + + true + + + + + + + + Roboto + 12 + true + + + + Tree Widget + + + + + + + + + + Roboto + 10 + + + + 0 + + + + Tab 1 + + + + + Tab 2 + + + + + + + + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + + + 30 + 30 + + + + + 30 + 30 + + + + + + + :/icons/icons/Icon_Editor.png + + + true + + + + + + + + Roboto + 12 + true + + + + File Editors + + + + + + + + + + Roboto + 10 + + + + 7 + + + + Fast File + + + + + Zone File + + + + + Images + + + + + Local Strings + + + + + String Table + + + + + Sounds + + + + + Tech Set + + + + + Model + + + + + Page + + + + + + + + + + + + + + + + + + + + + + + + + + + + Roboto + 10 + + + + Qt::Orientation::Horizontal + + + QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + + + + + + + + + buttonBox + accepted() + PreferenceEditor + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PreferenceEditor + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/app/soundviewer.cpp b/app/soundviewer.cpp new file mode 100644 index 0000000..9007e9f --- /dev/null +++ b/app/soundviewer.cpp @@ -0,0 +1,80 @@ +#include "soundviewer.h" +#include "ui_soundviewer.h" + +SoundViewer::SoundViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::SoundViewer) + , player(new QMediaPlayer()) + , buffer(new QBuffer()) +{ + ui->setupUi(this); + + connect(ui->pushButton_Play, &QPushButton::clicked, player, &QMediaPlayer::play); + connect(ui->pushButton_Pause, &QPushButton::clicked, player, &QMediaPlayer::pause); + connect(ui->pushButton_Stop, &QPushButton::clicked, this, [this]() { + if (player->isPlaying()) { + player->stop(); + } + }); + connect(ui->pushButton_SkipForward, &QPushButton::clicked, this, [this]() { + player->setPosition(player->position() + 30); + }); + connect(ui->pushButton_SkipBack, &QPushButton::clicked, this, [this]() { + player->setPosition(player->position() - 30); + }); + connect(player, &QMediaPlayer::positionChanged, player, [this](qint64 position) { + ui->horizontalSlider->setSliderPosition(position); + ui->label_Time->setText(QString("%1:%2:%3") + .arg(position / 60000) + .arg((position % 60000) / 1000) + .arg(position % 1000)); + }); + connect(player, &QMediaPlayer::durationChanged, player, [this](qint64 duration) { + ui->horizontalSlider->setMaximum(duration); + ui->label_TimeMax->setText(QString("%1:%2:%3") + .arg(duration / 60000) + .arg((duration % 60000) / 1000) + .arg(duration % 1000)); + }); + connect(ui->horizontalSlider, &QSlider::sliderMoved, this, [this](int position) { + player->setPosition(position); + }); + + for (auto outputDevice : QMediaDevices::audioOutputs()) { + ui->comboBox_Output->addItem(outputDevice.description()); + } + connect(ui->comboBox_Output, &QComboBox::currentIndexChanged, this, [this](int index) { + auto outputDevice = QMediaDevices::audioOutputs()[index]; + QAudioOutput *audioOutput = new QAudioOutput(outputDevice); + player->setAudioOutput(audioOutput); + }); + + auto outputDevice = QMediaDevices::defaultAudioOutput(); + QAudioOutput *audioOutput = new QAudioOutput(outputDevice); + player->setAudioOutput(audioOutput); +} + +SoundViewer::~SoundViewer() +{ + delete buffer; + delete player; + delete ui; +} + +void SoundViewer::SetSound(std::shared_ptr aSound) +{ + buffer->setData(aSound->data); + if (!buffer->open(QIODevice::ReadOnly)) { + qWarning() << "Failed to open QBuffer."; + return; + } + + ui->groupBox->setTitle(aSound->path); + player->setSourceDevice(buffer); +} + +void SoundViewer::SetOutput(QAudioOutput *aOutput) { + if (!aOutput) { return; } + + player->setAudioOutput(aOutput); +} diff --git a/app/soundviewer.h b/app/soundviewer.h new file mode 100644 index 0000000..825c28c --- /dev/null +++ b/app/soundviewer.h @@ -0,0 +1,34 @@ +#ifndef SOUNDVIEWER_H +#define SOUNDVIEWER_H + +#include "asset_structs.h" + +#include +#include +#include +#include +#include +#include + +namespace Ui { +class SoundViewer; +} + +class SoundViewer : public QWidget +{ + Q_OBJECT + +public: + explicit SoundViewer(QWidget *parent = nullptr); + ~SoundViewer(); + + void SetSound(std::shared_ptr aSound); + + void SetOutput(QAudioOutput *aOutput); +private: + Ui::SoundViewer *ui; + QMediaPlayer *player; + QBuffer *buffer; +}; + +#endif // SOUNDVIEWER_H diff --git a/app/soundviewer.ui b/app/soundviewer.ui new file mode 100644 index 0000000..e6b290a --- /dev/null +++ b/app/soundviewer.ui @@ -0,0 +1,2573 @@ + + + SoundViewer + + + + 0 + 0 + 294 + 198 + + + + Form + + + + + + + 0 + 160 + + + + + 16777215 + 131 + + + + Player + + + + + + + + Output Device: + + + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 40 + 40 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + + + + + + :/icons/icons/Icon_SkipBack.png:/icons/icons/Icon_SkipBack.png + + + + 40 + 40 + + + + + + + + + 40 + 40 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + + + + + + :/icons/icons/Icon_Stop.png:/icons/icons/Icon_Stop.png + + + + 40 + 40 + + + + + + + + + 50 + 50 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + + + + + + :/icons/icons/Icon_Play.png:/icons/icons/Icon_Play.png + + + + 50 + 50 + + + + + + + + + 40 + 40 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + + + + + + :/icons/icons/Icon_Pause.png:/icons/icons/Icon_Pause.png + + + + 40 + 40 + + + + + + + + + 40 + 40 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 247 + 247 + 247 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 120 + 120 + 120 + + + + + + + 160 + 160 + 160 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + 120 + 120 + 120 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 240 + 240 + 240 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + 120 + 120 + 120 + + + + + + + 255 + 255 + 255 + + + + + + + + + + + + :/icons/icons/Icon_SkipForward.png:/icons/icons/Icon_SkipForward.png + + + + 40 + 40 + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 00:00:00 + + + + + + + Qt::Orientation::Horizontal + + + + + + + 00:00:00 + + + + + + + + + + + + + + + diff --git a/app/stringtableviewer.cpp b/app/stringtableviewer.cpp new file mode 100644 index 0000000..b71b8e5 --- /dev/null +++ b/app/stringtableviewer.cpp @@ -0,0 +1,36 @@ +#include "stringtableviewer.h" +#include "ui_stringtableviewer.h" + +StringTableViewer::StringTableViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::StringTableViewer) +{ + ui->setupUi(this); +} + +StringTableViewer::~StringTableViewer() +{ + delete ui; +} + +void StringTableViewer::SetStringTable(std::shared_ptr aStringTable) { + ui->tableWidget_Strings->clear(); + + ui->tableWidget_Strings->setRowCount(aStringTable->rowCount); + ui->tableWidget_Strings->setColumnCount(aStringTable->columnCount); + + int currentIndex = 0; + for (const QString &key : aStringTable->content.keys()) { + const QString value = aStringTable->content[key]; + + QTableWidgetItem *tableKeyItem = new QTableWidgetItem(); + tableKeyItem->setText(key); + ui->tableWidget_Strings->setItem(currentIndex, 0, tableKeyItem); + + QTableWidgetItem *tableValItem = new QTableWidgetItem(); + tableValItem->setText(value); + ui->tableWidget_Strings->setItem(currentIndex, 1, tableValItem); + + currentIndex++; + } +} diff --git a/app/stringtableviewer.h b/app/stringtableviewer.h new file mode 100644 index 0000000..29dc08a --- /dev/null +++ b/app/stringtableviewer.h @@ -0,0 +1,25 @@ +#ifndef STRINGTABLEVIEWER_H +#define STRINGTABLEVIEWER_H + +#include "asset_structs.h" +#include + +namespace Ui { +class StringTableViewer; +} + +class StringTableViewer : public QWidget +{ + Q_OBJECT + +public: + explicit StringTableViewer(QWidget *parent = nullptr); + ~StringTableViewer(); + + void SetStringTable(std::shared_ptr aStringTable); + +private: + Ui::StringTableViewer *ui; +}; + +#endif // STRINGTABLEVIEWER_H diff --git a/app/stringtableviewer.ui b/app/stringtableviewer.ui new file mode 100644 index 0000000..55ce6e0 --- /dev/null +++ b/app/stringtableviewer.ui @@ -0,0 +1,24 @@ + + + StringTableViewer + + + + 0 + 0 + 525 + 752 + + + + Form + + + + + + + + + + diff --git a/app/techsetviewer.cpp b/app/techsetviewer.cpp new file mode 100644 index 0000000..81548b3 --- /dev/null +++ b/app/techsetviewer.cpp @@ -0,0 +1,25 @@ +#include "techsetviewer.h" +#include "ui_techsetviewer.h" + +TechSetViewer::TechSetViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::TechSetViewer) +{ + ui->setupUi(this); +} + +TechSetViewer::~TechSetViewer() +{ + delete ui; +} + +void TechSetViewer::SetTechSet(std::shared_ptr aTechSet) { + ui->listWidget_Ptrs->clear(); + ui->label_Title->setText(aTechSet->name); + + int ptrIndex = 1; + for (auto ptr : aTechSet->pointers) { + ui->listWidget_Ptrs->addItem(QString("Pointer %1: %2").arg(ptrIndex).arg(ptr)); + ptrIndex++; + } +} diff --git a/app/techsetviewer.h b/app/techsetviewer.h new file mode 100644 index 0000000..20182cb --- /dev/null +++ b/app/techsetviewer.h @@ -0,0 +1,25 @@ +#ifndef TECHSETVIEWER_H +#define TECHSETVIEWER_H + +#include "asset_structs.h" +#include + +namespace Ui { +class TechSetViewer; +} + +class TechSetViewer : public QWidget +{ + Q_OBJECT + +public: + explicit TechSetViewer(QWidget *parent = nullptr); + ~TechSetViewer(); + + void SetTechSet(std::shared_ptr aTechSet); + +private: + Ui::TechSetViewer *ui; +}; + +#endif // TECHSETVIEWER_H diff --git a/app/techsetviewer.ui b/app/techsetviewer.ui new file mode 100644 index 0000000..fadd6d2 --- /dev/null +++ b/app/techsetviewer.ui @@ -0,0 +1,77 @@ + + + TechSetViewer + + + + 0 + 0 + 961 + 756 + + + + Form + + + + + + + Roboto + 16 + true + + + + Technique Set 0 + + + + + + + + + Unknown Pointers: + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 363 + + + + + + + + + diff --git a/app/xtreewidget.cpp b/app/xtreewidget.cpp new file mode 100644 index 0000000..043f5e4 --- /dev/null +++ b/app/xtreewidget.cpp @@ -0,0 +1,800 @@ +#include "xtreewidget.h" +#include "qheaderview.h" +#include "qmenu.h" +#include "logmanager.h" + +XTreeWidget::XTreeWidget(QWidget *parent) + : QTreeWidget(parent) { + mFastFiles = QMap>(); + mZoneFiles = QMap>(); + mDDSFiles = QMap>(); + mIWIFiles = QMap>(); + + setContextMenuPolicy(Qt::CustomContextMenu); + setSelectionMode(QTreeWidget::SingleSelection); + setColumnCount(3); + header()->hide(); + setMinimumWidth(350); + setSortingEnabled(true); + + header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + + // Set the last two columns to a fixed width + //header()->setSectionResizeMode(1, QHeaderView::Fixed); + //header()->setSectionResizeMode(2, QHeaderView::Fixed); + + // Adjust the fixed widths to suit your icon size (e.g., 32 pixels) + //header()->resizeSection(0, 275); + //header()->resizeSection(1, 32); + //header()->resizeSection(2, 32); + + connect(this, &XTreeWidget::itemSelectionChanged, this, &XTreeWidget::ItemSelectionChanged); + connect(this, &XTreeWidget::customContextMenuRequested, this, &XTreeWidget::PrepareContextMenu); +} + +XTreeWidget::~XTreeWidget() { + +} + +void XTreeWidget::AddFastFile(std::shared_ptr aFastFile) { + XTreeWidgetItem *fastFileItem = new XTreeWidgetItem(this); + fastFileItem->setText(0, aFastFile->GetStem() + ".ff"); + fastFileItem->setIcon(0, QIcon(":/icons/icons/Icon_FastFile.png")); + if (aFastFile->GetPlatform() == "PC") { + fastFileItem->setIcon(1, QIcon(":/icons/icons/Icon_PC.png")); + } else if (aFastFile->GetPlatform() == "360") { + fastFileItem->setIcon(1, QIcon(":/icons/icons/Icon_Xbox.png")); + } else if (aFastFile->GetPlatform() == "Wii") { + fastFileItem->setIcon(1, QIcon(":/icons/icons/Icon_Wii.png")); + } else if (aFastFile->GetPlatform() == "WiiU") { + fastFileItem->setIcon(1, QIcon(":/icons/icons/Icon_WiiU.png")); + } + if (aFastFile->GetGame() == "COD2") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD2.png")); + } if (aFastFile->GetGame() == "COD4") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD4.png")); + } else if (aFastFile->GetGame() == "COD5") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD5.png")); + } else if (aFastFile->GetGame() == "COD6") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD6.png")); + } else if (aFastFile->GetGame() == "COD7") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD7.png")); + } else if (aFastFile->GetGame() == "COD8") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD8.png")); + } else if (aFastFile->GetGame() == "COD9") { + fastFileItem->setIcon(2, QIcon(":/icons/icons/Icon_COD9.png")); + } + + AddZoneFile(aFastFile->GetZoneFile(), fastFileItem); + + mFastFiles[aFastFile->GetStem().section(".", 0, 0)] = aFastFile; + + resizeColumnToContents(1); + setSortingEnabled(true); + sortByColumn(0, Qt::AscendingOrder); +} + +void XTreeWidget::AddZoneFile(std::shared_ptr aZoneFile, XTreeWidgetItem *aParentItem) { + XTreeWidgetItem *zoneItem; + if (aParentItem != nullptr) { + zoneItem = new XTreeWidgetItem(aParentItem); + } else { + zoneItem = new XTreeWidgetItem(this); + } + zoneItem->setIcon(0, QIcon(":/icons/icons/Icon_ZoneFile.png")); + zoneItem->setText(0, aZoneFile->GetStem() + ".zone"); + + auto assetMap = aZoneFile->GetAssetMap(); + + if (!assetMap.localStrings.isEmpty()) { + XTreeWidgetItem *localStrRoot = new XTreeWidgetItem(zoneItem); + localStrRoot->setText(0, "String Files"); + localStrRoot->setIcon(0, QIcon(":/icons/icons/Icon_StringFile.png")); + + XTreeWidgetItem *localStrItem = new XTreeWidgetItem(localStrRoot); + localStrItem->setText(0, aZoneFile->GetStem().section('.', 0, 0) + ".str"); + localStrItem->setIcon(0, QIcon(":/icons/icons/Icon_StringFile.png")); + } + + if (!assetMap.techSets.isEmpty()) { + XTreeWidgetItem *techSetRoot = new XTreeWidgetItem(zoneItem); + techSetRoot->setText(0, "Tech Sets"); + techSetRoot->setIcon(0, QIcon(":/icons/icons/Icon_TechSetFile.png")); + + for (TechSet techSet : assetMap.techSets) { + XTreeWidgetItem *techSetItem = new XTreeWidgetItem(techSetRoot); + techSetItem->setText(0, techSet.name); + techSetItem->setIcon(0, QIcon(":/icons/icons/Icon_TechSetFile.png")); + } + } + + if (!assetMap.rawFiles.isEmpty()) { + XTreeWidgetItem *rawFileRoot = new XTreeWidgetItem(zoneItem); + rawFileRoot->setText(0, "Raw Files"); + rawFileRoot->setIcon(0, QIcon(":/icons/icons/Icon_GSCFile.png")); + for (RawFile rawFile : assetMap.rawFiles) { + if (!rawFile.length) { continue; } + + XTreeWidgetItem *tempItem = rawFileRoot; + for (const QString &pathPart : rawFile.path.split('/')) { + bool childFound = false; + for (int i = 0; i < tempItem->childCount(); i++) { + QTreeWidgetItem *rawChildItem = tempItem->child(i); + XTreeWidgetItem *childItem = dynamic_cast(rawChildItem); + if (childItem->text(0) == pathPart) { + tempItem = childItem; + + childFound = true; + break; + } + } + + if (pathPart.contains(".gsc")) { + XTreeWidgetItem *rawFileItem = new XTreeWidgetItem(tempItem); + rawFileItem->setText(0, pathPart); + + tempItem = rawFileItem; + } else if (!childFound) { + tempItem = new XTreeWidgetItem(tempItem); + tempItem->setText(0, pathPart); + } + + } + tempItem->setIcon(0, QIcon(":/icons/icons/Icon_GSCFile.png")); + } + } + + if (!assetMap.menuFiles.isEmpty()) { + XTreeWidgetItem *menuRoot = new XTreeWidgetItem(zoneItem); + menuRoot->setText(0, "Menu Files"); + menuRoot->setIcon(0, QIcon(":/icons/icons/Icon_MenuFile.png")); + + int menuIndex = 1; + for (MenuFile menuFile : assetMap.menuFiles) { + XTreeWidgetItem *menuFileRoot = new XTreeWidgetItem(menuRoot); + menuFileRoot->setText(0, QString("Menu %1").arg(menuIndex)); + for (Menu menu : menuFile.menuDefs) { + XTreeWidgetItem *menuItem = new XTreeWidgetItem(menuFileRoot); + menuItem->setText(0, menu.name); + menuItem->setIcon(0, QIcon(":/icons/icons/Icon_MenuFile.png")); + } + menuIndex++; + } + } + + if (!assetMap.images.isEmpty()) { + XTreeWidgetItem *imageRoot = new XTreeWidgetItem(zoneItem); + imageRoot->setText(0, "Images"); + imageRoot->setIcon(0, QIcon(":/icons/icons/Icon_Image.png")); + + for (Image image : assetMap.images) { + XTreeWidgetItem *imageItem = new XTreeWidgetItem(imageRoot); + imageItem->setText(0, image.materialName); + imageItem->setIcon(0, QIcon(":/icons/icons/Icon_Image.png")); + } + } + + if (!assetMap.models.isEmpty()) { + XTreeWidgetItem *modelsRoot = new XTreeWidgetItem(zoneItem); + modelsRoot->setText(0, "Models"); + modelsRoot->setIcon(0, QIcon(":/icons/icons/Icon_Model.png")); + + for (Model model: assetMap.models) { + XTreeWidgetItem *modelItem = new XTreeWidgetItem(modelsRoot); + modelItem->setText(0, model.modelName); + modelItem->setIcon(0, QIcon(":/icons/icons/Icon_Model.png")); + } + } + + if (!assetMap.materials.isEmpty()) { + XTreeWidgetItem *materialsRoot = new XTreeWidgetItem(zoneItem); + materialsRoot->setText(0, "Materials"); + materialsRoot->setIcon(0, QIcon(":/icons/icons/Icon_Material.png")); + + for (Material material: assetMap.materials) { + XTreeWidgetItem *materialItem = new XTreeWidgetItem(materialsRoot); + materialItem->setText(0, material.name); + materialItem->setIcon(0, QIcon(":/icons/icons/Icon_Material.png")); + } + } + + if (!assetMap.stringTables.isEmpty()) { + XTreeWidgetItem *strTableRoot = new XTreeWidgetItem(zoneItem); + strTableRoot->setText(0, "String Tables"); + strTableRoot->setIcon(0, QIcon(":/icons/icons/Icon_StringTable.png")); + + for (StringTable strTable: assetMap.stringTables) { + XTreeWidgetItem *modelItem = new XTreeWidgetItem(strTableRoot); + modelItem->setText(0, strTable.name); + modelItem->setIcon(0, QIcon(":/icons/icons/Icon_StringTable.png")); + } + } + + if (!assetMap.sounds.isEmpty()) { + XTreeWidgetItem *soundsRoot = new XTreeWidgetItem(zoneItem); + soundsRoot->setText(0, "Sounds"); + soundsRoot->setIcon(0, QIcon(":/icons/icons/Icon_Sound.png")); + for (SoundAsset soundAsset : assetMap.sounds) { + for (Sound sound : soundAsset.sounds) { + XTreeWidgetItem *tempItem = soundsRoot; + + if (!sound.dataLength) { continue; } + + for (const QString &pathPart : sound.path.split('/')) { + if (pathPart.isEmpty()) { continue; } + + bool childFound = false; + for (int i = 0; i < tempItem->childCount(); i++) { + XTreeWidgetItem *childItem = dynamic_cast(tempItem->child(i)); + if (childItem->text(0) == pathPart) { + tempItem = childItem; + + childFound = true; + break; + } + } + + if (pathPart.contains(".wav")) { + XTreeWidgetItem *soundItem = new XTreeWidgetItem(tempItem); + soundItem->setText(0, pathPart); + + tempItem = soundItem; + } else if (!childFound) { + tempItem = new XTreeWidgetItem(tempItem); + tempItem->setText(0, pathPart); + } + + } + tempItem->setIcon(0, QIcon(":/icons/icons/Icon_Sound.png")); + } + } + } + + mZoneFiles[aZoneFile->GetStem().section(".", 0, 0)] = aZoneFile; +} + +void XTreeWidget::CloseFastFile(const QString aFFName) { + const QString fileStem = aFFName.section(".", 0, 0); + emit ItemClosed(fileStem); +} + +void XTreeWidget::PrepareContextMenu(const QPoint &pos) { + auto activeItem = itemAt(pos); + if (!activeItem) { return; } + if (activeItem->text(0).isEmpty()) { return; } + + QString activeText = activeItem->text(0); + QMenu *contextMenu = new QMenu(this); + + if (activeText.contains(".dds")) { + const QString fileStem = activeText.replace(".dds", ""); + if (!mDDSFiles.contains(fileStem)) { + qDebug() << "Error: Could not find " << fileStem << " in DDS map!"; + return; + } + + QAction *closeAction = new QAction("Close File"); + contextMenu->addAction(closeAction); + connect(closeAction, &QAction::triggered, this, [this, &fileStem, &activeItem](bool checked) { + Q_UNUSED(checked); + + mDDSFiles.remove(fileStem); + invisibleRootItem()->removeChild(activeItem); + }); + + QMenu *exportSubmenu = new QMenu("Export...", this); + contextMenu->addMenu(exportSubmenu); + + std::shared_ptr ddsFile = mDDSFiles[fileStem]; + + QAction *exportIWIAction = new QAction("Export as IWI"); + exportSubmenu->addAction(exportIWIAction); + connect(exportIWIAction, &QAction::triggered, this, [ddsFile](bool checked) { + Q_UNUSED(checked); + + ddsFile->SaveIWI(); + }); + + QAction *exportPNGAction = new QAction("Export as PNG"); + exportSubmenu->addAction(exportPNGAction); + connect(exportPNGAction, &QAction::triggered, this, [ddsFile](bool checked) { + Q_UNUSED(checked); + + ddsFile->SavePNG(); + }); + + QAction *exportJPGAction = new QAction("Export as JPG"); + exportSubmenu->addAction(exportJPGAction); + connect(exportJPGAction, &QAction::triggered, this, [ddsFile](bool checked) { + Q_UNUSED(checked); + + ddsFile->SaveJPG(); + }); + } else if (activeText.contains(".iwi")) { + const QString fileStem = activeText.replace(".iwi", ""); + if (!mIWIFiles.contains(fileStem)) { + qDebug() << "Error: Could not find " << fileStem << " in IWI map!"; + return; + } + + QAction *closeAction = new QAction("Close File"); + contextMenu->addAction(closeAction); + connect(closeAction, &QAction::triggered, this, [this, &fileStem, &activeItem](bool checked) { + Q_UNUSED(checked); + + mIWIFiles.remove(fileStem); + invisibleRootItem()->removeChild(activeItem); + }); + + QMenu *exportSubmenu = new QMenu("Export...", this); + contextMenu->addMenu(exportSubmenu); + + std::shared_ptr iwiFile = mIWIFiles[fileStem]; + + QAction *exportDDSAction = new QAction("Export as DDS"); + exportSubmenu->addAction(exportDDSAction); + connect(exportDDSAction, &QAction::triggered, this, [iwiFile](bool checked) { + Q_UNUSED(checked); + + iwiFile->SaveDDS(); + }); + + QAction *exportPNGAction = new QAction("Export as PNG"); + exportSubmenu->addAction(exportPNGAction); + connect(exportPNGAction, &QAction::triggered, this, [iwiFile](bool checked) { + Q_UNUSED(checked); + + iwiFile->SavePNG(); + }); + + QAction *exportJPGAction = new QAction("Export as JPG"); + exportSubmenu->addAction(exportJPGAction); + connect(exportJPGAction, &QAction::triggered, this, [iwiFile](bool checked) { + Q_UNUSED(checked); + + iwiFile->SaveJPG(); + }); + } else if (activeText.contains(".ff")) { + const QString fileStem = activeText.replace(".zone", ""); + + QMenu *closeMultipleAction = new QMenu("Close Multiple Tabs"); + + QAction *closeAllAction = new QAction("Close All"); + closeMultipleAction->addAction(closeAllAction); + connect(closeAllAction, &QAction::triggered, this, [this](bool checked) { + Q_UNUSED(checked); + + mFastFiles.clear(); + clear(); + + emit Cleared(); + }); + + QAction *closeAllButAction = new QAction("Close All BUT This"); + closeMultipleAction->addAction(closeAllButAction); + connect(closeAllButAction, &QAction::triggered, this, [this, &activeItem](bool checked) { + Q_UNUSED(checked); + + for (int i = 0; i < invisibleRootItem()->childCount(); i++) { + auto childItem = invisibleRootItem()->child(i); + if (childItem == activeItem) { continue; } + + const QString fileStem = childItem->text(0).replace(".ff", ""); + if (!mFastFiles.contains(fileStem)) { + qDebug() << "Error: Could not find " << fileStem << " in Fast File map!"; + return; + } + + mFastFiles.remove(fileStem); + CloseFastFile(fileStem); + invisibleRootItem()->removeChild(childItem); + i--; + } + }); + + QAction *closeAboveAction = new QAction("Close All Above"); + closeMultipleAction->addAction(closeAboveAction); + connect(closeAboveAction, &QAction::triggered, this, [this, &activeItem](bool checked) { + Q_UNUSED(checked); + + for (int i = 0; i < invisibleRootItem()->childCount(); i++) { + auto childItem = invisibleRootItem()->child(i); + if (childItem == activeItem) { return; } + + const QString fileStem = childItem->text(0).replace(".ff", ""); + if (!mFastFiles.contains(fileStem)) { + qDebug() << "Error: Could not find " << fileStem << " in Fast File map!"; + return; + } + + mFastFiles.remove(fileStem); + CloseFastFile(fileStem); + invisibleRootItem()->removeChild(childItem); + i--; + } + }); + + QAction *closeBelowAction = new QAction("Close All Below"); + closeMultipleAction->addAction(closeBelowAction); + connect(closeBelowAction, &QAction::triggered, this, [this, &activeItem](bool checked) { + Q_UNUSED(checked); + + bool ready = false; + for (int i = 0; i < invisibleRootItem()->childCount(); i++) { + auto childItem = invisibleRootItem()->child(i); + if (!ready && (childItem != activeItem)) { continue; } + if (childItem == activeItem) { + ready = true; + continue; + } + + const QString fileStem = childItem->text(0).replace(".ff", ""); + if (!mFastFiles.contains(fileStem)) { + qDebug() << "Error: Could not find " << fileStem << " in Fast File map!"; + return; + } + + mFastFiles.remove(fileStem); + CloseFastFile(fileStem); + invisibleRootItem()->removeChild(childItem); + i--; + } + }); + + contextMenu->addMenu(closeMultipleAction); + + QAction *closeAction = new QAction("Close File"); + contextMenu->addAction(closeAction); + connect(closeAction, &QAction::triggered, this, [this, &activeItem, &activeText](bool checked) { + Q_UNUSED(checked); + + const QString fileStem = activeItem->text(0).replace(".ff", ""); + + mFastFiles.remove(fileStem); + CloseFastFile(activeText); + invisibleRootItem()->removeChild(activeItem); + }); + + QMenu *exportSubmenu = new QMenu("Export...", this); + contextMenu->addMenu(exportSubmenu); + + std::shared_ptr fastFile = mFastFiles[fileStem]; + + QAction *exportFastFileAction = new QAction("Export Fast File"); + exportSubmenu->addAction(exportFastFileAction); + connect(exportFastFileAction, &QAction::triggered, this, [fastFile](bool checked) { + Q_UNUSED(checked); + + const QString fastFilePath = QFileDialog::getSaveFileName( + nullptr, "Export Fast File...", QDir::currentPath(), + "Fast File (*.ff);;All Files(*.*)"); + + fastFile->ExportFastFile(fastFilePath); + }); + QAction *exportZoneFileAction = new QAction("Export Zone File"); + exportSubmenu->addAction(exportZoneFileAction); + connect(exportZoneFileAction, &QAction::triggered, this, [fastFile](bool checked) { + Q_UNUSED(checked); + + const QString zoneFilePath = QFileDialog::getSaveFileName( + nullptr, "Export Zone File...", QDir::currentPath(), + "Zone File (*.zone);;All Files(*.*)"); + fastFile->GetZoneFile()->SaveZoneFile(zoneFilePath); + }); + } else if (activeText.contains(".zone")) { + const QString fileStem = activeText.replace(".zone", ""); + if (!mZoneFiles.contains(fileStem)) { + qDebug() << "Error: Could not find " << fileStem << " in Zone File map!"; + return; + } + + QMenu *exportSubmenu = new QMenu("Export...", this); + contextMenu->addMenu(exportSubmenu); + + std::shared_ptr zoneFile = mZoneFiles[fileStem]; + + QAction *exportZoneFileAction = new QAction("Export Zone File"); + exportSubmenu->addAction(exportZoneFileAction); + connect(exportZoneFileAction, &QAction::triggered, this, [](bool checked) { + Q_UNUSED(checked); + }); + QAction *exportFastFileAction = new QAction("Export Fast File"); + exportSubmenu->addAction(exportFastFileAction); + connect(exportFastFileAction, &QAction::triggered, this, [](bool checked) { + Q_UNUSED(checked); + }); + } else if (activeItem && activeText.contains(".wav")) { + XTreeWidgetItem *parentItem = dynamic_cast(activeItem->parent()); + while (parentItem && !parentItem->text(0).contains(".zone")) { + parentItem = dynamic_cast(parentItem->parent()); + + if (parentItem == invisibleRootItem()) { + break; + } + } + if (parentItem && parentItem != invisibleRootItem() && parentItem->text(0).contains(".zone")) { + const QString fileStem = parentItem->text(0).section('.', 0, 0); + QVector soundAssets = mZoneFiles[fileStem]->GetAssetMap().sounds; + for (SoundAsset soundAsset : soundAssets) { + for (Sound sound : soundAsset.sounds) { + if (sound.path.contains(activeText)) { + QMenu *exportSubmenu = new QMenu("Export...", this); + contextMenu->addMenu(exportSubmenu); + + QAction *exportWAVAction = new QAction("Export as WAV File"); + exportSubmenu->addAction(exportWAVAction); + connect(exportWAVAction, &QAction::triggered, this, [sound](bool checked) { + Q_UNUSED(checked); + + QDir dir = QDir::currentPath(); + if (!dir.exists("exports/")) { + dir.mkdir("exports/"); + } + + if (!dir.exists("exports/sounds/")) { + dir.mkdir("exports/sounds/"); + } + + const QString fileName = "exports/sounds/" + sound.path.split('/').last(); + QFile wavFile(fileName); + if (!wavFile.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to write wav file!"; + return; + } + wavFile.write(sound.data); + wavFile.close(); + }); + break; + } + } + } + } + } else if (activeItem && activeText == "Sounds") { + XTreeWidgetItem *parentItem = dynamic_cast(activeItem->parent()); + while (parentItem && !parentItem->text(0).contains(".zone")) { + parentItem = dynamic_cast(parentItem->parent()); + + if (parentItem == invisibleRootItem()) { + break; + } + } + if (parentItem && parentItem != invisibleRootItem() && parentItem->text(0).contains(".zone")) { + const QString fileStem = parentItem->text(0).section('.', 0, 0); + auto zoneFile = mZoneFiles[fileStem]; + + QMenu *exportSubmenu = new QMenu("Export...", this); + contextMenu->addMenu(exportSubmenu); + + QAction *exportAllWAVAction = new QAction("Export ALL as WAV Files"); + exportSubmenu->addAction(exportAllWAVAction); + connect(exportAllWAVAction, &QAction::triggered, this, [zoneFile](bool checked) { + Q_UNUSED(checked); + + for (SoundAsset soundAsset : zoneFile->GetAssetMap().sounds) { + for (Sound sound : soundAsset.sounds) { + if (!sound.dataLength) { continue; } + + QDir dir = QDir::currentPath(); + if (!dir.exists("exports/")) { + dir.mkdir("exports/"); + } + + if (!dir.exists("exports/sounds/")) { + dir.mkdir("exports/sounds/"); + } + + const QString fileName = "exports/sounds/" + sound.path.split('/').last(); + QFile wavFile(fileName); + if (!wavFile.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to write wav file!"; + return; + } + wavFile.write(sound.data); + wavFile.close(); + } + } + }); + } + } + + QPoint pt(pos); + contextMenu->exec(mapToGlobal(pt)); + + delete contextMenu; +} + +void XTreeWidget::ItemSelectionChanged() { + if (selectedItems().isEmpty()) { return; } + + XTreeWidgetItem *selectedItem = dynamic_cast(selectedItems().first()); + if (!selectedItem) { return; } + if (selectedItem->text(0).isEmpty()) { return; } + QString selectedText = selectedItem->text(0); + emit ItemSelected(selectedText); + + const QString fileStem = selectedText.section(".", 0, 0); + + XTreeWidgetItem *parentItem = dynamic_cast(selectedItem->parent()); + + if (selectedText.contains(".dds")) { + if (!mDDSFiles.contains(fileStem)) { + LogManager::instance().addError("Could not find " + fileStem + " in DDS map!"); + return; + } + std::shared_ptr ddsFile = mDDSFiles[fileStem]; + emit DDSFileSelected(ddsFile, fileStem); + } else if (selectedText.contains(".iwi")) { + if (!mIWIFiles.contains(fileStem)) { + LogManager::instance().addError("Could not find " + fileStem + " in IWI map!"); + return; + } + emit IWIFileSelected(mIWIFiles[fileStem], fileStem); + } else if (selectedText.contains(".ff")) { + if (!mFastFiles.contains(fileStem)) { + LogManager::instance().addError("Could not find " + fileStem + " in Fast File map!"); + return; + } + emit FastFileSelected(mFastFiles[fileStem], fileStem); + } else if (selectedText.contains(".zone")) { + if (!mZoneFiles.contains(fileStem)) { + LogManager::instance().addError("Could not find " + fileStem + " in Zone File map!"); + return; + } + emit ZoneFileSelected(mZoneFiles[fileStem], fileStem); + } else if (selectedText.contains(".str")) { + if (!mZoneFiles.contains(fileStem)) { + LogManager::instance().addError("Could not find " + fileStem + " in Zone File map!"); + return; + } + emit LocalStringSelected(mZoneFiles[fileStem], fileStem); + } else if (selectedText.contains(".gsc")) { + XTreeWidgetItem *zoneRoot = selectedItem; + if (!zoneRoot) { return; } + + while (!zoneRoot->text(0).contains(".zone")) { + zoneRoot = dynamic_cast(zoneRoot->parent()); + if (!zoneRoot) { return; } + } + + const QString fileStem = zoneRoot->text(0).section('.', 0, 0); + if (!mZoneFiles.contains(fileStem)) { + LogManager::instance().addError("Could not find " + fileStem + " in Zone File map!"); + return; + } + + QVector rawFiles = mZoneFiles[fileStem]->GetAssetMap().rawFiles; + for (RawFile rawFile : rawFiles) { + if (rawFile.path.contains(selectedText)) { + emit RawFileSelected(std::make_shared(rawFile), fileStem); + return; + } + } + } else if (parentItem && (parentItem->text(0) == "Images")) { + XTreeWidgetItem *grandpaItem = dynamic_cast(parentItem->parent()); + if (grandpaItem && grandpaItem->text(0).contains(".zone")) { + const QString fileStem = grandpaItem->text(0).section('.', 0, 0); + QVector images = mZoneFiles[fileStem]->GetAssetMap().images; + for (Image image : images) { + if (image.materialName == selectedText) { + emit ImageSelected(std::make_shared(image), fileStem); + break; + } + } + } + } else if (parentItem && (parentItem->text(0) == "Tech Sets")) { + XTreeWidgetItem *grandpaItem = dynamic_cast(parentItem->parent()); + if (grandpaItem && grandpaItem->text(0).contains(".zone")) { + const QString fileStem = grandpaItem->text(0).section('.', 0, 0); + auto techsets = mZoneFiles[fileStem]->GetAssetMap().techSets; + for (auto techset : techsets) { + if (techset.name == selectedText) { + emit TechSetSelected(std::make_shared(techset), fileStem); + break; + } + } + } + } else if (parentItem && (parentItem->text(0) == "Tech Sets")) { + XTreeWidgetItem *grandpaItem = dynamic_cast(parentItem->parent()); + if (grandpaItem && grandpaItem->text(0).contains(".zone")) { + const QString fileStem = grandpaItem->text(0).section('.', 0, 0); + auto techsets = mZoneFiles[fileStem]->GetAssetMap().techSets; + for (auto techset : techsets) { + if (techset.name == selectedText) { + emit TechSetSelected(std::make_shared(techset), fileStem); + break; + } + } + } + } else if (parentItem && (parentItem->text(0) == "Materials")) { + XTreeWidgetItem *grandpaItem = dynamic_cast(parentItem->parent()); + if (grandpaItem && grandpaItem->text(0).contains(".zone")) { + const QString fileStem = grandpaItem->text(0).section('.', 0, 0); + QVector materials = mZoneFiles[fileStem]->GetAssetMap().materials; + for (Material material : materials) { + if (material.name == selectedText) { + emit MaterialSelected(std::make_shared(material), fileStem); + break; + } + } + } + } else if (parentItem && selectedText.contains(".wav")) { + XTreeWidgetItem *grandpaItem = dynamic_cast(parentItem->parent()); + while (grandpaItem && !grandpaItem->text(0).contains(".zone")) { + grandpaItem = dynamic_cast(grandpaItem->parent()); + + if (grandpaItem == invisibleRootItem()) { + break; + } + } + if (grandpaItem && grandpaItem != invisibleRootItem() && grandpaItem->text(0).contains(".zone")) { + const QString fileStem = grandpaItem->text(0).section('.', 0, 0); + QVector soundAssets = mZoneFiles[fileStem]->GetAssetMap().sounds; + for (SoundAsset soundAsset : soundAssets) { + for (Sound sound : soundAsset.sounds) { + if (sound.path.contains(selectedText)) { + emit SoundSelected(std::make_shared(sound), fileStem); + break; + } + } + } + } + } +} + +std::shared_ptr XTreeWidget::FindZoneFile(const QString aStem) { + foreach (auto zoneFile, mZoneFiles) { + if (zoneFile->GetStem() == aStem) { + return zoneFile; + } + } + return nullptr; +} + +std::shared_ptr XTreeWidget::FindFastFile(const QString aStem) { + foreach (auto fastFile, mFastFiles) { + if (fastFile->GetStem() == aStem) { + return fastFile; + } + } + return nullptr; +} + +bool XTreeWidget::HasZoneFile(const QString aStem) { + return FindZoneFile(aStem) != nullptr; +} + +bool XTreeWidget::HasFastFile(const QString aStem) { + return FindFastFile(aStem) != nullptr; +} + +void XTreeWidget::AddIWIFile(std::shared_ptr aIWIFile) { + const QString iwiFileName = QString(aIWIFile->fileStem + ".iwi"); + + for (int i = 0; i < invisibleRootItem()->childCount(); i++) { + auto iwiFileItem = invisibleRootItem()->child(i); + if (iwiFileItem->text(0) == iwiFileName) { + delete iwiFileItem; + } + } + + XTreeWidgetItem *iwiItem = new XTreeWidgetItem(this); + iwiItem->setIcon(0, QIcon(":/icons/icons/Icon_IWIFile.png")); + iwiItem->setText(0, iwiFileName); + mIWIFiles[aIWIFile->fileStem.section(".", 0, 0)] = aIWIFile; +} + +void XTreeWidget::AddDDSFile(std::shared_ptr aDDSFile) { + const QString ddsFileName = QString(aDDSFile->fileStem + ".dds"); + + for (int i = 0; i < invisibleRootItem()->childCount(); i++) { + auto ddsFileItem = invisibleRootItem()->child(i); + if (ddsFileItem->text(0) == ddsFileName) { + delete ddsFileItem; + } + } + + XTreeWidgetItem *ddsItem = new XTreeWidgetItem(this); + ddsItem->setIcon(0, QIcon(":/icons/icons/Icon_DDSFile.png")); + ddsItem->setText(0, ddsFileName); + mDDSFiles[aDDSFile->fileStem.section(".", 0, 0)] = aDDSFile; +} diff --git a/app/xtreewidget.h b/app/xtreewidget.h new file mode 100644 index 0000000..37e3761 --- /dev/null +++ b/app/xtreewidget.h @@ -0,0 +1,62 @@ +#ifndef XTREEWIDGET_H +#define XTREEWIDGET_H + +#include "d3dbsp_structs.h" +#include "asset_structs.h" +#include "ddsfile.h" +#include "iwifile.h" +#include "fastfile.h" +#include "xtreewidgetitem.h" +#include "zonefile.h" + +#include + +class XTreeWidget : public QTreeWidget +{ + Q_OBJECT +public: + explicit XTreeWidget(QWidget *parent = nullptr); + ~XTreeWidget(); + + void AddFastFile(std::shared_ptr aFastFile); + void AddZoneFile(std::shared_ptr aZoneFile, XTreeWidgetItem *aParentItem = nullptr); + void AddIWIFile(std::shared_ptr aIWIFile); + void AddDDSFile(std::shared_ptr aDDSFile); + + std::shared_ptr FindZoneFile(const QString aStem); + std::shared_ptr FindFastFile(const QString aStem); + + bool HasZoneFile(const QString aStem); + bool HasFastFile(const QString aStem); + + void CloseFastFile(const QString aFFName); +signals: + void DDSFileSelected(std::shared_ptr aDDSFile, const QString aParentName); + void IWIFileSelected(std::shared_ptr aIWIFile, const QString aParentName); + void FastFileSelected(std::shared_ptr aFastFile, const QString aParentName); + void ZoneFileSelected(std::shared_ptr aZoneFile, const QString aParentName); + void LocalStringSelected(std::shared_ptr aZoneFile, const QString aParentName); + void RawFileSelected(std::shared_ptr aRawFile, const QString aParentName); + void ImageSelected(std::shared_ptr aImage, const QString aParentName); + void TechSetSelected(std::shared_ptr aZoneFile, const QString aParentName); + void StrTableSelected(std::shared_ptr aStrTable, const QString aParentName); + void MenuSelected(std::shared_ptr aMenu, const QString aParentName); + void SoundSelected(std::shared_ptr aSound, const QString aParentName); + void MaterialSelected(std::shared_ptr aMaterial, const QString aParentName); + void ItemSelected(const QString itemText); + + void ItemClosed(const QString itemText); + void Cleared(); + +protected: + void ItemSelectionChanged(); + void PrepareContextMenu(const QPoint &pos); + +private: + QMap> mFastFiles; + QMap> mZoneFiles; + QMap> mDDSFiles; + QMap> mIWIFiles; +}; + +#endif // XTREEWIDGET_H diff --git a/app/xtreewidgetitem.cpp b/app/xtreewidgetitem.cpp new file mode 100644 index 0000000..eae4ee9 --- /dev/null +++ b/app/xtreewidgetitem.cpp @@ -0,0 +1,42 @@ +#include "xtreewidgetitem.h" + +XTreeWidgetItem::XTreeWidgetItem(QTreeWidget *parent, bool group) + : QTreeWidgetItem(parent), isGroup(group) { + +} + +XTreeWidgetItem::XTreeWidgetItem(QTreeWidgetItem *parent, bool group) + : QTreeWidgetItem(parent), isGroup(group) { + +} + +bool XTreeWidgetItem::operator<(const QTreeWidgetItem &other) const { + // Attempt to cast the other item to our custom type. + const XTreeWidgetItem* otherItem = dynamic_cast(&other); + if (otherItem) { + bool thisIsGroup = this->childCount() > 0; + bool otherIsGroup = otherItem->childCount() > 0; + + if (thisIsGroup != otherIsGroup) { + return otherIsGroup; // Groups should come before non-groups + } + } + // Fallback to the default string comparison on the current sort column. + return QTreeWidgetItem::operator<(other); +} + + +XTreeWidgetItem& XTreeWidgetItem::operator=(const XTreeWidgetItem &other) +{ + if (this != &other) { + // Copy text and icon for each column. + const int colCount = other.columnCount(); + for (int i = 0; i < colCount; ++i) { + setText(i, other.text(i)); + setIcon(i, other.icon(i)); + } + // Copy custom members. + this->isGroup = other.isGroup; + } + return *this; +} diff --git a/app/xtreewidgetitem.h b/app/xtreewidgetitem.h new file mode 100644 index 0000000..e189d04 --- /dev/null +++ b/app/xtreewidgetitem.h @@ -0,0 +1,24 @@ +#ifndef XTREEWIDGETITEM_H +#define XTREEWIDGETITEM_H + +#include +#include + +// Custom item class +class XTreeWidgetItem : public QTreeWidgetItem +{ +public: + // Flag to indicate if the item is a collapsible group/header. + bool isGroup; + + // Constructors: default to non-group unless specified. + XTreeWidgetItem(QTreeWidget *parent, bool group = false); + XTreeWidgetItem(QTreeWidgetItem *parent, bool group = false); + + // Override the less-than operator to customize sorting. + bool operator<(const QTreeWidgetItem &other) const override; + XTreeWidgetItem &operator =(const XTreeWidgetItem &other); +}; + + +#endif // XTREEWIDGETITEM_H diff --git a/app/zonefileviewer.cpp b/app/zonefileviewer.cpp new file mode 100644 index 0000000..12c48a3 --- /dev/null +++ b/app/zonefileviewer.cpp @@ -0,0 +1,127 @@ +#include "zonefileviewer.h" +#include "ui_zonefileviewer.h" + +ZoneFileViewer::ZoneFileViewer(QWidget *parent) + : QWidget(parent) + , ui(new Ui::ZoneFileViewer) { + ui->setupUi(this); + + aZoneFile = nullptr; + + ui->tableWidget_RecordCounts->setColumnCount(4); + ui->tableWidget_RecordCounts->setHorizontalHeaderLabels({ "Identifier", "Asset", "Count", "Icon" }); + ui->tableWidget_RecordCounts->horizontalHeader()->setStretchLastSection(true); + + ui->tableWidget_RecordOrder->setColumnCount(4); + ui->tableWidget_RecordOrder->setHorizontalHeaderLabels({ "Identifier", "Asset", "Count", "Icon" }); + ui->tableWidget_RecordOrder->horizontalHeader()->setStretchLastSection(true); +} + +ZoneFileViewer::~ZoneFileViewer() { + delete ui; +} + +void ZoneFileViewer::SetZoneFile(std::shared_ptr aZoneFile) { + ui->tableWidget_RecordCounts->clearContents(); + ui->tableWidget_RecordOrder->clearContents(); + ui->listWidget_Tags->clear(); + + const QStringList tags = aZoneFile->GetTags(); + ui->listWidget_Tags->addItems(tags); + ui->label_Title->setText(aZoneFile->GetStem() + ".zone"); + + if (tags.isEmpty()) { + ui->groupBox_Tags->hide(); + } else { + ui->groupBox_Tags->show(); + } + + QString lastAsset = ""; + QString lastRecord = ""; + QIcon assetIcon; + int consecutiveCount = 1; + int consecutiveIndex = 0; + const QStringList records = aZoneFile->GetRecords(); + QMap recordCounts = QMap(); + for (const QString &record : records) { + lastRecord = record; + if (record == "ffffffff") { break; } + if (!recordCounts.contains(record)) { + recordCounts[record] = 0; + } + recordCounts[record]++; + + QString assetType = aZoneFile->AssetTypeToString(record); + if (assetIcon.isNull()) { + qDebug() << "Icon is null for record: " << record; + } + + if (lastAsset.isEmpty()) { + lastAsset = assetType; + lastRecord = record; + } else if (lastAsset == assetType) { + consecutiveCount++; + } else { + ui->tableWidget_RecordOrder->setRowCount(consecutiveIndex + 1); + + QTableWidgetItem *recordItem = new QTableWidgetItem(lastRecord.toUpper()); + QTableWidgetItem *recordStrItem = new QTableWidgetItem(lastAsset); + QTableWidgetItem *recordCountItem = new QTableWidgetItem(QString::number(consecutiveCount)); + QTableWidgetItem *recordIconItem = new QTableWidgetItem(); + assetIcon = aZoneFile->AssetStrToIcon(lastAsset); + recordIconItem->setIcon(assetIcon); + + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 0, recordItem); + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 1, recordStrItem); + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 2, recordCountItem); + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 3, recordIconItem); + + consecutiveCount = 1; + consecutiveIndex++; + lastAsset = assetType; + lastRecord = record; + } + } + ui->tableWidget_RecordOrder->setRowCount(consecutiveIndex + 1); + + QTableWidgetItem *recordItem = new QTableWidgetItem(lastRecord.toUpper()); + QTableWidgetItem *recordStrItem = new QTableWidgetItem(lastAsset); + QTableWidgetItem *recordCountItem = new QTableWidgetItem(QString::number(consecutiveCount)); + QTableWidgetItem *recordIconItem = new QTableWidgetItem(); + assetIcon = aZoneFile->AssetStrToIcon(lastAsset); + recordIconItem->setIcon(assetIcon); + + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 0, recordItem); + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 1, recordStrItem); + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 2, recordCountItem); + ui->tableWidget_RecordOrder->setItem(consecutiveIndex, 3, recordIconItem); + + int recordIndex = 0; + for (const QString &record : recordCounts.keys()) { + int recordCount = recordCounts[record]; + + QString assetType = aZoneFile->AssetTypeToString(record); + assetIcon = aZoneFile->AssetStrToIcon(assetType); + if (assetIcon.isNull()) { + qDebug() << "Icon is null for record: " << record; + } + + ui->tableWidget_RecordCounts->setRowCount(recordIndex + 1); + + QTableWidgetItem *recordCountStrItem = new QTableWidgetItem(assetType); + QTableWidgetItem *recordItem = new QTableWidgetItem(record.toUpper()); + QTableWidgetItem *recordCountItem = new QTableWidgetItem(QString::number(recordCount)); + QTableWidgetItem *recordIconItem = new QTableWidgetItem(); + recordIconItem->setIcon(assetIcon); + + ui->tableWidget_RecordCounts->setItem(recordIndex, 0, recordItem); + ui->tableWidget_RecordCounts->setItem(recordIndex, 1, recordCountStrItem); + ui->tableWidget_RecordCounts->setItem(recordIndex, 2, recordCountItem); + ui->tableWidget_RecordCounts->setItem(recordIndex, 3, recordIconItem); + + recordIndex++; + } + + ui->tableWidget_RecordOrder->resizeColumnsToContents(); + ui->tableWidget_RecordCounts->resizeColumnsToContents(); +} diff --git a/app/zonefileviewer.h b/app/zonefileviewer.h new file mode 100644 index 0000000..e335d2c --- /dev/null +++ b/app/zonefileviewer.h @@ -0,0 +1,27 @@ +#ifndef ZONEFILEVIEWER_H +#define ZONEFILEVIEWER_H + +#include "zonefile.h" +#include "utils.h" + +#include + +namespace Ui { +class ZoneFileViewer; +} + +class ZoneFileViewer : public QWidget +{ + Q_OBJECT + +public: + explicit ZoneFileViewer(QWidget *parent = nullptr); + ~ZoneFileViewer(); + + void SetZoneFile(std::shared_ptr aZoneFile); +private: + Ui::ZoneFileViewer *ui; + std::shared_ptr aZoneFile; +}; + +#endif // ZONEFILEVIEWER_H diff --git a/app/zonefileviewer.ui b/app/zonefileviewer.ui new file mode 100644 index 0000000..7b0755a --- /dev/null +++ b/app/zonefileviewer.ui @@ -0,0 +1,99 @@ + + + ZoneFileViewer + + + + 0 + 0 + 556 + 428 + + + + Form + + + + + + + Roboto + 16 + true + + + + ZoneFile 0 + + + + + + + + + + Roboto + 9 + + + + Tags + + + + + + + + Search: + + + + + + + Search tags... + + + + + + + + + + + + + + + Record Counts + + + + + + + + + + + + Record Order + + + + + + + + + + + + + + + diff --git a/data/Data.qrc b/data/Data.qrc new file mode 100644 index 0000000..e1c377a --- /dev/null +++ b/data/Data.qrc @@ -0,0 +1,91 @@ + + + obj/defaultactor_LOD0.XMODEL_BIN + obj/defaultactor_LOD0.XMODEL_EXPORT + obj/defaultactor_LOD0.bin + obj/defaultactor_LOD0.cast + obj/defaultactor_LOD0.gltf + obj/defaultactor_LOD0.ma + obj/defaultactor_LOD0.mesh.ascii + obj/defaultactor_LOD0.obj + obj/defaultactor_LOD0.semodel + obj/defaultactor_LOD0.smd + obj/defaultactor_LOD0_BIND.mel + obj/defaultactor_LOD0_cosmetics.mel + obj/diffusemap.png + obj/mtl_body_default_character.mtl + obj/mtl_body_default_character_images.txt + obj/normalmap.png + + + d3dbsp/asset_viewer.d3dbsp + d3dbsp/barebones.d3dbsp + + + images/XPlor.png + images/copy.svg + images/cut.svg + images/multiple.png + images/new_file.svg + images/open_file.svg + images/open_folder.svg + images/paste.svg + images/refresh.svg + images/save.svg + + + icons/Icon_COD4.png + icons/Icon_COD5.png + icons/Icon_COD6.png + icons/Icon_COD7.png + icons/Icon_COD8.png + icons/Icon_COD9.png + icons/Icon_DDSFile.png + icons/Icon_FastFile.png + icons/Icon_IWIFile.png + icons/Icon_PC.png + icons/Icon_Playstation.png + icons/Icon_Xbox.png + icons/Icon_ZoneFile.png + icons/Icon_GSCFile.png + icons/Icon_StringFile.png + icons/Icon_TechSetFile.png + icons/Icon_WAVFile.png + icons/Icon_MenuFile.png + icons/Icon_Image.png + icons/Icon_Model.png + icons/Icon_StringTable.png + icons/Icon_Sound.png + icons/Icon_Pause.png + icons/Icon_Play.png + icons/Icon_SkipBack.png + icons/Icon_SkipForward.png + icons/Icon_Stop.png + icons/Icon_Editor.png + icons/Icon_Views.png + icons/Icon_Tree.png + icons/Icon_Copy.png + icons/Icon_Cut.png + icons/Icon_Find.png + icons/Icon_NewFile.png + icons/Icon_Paste.png + icons/Icon_Save.png + icons/Icon_OpenFile.png + icons/Icon_COD2.png + icons/Icon_Material.png + icons/Icon_Animation.png + icons/Icon_BSP.png + icons/Icon_ColMapSp.png + icons/Icon_Effect.png + icons/Icon_GameMapSp.png + icons/Icon_Font.png + icons/Icon_FXMap.png + icons/Icon_LightDef.png + icons/Icon_Weapon.png + icons/Icon_RawFile.png + icons/Icon_Destructible.png + icons/Icon_PhysPreset.png + icons/Icon_Wii.png + icons/Icon_WiiU.png + + diff --git a/data/icons/Icon_Animation.png b/data/icons/Icon_Animation.png new file mode 100644 index 0000000..0dc0e31 Binary files /dev/null and b/data/icons/Icon_Animation.png differ diff --git a/data/icons/Icon_BSP.png b/data/icons/Icon_BSP.png new file mode 100644 index 0000000..4a3ab1d Binary files /dev/null and b/data/icons/Icon_BSP.png differ diff --git a/data/icons/Icon_COD2.png b/data/icons/Icon_COD2.png new file mode 100644 index 0000000..470c389 Binary files /dev/null and b/data/icons/Icon_COD2.png differ diff --git a/data/icons/Icon_COD4.png b/data/icons/Icon_COD4.png new file mode 100644 index 0000000..fa0df53 Binary files /dev/null and b/data/icons/Icon_COD4.png differ diff --git a/data/icons/Icon_COD5.png b/data/icons/Icon_COD5.png new file mode 100644 index 0000000..81b926a Binary files /dev/null and b/data/icons/Icon_COD5.png differ diff --git a/data/icons/Icon_COD6.png b/data/icons/Icon_COD6.png new file mode 100644 index 0000000..aecb4b0 Binary files /dev/null and b/data/icons/Icon_COD6.png differ diff --git a/data/icons/Icon_COD7.png b/data/icons/Icon_COD7.png new file mode 100644 index 0000000..d237f37 Binary files /dev/null and b/data/icons/Icon_COD7.png differ diff --git a/data/icons/Icon_COD8.png b/data/icons/Icon_COD8.png new file mode 100644 index 0000000..57f6d45 Binary files /dev/null and b/data/icons/Icon_COD8.png differ diff --git a/data/icons/Icon_COD9.png b/data/icons/Icon_COD9.png new file mode 100644 index 0000000..ac82d59 Binary files /dev/null and b/data/icons/Icon_COD9.png differ diff --git a/data/icons/Icon_ColMapSp.png b/data/icons/Icon_ColMapSp.png new file mode 100644 index 0000000..085e84d Binary files /dev/null and b/data/icons/Icon_ColMapSp.png differ diff --git a/data/icons/Icon_Copy.png b/data/icons/Icon_Copy.png new file mode 100644 index 0000000..2246199 Binary files /dev/null and b/data/icons/Icon_Copy.png differ diff --git a/data/icons/Icon_Cut.png b/data/icons/Icon_Cut.png new file mode 100644 index 0000000..3ff11cc Binary files /dev/null and b/data/icons/Icon_Cut.png differ diff --git a/data/icons/Icon_DDSFile.png b/data/icons/Icon_DDSFile.png new file mode 100644 index 0000000..d9aa7eb Binary files /dev/null and b/data/icons/Icon_DDSFile.png differ diff --git a/data/icons/Icon_Destructible.png b/data/icons/Icon_Destructible.png new file mode 100644 index 0000000..06f5eb1 Binary files /dev/null and b/data/icons/Icon_Destructible.png differ diff --git a/data/icons/Icon_Editor.png b/data/icons/Icon_Editor.png new file mode 100644 index 0000000..f3b72af Binary files /dev/null and b/data/icons/Icon_Editor.png differ diff --git a/data/icons/Icon_Effect.png b/data/icons/Icon_Effect.png new file mode 100644 index 0000000..ba41f66 Binary files /dev/null and b/data/icons/Icon_Effect.png differ diff --git a/data/icons/Icon_FXMap.png b/data/icons/Icon_FXMap.png new file mode 100644 index 0000000..f434048 Binary files /dev/null and b/data/icons/Icon_FXMap.png differ diff --git a/data/icons/Icon_FastFile.png b/data/icons/Icon_FastFile.png new file mode 100644 index 0000000..8221e33 Binary files /dev/null and b/data/icons/Icon_FastFile.png differ diff --git a/data/icons/Icon_Find.png b/data/icons/Icon_Find.png new file mode 100644 index 0000000..936c431 Binary files /dev/null and b/data/icons/Icon_Find.png differ diff --git a/data/icons/Icon_Font.png b/data/icons/Icon_Font.png new file mode 100644 index 0000000..1af47b2 Binary files /dev/null and b/data/icons/Icon_Font.png differ diff --git a/data/icons/Icon_GSCFile.png b/data/icons/Icon_GSCFile.png new file mode 100644 index 0000000..9a5fad0 Binary files /dev/null and b/data/icons/Icon_GSCFile.png differ diff --git a/data/icons/Icon_GameMapSp.png b/data/icons/Icon_GameMapSp.png new file mode 100644 index 0000000..6b72e9a Binary files /dev/null and b/data/icons/Icon_GameMapSp.png differ diff --git a/data/icons/Icon_IWIFile.png b/data/icons/Icon_IWIFile.png new file mode 100644 index 0000000..0a9e2fd Binary files /dev/null and b/data/icons/Icon_IWIFile.png differ diff --git a/data/icons/Icon_Image.png b/data/icons/Icon_Image.png new file mode 100644 index 0000000..5f31b19 Binary files /dev/null and b/data/icons/Icon_Image.png differ diff --git a/data/icons/Icon_LightDef.png b/data/icons/Icon_LightDef.png new file mode 100644 index 0000000..20689ba Binary files /dev/null and b/data/icons/Icon_LightDef.png differ diff --git a/data/icons/Icon_Material.png b/data/icons/Icon_Material.png new file mode 100644 index 0000000..2e9d2e8 Binary files /dev/null and b/data/icons/Icon_Material.png differ diff --git a/data/icons/Icon_MenuFile.png b/data/icons/Icon_MenuFile.png new file mode 100644 index 0000000..7d40946 Binary files /dev/null and b/data/icons/Icon_MenuFile.png differ diff --git a/data/icons/Icon_Model.png b/data/icons/Icon_Model.png new file mode 100644 index 0000000..c5e0355 Binary files /dev/null and b/data/icons/Icon_Model.png differ diff --git a/data/icons/Icon_NewFile.png b/data/icons/Icon_NewFile.png new file mode 100644 index 0000000..0e9d05c Binary files /dev/null and b/data/icons/Icon_NewFile.png differ diff --git a/data/icons/Icon_OpenFile.png b/data/icons/Icon_OpenFile.png new file mode 100644 index 0000000..a7166b5 Binary files /dev/null and b/data/icons/Icon_OpenFile.png differ diff --git a/data/icons/Icon_PC.png b/data/icons/Icon_PC.png new file mode 100644 index 0000000..b71e03d Binary files /dev/null and b/data/icons/Icon_PC.png differ diff --git a/data/icons/Icon_Paste.png b/data/icons/Icon_Paste.png new file mode 100644 index 0000000..65d704c Binary files /dev/null and b/data/icons/Icon_Paste.png differ diff --git a/data/icons/Icon_Pause.png b/data/icons/Icon_Pause.png new file mode 100644 index 0000000..8d46f91 Binary files /dev/null and b/data/icons/Icon_Pause.png differ diff --git a/data/icons/Icon_PhysPreset.png b/data/icons/Icon_PhysPreset.png new file mode 100644 index 0000000..5e4339f Binary files /dev/null and b/data/icons/Icon_PhysPreset.png differ diff --git a/data/icons/Icon_Play.png b/data/icons/Icon_Play.png new file mode 100644 index 0000000..47d198f Binary files /dev/null and b/data/icons/Icon_Play.png differ diff --git a/data/icons/Icon_Playstation.png b/data/icons/Icon_Playstation.png new file mode 100644 index 0000000..c706d53 Binary files /dev/null and b/data/icons/Icon_Playstation.png differ diff --git a/data/icons/Icon_RawFile.png b/data/icons/Icon_RawFile.png new file mode 100644 index 0000000..1281b71 Binary files /dev/null and b/data/icons/Icon_RawFile.png differ diff --git a/data/icons/Icon_Save.png b/data/icons/Icon_Save.png new file mode 100644 index 0000000..587ea2e Binary files /dev/null and b/data/icons/Icon_Save.png differ diff --git a/data/icons/Icon_SkipBack.png b/data/icons/Icon_SkipBack.png new file mode 100644 index 0000000..fd217d8 Binary files /dev/null and b/data/icons/Icon_SkipBack.png differ diff --git a/data/icons/Icon_SkipForward.png b/data/icons/Icon_SkipForward.png new file mode 100644 index 0000000..d41874f Binary files /dev/null and b/data/icons/Icon_SkipForward.png differ diff --git a/data/icons/Icon_Sound.png b/data/icons/Icon_Sound.png new file mode 100644 index 0000000..f55c471 Binary files /dev/null and b/data/icons/Icon_Sound.png differ diff --git a/data/icons/Icon_Stop.png b/data/icons/Icon_Stop.png new file mode 100644 index 0000000..fb18f60 Binary files /dev/null and b/data/icons/Icon_Stop.png differ diff --git a/data/icons/Icon_StringFile.png b/data/icons/Icon_StringFile.png new file mode 100644 index 0000000..ac3e25f Binary files /dev/null and b/data/icons/Icon_StringFile.png differ diff --git a/data/icons/Icon_StringTable.png b/data/icons/Icon_StringTable.png new file mode 100644 index 0000000..9ca4722 Binary files /dev/null and b/data/icons/Icon_StringTable.png differ diff --git a/data/icons/Icon_TechSetFile.png b/data/icons/Icon_TechSetFile.png new file mode 100644 index 0000000..96fc774 Binary files /dev/null and b/data/icons/Icon_TechSetFile.png differ diff --git a/data/icons/Icon_Tree.png b/data/icons/Icon_Tree.png new file mode 100644 index 0000000..d3d29b1 Binary files /dev/null and b/data/icons/Icon_Tree.png differ diff --git a/data/icons/Icon_Views.png b/data/icons/Icon_Views.png new file mode 100644 index 0000000..7b0e437 Binary files /dev/null and b/data/icons/Icon_Views.png differ diff --git a/data/icons/Icon_WAVFile.png b/data/icons/Icon_WAVFile.png new file mode 100644 index 0000000..f7e43e8 Binary files /dev/null and b/data/icons/Icon_WAVFile.png differ diff --git a/data/icons/Icon_Weapon.png b/data/icons/Icon_Weapon.png new file mode 100644 index 0000000..76e98e7 Binary files /dev/null and b/data/icons/Icon_Weapon.png differ diff --git a/data/icons/Icon_Wii.png b/data/icons/Icon_Wii.png new file mode 100644 index 0000000..efed38a Binary files /dev/null and b/data/icons/Icon_Wii.png differ diff --git a/data/icons/Icon_WiiU.png b/data/icons/Icon_WiiU.png new file mode 100644 index 0000000..a827c6a Binary files /dev/null and b/data/icons/Icon_WiiU.png differ diff --git a/data/icons/Icon_Xbox.png b/data/icons/Icon_Xbox.png new file mode 100644 index 0000000..c25da9a Binary files /dev/null and b/data/icons/Icon_Xbox.png differ diff --git a/data/icons/Icon_ZoneFile.png b/data/icons/Icon_ZoneFile.png new file mode 100644 index 0000000..f9e8daf Binary files /dev/null and b/data/icons/Icon_ZoneFile.png differ diff --git a/data/images/XPlor.png b/data/images/XPlor.png new file mode 100644 index 0000000..babe14d Binary files /dev/null and b/data/images/XPlor.png differ diff --git a/data/images/copy.svg b/data/images/copy.svg new file mode 100644 index 0000000..f09d902 --- /dev/null +++ b/data/images/copy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/cut.svg b/data/images/cut.svg new file mode 100644 index 0000000..c563fb2 --- /dev/null +++ b/data/images/cut.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/multiple.png b/data/images/multiple.png new file mode 100644 index 0000000..a18bbb4 Binary files /dev/null and b/data/images/multiple.png differ diff --git a/data/images/new_file.svg b/data/images/new_file.svg new file mode 100644 index 0000000..7c19795 --- /dev/null +++ b/data/images/new_file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/open_file.svg b/data/images/open_file.svg new file mode 100644 index 0000000..ee0ee85 --- /dev/null +++ b/data/images/open_file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/open_folder.svg b/data/images/open_folder.svg new file mode 100644 index 0000000..3e7b372 --- /dev/null +++ b/data/images/open_folder.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/paste.svg b/data/images/paste.svg new file mode 100644 index 0000000..bb4e796 --- /dev/null +++ b/data/images/paste.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/refresh.svg b/data/images/refresh.svg new file mode 100644 index 0000000..4e6d30c --- /dev/null +++ b/data/images/refresh.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/images/save.svg b/data/images/save.svg new file mode 100644 index 0000000..4f76105 --- /dev/null +++ b/data/images/save.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/libs/compression/compression.cpp b/libs/compression/compression.cpp new file mode 100644 index 0000000..690b43f --- /dev/null +++ b/libs/compression/compression.cpp @@ -0,0 +1,307 @@ +#include "compression.h" +//#include "lzokay.h" + +#define XBOXAPI __declspec(dllimport) +#include "xcompress.h" + +#include +#include +#include +#include + +QByteArray Compression::CompressXMem(const QByteArray &data) +{ + XMEMCODEC_PARAMETERS_LZX lzxParams = {}; + lzxParams.Flags = 0; + lzxParams.WindowSize = XCOMPRESS_LZX_BLOCK_SIZE; + lzxParams.CompressionPartitionSize = XCOMPRESS_LZX_BLOCK_SIZE; + + XMEMCOMPRESSION_CONTEXT ctx = nullptr; + if (FAILED(XMemCreateCompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx) + return QByteArray(); + + SIZE_T estimatedSize = data.size() + XCOMPRESS_LZX_BLOCK_GROWTH_SIZE_MAX; + QByteArray output(static_cast(estimatedSize), 0); + SIZE_T actualSize = estimatedSize; + + HRESULT hr = XMemCompress(ctx, output.data(), &actualSize, data.constData(), data.size()); + XMemDestroyCompressionContext(ctx); + + if (FAILED(hr)) + return QByteArray(); + + output.resize(static_cast(actualSize)); + return output; +} + +QByteArray Compression::DecompressXMem(const QByteArray &data) +{ + XMEMCODEC_PARAMETERS_LZX lzxParams = {}; + lzxParams.Flags = 0; + lzxParams.WindowSize = XCOMPRESS_LZX_BLOCK_SIZE; + lzxParams.CompressionPartitionSize = XCOMPRESS_LZX_BLOCK_SIZE; + + XMEMDECOMPRESSION_CONTEXT ctx = nullptr; + if (FAILED(XMemCreateDecompressionContext(XMEMCODEC_LZX, &lzxParams, 0, &ctx)) || !ctx) + return QByteArray(); + + QByteArray output(data.size(), 0); + SIZE_T actualSize = data.size(); + + HRESULT hr = XMemDecompress(ctx, output.data(), &actualSize, data.constData(), data.size()); + XMemDestroyDecompressionContext(ctx); + + if (FAILED(hr)) + return QByteArray(); + + output.resize(static_cast(actualSize)); + return output; +} + +quint32 Compression::CalculateAdler32Checksum(const QByteArray &data) { + // Start with the initial value for Adler-32 + quint32 adler = adler32(0L, Z_NULL, 0); + + // Calculate Adler-32 checksum + adler = adler32(adler, reinterpret_cast(data.constData()), data.size()); + + return adler; +} + +QByteArray Compression::DecompressZLIB(const QByteArray &aCompressedData) { + if (aCompressedData.isEmpty()) { + return {}; + } + + z_stream strm{}; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = static_cast(aCompressedData.size()); + strm.next_in = reinterpret_cast(const_cast(aCompressedData.data())); + + if (inflateInit2(&strm, MAX_WBITS) != Z_OK) { + qWarning() << "inflateInit2 failed"; + return {}; + } + + QByteArray decompressed; + QByteArray buffer(fmin(strm.avail_in * 2, 4096), Qt::Uninitialized); + + int ret; + do { + strm.next_out = reinterpret_cast(buffer.data()); + strm.avail_out = buffer.size(); + + ret = inflate(&strm, Z_NO_FLUSH); + + if (strm.avail_out < buffer.size()) { // Data has been written to the buffer + decompressed.append(buffer.constData(), buffer.size() - strm.avail_out); + } + + if (ret == Z_STREAM_END) { + break; // Proper end of the data stream + } + + if (ret == Z_BUF_ERROR && strm.avail_out == 0) { + // Buffer was completely used, resize it + int newSize = buffer.size() * 2; // Double the buffer size + buffer.resize(newSize); + } else if (ret != Z_OK) { + qWarning() << "Zlib error:" << zError(ret); + inflateEnd(&strm); + return {}; // Return on other errors + } + } while (ret != Z_STREAM_END); + + inflateEnd(&strm); + return decompressed; +} + +QByteArray Compression::CompressZLIB(const QByteArray &aData) { + return CompressZLIBWithSettings(aData); +} + +QByteArray Compression::CompressZLIBWithSettings(const QByteArray &aData, int aCompressionLevel, int aWindowBits, int aMemLevel, int aStrategy, const QByteArray &aDictionary) { + if (aData.isEmpty()) + return {}; + + z_stream strm{}; + if (deflateInit2(&strm, aCompressionLevel, Z_DEFLATED, aWindowBits, aMemLevel, aStrategy) != Z_OK) { + qWarning() << "Failed to initialize compression with custom settings."; + return {}; + } + + if (!aDictionary.isEmpty()) { + deflateSetDictionary(&strm, reinterpret_cast(aDictionary.constData()), aDictionary.size()); + } + + strm.next_in = reinterpret_cast(const_cast(aData.data())); + strm.avail_in = aData.size(); + + QByteArray compressed; + char buffer[4096]; + + int ret; + do { + strm.next_out = reinterpret_cast(buffer); + strm.avail_out = sizeof(buffer); + + ret = deflate(&strm, strm.avail_in ? Z_NO_FLUSH : Z_FINISH); + if (ret != Z_OK && ret != Z_STREAM_END) { + qWarning() << "Compression error:" << zError(ret); + deflateEnd(&strm); + return {}; + } + + compressed.append(buffer, sizeof(buffer) - strm.avail_out); + } while (ret != Z_STREAM_END); + + deflateEnd(&strm); + return compressed; +} + +QByteArray Compression::DecompressDeflate(const QByteArray &aCompressedData) { + if (aCompressedData.isEmpty()) + return {}; + + z_stream strm{}; + strm.next_in = reinterpret_cast(const_cast(aCompressedData.data())); + strm.avail_in = static_cast(aCompressedData.size()); + + // Negative window bits (-MAX_WBITS) indicate raw DEFLATE data. + if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) { + qWarning() << "Failed to initialize DEFLATE for decompression."; + return QByteArray(); + } + + QByteArray decompressed; + char buffer[4096]; + + int ret; + do { + strm.next_out = reinterpret_cast(buffer); + strm.avail_out = sizeof(buffer); + + ret = inflate(&strm, Z_NO_FLUSH); + + if (ret != Z_OK && ret != Z_STREAM_END) { + qWarning() << "DEFLATE decompression error:" << zError(ret); + inflateEnd(&strm); + return QByteArray(); + } + + decompressed.append(buffer, sizeof(buffer) - strm.avail_out); + } while (ret != Z_STREAM_END); + + inflateEnd(&strm); + return decompressed; +} + +QByteArray Compression::CompressDeflate(const QByteArray &aData) { + return CompressDeflateWithSettings(aData); +} + +QByteArray Compression::CompressDeflateWithSettings(const QByteArray &aData, int aCompressionLevel, int aWindowBits, int aMemLevel, int aStrategy, const QByteArray &aDictionary) { + Q_UNUSED(aDictionary); + + if (aData.isEmpty()) + return QByteArray(); + + z_stream strm{}; + + // Negative window bits (-MAX_WBITS) indicate raw DEFLATE data. + if (deflateInit2(&strm, aCompressionLevel, Z_DEFLATED, -aWindowBits, aMemLevel, aStrategy) != Z_OK) { + qWarning() << "Failed to initialize DEFLATE for compression."; + return QByteArray(); + } + + strm.next_in = reinterpret_cast(const_cast(aData.data())); + strm.avail_in = static_cast(aData.size()); + + QByteArray compressed; + char buffer[4096]; + + int ret; + do { + strm.next_out = reinterpret_cast(buffer); + strm.avail_out = sizeof(buffer); + + ret = deflate(&strm, strm.avail_in ? Z_NO_FLUSH : Z_FINISH); + + if (ret != Z_OK && ret != Z_STREAM_END) { + qWarning() << "DEFLATE compression error:" << zError(ret); + deflateEnd(&strm); + return {}; + } + + compressed.append(buffer, sizeof(buffer) - strm.avail_out); + } while (ret != Z_STREAM_END); + + deflateEnd(&strm); + return compressed; +} + +QByteArray Compression::DecompressOodle(const QByteArray &aCompressedData, quint32 aDecompressedSize) { + return pDecompressOodle(aCompressedData, aCompressedData.length(), aDecompressedSize); +} + +QByteArray Compression::CompressOodle(const QByteArray &aData) { + quint32 maxSize = pGetOodleCompressedBounds(aData.length()); + QByteArray compressedData = pCompressOodle(aData, aData.length(), + maxSize, OodleFormat::Kraken, OodleCompressionLevel::Optimal5); + + return compressedData.mid(0, maxSize); +} + +quint32 Compression::pGetOodleCompressedBounds(quint32 aBufferSize) { + return aBufferSize + 274 * ((aBufferSize + 0x3FFFF) / 0x400000); +} + +QByteArray Compression::pCompressOodle(QByteArray aBuffer, quint32 aBufferSize, quint32 aOutputBufferSize, OodleFormat aformat, OodleCompressionLevel alevel) { + QLibrary oodleLib("oo2core_8_win64"); + + if (!oodleLib.load()) { + qDebug() << "Failed to load DLL:" << oodleLib.errorString(); + return QByteArray(); + } + + OodleLZ_CompressFunc OodleLZ_Compress = + (OodleLZ_CompressFunc)oodleLib.resolve("OodleLZ_Compress"); + + if (!OodleLZ_Compress) { + qDebug() << "Failed to resolve function:" << oodleLib.errorString(); + return QByteArray(); + } + + std::byte *outputBuffer = new std::byte[aOutputBufferSize]; + + if (aBuffer.length() > 0 && aBufferSize > 0 && aOutputBufferSize > 0) + OodleLZ_Compress(aformat, reinterpret_cast(aBuffer.data()), aBufferSize, outputBuffer, alevel, 0, 0, 0); + + return QByteArray(reinterpret_cast(outputBuffer), aOutputBufferSize); +} + +QByteArray Compression::pDecompressOodle(QByteArray aBuffer, quint32 aBufferSize, quint32 aOutputBufferSize) { + QLibrary oodleLib("oo2core_8_win64"); + + if (!oodleLib.load()) { + qDebug() << "Failed to load DLL:" << oodleLib.errorString(); + return QByteArray(); + } + + OodleLZ_DecompressFunc OodleLZ_Decompress = + (OodleLZ_DecompressFunc)oodleLib.resolve("OodleLZ_Decompress"); + + if (!OodleLZ_Decompress) { + qDebug() << "Failed to resolve function:" << oodleLib.errorString(); + return QByteArray(); + } + + std::byte *outputBuffer = new std::byte[aOutputBufferSize]; + + if (aBuffer.length() > 0 && aBufferSize > 0 && aOutputBufferSize > 0) + OodleLZ_Decompress(reinterpret_cast(aBuffer.data()), aBufferSize, outputBuffer, aOutputBufferSize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + return QByteArray(reinterpret_cast(outputBuffer), aOutputBufferSize); +} diff --git a/libs/compression/compression.h b/libs/compression/compression.h new file mode 100644 index 0000000..6bdae3b --- /dev/null +++ b/libs/compression/compression.h @@ -0,0 +1,82 @@ +#ifndef COMPRESSION_H +#define COMPRESSION_H + +#include "QtZlib/zlib.h" + +#include +#include +#include +#include +#include +#include + +enum OodleFormat { + LZH = 0, + LZHLW = 1, + LZNIB = 2, + FormatNone = 3, + LZB16 = 4, + LZBLW = 5, + LZA = 6, + LZNA = 7, + Kraken = 8, + Mermaid = 9, + BitKnit = 10, + Selkie = 11, + Hydra = 12, + Leviathan = 13 +}; + +enum OodleCompressionLevel { + LevelNone = 0, + SuperFast = 1, + VeryFast = 2, + Fast = 3, + Normal = 4, + Optimal1 = 5, + Optimal2 = 6, + Optimal3 = 7, + Optimal4 = 8, + Optimal5 = 9 +}; + +typedef int (*OodleLZ_CompressFunc)(OodleFormat Format, std::byte *Buffer, long BufferSize, std::byte *OutputBuffer, OodleCompressionLevel Level, uint a, uint b, uint c); +typedef int (*OodleLZ_DecompressFunc)(std::byte* Buffer, long BufferSize, std::byte* OutputBuffer, long OutputBufferSize, uint a, uint b, uint c, uint d, uint e, uint f, uint g, uint h, uint i, int ThreadModule); + +class Compression { +public: + static quint32 CalculateAdler32Checksum(const QByteArray &data); + static QByteArray DecompressZLIB(const QByteArray &aCompressedData); + static QByteArray CompressZLIB(const QByteArray &aData); + static QByteArray CompressZLIBWithSettings(const QByteArray &aData, + int aCompressionLevel = Z_BEST_COMPRESSION, + int aWindowBits = MAX_WBITS, + int aMemLevel = 8, + int aStrategy = Z_DEFAULT_STRATEGY, + const QByteArray &aDictionary = {}); + + static QByteArray DecompressDeflate(const QByteArray &aCompressedData); + static QByteArray CompressDeflate(const QByteArray &aData); + static QByteArray CompressDeflateWithSettings(const QByteArray &aData, + int aCompressionLevel = Z_BEST_COMPRESSION, + int aWindowBits = MAX_WBITS, + int aMemLevel = 8, + int aStrategy = Z_DEFAULT_STRATEGY, + const QByteArray &aDictionary = {}); + + static QByteArray DecompressOodle(const QByteArray &aCompressedData, quint32 aDecompressedSize); + static QByteArray CompressOodle(const QByteArray &aData); + + + static QByteArray CompressXMem(const QByteArray &data); + static QByteArray DecompressXMem(const QByteArray &data); + +private: + static quint32 pGetOodleCompressedBounds(quint32 aBufferSize); + static QByteArray pCompressOodle(QByteArray aBuffer, quint32 aBufferSize, quint32 aOutputBufferSize, + OodleFormat aformat, OodleCompressionLevel alevel); + static QByteArray pDecompressOodle(QByteArray aBuffer, quint32 aBufferSize, quint32 aOutputBufferSize); +}; + + +#endif // COMPRESSION_H diff --git a/libs/compression/compression.pro b/libs/compression/compression.pro new file mode 100644 index 0000000..a585902 --- /dev/null +++ b/libs/compression/compression.pro @@ -0,0 +1,28 @@ +QT += core +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + compression.cpp \ + lzokay.cpp \ + +HEADERS += \ + compression.h \ + lzokay.h + +LIBS += \ + -L$$PWD/../../third_party/xbox_sdk/lib -lxcompress64 \ + -L$$OUT_PWD/../libs/core -lcore \ + -L$$OUT_PWD/../libs/encryption -lencryption + +INCLUDEPATH += \ + $$PWD/../../third_party/xbox_sdk/include \ + $$PWD/../core \ + $$PWD/../encryption + +DEPENDPATH += \ + $$PWD/../../third_party/xbox_sdk/include \ + $$PWD/../core \ + $$PWD/../encryption + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/compression/lzokay.cpp b/libs/compression/lzokay.cpp new file mode 100644 index 0000000..2bccc48 --- /dev/null +++ b/libs/compression/lzokay.cpp @@ -0,0 +1,647 @@ +#include "lzokay.h" +#include +#include +#include + +/* + * Based on documentation from the Linux sources: Documentation/lzo.txt + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/lzo.txt + */ + +namespace lzokay { + +#if _WIN32 +#define HOST_BIG_ENDIAN 0 +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define HOST_BIG_ENDIAN 1 +#else +#define HOST_BIG_ENDIAN 0 +#endif + +#if HOST_BIG_ENDIAN +static uint16_t get_le16(const uint8_t* p) { + uint16_t val = *reinterpret_cast(p); +#if __GNUC__ + return __builtin_bswap16(val); +#elif _WIN32 + return _byteswap_ushort(val); +#else + return (val = (val << 8) | ((val >> 8) & 0xFF)); +#endif +} +#else +static uint16_t get_le16(const uint8_t* p) { + return *reinterpret_cast(p); +} +#endif + +constexpr std::size_t Max255Count = std::size_t(~0) / 255 - 2; + +#define NEEDS_IN(count) \ +if (inp + (count) > inp_end) { \ + dst_size = outp - dst; \ + return EResult::InputOverrun; \ +} + +#define NEEDS_OUT(count) \ +if (outp + (count) > outp_end) { \ + dst_size = outp - dst; \ + return EResult::OutputOverrun; \ +} + +#define CONSUME_ZERO_BYTE_LENGTH \ +std::size_t offset; \ +{ \ + const uint8_t *old_inp = inp; \ + while (*inp == 0) ++inp; \ + offset = inp - old_inp; \ + if (offset > Max255Count) { \ + dst_size = outp - dst; \ + return EResult::Error; \ + } \ +} + +#define WRITE_ZERO_BYTE_LENGTH(length) \ +{ \ + std::size_t l; \ + for (l = length; l > 255; l -= 255) { *outp++ = 0; } \ + *outp++ = static_cast(l); \ +} + +constexpr uint32_t M1MaxOffset = 0x0400; +constexpr uint32_t M2MaxOffset = 0x0800; +constexpr uint32_t M3MaxOffset = 0x4000; +// constexpr uint32_t M4MaxOffset = 0xbfff; + +// constexpr uint32_t M1MinLen = 2; +// constexpr uint32_t M1MaxLen = 2; +constexpr uint32_t M2MinLen = 3; +constexpr uint32_t M2MaxLen = 8; +// constexpr uint32_t M3MinLen = 3; +constexpr uint32_t M3MaxLen = 33; +// constexpr uint32_t M4MinLen = 3; +constexpr uint32_t M4MaxLen = 9; + +constexpr uint32_t M1Marker = 0x0; +// constexpr uint32_t M2Marker = 0x40; +constexpr uint32_t M3Marker = 0x20; +constexpr uint32_t M4Marker = 0x10; + +constexpr uint32_t MaxMatchByLengthLen = 34; /* Max M3 len + 1 */ + +EResult decompress(const uint8_t* src, std::size_t src_size, + uint8_t* dst, std::size_t init_dst_size, + std::size_t& dst_size) { + dst_size = init_dst_size; + + if (src_size < 3) { + dst_size = 0; + return EResult::InputOverrun; + } + + const uint8_t* inp = src; + const uint8_t* inp_end = src + src_size; + uint8_t* outp = dst; + uint8_t* outp_end = dst + dst_size; + uint8_t* lbcur; + std::size_t lblen; + std::size_t state = 0; + std::size_t nstate = 0; + + /* First byte encoding */ + if (*inp >= 22) { + /* 22..255 : copy literal string + * length = (byte - 17) = 4..238 + * state = 4 [ don't copy extra literals ] + * skip byte + */ + std::size_t len = *inp++ - uint8_t(17); + NEEDS_IN(len) + NEEDS_OUT(len) + for (std::size_t i = 0; i < len; ++i) + *outp++ = *inp++; + state = 4; + } else if (*inp >= 18) { + /* 18..21 : copy 0..3 literals + * state = (byte - 17) = 0..3 [ copy literals ] + * skip byte + */ + nstate = *inp++ - uint8_t(17); + state = nstate; + NEEDS_IN(nstate) + NEEDS_OUT(nstate) + for (std::size_t i = 0; i < nstate; ++i) + *outp++ = *inp++; + } + /* 0..17 : follow regular instruction encoding, see below. It is worth + * noting that codes 16 and 17 will represent a block copy from + * the dictionary which is empty, and that they will always be + * invalid at this place. + */ + + while (true) { + NEEDS_IN(1) + uint8_t inst = *inp++; + if (inst & 0xC0) { + /* [M2] + * 1 L L D D D S S (128..255) + * Copy 5-8 bytes from block within 2kB distance + * state = S (copy S literals after this block) + * length = 5 + L + * Always followed by exactly one byte : H H H H H H H H + * distance = (H << 3) + D + 1 + * + * 0 1 L D D D S S (64..127) + * Copy 3-4 bytes from block within 2kB distance + * state = S (copy S literals after this block) + * length = 3 + L + * Always followed by exactly one byte : H H H H H H H H + * distance = (H << 3) + D + 1 + */ + NEEDS_IN(1) + lbcur = outp - ((*inp++ << 3) + ((inst >> 2) & 0x7) + 1); + lblen = std::size_t(inst >> 5) + 1; + nstate = inst & uint8_t(0x3); + } else if (inst & M3Marker) { + /* [M3] + * 0 0 1 L L L L L (32..63) + * Copy of small block within 16kB distance (preferably less than 34B) + * length = 2 + (L ?: 31 + (zero_bytes * 255) + non_zero_byte) + * Always followed by exactly one LE16 : D D D D D D D D : D D D D D D S S + * distance = D + 1 + * state = S (copy S literals after this block) + */ + lblen = std::size_t(inst & uint8_t(0x1f)) + 2; + if (lblen == 2) { + CONSUME_ZERO_BYTE_LENGTH + NEEDS_IN(1) + lblen += offset * 255 + 31 + *inp++; + } + NEEDS_IN(2) + nstate = get_le16(inp); + inp += 2; + lbcur = outp - ((nstate >> 2) + 1); + nstate &= 0x3; + } else if (inst & M4Marker) { + /* [M4] + * 0 0 0 1 H L L L (16..31) + * Copy of a block within 16..48kB distance (preferably less than 10B) + * length = 2 + (L ?: 7 + (zero_bytes * 255) + non_zero_byte) + * Always followed by exactly one LE16 : D D D D D D D D : D D D D D D S S + * distance = 16384 + (H << 14) + D + * state = S (copy S literals after this block) + * End of stream is reached if distance == 16384 + */ + lblen = std::size_t(inst & uint8_t(0x7)) + 2; + if (lblen == 2) { + CONSUME_ZERO_BYTE_LENGTH + NEEDS_IN(1) + lblen += offset * 255 + 7 + *inp++; + } + NEEDS_IN(2) + nstate = get_le16(inp); + inp += 2; + lbcur = outp - (((inst & 0x8) << 11) + (nstate >> 2)); + nstate &= 0x3; + if (lbcur == outp) + break; /* Stream finished */ + lbcur -= 16384; + } else { + /* [M1] Depends on the number of literals copied by the last instruction. */ + if (state == 0) { + /* If last instruction did not copy any literal (state == 0), this + * encoding will be a copy of 4 or more literal, and must be interpreted + * like this : + * + * 0 0 0 0 L L L L (0..15) : copy long literal string + * length = 3 + (L ?: 15 + (zero_bytes * 255) + non_zero_byte) + * state = 4 (no extra literals are copied) + */ + std::size_t len = inst + 3; + if (len == 3) { + CONSUME_ZERO_BYTE_LENGTH + NEEDS_IN(1) + len += offset * 255 + 15 + *inp++; + } + /* copy_literal_run */ + NEEDS_IN(len) + NEEDS_OUT(len) + for (std::size_t i = 0; i < len; ++i) + *outp++ = *inp++; + state = 4; + continue; + } else if (state != 4) { + /* If last instruction used to copy between 1 to 3 literals (encoded in + * the instruction's opcode or distance), the instruction is a copy of a + * 2-byte block from the dictionary within a 1kB distance. It is worth + * noting that this instruction provides little savings since it uses 2 + * bytes to encode a copy of 2 other bytes but it encodes the number of + * following literals for free. It must be interpreted like this : + * + * 0 0 0 0 D D S S (0..15) : copy 2 bytes from <= 1kB distance + * length = 2 + * state = S (copy S literals after this block) + * Always followed by exactly one byte : H H H H H H H H + * distance = (H << 2) + D + 1 + */ + NEEDS_IN(1) + nstate = inst & uint8_t(0x3); + lbcur = outp - ((inst >> 2) + (*inp++ << 2) + 1); + lblen = 2; + } else { + /* If last instruction used to copy 4 or more literals (as detected by + * state == 4), the instruction becomes a copy of a 3-byte block from the + * dictionary from a 2..3kB distance, and must be interpreted like this : + * + * 0 0 0 0 D D S S (0..15) : copy 3 bytes from 2..3 kB distance + * length = 3 + * state = S (copy S literals after this block) + * Always followed by exactly one byte : H H H H H H H H + * distance = (H << 2) + D + 2049 + */ + NEEDS_IN(1) + nstate = inst & uint8_t(0x3); + lbcur = outp - ((inst >> 2) + (*inp++ << 2) + 2049); + lblen = 3; + } + } + if (lbcur < dst) { + dst_size = outp - dst; + return EResult::LookbehindOverrun; + } + NEEDS_IN(nstate) + NEEDS_OUT(lblen + nstate) + /* Copy lookbehind */ + for (std::size_t i = 0; i < lblen; ++i) + *outp++ = *lbcur++; + state = nstate; + /* Copy literal */ + for (std::size_t i = 0; i < nstate; ++i) + *outp++ = *inp++; + } + + dst_size = outp - dst; + if (lblen != 3) /* Ensure terminating M4 was encountered */ + return EResult::Error; + if (inp == inp_end) + return EResult::Success; + else if (inp < inp_end) + return EResult::InputNotConsumed; + else + return EResult::InputOverrun; +} + +struct State { + const uint8_t* src; + const uint8_t* src_end; + const uint8_t* inp; + uint32_t wind_sz; + uint32_t wind_b; + uint32_t wind_e; + uint32_t cycle1_countdown; + + const uint8_t* bufp; + uint32_t buf_sz; + + /* Access next input byte and advance both ends of circular buffer */ + void get_byte(uint8_t* buf) { + if (inp >= src_end) { + if (wind_sz > 0) + --wind_sz; + buf[wind_e] = 0; + if (wind_e < DictBase::MaxMatchLen) + buf[DictBase::BufSize + wind_e] = 0; + } else { + buf[wind_e] = *inp; + if (wind_e < DictBase::MaxMatchLen) + buf[DictBase::BufSize + wind_e] = *inp; + ++inp; + } + if (++wind_e == DictBase::BufSize) + wind_e = 0; + if (++wind_b == DictBase::BufSize) + wind_b = 0; + } + + uint32_t pos2off(uint32_t pos) const { + return wind_b > pos ? wind_b - pos : DictBase::BufSize - (pos - wind_b); + } +}; + +class DictImpl : public DictBase { +public: + struct Match3Impl : DictBase::Match3 { + static uint32_t make_key(const uint8_t* data) { + return ((0x9f5f * (((uint32_t(data[0]) << 5 ^ uint32_t(data[1])) << 5) ^ data[2])) >> 5) & 0x3fff; + } + + uint16_t get_head(uint32_t key) const { + return (chain_sz[key] == 0) ? uint16_t(UINT16_MAX) : head[key]; + } + + void init() { + std::fill(std::begin(chain_sz), std::end(chain_sz), 0); + } + + void remove(uint32_t pos, const uint8_t* b) { + --chain_sz[make_key(b + pos)]; + } + + void advance(State& s, uint32_t& match_pos, uint32_t& match_count, const uint8_t* b) { + uint32_t key = make_key(b + s.wind_b); + match_pos = chain[s.wind_b] = get_head(key); + match_count = chain_sz[key]++; + if (match_count > DictBase::MaxMatchLen) + match_count = DictBase::MaxMatchLen; + head[key] = uint16_t(s.wind_b); + } + + void skip_advance(State& s, const uint8_t* b) { + uint32_t key = make_key(b + s.wind_b); + chain[s.wind_b] = get_head(key); + head[key] = uint16_t(s.wind_b); + best_len[s.wind_b] = uint16_t(DictBase::MaxMatchLen + 1); + chain_sz[key]++; + } + }; + + struct Match2Impl : DictBase::Match2 { + static uint32_t make_key(const uint8_t* data) { + return uint32_t(data[0]) ^ (uint32_t(data[1]) << 8); + } + + void init() { + std::fill(std::begin(head), std::end(head), UINT16_MAX); + } + + void add(uint16_t pos, const uint8_t* b) { + head[make_key(b + pos)] = pos; + } + + void remove(uint32_t pos, const uint8_t* b) { + uint16_t& p = head[make_key(b + pos)]; + if (p == pos) + p = UINT16_MAX; + } + + bool search(State& s, uint32_t& lb_pos, uint32_t& lb_len, + uint32_t best_pos[MaxMatchByLengthLen], const uint8_t* b) const { + uint16_t pos = head[make_key(b + s.wind_b)]; + if (pos == UINT16_MAX) + return false; + if (best_pos[2] == 0) + best_pos[2] = pos + 1; + if (lb_len < 2) { + lb_len = 2; + lb_pos = pos; + } + return true; + } + }; + + void init(State& s, const uint8_t* src, std::size_t src_size) { + auto& match3 = static_cast(_storage->match3); + auto& match2 = static_cast(_storage->match2); + + s.cycle1_countdown = DictBase::MaxDist; + match3.init(); + match2.init(); + + s.src = src; + s.src_end = src + src_size; + s.inp = src; + s.wind_sz = uint32_t(std::min(src_size, std::size_t(MaxMatchLen))); + s.wind_b = 0; + s.wind_e = s.wind_sz; + std::copy_n(s.inp, s.wind_sz, _storage->buffer); + s.inp += s.wind_sz; + + if (s.wind_e == DictBase::BufSize) + s.wind_e = 0; + + if (s.wind_sz < 3) + std::fill_n(_storage->buffer + s.wind_b + s.wind_sz, 3, 0); + } + + void reset_next_input_entry(State& s, Match3Impl& match3, Match2Impl& match2) { + /* Remove match from about-to-be-clobbered buffer entry */ + if (s.cycle1_countdown == 0) { + match3.remove(s.wind_e, _storage->buffer); + match2.remove(s.wind_e, _storage->buffer); + } else { + --s.cycle1_countdown; + } + } + + void advance(State& s, uint32_t& lb_off, uint32_t& lb_len, + uint32_t best_off[MaxMatchByLengthLen], bool skip) { + auto& match3 = static_cast(_storage->match3); + auto& match2 = static_cast(_storage->match2); + + if (skip) { + for (uint32_t i = 0; i < lb_len - 1; ++i) { + reset_next_input_entry(s, match3, match2); + match3.skip_advance(s, _storage->buffer); + match2.add(uint16_t(s.wind_b), _storage->buffer); + s.get_byte(_storage->buffer); + } + } + + lb_len = 1; + lb_off = 0; + uint32_t lb_pos; + + uint32_t best_pos[MaxMatchByLengthLen] = {}; + uint32_t match_pos, match_count; + match3.advance(s, match_pos, match_count, _storage->buffer); + + int best_char = _storage->buffer[s.wind_b]; + uint32_t best_len = lb_len; + if (lb_len >= s.wind_sz) { + if (s.wind_sz == 0) + best_char = -1; + lb_off = 0; + match3.best_len[s.wind_b] = DictBase::MaxMatchLen + 1; + } else { + if (match2.search(s, lb_pos, lb_len, best_pos, _storage->buffer) && s.wind_sz >= 3) { + for (uint32_t i = 0; i < match_count; ++i, match_pos = match3.chain[match_pos]) { + auto ref_ptr = _storage->buffer + s.wind_b; + auto match_ptr = _storage->buffer + match_pos; + auto mismatch = std::mismatch(ref_ptr, ref_ptr + s.wind_sz, match_ptr); + auto match_len = uint32_t(mismatch.first - ref_ptr); + if (match_len < 2) + continue; + if (match_len < MaxMatchByLengthLen && best_pos[match_len] == 0) + best_pos[match_len] = match_pos + 1; + if (match_len > lb_len) { + lb_len = match_len; + lb_pos = match_pos; + if (match_len == s.wind_sz || match_len > match3.best_len[match_pos]) + break; + } + } + } + if (lb_len > best_len) + lb_off = s.pos2off(lb_pos); + match3.best_len[s.wind_b] = uint16_t(lb_len); + for (auto posit = std::begin(best_pos) + 2, offit = best_off + 2; + posit != std::end(best_pos); ++posit, ++offit) { + *offit = (*posit > 0) ? s.pos2off(*posit - 1) : 0; + } + } + + reset_next_input_entry(s, match3, match2); + + match2.add(uint16_t(s.wind_b), _storage->buffer); + + s.get_byte(_storage->buffer); + + if (best_char < 0) { + s.buf_sz = 0; + lb_len = 0; + /* Signal exit */ + } else { + s.buf_sz = s.wind_sz + 1; + } + s.bufp = s.inp - s.buf_sz; + } +}; + +static void find_better_match(const uint32_t best_off[MaxMatchByLengthLen], uint32_t& lb_len, uint32_t& lb_off) { + if (lb_len <= M2MinLen || lb_off <= M2MaxOffset) + return; + if (lb_off > M2MaxOffset && lb_len >= M2MinLen + 1 && lb_len <= M2MaxLen + 1 && + best_off[lb_len - 1] != 0 && best_off[lb_len - 1] <= M2MaxOffset) { + lb_len -= 1; + lb_off = best_off[lb_len]; + } else if (lb_off > M3MaxOffset && lb_len >= M4MaxLen + 1 && lb_len <= M2MaxLen + 2 && + best_off[lb_len - 2] && best_off[lb_len] <= M2MaxOffset) { + lb_len -= 2; + lb_off = best_off[lb_len]; + } else if (lb_off > M3MaxOffset && lb_len >= M4MaxLen + 1 && lb_len <= M3MaxLen + 1 && + best_off[lb_len - 1] != 0 && best_off[lb_len - 2] <= M3MaxOffset) { + lb_len -= 1; + lb_off = best_off[lb_len]; + } +} + +static EResult encode_literal_run(uint8_t*& outp, const uint8_t* outp_end, const uint8_t* dst, std::size_t& dst_size, + const uint8_t* lit_ptr, uint32_t lit_len) { + if (outp == dst && lit_len <= 238) { + NEEDS_OUT(1); + *outp++ = uint8_t(17 + lit_len); + } else if (lit_len <= 3) { + outp[-2] = uint8_t(outp[-2] | lit_len); + } else if (lit_len <= 18) { + NEEDS_OUT(1); + *outp++ = uint8_t(lit_len - 3); + } else { + NEEDS_OUT((lit_len - 18) / 255 + 2); + *outp++ = 0; + WRITE_ZERO_BYTE_LENGTH(lit_len - 18); + } + NEEDS_OUT(lit_len); + outp = std::copy_n(lit_ptr, lit_len, outp); + return EResult::Success; +} + +static EResult encode_lookback_match(uint8_t*& outp, const uint8_t* outp_end, const uint8_t* dst, std::size_t& dst_size, + uint32_t lb_len, uint32_t lb_off, uint32_t last_lit_len) { + if (lb_len == 2) { + lb_off -= 1; + NEEDS_OUT(2); + *outp++ = uint8_t(M1Marker | ((lb_off & 0x3) << 2)); + *outp++ = uint8_t(lb_off >> 2); + } else if (lb_len <= M2MaxLen && lb_off <= M2MaxOffset) { + lb_off -= 1; + NEEDS_OUT(2); + *outp++ = uint8_t((lb_len - 1) << 5 | ((lb_off & 0x7) << 2)); + *outp++ = uint8_t(lb_off >> 3); + } else if (lb_len == M2MinLen && lb_off <= M1MaxOffset + M2MaxOffset && last_lit_len >= 4) { + lb_off -= 1 + M2MaxOffset; + NEEDS_OUT(2); + *outp++ = uint8_t(M1Marker | ((lb_off & 0x3) << 2)); + *outp++ = uint8_t(lb_off >> 2); + } else if (lb_off <= M3MaxOffset) { + lb_off -= 1; + if (lb_len <= M3MaxLen) { + NEEDS_OUT(1); + *outp++ = uint8_t(M3Marker | (lb_len - 2)); + } else { + lb_len -= M3MaxLen; + NEEDS_OUT(lb_len / 255 + 2); + *outp++ = uint8_t(M3Marker); + WRITE_ZERO_BYTE_LENGTH(lb_len); + } + NEEDS_OUT(2); + *outp++ = uint8_t(lb_off << 2); + *outp++ = uint8_t(lb_off >> 6); + } else { + lb_off -= 0x4000; + if (lb_len <= M4MaxLen) { + NEEDS_OUT(1); + *outp++ = uint8_t(M4Marker | ((lb_off & 0x4000) >> 11) | (lb_len - 2)); + } else { + lb_len -= M4MaxLen; + NEEDS_OUT(lb_len / 255 + 2); + *outp++ = uint8_t(M4Marker | ((lb_off & 0x4000) >> 11)); + WRITE_ZERO_BYTE_LENGTH(lb_len); + } + NEEDS_OUT(2); + *outp++ = uint8_t(lb_off << 2); + *outp++ = uint8_t(lb_off >> 6); + } + return EResult::Success; +} + +EResult compress(const uint8_t* src, std::size_t src_size, + uint8_t* dst, std::size_t init_dst_size, + std::size_t& dst_size, DictBase& dict) { + EResult err; + State s; + auto& d = static_cast(dict); + dst_size = init_dst_size; + uint8_t* outp = dst; + uint8_t* outp_end = dst + dst_size; + uint32_t lit_len = 0; + uint32_t lb_off, lb_len; + uint32_t best_off[MaxMatchByLengthLen]; + d.init(s, src, src_size); + const uint8_t* lit_ptr = s.inp; + d.advance(s, lb_off, lb_len, best_off, false); + while (s.buf_sz > 0) { + if (lit_len == 0) + lit_ptr = s.bufp; + if (lb_len < 2 || (lb_len == 2 && (lb_off > M1MaxOffset || lit_len == 0 || lit_len >= 4)) || + (lb_len == 2 && outp == dst) || (outp == dst && lit_len == 0)) { + lb_len = 0; + } else if (lb_len == M2MinLen && lb_off > M1MaxOffset + M2MaxOffset && lit_len >= 4) { + lb_len = 0; + } + if (lb_len == 0) { + ++lit_len; + d.advance(s, lb_off, lb_len, best_off, false); + continue; + } + find_better_match(best_off, lb_len, lb_off); + if ((err = encode_literal_run(outp, outp_end, dst, dst_size, lit_ptr, lit_len)) < EResult::Success) + return err; + if ((err = encode_lookback_match(outp, outp_end, dst, dst_size, lb_len, lb_off, lit_len)) < EResult::Success) + return err; + lit_len = 0; + d.advance(s, lb_off, lb_len, best_off, true); + } + if ((err = encode_literal_run(outp, outp_end, dst, dst_size, lit_ptr, lit_len)) < EResult::Success) + return err; + + /* Terminating M4 */ + NEEDS_OUT(3); + *outp++ = M4Marker | 1; + *outp++ = 0; + *outp++ = 0; + + dst_size = outp - dst; + return EResult::Success; +} + +} diff --git a/libs/compression/lzokay.h b/libs/compression/lzokay.h new file mode 100644 index 0000000..522edd8 --- /dev/null +++ b/libs/compression/lzokay.h @@ -0,0 +1,79 @@ +#pragma once +#include +#include +#include + +namespace lzokay { + +enum class EResult { + LookbehindOverrun = -4, + OutputOverrun = -3, + InputOverrun = -2, + Error = -1, + Success = 0, + InputNotConsumed = 1, +}; + +class DictBase { +protected: + static constexpr uint32_t HashSize = 0x4000; + static constexpr uint32_t MaxDist = 0xbfff; + static constexpr uint32_t MaxMatchLen = 0x800; + static constexpr uint32_t BufSize = MaxDist + MaxMatchLen; + + /* List encoding of previous 3-byte data matches */ + struct Match3 { + uint16_t head[HashSize]; /* key -> chain-head-pos */ + uint16_t chain_sz[HashSize]; /* key -> chain-size */ + uint16_t chain[BufSize]; /* chain-pos -> next-chain-pos */ + uint16_t best_len[BufSize]; /* chain-pos -> best-match-length */ + }; + /* Encoding of 2-byte data matches */ + struct Match2 { + uint16_t head[1 << 16]; /* 2-byte-data -> head-pos */ + }; + + struct Data { + Match3 match3; + Match2 match2; + + /* Circular buffer caching enough data to access the maximum lookback + * distance of 48K + maximum match length of 2K. An additional 2K is + * allocated so the start of the buffer may be replicated at the end, + * therefore providing efficient circular access. + */ + uint8_t buffer[BufSize + MaxMatchLen]; + }; + using storage_type = Data; + storage_type* _storage; + DictBase() = default; + friend struct State; + friend EResult compress(const uint8_t* src, std::size_t src_size, + uint8_t* dst, std::size_t& dst_size, DictBase& dict); +}; +template class _Alloc = std::allocator> +class Dict : public DictBase { + _Alloc _allocator; +public: + Dict() { _storage = _allocator.allocate(1); } + ~Dict() { _allocator.deallocate(_storage, 1); } +}; + +EResult decompress(const uint8_t* src, std::size_t src_size, + uint8_t* dst, std::size_t dst_size, + std::size_t& out_size); +EResult compress(const uint8_t* src, std::size_t src_size, + uint8_t* dst, std::size_t dst_size, + std::size_t& out_size, DictBase& dict); +inline EResult compress(const uint8_t* src, std::size_t src_size, + uint8_t* dst, std::size_t dst_size, + std::size_t& out_size) { + Dict<> dict; + return compress(src, src_size, dst, dst_size, out_size, dict); +} + +constexpr std::size_t compress_worst_size(std::size_t s) { + return s + s / 16 + 64 + 3; +} + +} diff --git a/libs/core/core.pro b/libs/core/core.pro new file mode 100644 index 0000000..8cb5e5d --- /dev/null +++ b/libs/core/core.pro @@ -0,0 +1,16 @@ +QT += core widgets +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + logmanager.cpp \ + statusbarmanager.cpp + +HEADERS += \ + enums.h \ + logmanager.h \ + stringutils.h \ + utils.h \ + statusbarmanager.h + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/core/enums.h b/libs/core/enums.h new file mode 100644 index 0000000..92a9739 --- /dev/null +++ b/libs/core/enums.h @@ -0,0 +1,878 @@ +#ifndef ENUMS_H +#define ENUMS_H + +#include + +enum FF_PLATFORM { + FF_PLATFORM_NONE = 0x00, // No platform + FF_PLATFORM_XBOX = 0x01, // Xbox 360 + FF_PLATFORM_PS3 = 0x02, // Playstation 3 + FF_PLATFORM_PC = 0x03, // PC + FF_PLATFORM_WII = 0x04, // WII + FF_PLATFORM_WIIU = 0x05 // WII U +}; + +enum FF_GAME { + FF_GAME_NONE = 0x00, // No game + FF_GAME_COD1 = 0x01, // Call of Duty + FF_GAME_COD2 = 0x02, // Call of Duty 2 + FF_GAME_COD3 = 0x03, // Call of Duty 3 + FF_GAME_COD4 = 0x04, // Modern Warware 1 + FF_GAME_COD5 = 0x05, // World at War + FF_GAME_COD6 = 0x06, // Modern Warfare 2 + FF_GAME_COD7 = 0x07, // Black Ops 1 + FF_GAME_COD8 = 0x08, // Modern Warfare 3 + FF_GAME_COD9 = 0x09, // Black Ops 2 +}; + +enum IWI_VERSION { + IWI_VERSION_COD2 = 0x05, // 05 CoD2 + IWI_VERSION_COD4 = 0x06, // 06 CoD4 + IWI_VERSION_COD5 = 0x06, // 06 CoD5 + IWI_VERSION_CODMW2 = 0x08, // 08 CoDMW2 + IWI_VERSION_CODMW3 = 0x08, // 08 CoDMW3 + IWI_VERSION_CODBO1 = 0x0D, // 13 CoDBO1 + IWI_VERSION_CODBO2 = 0x1B, // 27 CoDBO2 +}; + +enum IWI_FORMAT { + // IWI Format + IWI_FORMAT_ARGB32 = 0x01, // 01 ARGB32 + IWI_FORMAT_RGB24 = 0x02, // 02 RGB24 + IWI_FORMAT_GA16 = 0x03, // 03 GA16 + IWI_FORMAT_A8 = 0x04, // 04 A8 + IWI_FORMAT_DXT1 = 0x0B, // 11 DXT1 + IWI_FORMAT_DXT3 = 0x0C, // 12 DXT3 + IWI_FORMAT_DXT5 = 0x0D // 13 DXT5 +}; + +enum DDS_FLAGS { + DDSD_CAPS = 0x1, + DDSD_HEIGHT = 0x2, + DDSD_WIDTH = 0x4, + DDSD_PITCH = 0x8, + DDSD_PIXELFORMAT = 0x1000, + DDSD_MIPMAPCOUNT = 0x20000, + DDSD_LINEARSIZE = 0x80000, + DDSD_DEPTH = 0x800000 +}; + +enum DDS_PIXELFORMAT_FLAGS { + DDPF_ALPHAPIXELS = 0x1, + DDPF_ALPHA = 0x2, + DDPF_FOURCC = 0x4, + DDPF_RGB = 0x40, + DDPF_YUV = 0x200, + DDPF_LUMINANCE = 0x20000 +}; + +enum DDS_CAPS_FLAGS { + DDSCAPS_COMPLEX = 0x8, + DDSCAPS_MIPMAP = 0x400000, + DDSCAPS_TEXTURE = 0x1000 +}; + +enum DDS_CAPS2_FLAGS { + DDSCAPS2_CUBEMAP = 0x200, // Indicates a cubemap. + DDSCAPS2_CUBEMAP_POSITIVEX = 0x400, + DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800, + DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000, + DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000, + DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000, + DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000, + DDSCAPS2_VOLUME = 0x200000 // Indicates that the texture is a volume texture. +}; + +enum LUMP_TYPE +{ + LUMP_MATERIALS = 0x0, + LUMP_LIGHTBYTES = 0x1, + LUMP_LIGHTGRIDENTRIES = 0x2, + LUMP_LIGHTGRIDCOLORS = 0x3, + LUMP_PLANES = 0x4, + LUMP_BRUSHSIDES = 0x5, + LUMP_BRUSHSIDEEDGECOUNTS = 0x6, + LUMP_BRUSHEDGES = 0x7, + LUMP_BRUSHES = 0x8, + LUMP_TRIANGLES = 0x9, + LUMP_DRAWVERTS = 0xA, + LUMP_DRAWINDICES = 0xB, + LUMP_CULLGROUPS = 0xC, + LUMP_CULLGROUPINDICES = 0xD, + LUMP_OBSOLETE_1 = 0xE, + LUMP_OBSOLETE_2 = 0xF, + LUMP_OBSOLETE_3 = 0x10, + LUMP_OBSOLETE_4 = 0x11, + LUMP_OBSOLETE_5 = 0x12, + LUMP_PORTALVERTS = 0x13, + LUMP_OBSOLETE_6 = 0x14, + LUMP_UINDS = 0x15, + LUMP_BRUSHVERTSCOUNTS = 0x16, + LUMP_BRUSHVERTS = 0x17, + LUMP_AABBTREES = 0x18, + LUMP_CELLS = 0x19, + LUMP_PORTALS = 0x1A, + LUMP_NODES = 0x1B, + LUMP_LEAFS = 0x1C, + LUMP_LEAFBRUSHES = 0x1D, + LUMP_LEAFSURFACES = 0x1E, + LUMP_COLLISIONVERTS = 0x1F, + LUMP_COLLISIONTRIS = 0x20, + LUMP_COLLISIONEDGEWALKABLE = 0x21, + LUMP_COLLISIONBORDERS = 0x22, + LUMP_COLLISIONPARTITIONS = 0x23, + LUMP_COLLISIONAABBS = 0x24, + LUMP_MODELS = 0x25, + LUMP_VISIBILITY = 0x26, + LUMP_ENTITIES = 0x27, + LUMP_PATHCONNECTIONS = 0x28, + LUMP_REFLECTION_PROBES = 0x29, + LUMP_VERTEX_LAYER_DATA = 0x2A, + LUMP_PRIMARY_LIGHTS = 0x2B, + LUMP_LIGHTGRIDHEADER = 0x2C, + LUMP_LIGHTGRIDROWS = 0x2D, + LUMP_OBSOLETE_10 = 0x2E, + + //Obsolete in BO1///////////////// + LUMP_UNLAYERED_TRIANGLES = 0x2F, + LUMP_UNLAYERED_DRAWVERTS = 0x30, + LUMP_UNLAYERED_DRAWINDICES = 0x31, + LUMP_UNLAYERED_CULLGROUPS = 0x32, + LUMP_UNLAYERED_AABBTREES = 0x33, + ////////////////////////////////// + + LUMP_WATERHEADER = 0x34, + LUMP_WATERCELLS = 0x35, + LUMP_WATERCELLDATA = 0x36, + LUMP_BURNABLEHEADER = 0x37, + LUMP_BURNABLECELLS = 0x38, + LUMP_BURNABLECELLDATA = 0x39, + LUMP_SIMPLELIGHTMAPBYTES = 0x3A, + LUMP_LODCHAINS = 0x3B, + LUMP_LODINFOS = 0x3C, + LUMP_LODSURFACES = 0x3D, + LUMP_LIGHTREGIONS = 0x3E, + LUMP_LIGHTREGION_HULLS = 0x3F, + LUMP_LIGHTREGION_AXES = 0x40, + LUMP_WIILIGHTGRID = 0x41, + LUMP_LIGHTGRID2D_LIGHTS = 0x42, + LUMP_LIGHTGRID2D_INDICES = 0x43, + LUMP_LIGHTGRID2D_POINTS = 0x44, + LUMP_LIGHTGRID2D_CELLS = 0x45, + LUMP_LIGHT_CORONAS = 0x46, + + //BO Specific///////////////////////// + LUMP_SHADOWMAP_VOLUMES = 0x47, + LUMP_SHADOWMAP_VOLUME_PLANES = 0x48, + LUMP_EXPOSURE_VOLUMES = 0x49, + LUMP_EXPOSURE_VOLUME_PLANES = 0x4A, + LUMP_OCCLUDERS = 0x4B, + LUMP_OUTDOORBOUNDS = 0x4C, + LUMP_HERO_ONLY_LIGHTS = 0x4D, + ////////////////////////////////////// + + INFO_LUMP_TYPE_COUNT +}; + +enum BSPVERSION_TYPE +{ + BSPVERSION_COD_WAW = 31, + BSPVERSION_COD_BO = 45 +}; + +enum FF_COMPANY { + COMPANY_NONE = 0x00, + COMPANY_INFINITY_WARD = 0x01, + COMPANY_TREYARCH = 0x02, + COMPANY_SLEDGEHAMMER = 0x03, + COMPANY_NEVERSOFT = 0x04 +}; + +enum FF_FILETYPE { + FILETYPE_NONE = 0x00, + FILETYPE_FAST_FILE = 0x01 +}; + +enum FF_SIGNAGE { + SIGNAGE_NONE = 0x00, + SIGNAGE_SIGNED = 0x01, + SIGNAGE_UNSIGNED = 0x02 +}; + +enum IMAGE_COMPRESSION { + COMPRESSION_NONE = 0x00, + COMPRESSION_DXT1 = 0x01, + COMPRESSION_DXT3 = 0x02, + COMPRESSION_DXT5 = 0x03 +}; +enum MENU_ITEM_TYPE { + ITEM_TYPE_TEXT = 0, // simple text + ITEM_TYPE_BUTTON = 1, // button, basically text with a border + ITEM_TYPE_RADIOBUTTON = 2, // toggle button, may be grouped + ITEM_TYPE_CHECKBOX = 3, // check box + ITEM_TYPE_EDITFIELD = 4, // editable text, associated with a dvar + ITEM_TYPE_COMBO = 5, // drop down list + ITEM_TYPE_LISTBOX = 6, // scrollable list + ITEM_TYPE_MODEL = 7, // model + ITEM_TYPE_OWNERDRAW = 8, // owner draw, name specs what it is + ITEM_TYPE_NUMERICFIELD = 9, // editable text, associated with a dvar + ITEM_TYPE_SLIDER = 10, // mouse speed, volume, etc. + ITEM_TYPE_YESNO = 11, // yes no dvar setting + ITEM_TYPE_MULTI = 12, // multiple list setting, enumerated + ITEM_TYPE_DVARENUM = 13, // multiple list setting, enumerated from a dvar + ITEM_TYPE_BIND = 14, // bind + ITEM_TYPE_MENUMODEL = 15, // special menu model + ITEM_TYPE_VALIDFILEFIELD = 16, // text must be valid for use in a dos filename + ITEM_TYPE_DECIMALFIELD = 17, // editable text, associated with a dvar, which allows decimal input + ITEM_TYPE_UPREDITFIELD = 18, // editable text, associated with a dvar + ITEM_TYPE_GAME_MESSAGE_WINDOW = 19, // game message window + ITEM_TYPE_SCALEFORM = 20, // Flash movie for Scaleform GFx + ITEM_TYPE_BIND2 = 21, // bind2 +}; + +enum MENU_ITEM_H_ALIGN { + ITEM_ALIGN_LEFT = 0, // aligns left of text to left of containing rectangle + ITEM_ALIGN_CENTER = 1, // aligns center of text to center of containing rectangle + ITEM_ALIGN_RIGHT = 2, // aligns right of text to right of containing rectangle + ITEM_ALIGN_X_MASK = 3, +}; + +enum MENU_ITEM_V_ALIGN { + ITEM_ALIGN_LEGACY = 0, // aligns bottom of text to top of containing rectangle + ITEM_ALIGN_TOP = 4, // aligns top of text to top of containing rectangle + ITEM_ALIGN_MIDDLE = 8, // aligns middle of text to middle of containing rectangle + ITEM_ALIGN_BOTTOM = 12, // aligns bottom of text to bottom of containing rectangle + ITEM_ALIGN_Y_MASK = 12, +}; + +enum MENU_ITEM_ALIGN { + ITEM_ALIGN_LEGACY_LEFT = 0, + ITEM_ALIGN_LEGACY_CENTER = 1, + ITEM_ALIGN_LEGACY_RIGHT = 2, + ITEM_ALIGN_TOP_LEFT = 4, + ITEM_ALIGN_TOP_CENTER = 5, + ITEM_ALIGN_TOP_RIGHT = 6, + ITEM_ALIGN_MIDDLE_LEFT = 8, + ITEM_ALIGN_MIDDLE_CENTER = 9, + ITEM_ALIGN_MIDDLE_RIGHT = 10, + ITEM_ALIGN_BOTTOM_LEFT = 12, + ITEM_ALIGN_BOTTOM_CENTER = 13, + ITEM_ALIGN_BOTTOM_RIGHT = 14 +}; + +enum MENU_ITEM_TEXTSTYLE { + ITEM_TEXTSTYLE_NORMAL = 0, // normal text + ITEM_TEXTSTYLE_BLINK = 1, // fast blinking + ITEM_TEXTSTYLE_SHADOWED = 3, // drop shadow ( need a color for this ) + ITEM_TEXTSTYLE_SHADOWEDMORE = 6, // drop shadow ( need a color for this ) + ITEM_TEXTSTYLE_MONOSPACE = 128 +}; + +enum MENU_WINDOW_BORDER { + WINDOW_BORDER_NONE = 0, // no border + WINDOW_BORDER_FULL = 1, // full border based on border color ( single pixel ) + WINDOW_BORDER_HORZ = 2, // horizontal borders only + WINDOW_BORDER_VERT = 3, // vertical borders only + WINDOW_BORDER_KCGRADIENT = 4, // horizontal border using the gradient bars + WINDOW_BORDER_RAISED = 5, // darken the bottom and right sides of the border + WINDOW_BORDER_SUNKEN = 6 // darken the top and left sides of the border +}; + +enum MENU_WINDOW_STYLE { + WINDOW_STYLE_EMPTY = 0, // no background + WINDOW_STYLE_FILLED = 1, // filled with background color + WINDOW_STYLE_GRADIENT = 2, // gradient bar based on background color + WINDOW_STYLE_SHADER = 3, // shader based on background color + WINDOW_STYLE_TEAMCOLOR = 4, // team color + WINDOW_STYLE_DVAR_SHADER = 5, // draws the shader specified by the dvar + WINDOW_STYLE_LOADBAR = 6, // shader based on background color +}; + +enum MENU_MODE { + MODE_BOTTOMUP_ALIGN_TOP = 0, // text appears on bottom of list and moves up to specified Y coordinate as old text fades out + MODE_BOTTOMUP_ALIGN_BOTTOM = 1, // text appears on bottom of list and moves away from specified Y coordinate as new text pushes it up + MODE_TOPDOWN_ALIGN_TOP = 2, // text appears on top of list and moves away from specified Y coordinate as new text pushes it down + MODE_TOPDOWN_ALIGN_BOTTOM = 3 // text appears on top of list and moves down to specified Y coordinate as old text fades out +}; + +enum MENU_BOOL { + MENU_TRUE = 1, + MENU_FALSE = 0 +}; + +enum MENU_ORIENTATION { + HUD_VERTICAL = 0x00, + HUD_HORIZONTAL = 0x01 +}; + +enum MENU_RANGETYPE { + RANGETYPE_ABSOLUTE = 0, + RANGETYPE_RELATIVE = 1 +}; + +// list box element types +enum MENU_LIST_BOX { + LISTBOX_TEXT = 0x00, + LISTBOX_IMAGE = 0x01 +}; + +// list feeders +enum MENU_FEEDERS { + FEEDER_HEADS = 0x00, // model heads + FEEDER_MAPS = 0x01, // text maps based on game type + FEEDER_SERVERS = 0x02, // servers + FEEDER_CLAN_MEMBERS = 0x03, // clan names + FEEDER_ALLMAPS = 0x04, // all maps available, in graphic format + FEEDER_REDTEAM_LIST = 0x05, // red team members + FEEDER_BLUETEAM_LIST = 0x06, // blue team members + FEEDER_PLAYER_LIST = 0x07, // players + FEEDER_TEAM_LIST = 0x08, // team members for team voting + FEEDER_MODS = 0x09, // team members for team voting + FEEDER_DEMOS = 0x0a, // team members for team voting + FEEDER_SCOREBOARD = 0x0b, // team members for team voting + FEEDER_Q3HEADS = 0x0c, // model heads + FEEDER_SERVERSTATUS = 0x0d, // server status + FEEDER_FINDPLAYER = 0x0e, // find player + FEEDER_CINEMATICS = 0x0f, // cinematics + FEEDER_SAVEGAMES = 0x10, // savegames + FEEDER_PICKSPAWN = 0x11, // pickspawn + FEEDER_LOBBY_MEMBERS = 0x12, // list of players in your party + FEEDER_LOBBY_MEMBERS_TALK = 0x13, // icon for whether they are speaking or not + FEEDER_MUTELIST = 0x14, // list of musted players + FEEDER_PLAYERSTALKING = 0x15, // list of players who are currently talking + FEEDER_SPLITSCREENPLAYERS = 0x16, // list of all players who are playing splitscreen + FEEDER_LOBBY_MEMBERS_READY = 0x17, // icon for whether they are ready or not + FEEDER_PLAYER_PROFILES = 0x18, // player profiles + FEEDER_PARTY_MEMBERS = 0x19, // list of players in your party + FEEDER_PARTY_MEMBERS_TALK = 0x1a, // icon for whether they are speaking or not + FEEDER_PARTY_MEMBERS_READY = 0x1b, // icon for whether they are ready or not + FEEDER_PLAYLISTS = 0x1c, // list of all playlists + FEEDER_GAMEMODES = 0x1d, // list of all game type modes, including any player custom modes + FEEDER_CATEGORIES = 0x1e, // list of all categories + FEEDER_LEADERBOARD = 0x1f, // list of rows for a leaderboard + FEEDER_MYTEAM_MEMBERS = 0x20, // list of marine team members + FEEDER_MYTEAM_MEMBERS_TALK = 0x21, // icon for whether they are speaking + FEEDER_ENEMY_MEMBERS = 0x22, // list of opfor team members + FEEDER_ENEMY_MEMBERS_TALK = 0x23, // icon for whether they are speaking + FEEDER_LOBBY_MEMBERS_STAT = 0x24, // last round stats for lobby members + FEEDER_MYTEAM_MEMBERS_STAT = 0x25, // last round stats for marine team members + FEEDER_ENEMY_MEMBERS_STAT = 0x26, // last round stats for opfor team members + FEEDER_ONLINEFRIENDS = 0x27, // list of your online friends + FEEDER_LOBBY_MEMBERS_RANK = 0x28, // rank icon + FEEDER_PARTY_MEMBERS_RANK = 0x29, // rank icon + FEEDER_ENEMY_MEMBERS_RANK = 0x2a, // rank icon + FEEDER_MYTEAM_MEMBERS_RANK = 0x2b, // rank icon + FEEDER_TESTMAPS = 0x2c, // department test maps + FEEDER_SYSTEMLINK_LOBBY_MEMBERS = 0x2d, // list of players in a system link lobby + FEEDER_LOBBY_MEMBERS_CONTROLLER = 0x2e, // icon for controller quadrant for splitscreen + FEEDER_PARTY_MEMBERS_CONTROLLER = 0x2f, // icon for controller quadrant for splitscreen + FEEDER_MYTEAM_MEMBERS_SQUAD = 0x30, // squad icon + FEEDER_ENEMY_MEMBERS_SQUAD = 0x31, // squad icon + FEEDER_INGAME_SQUAD_MEMBERS = 0x32, // Squad members displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_MEMBERS_FULL = 0x33, // Squad members' name, rank, talk, leader displayed in PC MP 'Pause' menu + FEEDER_INGAME_SQUAD_NAMES = 0x34, // Squad names displayed in MP 'Join Squad' menu + FEEDER_INGAME_SQUAD_NAMES2 = 0x35, // Squad names displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_NAMES_FULL = 0x36, // Squad names, lock, invite displayed in PC MP 'Pause' menu + FEEDER_CUSTOM_GAMETYPES = 0x37, // list of all the gametypes for custom matches + FEEDER_INGAME_SQUAD_MEMBER_RANK = 0x38, // Squad members' rank displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_MEMBER_TALK = 0x39, // Squad members' talk icon displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_LOCKED = 0x3a, // Squad lock icon displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_MEMBER_INVITED = 0x3b, // Squad invite icon displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_INVITE = 0x3c, // Squad invite icon displayed in MP 'Join Squad' menu + FEEDER_INGAME_SQUAD_LEADER = 0x3d, // Squad leader icon displayled in MP 'Pause' menu + FEEDER_FRIENDS = 0x3e, // list of your friends + FEEDER_PENDINGFRIENDS = 0x3f, // list of your pending friends + FEEDER_INVITES = 0x40, // list of the game invites from your friends +}; + +// display flags +enum MENU_DISPLAY_FLAG { + CG_SHOW_BLUE_TEAM_HAS_REDFLAG = 0x00000001, + CG_SHOW_RED_TEAM_HAS_BLUEFLAG = 0x00000002, + CG_SHOW_ANYTEAMGAME = 0x00000004, + CG_SHOW_CTF = 0x00000020, + CG_SHOW_OBELISK = 0x00000040, + CG_SHOW_HEALTHCRITICAL = 0x00000080, + CG_SHOW_SINGLEPLAYER = 0x00000100, + CG_SHOW_TOURNAMENT = 0x00000200, + CG_SHOW_DURINGINCOMINGVOICE = 0x00000400, + CG_SHOW_IF_PLAYER_HAS_FLAG = 0x00000800, + CG_SHOW_LANPLAYONLY = 0x00001000, + CG_SHOW_MINED = 0x00002000, + CG_SHOW_HEALTHOK = 0x00004000, + CG_SHOW_TEAMINFO = 0x00008000, + CG_SHOW_NOTEAMINFO = 0x00010000, + CG_SHOW_OTHERTEAMHASFLAG = 0x00020000, + CG_SHOW_YOURTEAMHASENEMYFLAG = 0x00040000, + CG_SHOW_ANYNONTEAMGAME = 0x00080000, + CG_SHOW_TEXTASINT = 0x00200000, + CG_SHOW_HIGHLIGHTED = 0x00100000, + CG_SHOW_NOT_V_CLEAR = 0x02000000, + CG_SHOW_2DONLY = 0x10000000 +}; + +enum MENU_UI_FLAG{ + UI_SHOW_LEADER = 0x00000001, + UI_SHOW_NOTLEADER = 0x00000002, + UI_SHOW_FAVORITESERVERS = 0x00000004, + UI_SHOW_ANYNONTEAMGAME = 0x00000008, + UI_SHOW_ANYTEAMGAME = 0x00000010, + UI_SHOW_NEWHIGHSCORE = 0x00000020, + UI_SHOW_DEMOAVAILABLE = 0x00000040, + UI_SHOW_NEWBESTTIME = 0x00000080, + UI_SHOW_FFA = 0x00000100, + UI_SHOW_NOTFFA = 0x00000200, + UI_SHOW_NETANYNONTEAMGAME = 0x00000400, + UI_SHOW_NETANYTEAMGAME = 0x00000800, + UI_SHOW_NOTFAVORITESERVERS = 0x00001000 +}; + +// font types +enum MENU_FONT_TYPE{ + UI_FONT_DEFAULT = 0, // auto-chose betwen big/reg/small + UI_FONT_NORMAL = 1, + UI_FONT_BIG = 2, + UI_FONT_SMALL = 3, + UI_FONT_BOLD = 4, + UI_FONT_CONSOLE = 5, + UI_FONT_OBJECTIVE = 6, + UI_FONT_MAX = 6, +}; + +// owner draw types +// ideally these should be done outside of this file but +// this makes it much easier for the macro expansion to +// convert them for the designers ( from the .menu files ) +enum MENU_OWNER_DRAW_TYPE { + CG_OWNERDRAW_BASE = 1, + CG_PLAYER_AMMO_VALUE = 5, + CG_PLAYER_AMMO_BACKDROP = 6, + CG_PLAYER_HEAT_VALUE = 7, + CG_PLAYER_STANCE = 20, + CG_SPECTATORS = 60, + CG_HOLD_BREATH_HINT = 71, + CG_CURSORHINT = 72, + CG_PLAYER_POWERUP = 73, + CG_PLAYER_HOLDABLE = 74, + CG_PLAYER_INVENTORY = 75, + CG_CURSORHINT_STATUS = 78, // like 'health' bar when pointing at a func_explosive + CG_PLAYER_BAR_HEALTH = 79, + CG_MANTLE_HINT = 80, + CG_PLAYER_WEAPON_NAME = 81, + CG_PLAYER_WEAPON_NAME_BACK = 82, + CG_CENTER_MESSAGE = 90, // for things like "You were killed by ..." + CG_TANK_BODY_DIR = 95, + CG_TANK_BARREL_DIR = 96, + CG_DEADQUOTE = 97, + CG_PLAYER_BAR_HEALTH_BACK = 98, + CG_MISSION_OBJECTIVE_HEADER = 99, + CG_MISSION_OBJECTIVE_LIST = 100, + CG_MISSION_OBJECTIVE_BACKDROP = 101, + CG_PAUSED_MENU_LINE = 102, + CG_OFFHAND_WEAPON_ICON_FRAG = 103, + CG_OFFHAND_WEAPON_ICON_SMOKEFLASH = 104, + CG_OFFHAND_WEAPON_AMMO_FRAG = 105, + CG_OFFHAND_WEAPON_AMMO_SMOKEFLASH = 106, + CG_OFFHAND_WEAPON_NAME_FRAG = 107, + CG_OFFHAND_WEAPON_NAME_SMOKEFLASH = 108, + CG_OFFHAND_WEAPON_SELECT_FRAG = 109, + CG_OFFHAND_WEAPON_SELECT_SMOKEFLASH = 110, + CG_SAVING = 111, + CG_PLAYER_LOW_HEALTH_OVERLAY = 112, + CG_INVALID_CMD_HINT = 113, + CG_PLAYER_SPRINT_METER = 114, + CG_PLAYER_SPRINT_BACK = 115, + CG_PLAYER_WEAPON_BACKGROUND = 116, + CG_PLAYER_WEAPON_AMMO_CLIP_GRAPHIC = 117, + CG_PLAYER_WEAPON_PRIMARY_ICON = 118, + CG_PLAYER_WEAPON_AMMO_STOCK = 119, + CG_PLAYER_WEAPON_LOW_AMMO_WARNING = 120, + CG_BATTLE_COMPASS_MARKERS = 122, + CG_BATTLE_FULLMAP_MARKERS = 123, + CG_SUCCESSFUL_CMD_HINT = 130, + CG_WAR_TEXT = 135, + CG_PLAYER_COMPASS_TICKERTAPE = 145, + CG_PLAYER_COMPASS_TICKERTAPE_NO_OBJ = 146, + CG_PLAYER_COMPASS_DOGS = 147, + CG_PLAYER_COMPASS_ARTILLERY_ICON = 148, + CG_PLAYER_COMPASS_SQUAD_OBJECTIVE = 149, + CG_PLAYER_COMPASS_PLAYER = 150, + CG_PLAYER_COMPASS_BACK = 151, + CG_PLAYER_COMPASS_POINTERS = 152, + CG_PLAYER_COMPASS_ACTORS = 153, + CG_PLAYER_COMPASS_TANKS = 154, + CG_PLAYER_COMPASS_HELICOPTERS = 155, + CG_PLAYER_COMPASS_PLANES = 156, + CG_PLAYER_COMPASS_AUTOMOBILES = 157, + CG_PLAYER_COMPASS_FRIENDS = 158, + CG_PLAYER_COMPASS_MAP = 159, + CG_PLAYER_COMPASS_NORTHCOORD = 160, + CG_PLAYER_COMPASS_EASTCOORD = 161, + CG_PLAYER_COMPASS_NCOORD_SCROLL = 162, + CG_PLAYER_COMPASS_ECOORD_SCROLL = 163, + CG_PLAYER_COMPASS_GOALDISTANCE = 164, + CG_PLAYER_ACTIONSLOT_DPAD = 165, + CG_PLAYER_ACTIONSLOT_1 = 166, + CG_PLAYER_ACTIONSLOT_2 = 167, + CG_PLAYER_ACTIONSLOT_3 = 168, + CG_PLAYER_ACTIONSLOT_4 = 169, + CG_PLAYER_COMPASS_ENEMIES = 170, + CG_PLAYER_FULLMAP_DOGS = 176, + CG_PLAYER_FULLMAP_VEHICLES = 177, + CG_PLAYER_FULLMAP_ARTILLERY_ICON = 178, + CG_PLAYER_FULLMAP_SQUAD_OBJECTIVE = 179, + CG_PLAYER_FULLMAP_BACK = 180, + CG_PLAYER_FULLMAP_MAP = 181, + CG_PLAYER_FULLMAP_POINTERS = 182, + CG_PLAYER_FULLMAP_PLAYER = 183, + CG_PLAYER_FULLMAP_ACTORS = 184, + CG_PLAYER_FULLMAP_FRIENDS = 185, + CG_PLAYER_FULLMAP_LOCATION_SELECTOR = 186, + CG_PLAYER_FULLMAP_BORDER = 187, + CG_PLAYER_FULLMAP_ENEMIES = 188, + CG_PLAYER_COMPASS = 189, + CG_VEHICLE_RETICLE = 190, + CG_HUD_TARGETS_VEHICLE = 191, + CG_HUD_TARGETS_JAVELIN = 192, + CG_TALKER1 = 193, + CG_TALKER2 = 194, + CG_TALKER3 = 195, + CG_TALKER4 = 196, + CG_FRIENDLYARROWS = 197, + CG_FRIENDLYNAMES = 198, + UI_OWNERDRAW_BASE = 200, + UI_HANDICAP = 200, + UI_EFFECTS = 201, + UI_PLAYERMODEL = 202, + UI_GAMETYPE = 205, + UI_SKILL = 207, + UI_NETSOURCE = 220, + UI_NETFILTER = 222, + UI_VOTE_KICK = 238, + UI_NETGAMETYPE = 245, + UI_SERVERREFRESHDATE = 247, + UI_SERVERMOTD = 248, + UI_GLINFO = 249, + UI_KEYBINDSTATUS = 250, + UI_JOINGAMETYPE = 253, + UI_MAPPREVIEW = 254, + UI_MENUMODEL = 257, + UI_SAVEGAME_SHOT = 258, + UI_SAVEGAMENAME = 262, + UI_SAVEGAMEINFO = 263, + UI_LOADPROFILING = 264, + UI_RECORDLEVEL = 265, + UI_AMITALKING = 266, + UI_TALKER1 = 267, + UI_TALKER2 = 268, + UI_TALKER3 = 269, + UI_TALKER4 = 270, + UI_PARTYSTATUS = 271, + UI_LOGGEDINUSER = 272, + UI_RESERVEDSLOTS = 273, + UI_PLAYLISTNAME = 274, + UI_PLAYLISTDESCRIPTION = 275, + UI_USERNAME = 276, + UI_CINEMATIC = 277, + UI_TOTALONLINE = 278, + UI_CATEGORYNAME = 279, + UI_CATEGORYDESCRIPTION = 280, + UI_PLAYLISTICON = 281, + UI_CATEGORYICON = 282, + UI_GAMETYPE_MAPNAME = 283, + CG_HUD_WAR_MOMENTUM_PROGRESS = 284, + CG_HUD_WAR_MOMENTUM_MULTIPLIER = 285, + CG_HUD_WAR_MOMENTUM_MULTIPLIER_DETAIL = 286, + CG_HUD_WAR_MOMENTUM_MULTIPLIER_BLITZKRIEG = 287, + CG_COMPETITIVE_MODE_SCORES = 288, + UI_LOAD_STATUS_SCREEN = 289, + UI_LEADERBOARD_GAMEMODE = 290, + CG_PLAYER_ACTIONSLOT_BACK_1 = 290, + CG_PLAYER_ACTIONSLOT_BACK_2 = 291, + CG_PLAYER_ACTIONSLOT_BACK_3 = 292, + CG_PLAYER_ACTIONSLOT_BACK_4 = 293, + CG_PLAYER_ACTIONSLOT_ARROW_1 = 294, + CG_PLAYER_ACTIONSLOT_ARROW_2 = 295, + CG_PLAYER_ACTIONSLOT_ARROW_3 = 296, + CG_PLAYER_ACTIONSLOT_ARROW_4 = 297, + UI_DIFFICULTY_INFO = 298, + UI_DIFFICULTY_ICON = 299, + UI_LOBBY_CHAT = 300 +}; + +// Edge relative placement values for rect->h_align and rect->v_align +enum MENU_H_ALIGNMENT { + HORIZONTAL_ALIGN_SUBLEFT = 0, // left edge of a 4:3 screen (safe area not included) + HORIZONTAL_ALIGN_LEFT = 1, // left viewable (safe area) edge + HORIZONTAL_ALIGN_CENTER = 2, // center of the screen (reticle) + HORIZONTAL_ALIGN_RIGHT = 3, // right viewable (safe area) edge + HORIZONTAL_ALIGN_FULLSCREEN = 4, // disregards safe area + HORIZONTAL_ALIGN_NOSCALE = 5, // uses exact parameters - neither adjusts for safe area nor scales for screen size + HORIZONTAL_ALIGN_TO640 = 6, // scales a real-screen resolution x down into the 0 - 640 range + HORIZONTAL_ALIGN_CENTER_SAFEAREA = 7, // center of the safearea + HORIZONTAL_ALIGN_MAX = HORIZONTAL_ALIGN_CENTER_SAFEAREA, + HORIZONTAL_ALIGN_DEFAULT = HORIZONTAL_ALIGN_SUBLEFT +}; + +enum MENU_V_ALIGNMENT { + VERTICAL_ALIGN_SUBTOP = 0, // top edge of the 4:3 screen (safe area not included) + VERTICAL_ALIGN_TOP = 1, // top viewable (safe area) edge + VERTICAL_ALIGN_CENTER = 2, // center of the screen (reticle) + VERTICAL_ALIGN_BOTTOM = 3, // bottom viewable (safe area) edge + VERTICAL_ALIGN_FULLSCREEN = 4, // disregards safe area + VERTICAL_ALIGN_NOSCALE = 5, // uses exact parameters - neither adjusts for safe area nor scales for screen size + VERTICAL_ALIGN_TO480 = 6, // scales a real-screen resolution y down into the 0 - 480 range + VERTICAL_ALIGN_CENTER_SAFEAREA = 7, // center of the save area + VERTICAL_ALIGN_MAX = VERTICAL_ALIGN_CENTER_SAFEAREA, + VERTICAL_ALIGN_DEFAULT = VERTICAL_ALIGN_SUBTOP +}; + +enum MENU_BUTTON { + BUTTON_A = 1, + BUTTON_B = 2, + BUTTON_X = 3, + BUTTON_Y = 4, + BUTTON_LSHLDR = 5, + BUTTON_RSHLDR = 6, + BUTTON_START = 14, + BUTTON_BACK = 15, + BUTTON_LSTICK = 16, + BUTTON_RSTICK = 17, + BUTTON_LTRIG = 18, + BUTTON_RTRIG = 19, + DPAD_UP = 20, + DPAD_DOWN = 21, + DPAD_LEFT = 22, + DPAD_RIGHT = 23, + APAD_UP = 28, + APAD_DOWN = 29, + APAD_LEFT = 30, + APAD_RIGHT = 31 +}; + +enum ASSET_TYPE { + ASSET_UNKNOWN = 0, + ASSET_ANIMATION = 4, // x_anim PARTIALLY VERIFIED + ASSET_MODEL = 5, // xmodel PARTIALLY VERIFIED + ASSET_MATERIAL = 6, // material VERIFIED + ASSET_BIK_FILE = 7, // .bik file PARTIALLY VERIFIED + ASSET_SOUND = 9, // loaded_sound VERIFIED + ASSET_COLLISION_MAP = 12, // collision_map PARTIALLY VERIFIED + ASSET_SHADER = 13, // shader PARTIALLY VERIFIED + ASSET_D3DBSP_DUMP = 17, // d3dbsp dump VERIFIED + ASSET_FONT = 20, // font PARTIALLY VERIFIED + ASSET_MENU = 21, // menu_file VERIFIED + ASSET_LOCAL_STRING = 23, // localized string VERIFIED + ASSET_WEAPON = 24, // weapon VERIFIED + ASSET_EFFECT = 26, // fx VERIFIED + ASSET_RAW_FILE = 32, // raw_file VERIFIED + ASSET_STRING_TABLE = 33 // string_table PARTIALLY VERIFIED +}; + +enum SHADER_TYPE { + SHADER_NONE = 0x00, + SHADER_PIXEL = 0x01, + SHADER_VERTEX = 0x02 +}; + +enum SHADER_OPCODE { + OPCODE_Nop, + OPCODE_Mov, + OPCODE_Add, + OPCODE_Sub, + OPCODE_Mad, + OPCODE_Mul, + OPCODE_Rcp, + OPCODE_Rsq, + OPCODE_Dp3, + OPCODE_Dp4, + OPCODE_Min, + OPCODE_Max, + OPCODE_Slt, + OPCODE_Sge, + OPCODE_Exp, + OPCODE_Log, + OPCODE_Lit, + OPCODE_Dst, + OPCODE_Lrp, + OPCODE_Frc, + OPCODE_M4x4, + OPCODE_M4x3, + OPCODE_M3x4, + OPCODE_M3x3, + OPCODE_M3x2, + OPCODE_Call, + OPCODE_CallNZ, + OPCODE_Loop, + OPCODE_Ret, + OPCODE_EndLoop, + OPCODE_Label, + OPCODE_Dcl, + OPCODE_Pow, + OPCODE_Crs, + OPCODE_Sgn, + OPCODE_Abs, + OPCODE_Nrm, + OPCODE_SinCos, + OPCODE_Rep, + OPCODE_EndRep, + OPCODE_If, + OPCODE_IfC, + OPCODE_Else, + OPCODE_Endif, + OPCODE_Break, + OPCODE_BreakC, + OPCODE_MovA, + OPCODE_DefB, + OPCODE_DefI, + OPCODE_TexCoord = 64, + OPCODE_TexKill, + OPCODE_Tex, + OPCODE_TexBem, + OPCODE_TexBeml, + OPCODE_TexReg2AR, + OPCODE_TexReg2GB, + OPCODE_TeXM3x2Pad, + OPCODE_TexM3x2Tex, + OPCODE_TeXM3x3Pad, + OPCODE_TexM3x3Tex, + OPCODE_TexM3x3Diff, + OPCODE_TexM3x3Spec, + OPCODE_TexM3x3VSpec, + OPCODE_ExpP, + OPCODE_LogP, + OPCODE_Cnd, + OPCODE_Def, + OPCODE_TexReg2RGB, + OPCODE_TexDP3Tex, + OPCODE_TexM3x2Depth, + OPCODE_TexDP3, + OPCODE_TexM3x3, + OPCODE_TexDepth, + OPCODE_Cmp, + OPCODE_Bem, + OPCODE_DP2Add, + OPCODE_DSX, + OPCODE_DSY, + OPCODE_TexLDD, + OPCODE_SetP, + OPCODE_TexLDL, + OPCODE_Breakp, + OPCODE_Phase = 0xFFFD, + OPCODE_Comment = 0xFFFE, + OPCODE_End = 0xFFFF +}; + +#define SECTION_TYPE_INFO 1 +#define SECTION_TYPE_DATA 2 + +#define IPAK_SECTION_ENTRY 1 +#define IPAK_SECTION_DATA 2 +#define IPAK_SECTION_METADATA 3 + +#define FORMAT_DXT1 0 +#define FORMAT_DXT3 1 +#define FORMAT_DXT5 2 +#define FORMAT_A8R8G8B8 3 + +// Change this depending on the platform +// PC +#define DEVMAP_LEVEL_FIRST "devmap intro_pac" +#define DEVMAP "devmap" +// Not PC +// #define DEVMAP_LEVEL_FIRST "map intro_pac" +// #define DEVMAP "map" + +// Remove this to restore full frontend instead of limited EPD frontend +#define COOP_EPD 0 + +// LDS - This enables a German SKU with Nazi Zombies enabled *SHOULD BE SET TO 0 IF NOT APPROVED* +#define GERMAN_ZOMBIE_BUILD 0 + +#define DEVMAP_LEVEL_TRAINING "devmap training" +#define LEVEL_FIRST "intro_pac" +#define LEVEL_TRAINING "training" +#define FIRST_PLAYABLE_CAMPAIGN_LEVEL "mak" +#define FIRST_PLAYABLE_ZOMBIE_LEVEL "nazi_zombie_prototype" + +// Size define for the hud compass +// These are used for both the dynamic & non-dynamic compass drawing +// If these are changed, the cgame should be recompiled +#define COMPASS_SIZE 160 +#define MINIMAP_X 11.5 +#define MINIMAP_Y 5 +#define MINIMAP_W 89.5 +#define MINIMAP_H 89.5 + +#define COMPASS_SIZE_MP 125 +#define MINIMAP_X_MP 0 +#define MINIMAP_Y_MP 12 +#define MINIMAP_W_MP 102 +#define MINIMAP_H_MP 102 + +#define FULLSCREEN 0 0 640 480 +#define FULLSCREEN_WIDE -107 0 854 480 + +// PC +#define ORIGIN_TITLE 30 34 +// Not PC +// #define ORIGIN_TITLE 0 0 + +#define ORIGIN_TITLE_SS 104 120 + +#define FONTSCALE_SMALL 0.3095 //0.3750 // <-- COD4 // COD5 --> 0.30952//0.35897//0.24138 //14 pt //0.2900 //0.2750 // 18 +#define FONTSCALE_LOBBY 0.26 // <--Slate // 0.3010 <-- Slate Compressed // 0.3750 // <-- COD4 CONDUIT ITC small +#define FONTSCALE_NORMAL 0.3810 //0.35897//0.4583 +#define FONTSCALE_BOLD 0.5476 //0.4583 +#define FONTSCALE_BIG 0.5476 //0.5833 +#define FONTSCALE_EXTRABIG 1 //1.0000 + +// new settings +#define TEXTSIZE_SMALL FONTSCALE_SMALL +#define TEXTSIZE_SMALL_SS (FONTSCALE_SMALL*2) +#define TEXTSIZE_DEFAULT FONTSCALE_NORMAL +#define TEXTSIZE_DEFAULT_SS (FONTSCALE_NORMAL*2) +#define TEXTSIZE_TITLE FONTSCALE_BIG +#define TEXTSIZE_TITLE_SS 1 + +#define TEXTSIZE_BOLD TEXTSIZE_DEFAULT +#define TEXTSIZE_BIG TEXTSIZE_TITLE + +//#define COLOR_TITLE 1 0.8 0.4 1 +#define COLOR_TITLE 1 1 1 1 +#define COLOR_HEADER 0.69 0.69 0.69 1 +#define COLOR_FOCUSED 0.95294 0.72156 0.21176 1 //1 0.788 0.129 1 +//#define COLOR_FOCUS_YELLOW 0.95294 0.72156 0.21176 1 +#define COLOR_UNFOCUSED 0.4823 0.4823 0.4823 1 +//#define COLOR_DISABLED 0.35 0.35 0.35 1 +#define COLOR_SAFEAREA 0 0 1 1 + +#define COLOR_INFO_YELLOW COLOR_FOCUSED//1 0.84706 0 1 +#define COLOR_TEXT 0.84313 0.84313 0.84313 1 +#define COLOR_DISABLED 0.34118 0.36863 0.37647 1 +#define COLOR_TITLEBAR 0.14510 0.16078 0.16862 0.3//1 +#define COLOR_RED_TEXT 0.69020 0.00784 0.00784 1 + +#define COLOR_FADEOUT 0.09412 0.09412 0.04912 0.65 + +#define COLOR_BODY_TEXT 0.62745 0.66667 0.67451 1 + +#define COLOR_USMC 0 0.0196 0.41 +#define COLOR_JPN 0.53 0.027 0.027 +#define COLOR_USSR 0.368 0.035 0.035 +#define COLOR_GER 0.937 0.9 0.607 + +#define DEFAULT_MP_CFG "default_mp.cfg" +#define SPLITSCREEN_MP_CFG "default_splitscreen.cfg" +#define SYSTEMLINK_MP_CFG "default_systemlink.cfg" +#define XBOXLIVE_MP_CFG "default_xboxlive.cfg" + +#define MAX_RANK int(tableLookup( "mp/rankTable.csv", 0, "maxrank", 1)) +#define MAX_PRESTIGE int(tableLookup( "mp/rankIconTable.csv", 0, "maxprestige", 1)) + +#define PRESTIGE_AVAIL (stat(2326) < MAX_PRESTIGE && stat(2301) == int(tableLookup("mp/rankTable.csv",0,MAX_RANK,7))) +#define PRESTIGE_NEXT (stat(2326) < MAX_PRESTIGE && stat(252) == MAX_RANK) +#define PRESTIGE_FINISH (stat(2326) == MAX_PRESTIGE) + +#define CAN_RANK_UP (stat(252) < MAX_RANK || stat(2326) < MAX_PRESTIGE) +#endif // ENUMS_H diff --git a/libs/core/logmanager.cpp b/libs/core/logmanager.cpp new file mode 100644 index 0000000..a0ab70e --- /dev/null +++ b/libs/core/logmanager.cpp @@ -0,0 +1,15 @@ +#include "logmanager.h" +#include "qdebug.h" + +void LogManager::addEntry(const QString &entry) { + qDebug() << entry; + emit entryAdded(entry); +} + +void LogManager::addError(const QString &error) { + emit entryAdded(QString("ERROR: " + error)); +} + +void LogManager::addLine() { + emit entryAdded(""); +} diff --git a/libs/core/logmanager.h b/libs/core/logmanager.h new file mode 100644 index 0000000..d3161d5 --- /dev/null +++ b/libs/core/logmanager.h @@ -0,0 +1,31 @@ +#ifndef LOGMANAGER_H +#define LOGMANAGER_H + +#include +#include + +class LogManager : public QObject +{ + Q_OBJECT + +public: + static LogManager &instance() { + static LogManager instance; + return instance; + } + + void addEntry(const QString &entry); + void addError(const QString &error); + void addLine(); + +signals: + void entryAdded(const QString &entry); + +private: + LogManager() {} // Private constructor for singleton + ~LogManager() {} + + Q_DISABLE_COPY(LogManager) +}; + +#endif // LOGMANAGER_H diff --git a/libs/core/statusbarmanager.cpp b/libs/core/statusbarmanager.cpp new file mode 100644 index 0000000..d72c664 --- /dev/null +++ b/libs/core/statusbarmanager.cpp @@ -0,0 +1,9 @@ +#include "statusbarmanager.h" + +void StatusBarManager::updateStatus(const QString &message, int timeout) { + emit statusUpdated(message, timeout); +} + +void StatusBarManager::updateProgressStatus(const QString &message, int progress, int max) { + emit progressUpdated(message, progress, max); +} diff --git a/libs/core/statusbarmanager.h b/libs/core/statusbarmanager.h new file mode 100644 index 0000000..ed7cae4 --- /dev/null +++ b/libs/core/statusbarmanager.h @@ -0,0 +1,31 @@ +#ifndef STATUSBARMANAGER_H +#define STATUSBARMANAGER_H + +#include +#include + +class StatusBarManager : public QObject +{ + Q_OBJECT + +public: + static StatusBarManager &instance() { + static StatusBarManager instance; + return instance; + } + + void updateStatus(const QString &message, int timeout = 5000); + void updateProgressStatus(const QString &message, int progress, int max); + +signals: + void statusUpdated(const QString &message, int timeout); + void progressUpdated(const QString &message, int progress, int max); + +private: + StatusBarManager() {} // Private constructor for singleton + ~StatusBarManager() {} + + Q_DISABLE_COPY(StatusBarManager) +}; + +#endif // STATUSBARMANAGER_H diff --git a/libs/core/stringutils.h b/libs/core/stringutils.h new file mode 100644 index 0000000..e69de29 diff --git a/libs/core/utils.h b/libs/core/utils.h new file mode 100644 index 0000000..9ebf74c --- /dev/null +++ b/libs/core/utils.h @@ -0,0 +1,389 @@ +#ifndef UTILS_H +#define UTILS_H + +#include "enums.h" + +#include +#include +#include +#include + +class Utils { +public: + static bool ExportData(const QString aFileName, const QByteArray aData) { + QDir workingDir = QDir::currentPath(); + workingDir.mkdir("exports"); + + QFile testFile("exports/" + aFileName); + if(!testFile.open(QIODevice::WriteOnly)) { + return false; + } + testFile.write(aData); + testFile.close(); + return true; + } + static bool ReadUntilString(QDataStream* stream, const QString& targetString) { + if (!stream || targetString.isEmpty()) { + return false; // Invalid input + } + + QByteArray buffer; + QByteArray targetBytes = targetString.toUtf8(); // Handle multibyte characters + const int targetLength = targetBytes.size(); + qDebug() << targetBytes << targetLength; + + // Read as unsigned bytes to handle all possible values (0-255) + unsigned char byte; + while (!stream->atEnd()) { + // Read one byte at a time + *stream >> byte; + buffer.append(static_cast(byte)); // Append as char for QByteArray + + // Keep buffer size limited to the target length + if (buffer.size() > targetLength) { + buffer.remove(0, 1); + } + + // Check if the buffer matches the target string in raw bytes + if (buffer == targetBytes) { + // Backup to the start of the matched string + stream->device()->seek(stream->device()->pos() - targetLength); + return true; + } + } + + // Target string not found + return false; + } + + static bool ReadUntilHex(QDataStream* stream, const QString& hexString) { + if (!stream || hexString.isEmpty() || hexString.size() % 2 != 0) { + return false; // Invalid input + } + + // Convert hex string to byte array + QByteArray targetBytes = QByteArray::fromHex(hexString.toUtf8()); + const int targetLength = targetBytes.size(); + + QByteArray buffer; + unsigned char byte; + + while (!stream->atEnd()) { + // Read one byte at a time + *stream >> byte; + buffer.append(static_cast(byte)); // Append as char for QByteArray + + // Keep buffer size limited to the target length + if (buffer.size() > targetLength) { + buffer.remove(0, 1); + } + + // Check if the buffer matches the target byte sequence + if (buffer == targetBytes) { + // Backup to the start of the matched sequence + stream->device()->seek(stream->device()->pos() - targetLength); + return true; + } + } + + // Target sequence not found + return false; + } + + /* + AssetTypeToString() + + Convert asset type string to asset desc string +*/ + static QString AssetTypeToString(const QString aAssetType) { + const QString cleanedType = aAssetType.toUpper(); + if (cleanedType == "17000000") { // localized string PARTIALLY VERIFIED + return "LOCAL STRING"; + } else if (cleanedType == "20000000") { // raw_file PARTIALLY VERIFIED + return "RAW FILE"; + } else if (cleanedType == "1A000000") { // fx PARTIALLY VERIFIED + return "EFFECT"; + } else if (cleanedType == "09000000") { // loaded_sound PARTIALLY VERIFIED + return "SOUND"; + } else if (cleanedType == "04000000") { // x_anim PARTIALLY VERIFIED + return "ANIMATION"; + } else if (cleanedType == "0C000000") { // collision_map PARTIALLY VERIFIED + return "COLLISION MAP"; + } else if (cleanedType == "21000000") { // string_table PARTIALLY VERIFIED + return "STRING TABLE"; + } else if (cleanedType == "15000000") { // menu_file PARTIALLY VERIFIED + return "MENU"; + } else if (cleanedType == "07000000") { // tech set PARTIALLY VERIFIED + return "TECH SET"; + } else if (cleanedType == "18000000") { // weapon PARTIALLY VERIFIED + return "WEAPON"; + } else if (cleanedType == "11000000") { // gfx map PARTIALLY VERIFIED + return "GFX MAP"; + } else if (cleanedType == "12000000") { // light_def PARTIALLY VERIFIED + return "LIGHT DEF"; + } else if (cleanedType == "14000000") { // font PARTIALLY VERIFIED + return "FONT"; + } else if (cleanedType == "05000000") { // xmodel PARTIALLY VERIFIED + return "MODEL"; + } else if (cleanedType == "0D000000") { // d3dbsp PARTIALLY VERIFIED + return "D3DBSP"; + } else if (cleanedType == "06000000") { // image PARTIALLY VERIFIED + return "IMAGE"; + } else if (cleanedType == "0E000000") { // game map sp PARTIALLY VERIFIED + return "GAME MAP SP"; + } else if (cleanedType == "0B000000") { // col map sp PARTIALLY VERIFIED + return "COL MAP SP"; + } + return aAssetType; + } + + /* + LumpTypeToString() + + Convert BSP lump type to desc string +*/ + static QString LumpTypeToString(LUMP_TYPE aLumpType) { + switch (aLumpType) { + case LUMP_MATERIALS: return "LUMP_MATERIALS"; + case LUMP_LIGHTBYTES: return "LUMP_LIGHTBYTES"; + case LUMP_LIGHTGRIDENTRIES: return "LUMP_LIGHTGRIDENTRIES"; + case LUMP_LIGHTGRIDCOLORS: return "LUMP_LIGHTGRIDCOLORS"; + case LUMP_PLANES: return "LUMP_PLANES"; + case LUMP_BRUSHSIDES: return "LUMP_BRUSHSIDES"; + case LUMP_BRUSHSIDEEDGECOUNTS: return "LUMP_BRUSHSIDEEDGECOUNTS"; + case LUMP_BRUSHEDGES: return "LUMP_BRUSHEDGES"; + case LUMP_BRUSHES: return "LUMP_BRUSHES"; + case LUMP_TRIANGLES: return "LUMP_TRIANGLES"; + case LUMP_DRAWVERTS: return "LUMP_DRAWVERTS"; + case LUMP_DRAWINDICES: return "LUMP_DRAWINDICES"; + case LUMP_CULLGROUPS: return "LUMP_CULLGROUPS"; + case LUMP_CULLGROUPINDICES: return "LUMP_CULLGROUPINDICES"; + case LUMP_OBSOLETE_1: return "LUMP_OBSOLETE_1"; + case LUMP_OBSOLETE_2: return "LUMP_OBSOLETE_2"; + case LUMP_OBSOLETE_3: return "LUMP_OBSOLETE_3"; + case LUMP_OBSOLETE_4: return "LUMP_OBSOLETE_4"; + case LUMP_OBSOLETE_5: return "LUMP_OBSOLETE_5"; + case LUMP_PORTALVERTS: return "LUMP_PORTALVERTS"; + case LUMP_OBSOLETE_6: return "LUMP_OBSOLETE_6"; + case LUMP_UINDS: return "LUMP_UINDS"; + case LUMP_BRUSHVERTSCOUNTS: return "LUMP_BRUSHVERTSCOUNTS"; + case LUMP_BRUSHVERTS: return "LUMP_BRUSHVERTS"; + case LUMP_AABBTREES: return "LUMP_AABBTREES"; + case LUMP_CELLS: return "LUMP_CELLS"; + case LUMP_PORTALS: return "LUMP_PORTALS"; + case LUMP_NODES: return "LUMP_NODES"; + case LUMP_LEAFS: return "LUMP_LEAFS"; + case LUMP_LEAFBRUSHES: return "LUMP_LEAFBRUSHES"; + case LUMP_LEAFSURFACES: return "LUMP_LEAFSURFACES"; + case LUMP_COLLISIONVERTS: return "LUMP_COLLISIONVERTS"; + case LUMP_COLLISIONTRIS: return "LUMP_COLLISIONTRIS"; + case LUMP_COLLISIONEDGEWALKABLE: return "LUMP_COLLISIONEDGEWALKABLE"; + case LUMP_COLLISIONBORDERS: return "LUMP_COLLISIONBORDERS"; + case LUMP_COLLISIONPARTITIONS: return "LUMP_COLLISIONPARTITIONS"; + case LUMP_COLLISIONAABBS: return "LUMP_COLLISIONAABBS"; + case LUMP_MODELS: return "LUMP_MODELS"; + case LUMP_VISIBILITY: return "LUMP_VISIBILITY"; + case LUMP_ENTITIES: return "LUMP_ENTITIES"; + case LUMP_PATHCONNECTIONS: return "LUMP_PATHCONNECTIONS"; + case LUMP_REFLECTION_PROBES: return "LUMP_REFLECTION_PROBES"; + case LUMP_VERTEX_LAYER_DATA: return "LUMP_VERTEX_LAYER_DATA"; + case LUMP_PRIMARY_LIGHTS: return "LUMP_PRIMARY_LIGHTS"; + case LUMP_LIGHTGRIDHEADER: return "LUMP_LIGHTGRIDHEADER"; + case LUMP_LIGHTGRIDROWS: return "LUMP_LIGHTGRIDROWS"; + case LUMP_OBSOLETE_10: return "LUMP_OBSOLETE_10"; + case LUMP_UNLAYERED_TRIANGLES: return "LUMP_UNLAYERED_TRIANGLES"; + case LUMP_UNLAYERED_DRAWVERTS: return "LUMP_UNLAYERED_DRAWVERTS"; + case LUMP_UNLAYERED_DRAWINDICES: return "LUMP_UNLAYERED_DRAWINDICES"; + case LUMP_UNLAYERED_CULLGROUPS: return "LUMP_UNLAYERED_CULLGROUPS"; + case LUMP_UNLAYERED_AABBTREES: return "LUMP_UNLAYERED_AABBTREES"; + case LUMP_WATERHEADER: return "LUMP_WATERHEADER"; + case LUMP_WATERCELLS: return "LUMP_WATERCELLS"; + case LUMP_WATERCELLDATA: return "LUMP_WATERCELLDATA"; + case LUMP_BURNABLEHEADER: return "LUMP_BURNABLEHEADER"; + case LUMP_BURNABLECELLS: return "LUMP_BURNABLECELLS"; + case LUMP_BURNABLECELLDATA: return "LUMP_BURNABLECELLDATA"; + case LUMP_SIMPLELIGHTMAPBYTES: return "LUMP_SIMPLELIGHTMAPBYTES"; + case LUMP_LODCHAINS: return "LUMP_LODCHAINS"; + case LUMP_LODINFOS: return "LUMP_LODINFOS"; + case LUMP_LODSURFACES: return "LUMP_LODSURFACES"; + case LUMP_LIGHTREGIONS: return "LUMP_LIGHTREGIONS"; + case LUMP_LIGHTREGION_HULLS: return "LUMP_LIGHTREGION_HULLS"; + case LUMP_LIGHTREGION_AXES: return "LUMP_LIGHTREGION_AXES"; + case LUMP_WIILIGHTGRID: return "LUMP_WIILIGHTGRID"; + case LUMP_LIGHTGRID2D_LIGHTS: return "LUMP_LIGHTGRID2D_LIGHTS"; + case LUMP_LIGHTGRID2D_INDICES: return "LUMP_LIGHTGRID2D_INDICES"; + case LUMP_LIGHTGRID2D_POINTS: return "LUMP_LIGHTGRID2D_POINTS"; + case LUMP_LIGHTGRID2D_CELLS: return "LUMP_LIGHTGRID2D_CELLS"; + case LUMP_LIGHT_CORONAS: return "LUMP_LIGHT_CORONAS"; + case LUMP_SHADOWMAP_VOLUMES: return "LUMP_SHADOWMAP_VOLUMES"; + case LUMP_SHADOWMAP_VOLUME_PLANES: return "LUMP_SHADOWMAP_VOLUME_PLANES"; + case LUMP_EXPOSURE_VOLUMES: return "LUMP_EXPOSURE_VOLUMES"; + case LUMP_EXPOSURE_VOLUME_PLANES: return "LUMP_EXPOSURE_VOLUME_PLANES"; + case LUMP_OCCLUDERS: return "LUMP_OCCLUDERS"; + case LUMP_OUTDOORBOUNDS: return "LUMP_OUTDOORBOUNDS"; + case LUMP_HERO_ONLY_LIGHTS: return "LUMP_HERO_ONLY_LIGHTS"; + default: return "Unknown Lump Type"; + } + return "Unknown Lump Type"; + } + + static QString ZLibErrorToString(int result) { + switch (result) { + case Z_ERRNO: + return "Encountered file operation error!"; + case Z_STREAM_ERROR: + return "Stream was not initialized properly!"; + case Z_DATA_ERROR: + return "The input data was corrupted or incomplete!"; + case Z_MEM_ERROR: + return "There was not enough memory!"; + case Z_BUF_ERROR: + return "There was not enough room in the output buffer!"; + case Z_VERSION_ERROR: + return "Linked libraries are out of date!"; + } + return ""; + } + + static quint32 PadInt4(quint32 size) { + return (size + 3) & ~3; // Align size to 4 bytes + } + + static quint32 PaddingSize(quint32 size) { + return PadInt4(size) - size; + } + + static QString GetOpenFastFileName(QWidget *parent = nullptr) { + // Open file dialog to steam apps + const QString steamPath = "C:/Program Files (x86)/Steam/steamapps/common/Call of Duty World at War/zone/english/"; + const QString fastFilePath = QFileDialog::getOpenFileName(parent, "Open Fast File", steamPath, "Fast File (*.ff);;All Files (*.*)"); + if (fastFilePath.isNull()) { + // User pressed cancel + return ""; + } else if (!QFile::exists(fastFilePath)) { + QMessageBox::warning(parent, "Warning!", QString("%1 does not exist!.").arg(fastFilePath)); + return ""; + } + return fastFilePath; + } + + static QString GetOpenZoneFileName(QWidget *parent = nullptr) { + // Open file dialog to steam apps + const QString steamPath = "C:/Program Files (x86)/Steam/steamapps/common/Call of Duty World at War/zone/english/"; + const QString zoneFilePath = QFileDialog::getOpenFileName(parent, "Open Zone File", steamPath, "Zone File (*.zone);;All Files (*.*)"); + if (zoneFilePath.isNull()) { + // User pressed cancel + return ""; + } else if (!QFile::exists(zoneFilePath)) { + QMessageBox::warning(parent, "Warning!", QString("%1 does not exist!.").arg(zoneFilePath)); + return nullptr; + } + return zoneFilePath; + } + + static QString CompanyEnumToStr(FF_COMPANY aCompany) { + switch (aCompany) { + case COMPANY_NONE: + return "None"; + case COMPANY_INFINITY_WARD: + return "Infinity Ward"; + case COMPANY_TREYARCH: + return "Treyarch"; + case COMPANY_SLEDGEHAMMER: + return "Sledgehammer"; + case COMPANY_NEVERSOFT: + return "Neversoft"; + } + return "None"; + } + + static QString FileTypeEnumToStr(FF_FILETYPE aFileType) { + switch (aFileType) { + case FILETYPE_NONE: + return "None"; + case FILETYPE_FAST_FILE: + return "Fast File"; + } + return "None"; + } + + static QString SignageEnumToStr(FF_SIGNAGE aSignage) { + switch (aSignage) { + case SIGNAGE_NONE: + return "None"; + case SIGNAGE_SIGNED: + return "Signed"; + case SIGNAGE_UNSIGNED: + return "Unsigned"; + } + return "None"; + } + + static QString MenuVAlignToStr(MENU_V_ALIGNMENT align) { + if (align == VERTICAL_ALIGN_SUBTOP) { + return "VERTICAL_ALIGN_SUBTOP"; + } else if (align == VERTICAL_ALIGN_TOP) { + return "VERTICAL_ALIGN_TOP"; + } else if (align == VERTICAL_ALIGN_CENTER) { + return "VERTICAL_ALIGN_CENTER"; + } else if (align == VERTICAL_ALIGN_BOTTOM) { + return "VERTICAL_ALIGN_BOTTOM"; + } else if (align == VERTICAL_ALIGN_FULLSCREEN) { + return "VERTICAL_ALIGN_FULLSCREEN"; + } else if (align == VERTICAL_ALIGN_NOSCALE) { + return "VERTICAL_ALIGN_NOSCALE"; + } else if (align == VERTICAL_ALIGN_TO480) { + return "VERTICAL_ALIGN_TO480"; + } else if (align == VERTICAL_ALIGN_CENTER_SAFEAREA) { + return "VERTICAL_ALIGN_CENTER_SAFEAREA"; + } else if (align == VERTICAL_ALIGN_MAX) { + return "VERTICAL_ALIGN_CENTER_SAFEAREA"; + } else if (align == VERTICAL_ALIGN_DEFAULT) { + return "VERTICAL_ALIGN_SUBTOP"; + } + return "VERTICAL_ALIGN_SUBTOP"; + } + + static QString MenuHAlignToStr(MENU_H_ALIGNMENT align) { + if (align == HORIZONTAL_ALIGN_SUBLEFT) { + return "HORIZONTAL_ALIGN_SUBLEFT"; + } else if (align == HORIZONTAL_ALIGN_LEFT) { + return "HORIZONTAL_ALIGN_LEFT"; + } else if (align == HORIZONTAL_ALIGN_CENTER) { + return "HORIZONTAL_ALIGN_CENTER"; + } else if (align == HORIZONTAL_ALIGN_RIGHT) { + return "HORIZONTAL_ALIGN_RIGHT"; + } else if (align == HORIZONTAL_ALIGN_FULLSCREEN) { + return "HORIZONTAL_ALIGN_FULLSCREEN"; + } else if (align == HORIZONTAL_ALIGN_NOSCALE) { + return "HORIZONTAL_ALIGN_NOSCALE"; + } else if (align == HORIZONTAL_ALIGN_TO640) { + return "HORIZONTAL_ALIGN_TO640"; + } else if (align == HORIZONTAL_ALIGN_CENTER_SAFEAREA) { + return "HORIZONTAL_ALIGN_CENTER_SAFEAREA"; + } else if (align == HORIZONTAL_ALIGN_MAX) { + return "HORIZONTAL_ALIGN_CENTER_SAFEAREA"; + } else if (align == HORIZONTAL_ALIGN_DEFAULT) { + return "HORIZONTAL_ALIGN_SUBLEFT"; + } + return "HORIZONTAL_ALIGN_SUBLEFT"; + } + + static QColor ColorFromNormalized(float r, float g, float b, float a) { + // Ensure values are clamped between 0 and 1 + r = qBound(0.0f, r, 1.0f); + g = qBound(0.0f, g, 1.0f); + b = qBound(0.0f, b, 1.0f); + a = qBound(0.0f, a, 1.0f); + + // Convert to 0-255 scale + int red = static_cast(r * 255); + int green = static_cast(g * 255); + int blue = static_cast(b * 255); + int alpha = static_cast(a * 255); + + return QColor(red, green, blue, alpha); + } +}; + +#endif // UTILS_H diff --git a/libs/ddsfile/dds_structs.h b/libs/ddsfile/dds_structs.h new file mode 100644 index 0000000..9058a9a --- /dev/null +++ b/libs/ddsfile/dds_structs.h @@ -0,0 +1,8 @@ +#ifndef DDS_STRUCTS_H +#define DDS_STRUCTS_H + +#include +#include + + +#endif // DDS_STRUCTS_H diff --git a/libs/ddsfile/ddsfile.cpp b/libs/ddsfile/ddsfile.cpp new file mode 100644 index 0000000..bc99b47 --- /dev/null +++ b/libs/ddsfile/ddsfile.cpp @@ -0,0 +1,345 @@ +#include "ddsfile.h" +#include "iwifile.h" +#include "qdir.h" + +DDSPixelFormat DDSFile::CalculatePixelFormat(quint8 aIWIFormat) { + DDSPixelFormat ddsPixelFormat = {}; + ddsPixelFormat.size = 16; // Fixed + ddsPixelFormat.format = 0; + + switch (aIWIFormat) { + case IWI_FORMAT_ARGB32: + ddsPixelFormat.flags = DDPF_RGB | DDPF_ALPHAPIXELS; + ddsPixelFormat.rgbBitCount = 32; + ddsPixelFormat.rBitMask = 0x00ff0000; + ddsPixelFormat.gBitMask = 0x0000ff00; + ddsPixelFormat.bBitMask = 0x000000ff; + ddsPixelFormat.aBitMask = 0xff000000; + break; + case IWI_FORMAT_DXT1: + ddsPixelFormat.flags = DDPF_FOURCC; + ddsPixelFormat.format = 0x31545844; + break; + case IWI_FORMAT_DXT3: + ddsPixelFormat.flags = DDPF_FOURCC; + ddsPixelFormat.format = 0x33545844; + break; + case IWI_FORMAT_DXT5: + ddsPixelFormat.flags = DDPF_FOURCC; + ddsPixelFormat.format = 0x35545844; + break; + default: + qDebug() << "Error: Invalid IWI format: " << aIWIFormat; + return {}; + } + return ddsPixelFormat; +} + +void DDSFile::SetupExportDirs() { + QDir dir = QDir::currentPath(); + if (!dir.exists("exports/")) { + dir.mkdir("exports/"); + } + + if (!dir.exists("exports/iwi/")) { + dir.mkdir("exports/iwi/"); + } + if (!dir.exists("exports/dds/")) { + dir.mkdir("exports/dds/"); + } + if (!dir.exists("exports/png/")) { + dir.mkdir("exports/png/"); + } + if (!dir.exists("exports/jpg/")) { + dir.mkdir("exports/jpg/"); + } +} + +DDSFile::DDSFile() : + fileStem(), + header(), + mipmaps() { + +} + +QByteArray DDSFile::ReadDDSFile(const QString &aFilePath) { + if (!aFilePath.endsWith(".dds", Qt::CaseInsensitive)) { + qDebug() << "Error: Invalid filename " << aFilePath; + return {}; + } + + if (!QFile::exists(aFilePath)) { + qDebug() << "Error: File does not exist!"; + return {}; + } + + QFile file(aFilePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Error: Failed to read DDS file."; + return {}; + } + + const QByteArray ddsData = file.readAll(); + file.close(); + return ddsData; +} + +DDSFile::DDSFile(const QString &aFilePath) + : DDSFile(ReadDDSFile(aFilePath), aFilePath.split('.').first().split('/').last()) { +} + +DDSFile::DDSFile(const QByteArray aDDSData, const QString aFileStem) { + QDataStream ddsIn(aDDSData); + ddsIn.setByteOrder(QDataStream::LittleEndian); + + DDSHeader ddsHeader; + if (ddsIn.readRawData(reinterpret_cast(&ddsHeader), sizeof(DDSHeader)) != sizeof(DDSHeader)) { + qDebug() << "Error: Failed to read DDSHeader from QByteArray!"; + return; + } + + fileStem = aFileStem; + header = ddsHeader; + + // Ensure DevIL is initialized once globally + static bool devilInitialized = false; + if (!devilInitialized) { + ilInit(); + devilInitialized = true; + } + + // Generate and bind an image + ILuint imageID; + ilGenImages(1, &imageID); + ilBindImage(imageID); + + ilEnable(IL_ORIGIN_SET); + ilOriginFunc(IL_ORIGIN_UPPER_LEFT); + + // Load DDS file + if (!ilLoadL(IL_DDS, aDDSData.constData(), aDDSData.size())) { + ILuint devilError = ilGetError(); + qDebug() << "DevIL Error while loading DDS: " << devilError; + ilDeleteImages(1, &imageID); + return; + } + + // Get mipmap count + ILint numMipmaps = ilGetInteger(IL_NUM_MIPMAPS); + qDebug() << "Number of mipmaps: " << numMipmaps; + + // Loop over all mipmap levels (0 is the base image) + for (ILint level = 0; level <= numMipmaps; ++level) { + ilBindImage(imageID); + if (!ilActiveMipmap(level)) { + qDebug() << "DevIL failed to activate mipmap level" << level; + continue; + } + + // Get mipmap properties + int width = ilGetInteger(IL_IMAGE_WIDTH); + int height = ilGetInteger(IL_IMAGE_HEIGHT); + int depth = ilGetInteger(IL_IMAGE_DEPTH); + int format = ilGetInteger(IL_IMAGE_FORMAT); + int bpp = 0; + + switch (format) { + case IL_RGB: + bpp = 3; + break; + case IL_RGBA: + bpp = 4; + break; + default: + qDebug() << "Unsupported image format."; + continue; + } + + int dataSize = width * height * depth * bpp; + + ILubyte *data = ilGetData(); + if (!data) { + qDebug() << "Error: DevIL returned null data for mipmap level" << level; + continue; + } + + // Create a mipmap structure + DDSMipmap mipmap; + mipmap.width = width; + mipmap.height = height; + mipmap.data = QByteArray(reinterpret_cast(data), dataSize); + mipmap.size = dataSize; + + // Store in DDS file + mipmaps.append(mipmap); + } + + ilDeleteImages(1, &imageID); +} + +DDSFile::DDSFile(const DDSFile &ddsFile) : + fileStem(ddsFile.fileStem), + header(ddsFile.header), + mipmaps(ddsFile.mipmaps) { + +} + +DDSFile::DDSFile(const IWIFile &aIWIFile) + : DDSFile(IWItoDDSData(aIWIFile), aIWIFile.fileStem) { +} + +QByteArray DDSFile::IWItoDDSData(const IWIFile &aIWIFile) { + DDSHeader ddsHeader = {}; + ddsHeader.magic = 0x20534444; // 'DDS ' + ddsHeader.size = 124; + ddsHeader.flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_LINEARSIZE; + ddsHeader.height = aIWIFile.info.Height; + ddsHeader.width = aIWIFile.info.Width; + ddsHeader.depth = 0; + ddsHeader.mipMapCount = aIWIFile.mipmaps.size(); + + DDSPixelFormat ddsPixelFormat = CalculatePixelFormat(aIWIFile.info.Format); + if (ddsPixelFormat.flags & DDPF_FOURCC) { + ddsHeader.flags |= DDSD_LINEARSIZE; + } else { + ddsHeader.flags |= DDSD_PITCH; + } + ddsHeader.pixelFormat = ddsPixelFormat; + + // Calculate pitch/linear size + if (ddsPixelFormat.flags & DDPF_FOURCC) { + int blockSize = (ddsPixelFormat.format == 0x31545844) ? 8 : 16; + ddsHeader.pitchOrLinearSize = fmax(1, (ddsHeader.width + 3) / 4) * blockSize * (ddsHeader.height / 4); + } else { + ddsHeader.pitchOrLinearSize = ddsHeader.width * (ddsPixelFormat.rgbBitCount / 8); + } + + DDSCaps ddsCaps = {}; + ddsCaps.caps1 = DDSCAPS_TEXTURE; + ddsCaps.caps2 = 0; + ddsCaps.dDSX = 0; + ddsCaps.reserved = 0; + ddsHeader.caps = ddsCaps; + + QByteArray ddsData; + QDataStream out(&ddsData, QIODevice::WriteOnly); + out.setByteOrder(QDataStream::LittleEndian); + + // Write DDS header + out.writeRawData(reinterpret_cast(&ddsHeader), sizeof(DDSHeader)); + + for (auto mipmap : aIWIFile.mipmaps) { + if (!mipmap.data.size()) { continue; } + + // Write mipmap data + out.writeRawData(reinterpret_cast(mipmap.data.constData()), mipmap.data.size()); + } + + return ddsData; +} + +DDSFile &DDSFile::operator=(const DDSFile &other) { + if (this != &other) { + fileStem = other.fileStem; + header = other.header; + mipmaps = other.mipmaps; + } + return *this; +} + +// Write a DDS file from a DDSFile object +bool DDSFile::SaveDDS() { + SetupExportDirs(); + + QFile file("exports/dds/" + fileStem + ".dds"); + if (!file.open(QIODevice::WriteOnly)) { + qDebug() << "Error: Unable to write DDS file" << fileStem + ".dds"; + return false; + } + + QDataStream out(&file); + out.setByteOrder(QDataStream::LittleEndian); + + // Write DDS Header + out.writeRawData(reinterpret_cast(&header), sizeof(DDSHeader)); + file.close(); + + qDebug() << "Successfully wrote DDS file: " << fileStem + ".dds"; + return true; +} + +bool DDSFile::SaveIWI() { + SetupExportDirs(); + + IWIFile iwiFile(*this); + if (!iwiFile.SaveIWI()) { + qDebug() << "Error: Unable to write IWI file" << fileStem + ".iwi"; + return false; + } + return true; +} + +bool DDSFile::SavePNG() { + SetupExportDirs(); + + int mipmapIndex = 1; + for (const DDSMipmap &mipmap : mipmaps) { + QString subFilePath = "exports/png/" + fileStem + ".png"; + if (mipmaps.size() > 1) { + subFilePath = "exports/png/" + fileStem + QString("_%1").arg(mipmapIndex) + ".png"; + } + + // Calculate bytes per line (stride) + int bytesPerPixel = 4; // Assuming RGBA8888 (4 bytes per pixel) + int bytesPerLine = mipmap.width * bytesPerPixel; + + QImage image(reinterpret_cast(mipmap.data.constData()), + mipmap.width, mipmap.height, bytesPerLine, QImage::Format_RGBA8888); + + if (image.isNull()) { + qDebug() << "Error: Failed to create QImage for mipmap" << mipmapIndex; + return false; + } + + if (!image.save(subFilePath)) { + qDebug() << "Error: Unable to save PNG file" << subFilePath; + return false; + } + + mipmapIndex++; + } + return true; +} + +bool DDSFile::SaveJPG() { + SetupExportDirs(); + + int mipmapIndex = 1; + for (const DDSMipmap &mipmap : mipmaps) { + QString subFilePath = "exports/jpg/" + fileStem + ".jpg"; + if (mipmaps.size() > 1) { + subFilePath = "exports/jpg/" + fileStem + QString("_%1").arg(mipmapIndex) + ".jpg"; + } + + // Calculate bytes per line (stride) + int bytesPerPixel = 4; // Assuming RGBA8888 (4 bytes per pixel) + int bytesPerLine = mipmap.width * bytesPerPixel; + + QImage image(reinterpret_cast(mipmap.data.constData()), + mipmap.width, mipmap.height, bytesPerLine, QImage::Format_RGBA8888); + + if (image.isNull()) { + qDebug() << "Error: Failed to create QImage for mipmap" << mipmapIndex; + return false; + } + + if (!image.save(subFilePath, "JPG")) { + qDebug() << "Error: Unable to save JPG file" << subFilePath; + return false; + } + + mipmapIndex++; + } + return true; +} + diff --git a/libs/ddsfile/ddsfile.h b/libs/ddsfile/ddsfile.h new file mode 100644 index 0000000..a807e62 --- /dev/null +++ b/libs/ddsfile/ddsfile.h @@ -0,0 +1,84 @@ +#ifndef DDSFILE_H +#define DDSFILE_H + +#include "enums.h" +#include +#include +#include +#include +#include +#include +#include +#include + +struct DDSPixelFormat { + quint32 size; + quint32 flags; + quint32 format; + quint32 rgbBitCount; + quint32 rBitMask; + quint32 gBitMask; + quint32 bBitMask; + quint32 aBitMask; +}; + +struct DDSCaps { + quint32 caps1; + quint32 caps2; + quint32 dDSX; + quint32 reserved; +}; + +struct DDSHeader { + quint32 magic; + quint32 size; + quint32 flags; + quint32 height; + quint32 width; + quint32 pitchOrLinearSize; + quint32 depth; + quint32 mipMapCount; + quint32 reserved1[11]; + DDSPixelFormat pixelFormat; + DDSCaps caps; + quint32 reserved2; +}; + +// Mipmap Structure +struct DDSMipmap { + quint32 size; + quint32 width; + quint32 height; + QByteArray data; +}; + +class IWIFile; + +// DDS File Class +class DDSFile { +public: + QString fileStem; + DDSHeader header; + QVector mipmaps; + + DDSFile(); + DDSFile(const QString &aFilePath); + DDSFile(const IWIFile &aIWIFile); + DDSFile(const QByteArray aDDSData, const QString aFileStem); + DDSFile(const DDSFile &ddsFile); + DDSFile& operator=(const DDSFile& other); + + bool SaveDDS(); + bool SaveIWI(); + bool SavePNG(); + bool SaveJPG(); + + void SetupExportDirs(); + static DDSPixelFormat CalculatePixelFormat(quint8 aIWIFormat); + +private: + static QByteArray ReadDDSFile(const QString &aFilePath); + QByteArray IWItoDDSData(const IWIFile &aIWIFile); +}; + +#endif // DDSFILE_H diff --git a/libs/ddsfile/ddsfile.pro b/libs/ddsfile/ddsfile.pro new file mode 100644 index 0000000..10fbb3c --- /dev/null +++ b/libs/ddsfile/ddsfile.pro @@ -0,0 +1,27 @@ +QT += core +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + ddsfile.cpp + +HEADERS += \ + dds_structs.h \ + ddsfile.h \ + enums.h + +LIBS += \ + -L$$PWD/../../third_party/devil_sdk/lib/ -lDevIL \ + -L$$PWD/../../third_party/devil_sdk/lib/ -lILU \ + -L$$PWD/../../third_party/devil_sdk/lib/ -lILUT \ + -L$$OUT_PWD/../libs/iwifile -liwifile + +INCLUDEPATH += \ + $$PWD/../iwifile/ \ + $$PWD/../../third_party/devil_sdk/include/ + +DEPENDPATH += \ + $$PWD/../iwifile/ \ + $$PWD/../../third_party/devil_sdk/include/ + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/ddsfile/enums.h b/libs/ddsfile/enums.h new file mode 100644 index 0000000..b5f8204 --- /dev/null +++ b/libs/ddsfile/enums.h @@ -0,0 +1,876 @@ +#ifndef ENUMS_H +#define ENUMS_H + +#include + +enum FF_PLATFORM { + FF_PLATFORM_NONE = 0x00, // No platform + FF_PLATFORM_XBOX = 0x01, // Xbox 360 + FF_PLATFORM_PS3 = 0x02, // Playstation 3 + FF_PLATFORM_PC = 0x03 // PC +}; + +enum FF_GAME { + FF_GAME_NONE = 0x00, // No game + FF_GAME_COD1 = 0x01, // Call of Duty + FF_GAME_COD2 = 0x02, // Call of Duty 2 + FF_GAME_COD3 = 0x03, // Call of Duty 3 + FF_GAME_COD4 = 0x04, // Modern Warware 1 + FF_GAME_COD5 = 0x05, // World at War + FF_GAME_COD6 = 0x06, // Modern Warfare 2 + FF_GAME_COD7 = 0x07, // Black Ops 1 + FF_GAME_COD8 = 0x08, // Modern Warfare 3 + FF_GAME_COD9 = 0x09, // Black Ops 2 +}; + +enum IWI_VERSION { + IWI_VERSION_COD2 = 0x05, // 05 CoD2 + IWI_VERSION_COD4 = 0x06, // 06 CoD4 + IWI_VERSION_COD5 = 0x06, // 06 CoD5 + IWI_VERSION_CODMW2 = 0x08, // 08 CoDMW2 + IWI_VERSION_CODMW3 = 0x08, // 08 CoDMW3 + IWI_VERSION_CODBO1 = 0x0D, // 13 CoDBO1 + IWI_VERSION_CODBO2 = 0x1B, // 27 CoDBO2 +}; + +enum IWI_FORMAT { + // IWI Format + IWI_FORMAT_ARGB32 = 0x01, // 01 ARGB32 + IWI_FORMAT_RGB24 = 0x02, // 02 RGB24 + IWI_FORMAT_GA16 = 0x03, // 03 GA16 + IWI_FORMAT_A8 = 0x04, // 04 A8 + IWI_FORMAT_DXT1 = 0x0B, // 11 DXT1 + IWI_FORMAT_DXT3 = 0x0C, // 12 DXT3 + IWI_FORMAT_DXT5 = 0x0D // 13 DXT5 +}; + +enum DDS_FLAGS { + DDSD_CAPS = 0x1, + DDSD_HEIGHT = 0x2, + DDSD_WIDTH = 0x4, + DDSD_PITCH = 0x8, + DDSD_PIXELFORMAT = 0x1000, + DDSD_MIPMAPCOUNT = 0x20000, + DDSD_LINEARSIZE = 0x80000, + DDSD_DEPTH = 0x800000 +}; + +enum DDS_PIXELFORMAT_FLAGS { + DDPF_ALPHAPIXELS = 0x1, + DDPF_ALPHA = 0x2, + DDPF_FOURCC = 0x4, + DDPF_RGB = 0x40, + DDPF_YUV = 0x200, + DDPF_LUMINANCE = 0x20000 +}; + +enum DDS_CAPS_FLAGS { + DDSCAPS_COMPLEX = 0x8, + DDSCAPS_MIPMAP = 0x400000, + DDSCAPS_TEXTURE = 0x1000 +}; + +enum DDS_CAPS2_FLAGS { + DDSCAPS2_CUBEMAP = 0x200, // Indicates a cubemap. + DDSCAPS2_CUBEMAP_POSITIVEX = 0x400, + DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800, + DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000, + DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000, + DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000, + DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000, + DDSCAPS2_VOLUME = 0x200000 // Indicates that the texture is a volume texture. +}; + +enum LUMP_TYPE +{ + LUMP_MATERIALS = 0x0, + LUMP_LIGHTBYTES = 0x1, + LUMP_LIGHTGRIDENTRIES = 0x2, + LUMP_LIGHTGRIDCOLORS = 0x3, + LUMP_PLANES = 0x4, + LUMP_BRUSHSIDES = 0x5, + LUMP_BRUSHSIDEEDGECOUNTS = 0x6, + LUMP_BRUSHEDGES = 0x7, + LUMP_BRUSHES = 0x8, + LUMP_TRIANGLES = 0x9, + LUMP_DRAWVERTS = 0xA, + LUMP_DRAWINDICES = 0xB, + LUMP_CULLGROUPS = 0xC, + LUMP_CULLGROUPINDICES = 0xD, + LUMP_OBSOLETE_1 = 0xE, + LUMP_OBSOLETE_2 = 0xF, + LUMP_OBSOLETE_3 = 0x10, + LUMP_OBSOLETE_4 = 0x11, + LUMP_OBSOLETE_5 = 0x12, + LUMP_PORTALVERTS = 0x13, + LUMP_OBSOLETE_6 = 0x14, + LUMP_UINDS = 0x15, + LUMP_BRUSHVERTSCOUNTS = 0x16, + LUMP_BRUSHVERTS = 0x17, + LUMP_AABBTREES = 0x18, + LUMP_CELLS = 0x19, + LUMP_PORTALS = 0x1A, + LUMP_NODES = 0x1B, + LUMP_LEAFS = 0x1C, + LUMP_LEAFBRUSHES = 0x1D, + LUMP_LEAFSURFACES = 0x1E, + LUMP_COLLISIONVERTS = 0x1F, + LUMP_COLLISIONTRIS = 0x20, + LUMP_COLLISIONEDGEWALKABLE = 0x21, + LUMP_COLLISIONBORDERS = 0x22, + LUMP_COLLISIONPARTITIONS = 0x23, + LUMP_COLLISIONAABBS = 0x24, + LUMP_MODELS = 0x25, + LUMP_VISIBILITY = 0x26, + LUMP_ENTITIES = 0x27, + LUMP_PATHCONNECTIONS = 0x28, + LUMP_REFLECTION_PROBES = 0x29, + LUMP_VERTEX_LAYER_DATA = 0x2A, + LUMP_PRIMARY_LIGHTS = 0x2B, + LUMP_LIGHTGRIDHEADER = 0x2C, + LUMP_LIGHTGRIDROWS = 0x2D, + LUMP_OBSOLETE_10 = 0x2E, + + //Obsolete in BO1///////////////// + LUMP_UNLAYERED_TRIANGLES = 0x2F, + LUMP_UNLAYERED_DRAWVERTS = 0x30, + LUMP_UNLAYERED_DRAWINDICES = 0x31, + LUMP_UNLAYERED_CULLGROUPS = 0x32, + LUMP_UNLAYERED_AABBTREES = 0x33, + ////////////////////////////////// + + LUMP_WATERHEADER = 0x34, + LUMP_WATERCELLS = 0x35, + LUMP_WATERCELLDATA = 0x36, + LUMP_BURNABLEHEADER = 0x37, + LUMP_BURNABLECELLS = 0x38, + LUMP_BURNABLECELLDATA = 0x39, + LUMP_SIMPLELIGHTMAPBYTES = 0x3A, + LUMP_LODCHAINS = 0x3B, + LUMP_LODINFOS = 0x3C, + LUMP_LODSURFACES = 0x3D, + LUMP_LIGHTREGIONS = 0x3E, + LUMP_LIGHTREGION_HULLS = 0x3F, + LUMP_LIGHTREGION_AXES = 0x40, + LUMP_WIILIGHTGRID = 0x41, + LUMP_LIGHTGRID2D_LIGHTS = 0x42, + LUMP_LIGHTGRID2D_INDICES = 0x43, + LUMP_LIGHTGRID2D_POINTS = 0x44, + LUMP_LIGHTGRID2D_CELLS = 0x45, + LUMP_LIGHT_CORONAS = 0x46, + + //BO Specific///////////////////////// + LUMP_SHADOWMAP_VOLUMES = 0x47, + LUMP_SHADOWMAP_VOLUME_PLANES = 0x48, + LUMP_EXPOSURE_VOLUMES = 0x49, + LUMP_EXPOSURE_VOLUME_PLANES = 0x4A, + LUMP_OCCLUDERS = 0x4B, + LUMP_OUTDOORBOUNDS = 0x4C, + LUMP_HERO_ONLY_LIGHTS = 0x4D, + ////////////////////////////////////// + + INFO_LUMP_TYPE_COUNT +}; + +enum BSPVERSION_TYPE +{ + BSPVERSION_COD_WAW = 31, + BSPVERSION_COD_BO = 45 +}; + +enum FF_COMPANY { + COMPANY_NONE = 0x00, + COMPANY_INFINITY_WARD = 0x01, + COMPANY_TREYARCH = 0x02, + COMPANY_SLEDGEHAMMER = 0x03, + COMPANY_NEVERSOFT = 0x04 +}; + +enum FF_FILETYPE { + FILETYPE_NONE = 0x00, + FILETYPE_FAST_FILE = 0x01 +}; + +enum FF_SIGNAGE { + SIGNAGE_NONE = 0x00, + SIGNAGE_SIGNED = 0x01, + SIGNAGE_UNSIGNED = 0x02 +}; + +enum IMAGE_COMPRESSION { + COMPRESSION_NONE = 0x00, + COMPRESSION_DXT1 = 0x01, + COMPRESSION_DXT3 = 0x02, + COMPRESSION_DXT5 = 0x03 +}; +enum MENU_ITEM_TYPE { + ITEM_TYPE_TEXT = 0, // simple text + ITEM_TYPE_BUTTON = 1, // button, basically text with a border + ITEM_TYPE_RADIOBUTTON = 2, // toggle button, may be grouped + ITEM_TYPE_CHECKBOX = 3, // check box + ITEM_TYPE_EDITFIELD = 4, // editable text, associated with a dvar + ITEM_TYPE_COMBO = 5, // drop down list + ITEM_TYPE_LISTBOX = 6, // scrollable list + ITEM_TYPE_MODEL = 7, // model + ITEM_TYPE_OWNERDRAW = 8, // owner draw, name specs what it is + ITEM_TYPE_NUMERICFIELD = 9, // editable text, associated with a dvar + ITEM_TYPE_SLIDER = 10, // mouse speed, volume, etc. + ITEM_TYPE_YESNO = 11, // yes no dvar setting + ITEM_TYPE_MULTI = 12, // multiple list setting, enumerated + ITEM_TYPE_DVARENUM = 13, // multiple list setting, enumerated from a dvar + ITEM_TYPE_BIND = 14, // bind + ITEM_TYPE_MENUMODEL = 15, // special menu model + ITEM_TYPE_VALIDFILEFIELD = 16, // text must be valid for use in a dos filename + ITEM_TYPE_DECIMALFIELD = 17, // editable text, associated with a dvar, which allows decimal input + ITEM_TYPE_UPREDITFIELD = 18, // editable text, associated with a dvar + ITEM_TYPE_GAME_MESSAGE_WINDOW = 19, // game message window + ITEM_TYPE_SCALEFORM = 20, // Flash movie for Scaleform GFx + ITEM_TYPE_BIND2 = 21, // bind2 +}; + +enum MENU_ITEM_H_ALIGN { + ITEM_ALIGN_LEFT = 0, // aligns left of text to left of containing rectangle + ITEM_ALIGN_CENTER = 1, // aligns center of text to center of containing rectangle + ITEM_ALIGN_RIGHT = 2, // aligns right of text to right of containing rectangle + ITEM_ALIGN_X_MASK = 3, +}; + +enum MENU_ITEM_V_ALIGN { + ITEM_ALIGN_LEGACY = 0, // aligns bottom of text to top of containing rectangle + ITEM_ALIGN_TOP = 4, // aligns top of text to top of containing rectangle + ITEM_ALIGN_MIDDLE = 8, // aligns middle of text to middle of containing rectangle + ITEM_ALIGN_BOTTOM = 12, // aligns bottom of text to bottom of containing rectangle + ITEM_ALIGN_Y_MASK = 12, +}; + +enum MENU_ITEM_ALIGN { + ITEM_ALIGN_LEGACY_LEFT = 0, + ITEM_ALIGN_LEGACY_CENTER = 1, + ITEM_ALIGN_LEGACY_RIGHT = 2, + ITEM_ALIGN_TOP_LEFT = 4, + ITEM_ALIGN_TOP_CENTER = 5, + ITEM_ALIGN_TOP_RIGHT = 6, + ITEM_ALIGN_MIDDLE_LEFT = 8, + ITEM_ALIGN_MIDDLE_CENTER = 9, + ITEM_ALIGN_MIDDLE_RIGHT = 10, + ITEM_ALIGN_BOTTOM_LEFT = 12, + ITEM_ALIGN_BOTTOM_CENTER = 13, + ITEM_ALIGN_BOTTOM_RIGHT = 14 +}; + +enum MENU_ITEM_TEXTSTYLE { + ITEM_TEXTSTYLE_NORMAL = 0, // normal text + ITEM_TEXTSTYLE_BLINK = 1, // fast blinking + ITEM_TEXTSTYLE_SHADOWED = 3, // drop shadow ( need a color for this ) + ITEM_TEXTSTYLE_SHADOWEDMORE = 6, // drop shadow ( need a color for this ) + ITEM_TEXTSTYLE_MONOSPACE = 128 +}; + +enum MENU_WINDOW_BORDER { + WINDOW_BORDER_NONE = 0, // no border + WINDOW_BORDER_FULL = 1, // full border based on border color ( single pixel ) + WINDOW_BORDER_HORZ = 2, // horizontal borders only + WINDOW_BORDER_VERT = 3, // vertical borders only + WINDOW_BORDER_KCGRADIENT = 4, // horizontal border using the gradient bars + WINDOW_BORDER_RAISED = 5, // darken the bottom and right sides of the border + WINDOW_BORDER_SUNKEN = 6 // darken the top and left sides of the border +}; + +enum MENU_WINDOW_STYLE { + WINDOW_STYLE_EMPTY = 0, // no background + WINDOW_STYLE_FILLED = 1, // filled with background color + WINDOW_STYLE_GRADIENT = 2, // gradient bar based on background color + WINDOW_STYLE_SHADER = 3, // shader based on background color + WINDOW_STYLE_TEAMCOLOR = 4, // team color + WINDOW_STYLE_DVAR_SHADER = 5, // draws the shader specified by the dvar + WINDOW_STYLE_LOADBAR = 6, // shader based on background color +}; + +enum MENU_MODE { + MODE_BOTTOMUP_ALIGN_TOP = 0, // text appears on bottom of list and moves up to specified Y coordinate as old text fades out + MODE_BOTTOMUP_ALIGN_BOTTOM = 1, // text appears on bottom of list and moves away from specified Y coordinate as new text pushes it up + MODE_TOPDOWN_ALIGN_TOP = 2, // text appears on top of list and moves away from specified Y coordinate as new text pushes it down + MODE_TOPDOWN_ALIGN_BOTTOM = 3 // text appears on top of list and moves down to specified Y coordinate as old text fades out +}; + +enum MENU_BOOL { + MENU_TRUE = 1, + MENU_FALSE = 0 +}; + +enum MENU_ORIENTATION { + HUD_VERTICAL = 0x00, + HUD_HORIZONTAL = 0x01 +}; + +enum MENU_RANGETYPE { + RANGETYPE_ABSOLUTE = 0, + RANGETYPE_RELATIVE = 1 +}; + +// list box element types +enum MENU_LIST_BOX { + LISTBOX_TEXT = 0x00, + LISTBOX_IMAGE = 0x01 +}; + +// list feeders +enum MENU_FEEDERS { + FEEDER_HEADS = 0x00, // model heads + FEEDER_MAPS = 0x01, // text maps based on game type + FEEDER_SERVERS = 0x02, // servers + FEEDER_CLAN_MEMBERS = 0x03, // clan names + FEEDER_ALLMAPS = 0x04, // all maps available, in graphic format + FEEDER_REDTEAM_LIST = 0x05, // red team members + FEEDER_BLUETEAM_LIST = 0x06, // blue team members + FEEDER_PLAYER_LIST = 0x07, // players + FEEDER_TEAM_LIST = 0x08, // team members for team voting + FEEDER_MODS = 0x09, // team members for team voting + FEEDER_DEMOS = 0x0a, // team members for team voting + FEEDER_SCOREBOARD = 0x0b, // team members for team voting + FEEDER_Q3HEADS = 0x0c, // model heads + FEEDER_SERVERSTATUS = 0x0d, // server status + FEEDER_FINDPLAYER = 0x0e, // find player + FEEDER_CINEMATICS = 0x0f, // cinematics + FEEDER_SAVEGAMES = 0x10, // savegames + FEEDER_PICKSPAWN = 0x11, // pickspawn + FEEDER_LOBBY_MEMBERS = 0x12, // list of players in your party + FEEDER_LOBBY_MEMBERS_TALK = 0x13, // icon for whether they are speaking or not + FEEDER_MUTELIST = 0x14, // list of musted players + FEEDER_PLAYERSTALKING = 0x15, // list of players who are currently talking + FEEDER_SPLITSCREENPLAYERS = 0x16, // list of all players who are playing splitscreen + FEEDER_LOBBY_MEMBERS_READY = 0x17, // icon for whether they are ready or not + FEEDER_PLAYER_PROFILES = 0x18, // player profiles + FEEDER_PARTY_MEMBERS = 0x19, // list of players in your party + FEEDER_PARTY_MEMBERS_TALK = 0x1a, // icon for whether they are speaking or not + FEEDER_PARTY_MEMBERS_READY = 0x1b, // icon for whether they are ready or not + FEEDER_PLAYLISTS = 0x1c, // list of all playlists + FEEDER_GAMEMODES = 0x1d, // list of all game type modes, including any player custom modes + FEEDER_CATEGORIES = 0x1e, // list of all categories + FEEDER_LEADERBOARD = 0x1f, // list of rows for a leaderboard + FEEDER_MYTEAM_MEMBERS = 0x20, // list of marine team members + FEEDER_MYTEAM_MEMBERS_TALK = 0x21, // icon for whether they are speaking + FEEDER_ENEMY_MEMBERS = 0x22, // list of opfor team members + FEEDER_ENEMY_MEMBERS_TALK = 0x23, // icon for whether they are speaking + FEEDER_LOBBY_MEMBERS_STAT = 0x24, // last round stats for lobby members + FEEDER_MYTEAM_MEMBERS_STAT = 0x25, // last round stats for marine team members + FEEDER_ENEMY_MEMBERS_STAT = 0x26, // last round stats for opfor team members + FEEDER_ONLINEFRIENDS = 0x27, // list of your online friends + FEEDER_LOBBY_MEMBERS_RANK = 0x28, // rank icon + FEEDER_PARTY_MEMBERS_RANK = 0x29, // rank icon + FEEDER_ENEMY_MEMBERS_RANK = 0x2a, // rank icon + FEEDER_MYTEAM_MEMBERS_RANK = 0x2b, // rank icon + FEEDER_TESTMAPS = 0x2c, // department test maps + FEEDER_SYSTEMLINK_LOBBY_MEMBERS = 0x2d, // list of players in a system link lobby + FEEDER_LOBBY_MEMBERS_CONTROLLER = 0x2e, // icon for controller quadrant for splitscreen + FEEDER_PARTY_MEMBERS_CONTROLLER = 0x2f, // icon for controller quadrant for splitscreen + FEEDER_MYTEAM_MEMBERS_SQUAD = 0x30, // squad icon + FEEDER_ENEMY_MEMBERS_SQUAD = 0x31, // squad icon + FEEDER_INGAME_SQUAD_MEMBERS = 0x32, // Squad members displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_MEMBERS_FULL = 0x33, // Squad members' name, rank, talk, leader displayed in PC MP 'Pause' menu + FEEDER_INGAME_SQUAD_NAMES = 0x34, // Squad names displayed in MP 'Join Squad' menu + FEEDER_INGAME_SQUAD_NAMES2 = 0x35, // Squad names displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_NAMES_FULL = 0x36, // Squad names, lock, invite displayed in PC MP 'Pause' menu + FEEDER_CUSTOM_GAMETYPES = 0x37, // list of all the gametypes for custom matches + FEEDER_INGAME_SQUAD_MEMBER_RANK = 0x38, // Squad members' rank displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_MEMBER_TALK = 0x39, // Squad members' talk icon displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_LOCKED = 0x3a, // Squad lock icon displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_MEMBER_INVITED = 0x3b, // Squad invite icon displayed in MP 'Pause' menu + FEEDER_INGAME_SQUAD_INVITE = 0x3c, // Squad invite icon displayed in MP 'Join Squad' menu + FEEDER_INGAME_SQUAD_LEADER = 0x3d, // Squad leader icon displayled in MP 'Pause' menu + FEEDER_FRIENDS = 0x3e, // list of your friends + FEEDER_PENDINGFRIENDS = 0x3f, // list of your pending friends + FEEDER_INVITES = 0x40, // list of the game invites from your friends +}; + +// display flags +enum MENU_DISPLAY_FLAG { + CG_SHOW_BLUE_TEAM_HAS_REDFLAG = 0x00000001, + CG_SHOW_RED_TEAM_HAS_BLUEFLAG = 0x00000002, + CG_SHOW_ANYTEAMGAME = 0x00000004, + CG_SHOW_CTF = 0x00000020, + CG_SHOW_OBELISK = 0x00000040, + CG_SHOW_HEALTHCRITICAL = 0x00000080, + CG_SHOW_SINGLEPLAYER = 0x00000100, + CG_SHOW_TOURNAMENT = 0x00000200, + CG_SHOW_DURINGINCOMINGVOICE = 0x00000400, + CG_SHOW_IF_PLAYER_HAS_FLAG = 0x00000800, + CG_SHOW_LANPLAYONLY = 0x00001000, + CG_SHOW_MINED = 0x00002000, + CG_SHOW_HEALTHOK = 0x00004000, + CG_SHOW_TEAMINFO = 0x00008000, + CG_SHOW_NOTEAMINFO = 0x00010000, + CG_SHOW_OTHERTEAMHASFLAG = 0x00020000, + CG_SHOW_YOURTEAMHASENEMYFLAG = 0x00040000, + CG_SHOW_ANYNONTEAMGAME = 0x00080000, + CG_SHOW_TEXTASINT = 0x00200000, + CG_SHOW_HIGHLIGHTED = 0x00100000, + CG_SHOW_NOT_V_CLEAR = 0x02000000, + CG_SHOW_2DONLY = 0x10000000 +}; + +enum MENU_UI_FLAG{ + UI_SHOW_LEADER = 0x00000001, + UI_SHOW_NOTLEADER = 0x00000002, + UI_SHOW_FAVORITESERVERS = 0x00000004, + UI_SHOW_ANYNONTEAMGAME = 0x00000008, + UI_SHOW_ANYTEAMGAME = 0x00000010, + UI_SHOW_NEWHIGHSCORE = 0x00000020, + UI_SHOW_DEMOAVAILABLE = 0x00000040, + UI_SHOW_NEWBESTTIME = 0x00000080, + UI_SHOW_FFA = 0x00000100, + UI_SHOW_NOTFFA = 0x00000200, + UI_SHOW_NETANYNONTEAMGAME = 0x00000400, + UI_SHOW_NETANYTEAMGAME = 0x00000800, + UI_SHOW_NOTFAVORITESERVERS = 0x00001000 +}; + +// font types +enum MENU_FONT_TYPE{ + UI_FONT_DEFAULT = 0, // auto-chose betwen big/reg/small + UI_FONT_NORMAL = 1, + UI_FONT_BIG = 2, + UI_FONT_SMALL = 3, + UI_FONT_BOLD = 4, + UI_FONT_CONSOLE = 5, + UI_FONT_OBJECTIVE = 6, + UI_FONT_MAX = 6, +}; + +// owner draw types +// ideally these should be done outside of this file but +// this makes it much easier for the macro expansion to +// convert them for the designers ( from the .menu files ) +enum MENU_OWNER_DRAW_TYPE { + CG_OWNERDRAW_BASE = 1, + CG_PLAYER_AMMO_VALUE = 5, + CG_PLAYER_AMMO_BACKDROP = 6, + CG_PLAYER_HEAT_VALUE = 7, + CG_PLAYER_STANCE = 20, + CG_SPECTATORS = 60, + CG_HOLD_BREATH_HINT = 71, + CG_CURSORHINT = 72, + CG_PLAYER_POWERUP = 73, + CG_PLAYER_HOLDABLE = 74, + CG_PLAYER_INVENTORY = 75, + CG_CURSORHINT_STATUS = 78, // like 'health' bar when pointing at a func_explosive + CG_PLAYER_BAR_HEALTH = 79, + CG_MANTLE_HINT = 80, + CG_PLAYER_WEAPON_NAME = 81, + CG_PLAYER_WEAPON_NAME_BACK = 82, + CG_CENTER_MESSAGE = 90, // for things like "You were killed by ..." + CG_TANK_BODY_DIR = 95, + CG_TANK_BARREL_DIR = 96, + CG_DEADQUOTE = 97, + CG_PLAYER_BAR_HEALTH_BACK = 98, + CG_MISSION_OBJECTIVE_HEADER = 99, + CG_MISSION_OBJECTIVE_LIST = 100, + CG_MISSION_OBJECTIVE_BACKDROP = 101, + CG_PAUSED_MENU_LINE = 102, + CG_OFFHAND_WEAPON_ICON_FRAG = 103, + CG_OFFHAND_WEAPON_ICON_SMOKEFLASH = 104, + CG_OFFHAND_WEAPON_AMMO_FRAG = 105, + CG_OFFHAND_WEAPON_AMMO_SMOKEFLASH = 106, + CG_OFFHAND_WEAPON_NAME_FRAG = 107, + CG_OFFHAND_WEAPON_NAME_SMOKEFLASH = 108, + CG_OFFHAND_WEAPON_SELECT_FRAG = 109, + CG_OFFHAND_WEAPON_SELECT_SMOKEFLASH = 110, + CG_SAVING = 111, + CG_PLAYER_LOW_HEALTH_OVERLAY = 112, + CG_INVALID_CMD_HINT = 113, + CG_PLAYER_SPRINT_METER = 114, + CG_PLAYER_SPRINT_BACK = 115, + CG_PLAYER_WEAPON_BACKGROUND = 116, + CG_PLAYER_WEAPON_AMMO_CLIP_GRAPHIC = 117, + CG_PLAYER_WEAPON_PRIMARY_ICON = 118, + CG_PLAYER_WEAPON_AMMO_STOCK = 119, + CG_PLAYER_WEAPON_LOW_AMMO_WARNING = 120, + CG_BATTLE_COMPASS_MARKERS = 122, + CG_BATTLE_FULLMAP_MARKERS = 123, + CG_SUCCESSFUL_CMD_HINT = 130, + CG_WAR_TEXT = 135, + CG_PLAYER_COMPASS_TICKERTAPE = 145, + CG_PLAYER_COMPASS_TICKERTAPE_NO_OBJ = 146, + CG_PLAYER_COMPASS_DOGS = 147, + CG_PLAYER_COMPASS_ARTILLERY_ICON = 148, + CG_PLAYER_COMPASS_SQUAD_OBJECTIVE = 149, + CG_PLAYER_COMPASS_PLAYER = 150, + CG_PLAYER_COMPASS_BACK = 151, + CG_PLAYER_COMPASS_POINTERS = 152, + CG_PLAYER_COMPASS_ACTORS = 153, + CG_PLAYER_COMPASS_TANKS = 154, + CG_PLAYER_COMPASS_HELICOPTERS = 155, + CG_PLAYER_COMPASS_PLANES = 156, + CG_PLAYER_COMPASS_AUTOMOBILES = 157, + CG_PLAYER_COMPASS_FRIENDS = 158, + CG_PLAYER_COMPASS_MAP = 159, + CG_PLAYER_COMPASS_NORTHCOORD = 160, + CG_PLAYER_COMPASS_EASTCOORD = 161, + CG_PLAYER_COMPASS_NCOORD_SCROLL = 162, + CG_PLAYER_COMPASS_ECOORD_SCROLL = 163, + CG_PLAYER_COMPASS_GOALDISTANCE = 164, + CG_PLAYER_ACTIONSLOT_DPAD = 165, + CG_PLAYER_ACTIONSLOT_1 = 166, + CG_PLAYER_ACTIONSLOT_2 = 167, + CG_PLAYER_ACTIONSLOT_3 = 168, + CG_PLAYER_ACTIONSLOT_4 = 169, + CG_PLAYER_COMPASS_ENEMIES = 170, + CG_PLAYER_FULLMAP_DOGS = 176, + CG_PLAYER_FULLMAP_VEHICLES = 177, + CG_PLAYER_FULLMAP_ARTILLERY_ICON = 178, + CG_PLAYER_FULLMAP_SQUAD_OBJECTIVE = 179, + CG_PLAYER_FULLMAP_BACK = 180, + CG_PLAYER_FULLMAP_MAP = 181, + CG_PLAYER_FULLMAP_POINTERS = 182, + CG_PLAYER_FULLMAP_PLAYER = 183, + CG_PLAYER_FULLMAP_ACTORS = 184, + CG_PLAYER_FULLMAP_FRIENDS = 185, + CG_PLAYER_FULLMAP_LOCATION_SELECTOR = 186, + CG_PLAYER_FULLMAP_BORDER = 187, + CG_PLAYER_FULLMAP_ENEMIES = 188, + CG_PLAYER_COMPASS = 189, + CG_VEHICLE_RETICLE = 190, + CG_HUD_TARGETS_VEHICLE = 191, + CG_HUD_TARGETS_JAVELIN = 192, + CG_TALKER1 = 193, + CG_TALKER2 = 194, + CG_TALKER3 = 195, + CG_TALKER4 = 196, + CG_FRIENDLYARROWS = 197, + CG_FRIENDLYNAMES = 198, + UI_OWNERDRAW_BASE = 200, + UI_HANDICAP = 200, + UI_EFFECTS = 201, + UI_PLAYERMODEL = 202, + UI_GAMETYPE = 205, + UI_SKILL = 207, + UI_NETSOURCE = 220, + UI_NETFILTER = 222, + UI_VOTE_KICK = 238, + UI_NETGAMETYPE = 245, + UI_SERVERREFRESHDATE = 247, + UI_SERVERMOTD = 248, + UI_GLINFO = 249, + UI_KEYBINDSTATUS = 250, + UI_JOINGAMETYPE = 253, + UI_MAPPREVIEW = 254, + UI_MENUMODEL = 257, + UI_SAVEGAME_SHOT = 258, + UI_SAVEGAMENAME = 262, + UI_SAVEGAMEINFO = 263, + UI_LOADPROFILING = 264, + UI_RECORDLEVEL = 265, + UI_AMITALKING = 266, + UI_TALKER1 = 267, + UI_TALKER2 = 268, + UI_TALKER3 = 269, + UI_TALKER4 = 270, + UI_PARTYSTATUS = 271, + UI_LOGGEDINUSER = 272, + UI_RESERVEDSLOTS = 273, + UI_PLAYLISTNAME = 274, + UI_PLAYLISTDESCRIPTION = 275, + UI_USERNAME = 276, + UI_CINEMATIC = 277, + UI_TOTALONLINE = 278, + UI_CATEGORYNAME = 279, + UI_CATEGORYDESCRIPTION = 280, + UI_PLAYLISTICON = 281, + UI_CATEGORYICON = 282, + UI_GAMETYPE_MAPNAME = 283, + CG_HUD_WAR_MOMENTUM_PROGRESS = 284, + CG_HUD_WAR_MOMENTUM_MULTIPLIER = 285, + CG_HUD_WAR_MOMENTUM_MULTIPLIER_DETAIL = 286, + CG_HUD_WAR_MOMENTUM_MULTIPLIER_BLITZKRIEG = 287, + CG_COMPETITIVE_MODE_SCORES = 288, + UI_LOAD_STATUS_SCREEN = 289, + UI_LEADERBOARD_GAMEMODE = 290, + CG_PLAYER_ACTIONSLOT_BACK_1 = 290, + CG_PLAYER_ACTIONSLOT_BACK_2 = 291, + CG_PLAYER_ACTIONSLOT_BACK_3 = 292, + CG_PLAYER_ACTIONSLOT_BACK_4 = 293, + CG_PLAYER_ACTIONSLOT_ARROW_1 = 294, + CG_PLAYER_ACTIONSLOT_ARROW_2 = 295, + CG_PLAYER_ACTIONSLOT_ARROW_3 = 296, + CG_PLAYER_ACTIONSLOT_ARROW_4 = 297, + UI_DIFFICULTY_INFO = 298, + UI_DIFFICULTY_ICON = 299, + UI_LOBBY_CHAT = 300 +}; + +// Edge relative placement values for rect->h_align and rect->v_align +enum MENU_H_ALIGNMENT { + HORIZONTAL_ALIGN_SUBLEFT = 0, // left edge of a 4:3 screen (safe area not included) + HORIZONTAL_ALIGN_LEFT = 1, // left viewable (safe area) edge + HORIZONTAL_ALIGN_CENTER = 2, // center of the screen (reticle) + HORIZONTAL_ALIGN_RIGHT = 3, // right viewable (safe area) edge + HORIZONTAL_ALIGN_FULLSCREEN = 4, // disregards safe area + HORIZONTAL_ALIGN_NOSCALE = 5, // uses exact parameters - neither adjusts for safe area nor scales for screen size + HORIZONTAL_ALIGN_TO640 = 6, // scales a real-screen resolution x down into the 0 - 640 range + HORIZONTAL_ALIGN_CENTER_SAFEAREA = 7, // center of the safearea + HORIZONTAL_ALIGN_MAX = HORIZONTAL_ALIGN_CENTER_SAFEAREA, + HORIZONTAL_ALIGN_DEFAULT = HORIZONTAL_ALIGN_SUBLEFT +}; + +enum MENU_V_ALIGNMENT { + VERTICAL_ALIGN_SUBTOP = 0, // top edge of the 4:3 screen (safe area not included) + VERTICAL_ALIGN_TOP = 1, // top viewable (safe area) edge + VERTICAL_ALIGN_CENTER = 2, // center of the screen (reticle) + VERTICAL_ALIGN_BOTTOM = 3, // bottom viewable (safe area) edge + VERTICAL_ALIGN_FULLSCREEN = 4, // disregards safe area + VERTICAL_ALIGN_NOSCALE = 5, // uses exact parameters - neither adjusts for safe area nor scales for screen size + VERTICAL_ALIGN_TO480 = 6, // scales a real-screen resolution y down into the 0 - 480 range + VERTICAL_ALIGN_CENTER_SAFEAREA = 7, // center of the save area + VERTICAL_ALIGN_MAX = VERTICAL_ALIGN_CENTER_SAFEAREA, + VERTICAL_ALIGN_DEFAULT = VERTICAL_ALIGN_SUBTOP +}; + +enum MENU_BUTTON { + BUTTON_A = 1, + BUTTON_B = 2, + BUTTON_X = 3, + BUTTON_Y = 4, + BUTTON_LSHLDR = 5, + BUTTON_RSHLDR = 6, + BUTTON_START = 14, + BUTTON_BACK = 15, + BUTTON_LSTICK = 16, + BUTTON_RSTICK = 17, + BUTTON_LTRIG = 18, + BUTTON_RTRIG = 19, + DPAD_UP = 20, + DPAD_DOWN = 21, + DPAD_LEFT = 22, + DPAD_RIGHT = 23, + APAD_UP = 28, + APAD_DOWN = 29, + APAD_LEFT = 30, + APAD_RIGHT = 31 +}; + +enum ASSET_TYPE { + ASSET_UNKNOWN = 0, + ASSET_ANIMATION = 4, // x_anim PARTIALLY VERIFIED + ASSET_MODEL = 5, // xmodel PARTIALLY VERIFIED + ASSET_MATERIAL = 6, // material VERIFIED + ASSET_BIK_FILE = 7, // .bik file PARTIALLY VERIFIED + ASSET_SOUND = 9, // loaded_sound VERIFIED + ASSET_COLLISION_MAP = 12, // collision_map PARTIALLY VERIFIED + ASSET_SHADER = 13, // shader PARTIALLY VERIFIED + ASSET_D3DBSP_DUMP = 17, // d3dbsp dump VERIFIED + ASSET_FONT = 20, // font PARTIALLY VERIFIED + ASSET_MENU = 21, // menu_file VERIFIED + ASSET_LOCAL_STRING = 23, // localized string VERIFIED + ASSET_WEAPON = 24, // weapon VERIFIED + ASSET_EFFECT = 26, // fx VERIFIED + ASSET_RAW_FILE = 32, // raw_file VERIFIED + ASSET_STRING_TABLE = 33 // string_table PARTIALLY VERIFIED +}; + +enum SHADER_TYPE { + SHADER_NONE = 0x00, + SHADER_PIXEL = 0x01, + SHADER_VERTEX = 0x02 +}; + +enum SHADER_OPCODE { + OPCODE_Nop, + OPCODE_Mov, + OPCODE_Add, + OPCODE_Sub, + OPCODE_Mad, + OPCODE_Mul, + OPCODE_Rcp, + OPCODE_Rsq, + OPCODE_Dp3, + OPCODE_Dp4, + OPCODE_Min, + OPCODE_Max, + OPCODE_Slt, + OPCODE_Sge, + OPCODE_Exp, + OPCODE_Log, + OPCODE_Lit, + OPCODE_Dst, + OPCODE_Lrp, + OPCODE_Frc, + OPCODE_M4x4, + OPCODE_M4x3, + OPCODE_M3x4, + OPCODE_M3x3, + OPCODE_M3x2, + OPCODE_Call, + OPCODE_CallNZ, + OPCODE_Loop, + OPCODE_Ret, + OPCODE_EndLoop, + OPCODE_Label, + OPCODE_Dcl, + OPCODE_Pow, + OPCODE_Crs, + OPCODE_Sgn, + OPCODE_Abs, + OPCODE_Nrm, + OPCODE_SinCos, + OPCODE_Rep, + OPCODE_EndRep, + OPCODE_If, + OPCODE_IfC, + OPCODE_Else, + OPCODE_Endif, + OPCODE_Break, + OPCODE_BreakC, + OPCODE_MovA, + OPCODE_DefB, + OPCODE_DefI, + OPCODE_TexCoord = 64, + OPCODE_TexKill, + OPCODE_Tex, + OPCODE_TexBem, + OPCODE_TexBeml, + OPCODE_TexReg2AR, + OPCODE_TexReg2GB, + OPCODE_TeXM3x2Pad, + OPCODE_TexM3x2Tex, + OPCODE_TeXM3x3Pad, + OPCODE_TexM3x3Tex, + OPCODE_TexM3x3Diff, + OPCODE_TexM3x3Spec, + OPCODE_TexM3x3VSpec, + OPCODE_ExpP, + OPCODE_LogP, + OPCODE_Cnd, + OPCODE_Def, + OPCODE_TexReg2RGB, + OPCODE_TexDP3Tex, + OPCODE_TexM3x2Depth, + OPCODE_TexDP3, + OPCODE_TexM3x3, + OPCODE_TexDepth, + OPCODE_Cmp, + OPCODE_Bem, + OPCODE_DP2Add, + OPCODE_DSX, + OPCODE_DSY, + OPCODE_TexLDD, + OPCODE_SetP, + OPCODE_TexLDL, + OPCODE_Breakp, + OPCODE_Phase = 0xFFFD, + OPCODE_Comment = 0xFFFE, + OPCODE_End = 0xFFFF +}; + +#define SECTION_TYPE_INFO 1 +#define SECTION_TYPE_DATA 2 + +#define IPAK_SECTION_ENTRY 1 +#define IPAK_SECTION_DATA 2 +#define IPAK_SECTION_METADATA 3 + +#define FORMAT_DXT1 0 +#define FORMAT_DXT3 1 +#define FORMAT_DXT5 2 +#define FORMAT_A8R8G8B8 3 + +// Change this depending on the platform +// PC +#define DEVMAP_LEVEL_FIRST "devmap intro_pac" +#define DEVMAP "devmap" +// Not PC +// #define DEVMAP_LEVEL_FIRST "map intro_pac" +// #define DEVMAP "map" + +// Remove this to restore full frontend instead of limited EPD frontend +#define COOP_EPD 0 + +// LDS - This enables a German SKU with Nazi Zombies enabled *SHOULD BE SET TO 0 IF NOT APPROVED* +#define GERMAN_ZOMBIE_BUILD 0 + +#define DEVMAP_LEVEL_TRAINING "devmap training" +#define LEVEL_FIRST "intro_pac" +#define LEVEL_TRAINING "training" +#define FIRST_PLAYABLE_CAMPAIGN_LEVEL "mak" +#define FIRST_PLAYABLE_ZOMBIE_LEVEL "nazi_zombie_prototype" + +// Size define for the hud compass +// These are used for both the dynamic & non-dynamic compass drawing +// If these are changed, the cgame should be recompiled +#define COMPASS_SIZE 160 +#define MINIMAP_X 11.5 +#define MINIMAP_Y 5 +#define MINIMAP_W 89.5 +#define MINIMAP_H 89.5 + +#define COMPASS_SIZE_MP 125 +#define MINIMAP_X_MP 0 +#define MINIMAP_Y_MP 12 +#define MINIMAP_W_MP 102 +#define MINIMAP_H_MP 102 + +#define FULLSCREEN 0 0 640 480 +#define FULLSCREEN_WIDE -107 0 854 480 + +// PC +#define ORIGIN_TITLE 30 34 +// Not PC +// #define ORIGIN_TITLE 0 0 + +#define ORIGIN_TITLE_SS 104 120 + +#define FONTSCALE_SMALL 0.3095 //0.3750 // <-- COD4 // COD5 --> 0.30952//0.35897//0.24138 //14 pt //0.2900 //0.2750 // 18 +#define FONTSCALE_LOBBY 0.26 // <--Slate // 0.3010 <-- Slate Compressed // 0.3750 // <-- COD4 CONDUIT ITC small +#define FONTSCALE_NORMAL 0.3810 //0.35897//0.4583 +#define FONTSCALE_BOLD 0.5476 //0.4583 +#define FONTSCALE_BIG 0.5476 //0.5833 +#define FONTSCALE_EXTRABIG 1 //1.0000 + +// new settings +#define TEXTSIZE_SMALL FONTSCALE_SMALL +#define TEXTSIZE_SMALL_SS (FONTSCALE_SMALL*2) +#define TEXTSIZE_DEFAULT FONTSCALE_NORMAL +#define TEXTSIZE_DEFAULT_SS (FONTSCALE_NORMAL*2) +#define TEXTSIZE_TITLE FONTSCALE_BIG +#define TEXTSIZE_TITLE_SS 1 + +#define TEXTSIZE_BOLD TEXTSIZE_DEFAULT +#define TEXTSIZE_BIG TEXTSIZE_TITLE + +//#define COLOR_TITLE 1 0.8 0.4 1 +#define COLOR_TITLE 1 1 1 1 +#define COLOR_HEADER 0.69 0.69 0.69 1 +#define COLOR_FOCUSED 0.95294 0.72156 0.21176 1 //1 0.788 0.129 1 +//#define COLOR_FOCUS_YELLOW 0.95294 0.72156 0.21176 1 +#define COLOR_UNFOCUSED 0.4823 0.4823 0.4823 1 +//#define COLOR_DISABLED 0.35 0.35 0.35 1 +#define COLOR_SAFEAREA 0 0 1 1 + +#define COLOR_INFO_YELLOW COLOR_FOCUSED//1 0.84706 0 1 +#define COLOR_TEXT 0.84313 0.84313 0.84313 1 +#define COLOR_DISABLED 0.34118 0.36863 0.37647 1 +#define COLOR_TITLEBAR 0.14510 0.16078 0.16862 0.3//1 +#define COLOR_RED_TEXT 0.69020 0.00784 0.00784 1 + +#define COLOR_FADEOUT 0.09412 0.09412 0.04912 0.65 + +#define COLOR_BODY_TEXT 0.62745 0.66667 0.67451 1 + +#define COLOR_USMC 0 0.0196 0.41 +#define COLOR_JPN 0.53 0.027 0.027 +#define COLOR_USSR 0.368 0.035 0.035 +#define COLOR_GER 0.937 0.9 0.607 + +#define DEFAULT_MP_CFG "default_mp.cfg" +#define SPLITSCREEN_MP_CFG "default_splitscreen.cfg" +#define SYSTEMLINK_MP_CFG "default_systemlink.cfg" +#define XBOXLIVE_MP_CFG "default_xboxlive.cfg" + +#define MAX_RANK int(tableLookup( "mp/rankTable.csv", 0, "maxrank", 1)) +#define MAX_PRESTIGE int(tableLookup( "mp/rankIconTable.csv", 0, "maxprestige", 1)) + +#define PRESTIGE_AVAIL (stat(2326) < MAX_PRESTIGE && stat(2301) == int(tableLookup("mp/rankTable.csv",0,MAX_RANK,7))) +#define PRESTIGE_NEXT (stat(2326) < MAX_PRESTIGE && stat(252) == MAX_RANK) +#define PRESTIGE_FINISH (stat(2326) == MAX_PRESTIGE) + +#define CAN_RANK_UP (stat(252) < MAX_RANK || stat(2326) < MAX_PRESTIGE) +#endif // ENUMS_H diff --git a/libs/encryption/config_win32.h b/libs/encryption/config_win32.h new file mode 100644 index 0000000..29e4784 --- /dev/null +++ b/libs/encryption/config_win32.h @@ -0,0 +1,28 @@ +/* configuration header file for compiling under Microsoft Windows */ + +/* update package version here */ + +#pragma once + +#define PACKAGE "jbig2dec" +#define VERSION "0.2" + +/* define this iff you are linking to/compiling in libpng */ +#define HAVE_LIBPNG + +#ifdef _MSC_VER /* Microsoft Visual C+*/ + +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; +typedef __int64 int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +/* no uint64_t */ + +# define vsnprintf _vsnprintf +# define snprintf _snprintf + +#endif /* _MSC_VER */ diff --git a/libs/encryption/ecrypt-config.h b/libs/encryption/ecrypt-config.h new file mode 100644 index 0000000..f388224 --- /dev/null +++ b/libs/encryption/ecrypt-config.h @@ -0,0 +1,272 @@ +/* ecrypt-config.h */ + +/* *** Normally, it should not be necessary to edit this file. *** */ + +#ifndef ECRYPT_CONFIG +#define ECRYPT_CONFIG + +/* ------------------------------------------------------------------------- */ + +/* Guess the endianness of the target architecture. */ + +/* + * The LITTLE endian machines: + */ +#if defined(__ultrix) /* Older MIPS */ +#define ECRYPT_LITTLE_ENDIAN +#elif defined(__alpha) /* Alpha */ +#define ECRYPT_LITTLE_ENDIAN +#elif defined(i386) /* x86 (gcc) */ +#define ECRYPT_LITTLE_ENDIAN +#elif defined(__i386) /* x86 (gcc) */ +#define ECRYPT_LITTLE_ENDIAN +#elif defined(_M_IX86) /* x86 (MSC, Borland) */ +#define ECRYPT_LITTLE_ENDIAN +#elif defined(_MSC_VER) /* x86 (surely MSC) */ +#define ECRYPT_LITTLE_ENDIAN +#elif defined(__INTEL_COMPILER) /* x86 (surely Intel compiler icl.exe) */ +#define ECRYPT_LITTLE_ENDIAN + +/* + * The BIG endian machines: + */ +#elif defined(sun) /* Newer Sparc's */ +#define ECRYPT_BIG_ENDIAN +#elif defined(__ppc__) /* PowerPC */ +#define ECRYPT_BIG_ENDIAN + +/* + * Finally machines with UNKNOWN endianness: + */ +#elif defined (_AIX) /* RS6000 */ +#define ECRYPT_UNKNOWN +#elif defined(__hpux) /* HP-PA */ +#define ECRYPT_UNKNOWN +#elif defined(__aux) /* 68K */ +#define ECRYPT_UNKNOWN +#elif defined(__dgux) /* 88K (but P6 in latest boxes) */ +#define ECRYPT_UNKNOWN +#elif defined(__sgi) /* Newer MIPS */ +#define ECRYPT_UNKNOWN +#else /* Any other processor */ +#define ECRYPT_UNKNOWN +#endif + +/* ------------------------------------------------------------------------- */ + +/* + * Find minimal-width types to store 8-bit, 16-bit, 32-bit, and 64-bit + * integers. + * + * Note: to enable 64-bit types on 32-bit compilers, it might be + * necessary to switch from ISO C90 mode to ISO C99 mode (e.g., gcc + * -std=c99). + */ + +#include + +/* --- check char --- */ + +#if (UCHAR_MAX / 0xFU > 0xFU) +#ifndef I8T +#define I8T char +#define U8C(v) (v##U) + +#if (UCHAR_MAX == 0xFFU) +#define ECRYPT_I8T_IS_BYTE +#endif + +#endif + +#if (UCHAR_MAX / 0xFFU > 0xFFU) +#ifndef I16T +#define I16T char +#define U16C(v) (v##U) +#endif + +#if (UCHAR_MAX / 0xFFFFU > 0xFFFFU) +#ifndef I32T +#define I32T char +#define U32C(v) (v##U) +#endif + +#if (UCHAR_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) +#ifndef I64T +#define I64T char +#define U64C(v) (v##U) +#define ECRYPT_NATIVE64 +#endif + +#endif +#endif +#endif +#endif + +/* --- check short --- */ + +#if (USHRT_MAX / 0xFU > 0xFU) +#ifndef I8T +#define I8T short +#define U8C(v) (v##U) + +#if (USHRT_MAX == 0xFFU) +#define ECRYPT_I8T_IS_BYTE +#endif + +#endif + +#if (USHRT_MAX / 0xFFU > 0xFFU) +#ifndef I16T +#define I16T short +#define U16C(v) (v##U) +#endif + +#if (USHRT_MAX / 0xFFFFU > 0xFFFFU) +#ifndef I32T +#define I32T short +#define U32C(v) (v##U) +#endif + +#if (USHRT_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) +#ifndef I64T +#define I64T short +#define U64C(v) (v##U) +#define ECRYPT_NATIVE64 +#endif + +#endif +#endif +#endif +#endif + +/* --- check int --- */ + +#if (UINT_MAX / 0xFU > 0xFU) +#ifndef I8T +#define I8T int +#define U8C(v) (v##U) + +#if (ULONG_MAX == 0xFFU) +#define ECRYPT_I8T_IS_BYTE +#endif + +#endif + +#if (UINT_MAX / 0xFFU > 0xFFU) +#ifndef I16T +#define I16T int +#define U16C(v) (v##U) +#endif + +#if (UINT_MAX / 0xFFFFU > 0xFFFFU) +#ifndef I32T +#define I32T int +#define U32C(v) (v##U) +#endif + +#if (UINT_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) +#ifndef I64T +#define I64T int +#define U64C(v) (v##U) +#define ECRYPT_NATIVE64 +#endif + +#endif +#endif +#endif +#endif + +/* --- check long --- */ + +#if (ULONG_MAX / 0xFUL > 0xFUL) +#ifndef I8T +#define I8T long +#define U8C(v) (v##UL) + +#if (ULONG_MAX == 0xFFUL) +#define ECRYPT_I8T_IS_BYTE +#endif + +#endif + +#if (ULONG_MAX / 0xFFUL > 0xFFUL) +#ifndef I16T +#define I16T long +#define U16C(v) (v##UL) +#endif + +#if (ULONG_MAX / 0xFFFFUL > 0xFFFFUL) +#ifndef I32T +#define I32T long +#define U32C(v) (v##UL) +#endif + +#if (ULONG_MAX / 0xFFFFFFFFUL > 0xFFFFFFFFUL) +#ifndef I64T +#define I64T long +#define U64C(v) (v##UL) +#define ECRYPT_NATIVE64 +#endif + +#endif +#endif +#endif +#endif + +/* --- check long long --- */ + +#ifdef ULLONG_MAX + +#if (ULLONG_MAX / 0xFULL > 0xFULL) +#ifndef I8T +#define I8T long long +#define U8C(v) (v##ULL) + +#if (ULLONG_MAX == 0xFFULL) +#define ECRYPT_I8T_IS_BYTE +#endif + +#endif + +#if (ULLONG_MAX / 0xFFULL > 0xFFULL) +#ifndef I16T +#define I16T long long +#define U16C(v) (v##ULL) +#endif + +#if (ULLONG_MAX / 0xFFFFULL > 0xFFFFULL) +#ifndef I32T +#define I32T long long +#define U32C(v) (v##ULL) +#endif + +#if (ULLONG_MAX / 0xFFFFFFFFULL > 0xFFFFFFFFULL) +#ifndef I64T +#define I64T long long +#define U64C(v) (v##ULL) +#endif + +#endif +#endif +#endif +#endif + +#endif + +/* --- check __int64 --- */ + +#ifdef _UI64_MAX + +#if (_UI64_MAX / 0xFFFFFFFFuLL > 0xFFFFFFFFuLL) +#ifndef I64T +#define I64T __int64 +#define U64C(v) (v##ui64) +#endif + +#endif + +#endif + +/* ------------------------------------------------------------------------- */ + +#endif diff --git a/libs/encryption/ecrypt-machine.h b/libs/encryption/ecrypt-machine.h new file mode 100644 index 0000000..3e550d0 --- /dev/null +++ b/libs/encryption/ecrypt-machine.h @@ -0,0 +1,46 @@ +/* ecrypt-machine.h */ + +/* + * This file is included by 'ecrypt-portable.h'. It allows to override + * the default macros for specific platforms. Please carefully check + * the machine code generated by your compiler (with optimisations + * turned on) before deciding to edit this file. + */ + +/* ------------------------------------------------------------------------- */ + +#if (defined(ECRYPT_DEFAULT_ROT) && !defined(ECRYPT_MACHINE_ROT)) + +#define ECRYPT_MACHINE_ROT + +#if (defined(WIN32) && defined(_MSC_VER)) + +#undef ROTL32 +#undef ROTR32 +#undef ROTL64 +#undef ROTR64 + +#include + +#define ROTL32(v, n) _lrotl(v, n) +#define ROTR32(v, n) _lrotr(v, n) +#define ROTL64(v, n) _rotl64(v, n) +#define ROTR64(v, n) _rotr64(v, n) + +#endif + +#endif + +/* ------------------------------------------------------------------------- */ + +#if (defined(ECRYPT_DEFAULT_SWAP) && !defined(ECRYPT_MACHINE_SWAP)) + +#define ECRYPT_MACHINE_SWAP + +/* + * If you want to overwrite the default swap macros, put it here. And so on. + */ + +#endif + +/* ------------------------------------------------------------------------- */ diff --git a/libs/encryption/ecrypt-portable.h b/libs/encryption/ecrypt-portable.h new file mode 100644 index 0000000..972e7e9 --- /dev/null +++ b/libs/encryption/ecrypt-portable.h @@ -0,0 +1,303 @@ +/* ecrypt-portable.h */ + +/* + * WARNING: the conversions defined below are implemented as macros, + * and should be used carefully. They should NOT be used with + * parameters which perform some action. E.g., the following two lines + * are not equivalent: + * + * 1) ++x; y = ROTL32(x, n); + * 2) y = ROTL32(++x, n); + */ + +/* + * *** Please do not edit this file. *** + * + * The default macros can be overridden for specific architectures by + * editing 'ecrypt-machine.h'. + */ + +#ifndef ECRYPT_PORTABLE +#define ECRYPT_PORTABLE + +#include "ecrypt-config.h" + +/* ------------------------------------------------------------------------- */ + +/* + * The following types are defined (if available): + * + * u8: unsigned integer type, at least 8 bits + * u16: unsigned integer type, at least 16 bits + * u32: unsigned integer type, at least 32 bits + * u64: unsigned integer type, at least 64 bits + * + * s8, s16, s32, s64 -> signed counterparts of u8, u16, u32, u64 + * + * The selection of minimum-width integer types is taken care of by + * 'ecrypt-config.h'. Note: to enable 64-bit types on 32-bit + * compilers, it might be necessary to switch from ISO C90 mode to ISO + * C99 mode (e.g., gcc -std=c99). + */ + +#ifdef I8T +typedef signed I8T s8; +typedef unsigned I8T u8; +#endif + +#ifdef I16T +typedef signed I16T s16; +typedef unsigned I16T u16; +#endif + +#ifdef I32T +typedef signed I32T s32; +typedef unsigned I32T u32; +#endif + +#ifdef I64T +typedef signed I64T s64; +typedef unsigned I64T u64; +#endif + +/* + * The following macros are used to obtain exact-width results. + */ + +#define U8V(v) ((u8)(v) & U8C(0xFF)) +#define U16V(v) ((u16)(v) & U16C(0xFFFF)) +#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) +#define U64V(v) ((u64)(v) & U64C(0xFFFFFFFFFFFFFFFF)) + +/* ------------------------------------------------------------------------- */ + +/* + * The following macros return words with their bits rotated over n + * positions to the left/right. + */ + +#define ECRYPT_DEFAULT_ROT + +#define ROTL8(v, n) \ +(U8V((v) << (n)) | ((v) >> (8 - (n)))) + +#define ROTL16(v, n) \ + (U16V((v) << (n)) | ((v) >> (16 - (n)))) + +#define ROTL32(v, n) \ + (U32V((v) << (n)) | ((v) >> (32 - (n)))) + +#define ROTL64(v, n) \ + (U64V((v) << (n)) | ((v) >> (64 - (n)))) + +#define ROTR8(v, n) ROTL8(v, 8 - (n)) +#define ROTR16(v, n) ROTL16(v, 16 - (n)) +#define ROTR32(v, n) ROTL32(v, 32 - (n)) +#define ROTR64(v, n) ROTL64(v, 64 - (n)) + +#include "ecrypt-machine.h" + +/* ------------------------------------------------------------------------- */ + +/* + * The following macros return a word with bytes in reverse order. + */ + +#define ECRYPT_DEFAULT_SWAP + +#define SWAP16(v) \ + ROTL16(v, 8) + +#define SWAP32(v) \ + ((ROTL32(v, 8) & U32C(0x00FF00FF)) | \ + (ROTL32(v, 24) & U32C(0xFF00FF00))) + +#ifdef ECRYPT_NATIVE64 +#define SWAP64(v) \ + ((ROTL64(v, 8) & U64C(0x000000FF000000FF)) | \ + (ROTL64(v, 24) & U64C(0x0000FF000000FF00)) | \ + (ROTL64(v, 40) & U64C(0x00FF000000FF0000)) | \ + (ROTL64(v, 56) & U64C(0xFF000000FF000000))) +#else +#define SWAP64(v) \ + (((u64)SWAP32(U32V(v)) << 32) | (u64)SWAP32(U32V(v >> 32))) +#endif + +#include "ecrypt-machine.h" + +#define ECRYPT_DEFAULT_WTOW + +#ifdef ECRYPT_LITTLE_ENDIAN +#define U16TO16_LITTLE(v) (v) +#define U32TO32_LITTLE(v) (v) +#define U64TO64_LITTLE(v) (v) + +#define U16TO16_BIG(v) SWAP16(v) +#define U32TO32_BIG(v) SWAP32(v) +#define U64TO64_BIG(v) SWAP64(v) +#endif + +#ifdef ECRYPT_BIG_ENDIAN +#define U16TO16_LITTLE(v) SWAP16(v) +#define U32TO32_LITTLE(v) SWAP32(v) +#define U64TO64_LITTLE(v) SWAP64(v) + +#define U16TO16_BIG(v) (v) +#define U32TO32_BIG(v) (v) +#define U64TO64_BIG(v) (v) +#endif + +#include "ecrypt-machine.h" + +/* + * The following macros load words from an array of bytes with + * different types of endianness, and vice versa. + */ + +#define ECRYPT_DEFAULT_BTOW + +#if (!defined(ECRYPT_UNKNOWN) && defined(ECRYPT_I8T_IS_BYTE)) + +#define U8TO16_LITTLE(p) U16TO16_LITTLE(((u16*)(p))[0]) +#define U8TO32_LITTLE(p) U32TO32_LITTLE(((u32*)(p))[0]) +#define U8TO64_LITTLE(p) U64TO64_LITTLE(((u64*)(p))[0]) + +#define U8TO16_BIG(p) U16TO16_BIG(((u16*)(p))[0]) +#define U8TO32_BIG(p) U32TO32_BIG(((u32*)(p))[0]) +#define U8TO64_BIG(p) U64TO64_BIG(((u64*)(p))[0]) + +#define U16TO8_LITTLE(p, v) (((u16*)(p))[0] = U16TO16_LITTLE(v)) +#define U32TO8_LITTLE(p, v) (((u32*)(p))[0] = U32TO32_LITTLE(v)) +#define U64TO8_LITTLE(p, v) (((u64*)(p))[0] = U64TO64_LITTLE(v)) + +#define U16TO8_BIG(p, v) (((u16*)(p))[0] = U16TO16_BIG(v)) +#define U32TO8_BIG(p, v) (((u32*)(p))[0] = U32TO32_BIG(v)) +#define U64TO8_BIG(p, v) (((u64*)(p))[0] = U64TO64_BIG(v)) + +#else + +#define U8TO16_LITTLE(p) \ +(((u16)((p)[0]) ) | \ + ((u16)((p)[1]) << 8)) + +#define U8TO32_LITTLE(p) \ + (((u32)((p)[0]) ) | \ + ((u32)((p)[1]) << 8) | \ + ((u32)((p)[2]) << 16) | \ + ((u32)((p)[3]) << 24)) + +#ifdef ECRYPT_NATIVE64 +#define U8TO64_LITTLE(p) \ + (((u64)((p)[0]) ) | \ + ((u64)((p)[1]) << 8) | \ + ((u64)((p)[2]) << 16) | \ + ((u64)((p)[3]) << 24) | \ + ((u64)((p)[4]) << 32) | \ + ((u64)((p)[5]) << 40) | \ + ((u64)((p)[6]) << 48) | \ + ((u64)((p)[7]) << 56)) +#else +#define U8TO64_LITTLE(p) \ + ((u64)U8TO32_LITTLE(p) | ((u64)U8TO32_LITTLE((p) + 4) << 32)) +#endif + +#define U8TO16_BIG(p) \ + (((u16)((p)[0]) << 8) | \ + ((u16)((p)[1]) )) + +#define U8TO32_BIG(p) \ + (((u32)((p)[0]) << 24) | \ + ((u32)((p)[1]) << 16) | \ + ((u32)((p)[2]) << 8) | \ + ((u32)((p)[3]) )) + +#ifdef ECRYPT_NATIVE64 +#define U8TO64_BIG(p) \ + (((u64)((p)[0]) << 56) | \ + ((u64)((p)[1]) << 48) | \ + ((u64)((p)[2]) << 40) | \ + ((u64)((p)[3]) << 32) | \ + ((u64)((p)[4]) << 24) | \ + ((u64)((p)[5]) << 16) | \ + ((u64)((p)[6]) << 8) | \ + ((u64)((p)[7]) )) +#else +#define U8TO64_BIG(p) \ + (((u64)U8TO32_BIG(p) << 32) | (u64)U8TO32_BIG((p) + 4)) +#endif + +#define U16TO8_LITTLE(p, v) \ + do { \ + (p)[0] = U8V((v) ); \ + (p)[1] = U8V((v) >> 8); \ +} while (0) + +#define U32TO8_LITTLE(p, v) \ + do { \ + (p)[0] = U8V((v) ); \ + (p)[1] = U8V((v) >> 8); \ + (p)[2] = U8V((v) >> 16); \ + (p)[3] = U8V((v) >> 24); \ + } while (0) + +#ifdef ECRYPT_NATIVE64 +#define U64TO8_LITTLE(p, v) \ + do { \ + (p)[0] = U8V((v) ); \ + (p)[1] = U8V((v) >> 8); \ + (p)[2] = U8V((v) >> 16); \ + (p)[3] = U8V((v) >> 24); \ + (p)[4] = U8V((v) >> 32); \ + (p)[5] = U8V((v) >> 40); \ + (p)[6] = U8V((v) >> 48); \ + (p)[7] = U8V((v) >> 56); \ + } while (0) +#else +#define U64TO8_LITTLE(p, v) \ + do { \ + U32TO8_LITTLE((p), U32V((v) )); \ + U32TO8_LITTLE((p) + 4, U32V((v) >> 32)); \ + } while (0) +#endif + +#define U16TO8_BIG(p, v) \ + do { \ + (p)[0] = U8V((v) ); \ + (p)[1] = U8V((v) >> 8); \ + } while (0) + +#define U32TO8_BIG(p, v) \ + do { \ + (p)[0] = U8V((v) >> 24); \ + (p)[1] = U8V((v) >> 16); \ + (p)[2] = U8V((v) >> 8); \ + (p)[3] = U8V((v) ); \ + } while (0) + +#ifdef ECRYPT_NATIVE64 +#define U64TO8_BIG(p, v) \ + do { \ + (p)[0] = U8V((v) >> 56); \ + (p)[1] = U8V((v) >> 48); \ + (p)[2] = U8V((v) >> 40); \ + (p)[3] = U8V((v) >> 32); \ + (p)[4] = U8V((v) >> 24); \ + (p)[5] = U8V((v) >> 16); \ + (p)[6] = U8V((v) >> 8); \ + (p)[7] = U8V((v) ); \ +} while (0) +#else +#define U64TO8_BIG(p, v) \ + do { \ + U32TO8_BIG((p), U32V((v) >> 32)); \ + U32TO8_BIG((p) + 4, U32V((v) )); \ +} while (0) +#endif + +#endif + +#include "ecrypt-machine.h" + +/* ------------------------------------------------------------------------- */ + +#endif diff --git a/libs/encryption/ecrypt-sync.h b/libs/encryption/ecrypt-sync.h new file mode 100644 index 0000000..9027877 --- /dev/null +++ b/libs/encryption/ecrypt-sync.h @@ -0,0 +1,279 @@ +/* ecrypt-sync.h */ + +/* + * Header file for synchronous stream ciphers without authentication + * mechanism. + * + * *** Please only edit parts marked with "[edit]". *** + */ + +#ifndef ECRYPT_SYNC +#define ECRYPT_SYNC + +#include "ecrypt-portable.h" + +/* ------------------------------------------------------------------------- */ + +/* Cipher parameters */ + +/* + * The name of your cipher. + */ +#define ECRYPT_NAME "Salsa20" /* [edit] */ +#define ECRYPT_PROFILE "S!_H." + +/* + * Specify which key and IV sizes are supported by your cipher. A user + * should be able to enumerate the supported sizes by running the + * following code: + * + * for (i = 0; ECRYPT_KEYSIZE(i) <= ECRYPT_MAXKEYSIZE; ++i) + * { + * keysize = ECRYPT_KEYSIZE(i); + * + * ... + * } + * + * All sizes are in bits. + */ + +#define ECRYPT_MAXKEYSIZE 256 /* [edit] */ +#define ECRYPT_KEYSIZE(i) (128 + (i)*128) /* [edit] */ + +#define ECRYPT_MAXIVSIZE 64 /* [edit] */ +#define ECRYPT_IVSIZE(i) (64 + (i)*64) /* [edit] */ + +/* ------------------------------------------------------------------------- */ + +/* Data structures */ + +/* + * ECRYPT_ctx is the structure containing the representation of the + * internal state of your cipher. + */ + +typedef struct +{ + u32 input[16]; /* could be compressed */ + /* + * [edit] + * + * Put here all state variable needed during the encryption process. + */ +} ECRYPT_ctx; + +/* ------------------------------------------------------------------------- */ + +/* Mandatory functions */ + +/* + * Key and message independent initialization. This function will be + * called once when the program starts (e.g., to build expanded S-box + * tables). + */ +void ECRYPT_init(); + +/* + * Key setup. It is the user's responsibility to select the values of + * keysize and ivsize from the set of supported values specified + * above. + */ +void ECRYPT_keysetup( + ECRYPT_ctx* ctx, + const u8* key, + u32 keysize, /* Key size in bits. */ + u32 ivsize); /* IV size in bits. */ + +/* + * IV setup. After having called ECRYPT_keysetup(), the user is + * allowed to call ECRYPT_ivsetup() different times in order to + * encrypt/decrypt different messages with the same key but different + * IV's. + */ +void ECRYPT_ivsetup( + ECRYPT_ctx* ctx, + const u8* iv); + +/* + * Encryption/decryption of arbitrary length messages. + * + * For efficiency reasons, the API provides two types of + * encrypt/decrypt functions. The ECRYPT_encrypt_bytes() function + * (declared here) encrypts byte strings of arbitrary length, while + * the ECRYPT_encrypt_blocks() function (defined later) only accepts + * lengths which are multiples of ECRYPT_BLOCKLENGTH. + * + * The user is allowed to make multiple calls to + * ECRYPT_encrypt_blocks() to incrementally encrypt a long message, + * but he is NOT allowed to make additional encryption calls once he + * has called ECRYPT_encrypt_bytes() (unless he starts a new message + * of course). For example, this sequence of calls is acceptable: + * + * ECRYPT_keysetup(); + * + * ECRYPT_ivsetup(); + * ECRYPT_encrypt_blocks(); + * ECRYPT_encrypt_blocks(); + * ECRYPT_encrypt_bytes(); + * + * ECRYPT_ivsetup(); + * ECRYPT_encrypt_blocks(); + * ECRYPT_encrypt_blocks(); + * + * ECRYPT_ivsetup(); + * ECRYPT_encrypt_bytes(); + * + * The following sequence is not: + * + * ECRYPT_keysetup(); + * ECRYPT_ivsetup(); + * ECRYPT_encrypt_blocks(); + * ECRYPT_encrypt_bytes(); + * ECRYPT_encrypt_blocks(); + */ + +void ECRYPT_encrypt_bytes( + ECRYPT_ctx* ctx, + const u8* plaintext, + u8* ciphertext, + u32 msglen); /* Message length in bytes. */ + +void ECRYPT_decrypt_bytes( + ECRYPT_ctx* ctx, + const u8* ciphertext, + u8* plaintext, + u32 msglen); /* Message length in bytes. */ + +/* ------------------------------------------------------------------------- */ + +/* Optional features */ + +/* + * For testing purposes it can sometimes be useful to have a function + * which immediately generates keystream without having to provide it + * with a zero plaintext. If your cipher cannot provide this function + * (e.g., because it is not strictly a synchronous cipher), please + * reset the ECRYPT_GENERATES_KEYSTREAM flag. + */ + +#define ECRYPT_GENERATES_KEYSTREAM +#ifdef ECRYPT_GENERATES_KEYSTREAM + +void ECRYPT_keystream_bytes( + ECRYPT_ctx* ctx, + u8* keystream, + u32 length); /* Length of keystream in bytes. */ + +#endif + +/* ------------------------------------------------------------------------- */ + +/* Optional optimizations */ + +/* + * By default, the functions in this section are implemented using + * calls to functions declared above. However, you might want to + * implement them differently for performance reasons. + */ + +/* + * All-in-one encryption/decryption of (short) packets. + * + * The default definitions of these functions can be found in + * "ecrypt-sync.c". If you want to implement them differently, please + * undef the ECRYPT_USES_DEFAULT_ALL_IN_ONE flag. + */ +#define ECRYPT_USES_DEFAULT_ALL_IN_ONE /* [edit] */ + +void ECRYPT_encrypt_packet( + ECRYPT_ctx* ctx, + const u8* iv, + const u8* plaintext, + u8* ciphertext, + u32 msglen); + +void ECRYPT_decrypt_packet( + ECRYPT_ctx* ctx, + const u8* iv, + const u8* ciphertext, + u8* plaintext, + u32 msglen); + +/* + * Encryption/decryption of blocks. + * + * By default, these functions are defined as macros. If you want to + * provide a different implementation, please undef the + * ECRYPT_USES_DEFAULT_BLOCK_MACROS flag and implement the functions + * declared below. + */ + +#define ECRYPT_BLOCKLENGTH 64 /* [edit] */ + +#define ECRYPT_USES_DEFAULT_BLOCK_MACROS /* [edit] */ +#ifdef ECRYPT_USES_DEFAULT_BLOCK_MACROS + +#define ECRYPT_encrypt_blocks(ctx, plaintext, ciphertext, blocks) \ +ECRYPT_encrypt_bytes(ctx, plaintext, ciphertext, \ + (blocks) * ECRYPT_BLOCKLENGTH) + +#define ECRYPT_decrypt_blocks(ctx, ciphertext, plaintext, blocks) \ + ECRYPT_decrypt_bytes(ctx, ciphertext, plaintext, \ + (blocks) * ECRYPT_BLOCKLENGTH) + +#ifdef ECRYPT_GENERATES_KEYSTREAM + +#define ECRYPT_keystream_blocks(ctx, keystream, blocks) \ + ECRYPT_keystream_bytes(ctx, keystream, \ + (blocks) * ECRYPT_BLOCKLENGTH) + +#endif + +#else + +void ECRYPT_encrypt_blocks( + ECRYPT_ctx* ctx, + const u8* plaintext, + u8* ciphertext, + u32 blocks); /* Message length in blocks. */ + +void ECRYPT_decrypt_blocks( + ECRYPT_ctx* ctx, + const u8* ciphertext, + u8* plaintext, + u32 blocks); /* Message length in blocks. */ + +#ifdef ECRYPT_GENERATES_KEYSTREAM + +void ECRYPT_keystream_blocks( + ECRYPT_ctx* ctx, + const u8* keystream, + u32 blocks); /* Keystream length in blocks. */ + +#endif + +#endif + +/* + * If your cipher can be implemented in different ways, you can use + * the ECRYPT_VARIANT parameter to allow the user to choose between + * them at compile time (e.g., gcc -DECRYPT_VARIANT=3 ...). Please + * only use this possibility if you really think it could make a + * significant difference and keep the number of variants + * (ECRYPT_MAXVARIANT) as small as possible (definitely not more than + * 10). Note also that all variants should have exactly the same + * external interface (i.e., the same ECRYPT_BLOCKLENGTH, etc.). + */ +#define ECRYPT_MAXVARIANT 1 /* [edit] */ + +#ifndef ECRYPT_VARIANT +#define ECRYPT_VARIANT 1 +#endif + +#if (ECRYPT_VARIANT > ECRYPT_MAXVARIANT) +#error this variant does not exist +#endif + +/* ------------------------------------------------------------------------- */ + +#endif diff --git a/libs/encryption/encryption.cpp b/libs/encryption/encryption.cpp new file mode 100644 index 0000000..613ea2e --- /dev/null +++ b/libs/encryption/encryption.cpp @@ -0,0 +1,440 @@ +#include "encryption.h" +#include "QtZlib/zlib.h" +#include "ecrypt-sync.h" + +void Encryption::Convert32BitTo8Bit(quint32 value, quint8 *array) { + array[0] = static_cast(value >> 0); + array[1] = static_cast(value >> 8); + array[2] = static_cast(value >> 16); + array[3] = static_cast(value >> 24); +} + +quint32 Encryption::ConvertArrayTo32Bit(const QByteArray &array) { + return ((static_cast(static_cast(array[0])) << 0) | + (static_cast(static_cast(array[1])) << 8) | + (static_cast(static_cast(array[2])) << 16) | + (static_cast(static_cast(array[3])) << 24)); +} + +quint32 Encryption::Rotate(quint32 value, quint32 numBits) { + return (value << numBits) | (value >> (32 - numBits)); +} + +QByteArray Encryption::InitIVTable(const QByteArray &feed) { + const int tableSize = 0xFB0; + QByteArray table; + table.resize(tableSize); + int ptr = 0; + for (int i = 0; i < 200; ++i) { + for (int x = 0; x < 5; ++x) { + if (static_cast(feed.at(ptr)) == 0x00) + ptr = 0; + int base = i * 20 + x * 4; + table[base] = feed.at(ptr); + table[base + 1] = feed.at(ptr); + table[base + 2] = feed.at(ptr); + table[base + 3] = feed.at(ptr); + ++ptr; + } + } + // Copy block numbers [1,0,0,0] into the last 16 bytes + QByteArray oneBlock; + oneBlock.append(char(1)); oneBlock.append(char(0)); oneBlock.append(char(0)); oneBlock.append(char(0)); + table.replace(0xFA0, 4, oneBlock); + table.replace(0xFA4, 4, oneBlock); + table.replace(0xFA8, 4, oneBlock); + table.replace(0xFAC, 4, oneBlock); + return table; +} + +int Encryption::unk(quint64 arg1, quint8 arg2) { + if (arg2 >= 0x40) + return 0; + return static_cast(arg1 >> arg2); +} + +QByteArray Encryption::GetIV(const QByteArray &table, int index) { + int num1 = 0xFA0 + index; + int num2 = unk(0x51EB851FLL * num1, 0x20); + int adjust = ((num2 >> 6) + (num2 >> 31)); + int startIndex = 20 * (num1 - 200 * adjust); + // Return 8 bytes from that location. + return table.mid(startIndex, 8); +} + +void Encryption::UpdateIVTable(QByteArray &table, int index, const QByteArray §ionHash) { + int blockNumIndex = index % 4; + int baseOffset = 0xFA0 + blockNumIndex * 4; + quint32 blockNumVal = (static_cast(table.at(baseOffset)) ) | + (static_cast(table.at(baseOffset + 1)) << 8 ) | + (static_cast(table.at(baseOffset + 2)) << 16) | + (static_cast(table.at(baseOffset + 3)) << 24); + int blockNum = blockNumVal * 4 + index; + int num2 = unk(0x51EB851FLL * blockNum, 0x20); + int adjust = ((num2 >> 6) + (num2 >> 31)); + int startIndex = 20 * (blockNum - 200 * adjust) + 1; + int hashIndex = 0; + for (int x = 0; x < 4; ++x) { + table[startIndex - 1] = table.at(startIndex - 1) ^ sectionHash.at(hashIndex); + table[startIndex] = table.at(startIndex) ^ sectionHash.at(hashIndex + 1); + table[startIndex + 1] = table.at(startIndex + 1) ^ sectionHash.at(hashIndex + 2); + table[startIndex + 2] = table.at(startIndex + 2) ^ sectionHash.at(hashIndex + 3); + table[startIndex + 3] = table.at(startIndex + 3) ^ sectionHash.at(hashIndex + 4); + startIndex += 5; + hashIndex += 5; + } +} + +quint32 Encryption::ToUInt32(const QByteArray &data, int offset) { + // Converts 4 bytes (starting at offset) from data into a 32-bit unsigned integer (little-endian) + return ((static_cast(static_cast(data[offset])) ) | + (static_cast(static_cast(data[offset+1])) << 8 ) | + (static_cast(static_cast(data[offset+2])) << 16) | + (static_cast(static_cast(data[offset+3])) << 24)); +} + +QByteArray Encryption::salsa20DecryptSection(const QByteArray §ionData, const QByteArray &key, const QByteArray &iv, int blockSize) +{ + // Choose the appropriate constant based on key length. + QByteArray constants; + if (key.size() == 32) + constants = "expand 32-byte k"; + else if (key.size() == 16) + constants = "expand 16-byte k"; + else { + qWarning() << "Invalid key size:" << key.size() << "; expected 16 or 32 bytes."; + return QByteArray(); + } + + QVector state(VECTOR_SIZE); + + // Set state[0] using the first 4 bytes of the constant. + state[0] = ConvertArrayTo32Bit(constants.mid(0, 4)); + + // state[1] through state[4] come from the first 16 bytes of the key. + state[1] = ToUInt32(key, 0); + state[2] = ToUInt32(key, 4); + state[3] = ToUInt32(key, 8); + state[4] = ToUInt32(key, 12); + + // state[5] comes from the next 4 bytes of the constant. + state[5] = ConvertArrayTo32Bit(constants.mid(4, 4)); + + // state[6] and state[7] come from the IV (which must be 8 bytes). + state[6] = ConvertArrayTo32Bit(iv.mid(0, 4)); + state[7] = ConvertArrayTo32Bit(iv.mid(4, 4)); + + // state[8] and state[9] are the 64-bit block counter (start at 0). + state[8] = 0; + state[9] = 0; + + // state[10] comes from the next 4 bytes of the constant. + state[10] = ConvertArrayTo32Bit(constants.mid(8, 4)); + + // For state[11] through state[14]: + // If the key is 32 bytes, use bytes 16..31; if 16 bytes, reuse the first 16 bytes. + if (key.size() == 32) { + state[11] = ToUInt32(key, 16); + state[12] = ToUInt32(key, 20); + state[13] = ToUInt32(key, 24); + state[14] = ToUInt32(key, 28); + } else { // key.size() == 16 + state[11] = ToUInt32(key, 0); + state[12] = ToUInt32(key, 4); + state[13] = ToUInt32(key, 8); + state[14] = ToUInt32(key, 12); + } + + // state[15] comes from the last 4 bytes of the constant. + state[15] = ConvertArrayTo32Bit(constants.mid(12, 4)); + + // Prepare the output buffer. + QByteArray output(sectionData.size(), Qt::Uninitialized); + int numBlocks = sectionData.size() / blockSize; + int remainder = sectionData.size() % blockSize; + + // Process each full block. + for (int blockIndex = 0; blockIndex < numBlocks; ++blockIndex) { + QVector x = state; // make a copy of the current state for this block + + // Run 20 rounds (10 iterations) of Salsa20. + for (int round = 20; round > 0; round -= 2) { + x[4] ^= Rotate(x[0] + x[12], 7); + x[8] ^= Rotate(x[4] + x[0], 9); + x[12] ^= Rotate(x[8] + x[4], 13); + x[0] ^= Rotate(x[12] + x[8], 18); + + x[9] ^= Rotate(x[5] + x[1], 7); + x[13] ^= Rotate(x[9] + x[5], 9); + x[1] ^= Rotate(x[13] + x[9], 13); + x[5] ^= Rotate(x[1] + x[13], 18); + + x[14] ^= Rotate(x[10] + x[6], 7); + x[2] ^= Rotate(x[14] + x[10], 9); + x[6] ^= Rotate(x[2] + x[14], 13); + x[10] ^= Rotate(x[6] + x[2], 18); + + x[3] ^= Rotate(x[15] + x[11], 7); + x[7] ^= Rotate(x[3] + x[15], 9); + x[11] ^= Rotate(x[7] + x[3], 13); + x[15] ^= Rotate(x[11] + x[7], 18); + + x[1] ^= Rotate(x[0] + x[3], 7); + x[2] ^= Rotate(x[1] + x[0], 9); + x[3] ^= Rotate(x[2] + x[1], 13); + x[0] ^= Rotate(x[3] + x[2], 18); + + x[6] ^= Rotate(x[5] + x[4], 7); + x[7] ^= Rotate(x[6] + x[5], 9); + x[4] ^= Rotate(x[7] + x[6], 13); + x[5] ^= Rotate(x[4] + x[7], 18); + + x[11] ^= Rotate(x[10] + x[9], 7); + x[8] ^= Rotate(x[11] + x[10], 9); + x[9] ^= Rotate(x[8] + x[11], 13); + x[10] ^= Rotate(x[9] + x[8], 18); + + x[12] ^= Rotate(x[15] + x[14], 7); + x[13] ^= Rotate(x[12] + x[15], 9); + x[14] ^= Rotate(x[13] + x[12], 13); + x[15] ^= Rotate(x[14] + x[13], 18); + } + + // Produce the 64-byte keystream block by adding the original state. + QVector keyStreamBlock(blockSize); + for (int i = 0; i < VECTOR_SIZE; ++i) { + x[i] += state[i]; + Convert32BitTo8Bit(x[i], keyStreamBlock.data() + 4 * i); + } + + // XOR the keystream block with the corresponding block of sectionData. + const uchar* inBlock = reinterpret_cast(sectionData.constData()) + blockIndex * blockSize; + uchar* outBlock = reinterpret_cast(output.data()) + blockIndex * blockSize; + for (int j = 0; j < blockSize; ++j) { + outBlock[j] = inBlock[j] ^ keyStreamBlock[j]; + } + // Increment the 64-bit block counter. + state[8]++; + if (state[8] == 0) + state[9]++; + } + + // Process any remaining bytes. + if (remainder > 0) { + QVector x = state; + for (int round = 20; round > 0; round -= 2) { + x[4] ^= Rotate(x[0] + x[12], 7); + x[8] ^= Rotate(x[4] + x[0], 9); + x[12] ^= Rotate(x[8] + x[4], 13); + x[0] ^= Rotate(x[12] + x[8], 18); + + x[9] ^= Rotate(x[5] + x[1], 7); + x[13] ^= Rotate(x[9] + x[5], 9); + x[1] ^= Rotate(x[13] + x[9], 13); + x[5] ^= Rotate(x[1] + x[13], 18); + + x[14] ^= Rotate(x[10] + x[6], 7); + x[2] ^= Rotate(x[14] + x[10], 9); + x[6] ^= Rotate(x[2] + x[14], 13); + x[10] ^= Rotate(x[6] + x[2], 18); + + x[3] ^= Rotate(x[15] + x[11], 7); + x[7] ^= Rotate(x[3] + x[15], 9); + x[11] ^= Rotate(x[7] + x[3], 13); + x[15] ^= Rotate(x[11] + x[7], 18); + + x[1] ^= Rotate(x[0] + x[3], 7); + x[2] ^= Rotate(x[1] + x[0], 9); + x[3] ^= Rotate(x[2] + x[1], 13); + x[0] ^= Rotate(x[3] + x[2], 18); + + x[6] ^= Rotate(x[5] + x[4], 7); + x[7] ^= Rotate(x[6] + x[5], 9); + x[4] ^= Rotate(x[7] + x[6], 13); + x[5] ^= Rotate(x[4] + x[7], 18); + + x[11] ^= Rotate(x[10] + x[9], 7); + x[8] ^= Rotate(x[11] + x[10], 9); + x[9] ^= Rotate(x[8] + x[11], 13); + x[10] ^= Rotate(x[9] + x[8], 18); + + x[12] ^= Rotate(x[15] + x[14], 7); + x[13] ^= Rotate(x[12] + x[15], 9); + x[14] ^= Rotate(x[13] + x[12], 13); + x[15] ^= Rotate(x[14] + x[13], 18); + } + QVector keyStreamBlock(blockSize); + for (int i = 0; i < VECTOR_SIZE; ++i) { + x[i] += state[i]; + Convert32BitTo8Bit(x[i], keyStreamBlock.data() + 4 * i); + } + const uchar* inBlock = reinterpret_cast(sectionData.constData()) + numBlocks * blockSize; + uchar* outBlock = reinterpret_cast(output.data()) + numBlocks * blockSize; + for (int j = 0; j < remainder; ++j) + outBlock[j] = inBlock[j] ^ keyStreamBlock[j]; + } + + return output; +} + +void Encryption::fillIVTable(QByteArray fastFileData, QByteArray &ivTable, quint32 ivTableLength) +{ + QDataStream stream(fastFileData); + stream.skipRawData(24); + + quint32 nameKeyLength = 0; + for (int i = 0; i < 32 && !stream.atEnd(); i++) { + if (!stream.atEnd() && stream.device()->peek(1).toHex() != "00") { + nameKeyLength++; + stream.skipRawData(1); + } else { + break; + } + } + + if (nameKeyLength < 32) { + stream.skipRawData(32 - nameKeyLength); + } + + if (ivTableLength < 16) { + qWarning() << "IV table length too small!"; + return; + } + + for (quint32 i = 0; i < ivTableLength - 16; i++) { + if (stream.atEnd()) { + qWarning() << "Stream ended while filling IV table!"; + return; + } + quint8 ivVal; + stream >> ivVal; + ivTable[i] = ivVal; + } +} + +void Encryption::fillIV(int index, QByteArray &ivPtr, const QByteArray &ivTable, const QVector &ivCounter) +{ + if (index < 0 || index >= ivCounter.size()) { + qWarning() << "Invalid IV index: " << index; + return; + } + + int ivOffset = ((index + 4 * (ivCounter[index] - 1)) % 800) * 20; + + if (ivOffset + 8 > ivTable.size()) { + qWarning() << "IV offset out of bounds! Offset: " << ivOffset; + return; + } + + ivPtr = ivTable.mid(ivOffset, 8); +} + +void Encryption::generateNewIV(int index, const QByteArray &hash, QByteArray &ivTable, QVector &ivCounter) +{ + if (index < 0 || index >= ivCounter.size()) { + qWarning() << "Invalid index: " << index; + return; + } + + quint32 safeCounter = fmin(ivCounter[index], 800u - 1); + int ivOffset = (index + 4 * safeCounter) % 800 * 5; + + for (int i = 0; i < 20; i++) { + if (ivOffset + i >= ivTable.size()) { + qWarning() << "Index out of bounds for IV table!"; + return; + } + ivTable[ivOffset + i] ^= hash[i]; + } + + ivCounter[index]++; +} + +QByteArray Encryption::decryptFastFile(const QByteArray &fastFileData) +{ + const QByteArray bo2_salsa20_key = QByteArray::fromHex("641D8A2FE31D3AA63622BBC9CE8587229D42B0F8ED9B924130BF88B65EDC50BE"); + + QByteArray fileData = fastFileData; + QByteArray finalFastFile; + + QByteArray ivTable(16000, 0); + fillIVTable(fileData, ivTable, 16000 - 1); + + QVector ivCounter(4, 1); + QDataStream stream(fileData); + stream.setByteOrder(QDataStream::LittleEndian); + stream.skipRawData(0x138); + + QByteArray sha1Hash(20, 0); + QByteArray ivPtr(8, 0); + int chunkIndex = 0; + + while (!stream.atEnd()) { + quint32 dataLength; + stream >> dataLength; + + if (dataLength == 0 || dataLength > fileData.size() - stream.device()->pos()) { + qWarning() << "Invalid data length at offset: " << stream.device()->pos(); + break; + } + + fillIV(chunkIndex % 4, ivPtr, ivTable, ivCounter); + + ECRYPT_ctx x; + ECRYPT_keysetup(&x, reinterpret_cast(bo2_salsa20_key.constData()), 256, 0); + ECRYPT_ivsetup(&x, reinterpret_cast(ivPtr.constData())); + + QByteArray encryptedBlock = fileData.mid(stream.device()->pos(), dataLength); + QByteArray decryptedBlock; + decryptedBlock.resize(dataLength); + + ECRYPT_decrypt_bytes(&x, reinterpret_cast(encryptedBlock.constData()), + reinterpret_cast(decryptedBlock.data()), dataLength); + + QCryptographicHash sha1(QCryptographicHash::Sha1); + sha1.addData(decryptedBlock); + sha1Hash = sha1.result(); + + z_stream strm = {}; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = static_cast(decryptedBlock.size()); + strm.next_in = reinterpret_cast(decryptedBlock.data()); + + QByteArray decompressedData; + decompressedData.resize(fmax(dataLength * 2, 4096)); + strm.avail_out = decompressedData.size(); + strm.next_out = reinterpret_cast(decompressedData.data()); + + int zReturn = inflateInit2(&strm, -15); + if (zReturn != Z_OK) { + qWarning() << "inflateInit2 failed with error code" << zReturn; + break; + } + + zReturn = inflate(&strm, Z_FINISH); + inflateEnd(&strm); + + if (zReturn != Z_STREAM_END) { + qDebug() << "Error decompressing at offset: " << stream.device()->pos() << " : " << zReturn; + decompressedData.clear(); + } else { + decompressedData.resize(strm.total_out); + } + + finalFastFile.append(decompressedData); + + generateNewIV(chunkIndex % 4, sha1Hash, ivTable, ivCounter); + + if (stream.device()->pos() + static_cast(dataLength) > fileData.size()) { + qWarning() << "Skipping past file size!"; + break; + } + + stream.skipRawData(dataLength); + chunkIndex++; + } + + return finalFastFile; +} diff --git a/libs/encryption/encryption.h b/libs/encryption/encryption.h new file mode 100644 index 0000000..6b36041 --- /dev/null +++ b/libs/encryption/encryption.h @@ -0,0 +1,52 @@ +#ifndef ENCRYPTION_H +#define ENCRYPTION_H + +#include +#include +#include +#include + +class Encryption { +public: + static const int VECTOR_SIZE = 16; // 16 32-bit words + static const int NUM_OF_BLOCKS_PER_CHUNK = 8192; + + //-------------------------------------------------------------------- + // Helper functions (assuming little–endian order) + + static void Convert32BitTo8Bit(quint32 value, quint8* array); + + static quint32 ConvertArrayTo32Bit(const QByteArray &array); + + static quint32 Rotate(quint32 value, quint32 numBits); + + // Build the IV table from a 0x20–byte feed. The table is 0xFB0 bytes. + static QByteArray InitIVTable(const QByteArray &feed); + + // "unk" function as in the C# code. + static int unk(quint64 arg1, quint8 arg2); + + // Compute the IV for a given section index using the IV table. + static QByteArray GetIV(const QByteArray &table, int index); + + // Update the IV table given the section's SHA1 hash. + static void UpdateIVTable(QByteArray &table, int index, const QByteArray §ionHash); + + static quint32 ToUInt32(const QByteArray &data, int offset); + + //-------------------------------------------------------------------- + // Salsa20 decryption for one section. + // This function resets the counter for each section. + static QByteArray salsa20DecryptSection(const QByteArray §ionData, const QByteArray &key, const QByteArray &iv, int blockSize = 64); + + static void fillIVTable(QByteArray fastFileData, QByteArray& ivTable, quint32 ivTableLength); + + static void fillIV(int index, QByteArray& ivPtr, const QByteArray& ivTable, const QVector& ivCounter); + + + static void generateNewIV(int index, const QByteArray& hash, QByteArray& ivTable, QVector& ivCounter); + + static QByteArray decryptFastFile(const QByteArray& fastFileData); +}; + +#endif // ENCRYPTION_H diff --git a/libs/encryption/encryption.pro b/libs/encryption/encryption.pro new file mode 100644 index 0000000..28d2cfb --- /dev/null +++ b/libs/encryption/encryption.pro @@ -0,0 +1,20 @@ +QT += core +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + salsa20.cpp \ + sha1.cpp \ + encryption.cpp + +HEADERS += \ + ecrypt-config.h \ + ecrypt-machine.h \ + ecrypt-portable.h \ + ecrypt-sync.h \ + encryption.h \ + os_types.h \ + config_win32.h \ + sha1.h + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/encryption/os_types.h b/libs/encryption/os_types.h new file mode 100644 index 0000000..2006a21 --- /dev/null +++ b/libs/encryption/os_types.h @@ -0,0 +1,30 @@ +/* + jbig2dec + + Copyright (c) 2002 artofcode LLC. + + 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; either version 2 of the License, or + (at your option) any later version. + + $Id: os_types.h,v 1.1 2002/07/20 17:23:15 giles Exp $ +*/ + +/* + indirection layer for build and platform-specific definitions + + in general, this header should insure that the stdint types are + available, and that any optional compile flags are defined if + the build system doesn't pass them directly. +*/ + +#ifdef HAVE_CONFIG_H +#include "config_types.h" +#elif defined(_WIN32) +#include "config_win32.h" +#endif + +#if defined(HAVE_STDINT_H) || defined(__MACOS__) +#include +#endif diff --git a/libs/encryption/salsa20.cpp b/libs/encryption/salsa20.cpp new file mode 100644 index 0000000..272199f --- /dev/null +++ b/libs/encryption/salsa20.cpp @@ -0,0 +1,221 @@ +/* +salsa20-merged.c version 20051118 +D. J. Bernstein +Public domain. +*/ + +#include "ecrypt-sync.h" +#include "qtpreprocessorsupport.h" + +#define ROTATE(v,c) (ROTL32(v,c)) +#define XOR(v,w) ((v) ^ (w)) +#define PLUS(v,w) (U32V((v) + (w))) +#define PLUSONE(v) (PLUS((v),1)) + +void ECRYPT_init(void) +{ + return; +} + +static const char sigma[17] = "expand 32-byte k"; +static const char tau[17] = "expand 16-byte k"; + +void ECRYPT_keysetup(ECRYPT_ctx *x,const u8 *k,u32 kbits,u32 ivbits) +{ + Q_UNUSED(ivbits); + const char *constants; + + x->input[1] = U8TO32_LITTLE(k + 0); + x->input[2] = U8TO32_LITTLE(k + 4); + x->input[3] = U8TO32_LITTLE(k + 8); + x->input[4] = U8TO32_LITTLE(k + 12); + if (kbits == 256) { /* recommended */ + k += 16; + constants = sigma; + } else { /* kbits == 128 */ + constants = tau; + } + x->input[11] = U8TO32_LITTLE(k + 0); + x->input[12] = U8TO32_LITTLE(k + 4); + x->input[13] = U8TO32_LITTLE(k + 8); + x->input[14] = U8TO32_LITTLE(k + 12); + x->input[0] = U8TO32_LITTLE(constants + 0); + x->input[5] = U8TO32_LITTLE(constants + 4); + x->input[10] = U8TO32_LITTLE(constants + 8); + x->input[15] = U8TO32_LITTLE(constants + 12); +} + +void ECRYPT_ivsetup(ECRYPT_ctx *x,const u8 *iv) +{ + x->input[6] = U8TO32_LITTLE(iv + 0); + x->input[7] = U8TO32_LITTLE(iv + 4); + x->input[8] = 0; + x->input[9] = 0; +} + +void ECRYPT_encrypt_bytes(ECRYPT_ctx *x,const u8 *m,u8 *c,u32 bytes) +{ + u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; + u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; + u8 *ctarget; + u8 tmp[64]; + unsigned int i; + + if (!bytes) return; + + j0 = x->input[0]; + j1 = x->input[1]; + j2 = x->input[2]; + j3 = x->input[3]; + j4 = x->input[4]; + j5 = x->input[5]; + j6 = x->input[6]; + j7 = x->input[7]; + j8 = x->input[8]; + j9 = x->input[9]; + j10 = x->input[10]; + j11 = x->input[11]; + j12 = x->input[12]; + j13 = x->input[13]; + j14 = x->input[14]; + j15 = x->input[15]; + + for (;;) { + if (bytes < 64) { + for (i = 0;i < bytes;++i) tmp[i] = m[i]; + m = tmp; + ctarget = c; + c = tmp; + } + x0 = j0; + x1 = j1; + x2 = j2; + x3 = j3; + x4 = j4; + x5 = j5; + x6 = j6; + x7 = j7; + x8 = j8; + x9 = j9; + x10 = j10; + x11 = j11; + x12 = j12; + x13 = j13; + x14 = j14; + x15 = j15; + for (i = 20;i > 0;i -= 2) { + x4 = XOR( x4,ROTATE(PLUS( x0,x12), 7)); + x8 = XOR( x8,ROTATE(PLUS( x4, x0), 9)); + x12 = XOR(x12,ROTATE(PLUS( x8, x4),13)); + x0 = XOR( x0,ROTATE(PLUS(x12, x8),18)); + x9 = XOR( x9,ROTATE(PLUS( x5, x1), 7)); + x13 = XOR(x13,ROTATE(PLUS( x9, x5), 9)); + x1 = XOR( x1,ROTATE(PLUS(x13, x9),13)); + x5 = XOR( x5,ROTATE(PLUS( x1,x13),18)); + x14 = XOR(x14,ROTATE(PLUS(x10, x6), 7)); + x2 = XOR( x2,ROTATE(PLUS(x14,x10), 9)); + x6 = XOR( x6,ROTATE(PLUS( x2,x14),13)); + x10 = XOR(x10,ROTATE(PLUS( x6, x2),18)); + x3 = XOR( x3,ROTATE(PLUS(x15,x11), 7)); + x7 = XOR( x7,ROTATE(PLUS( x3,x15), 9)); + x11 = XOR(x11,ROTATE(PLUS( x7, x3),13)); + x15 = XOR(x15,ROTATE(PLUS(x11, x7),18)); + x1 = XOR( x1,ROTATE(PLUS( x0, x3), 7)); + x2 = XOR( x2,ROTATE(PLUS( x1, x0), 9)); + x3 = XOR( x3,ROTATE(PLUS( x2, x1),13)); + x0 = XOR( x0,ROTATE(PLUS( x3, x2),18)); + x6 = XOR( x6,ROTATE(PLUS( x5, x4), 7)); + x7 = XOR( x7,ROTATE(PLUS( x6, x5), 9)); + x4 = XOR( x4,ROTATE(PLUS( x7, x6),13)); + x5 = XOR( x5,ROTATE(PLUS( x4, x7),18)); + x11 = XOR(x11,ROTATE(PLUS(x10, x9), 7)); + x8 = XOR( x8,ROTATE(PLUS(x11,x10), 9)); + x9 = XOR( x9,ROTATE(PLUS( x8,x11),13)); + x10 = XOR(x10,ROTATE(PLUS( x9, x8),18)); + x12 = XOR(x12,ROTATE(PLUS(x15,x14), 7)); + x13 = XOR(x13,ROTATE(PLUS(x12,x15), 9)); + x14 = XOR(x14,ROTATE(PLUS(x13,x12),13)); + x15 = XOR(x15,ROTATE(PLUS(x14,x13),18)); + } + x0 = PLUS(x0,j0); + x1 = PLUS(x1,j1); + x2 = PLUS(x2,j2); + x3 = PLUS(x3,j3); + x4 = PLUS(x4,j4); + x5 = PLUS(x5,j5); + x6 = PLUS(x6,j6); + x7 = PLUS(x7,j7); + x8 = PLUS(x8,j8); + x9 = PLUS(x9,j9); + x10 = PLUS(x10,j10); + x11 = PLUS(x11,j11); + x12 = PLUS(x12,j12); + x13 = PLUS(x13,j13); + x14 = PLUS(x14,j14); + x15 = PLUS(x15,j15); + + x0 = XOR(x0,U8TO32_LITTLE(m + 0)); + x1 = XOR(x1,U8TO32_LITTLE(m + 4)); + x2 = XOR(x2,U8TO32_LITTLE(m + 8)); + x3 = XOR(x3,U8TO32_LITTLE(m + 12)); + x4 = XOR(x4,U8TO32_LITTLE(m + 16)); + x5 = XOR(x5,U8TO32_LITTLE(m + 20)); + x6 = XOR(x6,U8TO32_LITTLE(m + 24)); + x7 = XOR(x7,U8TO32_LITTLE(m + 28)); + x8 = XOR(x8,U8TO32_LITTLE(m + 32)); + x9 = XOR(x9,U8TO32_LITTLE(m + 36)); + x10 = XOR(x10,U8TO32_LITTLE(m + 40)); + x11 = XOR(x11,U8TO32_LITTLE(m + 44)); + x12 = XOR(x12,U8TO32_LITTLE(m + 48)); + x13 = XOR(x13,U8TO32_LITTLE(m + 52)); + x14 = XOR(x14,U8TO32_LITTLE(m + 56)); + x15 = XOR(x15,U8TO32_LITTLE(m + 60)); + + j8 = PLUSONE(j8); + if (!j8) { + j9 = PLUSONE(j9); + /* stopping at 2^70 bytes per nonce is user's responsibility */ + } + + U32TO8_LITTLE(c + 0,x0); + U32TO8_LITTLE(c + 4,x1); + U32TO8_LITTLE(c + 8,x2); + U32TO8_LITTLE(c + 12,x3); + U32TO8_LITTLE(c + 16,x4); + U32TO8_LITTLE(c + 20,x5); + U32TO8_LITTLE(c + 24,x6); + U32TO8_LITTLE(c + 28,x7); + U32TO8_LITTLE(c + 32,x8); + U32TO8_LITTLE(c + 36,x9); + U32TO8_LITTLE(c + 40,x10); + U32TO8_LITTLE(c + 44,x11); + U32TO8_LITTLE(c + 48,x12); + U32TO8_LITTLE(c + 52,x13); + U32TO8_LITTLE(c + 56,x14); + U32TO8_LITTLE(c + 60,x15); + + if (bytes <= 64) { + if (bytes < 64) { + for (i = 0;i < bytes;++i) ctarget[i] = c[i]; + } + x->input[8] = j8; + x->input[9] = j9; + return; + } + bytes -= 64; + c += 64; + m += 64; + } +} + +void ECRYPT_decrypt_bytes(ECRYPT_ctx *x,const u8 *c,u8 *m,u32 bytes) +{ + ECRYPT_encrypt_bytes(x,c,m,bytes); +} + +void ECRYPT_keystream_bytes(ECRYPT_ctx *x,u8 *stream,u32 bytes) +{ + u32 i; + for (i = 0;i < bytes;++i) stream[i] = 0; + ECRYPT_encrypt_bytes(x,stream,stream,bytes); +} diff --git a/libs/encryption/sha1.cpp b/libs/encryption/sha1.cpp new file mode 100644 index 0000000..608a3ae --- /dev/null +++ b/libs/encryption/sha1.cpp @@ -0,0 +1,259 @@ +/* +SHA-1 in C +By Steve Reid +100% Public Domain + +----------------- +Modified 7/98 +By James H. Brown +Still 100% Public Domain + +Corrected a problem which generated improper hash values on 16 bit machines +Routine SHA1Update changed from + void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int +len) +to + void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned +long len) + +The 'len' parameter was declared an int which works fine on 32 bit machines. +However, on 16 bit machines an int is too small for the shifts being done +against +it. This caused the hash function to generate incorrect values if len was +greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update(). + +Since the file IO in main() reads 16K at a time, any file 8K or larger would +be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million +"a"s). + +I also changed the declaration of variables i & j in SHA1Update to +unsigned long from unsigned int for the same reason. + +These changes should make no difference to any 32 bit implementations since +an +int and a long are the same size in those environments. + +-- +I also corrected a few compiler warnings generated by Borland C. +1. Added #include for exit() prototype +2. Removed unused variable 'j' in SHA1Final +3. Changed exit(0) to return(0) at end of main. + +ALL changes I made can be located by searching for comments containing 'JHB' +----------------- +Modified 8/98 +By Steve Reid +Still 100% public domain + +1- Removed #include and used return() instead of exit() +2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall) +3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net + +----------------- +Modified 4/01 +By Saul Kravitz +Still 100% PD +Modified to run on Compaq Alpha hardware. + +----------------- +Modified 07/2002 +By Ralph Giles +Still 100% public domain +modified for use with stdint types, autoconf +code cleanup, removed attribution comments +switched SHA1Final() argument order for consistency +use SHA1_ prefix for public api +move public api to sha1.h +*/ + +/* +Test Vectors (from FIPS PUB 180-1) +"abc" + A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D +"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 +A million repetitions of "a" + 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F +*/ + +#define SHA1HANDSOFF + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "os_types.h" +#include "sha1.h" + +void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]); + +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + +/* blk0() and blk() perform the initial expand. */ +/* I got the idea of expanding during the round function from SSLeay */ +/* FIXME: can we do this in an endian-proof way? */ +#ifdef WORDS_BIGENDIAN +#define blk0(i) block->l[i] +#else +#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ + |(rol(block->l[i],8)&0x00FF00FF)) +#endif +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ + ^block->l[(i+2)&15]^block->l[i&15],1)) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); + + +#ifdef VERBOSE /* SAK */ +void SHAPrintContext(SHA1_CTX *context, char *msg){ + printf("%s (%d,%d) %x %x %x %x %x\n", + msg, + context->count[0], context->count[1], + context->state[0], + context->state[1], + context->state[2], + context->state[3], + context->state[4]); +} +#endif /* VERBOSE */ + +/* Hash a single 512-bit block. This is the core of the algorithm. */ +void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]) +{ + uint32_t a, b, c, d, e; + typedef union { + uint8_t c[64]; + uint32_t l[16]; + } CHAR64LONG16; + CHAR64LONG16* block; + +#ifdef SHA1HANDSOFF + static uint8_t workspace[64]; + block = (CHAR64LONG16*)workspace; + memcpy(block, buffer, 64); +#else + block = (CHAR64LONG16*)buffer; +#endif + + /* Copy context->state[] to working vars */ + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + + /* 4 rounds of 20 operations each. Loop unrolled. */ + R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); + R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); + R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); + R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); + R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); + R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); + R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); + R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); + R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); + R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); + R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); + R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); + R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); + R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); + R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); + R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); + R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); + R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); + R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); + R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); + + /* Add the working vars back into context.state[] */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + + /* Wipe variables */ + a = b = c = d = e = 0; +} + + +/* SHA1Init - Initialize new context */ +void SHA1_Init(SHA1_CTX* context) +{ + /* SHA1 initialization constants */ + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; + context->state[4] = 0xC3D2E1F0; + context->count[0] = context->count[1] = 0; +} + + +/* Run your data through this. */ +void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len) +{ + size_t i, j; + +#ifdef VERBOSE + SHAPrintContext(context, "before"); +#endif + + j = (context->count[0] >> 3) & 63; + if ((context->count[0] += static_cast(len << 3)) < (len << 3)) context->count[1]++; + context->count[1] += static_cast(len >> 29); + if ((j + len) > 63) { + memcpy(&context->buffer[j], data, (i = 64-j)); + SHA1_Transform(context->state, context->buffer); + for ( ; i + 63 < len; i += 64) { + SHA1_Transform(context->state, data + i); + } + j = 0; + } + else i = 0; + memcpy(&context->buffer[j], &data[i], len - i); + +#ifdef VERBOSE + SHAPrintContext(context, "after "); +#endif +} + + +/* Add padding and return the message digest. */ +void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]) +{ + uint32_t i; + uint8_t finalcount[8]; + + for (i = 0; i < 8; i++) { + finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] + >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ + } + SHA1_Update(context, (uint8_t *)"\200", 1); + while ((context->count[0] & 504) != 448) { + SHA1_Update(context, (uint8_t *)"\0", 1); + } + SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */ + for (i = 0; i < SHA1_DIGEST_SIZE; i++) { + digest[i] = (uint8_t) + ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); + } + + /* Wipe variables */ + i = 0; + memset(context->buffer, 0, 64); + memset(context->state, 0, 20); + memset(context->count, 0, 8); + memset(finalcount, 0, 8); /* SWR */ + +#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ + SHA1_Transform(context->state, context->buffer); +#endif +} diff --git a/libs/encryption/sha1.h b/libs/encryption/sha1.h new file mode 100644 index 0000000..fd308b3 --- /dev/null +++ b/libs/encryption/sha1.h @@ -0,0 +1,30 @@ +/* public api for steve reid's public domain SHA-1 implementation */ +/* this file is in the public domain */ + +#include "config_win32.h" +#include + +#ifndef __SHA1_H +#define __SHA1_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint32_t state[5]; + uint32_t count[2]; + uint8_t buffer[64]; +} SHA1_CTX; + +#define SHA1_DIGEST_SIZE 20 + +void SHA1_Init(SHA1_CTX* context); +void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len); +void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]); + +#ifdef __cplusplus +} +#endif + +#endif /* __SHA1_H */ diff --git a/libs/fastfile/fastfile.cpp b/libs/fastfile/fastfile.cpp new file mode 100644 index 0000000..6dcdcca --- /dev/null +++ b/libs/fastfile/fastfile.cpp @@ -0,0 +1,338 @@ +#include "fastfile.h" + +#include "fastfile_cod2.h" +#include "fastfile_cod5.h" +#include "fastfile_cod7.h" +#include "fastfile_cod9.h" +#include "logmanager.h" + +#include +#include + +FastFile::FastFile() + : mStem(""), + mType(FILETYPE_NONE), + mCompany(COMPANY_NONE), + mSignage(SIGNAGE_NONE), + mMagic(""), + mVersion(0), + mZoneFile(nullptr), + mGame(""), + mPlatform("") { + +} + +FastFile::FastFile(FastFile &fastFile) + : mStem(fastFile.GetStem()), + mType(fastFile.GetType()), + mCompany(fastFile.GetCompany()), + mSignage(fastFile.GetSignage()), + mMagic(fastFile.GetMagic()), + mVersion(fastFile.GetVersion()), + mZoneFile(fastFile.GetZoneFile()), + mGame(fastFile.GetGame()), + mPlatform(fastFile.GetPlatform()) { + +} + +FastFile::~FastFile() { + +} + +QString FastFile::GetStem() const { + return mStem; +} + +FF_FILETYPE FastFile::GetType() const { + return mType; +} + +FF_COMPANY FastFile::GetCompany() const { + return mCompany; +} + +FF_SIGNAGE FastFile::GetSignage() const { + return mSignage; +} + +QString FastFile::GetMagic() const { + return mMagic; +} + +quint32 FastFile::GetVersion() const { + return mVersion; +} + +std::shared_ptr FastFile::GetZoneFile() const { + return mZoneFile; +} + +QString FastFile::GetGame() const { + return mGame; +} + +QString FastFile::GetPlatform() const { + return mPlatform; +} + +void FastFile::SetStem(const QString aStem) { + mStem = aStem; +} + +void FastFile::SetType(const FF_FILETYPE aType) { + mType = aType; +} + +void FastFile::SetCompany(const FF_COMPANY aCompany) { + mCompany = aCompany; +} + +void FastFile::SetSignage(const FF_SIGNAGE aSignage) { + mSignage = aSignage; +} + +void FastFile::SetMagic(const QString aMagic) { + mMagic = aMagic; +} + +void FastFile::SetVersion(const quint32 aVersion) { + mVersion = aVersion; +} + +void FastFile::SetZoneFile(const std::shared_ptr aZoneFile) { + mZoneFile = aZoneFile; +} + +void FastFile::SetGame(const QString aGame) { mGame = aGame; +} + +void FastFile::SetPlatform(const QString aPlatform) { + mPlatform = aPlatform; +} + +FF_COMPANY FastFile::pParseFFCompany(QDataStream *afastFileStream, quint32 &aCompanyInt) { + LogManager::instance().addEntry("Parsing company into reference..."); + // Check for null datastream ptr + if (!afastFileStream) { return COMPANY_NONE; } + // Parse company + QByteArray companyData(2, Qt::Uninitialized); + afastFileStream->readRawData(companyData.data(), 2); + aCompanyInt = companyData.toUInt(); + + if (companyData == "IW") { + return COMPANY_INFINITY_WARD; + } else if (companyData == "TA") { + return COMPANY_TREYARCH; + } else if (companyData == "Sl") { + return COMPANY_SLEDGEHAMMER; + } else if (companyData == "NX") { + return COMPANY_NEVERSOFT; + } + LogManager::instance().addEntry(QString("Failed to find company, found '%1'!").arg(companyData)); + return COMPANY_NONE; +} + +FF_COMPANY FastFile::pParseFFCompany(QDataStream *afastFileStream) { + LogManager::instance().addEntry("Parsing company..."); + // Check for null datastream ptr + if (!afastFileStream) { return COMPANY_NONE; } + // Parse company + QByteArray companyData(2, Qt::Uninitialized); + afastFileStream->readRawData(companyData.data(), 2); + + if (companyData == "IW") { + return COMPANY_INFINITY_WARD; + } else if (companyData == "TA") { + return COMPANY_TREYARCH; + } else if (companyData == "Sl") { + } else if (companyData == "NX") { + return COMPANY_NEVERSOFT; + } + LogManager::instance().addEntry(QString("Failed to find company, found '%1'!").arg(companyData)); + return COMPANY_NONE; +} + +FF_FILETYPE FastFile::pParseFFFileType(QDataStream *afastFileStream) { + // Parse filetype + QByteArray fileTypeData(2, Qt::Uninitialized); + afastFileStream->readRawData(fileTypeData.data(), 2); + if (fileTypeData == "ff") { + return FILETYPE_FAST_FILE; + } + LogManager::instance().addEntry("Failed to find file type!"); + return FILETYPE_NONE; +} + +FF_SIGNAGE FastFile::pParseFFSignage(QDataStream *afastFileStream) { + // Parse filetype + QByteArray signedData(1, Qt::Uninitialized); + afastFileStream->readRawData(signedData.data(), 1); + if (signedData == "u") { + return SIGNAGE_UNSIGNED; + } else if (signedData == "0" || signedData == "x") { + return SIGNAGE_SIGNED; + } + LogManager::instance().addEntry("Failed to determine signage of fastfile!"); + return SIGNAGE_NONE; +} + +QString FastFile::pParseFFMagic(QDataStream *afastFileStream) { + // Parse magic + QByteArray magicData(3, Qt::Uninitialized); + afastFileStream->readRawData(magicData.data(), 3); + if (magicData == "100") { + return magicData; + } + LogManager::instance().addEntry("Magic invalid!"); + return ""; +} + +quint32 FastFile::pParseFFVersion(QDataStream *afastFileStream) { + // Parse version + quint32 version; + *afastFileStream >> version; + qDebug() << QString("Found version: '%1'").arg(version); + return version; +} + +QString FastFile::pCalculateFFPlatform(quint32 aVersion) { + switch (aVersion) { + case 387: // PC World at War + case 473: // PC Black Ops 1 + case 1: // PC Modern Warfare 3 + case 147: // PC Black Ops 2 + return "PC"; + case 3640721408: // Xbox 360 Black Ops 1 + case 2449473536: // Xbox 360 Black Ops 2 + return "360"; + case 3707830272: // Wii Black Ops 1 + return "Wii"; + } + return "NONE"; +} + +QString FastFile::pCalculateFFGame(quint32 aVersion) { + QString result = "NONE"; + switch (aVersion) { + case 387: // PC World at War + result = "COD5"; + break; + case 473: // PC Black Ops 1 + break; + case 3640721408: // Xbox 360 Black Ops 1 + case 3707830272: // Wii Black Ops 1 + result = "COD7"; + break; + case 1: // PC Modern Warfare 3 + result = "COD8"; + break; + case 147: // PC Black Ops 2 + case 2449473536: // Xbox 360 Black Ops 2 + result = "COD9"; + break; + } + qDebug() << QString("Found game: '%1'").arg(result); + return result; +} + +std::shared_ptr FastFile::Open(const QString &aFilePath) { + LogManager::instance().addEntry("Processing Fastfile..."); + + if (aFilePath.isEmpty()) { + LogManager::instance().addError("Attempted to open file w/no name!"); + return nullptr; + } + LogManager::instance().addEntry("File Path: " + aFilePath); + + // Check fastfile can be read + QFile *file = new QFile(aFilePath); + if (!file->open(QIODevice::ReadOnly)) { + LogManager::instance().addError(QString("File failed to open: %1").arg(file->errorString())); + return nullptr; + } + LogManager::instance().addEntry("File opened"); + + const QByteArray data = file->readAll(); + LogManager::instance().addEntry("Contents read in"); + LogManager::instance().addEntry(QString("- Size: %1 B").arg(data.size())); + + LogManager::instance().addEntry("File closed"); + file->close(); + + // Create a QDataStream on the input data. + QDataStream fastFileStream(data); + fastFileStream.setByteOrder(QDataStream::LittleEndian); + + quint32 companyInt; + FF_COMPANY company = pParseFFCompany(&fastFileStream, companyInt); + qDebug() << "Company: " << company; + FF_FILETYPE fileType; + FF_SIGNAGE signage; + QString magic; + quint32 version; + QString platform; + QString game; + + if ((company == COMPANY_NONE) && (companyInt == 0)) { + company = COMPANY_INFINITY_WARD; + game = "COD2"; + platform = "360"; + } else { + fileType = pParseFFFileType(&fastFileStream); + signage = pParseFFSignage(&fastFileStream); + magic = pParseFFMagic(&fastFileStream); + version = pParseFFVersion(&fastFileStream); + platform = pCalculateFFPlatform(version); + game = pCalculateFFGame(version); + + LogManager::instance().addEntry(QString("Type: %1").arg(fileType)); + LogManager::instance().addEntry(QString("Signage: %1").arg(signage)); + LogManager::instance().addEntry(QString("Magic: %1").arg(magic)); + LogManager::instance().addEntry(QString("Version: %1").arg(version)); + } + LogManager::instance().addEntry(QString("Company: %1").arg(company)); + LogManager::instance().addEntry(QString("Game: %1").arg(game)); + LogManager::instance().addEntry(QString("Platform: %1").arg(platform)); + + const QString fastFileStem = aFilePath.section("/", -1, -1).section('.', 0, 0); + LogManager::instance().addEntry(QString("Stem: %1").arg(fastFileStem)); + + FastFile *fastFile; + bool validff = true; + if (game == "COD2") { + fastFile = new FastFile_COD2(); + } else if (game == "COD5") { + fastFile = new FastFile_COD5(); + } else if (game == "COD7") { + fastFile = new FastFile_COD7(); + } else if (game == "COD9") { + fastFile = new FastFile_COD9(); + } else { + validff = false; + } + + LogManager::instance().addLine(); + + if (validff) { + fastFile->SetCompany(company); + fastFile->SetStem(fastFileStem); + fastFile->Load(data); + return std::unique_ptr(fastFile); + } + + + // Open zone file after decompressing ff and writing + return nullptr; +} +bool FastFile::ExportFastFile(const QString aFastFilePath) { + QFile fastFile(aFastFilePath); + if (!fastFile.open(QIODevice::WriteOnly)) { + LogManager::instance().addEntry("Failed to write fast file! " + + fastFile.errorString()); + return false; + } + fastFile.write(GetBinaryData()); + fastFile.close(); + + return true; +} diff --git a/libs/fastfile/fastfile.h b/libs/fastfile/fastfile.h new file mode 100644 index 0000000..a1de1a2 --- /dev/null +++ b/libs/fastfile/fastfile.h @@ -0,0 +1,68 @@ +#ifndef FASTFILE_H +#define FASTFILE_H + +#include "enums.h" +#include "zonefile.h" + +#include +#include +#include + +class FastFile +{ +public: + FastFile(); + FastFile(FastFile &fastFile); + ~FastFile(); + + virtual bool Load(const QString aFilePath) = 0; + virtual bool Load(const QByteArray aData) = 0; + + virtual bool ExportFastFile(const QString aFastFilePath); + + virtual QByteArray GetBinaryData() = 0; + + virtual QString GetStem() const; + virtual FF_FILETYPE GetType() const; + virtual FF_COMPANY GetCompany() const; + virtual FF_SIGNAGE GetSignage() const; + virtual QString GetMagic() const; + virtual quint32 GetVersion() const; + virtual std::shared_ptr GetZoneFile() const; + virtual QString GetGame() const; + virtual QString GetPlatform() const; + + virtual void SetStem(const QString aStem); + virtual void SetType(const FF_FILETYPE aType); + virtual void SetCompany(const FF_COMPANY aCompany); + virtual void SetSignage(const FF_SIGNAGE aSignage); + virtual void SetMagic(const QString aMagic); + virtual void SetVersion(const quint32 aVersion); + virtual void SetZoneFile(const std::shared_ptr aZoneFile); + virtual void SetGame(const QString aGame); + virtual void SetPlatform(const QString aPlatform); + + static FF_COMPANY pParseFFCompany(QDataStream *afastFileStream, quint32 &aCompanyInt); + static FF_COMPANY pParseFFCompany(QDataStream *afastFileStream); + static FF_FILETYPE pParseFFFileType(QDataStream *afastFileStream); + static FF_SIGNAGE pParseFFSignage(QDataStream *afastFileStream); + static QString pParseFFMagic(QDataStream *afastFileStream); + static quint32 pParseFFVersion(QDataStream *afastFileStream); + static QString pCalculateFFPlatform(quint32 aVersion); + static QString pCalculateFFGame(quint32 aVersion); + + static std::shared_ptr Open(const QString& aFilePath); + +private: + QString mStem; + FF_FILETYPE mType; + FF_COMPANY mCompany; + FF_SIGNAGE mSignage; + QString mMagic; + quint32 mVersion; + std::shared_ptr mZoneFile; + QString mGame; + QString mPlatform; +}; + +#endif // FASTFILE_H diff --git a/libs/fastfile/fastfile.pro b/libs/fastfile/fastfile.pro new file mode 100644 index 0000000..9729134 --- /dev/null +++ b/libs/fastfile/fastfile.pro @@ -0,0 +1,37 @@ +QT += core widgets +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + fastfile_cod2.cpp \ + fastfile_cod5.cpp \ + fastfile_cod7.cpp \ + fastfile_cod9.cpp \ + fastfile.cpp + +HEADERS += \ + fastfile.h \ + fastfile_cod2.h \ + fastfile_cod5.h \ + fastfile_cod7.h \ + fastfile_cod9.h + +LIBS += \ + -L$$OUT_PWD/../libs/core -lcore \ + -L$$OUT_PWD/../libs/compression -lcompression \ + -L$$OUT_PWD/../libs/encryption -lencryption \ + -L$$OUT_PWD/../libs/zonefile -lzonefile + +INCLUDEPATH += \ + $$PWD/../core \ + $$PWD/../compression \ + $$PWD/../encryption \ + $$PWD/../zonefile + +DEPENDPATH += \ + $$PWD/../core \ + $$PWD/../compression \ + $$PWD/../encryption \ + $$PWD/../zonefile + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/fastfile/fastfile_cod2.cpp b/libs/fastfile/fastfile_cod2.cpp new file mode 100644 index 0000000..8c58687 --- /dev/null +++ b/libs/fastfile/fastfile_cod2.cpp @@ -0,0 +1,83 @@ +#include "fastfile_cod2.h" + +#include "utils.h" +#include "compression.h" +#include "zonefile_cod2.h" + +#include +#include + +FastFile_COD2::FastFile_COD2() { + +} + +FastFile_COD2::~FastFile_COD2() { + +} + +QByteArray FastFile_COD2::GetBinaryData() { + return QByteArray(); +} + +bool FastFile_COD2::Load(const QString aFilePath) { + if (aFilePath.isEmpty()) { + return false; + } + + // Check fastfile can be read + QFile *file = new QFile(aFilePath); + if (!file->open(QIODevice::ReadOnly)) { + qDebug() << QString("Error: Failed to open FastFile: %1!").arg(aFilePath); + return false; + } + + // Decompress fastfile and close + const QString fastFileStem = aFilePath.section("/", -1, -1).section(".", 0, 0); + qDebug() << "fastFileStem: " << fastFileStem; + SetStem(fastFileStem); + if (!Load(file->readAll())) { + qDebug() << "Error: Failed to load fastfile: " << fastFileStem; + return false; + } + + file->close(); + + // Open zone file after decompressing ff and writing + return true; +} + +bool FastFile_COD2::Load(const QByteArray aData) { + // Create a QDataStream on the input data. + QDataStream fastFileStream(aData); + fastFileStream.setByteOrder(QDataStream::LittleEndian); + + // Parse header values. + SetCompany(COMPANY_INFINITY_WARD); + SetType(FILETYPE_FAST_FILE); + SetSignage(SIGNAGE_UNSIGNED); + SetMagic(0); + SetVersion(0); + SetPlatform("360"); + SetGame("COD2"); + + Utils::ReadUntilHex(&fastFileStream, "78"); + QByteArray compressedData = aData.mid(fastFileStream.device()->pos()); + QByteArray decompressedData = Compression::DecompressZLIB(compressedData); + + QDir exportsDir(QDir::currentPath()); + exportsDir.mkdir("exports"); + + QFile testFile("exports/" + GetStem() + ".zone"); + if(testFile.open(QIODevice::WriteOnly)) { + testFile.write(decompressedData); + testFile.close(); + } + + // Load the zone file with the decompressed data (using an Xbox platform flag). + ZoneFile_COD2 zoneFile; + zoneFile.SetStem(GetStem()); + zoneFile.Load(decompressedData, FF_PLATFORM_XBOX); + SetZoneFile(std::make_shared(zoneFile)); + + return true; +} diff --git a/libs/fastfile/fastfile_cod2.h b/libs/fastfile/fastfile_cod2.h new file mode 100644 index 0000000..91adfe9 --- /dev/null +++ b/libs/fastfile/fastfile_cod2.h @@ -0,0 +1,18 @@ +#ifndef FASTFILE_COD2_H +#define FASTFILE_COD2_H + +#include "fastfile.h" + +class FastFile_COD2 : public FastFile +{ +public: + FastFile_COD2(); + ~FastFile_COD2(); + + QByteArray GetBinaryData() override; + + bool Load(const QString aFilePath) override; + bool Load(const QByteArray aData) override; +}; + +#endif // FASTFILE_COD2_H diff --git a/libs/fastfile/fastfile_cod5.cpp b/libs/fastfile/fastfile_cod5.cpp new file mode 100644 index 0000000..50d11f2 --- /dev/null +++ b/libs/fastfile/fastfile_cod5.cpp @@ -0,0 +1,88 @@ +#include "fastfile_cod5.h" +#include "zonefile_cod5.h" + +#include "utils.h" +#include "compression.h" +#include "statusbarmanager.h" + +#include +#include + +FastFile_COD5::FastFile_COD5() { + +} + +FastFile_COD5::~FastFile_COD5() { + +} + +QByteArray FastFile_COD5::GetBinaryData() { + return QByteArray(); +} + +bool FastFile_COD5::Load(const QString aFilePath) { + StatusBarManager::instance().updateStatus("Loading COD5 Fast File w/path", 1000); + + if (aFilePath.isEmpty()) { + return false; + } + + // Check fastfile can be read + QFile *file = new QFile(aFilePath); + if (!file->open(QIODevice::ReadOnly)) { + qDebug() << QString("Error: Failed to open FastFile: %1!").arg(aFilePath); + return false; + } + + // Decompress fastfile and close + const QString fastFileStem = aFilePath.section("/", -1, -1); + SetStem(fastFileStem); + if (!Load(file->readAll())) { + qDebug() << "Error: Failed to load fastfile: " << fastFileStem; + return false; + } + + file->close(); + + // Open zone file after decompressing ff and writing + return true; +} + +bool FastFile_COD5::Load(const QByteArray aData) { + StatusBarManager::instance().updateStatus("Loading COD5 Fast File w/data", 1000); + QByteArray decompressedData; + + // Create a QDataStream on the input data. + QDataStream fastFileStream(aData); + fastFileStream.setByteOrder(QDataStream::LittleEndian); + + // Parse header values. + SetCompany(pParseFFCompany(&fastFileStream)); + SetType(pParseFFFileType(&fastFileStream)); + SetSignage(pParseFFSignage(&fastFileStream)); + SetMagic(pParseFFMagic(&fastFileStream)); + quint32 version = pParseFFVersion(&fastFileStream); + SetVersion(version); + const QString platformStr = pCalculateFFPlatform(version); + SetPlatform(platformStr); + SetGame("COD5"); + + // For COD5, simply decompress from offset 12. + decompressedData = Compression::DecompressZLIB(aData.mid(12)); + + Utils::ExportData(GetStem() + ".zone", decompressedData); + + FF_PLATFORM platform = FF_PLATFORM_NONE; + if (platformStr == "PC") { + platform = FF_PLATFORM_PC; + } else if (platformStr == "360") { + platform = FF_PLATFORM_XBOX; + } + + ZoneFile_COD5 zoneFile; + zoneFile.SetStem(GetStem()); + zoneFile.Load(decompressedData, platform); + SetZoneFile(std::make_shared(zoneFile)); + + return true; +} diff --git a/libs/fastfile/fastfile_cod5.h b/libs/fastfile/fastfile_cod5.h new file mode 100644 index 0000000..0622ce3 --- /dev/null +++ b/libs/fastfile/fastfile_cod5.h @@ -0,0 +1,18 @@ +#ifndef FASTFILE_COD5_H +#define FASTFILE_COD5_H + +#include "fastfile.h" + +class FastFile_COD5 : public FastFile +{ +public: + FastFile_COD5(); + ~FastFile_COD5(); + + QByteArray GetBinaryData() override; + + bool Load(const QString aFilePath) override; + bool Load(const QByteArray aData) override; +}; + +#endif // FASTFILE_COD5_H diff --git a/libs/fastfile/fastfile_cod7.cpp b/libs/fastfile/fastfile_cod7.cpp new file mode 100644 index 0000000..92f34c2 --- /dev/null +++ b/libs/fastfile/fastfile_cod7.cpp @@ -0,0 +1,168 @@ +#include "fastfile_cod7.h" +#include "zonefile_cod7.h" + +#include "utils.h" +#include "compression.h" +#include "encryption.h" + +#include +#include + +FastFile_COD7::FastFile_COD7() { + +} + +FastFile_COD7::~FastFile_COD7() { + +} + +QByteArray FastFile_COD7::GetBinaryData() { + return QByteArray(); +} + +bool FastFile_COD7::Load(const QString aFilePath) { + if (aFilePath.isEmpty()) { + return false; + } + + // Check fastfile can be read + QFile *file = new QFile(aFilePath); + if (!file->open(QIODevice::ReadOnly)) { + qDebug() << QString("Error: Failed to open FastFile: %1!").arg(aFilePath); + return false; + } + + // Decompress fastfile and close + const QString fastFileStem = aFilePath.section("/", -1, -1); + SetStem(fastFileStem); + if (!Load(file->readAll())) { + qDebug() << "Error: Failed to load fastfile: " << fastFileStem; + return false; + } + + file->close(); + + // Open zone file after decompressing ff and writing + return true; +} + +bool FastFile_COD7::Load(const QByteArray aData) { + QByteArray decompressedData; + + // Create a QDataStream on the input data. + QDataStream fastFileStream(aData); + fastFileStream.setByteOrder(QDataStream::LittleEndian); + + // Parse header values. + SetCompany(pParseFFCompany(&fastFileStream)); + SetType(pParseFFFileType(&fastFileStream)); + SetSignage(pParseFFSignage(&fastFileStream)); + SetMagic(pParseFFMagic(&fastFileStream)); + quint32 version = pParseFFVersion(&fastFileStream); + SetVersion(version); + SetPlatform(pCalculateFFPlatform(version)); + SetGame("COD7"); + + // Load the zone file with the decompressed data (using an Xbox platform flag). + ZoneFile_COD7 zoneFile; + zoneFile.SetStem(GetStem()); + + // For COD7/COD9, use BigEndian. + fastFileStream.setByteOrder(QDataStream::BigEndian); + if (GetPlatform() == "PC") { + fastFileStream.setByteOrder(QDataStream::LittleEndian); + + // Select key based on game. + QByteArray key; + fastFileStream.skipRawData(4); + if (GetPlatform() == "360") { + key = QByteArray::fromHex("1ac1d12d527c59b40eca619120ff8217ccff09cd16896f81b829c7f52793405d"); + } else if (GetPlatform() == "PS3") { + key = QByteArray::fromHex("46D3F997F29C9ACE175B0DAE3AB8C0C1B8E423E2E3BF7E3C311EA35245BF193A"); + // or + // key = QByteArray::fromHex("0C99B3DDB8D6D0845D1147E470F28A8BF2AE69A8A9F534767B54E9180FF55370"); + } + + // Read the 8-byte magic. + QByteArray fileMagic(8, Qt::Uninitialized); + fastFileStream.readRawData(fileMagic.data(), 8); + if (fileMagic != "PHEEBs71") { + qWarning() << "Invalid fast file magic!"; + return false; + } + fastFileStream.skipRawData(4); + + // Read IV table name (32 bytes). + QByteArray fileName(32, Qt::Uninitialized); + fastFileStream.readRawData(fileName.data(), 32); + + // Build the IV table from the fileName. + QByteArray ivTable = Encryption::InitIVTable(fileName); + + // Skip the RSA signature (256 bytes). + QByteArray rsaSignature(256, Qt::Uninitialized); + fastFileStream.readRawData(rsaSignature.data(), 256); + + // Now the stream should be positioned at 0x13C, where sections begin. + int sectionIndex = 0; + while (true) { + qint32 sectionSize = 0; + fastFileStream >> sectionSize; + qDebug() << "Section index:" << sectionIndex << "Size:" << sectionSize + << "Pos:" << fastFileStream.device()->pos(); + if (sectionSize == 0) + break; + + // Read the section data. + QByteArray sectionData; + sectionData.resize(sectionSize); + fastFileStream.readRawData(sectionData.data(), sectionSize); + + // Compute the IV for this section. + QByteArray iv = Encryption::GetIV(ivTable, sectionIndex); + + // Decrypt the section using Salsa20. + QByteArray decData = Encryption::salsa20DecryptSection(sectionData, key, iv); + + // Compute SHA1 hash of the decrypted data. + QByteArray sectionHash = QCryptographicHash::hash(decData, QCryptographicHash::Sha1); + + // Update the IV table based on the section hash. + Encryption::UpdateIVTable(ivTable, sectionIndex, sectionHash); + + // Build a compressed data buffer by prepending the two-byte zlib header. + QByteArray compressedData; + compressedData.append(char(0x78)); + compressedData.append(char(0x01)); + compressedData.append(decData); + + decompressedData.append(Compression::DecompressZLIB(compressedData)); + + sectionIndex++; + } + + zoneFile.Load(decompressedData, FF_PLATFORM_XBOX); + } else if (GetPlatform() == "Wii") { + // For COD7, simply decompress from offset 12. + decompressedData = Compression::DecompressZLIB(aData.mid(12)); + + Utils::ExportData(GetStem() + ".zone", decompressedData); + + QDir workingDir = QDir::currentPath(); + workingDir.mkdir("exports"); + + QFile outputFile("exports/" + GetStem() + ".zone"); + if (!outputFile.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to extract IPAK file."; + } + qDebug() << " - File Name: " << outputFile.fileName(); + outputFile.write(decompressedData); + outputFile.close(); + + zoneFile.Load(decompressedData, FF_PLATFORM_WII); + } + + SetZoneFile(std::make_shared(zoneFile)); + + return true; +} diff --git a/libs/fastfile/fastfile_cod7.h b/libs/fastfile/fastfile_cod7.h new file mode 100644 index 0000000..ae2d478 --- /dev/null +++ b/libs/fastfile/fastfile_cod7.h @@ -0,0 +1,18 @@ +#ifndef FASTFILE_COD7_H +#define FASTFILE_COD7_H + +#include "fastfile.h" + +class FastFile_COD7 : public FastFile +{ +public: + FastFile_COD7(); + ~FastFile_COD7(); + + QByteArray GetBinaryData() override; + + bool Load(const QString aFilePath) override; + bool Load(const QByteArray aData) override; +}; + +#endif // FASTFILE_COD7_H diff --git a/libs/fastfile/fastfile_cod9.cpp b/libs/fastfile/fastfile_cod9.cpp new file mode 100644 index 0000000..353b0a0 --- /dev/null +++ b/libs/fastfile/fastfile_cod9.cpp @@ -0,0 +1,114 @@ +#include "fastfile_cod9.h" +#include "zonefile_cod9.h" +#include "encryption.h" + +#include +#include + +FastFile_COD9::FastFile_COD9() { + +} + +FastFile_COD9::~FastFile_COD9() { + +} + +QByteArray FastFile_COD9::GetBinaryData() { + return QByteArray(); +} + +bool FastFile_COD9::Load(const QString aFilePath) { + if (aFilePath.isEmpty()) { + return false; + } + + // Check fastfile can be read + QFile *file = new QFile(aFilePath); + if (!file->open(QIODevice::ReadOnly)) { + qDebug() << QString("Error: Failed to open FastFile: %1!").arg(aFilePath); + return false; + } + + // Decompress fastfile and close + const QString fastFileStem = aFilePath.section("/", -1, -1).section(".", 0, 0); + SetStem(fastFileStem); + if (!Load(file->readAll())) { + qDebug() << "Error: Failed to load fastfile: " << fastFileStem + ".ff"; + return false; + } + + file->close(); + + // Open zone file after decompressing ff and writing + return true; +} + +bool FastFile_COD9::Load(const QByteArray aData) { + QByteArray decompressedData; + + // Create a QDataStream on the input data. + QDataStream fastFileStream(aData); + fastFileStream.setByteOrder(QDataStream::LittleEndian); + + // Parse header values. + SetCompany(pParseFFCompany(&fastFileStream)); + SetType(pParseFFFileType(&fastFileStream)); + SetSignage(pParseFFSignage(&fastFileStream)); + SetMagic(pParseFFMagic(&fastFileStream)); + quint32 version = pParseFFVersion(&fastFileStream); + SetVersion(version); + SetPlatform(pCalculateFFPlatform(version)); + SetGame("COD9"); + + // For COD7/COD9, use BigEndian. + fastFileStream.setByteOrder(QDataStream::BigEndian); + if (GetPlatform() == "PC") { + fastFileStream.setByteOrder(QDataStream::LittleEndian); + } + + // Select key based on game. + QByteArray key; + if (GetPlatform() == "360") { + key = QByteArray::fromHex("0E50F49F412317096038665622DD091332A209BA0A05A00E1377CEDB0A3CB1D3"); + } else if (GetPlatform() == "PC") { + key = QByteArray::fromHex("641D8A2FE31D3AA63622BBC9CE8587229D42B0F8ED9B924130BF88B65EDC50BE"); + } + + // Read the 8-byte magic. + QByteArray fileMagic(8, Qt::Uninitialized); + fastFileStream.readRawData(fileMagic.data(), 8); + if (fileMagic != "PHEEBs71") { + qWarning() << "Invalid fast file magic!"; + return false; + } + fastFileStream.skipRawData(4); + + // Read IV table name (32 bytes). + QByteArray fileName(32, Qt::Uninitialized); + fastFileStream.readRawData(fileName.data(), 32); + + // Skip the RSA signature (256 bytes). + QByteArray rsaSignature(256, Qt::Uninitialized); + fastFileStream.readRawData(rsaSignature.data(), 256); + + if (GetPlatform() == "360") { + //decompressedData = Compressor::cod9_decryptFastFile(aData); + } else if (GetPlatform() == "PC") { + decompressedData = Encryption::decryptFastFile(aData); + } + + // For COD9, write out the complete decompressed zone for testing. + QFile testFile("exports/" + GetStem() + ".zone"); + if(testFile.open(QIODevice::WriteOnly)) { + testFile.write(decompressedData); + testFile.close(); + } + + // Load the zone file with the decompressed data (using an Xbox platform flag). + ZoneFile_COD9 zoneFile; + zoneFile.SetStem(GetStem()); + zoneFile.Load(decompressedData, FF_PLATFORM_PC); + SetZoneFile(std::make_shared(zoneFile)); + + return true; +} diff --git a/libs/fastfile/fastfile_cod9.h b/libs/fastfile/fastfile_cod9.h new file mode 100644 index 0000000..fdc3d16 --- /dev/null +++ b/libs/fastfile/fastfile_cod9.h @@ -0,0 +1,18 @@ +#ifndef FASTFILE_COD9_H +#define FASTFILE_COD9_H + +#include "fastfile.h" + +class FastFile_COD9 : public FastFile +{ +public: + FastFile_COD9(); + ~FastFile_COD9(); + + QByteArray GetBinaryData() override; + + bool Load(const QString aFilePath) override; + bool Load(const QByteArray aData) override; +}; + +#endif // FASTFILE_COD9_H diff --git a/libs/ipakfile/ipak_structs.h b/libs/ipakfile/ipak_structs.h new file mode 100644 index 0000000..44b996a --- /dev/null +++ b/libs/ipakfile/ipak_structs.h @@ -0,0 +1,167 @@ +#ifndef IPAK_STRUCTS_H +#define IPAK_STRUCTS_H + +#include +#include +#include + +struct IPAKHeader +{ + QString magic; + quint32 magicInt; + QString version; + quint32 versionInt; + quint32 size; + quint32 sectionCount; + QString platform; + // Serial read method + friend QDataStream &operator>>(QDataStream &in, IPAKHeader &data) { + in.setByteOrder(QDataStream::LittleEndian); + in >> data.magicInt; + if (data.magicInt == 1262571593) { + in.setByteOrder(QDataStream::BigEndian); + data.platform = "Console"; + } else { + data.platform = "PC"; + } + in >> data.versionInt >> data.size >> data.sectionCount; + // Format magic into string + const char *magicChars = reinterpret_cast(&data.magicInt); + data.magic = QString::fromUtf8(magicChars, 4); + + // Format version into hex + data.version = QString::number(data.versionInt, 16).toUpper(); + return in; + } + // Serial write method + friend QDataStream &operator<<(QDataStream &out, const IPAKHeader &data) { + out.setByteOrder(QDataStream::LittleEndian); + if (data.magicInt == 1262571593) { + out.setByteOrder(QDataStream::BigEndian); + } + out << data.magicInt << data.version << data.size << data.sectionCount; + return out; + } +}; + +struct IPAKSection +{ + QString type; + quint32 typeInt; + quint32 offset; + quint32 size; + quint32 itemCount; + // Serial read method + friend QDataStream &operator>>(QDataStream &in, IPAKSection &data) { + in >> data.typeInt >> data.offset >> data.size >> data.itemCount; + // Format type into string + if (data.typeInt == 1) { + data.type = "Index"; + } else if (data.typeInt == 2) { + data.type = "Data"; + } else { + data.type = "Unknown"; + } + return in; + } + // Serial write method + friend QDataStream &operator<<(QDataStream &out, const IPAKSection &data) { + out << data.typeInt << data.offset << data.size << data.itemCount; + return out; + } +}; + +struct IPAKDataChunkCommand { + quint32 size; + bool compressed; + // Serial read method + friend QDataStream &operator>>(QDataStream &in, IPAKDataChunkCommand &data) { + quint32 sizeAndCompression; + in >> sizeAndCompression; + + data.size = sizeAndCompression & 0x00FFFFFF; + data.compressed = (sizeAndCompression >> 24) & 0x01; + + return in; + } + // Serial write method + friend QDataStream &operator<<(QDataStream &out, const IPAKDataChunkCommand &data) { + quint32 sanitizedSize = data.size & 0x00FFFFFF; + quint32 sanitizedCompressed = data.compressed & 0x01; + quint32 sizeAndCompression = (sanitizedCompressed << 24) | sanitizedSize; + + out << sizeAndCompression; + return out; + } +}; + +struct IPAKDataChunkHeader +{ + quint32 count; + quint32 offset; + QVector commands; + // Serial read method + friend QDataStream &operator>>(QDataStream &in, IPAKDataChunkHeader &data) { + quint32 countAndOffset; + in >> countAndOffset; + data.count = (countAndOffset >> 24) & 0xFF; + data.offset = countAndOffset & 0x00FFFFFF; + return in; + } + // Serial write method + friend QDataStream &operator<<(QDataStream &out, const IPAKDataChunkHeader &data) { + quint32 count = data.count & 0xFF; + quint32 offset = data.offset & 0x00FFFFFF; + out << ((count << 24) | offset); + return out; + } +}; + +struct IPAKIndexEntry +{ + quint32 dataHash; + quint32 nameHash; + quint32 offset; + quint32 size; + // Serial read method + friend QDataStream &operator>>(QDataStream &in, IPAKIndexEntry &data) { + in >> data.dataHash >> data.nameHash >> data.offset >> data.size; + return in; + } + // Serial write method + friend QDataStream &operator<<(QDataStream &out, const IPAKIndexEntry &data) { + out << data.dataHash << data.nameHash << data.offset << data.size; + return out; + } +}; + +struct IPAKDataChunkMetaData +{ + quint64 key; + QString name; + int format; + int offset; + int size; + int width; + int height; + int levels; + int mip; + // Serial read method + friend QDataStream &operator>>(QDataStream &in, IPAKDataChunkMetaData &data) { + in >> data.key; + in.readRawData(reinterpret_cast(data.name.data()), sizeof(60)); + in >> data.format >> data.offset >> data.size >> data.width + >> data.height >> data.levels >> data.mip; + return in; + } + // Serial write method + friend QDataStream &operator<<(QDataStream &out, const IPAKDataChunkMetaData &data) { + out << data.key; + out.writeRawData(reinterpret_cast(data.name.constData()), sizeof(60)); + out << data.format << data.offset << data.size << data.width + << data.height << data.levels << data.mip; + return out; + } +}; + +#endif // IPAK_STRUCTS_H diff --git a/libs/ipakfile/ipakfile.cpp b/libs/ipakfile/ipakfile.cpp new file mode 100644 index 0000000..e864f00 --- /dev/null +++ b/libs/ipakfile/ipakfile.cpp @@ -0,0 +1 @@ +#include "ipak_structs.h" diff --git a/libs/ipakfile/ipakfile.pro b/libs/ipakfile/ipakfile.pro new file mode 100644 index 0000000..73422b6 --- /dev/null +++ b/libs/ipakfile/ipakfile.pro @@ -0,0 +1,11 @@ +QT += core +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + ipakfile.cpp + +HEADERS += \ + ipak_structs.h + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/iwifile/iwifile.cpp b/libs/iwifile/iwifile.cpp new file mode 100644 index 0000000..155fe20 --- /dev/null +++ b/libs/iwifile/iwifile.cpp @@ -0,0 +1,292 @@ +#include "iwifile.h" +#include "ddsfile.h" + +IWIFile::IWIFile() : + fileStem(), + header(), + info(), + mipmaps() { + +} + +IWIFile::IWIFile(const QString &aFilePath) : + fileStem(aFilePath.split('.').first().split('/').last()) { + + QFile file(aFilePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Error: Unable to open IWI file" << aFilePath; + return; + } + + QDataStream in(&file); + in.setByteOrder(QDataStream::LittleEndian); + + // Read header + in.readRawData(reinterpret_cast(&header), sizeof(IWIHeader)); + + if (!header.isSupported()) { + qDebug() << "Error: Unsupported IWI version!"; + return; + } + + // Adjust seek position for MW2/MW3 + if (header.Version == 0x08) { + file.seek(0x08); + } + + // Read info + in.readRawData(reinterpret_cast(&info), sizeof(IWIInfo)); + + // Determine offset array size + QVector offsets((header.Version == 0x1B) ? 8 : 4); + + if (header.Version == 0x0D || header.Version == 0x1B) { + file.seek(header.Version == 0x1B ? 0x20 : 0x10); + } + + // Read offsets + for (qint32 &offset : offsets) { + in >> offset; + } + + // Compute mipmaps + qint64 currentPos = file.pos(); + qint64 fileSize = file.size(); + QVector positions = QVector(); + + for (int i = 0; i < offsets.size(); i++) { + IWIMipmap m; + if (i == 0) { + m.offset = offsets[i]; + m.size = fileSize - offsets[i]; + } else if (i == offsets.size() - 1) { + m.offset = currentPos; + m.size = offsets[i] - currentPos; + } else { + m.offset = offsets[i]; + m.size = offsets[i - 1] - offsets[i]; + } + + quint64 pos = file.pos(); + + // Read mipmap + file.seek(m.offset); + m.data = file.read(m.size); + + file.seek(pos); + mipmaps.append(m); + } + + // Close file + file.close(); +} + +IWIFile::IWIFile(DDSFile &aDDSFile) { + // Ensure the DDS file has mipmaps + if (aDDSFile.mipmaps.isEmpty()) { + qDebug() << "Error: No mipmaps found in DDS file!"; + return; + } + + // Create IWIFile object + fileStem = aDDSFile.fileStem; + + // Set header (Magic & Version) + memcpy(header.Magic, "IWi", 3); + header.Version = 0x06; // Default to CoD4/CoD5 version + + // Set IWI Texture Info + info.Format = static_cast(aDDSFile.header.pixelFormat.format); + info.Width = aDDSFile.header.width; + info.Height = aDDSFile.header.height; + info.Depth = 1; // Default depth for 2D textures + info.Usage = 0; // No specific usage + + // Convert DDS mipmaps to IWI mipmaps + int offset = 28; // Standard offset start + for (const auto& ddsMipmap : aDDSFile.mipmaps) { + IWIMipmap iwiMipmap; + iwiMipmap.offset = offset; + iwiMipmap.size = ddsMipmap.data.size(); + iwiMipmap.data = ddsMipmap.data; + + offset += iwiMipmap.size; + mipmaps.append(iwiMipmap); + } +} + +IWIFile::IWIFile(const IWIFile &iwiFile) { + fileStem = iwiFile.fileStem; + header = iwiFile.header; + info = iwiFile.info; + mipmaps = iwiFile.mipmaps; +} + +IWIFile &IWIFile::operator=(const IWIFile &other) { + if (this != &other) { + fileStem = other.fileStem; + header = other.header; + info = other.info; + mipmaps = other.mipmaps; + } + return *this; +} + +IWIFile::~IWIFile() { + +} + +void IWIFile::SetupExportDirs() { + QDir dir = QDir::currentPath(); + if (!dir.exists("exports/")) { + dir.mkdir("exports/"); + } + + if (!dir.exists("exports/iwi/")) { + dir.mkdir("exports/iwi/"); + } + if (!dir.exists("exports/dds/")) { + dir.mkdir("exports/dds/"); + } + if (!dir.exists("exports/png/")) { + dir.mkdir("exports/png/"); + } + if (!dir.exists("exports/jpg/")) { + dir.mkdir("exports/jpg/"); + } +} + +bool IWIFile::SaveIWI() { + SetupExportDirs(); + QFile file("exports/iwi/" + fileStem + ".iwi"); + if (!file.open(QIODevice::WriteOnly)) { + qDebug() << "Error: Unable to write IWI file " << fileStem + ".iwi"; + return false; + } + + QDataStream out(&file); + out.setByteOrder(QDataStream::LittleEndian); + + // Write IWI Header + out.writeRawData(reinterpret_cast(&header), sizeof(IWIHeader)); + + // Adjust seek position for MW2/MW3 + if (header.Version == 0x08) { + file.seek(0x08); + } + + // Write IWI Texture Info + out.writeRawData(reinterpret_cast(&info), sizeof(IWIInfo)); + + // Determine number of mipmaps based on version + QVector offsets((header.Version == 0x1B) ? 8 : 4); + size_t currentOffset = file.pos() + (offsets.size() * sizeof(qint32)); + + // Compute offsets + for (int i = 0; i < offsets.size(); i++) { + offsets[i] = static_cast(currentOffset); + if (mipmaps.size() && i < mipmaps.size()) { + currentOffset += mipmaps[i].size; + } + } + + // Seek and write offsets + if (header.Version == 0x0D || header.Version == 0x1B) { + file.seek(header.Version == 0x1B ? 0x20 : 0x10); + } + + for (const qint32 &offset : offsets) { + out << offset; + } + + for (auto mipmap : mipmaps) { + file.seek(mipmap.offset); + file.write(mipmap.data); + } + + file.close(); + + qDebug() << "Successfully wrote IWI file: " << fileStem + ".iwi"; + return true; +} + +bool IWIFile::SaveDDS() { + SetupExportDirs(); + QFile file("exports/dds/" + fileStem + ".dds"); + if (!file.open(QIODevice::WriteOnly)) { + qDebug() << "Error: Unable to write DDS file " << fileStem + ".dds"; + return false; + } + + DDSHeader ddsHeader = {}; + ddsHeader.magic = 0x20534444; // 'DDS ' + ddsHeader.size = 124; + ddsHeader.flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_LINEARSIZE; + ddsHeader.height = info.Height; + ddsHeader.width = info.Width; + ddsHeader.depth = 0; + ddsHeader.mipMapCount = mipmaps.size(); + + DDSPixelFormat ddsPixelFormat = DDSFile::CalculatePixelFormat(info.Format); + if (ddsPixelFormat.flags & DDPF_FOURCC) { + ddsHeader.flags |= DDSD_LINEARSIZE; + } else { + ddsHeader.flags |= DDSD_PITCH; + } + ddsHeader.pixelFormat = ddsPixelFormat; + + // Calculate pitch/linear size + if (ddsPixelFormat.flags & DDPF_FOURCC) { + int blockSize = (ddsPixelFormat.format == 0x31545844) ? 8 : 16; + ddsHeader.pitchOrLinearSize = fmax(1, (ddsHeader.width + 3) / 4) * blockSize * (ddsHeader.height / 4); + } else { + ddsHeader.pitchOrLinearSize = ddsHeader.width * (ddsPixelFormat.rgbBitCount / 8); + } + + DDSCaps ddsCaps = {}; + ddsCaps.caps1 = DDSCAPS_TEXTURE; + ddsCaps.caps2 = 0; + ddsCaps.dDSX = 0; + ddsCaps.reserved = 0; + ddsHeader.caps = ddsCaps; + + QDataStream out(&file); + out.setByteOrder(QDataStream::LittleEndian); + + // Write DDS header + out.writeRawData(reinterpret_cast(&ddsHeader), sizeof(DDSHeader)); + + for (auto mipmap : mipmaps) { + if (!mipmap.data.size()) { continue; } + + // Write mipmap data + out.writeRawData(reinterpret_cast(mipmap.data.constData()), mipmap.data.size()); + } + file.close(); + + return true; +} + +bool IWIFile::SavePNG() { + DDSFile ddsFile(*this); + if (!ddsFile.SavePNG()) { + qDebug() << "Error: Failed to save PNG file: " << fileStem + ".png"; + return false; + } + return true; +} + +bool IWIFile::SaveJPG() { + DDSFile ddsFile(*this); + if (!ddsFile.SavePNG()) { + qDebug() << "Error: Failed to save JPG file: " << fileStem + ".jpg"; + return false; + } + return true; +} + +// Check if the IWI version is supported +bool IWIHeader::isSupported() const { + return (Magic[0] == 'I' && Magic[1] == 'W' && Magic[2] == 'i') && + supportedVersions.contains(Version); +} diff --git a/libs/iwifile/iwifile.h b/libs/iwifile/iwifile.h new file mode 100644 index 0000000..0af67bd --- /dev/null +++ b/libs/iwifile/iwifile.h @@ -0,0 +1,65 @@ +#ifndef IWIFILE_H +#define IWIFILE_H + +#include +#include +#include +#include +#include +#include +#include + +// Supported versions +static const QVector supportedVersions = { + 0x05, // CoD2 + 0x06, // CoD4, CoD5 + 0x08, // CoDMW2, CoDMW3 + 0x0D, // CoDBO1 + 0x1B // CoDBO2 +}; + +class DDSFile; + +struct IWIHeader { + char Magic[3]; + quint8 Version; + + bool isSupported() const; +}; + +struct IWIInfo { + quint8 Format; + quint8 Usage; + quint16 Width; + quint16 Height; + quint16 Depth; +}; + +struct IWIMipmap { + qint32 offset; + qint32 size; + QByteArray data; +}; + +class IWIFile { +public: + QString fileStem; + IWIHeader header; + IWIInfo info; + QVector mipmaps; + + IWIFile(); + IWIFile(const QString &aFilePath); + IWIFile(DDSFile &aDDSFile); + IWIFile(const IWIFile &iwiFile); + IWIFile& operator=(const IWIFile& other); + ~IWIFile(); + + bool SaveIWI(); + bool SaveDDS(); + bool SavePNG(); + bool SaveJPG(); + void SetupExportDirs(); +}; + +#endif // IWIFILE_H diff --git a/libs/iwifile/iwifile.pro b/libs/iwifile/iwifile.pro new file mode 100644 index 0000000..9c972c3 --- /dev/null +++ b/libs/iwifile/iwifile.pro @@ -0,0 +1,25 @@ +QT += core +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + iwifile.cpp + +HEADERS += \ + iwifile.h + +LIBS += \ + -L$$PWD/../../third_party/devil_sdk/lib/ -lDevIL \ + -L$$PWD/../../third_party/devil_sdk/lib/ -lILU \ + -L$$PWD/../../third_party/devil_sdk/lib/ -lILUT \ + -L$$OUT_PWD/../libs/ddsfile -lddsfile + +INCLUDEPATH += \ + $$PWD/../../third_party/devil_sdk/include/ \ + $$PWD/../ddsfile + +DEPENDPATH += \ + $$PWD/../../third_party/devil_sdk/include/ \ + $$PWD/../ddsfile + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/libs.pro b/libs/libs.pro new file mode 100644 index 0000000..65de95e --- /dev/null +++ b/libs/libs.pro @@ -0,0 +1,10 @@ +TEMPLATE = subdirs + +SUBDIRS += core \ + compression \ + encryption \ + fastfile \ + zonefile \ + ddsfile \ + iwifile \ + ipakfile diff --git a/libs/zonefile/asset_structs.h b/libs/zonefile/asset_structs.h new file mode 100644 index 0000000..1ed6c16 --- /dev/null +++ b/libs/zonefile/asset_structs.h @@ -0,0 +1,377 @@ +#ifndef ASSET_STRUCTS_H +#define ASSET_STRUCTS_H + +#include "enums.h" + +#include +#include +#include +#include + +struct LocalString { + QString string; + QString alias; +}; + +struct RawFile { + quint32 length; + QString path; + QString contents; +}; + +struct TechSet { + QString name; + bool hasShaders = false; + QVector pointers; +}; + +struct Shader { + quint32 shaderPtr; +}; + +struct XModelCollSurf_s +{ + float mins[3]; + float maxs[3]; + int boneIdx; + int contents; + int surfFlags; +}; + +struct XModelLodInfo +{ + float dist; + unsigned short numsurfs; + unsigned short surfIndex; + int partBits[5]; +}; + +struct XModelHighMipBounds +{ + float mins[3]; + float maxs[3]; +}; + +struct XModelStreamInfo +{ + XModelHighMipBounds *highMipBounds; +}; + +struct XBoneInfo +{ + float bounds[2][3]; + float offset[3]; + float radiusSquared; +}; + +struct Model { + quint32 namePtr; + quint8 tagCount; + quint8 rootTagCount; + quint8 surfCount; + quint8 unknownCount; + quint32 boneNamePtr; + quint32 parentListPtr; + quint32 quatsPtr; + quint32 transPtr; + quint32 partClassPtr; + quint32 baseMatPtr; + quint32 surfsPtr; + quint32 materialHandlesPtr; + + XModelLodInfo lodInfo[4]; + quint32 collSurfsPtr; + int numCollSurfs; + int contents; + quint32 boneInfoPtr; + float radius; + float mins[3]; + float maxs[3]; + short numLods; + short collLod; + quint32 streamInfoPtr; // is not loaded on ps3 + int memUsage; + char flags; + quint32 physPresetPtr; + quint32 physGeomsPtr; + + QString modelName; +}; + +struct Animation { + quint16 dataByteCount; + quint16 dataShortCount; + quint16 dataIntCount; + quint16 randomDataByteCount; + quint16 randomDataIntCount; + quint16 numframes; + bool isLooped; + bool isDelta; + quint8 noneRotatedBoneCount; + quint8 twoDRotatedBoneCount; + quint8 normalRotatedBoneCount; + quint8 twoDStaticRotatedBoneCount; + quint8 normalStaticRotatedBoneCount; + quint8 normalTranslatedBoneCount; + quint8 preciseTranslatedBoneCount; + quint8 staticTranslatedBoneCount; + quint8 noneTranslatedBoneCount; + quint8 totalBoneCount; + quint8 otherBoneCount1; + quint8 otherBoneCount2; + quint8 notifyCount; + quint8 assetType; + bool pad; + unsigned int randomDataShortCount; + unsigned int indexCount; + float frameRate; + float frequency; + quint32 boneIDsPtr; + quint32 dataBytePtr; + quint32 dataShortPtr; + quint32 dataIntPtr; + quint32 randomDataShortPtr; + quint32 randomDataBytePtr; + quint32 randomDataIntPtr; + quint32 longIndiciesPtr; + quint32 notificationsPtr; + quint32 deltaPartsPtr; + QString name; +}; + +struct StringTable { + quint32 columnCount; + quint32 rowCount; + QString name; + QVector tablePointers; + QMap content; +}; + +struct Image { + QString name; + QString materialName; + quint32 size1; + quint32 size2; + IMAGE_COMPRESSION compression; + quint32 unknowna; + quint32 unknownb; + quint32 unknownc; + quint32 unknownd; + quint32 unknowne; + quint32 unknownf; + quint32 unknowng; + quint32 unknownh; + quint32 unknowni; + quint32 unknownj; + quint32 unknownk; + quint32 unknownl; + quint32 unknownm; + quint32 unknown1; + quint32 unknown2; + quint32 unknown3; + quint32 unknown4; + quint32 unknown5; + quint32 unknown6; + quint32 unknown7; + quint32 unknown8; + quint32 unknown9; +}; + +struct Material { + quint32 namePtr; + QString name; + quint32 refNamePtr; + QString refName; + quint8 unknownA[12]; + quint32 stateBits[2]; + quint16 textureCount; + quint16 constCount; + quint32 techSetPtr; + quint32 texturePtr; + quint32 constPtr; +}; + +struct Menu { + QString filePath; + QString name; + QString definition; + quint32 menuNamePtr; + QRectF rect; + MENU_H_ALIGNMENT hAlign; + MENU_V_ALIGNMENT vAlign; + QRectF clientRect; + MENU_H_ALIGNMENT hClientAlign; + MENU_V_ALIGNMENT vClientAlign; + quint32 groupPtr; + MENU_WINDOW_STYLE style; + MENU_WINDOW_BORDER border; + quint32 ownerDraw; + quint32 ownerDrawFlags; + float borderSize; + int staticFlags; + float dynamicFlags; + float nextTime; + QColor foregroundColor; + QColor backgroundColor; + QColor borderColor; + QColor outlineColor; + quint32 materialPtr; + quint32 fontPtr; + quint32 fullScreen; + quint32 itemCount; + quint32 fontIndex; + quint32 cursorItem; + quint32 fadeCycle; + float fadeClamp; + float fadeAmount; + float fadeInAmount; + float blurRadius; + quint32 onOpenPtr; + quint32 onFocusPtr; + quint32 onClosePtr; + quint32 onESCPtr; + quint32 onKeyPtr; + quint32 visibleExpCount; + quint32 expEntryPtr; + quint32 allowedBindingPtr; + quint32 soundNamePtr; + quint32 imageTrack; + QColor focusColor; + QColor disabledColor; + quint32 rectXExpCount; + quint32 rectXExpPtr; + quint32 rectYExpCount; + quint32 rectYExpPtr; + quint32 itemWindowDefNamePtr; + QRectF itemRect; + MENU_H_ALIGNMENT itemHAlignment; + MENU_V_ALIGNMENT itemVAlignment; + quint32 itemGroupPtr; + MENU_WINDOW_STYLE itemWindowStyle; + MENU_WINDOW_BORDER itemWindowBorder; + quint32 itemOwnerDraw; + quint32 itemOwnerDrawFlags; + float itemBorderSize; + int itemStaticFlags; + int itemDynamicFlags; + int itemNextTime; + QColor itemForegroundColor; + QColor itemBackgroundColor; + QColor itemBorderColor; + QColor itemOutlineColor; + quint32 itemMaterialPtr; + QRectF itemTextRect; + MENU_H_ALIGNMENT itemText_hAlign; + MENU_V_ALIGNMENT itemText_vAlign; + MENU_ITEM_TYPE itemType; + quint32 dataType; + quint32 alignment; + MENU_FONT_TYPE fontEnum; + quint32 textAlignMode; + float textalignx; + float textaligny; + float textscale; + MENU_ITEM_TEXTSTYLE textStyle; + int gameMsgWindowIndex; + int gameMsgWindowMode; + quint32 testPtr; + quint32 textSavegameInfo; + quint32 parentPtr; + quint32 mouseEnterText; + quint32 mouseExitText; + quint32 mouseEnter; + quint32 mouseExit; + quint32 action; + quint32 onAccept; + quint32 onFocus; + quint32 leaveFocus; + quint32 dvar; + quint32 dvarTest; + quint32 keyHandlerPtr; + quint32 enableDvarPtr; + quint32 dvarFlags; + quint32 focusSoundPtr; + float special; + quint32 cursorPos; + // itemDefData_t typeData; + // listBoxDef_s *listBox; + quint32 startPos; + quint32 endPos; + quint32 drawPadding; + float elementWidth, elementHeight; + quint32 elementStyle, numColumns; + //columnInfo_s columnInfo[16]; + quint32 doubleClickPtr; + int notselectable; + int noScrollBars; + int usePaging; + QColor itemSelectBorderColor; + QColor itemDisableColor; + QColor itemFocusColor; + quint32 selectIconPtr; + quint32 backgroundItemListboxPtr; + quint32 highlightTexturePtr; + // editFieldDef_s *editField; + float minVal; + float maxVal; + float defVal; + float range; + int maxChars; + int maxCharsGotoNext; + int maxPaintChars; + int paintOffset; + // multiDef_s *multi; + QVector dvarListPtrs; + QVector dvarStrPtrs; + QVector dvarValues; + quint32 count; + quint32 strDef; + quint32 enumDvarNamePtr; + quint32 dataPtr; + quint32 itemImageTrack; +}; + +struct MenuFile { + quint32 menuCount; + QVector menuDefs; +}; + +struct Sound { + QString path; + QString alias; + quint32 dataPtr; + quint32 dataLength; + QByteArray data; +}; + +struct SoundAsset { + QString name; + quint32 count; + QVector sounds; +}; + +struct AssetMap { + QVector localStrings; + QVector rawFiles; + //QVector phyPresets; + QVector models; + QVector materials; + //QVector shaders; + QVector techSets; + QVector images; + QVector sounds; + //QVector collMaps; + //QVector lightDefs; + //QVector uiMaps; + //QVector driverGlobals; + //QVector aiType; + //QVector effects; + QVector animations; + QVector stringTables; + QVector menuFiles; + //QVector weapons; + //QVector d3dbspDumps; + //QVector spMaps; +}; + +#endif // ASSET_STRUCTS_H diff --git a/libs/zonefile/zonefile.cpp b/libs/zonefile/zonefile.cpp new file mode 100644 index 0000000..ac9aae8 --- /dev/null +++ b/libs/zonefile/zonefile.cpp @@ -0,0 +1,161 @@ +#include "zonefile.h" +#include "utils.h" +#include "logmanager.h" + +#include +#include +#include + +ZoneFile::ZoneFile() : + mStem(), + mSize(), + mTagCount(), + mTags(), + mRecordCount(), + mRecords(), + mAssetMap() { + +} + +ZoneFile::~ZoneFile() { + +} + +ZoneFile::ZoneFile(const ZoneFile &aZoneFile) { + mStem = aZoneFile.mStem; + mSize = aZoneFile.mSize; + mTagCount = aZoneFile.mTagCount; + mTags = aZoneFile.mTags; + mRecordCount = aZoneFile.mRecordCount; + mRecords = aZoneFile.mRecords; + mAssetMap = aZoneFile.mAssetMap; +} + +ZoneFile &ZoneFile::operator=(const ZoneFile &other) { + if (this != &other) { + mStem = other.mStem; + mSize = other.mSize; + mTagCount = other.mTagCount; + mTags = other.mTags; + mRecordCount = other.mRecordCount; + mRecords = other.mRecords; + mAssetMap = other.mAssetMap; + } + return *this; +} + +QIcon ZoneFile::AssetStrToIcon(const QString aAssetStr) { + const QString cleanedType = aAssetStr.toUpper(); + if (cleanedType == "LOCAL STRING") { // localized string PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_StringFile.png"); + } else if (cleanedType == "RAW FILE") { // raw_file PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_RawFile.png"); + } else if (cleanedType == "GSC FILE") { // raw_file PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_GSCFile.png"); + } else if (cleanedType == "EFFECT") { // fx PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Effect.png"); + } else if (cleanedType == "SOUND") { // loaded_sound PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Sound.png"); + } else if (cleanedType == "ANIMATION") { // x_anim PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Animation.png"); + } else if (cleanedType == "COLLISION MAP") { // collision_map PARTIALLY VERIFIED + //return "COLLISION MAP"; + } else if (cleanedType == "STRING TABLE") { // string_table PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_StringTable.png"); + } else if (cleanedType == "MENU") { // menu_file PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_MenuFile.png"); + } else if (cleanedType == "TECH SET") { // tech set PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_TechSetFile.png"); + } else if (cleanedType == "WEAPON") { // weapon PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Weapon.png"); + } else if (cleanedType == "GFX MAP") { // gfx map PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_FXMap.png"); + } else if (cleanedType == "LIGHT DEF") { // light_def PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_LightDef.png"); + } else if (cleanedType == "FONT") { // font PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Font.png"); + } else if (cleanedType == "MODEL") { // xmodel PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Model.png"); + } else if (cleanedType == "D3DBSP") { // d3dbsp PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_BSP.png"); + } else if (cleanedType == "IMAGE") { // image PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Image.png"); + } else if (cleanedType == "GAME MAP SP") { // game map sp PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_GameMapSp.png"); + } else if (cleanedType == "COL MAP SP") { // col map sp PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_ColMapSp.png"); + } else if (cleanedType == "PHYS PRESET") { // col map sp PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_PhysPreset.png"); + } else if (cleanedType == "DESTRUCTIBLE") { // col map sp PARTIALLY VERIFIED + return QIcon(":/icons/icons/Icon_Destructible.png"); + } + return QIcon(); +} + +bool ZoneFile::SaveZoneFile(const QString aZoneFilePath) { + QFile zoneFile(aZoneFilePath); + if (!zoneFile.open(QIODevice::WriteOnly)) { + LogManager::instance().addEntry("Failed to write zone file! " + zoneFile.errorString()); + return false; + } + zoneFile.write(GetBinaryData()); + zoneFile.close(); + return true; +} + +QString ZoneFile::GetStem() { + return mStem; +} + +quint32 ZoneFile::GetSize() { + return mSize; +} + +quint32 ZoneFile::GetTagCount() { + return mTagCount; +} + +QStringList ZoneFile::GetTags() { + return mTags; +} + +quint32 ZoneFile::GetRecordCount() { + return mRecordCount; +} + +QStringList ZoneFile::GetRecords() { + return mRecords; +} + +AssetMap ZoneFile::GetAssetMap() { + return mAssetMap; +} + +void ZoneFile::SetStem(const QString aStem) { + mStem = aStem; +} + +void ZoneFile::SetSize(quint32 aSize) { + mSize = aSize; +} + +void ZoneFile::SetTagCount(quint32 aTagCount) { + mTagCount = aTagCount; +} + +void ZoneFile::SetTags(const QStringList aTags) { + mTags = aTags; +} + +void ZoneFile::SetRecordCount(quint32 aRecordCount) { + mRecordCount = aRecordCount; +} + +void ZoneFile::SetRecords(const QStringList aRecords) { + mRecords = aRecords; +} + +void ZoneFile::SetAssetMap(const AssetMap aAssetMap) { + mAssetMap = aAssetMap; +} + diff --git a/libs/zonefile/zonefile.h b/libs/zonefile/zonefile.h new file mode 100644 index 0000000..1e08020 --- /dev/null +++ b/libs/zonefile/zonefile.h @@ -0,0 +1,87 @@ +#ifndef ZONEFILE_H +#define ZONEFILE_H + +#include "asset_structs.h" +#include "qicon.h" + +#include + +class ZoneFile +{ +public: + ZoneFile(); + ~ZoneFile(); + ZoneFile(const ZoneFile &aZoneFile); + ZoneFile &operator=(const ZoneFile &other); + + virtual bool Load(const QByteArray aFileData, FF_PLATFORM platform = FF_PLATFORM_NONE) = 0; + virtual QString AssetTypeToString(const QString aAssetType) = 0; + + QIcon AssetStrToIcon(const QString aAssetStr); + + virtual QByteArray GetBinaryData() = 0; + virtual bool SaveZoneFile(const QString aZoneFilePath); + + QString GetStem(); + quint32 GetSize(); + quint32 GetTagCount(); + QStringList GetTags(); + quint32 GetRecordCount(); + QStringList GetRecords(); + AssetMap GetAssetMap(); + + void SetStem(const QString aStem); + void SetSize(quint32 aSize); + void SetTagCount(quint32 aTagCount); + void SetTags(const QStringList aTags); + void SetRecordCount(quint32 aRecordCount); + void SetRecords(const QStringList aRecords); + void SetAssetMap(const AssetMap aAssetMap); + +private slots: + virtual void pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) = 0; + virtual quint32 pParseZoneSize(QDataStream *aZoneFileStream) = 0; + virtual void pParseZoneUnknownsA(QDataStream *aZoneFileStream) = 0; + virtual quint32 pParseZoneTagCount(QDataStream *aZoneFileStream) = 0; + virtual quint32 pParseZoneRecordCount(QDataStream *aZoneFileStream) = 0; + virtual void pParseZoneUnknownsB(QDataStream *aZoneFileStream) = 0; + virtual void pParseZoneUnknownsC(QDataStream *aZoneFileStream) = 0; + virtual QStringList pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) = 0; + virtual QStringList pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) = 0; + virtual AssetMap pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) = 0; + virtual LocalString pParseAsset_LocalString(QDataStream *aZoneFileStream) = 0; + virtual RawFile pParseAsset_RawFile(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_PhysPreset(QDataStream *aZoneFileStream) = 0; + virtual Model pParseAsset_Model(QDataStream *aZoneFileStream) = 0; + virtual Material pParseAsset_Material(QDataStream *aZoneFileStream) = 0; + virtual Shader pParseAsset_Shader(QDataStream *aZoneFileStream) = 0; + virtual TechSet pParseAsset_TechSet(QDataStream *aZoneFileStream) = 0; + virtual Image pParseAsset_Image(QDataStream *aZoneFileStream) = 0; + virtual SoundAsset pParseAsset_Sound(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_ColMapMP(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_GameMapSP(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_GameMapMP(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_LightDef(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_UIMap(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_AIType(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_FX(QDataStream *aZoneFileStream) = 0; + virtual Animation pParseAsset_Animation(QDataStream *aZoneFileStream) = 0; + virtual MenuFile pParseAsset_MenuFile(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_Weapon(QDataStream *aZoneFileStream) = 0; + virtual void pParseAsset_D3DBSP(QDataStream *aZoneFileStream) = 0; + virtual StringTable pParseAsset_StringTable(QDataStream *aZoneFileStream) = 0; + +private: + QString mStem; + quint32 mSize; + quint32 mTagCount; + QStringList mTags; + quint32 mRecordCount; + QStringList mRecords; + AssetMap mAssetMap; + QString mPlatform; + QString mGame; +}; + +#endif // ZONEFILE_H diff --git a/libs/zonefile/zonefile.pro b/libs/zonefile/zonefile.pro new file mode 100644 index 0000000..ec85195 --- /dev/null +++ b/libs/zonefile/zonefile.pro @@ -0,0 +1,29 @@ +QT += core widgets +TEMPLATE = lib +CONFIG += staticlib c++17 + +SOURCES += \ + zonefile.cpp \ + zonefile_cod2.cpp \ + zonefile_cod5.cpp \ + zonefile_cod7.cpp \ + zonefile_cod9.cpp + +HEADERS += \ + asset_structs.h \ + zonefile.h \ + zonefile_cod2.h \ + zonefile_cod5.h \ + zonefile_cod7.h \ + zonefile_cod9.h + +LIBS += \ + -L$$OUT_PWD/../libs/core -lcore + +INCLUDEPATH += \ + $$PWD/../core + +DEPENDPATH += \ + $$PWD/../core + +DESTDIR = $$OUT_PWD/../ diff --git a/libs/zonefile/zonefile_cod2.cpp b/libs/zonefile/zonefile_cod2.cpp new file mode 100644 index 0000000..3e49715 --- /dev/null +++ b/libs/zonefile/zonefile_cod2.cpp @@ -0,0 +1,1093 @@ +#include "zonefile_cod2.h" + +#include +#include +#include + +ZoneFile_COD2::ZoneFile_COD2() +{ + +} + +ZoneFile_COD2::~ZoneFile_COD2() +{ + +} + +bool ZoneFile_COD2::Load(const QByteArray aFileData, FF_PLATFORM aPlatform) { + // Open zone file as little endian stream + QDataStream zoneFileStream(aFileData); + if (aPlatform == FF_PLATFORM_PC) { + zoneFileStream.setByteOrder(QDataStream::LittleEndian); + } else { + zoneFileStream.setByteOrder(QDataStream::BigEndian); + } + + // Parse data from zone file header + pParseZoneHeader(&zoneFileStream, aPlatform); + SetRecords(pParseZoneIndex(&zoneFileStream, GetRecordCount())); + SetAssetMap(pParseAssets(&zoneFileStream, GetRecords())); + + return true; +} + +void ZoneFile_COD2::pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) { + Q_UNUSED(aPlatform); + + SetTagCount(pParseZoneTagCount(aZoneFileStream)); + pParseZoneUnknownsB(aZoneFileStream); + pParseZoneUnknownsC(aZoneFileStream); + SetRecordCount(pParseZoneRecordCount(aZoneFileStream)); + + aZoneFileStream->skipRawData(4); + + quint32 tagCount = GetTagCount(); + if (tagCount) { + SetTags(pParseZoneTags(aZoneFileStream, tagCount)); + } else { + aZoneFileStream->skipRawData(4); + } +} + +quint32 ZoneFile_COD2::pParseZoneSize(QDataStream *aZoneFileStream) { + quint32 zoneFileSize; + *aZoneFileStream >> zoneFileSize; + if (zoneFileSize <= 0) { + qDebug() << "Tried to open empty zone file!"; + exit(-1); + } + zoneFileSize += 36; + return zoneFileSize; +} + +/* + ParseZoneUnknownsA() + + Parses the 1st section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD2::pParseZoneUnknownsA(QDataStream *aZoneFileStream) { + // Byte 4-7, 8-11, 12-15: unknown + QByteArray unknown1(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown1.data(), 4); + + QByteArray unknown2(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown2.data(), 4); + + QByteArray unknown3(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown3.data(), 4); + + // Byte 16-19, 20-23: empty/unknown + QByteArray unknown4(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown4.data(), 4); + + QByteArray unknown5(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown5.data(), 4); + + // Byte 24-27: somehow related to the filesize, but smaller value + QByteArray unknown6(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown6.data(), 4); + + // Byte 28-31, 32-35: unknown + QByteArray unknown7(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown7.data(), 4); + + QByteArray unknown8(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown8.data(), 4); +} + +/* + ParseZoneTagCount() + + Parses the number of string tags in the zone index +*/ +quint32 ZoneFile_COD2::pParseZoneTagCount(QDataStream *aZoneFileStream) { + quint32 tagCount; + *aZoneFileStream >> tagCount; + return tagCount; +} + +/* + ParseZoneRecordCount() + + Parses the number of records in the zone index +*/ +quint32 ZoneFile_COD2::pParseZoneRecordCount(QDataStream *aZoneFileStream) { + quint32 recordCount; + *aZoneFileStream >> recordCount; + return recordCount; +} + +/* + ParseZoneUnknownsB() + + Parses the 2nd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD2::pParseZoneUnknownsB(QDataStream *aZoneFileStream) { + // Byte 44-47: Unknown/empty? + QByteArray unknown9(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown9.data(), 4); +} + +/* + pParseZoneUnknownsC() + + Parses the 3rd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD2::pParseZoneUnknownsC(QDataStream *aZoneFileStream) { + // Byte 40-43: Unknown/empty? + QByteArray unknown10(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown10.data(), 4); + + // Byte 44-47: Unknown/empty? + QByteArray unknown11(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown11.data(), 4); +} + +/* + ParseZoneTags() + + Parses the string tags ate the start of zone file +*/ +QStringList ZoneFile_COD2::pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) { + QStringList tags; + + // Byte 48-51: Repeated separators? ÿÿÿÿ x i + aZoneFileStream->skipRawData(4 * tagCount); + + // Parse tags/strings before index + QString zoneTag; + char zoneTagChar; + for (quint32 i = 0; i < tagCount; i++) { + *aZoneFileStream >> zoneTagChar; + while (zoneTagChar != 0) { + zoneTag += zoneTagChar; + *aZoneFileStream >> zoneTagChar; + } + tags << zoneTag; + zoneTag.clear(); + } + return tags; +} + +/* + ParseZoneIndex() + + Parse the binary zone index data and populate table +*/ +QStringList ZoneFile_COD2::pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) { + QStringList result; + + // Don't parse if no records + if (!recordCount) { return result; } + + // Parse index & map found asset types + for (quint32 i = 0; i < recordCount; i++) { + // Skip record start + QByteArray rawAssetType(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rawAssetType.data(), 4); + result << rawAssetType.toHex(); + + // Skip separator + aZoneFileStream->skipRawData(4); + } + return result; +} + +AssetMap ZoneFile_COD2::pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) { + AssetMap result; + + //aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 8); + + for (int i = 0; i < assetOrder.size(); i++) { + const QString typeHex = assetOrder[i]; + const QString typeStr = AssetTypeToString(typeHex); + + if (typeStr == "LOCAL STRING") { // localized string asset + result.localStrings << pParseAsset_LocalString(aZoneFileStream); + } else if (typeStr == "RAW FILE") { // gsc + auto rawFile = pParseAsset_RawFile(aZoneFileStream); + if (rawFile.length) { + result.rawFiles << rawFile; + } + } else if (typeStr == "PHYS PRESET") { // physpreset + pParseAsset_PhysPreset(aZoneFileStream); + } else if (typeStr == "MODEL") { // xmodel + result.models << pParseAsset_Model(aZoneFileStream); + } else if (typeStr == "MATERIAL") { // material + result.materials << pParseAsset_Material(aZoneFileStream); + } else if (typeStr == "SHADER") { // pixelshader + pParseAsset_Shader(aZoneFileStream); + } else if (typeStr == "TECH SET") { // techset include + result.techSets << pParseAsset_TechSet(aZoneFileStream); + } else if (typeStr == "IMAGE") { // image + result.images << pParseAsset_Image(aZoneFileStream); + } else if (typeStr == "SOUND") { // loaded_sound + result.sounds << pParseAsset_Sound(aZoneFileStream); + } else if (typeStr == "COLLISION MAP") { // col_map_mp + pParseAsset_ColMapMP(aZoneFileStream); + } else if (typeStr == "MP MAP") { // game_map_sp + pParseAsset_GameMapSP(aZoneFileStream); + } else if (typeStr == "SP MAP") { // game_map_mp + pParseAsset_GameMapMP(aZoneFileStream); + } else if (typeStr == "LIGHT DEF") { // lightdef + pParseAsset_LightDef(aZoneFileStream); + } else if (typeStr == "UI MAP") { // ui_map + pParseAsset_UIMap(aZoneFileStream); + } else if (typeStr == "SND DRIVER GLOBALS") { // snddriverglobals + pParseAsset_SNDDriverGlobals(aZoneFileStream); + } else if (typeStr == "AI TYPE") { // aitype + pParseAsset_AIType(aZoneFileStream); + } else if (typeStr == "EFFECT") { // aitype + pParseAsset_FX(aZoneFileStream); + } else if (typeStr == "ANIMATION") { // aitype + result.animations << pParseAsset_Animation(aZoneFileStream); + } else if (typeStr == "STRING TABLE") { // string_table + result.stringTables << pParseAsset_StringTable(aZoneFileStream); + } else if (typeStr == "MENU") { // string_table + result.menuFiles << pParseAsset_MenuFile(aZoneFileStream); + } else if (typeStr == "WEAPON") { // string_table + pParseAsset_Weapon(aZoneFileStream); + } else if (typeStr == "D3DBSP DUMP") { // string_table + pParseAsset_D3DBSP(aZoneFileStream); + } else if (typeStr != "UNKNOWN") { + qDebug() << "Found bad asset type!" << typeStr; + } + } + return result; +} + +LocalString ZoneFile_COD2::pParseAsset_LocalString(QDataStream *aZoneFileStream) { + LocalString result; + + quint32 stringPtr, aliasPtr; + *aZoneFileStream >> stringPtr >> aliasPtr; + if (stringPtr == 4294967295) { + // Parse local string asset contents + QString localStr; + char localStrChar; + *aZoneFileStream >> localStrChar; + while (localStrChar != 0) { + result.string += localStrChar; + *aZoneFileStream >> localStrChar; + } + } else { + result.string = "String Ptr: " + QString::number(stringPtr); + } + + if (aliasPtr == 4294967295) { + // Parse rawfile name + QString aliasName; + char aliasNameChar; + *aZoneFileStream >> aliasNameChar; + while (aliasNameChar != 0) { + result.alias += aliasNameChar; + *aZoneFileStream >> aliasNameChar; + } + } else { + result.string = "Alias Ptr: " + QString::number(aliasPtr); + } + + return result; +} + +RawFile ZoneFile_COD2::pParseAsset_RawFile(QDataStream *aZoneFileStream) { + RawFile result; + + // Skip start separator FF FF FF FF (pointer?) + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.length; + + // Skip unknown 4 byte data + aZoneFileStream->skipRawData(4); + + // Parse rawfile path + char scriptPathChar; + *aZoneFileStream >> scriptPathChar; + while (scriptPathChar != 0) { + result.path += scriptPathChar; + *aZoneFileStream >> scriptPathChar; + } + result.path.replace(",", ""); + const QStringList pathParts = result.path.split('/'); + if (pathParts.size() == 0) { + qDebug() << "Failed to parse ff path! " << result.path; + exit(-1); + } + + // Parse gsc contents + char rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + while (rawFileContentsChar != 0 && rawFileContentsChar != -1) { + result.contents += rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + } + return result; +} + +void ZoneFile_COD2::pParseAsset_PhysPreset(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Model ZoneFile_COD2::pParseAsset_Model(QDataStream *aZoneFileStream) { + Model result; + + qDebug() << "Model Info:"; + + *aZoneFileStream >> result.namePtr >> result.tagCount >> result.rootTagCount + >> result.surfCount >> result.unknownCount >> result.boneNamePtr + >> result.parentListPtr >> result.quatsPtr >> result.transPtr + >> result.partClassPtr >> result.baseMatPtr + >> result.surfsPtr >> result.materialHandlesPtr; + + // Parse XModelLodInfo + for (int i = 1; i <= 4; i++) { + qDebug() << "- Lod Info " << i; + + quint32 intDist; + *aZoneFileStream >> intDist; + + std::memcpy(&result.lodInfo[i].dist, &intDist, sizeof(result.lodInfo[i].dist)); + *aZoneFileStream >> result.lodInfo[i].numsurfs >> result.lodInfo[i].surfIndex; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.lodInfo[i].partBits[0] + >> result.lodInfo[i].partBits[1] + >> result.lodInfo[i].partBits[2] + >> result.lodInfo[i].partBits[3]; + } + + *aZoneFileStream >> result.collSurfsPtr >> result.numCollSurfs >> result.contents >> result.boneInfoPtr; + + quint32 intRadius, intMins[3], intMaxs[3]; + *aZoneFileStream >> intRadius >> intMins[0] >> intMins[1] + >> intMins[2] >> intMaxs[0] >> intMaxs[1] >> intMaxs[2]; + + std::memcpy(&result.radius, &intRadius, sizeof(result.radius)); + + std::memcpy(&result.mins[0], &intMins[0], sizeof(result.mins[0])); + std::memcpy(&result.mins[1], &intMins[1], sizeof(result.mins[1])); + std::memcpy(&result.mins[2], &intMins[2], sizeof(result.mins[2])); + + std::memcpy(&result.maxs[0], &intMaxs[0], sizeof(result.maxs[0])); + std::memcpy(&result.maxs[1], &intMaxs[1], sizeof(result.maxs[2])); + std::memcpy(&result.maxs[2], &intMaxs[2], sizeof(result.maxs[3])); + + *aZoneFileStream >> result.numLods >> result.collLod >> result.streamInfoPtr + >> result.memUsage >> result.flags >> result.physPresetPtr >> result.physGeomsPtr; + + // Parse model name + char modelNameChar; + *aZoneFileStream >> modelNameChar; + while (modelNameChar == 0) { + *aZoneFileStream >> modelNameChar; + } + while (modelNameChar != 0) { + result.modelName += modelNameChar; + *aZoneFileStream >> modelNameChar; + } + return result; +} + +Shader ZoneFile_COD2::pParseAsset_Shader(QDataStream *aZoneFileStream) { + Shader result = Shader(); + + quint8 minorVersion, majorVersion; + *aZoneFileStream >> minorVersion >> majorVersion; + + quint32 magic; + *aZoneFileStream >> magic; + + // Verify .fxc magic + if (magic != 65534 && magic != 65535) { return result; } + + SHADER_TYPE type = SHADER_NONE; + quint16 rawShaderType; + *aZoneFileStream >> rawShaderType; + if (rawShaderType == 65535) { // Pixel shader + type = SHADER_PIXEL; + } else if (rawShaderType == 65534) { // Vertex shader + type = SHADER_VERTEX; + } + Q_UNUSED(type); + + while (true) { + quint32 instructionToken; + *aZoneFileStream >> instructionToken; + + SHADER_OPCODE opCode = (SHADER_OPCODE)(instructionToken & 0xffff); + + int size; + if (opCode == OPCODE_End) { + break; + } else if (opCode == OPCODE_Comment) { + size = (int)((instructionToken >> 16) & 0x7FFF); + } else { + size = (int)((instructionToken >> 24) & 0x0f); + } + Q_UNUSED(size); + } + + + return result; +} + +TechSet ZoneFile_COD2::pParseAsset_TechSet(QDataStream *aZoneFileStream) { + TechSet result; + + for (int i = 1; i <= 62; i++) { + quint32 ptr; + *aZoneFileStream >> ptr; + + result.pointers << ptr; + } + qDebug() << aZoneFileStream->device()->pos(); + + // Parse techset name + char techSetNameChar; + *aZoneFileStream >> techSetNameChar; + while (techSetNameChar != 0) { + result.name += techSetNameChar; + *aZoneFileStream >> techSetNameChar; + } + result.name.replace(",", ""); + + return result; +} + +Image ZoneFile_COD2::pParseAsset_Image(QDataStream *aZoneFileStream) { + Image result; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknowna >> result.unknownb + >> result.unknownc >> result.unknownd + >> result.unknowne >> result.unknownf + >> result.unknowng; + + aZoneFileStream->skipRawData(15 * 4); + *aZoneFileStream >> result.unknownh >> result.unknowni; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknownj; + + aZoneFileStream->skipRawData(4); + + char materialNameChar; + *aZoneFileStream >> materialNameChar; + while (materialNameChar != 0) { + result.materialName += materialNameChar; + *aZoneFileStream >> materialNameChar; + } + result.materialName.replace(",", ""); + + if (result.unknowna) { + *aZoneFileStream >> result.unknownk; + *aZoneFileStream >> result.unknownl; + *aZoneFileStream >> result.unknownm; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown1; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown2 >> result.unknown3 + >> result.size1 >> result.size2 + >> result.unknown4 >> result.unknown5; + + aZoneFileStream->skipRawData(4); + + char imageNameChar; + *aZoneFileStream >> imageNameChar; + while (imageNameChar != 0) { + result.name += imageNameChar; + *aZoneFileStream >> imageNameChar; + } + + *aZoneFileStream >> result.unknown6 >> result.unknown7; + + QByteArray compressionData(8, Qt::Uninitialized); + aZoneFileStream->readRawData(compressionData.data(), 8); + if (compressionData.contains("DXT1")) { + result.compression = COMPRESSION_DXT1; + } else if (compressionData.contains("DXT3")) { + result.compression = COMPRESSION_DXT3; + } else if (compressionData.contains("DXT5")) { + result.compression = COMPRESSION_DXT5; + } else { + result.compression = COMPRESSION_NONE; + } + + *aZoneFileStream >> result.unknown8 >> result.unknown9; + } + + return result; +} + +Material ZoneFile_COD2::pParseAsset_Material(QDataStream *aZoneFileStream) { + Material result; + + *aZoneFileStream >> result.namePtr; + if (result.namePtr != 4294967295 && GetTagCount() > result.namePtr - 1) { + result.name = GetTags()[result.namePtr - 1]; + } + *aZoneFileStream >> result.refNamePtr; + if (result.refNamePtr != 4294967295 && GetTagCount() > result.refNamePtr - 1) { + result.refName = GetTags()[result.refNamePtr - 1]; + } + aZoneFileStream->skipRawData(12); + + *aZoneFileStream >> result.unknownA[0] >> result.unknownA[0] + >> result.unknownA[1] >> result.unknownA[2] >> result.unknownA[3] + >> result.unknownA[4] >> result.unknownA[5] >> result.unknownA[6] + >> result.unknownA[7] >> result.unknownA[8] >> result.unknownA[9] + >> result.unknownA[10] >> result.unknownA[11]; + + *aZoneFileStream >> result.stateBits[0] >> result.stateBits[1] + >> result.textureCount >> result.constCount >> result.techSetPtr + >> result.texturePtr >> result.constPtr; + + + return result; +} + +SoundAsset ZoneFile_COD2::pParseAsset_Sound(QDataStream *aZoneFileStream) { + SoundAsset result; + + qDebug() << aZoneFileStream->device()->pos(); + + QByteArray rootNamePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rootNamePtr.data(), 4); + qDebug() << "Root name ptr: " << (QString)rootNamePtr.toHex(); + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.count; + + if (rootNamePtr.toHex() == "ffffffff") { + // Read in sound file name + char soundNameChar; + *aZoneFileStream >> soundNameChar; + while (soundNameChar != 0) { + result.name += soundNameChar; + *aZoneFileStream >> soundNameChar; + } + } + + int tagCount = 0; + int resultCount = 0; + for (quint32 i = 0; i < result.count; i++) { + aZoneFileStream->skipRawData(12); + + QByteArray tagPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(tagPtr.data(), 4); + + if (tagPtr.toHex() == "ffffffff") { + qDebug() << "Tag Ptr: " << tagPtr.toHex(); + tagCount++; + } + aZoneFileStream->skipRawData(4); + + QByteArray pathPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pathPtr.data(), 4); + + if (pathPtr.toHex() == "ffffffff") { + qDebug() << "Path Ptr: " << pathPtr.toHex(); + resultCount++; + } + + aZoneFileStream->skipRawData(160); + } + + for (int i = 0; i < tagCount; i++) { + // Read in tag? + QString tag; + char tagChar; + *aZoneFileStream >> tagChar; + while (tagChar != 0) { + tag += tagChar; + *aZoneFileStream >> tagChar; + } + qDebug() << "Tag: " << tag; + } + + for (int i = 0; i < resultCount; i++) { + Sound sound; + + if (aZoneFileStream->device()->peek(12).toHex().contains("ffffffff00000000")) { + aZoneFileStream->skipRawData(12); + } + + aZoneFileStream->skipRawData(8); + + qDebug() << "- " << aZoneFileStream->device()->pos(); + QByteArray aliasPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(aliasPtr.data(), 4); + + QByteArray namePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(namePtr.data(), 4); + + *aZoneFileStream >> sound.dataLength; + qDebug() << "- Data length: " << sound.dataLength; + + if (aliasPtr.toHex() == "ffffffff") { + // Read in sound alias name + char soundAliasChar; + *aZoneFileStream >> soundAliasChar; + while (soundAliasChar != 0) { + sound.alias += soundAliasChar; + *aZoneFileStream >> soundAliasChar; + } + qDebug() << "- Alias: " << sound.alias; + } + + if (aZoneFileStream->device()->peek(4) == "RIFF") { + sound.path = sound.alias; + sound.alias = ""; + } else if (namePtr.toHex() == "ffffffff") { + // Read in sound file path + char soundPathChar; + *aZoneFileStream >> soundPathChar; + while (soundPathChar != 0) { + sound.path += soundPathChar; + *aZoneFileStream >> soundPathChar; + } + sound.path.replace(",", ""); + qDebug() << "- Path: " << sound.path; + } + + if (sound.dataLength) { + QByteArray data(sound.dataLength, Qt::Uninitialized); + aZoneFileStream->readRawData(data.data(), sound.dataLength); + sound.data = data; + } + result.sounds.append(sound); + } + qDebug() << "- " << aZoneFileStream->device()->pos(); + + return result; +} + +void ZoneFile_COD2::pParseAsset_ColMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_GameMapSP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_GameMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_LightDef(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_UIMap(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_AIType(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_FX(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Animation ZoneFile_COD2::pParseAsset_Animation(QDataStream *aZoneFileStream) { + Animation result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.dataByteCount + >> result.dataShortCount + >> result.dataIntCount + >> result.randomDataByteCount + >> result.randomDataIntCount + >> result.numframes + >> result.isLooped + >> result.isDelta + >> result.noneRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.normalTranslatedBoneCount + >> result.preciseTranslatedBoneCount + >> result.staticTranslatedBoneCount + >> result.noneTranslatedBoneCount + >> result.totalBoneCount + >> result.otherBoneCount1 + >> result.otherBoneCount2 + >> result.notifyCount + >> result.assetType + >> result.pad + >> result.randomDataShortCount + >> result.indexCount + >> result.frameRate + >> result.frequency + >> result.boneIDsPtr + >> result.dataBytePtr + >> result.dataShortPtr + >> result.dataIntPtr + >> result.randomDataShortPtr + >> result.randomDataBytePtr + >> result.randomDataIntPtr + >> result.longIndiciesPtr + >> result.notificationsPtr + >> result.deltaPartsPtr; + + // Read in x_anim file name + QString xAnimName; + char xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + while (xAnimNameChar != 0) { + result.name += xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + } + + // Parse x_anim index header + QVector sectionLengths; + for (int i = 0; i < result.numframes; i++) { + quint8 sectionlength; + *aZoneFileStream >> sectionlength; + sectionLengths.push_back(sectionlength); + // Skip padding + aZoneFileStream->skipRawData(1); + } + // Skip unknown section + aZoneFileStream->skipRawData(2 * 8); + + return result; +} + +MenuFile ZoneFile_COD2::pParseAsset_MenuFile(QDataStream *aZoneFileStream) { + //MENU_FILE + MenuFile result; + + aZoneFileStream->skipRawData(4); // Separator + + // Parse menu def count + *aZoneFileStream >> result.menuCount; + + // Clearly misparsed, never have this much + if (result.menuCount > 1000) { + qDebug() << "Failure reported when parsing menu file."; + return result; + } + for (uint i = 0; i < result.menuCount; i++) { + Menu menu; + + aZoneFileStream->skipRawData(4); // Separator + + // Read in x_anim file name + char menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + while (menuFilepathChar != 0) { + menu.filePath += menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + } + aZoneFileStream->skipRawData(4); // Separator + + *aZoneFileStream >> menu.menuNamePtr; + + float menuRectX, menuRectY, menuRectWidth, menuRectHeight; + *aZoneFileStream >> menuRectX >> menuRectY >> menuRectWidth >> menuRectHeight; + menu.rect = QRectF(menuRectX, menuRectY, menuRectWidth, menuRectHeight); + + quint32 hAlignInt, vAlignInt; + *aZoneFileStream >> hAlignInt >> vAlignInt; + menu.hAlign = (MENU_H_ALIGNMENT)hAlignInt; + menu.vAlign = (MENU_V_ALIGNMENT)vAlignInt; + + float rectClientX, rectClientY, rectClientWidth, rectClientHeight; + *aZoneFileStream >> rectClientX >> rectClientY >> rectClientWidth >> rectClientHeight; + menu.clientRect = QRectF(rectClientX, rectClientY, rectClientWidth, rectClientHeight); + + quint32 hClientAlignInt, vClientAlignInt, styleInt, borderInt; + *aZoneFileStream >> hClientAlignInt >> vClientAlignInt >> menu.groupPtr + >> styleInt >> borderInt >> menu.ownerDraw >> menu.ownerDrawFlags + >> menu.borderSize >> menu.staticFlags >> menu.dynamicFlags >> menu.nextTime; + menu.hClientAlign = (MENU_H_ALIGNMENT)hClientAlignInt; + menu.vClientAlign = (MENU_V_ALIGNMENT)vClientAlignInt; + menu.style = (MENU_WINDOW_STYLE)styleInt; + menu.border = (MENU_WINDOW_BORDER)borderInt; + + float foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA, + backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA, + borderColorR, borderColorG, borderColorB, borderColorA, + outlineColorR, outlineColorG, outlineColorB, outlineColorA; + *aZoneFileStream >> foregroundColorR >> foregroundColorG >> foregroundColorB >> foregroundColorA + >> backgroundColorR >> backgroundColorG >> backgroundColorB >> backgroundColorA + >> borderColorR >> borderColorG >> borderColorB >> borderColorA + >> outlineColorR >> outlineColorG >> outlineColorB >> outlineColorA; + + menu.foregroundColor = QColor(foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA); + menu.backgroundColor = QColor(backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA); + menu.borderColor = QColor(borderColorR, borderColorG, borderColorB, borderColorA); + menu.outlineColor = QColor(outlineColorR, outlineColorG, outlineColorB, outlineColorA); + + *aZoneFileStream >> menu.materialPtr >> menu.fontPtr >> menu.fullScreen >> menu.itemCount + >> menu.fontIndex >> menu.cursorItem >> menu.fadeCycle >> menu.fadeClamp + >> menu.fadeAmount >> menu.fadeInAmount >> menu.blurRadius >> menu.onOpenPtr + >> menu.onFocusPtr >> menu.onClosePtr >> menu.onESCPtr >> menu.onKeyPtr + >> menu.visibleExpCount >> menu.expEntryPtr >> menu.allowedBindingPtr + >> menu.soundNamePtr >> menu.imageTrack; + + float focusColorR, focusColorG, focusColorB, focusColorA, + disabledColorR, disabledColorG, disabledColorB, disabledColorA; + *aZoneFileStream >> focusColorR >> focusColorG >> focusColorB >> focusColorA + >> disabledColorR >> disabledColorG >> disabledColorB >> disabledColorA; + menu.focusColor = QColor(focusColorR, focusColorG, focusColorB, focusColorA); + menu.disabledColor = QColor(disabledColorR, disabledColorG, disabledColorB, disabledColorA); + + *aZoneFileStream >> menu.rectXExpCount >> menu.rectXExpPtr >> menu.rectYExpCount >> menu.rectYExpPtr; + + aZoneFileStream->skipRawData(4); // Separator + + char menuDefNameChar; + int menuDefNameLen = 0; + *aZoneFileStream >> menuDefNameChar; + while (menuDefNameChar != 0 && menuDefNameLen < 30) { + menuDefNameLen++; + menu.name += menuDefNameChar; + *aZoneFileStream >> menuDefNameChar; + } + + char defStringChar; + int defStringLen = 0; + *aZoneFileStream >> defStringChar; + while (defStringChar != 0 && defStringLen < 30) { + defStringLen++; + menu.definition += defStringChar; + *aZoneFileStream >> defStringChar; + } + aZoneFileStream->skipRawData(4 * 10); + + *aZoneFileStream >> menu.itemWindowDefNamePtr; + + float itemRectX, itemRectY, itemRectWidth, itemRectHeight; + *aZoneFileStream >> itemRectX >> itemRectY >> itemRectWidth >> itemRectHeight; + menu.itemRect = QRectF(itemRectX, itemRectY, itemRectWidth, itemRectHeight); + + *aZoneFileStream >> menu.itemHAlignment >> menu.itemVAlignment >> menu.itemGroupPtr + >> menu.itemWindowStyle >> menu.itemWindowBorder >> menu.itemOwnerDraw + >> menu.itemOwnerDrawFlags >> menu.itemBorderSize >> menu.itemStaticFlags + >> menu.itemDynamicFlags >> menu.itemNextTime; + + float itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA, + itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA, + itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA, + itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA; + *aZoneFileStream >> itemForegroundColorR >> itemForegroundColorG >> itemForegroundColorB >> itemForegroundColorA + >> itemBackgroundColorR >> itemBackgroundColorG >> itemBackgroundColorB >> itemBackgroundColorA + >> itemBorderColorR >> itemBorderColorG >> itemBorderColorB >> itemBorderColorA + >> itemOutlineColorR >> itemOutlineColorG >> itemOutlineColorB >> itemOutlineColorA; + + menu.itemForegroundColor = QColor(itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA); + menu.itemBackgroundColor = QColor(itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA); + menu.itemBorderColor = QColor(itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA); + menu.itemOutlineColor = QColor(itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA); + + *aZoneFileStream >> menu.itemMaterialPtr; + + float itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight; + *aZoneFileStream >> itemTextRectX >> itemTextRectY >> itemTextRectWidth >> itemTextRectHeight; + menu.itemTextRect = QRectF(itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight); + + quint32 hItemTextAlignInt, vItemTextAlignInt, itemType, fontTypeInt, textStyleInt; + *aZoneFileStream >> hItemTextAlignInt >> vItemTextAlignInt >> itemType >> menu.dataType + >> menu.alignment >> fontTypeInt >> menu.textAlignMode >> menu.textalignx >> menu.textaligny + >> menu.textscale >> textStyleInt >> menu.gameMsgWindowIndex >> menu.gameMsgWindowMode + >> menu.testPtr >> menu.textSavegameInfo >> menu.parentPtr; + menu.itemText_hAlign = (MENU_H_ALIGNMENT)hItemTextAlignInt; + menu.itemText_vAlign = (MENU_V_ALIGNMENT)vItemTextAlignInt; + menu.itemType = (MENU_ITEM_TYPE)itemType; + menu.fontEnum = (MENU_FONT_TYPE)fontTypeInt; + menu.textStyle = (MENU_ITEM_TEXTSTYLE)textStyleInt; + + *aZoneFileStream >> menu.mouseEnterText >> menu.mouseExitText >> menu.mouseEnter >> menu.mouseExit + >> menu.action >> menu.onAccept >> menu.onFocus >> menu.leaveFocus >> menu.dvar >> menu.dvarTest + >> menu.keyHandlerPtr >> menu.enableDvarPtr >> menu.dvarFlags >> menu.focusSoundPtr + >> menu.special >> menu.cursorPos; + + // itemDefData_t typeData; + + // listBoxDef_s *listBox; + + *aZoneFileStream >> menu.startPos >> menu.endPos >> menu.drawPadding; + + *aZoneFileStream >> menu.elementWidth >> menu.elementHeight; + + *aZoneFileStream >> menu.elementStyle >> menu.numColumns; + + //columnInfo_s columnInfo[16]; + + *aZoneFileStream >> menu.doubleClickPtr; + + + *aZoneFileStream >> menu.notselectable >> menu.noScrollBars >> menu.usePaging; + + float itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA, + itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA, + itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA; + *aZoneFileStream >> itemSelectBorderColorR >> itemSelectBorderColorG >> itemSelectBorderColorB >> itemSelectBorderColorA + >> itemDisableColorR >> itemDisableColorG >> itemDisableColorB >> itemDisableColorA + >> itemFocusColorR >> itemFocusColorG >> itemFocusColorB >> itemFocusColorA; + menu.itemSelectBorderColor = QColor(itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA); + menu.itemDisableColor = QColor(itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA); + menu.itemFocusColor = QColor(itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA); + + *aZoneFileStream >> menu.selectIconPtr >> menu.backgroundItemListboxPtr >> menu.highlightTexturePtr; + + // editFieldDef_s *editField; + + *aZoneFileStream >> menu.minVal >> menu.maxVal >> menu.defVal >> menu.range >> menu.maxChars + >> menu.maxCharsGotoNext >> menu.maxPaintChars >> menu.paintOffset; + + // multiDef_s *multi; + + for (int i = 0; i < 32; i++) { + quint32 dvarList; + *aZoneFileStream >> dvarList; + menu.dvarListPtrs.push_back(dvarList); + } + + for (int i = 0; i < 32; i++) { + quint32 dvarStr; + *aZoneFileStream >> dvarStr; + menu.dvarStrPtrs.push_back(dvarStr); + } + + for (int i = 0; i < 32; i++) { + float dvarValue; + *aZoneFileStream >> dvarValue; + menu.dvarValues.push_back(dvarValue); + } + + *aZoneFileStream >> menu.count >> menu.strDef >> menu.enumDvarNamePtr; + aZoneFileStream->skipRawData(4); + //>> menu.dataPtr + *aZoneFileStream >> menu.itemImageTrack; + + qDebug() << aZoneFileStream->device()->pos(); + + //statement_s visibleExp; + //statement_s textExp; + //statement_s materialExp; + //statement_s rectXExp; + //statement_s rectYExp; + //statement_s rectWExp; + //statement_s rectHExp; + //statement_s foreColorAExp; + result.menuDefs << menu; + } + return result; +} + +void ZoneFile_COD2::pParseAsset_Weapon(QDataStream *aZoneFileStream) { + //WEAPON_FILE + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD2::pParseAsset_D3DBSP(QDataStream *aZoneFileStream) { + //D3DBSP_DUMP + Q_UNUSED(aZoneFileStream); +} + +StringTable ZoneFile_COD2::pParseAsset_StringTable(QDataStream *aZoneFileStream) { + StringTable result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.columnCount + >> result.rowCount; + + // Todo fix this + result.columnCount = 0; + result.rowCount = 0; + + aZoneFileStream->skipRawData(4); + + QString stringTableName; + char stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + while (stringTableNameChar != 0) { + result.name += stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + } + + for (quint32 i = 0; i < result.rowCount; i++) { + QByteArray pointerData(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pointerData.data(), 4); + result.tablePointers.push_back(pointerData.toHex()); + + aZoneFileStream->skipRawData(4); + } + + for (const QString &pointerAddr : result.tablePointers) { + QString leadingContent = ""; + if (pointerAddr == "FFFFFFFF") { + char leadingContentChar; + *aZoneFileStream >> leadingContentChar; + while (leadingContentChar != 0) { + leadingContent += leadingContentChar; + *aZoneFileStream >> leadingContentChar; + } + } else { + leadingContent = pointerAddr; + } + + QString content; + char contentChar; + *aZoneFileStream >> contentChar; + while (contentChar != 0) { + content += contentChar; + *aZoneFileStream >> contentChar; + } + result.content[leadingContent] = content; + } + return result; +} +// "parts", +// "model", +// "material", +// "image", +// "sound", +// "sndCurve", +// "clipMap", +// "world", +// "lightDef", +// "font", +// "menuList", +// "menu", +// "localize", +// "weapon", +// "sndDriverGlobals", +// "fx", +// "impactFx", +// "rawfile", +// "data" + +QString ZoneFile_COD2::AssetTypeToString(const QString aAssetType) { + const QString cleanedType = aAssetType.toUpper(); + if (cleanedType == "") { // localized string PARTIALLY VERIFIED + return ""; + } + return aAssetType; +} + +QByteArray ZoneFile_COD2::GetBinaryData() { + QByteArray result; + + return result; +} diff --git a/libs/zonefile/zonefile_cod2.h b/libs/zonefile/zonefile_cod2.h new file mode 100644 index 0000000..9d560f7 --- /dev/null +++ b/libs/zonefile/zonefile_cod2.h @@ -0,0 +1,52 @@ +#ifndef ZONEFILE_COD2_H +#define ZONEFILE_COD2_H + +#include "zonefile.h" + +class ZoneFile_COD2 : public ZoneFile +{ +public: + ZoneFile_COD2(); + ~ZoneFile_COD2(); + + bool Load(const QByteArray aFileData, FF_PLATFORM aPlatform) override; + QString AssetTypeToString(const QString aAssetType); + + QByteArray GetBinaryData() override; + +protected: + void pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) override; + quint32 pParseZoneSize(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsA(QDataStream *aZoneFileStream) override; + quint32 pParseZoneTagCount(QDataStream *aZoneFileStream) override; + quint32 pParseZoneRecordCount(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsB(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsC(QDataStream *aZoneFileStream) override; + QStringList pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) override; + QStringList pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) override; + AssetMap pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) override; + LocalString pParseAsset_LocalString(QDataStream *aZoneFileStream) override; + RawFile pParseAsset_RawFile(QDataStream *aZoneFileStream) override; + void pParseAsset_PhysPreset(QDataStream *aZoneFileStream) override; + Model pParseAsset_Model(QDataStream *aZoneFileStream) override; + Material pParseAsset_Material(QDataStream *aZoneFileStream) override; + Shader pParseAsset_Shader(QDataStream *aZoneFileStream) override; + TechSet pParseAsset_TechSet(QDataStream *aZoneFileStream) override; + Image pParseAsset_Image(QDataStream *aZoneFileStream) override; + SoundAsset pParseAsset_Sound(QDataStream *aZoneFileStream) override; + void pParseAsset_ColMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapSP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_LightDef(QDataStream *aZoneFileStream) override; + void pParseAsset_UIMap(QDataStream *aZoneFileStream) override; + void pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) override; + void pParseAsset_AIType(QDataStream *aZoneFileStream) override; + void pParseAsset_FX(QDataStream *aZoneFileStream) override; + Animation pParseAsset_Animation(QDataStream *aZoneFileStream) override; + MenuFile pParseAsset_MenuFile(QDataStream *aZoneFileStream) override; + void pParseAsset_Weapon(QDataStream *aZoneFileStream) override; + void pParseAsset_D3DBSP(QDataStream *aZoneFileStream) override; + StringTable pParseAsset_StringTable(QDataStream *aZoneFileStream) override; +}; + +#endif // ZONEFILE_COD2_H diff --git a/libs/zonefile/zonefile_cod5.cpp b/libs/zonefile/zonefile_cod5.cpp new file mode 100644 index 0000000..78665ab --- /dev/null +++ b/libs/zonefile/zonefile_cod5.cpp @@ -0,0 +1,1096 @@ +#include "zonefile_cod5.h" + +#include +#include +#include + +ZoneFile_COD5::ZoneFile_COD5() + : ZoneFile() { + +} + +ZoneFile_COD5::~ZoneFile_COD5() { + +} + +bool ZoneFile_COD5::Load(const QByteArray aFileData, FF_PLATFORM aPlatform) { + // Open zone file as little endian stream + QDataStream zoneFileStream(aFileData); + if (aPlatform == FF_PLATFORM_PC) { + zoneFileStream.setByteOrder(QDataStream::LittleEndian); + } else { + zoneFileStream.setByteOrder(QDataStream::BigEndian); + } + + // Parse data from zone file header + pParseZoneHeader(&zoneFileStream, aPlatform); + SetRecords(pParseZoneIndex(&zoneFileStream, GetRecordCount())); + SetAssetMap(pParseAssets(&zoneFileStream, GetRecords())); + + return true; +} + +void ZoneFile_COD5::pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) { + Q_UNUSED(aPlatform); + + SetSize(pParseZoneSize(aZoneFileStream)); + pParseZoneUnknownsA(aZoneFileStream); + + SetTagCount(pParseZoneTagCount(aZoneFileStream)); + pParseZoneUnknownsB(aZoneFileStream); + + SetRecordCount(pParseZoneRecordCount(aZoneFileStream)); + + quint32 tagCount = GetTagCount(); + if (tagCount) { + pParseZoneUnknownsC(aZoneFileStream); + SetTags(pParseZoneTags(aZoneFileStream, tagCount)); + } else { + aZoneFileStream->skipRawData(4); + } +} + +quint32 ZoneFile_COD5::pParseZoneSize(QDataStream *aZoneFileStream) { + quint32 zoneFileSize; + *aZoneFileStream >> zoneFileSize; + if (zoneFileSize <= 0) { + qDebug() << "Tried to open empty zone file!"; + exit(-1); + } + zoneFileSize += 36; + return zoneFileSize; +} + +/* + ParseZoneUnknownsA() + + Parses the 1st section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD5::pParseZoneUnknownsA(QDataStream *aZoneFileStream) { + // Byte 4-7, 8-11, 12-15: unknown + QByteArray unknown1(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown1.data(), 4); + + QByteArray unknown2(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown2.data(), 4); + + QByteArray unknown3(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown3.data(), 4); + + // Byte 16-19, 20-23: empty/unknown + QByteArray unknown4(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown4.data(), 4); + + QByteArray unknown5(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown5.data(), 4); + + // Byte 24-27: somehow related to the filesize, but smaller value + QByteArray unknown6(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown6.data(), 4); + + // Byte 28-31, 32-35: unknown + QByteArray unknown7(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown7.data(), 4); + + QByteArray unknown8(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown8.data(), 4); +} + +/* + ParseZoneTagCount() + + Parses the number of string tags in the zone index +*/ +quint32 ZoneFile_COD5::pParseZoneTagCount(QDataStream *aZoneFileStream) { + quint32 tagCount; + *aZoneFileStream >> tagCount; + return tagCount; +} + +/* + ParseZoneRecordCount() + + Parses the number of records in the zone index +*/ +quint32 ZoneFile_COD5::pParseZoneRecordCount(QDataStream *aZoneFileStream) { + quint32 recordCount; + *aZoneFileStream >> recordCount; + return recordCount; +} + +/* + ParseZoneUnknownsB() + + Parses the 2nd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD5::pParseZoneUnknownsB(QDataStream *aZoneFileStream) { + // Byte 44-47: Unknown/empty? + QByteArray unknown9(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown9.data(), 4); +} + +/* + pParseZoneUnknownsC() + + Parses the 3rd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD5::pParseZoneUnknownsC(QDataStream *aZoneFileStream) { + // Byte 40-43: Unknown/empty? + QByteArray unknown10(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown10.data(), 4); + + // Byte 44-47: Unknown/empty? + QByteArray unknown11(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown11.data(), 4); +} + +/* + ParseZoneTags() + + Parses the string tags ate the start of zone file +*/ +QStringList ZoneFile_COD5::pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) { + QStringList tags; + + // Byte 48-51: Repeated separators? ÿÿÿÿ x i + aZoneFileStream->skipRawData(4 * (tagCount - 1)); + + // Parse tags/strings before index + QString zoneTag; + char zoneTagChar; + for (quint32 i = 0; i < tagCount; i++) { + *aZoneFileStream >> zoneTagChar; + while (zoneTagChar != 0) { + zoneTag += zoneTagChar; + *aZoneFileStream >> zoneTagChar; + } + tags << zoneTag; + zoneTag.clear(); + } + return tags; +} + +/* + ParseZoneIndex() + + Parse the binary zone index data and populate table +*/ +QStringList ZoneFile_COD5::pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) { + QStringList result; + + // Don't parse if no records + if (!recordCount) { return result; } + + if (aZoneFileStream->device()->peek(4).toHex().contains("ffff")) { + aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 2); + } + + // Parse index & map found asset types + for (quint32 i = 0; i <= recordCount; i++) { + // Skip record start + QByteArray rawAssetType(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rawAssetType.data(), 4); + result << rawAssetType.toHex(); + + // Skip separator + aZoneFileStream->skipRawData(4); + } + return result; +} + +AssetMap ZoneFile_COD5::pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) { + AssetMap result; + + aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 8); + + for (int i = 0; i < assetOrder.size(); i++) { + const QString typeHex = assetOrder[i]; + const QString typeStr = AssetTypeToString(typeHex); + + if (typeStr == "LOCAL STRING") { // localized string asset + result.localStrings << pParseAsset_LocalString(aZoneFileStream); + } else if (typeStr == "RAW FILE") { // gsc + auto rawFile = pParseAsset_RawFile(aZoneFileStream); + if (rawFile.length) { + result.rawFiles << rawFile; + } + } else if (typeStr == "PHYS PRESET") { // physpreset + pParseAsset_PhysPreset(aZoneFileStream); + } else if (typeStr == "MODEL") { // xmodel + result.models << pParseAsset_Model(aZoneFileStream); + } else if (typeStr == "MATERIAL") { // material + pParseAsset_Material(aZoneFileStream); + } else if (typeStr == "SHADER") { // pixelshader + pParseAsset_Shader(aZoneFileStream); + } else if (typeStr == "TECH SET") { // techset include + result.techSets << pParseAsset_TechSet(aZoneFileStream); + } else if (typeStr == "IMAGE") { // image + result.images << pParseAsset_Image(aZoneFileStream); + } else if (typeStr == "SOUND") { // loaded_sound + result.sounds << pParseAsset_Sound(aZoneFileStream); + } else if (typeStr == "COLLISION MAP") { // col_map_mp + pParseAsset_ColMapMP(aZoneFileStream); + } else if (typeStr == "MP MAP") { // game_map_sp + pParseAsset_GameMapSP(aZoneFileStream); + } else if (typeStr == "SP MAP") { // game_map_mp + pParseAsset_GameMapMP(aZoneFileStream); + } else if (typeStr == "LIGHT DEF") { // lightdef + pParseAsset_LightDef(aZoneFileStream); + } else if (typeStr == "UI MAP") { // ui_map + pParseAsset_UIMap(aZoneFileStream); + } else if (typeStr == "SND DRIVER GLOBALS") { // snddriverglobals + pParseAsset_SNDDriverGlobals(aZoneFileStream); + } else if (typeStr == "AI TYPE") { // aitype + pParseAsset_AIType(aZoneFileStream); + } else if (typeStr == "EFFECT") { // aitype + pParseAsset_FX(aZoneFileStream); + } else if (typeStr == "ANIMATION") { // aitype + result.animations << pParseAsset_Animation(aZoneFileStream); + } else if (typeStr == "STRING TABLE") { // string_table + result.stringTables << pParseAsset_StringTable(aZoneFileStream); + } else if (typeStr == "MENU") { // string_table + result.menuFiles << pParseAsset_MenuFile(aZoneFileStream); + } else if (typeStr == "WEAPON") { // string_table + pParseAsset_Weapon(aZoneFileStream); + } else if (typeStr == "D3DBSP DUMP") { // string_table + pParseAsset_D3DBSP(aZoneFileStream); + } else if (typeStr != "UNKNOWN") { + qDebug() << "Found bad asset type!" << typeStr; + } + } + return result; +} + +LocalString ZoneFile_COD5::pParseAsset_LocalString(QDataStream *aZoneFileStream) { + LocalString result; + + quint32 stringPtr, aliasPtr; + *aZoneFileStream >> stringPtr >> aliasPtr; + if (stringPtr == 4294967295) { + // Parse local string asset contents + QString localStr; + char localStrChar; + *aZoneFileStream >> localStrChar; + while (localStrChar != 0) { + result.string += localStrChar; + *aZoneFileStream >> localStrChar; + } + } else { + result.string = "String Ptr: " + QString::number(stringPtr); + } + + if (aliasPtr == 4294967295) { + // Parse rawfile name + QString aliasName; + char aliasNameChar; + *aZoneFileStream >> aliasNameChar; + while (aliasNameChar != 0) { + result.alias += aliasNameChar; + *aZoneFileStream >> aliasNameChar; + } + } else { + result.string = "Alias Ptr: " + QString::number(aliasPtr); + } + + return result; +} + +RawFile ZoneFile_COD5::pParseAsset_RawFile(QDataStream *aZoneFileStream) { + RawFile result; + + // Skip start separator FF FF FF FF (pointer?) + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.length; + + // Skip unknown 4 byte data + aZoneFileStream->skipRawData(4); + + // Parse rawfile path + char scriptPathChar; + *aZoneFileStream >> scriptPathChar; + while (scriptPathChar != 0) { + result.path += scriptPathChar; + *aZoneFileStream >> scriptPathChar; + } + result.path.replace(",", ""); + const QStringList pathParts = result.path.split('/'); + if (pathParts.size() == 0) { + qDebug() << "Failed to parse ff path! " << result.path; + exit(-1); + } + + // Parse gsc contents + char rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + while (rawFileContentsChar != 0 && rawFileContentsChar != -1) { + result.contents += rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + } + return result; +} + +void ZoneFile_COD5::pParseAsset_PhysPreset(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Model ZoneFile_COD5::pParseAsset_Model(QDataStream *aZoneFileStream) { + Model result; + + qDebug() << "Model Info:"; + + *aZoneFileStream >> result.namePtr >> result.tagCount >> result.rootTagCount + >> result.surfCount >> result.unknownCount >> result.boneNamePtr + >> result.parentListPtr >> result.quatsPtr >> result.transPtr + >> result.partClassPtr >> result.baseMatPtr + >> result.surfsPtr >> result.materialHandlesPtr; + + // Parse XModelLodInfo + for (int i = 1; i <= 4; i++) { + qDebug() << "- Lod Info " << i; + + quint32 intDist; + *aZoneFileStream >> intDist; + + std::memcpy(&result.lodInfo[i].dist, &intDist, sizeof(result.lodInfo[i].dist)); + *aZoneFileStream >> result.lodInfo[i].numsurfs >> result.lodInfo[i].surfIndex; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.lodInfo[i].partBits[0] + >> result.lodInfo[i].partBits[1] + >> result.lodInfo[i].partBits[2] + >> result.lodInfo[i].partBits[3]; + } + + *aZoneFileStream >> result.collSurfsPtr >> result.numCollSurfs >> result.contents >> result.boneInfoPtr; + + quint32 intRadius, intMins[3], intMaxs[3]; + *aZoneFileStream >> intRadius >> intMins[0] >> intMins[1] + >> intMins[2] >> intMaxs[0] >> intMaxs[1] >> intMaxs[2]; + + std::memcpy(&result.radius, &intRadius, sizeof(result.radius)); + + std::memcpy(&result.mins[0], &intMins[0], sizeof(result.mins[0])); + std::memcpy(&result.mins[1], &intMins[1], sizeof(result.mins[1])); + std::memcpy(&result.mins[2], &intMins[2], sizeof(result.mins[2])); + + std::memcpy(&result.maxs[0], &intMaxs[0], sizeof(result.maxs[0])); + std::memcpy(&result.maxs[1], &intMaxs[1], sizeof(result.maxs[2])); + std::memcpy(&result.maxs[2], &intMaxs[2], sizeof(result.maxs[3])); + + *aZoneFileStream >> result.numLods >> result.collLod >> result.streamInfoPtr + >> result.memUsage >> result.flags >> result.physPresetPtr >> result.physGeomsPtr; + + // Parse model name + char modelNameChar; + *aZoneFileStream >> modelNameChar; + while (modelNameChar == 0) { + *aZoneFileStream >> modelNameChar; + } + while (modelNameChar != 0) { + result.modelName += modelNameChar; + *aZoneFileStream >> modelNameChar; + } + return result; +} + +Material ZoneFile_COD5::pParseAsset_Material(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); + + return Material(); +} + +Shader ZoneFile_COD5::pParseAsset_Shader(QDataStream *aZoneFileStream) { + Shader result = Shader(); + + quint8 minorVersion, majorVersion; + *aZoneFileStream >> minorVersion >> majorVersion; + + quint32 magic; + *aZoneFileStream >> magic; + + // Verify .fxc magic + if (magic != 65534 && magic != 65535) { return result; } + + SHADER_TYPE type = SHADER_NONE; + quint16 rawShaderType; + *aZoneFileStream >> rawShaderType; + if (rawShaderType == 65535) { // Pixel shader + type = SHADER_PIXEL; + } else if (rawShaderType == 65534) { // Vertex shader + type = SHADER_VERTEX; + } + Q_UNUSED(type); + + while (true) { + quint32 instructionToken; + *aZoneFileStream >> instructionToken; + + SHADER_OPCODE opCode = (SHADER_OPCODE)(instructionToken & 0xffff); + + int size; + if (opCode == OPCODE_End) { + break; + } else if (opCode == OPCODE_Comment) { + size = (int)((instructionToken >> 16) & 0x7FFF); + } else { + size = (int)((instructionToken >> 24) & 0x0f); + } + Q_UNUSED(size); + } + + + return result; +} + +TechSet ZoneFile_COD5::pParseAsset_TechSet(QDataStream *aZoneFileStream) { + TechSet result; + + for (int i = 1; i <= 62; i++) { + quint32 ptr; + *aZoneFileStream >> ptr; + + result.pointers << ptr; + } + qDebug() << aZoneFileStream->device()->pos(); + + // Parse techset name + char techSetNameChar; + *aZoneFileStream >> techSetNameChar; + while (techSetNameChar != 0) { + result.name += techSetNameChar; + *aZoneFileStream >> techSetNameChar; + } + result.name.replace(",", ""); + + return result; +} + +Image ZoneFile_COD5::pParseAsset_Image(QDataStream *aZoneFileStream) { + Image result; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknowna >> result.unknownb + >> result.unknownc >> result.unknownd + >> result.unknowne >> result.unknownf + >> result.unknowng; + + aZoneFileStream->skipRawData(15 * 4); + *aZoneFileStream >> result.unknownh >> result.unknowni; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknownj; + + aZoneFileStream->skipRawData(4); + + char materialNameChar; + *aZoneFileStream >> materialNameChar; + while (materialNameChar != 0) { + result.materialName += materialNameChar; + *aZoneFileStream >> materialNameChar; + } + result.materialName.replace(",", ""); + + if (result.unknowna) { + *aZoneFileStream >> result.unknownk; + *aZoneFileStream >> result.unknownl; + *aZoneFileStream >> result.unknownm; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown1; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown2 >> result.unknown3 + >> result.size1 >> result.size2 + >> result.unknown4 >> result.unknown5; + + aZoneFileStream->skipRawData(4); + + char imageNameChar; + *aZoneFileStream >> imageNameChar; + while (imageNameChar != 0) { + result.name += imageNameChar; + *aZoneFileStream >> imageNameChar; + } + + *aZoneFileStream >> result.unknown6 >> result.unknown7; + + QByteArray compressionData(8, Qt::Uninitialized); + aZoneFileStream->readRawData(compressionData.data(), 8); + if (compressionData.contains("DXT1")) { + result.compression = COMPRESSION_DXT1; + } else if (compressionData.contains("DXT3")) { + result.compression = COMPRESSION_DXT3; + } else if (compressionData.contains("DXT5")) { + result.compression = COMPRESSION_DXT5; + } else { + result.compression = COMPRESSION_NONE; + } + + *aZoneFileStream >> result.unknown8 >> result.unknown9; + } + + return result; +} + +SoundAsset ZoneFile_COD5::pParseAsset_Sound(QDataStream *aZoneFileStream) { + SoundAsset result; + + qDebug() << aZoneFileStream->device()->pos(); + + QByteArray rootNamePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rootNamePtr.data(), 4); + qDebug() << "Root name ptr: " << (QString)rootNamePtr.toHex(); + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.count; + + if (rootNamePtr.toHex() == "ffffffff") { + // Read in sound file name + char soundNameChar; + *aZoneFileStream >> soundNameChar; + while (soundNameChar != 0) { + result.name += soundNameChar; + *aZoneFileStream >> soundNameChar; + } + } + + int tagCount = 0; + int resultCount = 0; + for (quint32 i = 0; i < result.count; i++) { + aZoneFileStream->skipRawData(12); + + QByteArray tagPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(tagPtr.data(), 4); + + if (tagPtr.toHex() == "ffffffff") { + qDebug() << "Tag Ptr: " << tagPtr.toHex(); + tagCount++; + } + aZoneFileStream->skipRawData(4); + + QByteArray pathPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pathPtr.data(), 4); + + if (pathPtr.toHex() == "ffffffff") { + qDebug() << "Path Ptr: " << pathPtr.toHex(); + resultCount++; + } + + aZoneFileStream->skipRawData(160); + } + + for (int i = 0; i < tagCount; i++) { + // Read in tag? + QString tag; + char tagChar; + *aZoneFileStream >> tagChar; + while (tagChar != 0) { + tag += tagChar; + *aZoneFileStream >> tagChar; + } + qDebug() << "Tag: " << tag; + } + + for (int i = 0; i < resultCount; i++) { + Sound sound; + + if (aZoneFileStream->device()->peek(12).toHex().contains("ffffffff00000000")) { + aZoneFileStream->skipRawData(12); + } + + aZoneFileStream->skipRawData(8); + + qDebug() << "- " << aZoneFileStream->device()->pos(); + QByteArray aliasPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(aliasPtr.data(), 4); + + QByteArray namePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(namePtr.data(), 4); + + *aZoneFileStream >> sound.dataLength; + qDebug() << "- Data length: " << sound.dataLength; + + if (aliasPtr.toHex() == "ffffffff") { + // Read in sound alias name + char soundAliasChar; + *aZoneFileStream >> soundAliasChar; + while (soundAliasChar != 0) { + sound.alias += soundAliasChar; + *aZoneFileStream >> soundAliasChar; + } + qDebug() << "- Alias: " << sound.alias; + } + + if (aZoneFileStream->device()->peek(4) == "RIFF") { + sound.path = sound.alias; + sound.alias = ""; + } else if (namePtr.toHex() == "ffffffff") { + // Read in sound file path + char soundPathChar; + *aZoneFileStream >> soundPathChar; + while (soundPathChar != 0) { + sound.path += soundPathChar; + *aZoneFileStream >> soundPathChar; + } + sound.path.replace(",", ""); + qDebug() << "- Path: " << sound.path; + } + + if (sound.dataLength) { + QByteArray data(sound.dataLength, Qt::Uninitialized); + aZoneFileStream->readRawData(data.data(), sound.dataLength); + sound.data = data; + } + result.sounds.append(sound); + } + qDebug() << "- " << aZoneFileStream->device()->pos(); + + return result; +} + +void ZoneFile_COD5::pParseAsset_ColMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_GameMapSP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_GameMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_LightDef(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_UIMap(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_AIType(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_FX(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Animation ZoneFile_COD5::pParseAsset_Animation(QDataStream *aZoneFileStream) { + Animation result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.dataByteCount + >> result.dataShortCount + >> result.dataIntCount + >> result.randomDataByteCount + >> result.randomDataIntCount + >> result.numframes + >> result.isLooped + >> result.isDelta + >> result.noneRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.normalTranslatedBoneCount + >> result.preciseTranslatedBoneCount + >> result.staticTranslatedBoneCount + >> result.noneTranslatedBoneCount + >> result.totalBoneCount + >> result.otherBoneCount1 + >> result.otherBoneCount2 + >> result.notifyCount + >> result.assetType + >> result.pad + >> result.randomDataShortCount + >> result.indexCount + >> result.frameRate + >> result.frequency + >> result.boneIDsPtr + >> result.dataBytePtr + >> result.dataShortPtr + >> result.dataIntPtr + >> result.randomDataShortPtr + >> result.randomDataBytePtr + >> result.randomDataIntPtr + >> result.longIndiciesPtr + >> result.notificationsPtr + >> result.deltaPartsPtr; + + // Read in x_anim file name + QString xAnimName; + char xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + while (xAnimNameChar != 0) { + result.name += xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + } + + // Parse x_anim index header + QVector sectionLengths; + for (int i = 0; i < result.numframes; i++) { + quint8 sectionlength; + *aZoneFileStream >> sectionlength; + sectionLengths.push_back(sectionlength); + // Skip padding + aZoneFileStream->skipRawData(1); + } + // Skip unknown section + aZoneFileStream->skipRawData(2 * 8); + + return result; +} + +MenuFile ZoneFile_COD5::pParseAsset_MenuFile(QDataStream *aZoneFileStream) { + //MENU_FILE + MenuFile result; + + aZoneFileStream->skipRawData(4); // Separator + + // Parse menu def count + *aZoneFileStream >> result.menuCount; + + // Clearly misparsed, never have this much + if (result.menuCount > 1000) { + qDebug() << "Failure reported when parsing menu file."; + return result; + } + for (uint i = 0; i < result.menuCount; i++) { + Menu menu; + + aZoneFileStream->skipRawData(4); // Separator + + // Read in x_anim file name + char menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + while (menuFilepathChar != 0) { + menu.filePath += menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + } + aZoneFileStream->skipRawData(4); // Separator + + *aZoneFileStream >> menu.menuNamePtr; + + float menuRectX, menuRectY, menuRectWidth, menuRectHeight; + *aZoneFileStream >> menuRectX >> menuRectY >> menuRectWidth >> menuRectHeight; + menu.rect = QRectF(menuRectX, menuRectY, menuRectWidth, menuRectHeight); + + quint32 hAlignInt, vAlignInt; + *aZoneFileStream >> hAlignInt >> vAlignInt; + menu.hAlign = (MENU_H_ALIGNMENT)hAlignInt; + menu.vAlign = (MENU_V_ALIGNMENT)vAlignInt; + + float rectClientX, rectClientY, rectClientWidth, rectClientHeight; + *aZoneFileStream >> rectClientX >> rectClientY >> rectClientWidth >> rectClientHeight; + menu.clientRect = QRectF(rectClientX, rectClientY, rectClientWidth, rectClientHeight); + + quint32 hClientAlignInt, vClientAlignInt, styleInt, borderInt; + *aZoneFileStream >> hClientAlignInt >> vClientAlignInt >> menu.groupPtr + >> styleInt >> borderInt >> menu.ownerDraw >> menu.ownerDrawFlags + >> menu.borderSize >> menu.staticFlags >> menu.dynamicFlags >> menu.nextTime; + menu.hClientAlign = (MENU_H_ALIGNMENT)hClientAlignInt; + menu.vClientAlign = (MENU_V_ALIGNMENT)vClientAlignInt; + menu.style = (MENU_WINDOW_STYLE)styleInt; + menu.border = (MENU_WINDOW_BORDER)borderInt; + + float foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA, + backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA, + borderColorR, borderColorG, borderColorB, borderColorA, + outlineColorR, outlineColorG, outlineColorB, outlineColorA; + *aZoneFileStream >> foregroundColorR >> foregroundColorG >> foregroundColorB >> foregroundColorA + >> backgroundColorR >> backgroundColorG >> backgroundColorB >> backgroundColorA + >> borderColorR >> borderColorG >> borderColorB >> borderColorA + >> outlineColorR >> outlineColorG >> outlineColorB >> outlineColorA; + + menu.foregroundColor = QColor(foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA); + menu.backgroundColor = QColor(backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA); + menu.borderColor = QColor(borderColorR, borderColorG, borderColorB, borderColorA); + menu.outlineColor = QColor(outlineColorR, outlineColorG, outlineColorB, outlineColorA); + + *aZoneFileStream >> menu.materialPtr >> menu.fontPtr >> menu.fullScreen >> menu.itemCount + >> menu.fontIndex >> menu.cursorItem >> menu.fadeCycle >> menu.fadeClamp + >> menu.fadeAmount >> menu.fadeInAmount >> menu.blurRadius >> menu.onOpenPtr + >> menu.onFocusPtr >> menu.onClosePtr >> menu.onESCPtr >> menu.onKeyPtr + >> menu.visibleExpCount >> menu.expEntryPtr >> menu.allowedBindingPtr + >> menu.soundNamePtr >> menu.imageTrack; + + float focusColorR, focusColorG, focusColorB, focusColorA, + disabledColorR, disabledColorG, disabledColorB, disabledColorA; + *aZoneFileStream >> focusColorR >> focusColorG >> focusColorB >> focusColorA + >> disabledColorR >> disabledColorG >> disabledColorB >> disabledColorA; + menu.focusColor = QColor(focusColorR, focusColorG, focusColorB, focusColorA); + menu.disabledColor = QColor(disabledColorR, disabledColorG, disabledColorB, disabledColorA); + + *aZoneFileStream >> menu.rectXExpCount >> menu.rectXExpPtr >> menu.rectYExpCount >> menu.rectYExpPtr; + + aZoneFileStream->skipRawData(4); // Separator + + char menuDefNameChar; + int menuDefNameLen = 0; + *aZoneFileStream >> menuDefNameChar; + while (menuDefNameChar != 0 && menuDefNameLen < 30) { + menuDefNameLen++; + menu.name += menuDefNameChar; + *aZoneFileStream >> menuDefNameChar; + } + + char defStringChar; + int defStringLen = 0; + *aZoneFileStream >> defStringChar; + while (defStringChar != 0 && defStringLen < 30) { + defStringLen++; + menu.definition += defStringChar; + *aZoneFileStream >> defStringChar; + } + aZoneFileStream->skipRawData(4 * 10); + + *aZoneFileStream >> menu.itemWindowDefNamePtr; + + float itemRectX, itemRectY, itemRectWidth, itemRectHeight; + *aZoneFileStream >> itemRectX >> itemRectY >> itemRectWidth >> itemRectHeight; + menu.itemRect = QRectF(itemRectX, itemRectY, itemRectWidth, itemRectHeight); + + *aZoneFileStream >> menu.itemHAlignment >> menu.itemVAlignment >> menu.itemGroupPtr + >> menu.itemWindowStyle >> menu.itemWindowBorder >> menu.itemOwnerDraw + >> menu.itemOwnerDrawFlags >> menu.itemBorderSize >> menu.itemStaticFlags + >> menu.itemDynamicFlags >> menu.itemNextTime; + + float itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA, + itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA, + itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA, + itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA; + *aZoneFileStream >> itemForegroundColorR >> itemForegroundColorG >> itemForegroundColorB >> itemForegroundColorA + >> itemBackgroundColorR >> itemBackgroundColorG >> itemBackgroundColorB >> itemBackgroundColorA + >> itemBorderColorR >> itemBorderColorG >> itemBorderColorB >> itemBorderColorA + >> itemOutlineColorR >> itemOutlineColorG >> itemOutlineColorB >> itemOutlineColorA; + + menu.itemForegroundColor = QColor(itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA); + menu.itemBackgroundColor = QColor(itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA); + menu.itemBorderColor = QColor(itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA); + menu.itemOutlineColor = QColor(itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA); + + *aZoneFileStream >> menu.itemMaterialPtr; + + float itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight; + *aZoneFileStream >> itemTextRectX >> itemTextRectY >> itemTextRectWidth >> itemTextRectHeight; + menu.itemTextRect = QRectF(itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight); + + quint32 hItemTextAlignInt, vItemTextAlignInt, itemType, fontTypeInt, textStyleInt; + *aZoneFileStream >> hItemTextAlignInt >> vItemTextAlignInt >> itemType >> menu.dataType + >> menu.alignment >> fontTypeInt >> menu.textAlignMode >> menu.textalignx >> menu.textaligny + >> menu.textscale >> textStyleInt >> menu.gameMsgWindowIndex >> menu.gameMsgWindowMode + >> menu.testPtr >> menu.textSavegameInfo >> menu.parentPtr; + menu.itemText_hAlign = (MENU_H_ALIGNMENT)hItemTextAlignInt; + menu.itemText_vAlign = (MENU_V_ALIGNMENT)vItemTextAlignInt; + menu.itemType = (MENU_ITEM_TYPE)itemType; + menu.fontEnum = (MENU_FONT_TYPE)fontTypeInt; + menu.textStyle = (MENU_ITEM_TEXTSTYLE)textStyleInt; + + *aZoneFileStream >> menu.mouseEnterText >> menu.mouseExitText >> menu.mouseEnter >> menu.mouseExit + >> menu.action >> menu.onAccept >> menu.onFocus >> menu.leaveFocus >> menu.dvar >> menu.dvarTest + >> menu.keyHandlerPtr >> menu.enableDvarPtr >> menu.dvarFlags >> menu.focusSoundPtr + >> menu.special >> menu.cursorPos; + + // itemDefData_t typeData; + + // listBoxDef_s *listBox; + + *aZoneFileStream >> menu.startPos >> menu.endPos >> menu.drawPadding; + + *aZoneFileStream >> menu.elementWidth >> menu.elementHeight; + + *aZoneFileStream >> menu.elementStyle >> menu.numColumns; + + //columnInfo_s columnInfo[16]; + + *aZoneFileStream >> menu.doubleClickPtr; + + + *aZoneFileStream >> menu.notselectable >> menu.noScrollBars >> menu.usePaging; + + float itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA, + itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA, + itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA; + *aZoneFileStream >> itemSelectBorderColorR >> itemSelectBorderColorG >> itemSelectBorderColorB >> itemSelectBorderColorA + >> itemDisableColorR >> itemDisableColorG >> itemDisableColorB >> itemDisableColorA + >> itemFocusColorR >> itemFocusColorG >> itemFocusColorB >> itemFocusColorA; + menu.itemSelectBorderColor = QColor(itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA); + menu.itemDisableColor = QColor(itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA); + menu.itemFocusColor = QColor(itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA); + + *aZoneFileStream >> menu.selectIconPtr >> menu.backgroundItemListboxPtr >> menu.highlightTexturePtr; + + // editFieldDef_s *editField; + + *aZoneFileStream >> menu.minVal >> menu.maxVal >> menu.defVal >> menu.range >> menu.maxChars + >> menu.maxCharsGotoNext >> menu.maxPaintChars >> menu.paintOffset; + + // multiDef_s *multi; + + for (int i = 0; i < 32; i++) { + quint32 dvarList; + *aZoneFileStream >> dvarList; + menu.dvarListPtrs.push_back(dvarList); + } + + for (int i = 0; i < 32; i++) { + quint32 dvarStr; + *aZoneFileStream >> dvarStr; + menu.dvarStrPtrs.push_back(dvarStr); + } + + for (int i = 0; i < 32; i++) { + float dvarValue; + *aZoneFileStream >> dvarValue; + menu.dvarValues.push_back(dvarValue); + } + + *aZoneFileStream >> menu.count >> menu.strDef >> menu.enumDvarNamePtr; + aZoneFileStream->skipRawData(4); + //>> menu.dataPtr + *aZoneFileStream >> menu.itemImageTrack; + + qDebug() << aZoneFileStream->device()->pos(); + + //statement_s visibleExp; + //statement_s textExp; + //statement_s materialExp; + //statement_s rectXExp; + //statement_s rectYExp; + //statement_s rectWExp; + //statement_s rectHExp; + //statement_s foreColorAExp; + result.menuDefs << menu; + } + return result; +} + +void ZoneFile_COD5::pParseAsset_Weapon(QDataStream *aZoneFileStream) { + //WEAPON_FILE + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD5::pParseAsset_D3DBSP(QDataStream *aZoneFileStream) { + //D3DBSP_DUMP + Q_UNUSED(aZoneFileStream); +} + +StringTable ZoneFile_COD5::pParseAsset_StringTable(QDataStream *aZoneFileStream) { + StringTable result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.columnCount + >> result.rowCount; + + // Todo fix this + result.columnCount = 0; + result.rowCount = 0; + + aZoneFileStream->skipRawData(4); + + QString stringTableName; + char stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + while (stringTableNameChar != 0) { + result.name += stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + } + + for (quint32 i = 0; i < result.rowCount; i++) { + QByteArray pointerData(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pointerData.data(), 4); + result.tablePointers.push_back(pointerData.toHex()); + + aZoneFileStream->skipRawData(4); + } + + for (const QString &pointerAddr : result.tablePointers) { + QString leadingContent = ""; + if (pointerAddr == "FFFFFFFF") { + char leadingContentChar; + *aZoneFileStream >> leadingContentChar; + while (leadingContentChar != 0) { + leadingContent += leadingContentChar; + *aZoneFileStream >> leadingContentChar; + } + } else { + leadingContent = pointerAddr; + } + + QString content; + char contentChar; + *aZoneFileStream >> contentChar; + while (contentChar != 0) { + content += contentChar; + *aZoneFileStream >> contentChar; + } + result.content[leadingContent] = content; + } + return result; +} + +QString ZoneFile_COD5::AssetTypeToString(const QString aAssetType) { + const QString cleanedType = aAssetType.toUpper(); + if (cleanedType == "17000000") { // localized string PARTIALLY VERIFIED + return "RAW FILE"; + } else if (cleanedType == "20000000") { // raw_file PARTIALLY VERIFIED + return "GSC FILE"; + } else if (cleanedType == "1A000000") { // fx PARTIALLY VERIFIED + return "EFFECT"; + } else if (cleanedType == "09000000") { // loaded_sound PARTIALLY VERIFIED + return "SOUND"; + } else if (cleanedType == "04000000") { // x_anim PARTIALLY VERIFIED + return "ANIMATION"; + } else if (cleanedType == "0C000000") { // collision_map PARTIALLY VERIFIED + return "COLLISION MAP"; + } else if (cleanedType == "21000000") { // string_table PARTIALLY VERIFIED + return "STRING TABLE"; + } else if (cleanedType == "15000000") { // menu_file PARTIALLY VERIFIED + return "MENU"; + } else if (cleanedType == "07000000") { // tech set PARTIALLY VERIFIED + return "TECH SET"; + } else if (cleanedType == "18000000") { // weapon PARTIALLY VERIFIED + return "WEAPON"; + } else if (cleanedType == "11000000") { // gfx map PARTIALLY VERIFIED + return "GFX MAP"; + } else if (cleanedType == "12000000") { // light_def PARTIALLY VERIFIED + return "LIGHT DEF"; + } else if (cleanedType == "14000000") { // font PARTIALLY VERIFIED + return "FONT"; + } else if (cleanedType == "05000000") { // xmodel PARTIALLY VERIFIED + return "MODEL"; + } else if (cleanedType == "0D000000") { // d3dbsp PARTIALLY VERIFIED + return "D3DBSP"; + } else if (cleanedType == "06000000") { // image PARTIALLY VERIFIED + return "IMAGE"; + } else if (cleanedType == "0E000000") { // game map sp PARTIALLY VERIFIED + return "GAME MAP SP"; + } else if (cleanedType == "0B000000") { // col map sp PARTIALLY VERIFIED + return "COL MAP SP"; + } else if (cleanedType == "01000000") { // physics preset PARTIALLY VERIFIED + return "PHYS PRESET"; + } else if (cleanedType == "03000000") { // destructible def PARTIALLY VERIFIED + return "DESTRUCTIBLE"; + } + return aAssetType; +} + +QByteArray ZoneFile_COD5::GetBinaryData() { + QByteArray result; + + return result; +} diff --git a/libs/zonefile/zonefile_cod5.h b/libs/zonefile/zonefile_cod5.h new file mode 100644 index 0000000..b7294fb --- /dev/null +++ b/libs/zonefile/zonefile_cod5.h @@ -0,0 +1,54 @@ +#ifndef ZONEFILE_COD5_H +#define ZONEFILE_COD5_H + +#include + +#include "zonefile.h" + +class ZoneFile_COD5 : public ZoneFile +{ +public: + ZoneFile_COD5(); + ~ZoneFile_COD5(); + + bool Load(const QByteArray aFileData, FF_PLATFORM aPlatform) override; + QString AssetTypeToString(const QString aAssetType) override; + + QByteArray GetBinaryData() override; + +private: + void pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) override; + quint32 pParseZoneSize(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsA(QDataStream *aZoneFileStream) override; + quint32 pParseZoneTagCount(QDataStream *aZoneFileStream) override; + quint32 pParseZoneRecordCount(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsB(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsC(QDataStream *aZoneFileStream) override; + QStringList pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) override; + QStringList pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) override; + AssetMap pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) override; + LocalString pParseAsset_LocalString(QDataStream *aZoneFileStream) override; + RawFile pParseAsset_RawFile(QDataStream *aZoneFileStream) override; + void pParseAsset_PhysPreset(QDataStream *aZoneFileStream) override; + Model pParseAsset_Model(QDataStream *aZoneFileStream) override; + Material pParseAsset_Material(QDataStream *aZoneFileStream) override; + Shader pParseAsset_Shader(QDataStream *aZoneFileStream) override; + TechSet pParseAsset_TechSet(QDataStream *aZoneFileStream) override; + Image pParseAsset_Image(QDataStream *aZoneFileStream) override; + SoundAsset pParseAsset_Sound(QDataStream *aZoneFileStream) override; + void pParseAsset_ColMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapSP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_LightDef(QDataStream *aZoneFileStream) override; + void pParseAsset_UIMap(QDataStream *aZoneFileStream) override; + void pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) override; + void pParseAsset_AIType(QDataStream *aZoneFileStream) override; + void pParseAsset_FX(QDataStream *aZoneFileStream) override; + Animation pParseAsset_Animation(QDataStream *aZoneFileStream) override; + MenuFile pParseAsset_MenuFile(QDataStream *aZoneFileStream) override; + void pParseAsset_Weapon(QDataStream *aZoneFileStream) override; + void pParseAsset_D3DBSP(QDataStream *aZoneFileStream) override; + StringTable pParseAsset_StringTable(QDataStream *aZoneFileStream) override; +}; + +#endif // ZONEFILE_COD5_H diff --git a/libs/zonefile/zonefile_cod7.cpp b/libs/zonefile/zonefile_cod7.cpp new file mode 100644 index 0000000..a6d6988 --- /dev/null +++ b/libs/zonefile/zonefile_cod7.cpp @@ -0,0 +1,1103 @@ +#include "zonefile_cod7.h" + +#include +#include +#include + +ZoneFile_COD7::ZoneFile_COD7() +{ + +} + +ZoneFile_COD7::~ZoneFile_COD7() +{ + +} + +bool ZoneFile_COD7::Load(const QByteArray aFileData, FF_PLATFORM aPlatform) { + // Open zone file as little endian stream + QDataStream zoneFileStream(aFileData); + if (aPlatform == FF_PLATFORM_PC) { + zoneFileStream.setByteOrder(QDataStream::LittleEndian); + } else { + zoneFileStream.setByteOrder(QDataStream::BigEndian); + } + + // Parse data from zone file header + pParseZoneHeader(&zoneFileStream, aPlatform); + zoneFileStream.device()->seek(zoneFileStream.device()->pos() - 1); + SetRecords(pParseZoneIndex(&zoneFileStream, GetRecordCount())); + SetAssetMap(pParseAssets(&zoneFileStream, GetRecords())); + + return true; +} + +void ZoneFile_COD7::pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) { + quint32 size = pParseZoneSize(aZoneFileStream); + SetSize(size); + + if (aPlatform == FF_PLATFORM_WII) { + aZoneFileStream->skipRawData(36); + } else { + pParseZoneUnknownsA(aZoneFileStream); + } + + quint32 tagCount = pParseZoneTagCount(aZoneFileStream); + SetTagCount(tagCount); + if (aPlatform == FF_PLATFORM_WII) { + SetTagCount(GetTagCount() - 1); + } + + pParseZoneUnknownsB(aZoneFileStream); + + quint32 recordCount = pParseZoneRecordCount(aZoneFileStream); + SetRecordCount(recordCount); + + if (tagCount) { + pParseZoneUnknownsC(aZoneFileStream); + SetTags(pParseZoneTags(aZoneFileStream, tagCount)); + } else { + aZoneFileStream->skipRawData(4); + } +} + +quint32 ZoneFile_COD7::pParseZoneSize(QDataStream *aZoneFileStream) { + quint32 zoneFileSize; + *aZoneFileStream >> zoneFileSize; + if (zoneFileSize <= 0) { + qDebug() << "Tried to open empty zone file!"; + exit(-1); + } + zoneFileSize += 36; + return zoneFileSize; +} + +/* + ParseZoneUnknownsA() + + Parses the 1st section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD7::pParseZoneUnknownsA(QDataStream *aZoneFileStream) { + // Byte 4-7, 8-11, 12-15: unknown + QByteArray unknown1(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown1.data(), 4); + + QByteArray unknown2(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown2.data(), 4); + + QByteArray unknown3(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown3.data(), 4); + + // Byte 16-19, 20-23: empty/unknown + QByteArray unknown4(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown4.data(), 4); + + QByteArray unknown5(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown5.data(), 4); + + // Byte 24-27: somehow related to the filesize, but smaller value + QByteArray unknown6(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown6.data(), 4); + + // Byte 28-31, 32-35: unknown + QByteArray unknown7(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown7.data(), 4); + + QByteArray unknown8(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown8.data(), 4); +} + +/* + ParseZoneTagCount() + + Parses the number of string tags in the zone index +*/ +quint32 ZoneFile_COD7::pParseZoneTagCount(QDataStream *aZoneFileStream) { + quint32 tagCount; + *aZoneFileStream >> tagCount; + return tagCount; +} + +/* + ParseZoneRecordCount() + + Parses the number of records in the zone index +*/ +quint32 ZoneFile_COD7::pParseZoneRecordCount(QDataStream *aZoneFileStream) { + quint32 recordCount; + *aZoneFileStream >> recordCount; + return recordCount; +} + +/* + ParseZoneUnknownsB() + + Parses the 2nd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD7::pParseZoneUnknownsB(QDataStream *aZoneFileStream) { + // Byte 44-47: Unknown/empty? + QByteArray unknown9(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown9.data(), 4); +} + +/* + pParseZoneUnknownsC() + + Parses the 3rd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD7::pParseZoneUnknownsC(QDataStream *aZoneFileStream) { + // Byte 40-43: Unknown/empty? + QByteArray unknown10(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown10.data(), 4); + + // Byte 44-47: Unknown/empty? + QByteArray unknown11(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown11.data(), 4); +} + +/* + ParseZoneTags() + + Parses the string tags ate the start of zone file +*/ +QStringList ZoneFile_COD7::pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) { + QStringList tags; + + // Byte 48-51: Repeated separators? ÿÿÿÿ x i + aZoneFileStream->skipRawData(4 * (tagCount - 1)); + + // Parse tags/strings before index + QString zoneTag; + char zoneTagChar; + for (quint32 i = 0; i < tagCount; i++) { + *aZoneFileStream >> zoneTagChar; + while (zoneTagChar != 0) { + zoneTag += zoneTagChar; + *aZoneFileStream >> zoneTagChar; + } + tags << zoneTag; + zoneTag.clear(); + } + return tags; +} + +/* + ParseZoneIndex() + + Parse the binary zone index data and populate table +*/ +QStringList ZoneFile_COD7::pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) { + QStringList result; + + // Don't parse if no records + if (!recordCount) { return result; } + + if (aZoneFileStream->device()->peek(4).toHex().contains("ffff")) { + aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 2); + } + + // Parse index & map found asset types + for (quint32 i = 0; i <= recordCount; i++) { + // Skip record start + QByteArray rawAssetType(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rawAssetType.data(), 4); + result << rawAssetType.toHex(); + + // Skip separator + aZoneFileStream->skipRawData(4); + } + return result; +} + +AssetMap ZoneFile_COD7::pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) { + AssetMap result; + + aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 8); + + for (int i = 0; i < assetOrder.size(); i++) { + const QString typeHex = assetOrder[i]; + const QString typeStr = AssetTypeToString(typeHex); + + if (typeStr == "LOCAL STRING") { // localized string asset + result.localStrings << pParseAsset_LocalString(aZoneFileStream); + } else if (typeStr == "RAW FILE") { // gsc + auto rawFile = pParseAsset_RawFile(aZoneFileStream); + if (rawFile.length) { + result.rawFiles << rawFile; + } + } else if (typeStr == "PHYS PRESET") { // physpreset + pParseAsset_PhysPreset(aZoneFileStream); + } else if (typeStr == "MODEL") { // xmodel + result.models << pParseAsset_Model(aZoneFileStream); + } else if (typeStr == "MATERIAL") { // material + pParseAsset_Material(aZoneFileStream); + } else if (typeStr == "SHADER") { // pixelshader + pParseAsset_Shader(aZoneFileStream); + } else if (typeStr == "TECH SET") { // techset include + result.techSets << pParseAsset_TechSet(aZoneFileStream); + } else if (typeStr == "IMAGE") { // image + result.images << pParseAsset_Image(aZoneFileStream); + } else if (typeStr == "SOUND") { // loaded_sound + result.sounds << pParseAsset_Sound(aZoneFileStream); + } else if (typeStr == "COLLISION MAP") { // col_map_mp + pParseAsset_ColMapMP(aZoneFileStream); + } else if (typeStr == "MP MAP") { // game_map_sp + pParseAsset_GameMapSP(aZoneFileStream); + } else if (typeStr == "SP MAP") { // game_map_mp + pParseAsset_GameMapMP(aZoneFileStream); + } else if (typeStr == "LIGHT DEF") { // lightdef + pParseAsset_LightDef(aZoneFileStream); + } else if (typeStr == "UI MAP") { // ui_map + pParseAsset_UIMap(aZoneFileStream); + } else if (typeStr == "SND DRIVER GLOBALS") { // snddriverglobals + pParseAsset_SNDDriverGlobals(aZoneFileStream); + } else if (typeStr == "AI TYPE") { // aitype + pParseAsset_AIType(aZoneFileStream); + } else if (typeStr == "EFFECT") { // aitype + pParseAsset_FX(aZoneFileStream); + } else if (typeStr == "ANIMATION") { // aitype + result.animations << pParseAsset_Animation(aZoneFileStream); + } else if (typeStr == "STRING TABLE") { // string_table + result.stringTables << pParseAsset_StringTable(aZoneFileStream); + } else if (typeStr == "MENU") { // string_table + result.menuFiles << pParseAsset_MenuFile(aZoneFileStream); + } else if (typeStr == "WEAPON") { // string_table + pParseAsset_Weapon(aZoneFileStream); + } else if (typeStr == "D3DBSP DUMP") { // string_table + pParseAsset_D3DBSP(aZoneFileStream); + } else if (typeStr != "UNKNOWN") { + qDebug() << "Found bad asset type!" << typeStr; + } + } + return result; +} + +LocalString ZoneFile_COD7::pParseAsset_LocalString(QDataStream *aZoneFileStream) { + LocalString result; + + quint32 stringPtr, aliasPtr; + *aZoneFileStream >> stringPtr >> aliasPtr; + if (stringPtr == 4294967295) { + // Parse local string asset contents + QString localStr; + char localStrChar; + *aZoneFileStream >> localStrChar; + while (localStrChar != 0) { + result.string += localStrChar; + *aZoneFileStream >> localStrChar; + } + } else { + result.string = "String Ptr: " + QString::number(stringPtr); + } + + if (aliasPtr == 4294967295) { + // Parse rawfile name + QString aliasName; + char aliasNameChar; + *aZoneFileStream >> aliasNameChar; + while (aliasNameChar != 0) { + result.alias += aliasNameChar; + *aZoneFileStream >> aliasNameChar; + } + } else { + result.string = "Alias Ptr: " + QString::number(aliasPtr); + } + + return result; +} + +RawFile ZoneFile_COD7::pParseAsset_RawFile(QDataStream *aZoneFileStream) { + RawFile result; + + // Skip start separator FF FF FF FF (pointer?) + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.length; + + // Skip unknown 4 byte data + aZoneFileStream->skipRawData(4); + + // Parse rawfile path + char scriptPathChar; + *aZoneFileStream >> scriptPathChar; + while (scriptPathChar != 0) { + result.path += scriptPathChar; + *aZoneFileStream >> scriptPathChar; + } + result.path.replace(",", ""); + const QStringList pathParts = result.path.split('/'); + if (pathParts.size() == 0) { + qDebug() << "Failed to parse ff path! " << result.path; + exit(-1); + } + + // Parse gsc contents + char rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + while (rawFileContentsChar != 0 && rawFileContentsChar != -1) { + result.contents += rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + } + return result; +} + +void ZoneFile_COD7::pParseAsset_PhysPreset(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Model ZoneFile_COD7::pParseAsset_Model(QDataStream *aZoneFileStream) { + Model result; + + qDebug() << "Model Info:"; + + *aZoneFileStream >> result.namePtr >> result.tagCount >> result.rootTagCount + >> result.surfCount >> result.unknownCount >> result.boneNamePtr + >> result.parentListPtr >> result.quatsPtr >> result.transPtr + >> result.partClassPtr >> result.baseMatPtr + >> result.surfsPtr >> result.materialHandlesPtr; + + // Parse XModelLodInfo + for (int i = 1; i <= 4; i++) { + qDebug() << "- Lod Info " << i; + + quint32 intDist; + *aZoneFileStream >> intDist; + + std::memcpy(&result.lodInfo[i].dist, &intDist, sizeof(result.lodInfo[i].dist)); + *aZoneFileStream >> result.lodInfo[i].numsurfs >> result.lodInfo[i].surfIndex; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.lodInfo[i].partBits[0] + >> result.lodInfo[i].partBits[1] + >> result.lodInfo[i].partBits[2] + >> result.lodInfo[i].partBits[3]; + } + + *aZoneFileStream >> result.collSurfsPtr >> result.numCollSurfs >> result.contents >> result.boneInfoPtr; + + quint32 intRadius, intMins[3], intMaxs[3]; + *aZoneFileStream >> intRadius >> intMins[0] >> intMins[1] + >> intMins[2] >> intMaxs[0] >> intMaxs[1] >> intMaxs[2]; + + std::memcpy(&result.radius, &intRadius, sizeof(result.radius)); + + std::memcpy(&result.mins[0], &intMins[0], sizeof(result.mins[0])); + std::memcpy(&result.mins[1], &intMins[1], sizeof(result.mins[1])); + std::memcpy(&result.mins[2], &intMins[2], sizeof(result.mins[2])); + + std::memcpy(&result.maxs[0], &intMaxs[0], sizeof(result.maxs[0])); + std::memcpy(&result.maxs[1], &intMaxs[1], sizeof(result.maxs[2])); + std::memcpy(&result.maxs[2], &intMaxs[2], sizeof(result.maxs[3])); + + *aZoneFileStream >> result.numLods >> result.collLod >> result.streamInfoPtr + >> result.memUsage >> result.flags >> result.physPresetPtr >> result.physGeomsPtr; + + // Parse model name + char modelNameChar; + *aZoneFileStream >> modelNameChar; + while (modelNameChar == 0) { + *aZoneFileStream >> modelNameChar; + } + while (modelNameChar != 0) { + result.modelName += modelNameChar; + *aZoneFileStream >> modelNameChar; + } + return result; +} + +Material ZoneFile_COD7::pParseAsset_Material(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); + + return Material(); +} + +Shader ZoneFile_COD7::pParseAsset_Shader(QDataStream *aZoneFileStream) { + Shader result = Shader(); + + quint8 minorVersion, majorVersion; + *aZoneFileStream >> minorVersion >> majorVersion; + + quint32 magic; + *aZoneFileStream >> magic; + + // Verify .fxc magic + if (magic != 65534 && magic != 65535) { return result; } + + SHADER_TYPE type = SHADER_NONE; + quint16 rawShaderType; + *aZoneFileStream >> rawShaderType; + if (rawShaderType == 65535) { // Pixel shader + type = SHADER_PIXEL; + } else if (rawShaderType == 65534) { // Vertex shader + type = SHADER_VERTEX; + } + Q_UNUSED(type); + + while (true) { + quint32 instructionToken; + *aZoneFileStream >> instructionToken; + + SHADER_OPCODE opCode = (SHADER_OPCODE)(instructionToken & 0xffff); + + int size; + if (opCode == OPCODE_End) { + break; + } else if (opCode == OPCODE_Comment) { + size = (int)((instructionToken >> 16) & 0x7FFF); + } else { + size = (int)((instructionToken >> 24) & 0x0f); + } + Q_UNUSED(size); + } + + + return result; +} + +TechSet ZoneFile_COD7::pParseAsset_TechSet(QDataStream *aZoneFileStream) { + TechSet result; + + for (int i = 1; i <= 62; i++) { + quint32 ptr; + *aZoneFileStream >> ptr; + + result.pointers << ptr; + } + qDebug() << aZoneFileStream->device()->pos(); + + // Parse techset name + char techSetNameChar; + *aZoneFileStream >> techSetNameChar; + while (techSetNameChar != 0) { + result.name += techSetNameChar; + *aZoneFileStream >> techSetNameChar; + } + result.name.replace(",", ""); + + return result; +} + +Image ZoneFile_COD7::pParseAsset_Image(QDataStream *aZoneFileStream) { + Image result; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknowna >> result.unknownb + >> result.unknownc >> result.unknownd + >> result.unknowne >> result.unknownf + >> result.unknowng; + + aZoneFileStream->skipRawData(15 * 4); + *aZoneFileStream >> result.unknownh >> result.unknowni; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknownj; + + aZoneFileStream->skipRawData(4); + + char materialNameChar; + *aZoneFileStream >> materialNameChar; + while (materialNameChar != 0) { + result.materialName += materialNameChar; + *aZoneFileStream >> materialNameChar; + } + result.materialName.replace(",", ""); + + if (result.unknowna) { + *aZoneFileStream >> result.unknownk; + *aZoneFileStream >> result.unknownl; + *aZoneFileStream >> result.unknownm; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown1; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown2 >> result.unknown3 + >> result.size1 >> result.size2 + >> result.unknown4 >> result.unknown5; + + aZoneFileStream->skipRawData(4); + + char imageNameChar; + *aZoneFileStream >> imageNameChar; + while (imageNameChar != 0) { + result.name += imageNameChar; + *aZoneFileStream >> imageNameChar; + } + + *aZoneFileStream >> result.unknown6 >> result.unknown7; + + QByteArray compressionData(8, Qt::Uninitialized); + aZoneFileStream->readRawData(compressionData.data(), 8); + if (compressionData.contains("DXT1")) { + result.compression = COMPRESSION_DXT1; + } else if (compressionData.contains("DXT3")) { + result.compression = COMPRESSION_DXT3; + } else if (compressionData.contains("DXT5")) { + result.compression = COMPRESSION_DXT5; + } else { + result.compression = COMPRESSION_NONE; + } + + *aZoneFileStream >> result.unknown8 >> result.unknown9; + } + + return result; +} + +SoundAsset ZoneFile_COD7::pParseAsset_Sound(QDataStream *aZoneFileStream) { + SoundAsset result; + + qDebug() << aZoneFileStream->device()->pos(); + + QByteArray rootNamePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rootNamePtr.data(), 4); + qDebug() << "Root name ptr: " << (QString)rootNamePtr.toHex(); + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.count; + + if (rootNamePtr.toHex() == "ffffffff") { + // Read in sound file name + char soundNameChar; + *aZoneFileStream >> soundNameChar; + while (soundNameChar != 0) { + result.name += soundNameChar; + *aZoneFileStream >> soundNameChar; + } + } + + int tagCount = 0; + int resultCount = 0; + for (quint32 i = 0; i < result.count; i++) { + aZoneFileStream->skipRawData(12); + + QByteArray tagPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(tagPtr.data(), 4); + + if (tagPtr.toHex() == "ffffffff") { + qDebug() << "Tag Ptr: " << tagPtr.toHex(); + tagCount++; + } + aZoneFileStream->skipRawData(4); + + QByteArray pathPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pathPtr.data(), 4); + + if (pathPtr.toHex() == "ffffffff") { + qDebug() << "Path Ptr: " << pathPtr.toHex(); + resultCount++; + } + + aZoneFileStream->skipRawData(160); + } + + for (int i = 0; i < tagCount; i++) { + // Read in tag? + QString tag; + char tagChar; + *aZoneFileStream >> tagChar; + while (tagChar != 0) { + tag += tagChar; + *aZoneFileStream >> tagChar; + } + qDebug() << "Tag: " << tag; + } + + for (int i = 0; i < resultCount; i++) { + Sound sound; + + if (aZoneFileStream->device()->peek(12).toHex().contains("ffffffff00000000")) { + aZoneFileStream->skipRawData(12); + } + + aZoneFileStream->skipRawData(8); + + qDebug() << "- " << aZoneFileStream->device()->pos(); + QByteArray aliasPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(aliasPtr.data(), 4); + + QByteArray namePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(namePtr.data(), 4); + + *aZoneFileStream >> sound.dataLength; + qDebug() << "- Data length: " << sound.dataLength; + + if (aliasPtr.toHex() == "ffffffff") { + // Read in sound alias name + char soundAliasChar; + *aZoneFileStream >> soundAliasChar; + while (soundAliasChar != 0) { + sound.alias += soundAliasChar; + *aZoneFileStream >> soundAliasChar; + } + qDebug() << "- Alias: " << sound.alias; + } + + if (aZoneFileStream->device()->peek(4) == "RIFF") { + sound.path = sound.alias; + sound.alias = ""; + } else if (namePtr.toHex() == "ffffffff") { + // Read in sound file path + char soundPathChar; + *aZoneFileStream >> soundPathChar; + while (soundPathChar != 0) { + sound.path += soundPathChar; + *aZoneFileStream >> soundPathChar; + } + sound.path.replace(",", ""); + qDebug() << "- Path: " << sound.path; + } + + if (sound.dataLength) { + QByteArray data(sound.dataLength, Qt::Uninitialized); + aZoneFileStream->readRawData(data.data(), sound.dataLength); + sound.data = data; + } + result.sounds.append(sound); + } + qDebug() << "- " << aZoneFileStream->device()->pos(); + + return result; +} + +void ZoneFile_COD7::pParseAsset_ColMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_GameMapSP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_GameMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_LightDef(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_UIMap(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_AIType(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_FX(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Animation ZoneFile_COD7::pParseAsset_Animation(QDataStream *aZoneFileStream) { + Animation result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.dataByteCount + >> result.dataShortCount + >> result.dataIntCount + >> result.randomDataByteCount + >> result.randomDataIntCount + >> result.numframes + >> result.isLooped + >> result.isDelta + >> result.noneRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.normalTranslatedBoneCount + >> result.preciseTranslatedBoneCount + >> result.staticTranslatedBoneCount + >> result.noneTranslatedBoneCount + >> result.totalBoneCount + >> result.otherBoneCount1 + >> result.otherBoneCount2 + >> result.notifyCount + >> result.assetType + >> result.pad + >> result.randomDataShortCount + >> result.indexCount + >> result.frameRate + >> result.frequency + >> result.boneIDsPtr + >> result.dataBytePtr + >> result.dataShortPtr + >> result.dataIntPtr + >> result.randomDataShortPtr + >> result.randomDataBytePtr + >> result.randomDataIntPtr + >> result.longIndiciesPtr + >> result.notificationsPtr + >> result.deltaPartsPtr; + + // Read in x_anim file name + QString xAnimName; + char xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + while (xAnimNameChar != 0) { + result.name += xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + } + + // Parse x_anim index header + QVector sectionLengths; + for (int i = 0; i < result.numframes; i++) { + quint8 sectionlength; + *aZoneFileStream >> sectionlength; + sectionLengths.push_back(sectionlength); + // Skip padding + aZoneFileStream->skipRawData(1); + } + // Skip unknown section + aZoneFileStream->skipRawData(2 * 8); + + return result; +} + +MenuFile ZoneFile_COD7::pParseAsset_MenuFile(QDataStream *aZoneFileStream) { + //MENU_FILE + MenuFile result; + + aZoneFileStream->skipRawData(4); // Separator + + // Parse menu def count + *aZoneFileStream >> result.menuCount; + + // Clearly misparsed, never have this much + if (result.menuCount > 1000) { + qDebug() << "Failure reported when parsing menu file."; + return result; + } + for (uint i = 0; i < result.menuCount; i++) { + Menu menu; + + aZoneFileStream->skipRawData(4); // Separator + + // Read in x_anim file name + char menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + while (menuFilepathChar != 0) { + menu.filePath += menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + } + aZoneFileStream->skipRawData(4); // Separator + + *aZoneFileStream >> menu.menuNamePtr; + + float menuRectX, menuRectY, menuRectWidth, menuRectHeight; + *aZoneFileStream >> menuRectX >> menuRectY >> menuRectWidth >> menuRectHeight; + menu.rect = QRectF(menuRectX, menuRectY, menuRectWidth, menuRectHeight); + + quint32 hAlignInt, vAlignInt; + *aZoneFileStream >> hAlignInt >> vAlignInt; + menu.hAlign = (MENU_H_ALIGNMENT)hAlignInt; + menu.vAlign = (MENU_V_ALIGNMENT)vAlignInt; + + float rectClientX, rectClientY, rectClientWidth, rectClientHeight; + *aZoneFileStream >> rectClientX >> rectClientY >> rectClientWidth >> rectClientHeight; + menu.clientRect = QRectF(rectClientX, rectClientY, rectClientWidth, rectClientHeight); + + quint32 hClientAlignInt, vClientAlignInt, styleInt, borderInt; + *aZoneFileStream >> hClientAlignInt >> vClientAlignInt >> menu.groupPtr + >> styleInt >> borderInt >> menu.ownerDraw >> menu.ownerDrawFlags + >> menu.borderSize >> menu.staticFlags >> menu.dynamicFlags >> menu.nextTime; + menu.hClientAlign = (MENU_H_ALIGNMENT)hClientAlignInt; + menu.vClientAlign = (MENU_V_ALIGNMENT)vClientAlignInt; + menu.style = (MENU_WINDOW_STYLE)styleInt; + menu.border = (MENU_WINDOW_BORDER)borderInt; + + float foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA, + backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA, + borderColorR, borderColorG, borderColorB, borderColorA, + outlineColorR, outlineColorG, outlineColorB, outlineColorA; + *aZoneFileStream >> foregroundColorR >> foregroundColorG >> foregroundColorB >> foregroundColorA + >> backgroundColorR >> backgroundColorG >> backgroundColorB >> backgroundColorA + >> borderColorR >> borderColorG >> borderColorB >> borderColorA + >> outlineColorR >> outlineColorG >> outlineColorB >> outlineColorA; + + menu.foregroundColor = QColor(foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA); + menu.backgroundColor = QColor(backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA); + menu.borderColor = QColor(borderColorR, borderColorG, borderColorB, borderColorA); + menu.outlineColor = QColor(outlineColorR, outlineColorG, outlineColorB, outlineColorA); + + *aZoneFileStream >> menu.materialPtr >> menu.fontPtr >> menu.fullScreen >> menu.itemCount + >> menu.fontIndex >> menu.cursorItem >> menu.fadeCycle >> menu.fadeClamp + >> menu.fadeAmount >> menu.fadeInAmount >> menu.blurRadius >> menu.onOpenPtr + >> menu.onFocusPtr >> menu.onClosePtr >> menu.onESCPtr >> menu.onKeyPtr + >> menu.visibleExpCount >> menu.expEntryPtr >> menu.allowedBindingPtr + >> menu.soundNamePtr >> menu.imageTrack; + + float focusColorR, focusColorG, focusColorB, focusColorA, + disabledColorR, disabledColorG, disabledColorB, disabledColorA; + *aZoneFileStream >> focusColorR >> focusColorG >> focusColorB >> focusColorA + >> disabledColorR >> disabledColorG >> disabledColorB >> disabledColorA; + menu.focusColor = QColor(focusColorR, focusColorG, focusColorB, focusColorA); + menu.disabledColor = QColor(disabledColorR, disabledColorG, disabledColorB, disabledColorA); + + *aZoneFileStream >> menu.rectXExpCount >> menu.rectXExpPtr >> menu.rectYExpCount >> menu.rectYExpPtr; + + aZoneFileStream->skipRawData(4); // Separator + + char menuDefNameChar; + int menuDefNameLen = 0; + *aZoneFileStream >> menuDefNameChar; + while (menuDefNameChar != 0 && menuDefNameLen < 30) { + menuDefNameLen++; + menu.name += menuDefNameChar; + *aZoneFileStream >> menuDefNameChar; + } + + char defStringChar; + int defStringLen = 0; + *aZoneFileStream >> defStringChar; + while (defStringChar != 0 && defStringLen < 30) { + defStringLen++; + menu.definition += defStringChar; + *aZoneFileStream >> defStringChar; + } + aZoneFileStream->skipRawData(4 * 10); + + *aZoneFileStream >> menu.itemWindowDefNamePtr; + + float itemRectX, itemRectY, itemRectWidth, itemRectHeight; + *aZoneFileStream >> itemRectX >> itemRectY >> itemRectWidth >> itemRectHeight; + menu.itemRect = QRectF(itemRectX, itemRectY, itemRectWidth, itemRectHeight); + + *aZoneFileStream >> menu.itemHAlignment >> menu.itemVAlignment >> menu.itemGroupPtr + >> menu.itemWindowStyle >> menu.itemWindowBorder >> menu.itemOwnerDraw + >> menu.itemOwnerDrawFlags >> menu.itemBorderSize >> menu.itemStaticFlags + >> menu.itemDynamicFlags >> menu.itemNextTime; + + float itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA, + itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA, + itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA, + itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA; + *aZoneFileStream >> itemForegroundColorR >> itemForegroundColorG >> itemForegroundColorB >> itemForegroundColorA + >> itemBackgroundColorR >> itemBackgroundColorG >> itemBackgroundColorB >> itemBackgroundColorA + >> itemBorderColorR >> itemBorderColorG >> itemBorderColorB >> itemBorderColorA + >> itemOutlineColorR >> itemOutlineColorG >> itemOutlineColorB >> itemOutlineColorA; + + menu.itemForegroundColor = QColor(itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA); + menu.itemBackgroundColor = QColor(itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA); + menu.itemBorderColor = QColor(itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA); + menu.itemOutlineColor = QColor(itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA); + + *aZoneFileStream >> menu.itemMaterialPtr; + + float itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight; + *aZoneFileStream >> itemTextRectX >> itemTextRectY >> itemTextRectWidth >> itemTextRectHeight; + menu.itemTextRect = QRectF(itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight); + + quint32 hItemTextAlignInt, vItemTextAlignInt, itemType, fontTypeInt, textStyleInt; + *aZoneFileStream >> hItemTextAlignInt >> vItemTextAlignInt >> itemType >> menu.dataType + >> menu.alignment >> fontTypeInt >> menu.textAlignMode >> menu.textalignx >> menu.textaligny + >> menu.textscale >> textStyleInt >> menu.gameMsgWindowIndex >> menu.gameMsgWindowMode + >> menu.testPtr >> menu.textSavegameInfo >> menu.parentPtr; + menu.itemText_hAlign = (MENU_H_ALIGNMENT)hItemTextAlignInt; + menu.itemText_vAlign = (MENU_V_ALIGNMENT)vItemTextAlignInt; + menu.itemType = (MENU_ITEM_TYPE)itemType; + menu.fontEnum = (MENU_FONT_TYPE)fontTypeInt; + menu.textStyle = (MENU_ITEM_TEXTSTYLE)textStyleInt; + + *aZoneFileStream >> menu.mouseEnterText >> menu.mouseExitText >> menu.mouseEnter >> menu.mouseExit + >> menu.action >> menu.onAccept >> menu.onFocus >> menu.leaveFocus >> menu.dvar >> menu.dvarTest + >> menu.keyHandlerPtr >> menu.enableDvarPtr >> menu.dvarFlags >> menu.focusSoundPtr + >> menu.special >> menu.cursorPos; + + // itemDefData_t typeData; + + // listBoxDef_s *listBox; + + *aZoneFileStream >> menu.startPos >> menu.endPos >> menu.drawPadding; + + *aZoneFileStream >> menu.elementWidth >> menu.elementHeight; + + *aZoneFileStream >> menu.elementStyle >> menu.numColumns; + + //columnInfo_s columnInfo[16]; + + *aZoneFileStream >> menu.doubleClickPtr; + + + *aZoneFileStream >> menu.notselectable >> menu.noScrollBars >> menu.usePaging; + + float itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA, + itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA, + itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA; + *aZoneFileStream >> itemSelectBorderColorR >> itemSelectBorderColorG >> itemSelectBorderColorB >> itemSelectBorderColorA + >> itemDisableColorR >> itemDisableColorG >> itemDisableColorB >> itemDisableColorA + >> itemFocusColorR >> itemFocusColorG >> itemFocusColorB >> itemFocusColorA; + menu.itemSelectBorderColor = QColor(itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA); + menu.itemDisableColor = QColor(itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA); + menu.itemFocusColor = QColor(itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA); + + *aZoneFileStream >> menu.selectIconPtr >> menu.backgroundItemListboxPtr >> menu.highlightTexturePtr; + + // editFieldDef_s *editField; + + *aZoneFileStream >> menu.minVal >> menu.maxVal >> menu.defVal >> menu.range >> menu.maxChars + >> menu.maxCharsGotoNext >> menu.maxPaintChars >> menu.paintOffset; + + // multiDef_s *multi; + + for (int i = 0; i < 32; i++) { + quint32 dvarList; + *aZoneFileStream >> dvarList; + menu.dvarListPtrs.push_back(dvarList); + } + + for (int i = 0; i < 32; i++) { + quint32 dvarStr; + *aZoneFileStream >> dvarStr; + menu.dvarStrPtrs.push_back(dvarStr); + } + + for (int i = 0; i < 32; i++) { + float dvarValue; + *aZoneFileStream >> dvarValue; + menu.dvarValues.push_back(dvarValue); + } + + *aZoneFileStream >> menu.count >> menu.strDef >> menu.enumDvarNamePtr; + aZoneFileStream->skipRawData(4); + //>> menu.dataPtr + *aZoneFileStream >> menu.itemImageTrack; + + qDebug() << aZoneFileStream->device()->pos(); + + //statement_s visibleExp; + //statement_s textExp; + //statement_s materialExp; + //statement_s rectXExp; + //statement_s rectYExp; + //statement_s rectWExp; + //statement_s rectHExp; + //statement_s foreColorAExp; + result.menuDefs << menu; + } + return result; +} + +void ZoneFile_COD7::pParseAsset_Weapon(QDataStream *aZoneFileStream) { + //WEAPON_FILE + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD7::pParseAsset_D3DBSP(QDataStream *aZoneFileStream) { + //D3DBSP_DUMP + Q_UNUSED(aZoneFileStream); +} + +StringTable ZoneFile_COD7::pParseAsset_StringTable(QDataStream *aZoneFileStream) { + StringTable result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.columnCount + >> result.rowCount; + + // Todo fix this + result.columnCount = 0; + result.rowCount = 0; + + aZoneFileStream->skipRawData(4); + + QString stringTableName; + char stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + while (stringTableNameChar != 0) { + result.name += stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + } + + for (quint32 i = 0; i < result.rowCount; i++) { + QByteArray pointerData(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pointerData.data(), 4); + result.tablePointers.push_back(pointerData.toHex()); + + aZoneFileStream->skipRawData(4); + } + + for (const QString &pointerAddr : result.tablePointers) { + QString leadingContent = ""; + if (pointerAddr == "FFFFFFFF") { + char leadingContentChar; + *aZoneFileStream >> leadingContentChar; + while (leadingContentChar != 0) { + leadingContent += leadingContentChar; + *aZoneFileStream >> leadingContentChar; + } + } else { + leadingContent = pointerAddr; + } + + QString content; + char contentChar; + *aZoneFileStream >> contentChar; + while (contentChar != 0) { + content += contentChar; + *aZoneFileStream >> contentChar; + } + result.content[leadingContent] = content; + } + return result; +} + +QString ZoneFile_COD7::AssetTypeToString(const QString aAssetType) { + const QString cleanedType = aAssetType.toUpper(); + if (cleanedType == "17000000") { // localized string PARTIALLY VERIFIED + return "LOCAL STRING"; + } else if (cleanedType == "20000000") { // raw_file PARTIALLY VERIFIED + return "RAW FILE"; + } else if (cleanedType == "1A000000") { // fx PARTIALLY VERIFIED + return "EFFECT"; + } else if (cleanedType == "09000000") { // loaded_sound PARTIALLY VERIFIED + return "SOUND"; + } else if (cleanedType == "04000000") { // x_anim PARTIALLY VERIFIED + return "ANIMATION"; + } else if (cleanedType == "0C000000") { // collision_map PARTIALLY VERIFIED + return "COLLISION MAP"; + } else if (cleanedType == "21000000") { // string_table PARTIALLY VERIFIED + return "STRING TABLE"; + } else if (cleanedType == "15000000") { // menu_file PARTIALLY VERIFIED + return "MENU"; + } else if (cleanedType == "07000000") { // tech set PARTIALLY VERIFIED + return "TECH SET"; + } else if (cleanedType == "18000000") { // weapon PARTIALLY VERIFIED + return "WEAPON"; + } else if (cleanedType == "11000000") { // gfx map PARTIALLY VERIFIED + return "GFX MAP"; + } else if (cleanedType == "12000000") { // light_def PARTIALLY VERIFIED + return "LIGHT DEF"; + } else if (cleanedType == "14000000") { // font PARTIALLY VERIFIED + return "FONT"; + } else if (cleanedType == "05000000") { // xmodel PARTIALLY VERIFIED + return "MODEL"; + } else if (cleanedType == "0D000000") { // d3dbsp PARTIALLY VERIFIED + return "D3DBSP"; + } else if (cleanedType == "06000000") { // image PARTIALLY VERIFIED + return "IMAGE"; + } else if (cleanedType == "0E000000") { // game map sp PARTIALLY VERIFIED + return "GAME MAP SP"; + } else if (cleanedType == "0B000000") { // col map sp PARTIALLY VERIFIED + return "COL MAP SP"; + } + return aAssetType; +} + +QByteArray ZoneFile_COD7::GetBinaryData() { + QByteArray result; + + return result; +} diff --git a/libs/zonefile/zonefile_cod7.h b/libs/zonefile/zonefile_cod7.h new file mode 100644 index 0000000..6509b4e --- /dev/null +++ b/libs/zonefile/zonefile_cod7.h @@ -0,0 +1,52 @@ +#ifndef ZONEFILE_COD7_H +#define ZONEFILE_COD7_H + +#include "zonefile.h" + +class ZoneFile_COD7 : public ZoneFile +{ +public: + ZoneFile_COD7(); + ~ZoneFile_COD7(); + + bool Load(const QByteArray aFileData, FF_PLATFORM aPlatform) override; + QString AssetTypeToString(const QString aAssetType); + + QByteArray GetBinaryData() override; + +protected: + void pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) override; + quint32 pParseZoneSize(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsA(QDataStream *aZoneFileStream) override; + quint32 pParseZoneTagCount(QDataStream *aZoneFileStream) override; + quint32 pParseZoneRecordCount(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsB(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsC(QDataStream *aZoneFileStream) override; + QStringList pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) override; + QStringList pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) override; + AssetMap pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) override; + LocalString pParseAsset_LocalString(QDataStream *aZoneFileStream) override; + RawFile pParseAsset_RawFile(QDataStream *aZoneFileStream) override; + void pParseAsset_PhysPreset(QDataStream *aZoneFileStream) override; + Model pParseAsset_Model(QDataStream *aZoneFileStream) override; + Material pParseAsset_Material(QDataStream *aZoneFileStream) override; + Shader pParseAsset_Shader(QDataStream *aZoneFileStream) override; + TechSet pParseAsset_TechSet(QDataStream *aZoneFileStream) override; + Image pParseAsset_Image(QDataStream *aZoneFileStream) override; + SoundAsset pParseAsset_Sound(QDataStream *aZoneFileStream) override; + void pParseAsset_ColMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapSP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_LightDef(QDataStream *aZoneFileStream) override; + void pParseAsset_UIMap(QDataStream *aZoneFileStream) override; + void pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) override; + void pParseAsset_AIType(QDataStream *aZoneFileStream) override; + void pParseAsset_FX(QDataStream *aZoneFileStream) override; + Animation pParseAsset_Animation(QDataStream *aZoneFileStream) override; + MenuFile pParseAsset_MenuFile(QDataStream *aZoneFileStream) override; + void pParseAsset_Weapon(QDataStream *aZoneFileStream) override; + void pParseAsset_D3DBSP(QDataStream *aZoneFileStream) override; + StringTable pParseAsset_StringTable(QDataStream *aZoneFileStream) override; +}; + +#endif // ZONEFILE_COD7_H diff --git a/libs/zonefile/zonefile_cod9.cpp b/libs/zonefile/zonefile_cod9.cpp new file mode 100644 index 0000000..9943633 --- /dev/null +++ b/libs/zonefile/zonefile_cod9.cpp @@ -0,0 +1,1093 @@ +#include "zonefile_cod9.h" + +#include +#include +#include + +ZoneFile_COD9::ZoneFile_COD9() +{ + +} + +ZoneFile_COD9::~ZoneFile_COD9() +{ + +} + +bool ZoneFile_COD9::Load(const QByteArray aFileData, FF_PLATFORM aPlatform) { + // Open zone file as little endian stream + QDataStream zoneFileStream(aFileData); + if (aPlatform == FF_PLATFORM_PC) { + zoneFileStream.setByteOrder(QDataStream::LittleEndian); + } else { + zoneFileStream.setByteOrder(QDataStream::BigEndian); + } + + // Parse data from zone file header + pParseZoneHeader(&zoneFileStream, aPlatform); + SetRecords(pParseZoneIndex(&zoneFileStream, GetRecordCount())); + SetAssetMap(pParseAssets(&zoneFileStream, GetRecords())); + + return true; +} + +void ZoneFile_COD9::pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) { + Q_UNUSED(aPlatform); + + SetSize(pParseZoneSize(aZoneFileStream)); + pParseZoneUnknownsA(aZoneFileStream); + + SetTagCount(pParseZoneTagCount(aZoneFileStream)); + pParseZoneUnknownsB(aZoneFileStream); + + SetRecordCount(pParseZoneRecordCount(aZoneFileStream)); + + quint32 tagCount = GetTagCount(); + if (tagCount) { + pParseZoneUnknownsC(aZoneFileStream); + SetTags(pParseZoneTags(aZoneFileStream, tagCount)); + } else { + aZoneFileStream->skipRawData(4); + } +} + +quint32 ZoneFile_COD9::pParseZoneSize(QDataStream *aZoneFileStream) { + quint32 zoneFileSize; + *aZoneFileStream >> zoneFileSize; + if (zoneFileSize <= 0) { + qDebug() << "Tried to open empty zone file!"; + exit(-1); + } + zoneFileSize += 36; + return zoneFileSize; +} + +/* + ParseZoneUnknownsA() + + Parses the 1st section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD9::pParseZoneUnknownsA(QDataStream *aZoneFileStream) { + // Byte 4-7, 8-11, 12-15: unknown + QByteArray unknown1(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown1.data(), 4); + + QByteArray unknown2(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown2.data(), 4); + + QByteArray unknown3(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown3.data(), 4); + + // Byte 16-19, 20-23: empty/unknown + QByteArray unknown4(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown4.data(), 4); + + QByteArray unknown5(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown5.data(), 4); + + // Byte 24-27: somehow related to the filesize, but smaller value + QByteArray unknown6(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown6.data(), 4); + + // Byte 28-31, 32-35: unknown + QByteArray unknown7(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown7.data(), 4); + + QByteArray unknown8(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown8.data(), 4); +} + +/* + ParseZoneTagCount() + + Parses the number of string tags in the zone index +*/ +quint32 ZoneFile_COD9::pParseZoneTagCount(QDataStream *aZoneFileStream) { + quint32 tagCount; + *aZoneFileStream >> tagCount; + return tagCount; +} + +/* + ParseZoneRecordCount() + + Parses the number of records in the zone index +*/ +quint32 ZoneFile_COD9::pParseZoneRecordCount(QDataStream *aZoneFileStream) { + quint32 recordCount; + *aZoneFileStream >> recordCount; + return recordCount; +} + +/* + ParseZoneUnknownsB() + + Parses the 2nd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD9::pParseZoneUnknownsB(QDataStream *aZoneFileStream) { + // Byte 44-47: Unknown/empty? + QByteArray unknown9(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown9.data(), 4); +} + +/* + pParseZoneUnknownsC() + + Parses the 3rd section of unknowns as hex vals and uint32s +*/ +void ZoneFile_COD9::pParseZoneUnknownsC(QDataStream *aZoneFileStream) { + // Byte 40-43: Unknown/empty? + QByteArray unknown10(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown10.data(), 4); + + // Byte 44-47: Unknown/empty? + QByteArray unknown11(4, Qt::Uninitialized); + aZoneFileStream->readRawData(unknown11.data(), 4); +} + +/* + ParseZoneTags() + + Parses the string tags ate the start of zone file +*/ +QStringList ZoneFile_COD9::pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) { + QStringList tags; + + // Byte 48-51: Repeated separators? ÿÿÿÿ x i + aZoneFileStream->skipRawData(4 * (tagCount - 1)); + + // Parse tags/strings before index + QString zoneTag; + char zoneTagChar; + for (quint32 i = 0; i < tagCount; i++) { + *aZoneFileStream >> zoneTagChar; + while (zoneTagChar != 0) { + zoneTag += zoneTagChar; + *aZoneFileStream >> zoneTagChar; + } + tags << zoneTag; + zoneTag.clear(); + } + return tags; +} + +/* + ParseZoneIndex() + + Parse the binary zone index data and populate table +*/ +QStringList ZoneFile_COD9::pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) { + QStringList result; + + // Don't parse if no records + if (!recordCount) { return result; } + + if (aZoneFileStream->device()->peek(4).toHex().contains("ffff")) { + aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 2); + } + + // Parse index & map found asset types + for (quint32 i = 0; i <= recordCount; i++) { + // Skip record start + QByteArray rawAssetType(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rawAssetType.data(), 4); + result << rawAssetType.toHex(); + + // Skip separator + aZoneFileStream->skipRawData(4); + } + return result; +} + +AssetMap ZoneFile_COD9::pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) { + AssetMap result; + + aZoneFileStream->device()->seek(aZoneFileStream->device()->pos() - 8); + + for (int i = 0; i < assetOrder.size(); i++) { + const QString typeHex = assetOrder[i]; + const QString typeStr = AssetTypeToString(typeHex); + + if (typeStr == "LOCAL STRING") { // localized string asset + result.localStrings << pParseAsset_LocalString(aZoneFileStream); + } else if (typeStr == "RAW FILE") { // gsc + auto rawFile = pParseAsset_RawFile(aZoneFileStream); + if (rawFile.length) { + result.rawFiles << rawFile; + } + } else if (typeStr == "PHYS PRESET") { // physpreset + pParseAsset_PhysPreset(aZoneFileStream); + } else if (typeStr == "MODEL") { // xmodel + result.models << pParseAsset_Model(aZoneFileStream); + } else if (typeStr == "MATERIAL") { // material + pParseAsset_Material(aZoneFileStream); + } else if (typeStr == "SHADER") { // pixelshader + pParseAsset_Shader(aZoneFileStream); + } else if (typeStr == "TECH SET") { // techset include + result.techSets << pParseAsset_TechSet(aZoneFileStream); + } else if (typeStr == "IMAGE") { // image + result.images << pParseAsset_Image(aZoneFileStream); + } else if (typeStr == "SOUND") { // loaded_sound + result.sounds << pParseAsset_Sound(aZoneFileStream); + } else if (typeStr == "COLLISION MAP") { // col_map_mp + pParseAsset_ColMapMP(aZoneFileStream); + } else if (typeStr == "MP MAP") { // game_map_sp + pParseAsset_GameMapSP(aZoneFileStream); + } else if (typeStr == "SP MAP") { // game_map_mp + pParseAsset_GameMapMP(aZoneFileStream); + } else if (typeStr == "LIGHT DEF") { // lightdef + pParseAsset_LightDef(aZoneFileStream); + } else if (typeStr == "UI MAP") { // ui_map + pParseAsset_UIMap(aZoneFileStream); + } else if (typeStr == "SND DRIVER GLOBALS") { // snddriverglobals + pParseAsset_SNDDriverGlobals(aZoneFileStream); + } else if (typeStr == "AI TYPE") { // aitype + pParseAsset_AIType(aZoneFileStream); + } else if (typeStr == "EFFECT") { // aitype + pParseAsset_FX(aZoneFileStream); + } else if (typeStr == "ANIMATION") { // aitype + result.animations << pParseAsset_Animation(aZoneFileStream); + } else if (typeStr == "STRING TABLE") { // string_table + result.stringTables << pParseAsset_StringTable(aZoneFileStream); + } else if (typeStr == "MENU") { // string_table + result.menuFiles << pParseAsset_MenuFile(aZoneFileStream); + } else if (typeStr == "WEAPON") { // string_table + pParseAsset_Weapon(aZoneFileStream); + } else if (typeStr == "D3DBSP DUMP") { // string_table + pParseAsset_D3DBSP(aZoneFileStream); + } else if (typeStr != "UNKNOWN") { + qDebug() << "Found bad asset type!" << typeStr; + } + } + return result; +} + +LocalString ZoneFile_COD9::pParseAsset_LocalString(QDataStream *aZoneFileStream) { + LocalString result; + + quint32 stringPtr, aliasPtr; + *aZoneFileStream >> stringPtr >> aliasPtr; + if (stringPtr == 4294967295) { + // Parse local string asset contents + QString localStr; + char localStrChar; + *aZoneFileStream >> localStrChar; + while (localStrChar != 0) { + result.string += localStrChar; + *aZoneFileStream >> localStrChar; + } + } else { + result.string = "String Ptr: " + QString::number(stringPtr); + } + + if (aliasPtr == 4294967295) { + // Parse rawfile name + QString aliasName; + char aliasNameChar; + *aZoneFileStream >> aliasNameChar; + while (aliasNameChar != 0) { + result.alias += aliasNameChar; + *aZoneFileStream >> aliasNameChar; + } + } else { + result.string = "Alias Ptr: " + QString::number(aliasPtr); + } + + return result; +} + +RawFile ZoneFile_COD9::pParseAsset_RawFile(QDataStream *aZoneFileStream) { + RawFile result; + + // Skip start separator FF FF FF FF (pointer?) + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.length; + + // Skip unknown 4 byte data + aZoneFileStream->skipRawData(4); + + // Parse rawfile path + char scriptPathChar; + *aZoneFileStream >> scriptPathChar; + while (scriptPathChar != 0) { + result.path += scriptPathChar; + *aZoneFileStream >> scriptPathChar; + } + result.path.replace(",", ""); + const QStringList pathParts = result.path.split('/'); + if (pathParts.size() == 0) { + qDebug() << "Failed to parse ff path! " << result.path; + exit(-1); + } + + // Parse gsc contents + char rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + while (rawFileContentsChar != 0 && rawFileContentsChar != -1) { + result.contents += rawFileContentsChar; + *aZoneFileStream >> rawFileContentsChar; + } + return result; +} + +void ZoneFile_COD9::pParseAsset_PhysPreset(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Model ZoneFile_COD9::pParseAsset_Model(QDataStream *aZoneFileStream) { + Model result; + + qDebug() << "Model Info:"; + + *aZoneFileStream >> result.namePtr >> result.tagCount >> result.rootTagCount + >> result.surfCount >> result.unknownCount >> result.boneNamePtr + >> result.parentListPtr >> result.quatsPtr >> result.transPtr + >> result.partClassPtr >> result.baseMatPtr + >> result.surfsPtr >> result.materialHandlesPtr; + + // Parse XModelLodInfo + for (int i = 1; i <= 4; i++) { + qDebug() << "- Lod Info " << i; + + quint32 intDist; + *aZoneFileStream >> intDist; + + std::memcpy(&result.lodInfo[i].dist, &intDist, sizeof(result.lodInfo[i].dist)); + *aZoneFileStream >> result.lodInfo[i].numsurfs >> result.lodInfo[i].surfIndex; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.lodInfo[i].partBits[0] + >> result.lodInfo[i].partBits[1] + >> result.lodInfo[i].partBits[2] + >> result.lodInfo[i].partBits[3]; + } + + *aZoneFileStream >> result.collSurfsPtr >> result.numCollSurfs >> result.contents >> result.boneInfoPtr; + + quint32 intRadius, intMins[3], intMaxs[3]; + *aZoneFileStream >> intRadius >> intMins[0] >> intMins[1] + >> intMins[2] >> intMaxs[0] >> intMaxs[1] >> intMaxs[2]; + + std::memcpy(&result.radius, &intRadius, sizeof(result.radius)); + + std::memcpy(&result.mins[0], &intMins[0], sizeof(result.mins[0])); + std::memcpy(&result.mins[1], &intMins[1], sizeof(result.mins[1])); + std::memcpy(&result.mins[2], &intMins[2], sizeof(result.mins[2])); + + std::memcpy(&result.maxs[0], &intMaxs[0], sizeof(result.maxs[0])); + std::memcpy(&result.maxs[1], &intMaxs[1], sizeof(result.maxs[2])); + std::memcpy(&result.maxs[2], &intMaxs[2], sizeof(result.maxs[3])); + + *aZoneFileStream >> result.numLods >> result.collLod >> result.streamInfoPtr + >> result.memUsage >> result.flags >> result.physPresetPtr >> result.physGeomsPtr; + + // Parse model name + char modelNameChar; + *aZoneFileStream >> modelNameChar; + while (modelNameChar == 0) { + *aZoneFileStream >> modelNameChar; + } + while (modelNameChar != 0) { + result.modelName += modelNameChar; + *aZoneFileStream >> modelNameChar; + } + return result; +} + +Material ZoneFile_COD9::pParseAsset_Material(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); + + return Material(); +} + +Shader ZoneFile_COD9::pParseAsset_Shader(QDataStream *aZoneFileStream) { + Shader result = Shader(); + + quint8 minorVersion, majorVersion; + *aZoneFileStream >> minorVersion >> majorVersion; + + quint32 magic; + *aZoneFileStream >> magic; + + // Verify .fxc magic + if (magic != 65534 && magic != 65535) { return result; } + + SHADER_TYPE type = SHADER_NONE; + quint16 rawShaderType; + *aZoneFileStream >> rawShaderType; + if (rawShaderType == 65535) { // Pixel shader + type = SHADER_PIXEL; + } else if (rawShaderType == 65534) { // Vertex shader + type = SHADER_VERTEX; + } + Q_UNUSED(type); + + while (true) { + quint32 instructionToken; + *aZoneFileStream >> instructionToken; + + SHADER_OPCODE opCode = (SHADER_OPCODE)(instructionToken & 0xffff); + + int size; + if (opCode == OPCODE_End) { + break; + } else if (opCode == OPCODE_Comment) { + size = (int)((instructionToken >> 16) & 0x7FFF); + } else { + size = (int)((instructionToken >> 24) & 0x0f); + } + Q_UNUSED(size); + } + + + return result; +} + +TechSet ZoneFile_COD9::pParseAsset_TechSet(QDataStream *aZoneFileStream) { + TechSet result; + + for (int i = 1; i <= 62; i++) { + quint32 ptr; + *aZoneFileStream >> ptr; + + result.pointers << ptr; + } + qDebug() << aZoneFileStream->device()->pos(); + + // Parse techset name + char techSetNameChar; + *aZoneFileStream >> techSetNameChar; + while (techSetNameChar != 0) { + result.name += techSetNameChar; + *aZoneFileStream >> techSetNameChar; + } + result.name.replace(",", ""); + + return result; +} + +Image ZoneFile_COD9::pParseAsset_Image(QDataStream *aZoneFileStream) { + Image result; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknowna >> result.unknownb + >> result.unknownc >> result.unknownd + >> result.unknowne >> result.unknownf + >> result.unknowng; + + aZoneFileStream->skipRawData(15 * 4); + *aZoneFileStream >> result.unknownh >> result.unknowni; + + aZoneFileStream->skipRawData(4); + *aZoneFileStream >> result.unknownj; + + aZoneFileStream->skipRawData(4); + + char materialNameChar; + *aZoneFileStream >> materialNameChar; + while (materialNameChar != 0) { + result.materialName += materialNameChar; + *aZoneFileStream >> materialNameChar; + } + result.materialName.replace(",", ""); + + if (result.unknowna) { + *aZoneFileStream >> result.unknownk; + *aZoneFileStream >> result.unknownl; + *aZoneFileStream >> result.unknownm; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown1; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.unknown2 >> result.unknown3 + >> result.size1 >> result.size2 + >> result.unknown4 >> result.unknown5; + + aZoneFileStream->skipRawData(4); + + char imageNameChar; + *aZoneFileStream >> imageNameChar; + while (imageNameChar != 0) { + result.name += imageNameChar; + *aZoneFileStream >> imageNameChar; + } + + *aZoneFileStream >> result.unknown6 >> result.unknown7; + + QByteArray compressionData(8, Qt::Uninitialized); + aZoneFileStream->readRawData(compressionData.data(), 8); + if (compressionData.contains("DXT1")) { + result.compression = COMPRESSION_DXT1; + } else if (compressionData.contains("DXT3")) { + result.compression = COMPRESSION_DXT3; + } else if (compressionData.contains("DXT5")) { + result.compression = COMPRESSION_DXT5; + } else { + result.compression = COMPRESSION_NONE; + } + + *aZoneFileStream >> result.unknown8 >> result.unknown9; + } + + return result; +} + +SoundAsset ZoneFile_COD9::pParseAsset_Sound(QDataStream *aZoneFileStream) { + SoundAsset result; + + qDebug() << aZoneFileStream->device()->pos(); + + QByteArray rootNamePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(rootNamePtr.data(), 4); + qDebug() << "Root name ptr: " << (QString)rootNamePtr.toHex(); + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream >> result.count; + + if (rootNamePtr.toHex() == "ffffffff") { + // Read in sound file name + char soundNameChar; + *aZoneFileStream >> soundNameChar; + while (soundNameChar != 0) { + result.name += soundNameChar; + *aZoneFileStream >> soundNameChar; + } + } + + int tagCount = 0; + int resultCount = 0; + for (quint32 i = 0; i < result.count; i++) { + aZoneFileStream->skipRawData(12); + + QByteArray tagPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(tagPtr.data(), 4); + + if (tagPtr.toHex() == "ffffffff") { + qDebug() << "Tag Ptr: " << tagPtr.toHex(); + tagCount++; + } + aZoneFileStream->skipRawData(4); + + QByteArray pathPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pathPtr.data(), 4); + + if (pathPtr.toHex() == "ffffffff") { + qDebug() << "Path Ptr: " << pathPtr.toHex(); + resultCount++; + } + + aZoneFileStream->skipRawData(160); + } + + for (int i = 0; i < tagCount; i++) { + // Read in tag? + QString tag; + char tagChar; + *aZoneFileStream >> tagChar; + while (tagChar != 0) { + tag += tagChar; + *aZoneFileStream >> tagChar; + } + qDebug() << "Tag: " << tag; + } + + for (int i = 0; i < resultCount; i++) { + Sound sound; + + if (aZoneFileStream->device()->peek(12).toHex().contains("ffffffff00000000")) { + aZoneFileStream->skipRawData(12); + } + + aZoneFileStream->skipRawData(8); + + qDebug() << "- " << aZoneFileStream->device()->pos(); + QByteArray aliasPtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(aliasPtr.data(), 4); + + QByteArray namePtr(4, Qt::Uninitialized); + aZoneFileStream->readRawData(namePtr.data(), 4); + + *aZoneFileStream >> sound.dataLength; + qDebug() << "- Data length: " << sound.dataLength; + + if (aliasPtr.toHex() == "ffffffff") { + // Read in sound alias name + char soundAliasChar; + *aZoneFileStream >> soundAliasChar; + while (soundAliasChar != 0) { + sound.alias += soundAliasChar; + *aZoneFileStream >> soundAliasChar; + } + qDebug() << "- Alias: " << sound.alias; + } + + if (aZoneFileStream->device()->peek(4) == "RIFF") { + sound.path = sound.alias; + sound.alias = ""; + } else if (namePtr.toHex() == "ffffffff") { + // Read in sound file path + char soundPathChar; + *aZoneFileStream >> soundPathChar; + while (soundPathChar != 0) { + sound.path += soundPathChar; + *aZoneFileStream >> soundPathChar; + } + sound.path.replace(",", ""); + qDebug() << "- Path: " << sound.path; + } + + if (sound.dataLength) { + QByteArray data(sound.dataLength, Qt::Uninitialized); + aZoneFileStream->readRawData(data.data(), sound.dataLength); + sound.data = data; + } + result.sounds.append(sound); + } + qDebug() << "- " << aZoneFileStream->device()->pos(); + + return result; +} + +void ZoneFile_COD9::pParseAsset_ColMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_GameMapSP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_GameMapMP(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_LightDef(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_UIMap(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_AIType(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_FX(QDataStream *aZoneFileStream) { + Q_UNUSED(aZoneFileStream); +} + +Animation ZoneFile_COD9::pParseAsset_Animation(QDataStream *aZoneFileStream) { + Animation result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.dataByteCount + >> result.dataShortCount + >> result.dataIntCount + >> result.randomDataByteCount + >> result.randomDataIntCount + >> result.numframes + >> result.isLooped + >> result.isDelta + >> result.noneRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.twoDRotatedBoneCount + >> result.normalRotatedBoneCount + >> result.normalTranslatedBoneCount + >> result.preciseTranslatedBoneCount + >> result.staticTranslatedBoneCount + >> result.noneTranslatedBoneCount + >> result.totalBoneCount + >> result.otherBoneCount1 + >> result.otherBoneCount2 + >> result.notifyCount + >> result.assetType + >> result.pad + >> result.randomDataShortCount + >> result.indexCount + >> result.frameRate + >> result.frequency + >> result.boneIDsPtr + >> result.dataBytePtr + >> result.dataShortPtr + >> result.dataIntPtr + >> result.randomDataShortPtr + >> result.randomDataBytePtr + >> result.randomDataIntPtr + >> result.longIndiciesPtr + >> result.notificationsPtr + >> result.deltaPartsPtr; + + // Read in x_anim file name + QString xAnimName; + char xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + while (xAnimNameChar != 0) { + result.name += xAnimNameChar; + *aZoneFileStream >> xAnimNameChar; + } + + // Parse x_anim index header + QVector sectionLengths; + for (int i = 0; i < result.numframes; i++) { + quint8 sectionlength; + *aZoneFileStream >> sectionlength; + sectionLengths.push_back(sectionlength); + // Skip padding + aZoneFileStream->skipRawData(1); + } + // Skip unknown section + aZoneFileStream->skipRawData(2 * 8); + + return result; +} + +MenuFile ZoneFile_COD9::pParseAsset_MenuFile(QDataStream *aZoneFileStream) { + //MENU_FILE + MenuFile result; + + aZoneFileStream->skipRawData(4); // Separator + + // Parse menu def count + *aZoneFileStream >> result.menuCount; + + // Clearly misparsed, never have this much + if (result.menuCount > 1000) { + qDebug() << "Failure reported when parsing menu file."; + return result; + } + for (uint i = 0; i < result.menuCount; i++) { + Menu menu; + + aZoneFileStream->skipRawData(4); // Separator + + // Read in x_anim file name + char menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + while (menuFilepathChar != 0) { + menu.filePath += menuFilepathChar; + *aZoneFileStream >> menuFilepathChar; + } + aZoneFileStream->skipRawData(4); // Separator + + *aZoneFileStream >> menu.menuNamePtr; + + float menuRectX, menuRectY, menuRectWidth, menuRectHeight; + *aZoneFileStream >> menuRectX >> menuRectY >> menuRectWidth >> menuRectHeight; + menu.rect = QRectF(menuRectX, menuRectY, menuRectWidth, menuRectHeight); + + quint32 hAlignInt, vAlignInt; + *aZoneFileStream >> hAlignInt >> vAlignInt; + menu.hAlign = (MENU_H_ALIGNMENT)hAlignInt; + menu.vAlign = (MENU_V_ALIGNMENT)vAlignInt; + + float rectClientX, rectClientY, rectClientWidth, rectClientHeight; + *aZoneFileStream >> rectClientX >> rectClientY >> rectClientWidth >> rectClientHeight; + menu.clientRect = QRectF(rectClientX, rectClientY, rectClientWidth, rectClientHeight); + + quint32 hClientAlignInt, vClientAlignInt, styleInt, borderInt; + *aZoneFileStream >> hClientAlignInt >> vClientAlignInt >> menu.groupPtr + >> styleInt >> borderInt >> menu.ownerDraw >> menu.ownerDrawFlags + >> menu.borderSize >> menu.staticFlags >> menu.dynamicFlags >> menu.nextTime; + menu.hClientAlign = (MENU_H_ALIGNMENT)hClientAlignInt; + menu.vClientAlign = (MENU_V_ALIGNMENT)vClientAlignInt; + menu.style = (MENU_WINDOW_STYLE)styleInt; + menu.border = (MENU_WINDOW_BORDER)borderInt; + + float foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA, + backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA, + borderColorR, borderColorG, borderColorB, borderColorA, + outlineColorR, outlineColorG, outlineColorB, outlineColorA; + *aZoneFileStream >> foregroundColorR >> foregroundColorG >> foregroundColorB >> foregroundColorA + >> backgroundColorR >> backgroundColorG >> backgroundColorB >> backgroundColorA + >> borderColorR >> borderColorG >> borderColorB >> borderColorA + >> outlineColorR >> outlineColorG >> outlineColorB >> outlineColorA; + + menu.foregroundColor = QColor(foregroundColorR, foregroundColorG, foregroundColorB, foregroundColorA); + menu.backgroundColor = QColor(backgroundColorR, backgroundColorG, backgroundColorB, backgroundColorA); + menu.borderColor = QColor(borderColorR, borderColorG, borderColorB, borderColorA); + menu.outlineColor = QColor(outlineColorR, outlineColorG, outlineColorB, outlineColorA); + + *aZoneFileStream >> menu.materialPtr >> menu.fontPtr >> menu.fullScreen >> menu.itemCount + >> menu.fontIndex >> menu.cursorItem >> menu.fadeCycle >> menu.fadeClamp + >> menu.fadeAmount >> menu.fadeInAmount >> menu.blurRadius >> menu.onOpenPtr + >> menu.onFocusPtr >> menu.onClosePtr >> menu.onESCPtr >> menu.onKeyPtr + >> menu.visibleExpCount >> menu.expEntryPtr >> menu.allowedBindingPtr + >> menu.soundNamePtr >> menu.imageTrack; + + float focusColorR, focusColorG, focusColorB, focusColorA, + disabledColorR, disabledColorG, disabledColorB, disabledColorA; + *aZoneFileStream >> focusColorR >> focusColorG >> focusColorB >> focusColorA + >> disabledColorR >> disabledColorG >> disabledColorB >> disabledColorA; + menu.focusColor = QColor(focusColorR, focusColorG, focusColorB, focusColorA); + menu.disabledColor = QColor(disabledColorR, disabledColorG, disabledColorB, disabledColorA); + + *aZoneFileStream >> menu.rectXExpCount >> menu.rectXExpPtr >> menu.rectYExpCount >> menu.rectYExpPtr; + + aZoneFileStream->skipRawData(4); // Separator + + char menuDefNameChar; + int menuDefNameLen = 0; + *aZoneFileStream >> menuDefNameChar; + while (menuDefNameChar != 0 && menuDefNameLen < 30) { + menuDefNameLen++; + menu.name += menuDefNameChar; + *aZoneFileStream >> menuDefNameChar; + } + + char defStringChar; + int defStringLen = 0; + *aZoneFileStream >> defStringChar; + while (defStringChar != 0 && defStringLen < 30) { + defStringLen++; + menu.definition += defStringChar; + *aZoneFileStream >> defStringChar; + } + aZoneFileStream->skipRawData(4 * 10); + + *aZoneFileStream >> menu.itemWindowDefNamePtr; + + float itemRectX, itemRectY, itemRectWidth, itemRectHeight; + *aZoneFileStream >> itemRectX >> itemRectY >> itemRectWidth >> itemRectHeight; + menu.itemRect = QRectF(itemRectX, itemRectY, itemRectWidth, itemRectHeight); + + *aZoneFileStream >> menu.itemHAlignment >> menu.itemVAlignment >> menu.itemGroupPtr + >> menu.itemWindowStyle >> menu.itemWindowBorder >> menu.itemOwnerDraw + >> menu.itemOwnerDrawFlags >> menu.itemBorderSize >> menu.itemStaticFlags + >> menu.itemDynamicFlags >> menu.itemNextTime; + + float itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA, + itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA, + itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA, + itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA; + *aZoneFileStream >> itemForegroundColorR >> itemForegroundColorG >> itemForegroundColorB >> itemForegroundColorA + >> itemBackgroundColorR >> itemBackgroundColorG >> itemBackgroundColorB >> itemBackgroundColorA + >> itemBorderColorR >> itemBorderColorG >> itemBorderColorB >> itemBorderColorA + >> itemOutlineColorR >> itemOutlineColorG >> itemOutlineColorB >> itemOutlineColorA; + + menu.itemForegroundColor = QColor(itemForegroundColorR, itemForegroundColorG, itemForegroundColorB, itemForegroundColorA); + menu.itemBackgroundColor = QColor(itemBackgroundColorR, itemBackgroundColorG, itemBackgroundColorB, itemBackgroundColorA); + menu.itemBorderColor = QColor(itemBorderColorR, itemBorderColorG, itemBorderColorB, itemBorderColorA); + menu.itemOutlineColor = QColor(itemOutlineColorR, itemOutlineColorG, itemOutlineColorB, itemOutlineColorA); + + *aZoneFileStream >> menu.itemMaterialPtr; + + float itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight; + *aZoneFileStream >> itemTextRectX >> itemTextRectY >> itemTextRectWidth >> itemTextRectHeight; + menu.itemTextRect = QRectF(itemTextRectX, itemTextRectY, itemTextRectWidth, itemTextRectHeight); + + quint32 hItemTextAlignInt, vItemTextAlignInt, itemType, fontTypeInt, textStyleInt; + *aZoneFileStream >> hItemTextAlignInt >> vItemTextAlignInt >> itemType >> menu.dataType + >> menu.alignment >> fontTypeInt >> menu.textAlignMode >> menu.textalignx >> menu.textaligny + >> menu.textscale >> textStyleInt >> menu.gameMsgWindowIndex >> menu.gameMsgWindowMode + >> menu.testPtr >> menu.textSavegameInfo >> menu.parentPtr; + menu.itemText_hAlign = (MENU_H_ALIGNMENT)hItemTextAlignInt; + menu.itemText_vAlign = (MENU_V_ALIGNMENT)vItemTextAlignInt; + menu.itemType = (MENU_ITEM_TYPE)itemType; + menu.fontEnum = (MENU_FONT_TYPE)fontTypeInt; + menu.textStyle = (MENU_ITEM_TEXTSTYLE)textStyleInt; + + *aZoneFileStream >> menu.mouseEnterText >> menu.mouseExitText >> menu.mouseEnter >> menu.mouseExit + >> menu.action >> menu.onAccept >> menu.onFocus >> menu.leaveFocus >> menu.dvar >> menu.dvarTest + >> menu.keyHandlerPtr >> menu.enableDvarPtr >> menu.dvarFlags >> menu.focusSoundPtr + >> menu.special >> menu.cursorPos; + + // itemDefData_t typeData; + + // listBoxDef_s *listBox; + + *aZoneFileStream >> menu.startPos >> menu.endPos >> menu.drawPadding; + + *aZoneFileStream >> menu.elementWidth >> menu.elementHeight; + + *aZoneFileStream >> menu.elementStyle >> menu.numColumns; + + //columnInfo_s columnInfo[16]; + + *aZoneFileStream >> menu.doubleClickPtr; + + + *aZoneFileStream >> menu.notselectable >> menu.noScrollBars >> menu.usePaging; + + float itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA, + itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA, + itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA; + *aZoneFileStream >> itemSelectBorderColorR >> itemSelectBorderColorG >> itemSelectBorderColorB >> itemSelectBorderColorA + >> itemDisableColorR >> itemDisableColorG >> itemDisableColorB >> itemDisableColorA + >> itemFocusColorR >> itemFocusColorG >> itemFocusColorB >> itemFocusColorA; + menu.itemSelectBorderColor = QColor(itemSelectBorderColorR, itemSelectBorderColorG, itemSelectBorderColorB, itemSelectBorderColorA); + menu.itemDisableColor = QColor(itemDisableColorR, itemDisableColorG, itemDisableColorB, itemDisableColorA); + menu.itemFocusColor = QColor(itemFocusColorR, itemFocusColorG, itemFocusColorB, itemFocusColorA); + + *aZoneFileStream >> menu.selectIconPtr >> menu.backgroundItemListboxPtr >> menu.highlightTexturePtr; + + // editFieldDef_s *editField; + + *aZoneFileStream >> menu.minVal >> menu.maxVal >> menu.defVal >> menu.range >> menu.maxChars + >> menu.maxCharsGotoNext >> menu.maxPaintChars >> menu.paintOffset; + + // multiDef_s *multi; + + for (int i = 0; i < 32; i++) { + quint32 dvarList; + *aZoneFileStream >> dvarList; + menu.dvarListPtrs.push_back(dvarList); + } + + for (int i = 0; i < 32; i++) { + quint32 dvarStr; + *aZoneFileStream >> dvarStr; + menu.dvarStrPtrs.push_back(dvarStr); + } + + for (int i = 0; i < 32; i++) { + float dvarValue; + *aZoneFileStream >> dvarValue; + menu.dvarValues.push_back(dvarValue); + } + + *aZoneFileStream >> menu.count >> menu.strDef >> menu.enumDvarNamePtr; + aZoneFileStream->skipRawData(4); + //>> menu.dataPtr + *aZoneFileStream >> menu.itemImageTrack; + + qDebug() << aZoneFileStream->device()->pos(); + + //statement_s visibleExp; + //statement_s textExp; + //statement_s materialExp; + //statement_s rectXExp; + //statement_s rectYExp; + //statement_s rectWExp; + //statement_s rectHExp; + //statement_s foreColorAExp; + result.menuDefs << menu; + } + return result; +} + +void ZoneFile_COD9::pParseAsset_Weapon(QDataStream *aZoneFileStream) { + //WEAPON_FILE + Q_UNUSED(aZoneFileStream); +} + +void ZoneFile_COD9::pParseAsset_D3DBSP(QDataStream *aZoneFileStream) { + //D3DBSP_DUMP + Q_UNUSED(aZoneFileStream); +} + +StringTable ZoneFile_COD9::pParseAsset_StringTable(QDataStream *aZoneFileStream) { + StringTable result; + + aZoneFileStream->skipRawData(4); + + *aZoneFileStream + >> result.columnCount + >> result.rowCount; + + // Todo fix this + result.columnCount = 0; + result.rowCount = 0; + + aZoneFileStream->skipRawData(4); + + QString stringTableName; + char stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + while (stringTableNameChar != 0) { + result.name += stringTableNameChar; + *aZoneFileStream >> stringTableNameChar; + } + + for (quint32 i = 0; i < result.rowCount; i++) { + QByteArray pointerData(4, Qt::Uninitialized); + aZoneFileStream->readRawData(pointerData.data(), 4); + result.tablePointers.push_back(pointerData.toHex()); + + aZoneFileStream->skipRawData(4); + } + + for (const QString &pointerAddr : result.tablePointers) { + QString leadingContent = ""; + if (pointerAddr == "FFFFFFFF") { + char leadingContentChar; + *aZoneFileStream >> leadingContentChar; + while (leadingContentChar != 0) { + leadingContent += leadingContentChar; + *aZoneFileStream >> leadingContentChar; + } + } else { + leadingContent = pointerAddr; + } + + QString content; + char contentChar; + *aZoneFileStream >> contentChar; + while (contentChar != 0) { + content += contentChar; + *aZoneFileStream >> contentChar; + } + result.content[leadingContent] = content; + } + return result; +} + +QString ZoneFile_COD9::AssetTypeToString(const QString aAssetType) { + const QString cleanedType = aAssetType.toUpper(); + if (cleanedType == "17000000") { // localized string PARTIALLY VERIFIED + return "LOCAL STRING"; + } else if (cleanedType == "20000000") { // raw_file PARTIALLY VERIFIED + return "RAW FILE"; + } else if (cleanedType == "1A000000") { // fx PARTIALLY VERIFIED + return "EFFECT"; + } else if (cleanedType == "09000000") { // loaded_sound PARTIALLY VERIFIED + return "SOUND"; + } else if (cleanedType == "04000000") { // x_anim PARTIALLY VERIFIED + return "ANIMATION"; + } else if (cleanedType == "0C000000") { // collision_map PARTIALLY VERIFIED + return "COLLISION MAP"; + } else if (cleanedType == "21000000") { // string_table PARTIALLY VERIFIED + return "STRING TABLE"; + } else if (cleanedType == "15000000") { // menu_file PARTIALLY VERIFIED + return "MENU"; + } else if (cleanedType == "07000000") { // tech set PARTIALLY VERIFIED + return "TECH SET"; + } else if (cleanedType == "18000000") { // weapon PARTIALLY VERIFIED + return "WEAPON"; + } else if (cleanedType == "11000000") { // gfx map PARTIALLY VERIFIED + return "GFX MAP"; + } else if (cleanedType == "12000000") { // light_def PARTIALLY VERIFIED + return "LIGHT DEF"; + } else if (cleanedType == "14000000") { // font PARTIALLY VERIFIED + return "FONT"; + } else if (cleanedType == "05000000") { // xmodel PARTIALLY VERIFIED + return "MODEL"; + } else if (cleanedType == "0D000000") { // d3dbsp PARTIALLY VERIFIED + return "D3DBSP"; + } else if (cleanedType == "06000000") { // image PARTIALLY VERIFIED + return "IMAGE"; + } else if (cleanedType == "0E000000") { // game map sp PARTIALLY VERIFIED + return "GAME MAP SP"; + } else if (cleanedType == "0B000000") { // col map sp PARTIALLY VERIFIED + return "COL MAP SP"; + } + return aAssetType; +} + +QByteArray ZoneFile_COD9::GetBinaryData() { + QByteArray result; + + return result; +} diff --git a/libs/zonefile/zonefile_cod9.h b/libs/zonefile/zonefile_cod9.h new file mode 100644 index 0000000..a77aa9a --- /dev/null +++ b/libs/zonefile/zonefile_cod9.h @@ -0,0 +1,52 @@ +#ifndef ZONEFILE_COD9_H +#define ZONEFILE_COD9_H + +#include "zonefile.h" + +class ZoneFile_COD9 : public ZoneFile +{ +public: + ZoneFile_COD9(); + ~ZoneFile_COD9(); + + bool Load(const QByteArray aFileData, FF_PLATFORM aPlatform) override; + QString AssetTypeToString(const QString aAssetType); + + QByteArray GetBinaryData() override; + +protected: + void pParseZoneHeader(QDataStream *aZoneFileStream, FF_PLATFORM aPlatform) override; + quint32 pParseZoneSize(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsA(QDataStream *aZoneFileStream) override; + quint32 pParseZoneTagCount(QDataStream *aZoneFileStream) override; + quint32 pParseZoneRecordCount(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsB(QDataStream *aZoneFileStream) override; + void pParseZoneUnknownsC(QDataStream *aZoneFileStream) override; + QStringList pParseZoneTags(QDataStream *aZoneFileStream, quint32 tagCount) override; + QStringList pParseZoneIndex(QDataStream *aZoneFileStream, quint32 recordCount) override; + AssetMap pParseAssets(QDataStream *aZoneFileStream, QStringList assetOrder) override; + LocalString pParseAsset_LocalString(QDataStream *aZoneFileStream) override; + RawFile pParseAsset_RawFile(QDataStream *aZoneFileStream) override; + void pParseAsset_PhysPreset(QDataStream *aZoneFileStream) override; + Model pParseAsset_Model(QDataStream *aZoneFileStream) override; + Material pParseAsset_Material(QDataStream *aZoneFileStream) override; + Shader pParseAsset_Shader(QDataStream *aZoneFileStream) override; + TechSet pParseAsset_TechSet(QDataStream *aZoneFileStream) override; + Image pParseAsset_Image(QDataStream *aZoneFileStream) override; + SoundAsset pParseAsset_Sound(QDataStream *aZoneFileStream) override; + void pParseAsset_ColMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapSP(QDataStream *aZoneFileStream) override; + void pParseAsset_GameMapMP(QDataStream *aZoneFileStream) override; + void pParseAsset_LightDef(QDataStream *aZoneFileStream) override; + void pParseAsset_UIMap(QDataStream *aZoneFileStream) override; + void pParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) override; + void pParseAsset_AIType(QDataStream *aZoneFileStream) override; + void pParseAsset_FX(QDataStream *aZoneFileStream) override; + Animation pParseAsset_Animation(QDataStream *aZoneFileStream) override; + MenuFile pParseAsset_MenuFile(QDataStream *aZoneFileStream) override; + void pParseAsset_Weapon(QDataStream *aZoneFileStream) override; + void pParseAsset_D3DBSP(QDataStream *aZoneFileStream) override; + StringTable pParseAsset_StringTable(QDataStream *aZoneFileStream) override; +}; + +#endif // ZONEFILE_COD9_H diff --git a/mainwindow.cpp b/mainwindow.cpp deleted file mode 100644 index 2026fba..0000000 --- a/mainwindow.cpp +++ /dev/null @@ -1,1352 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) { - ui->setupUi(this); - - mTypeMap = QMap(); - mTypeOrder = QStringList(); - mRawFileMap = QMap(); - mTreeMap = QMap(); - mStrTableMap = QMap>>(); - mBSPVersion = 0; - mDiskLumpCount = 0; - mDiskLumpOrder = QVector(); - mLumps = QMap(); - - connect(ui->treeWidget_Scripts, &QTreeWidget::itemSelectionChanged, this, &MainWindow::ScriptSelected); - connect(ui->comboBox_StringTable, &QComboBox::currentTextChanged, this, &MainWindow::StrTableSelected); - - // Initialize Asset Index Table - ui->tableWidget_Index->setColumnCount(3); - ui->tableWidget_Index->setHorizontalHeaderLabels({"Asset Type", "Asset Name", "Asset Count"}); - ui->tableWidget_Index->verticalHeader()->setVisible(false); - ui->tableWidget_Index->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui->tableWidget_Index->setSelectionBehavior(QAbstractItemView::SelectRows); - ui->tableWidget_Index->setSelectionMode(QAbstractItemView::SingleSelection); - ui->tableWidget_Index->setShowGrid(false); - ui->tableWidget_Index->setStyleSheet("QTableView {selection-background-color: red;}"); - - // Initialize Asset Order Table - ui->tableWidget_Order->setColumnCount(3); - ui->tableWidget_Order->setHorizontalHeaderLabels({"Asset Type", "Asset Name", "Asset Count"}); - ui->tableWidget_Order->verticalHeader()->setVisible(false); - ui->tableWidget_Order->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui->tableWidget_Order->setSelectionBehavior(QAbstractItemView::SelectRows); - ui->tableWidget_Order->setSelectionMode(QAbstractItemView::SingleSelection); - ui->tableWidget_Order->setShowGrid(false); - ui->tableWidget_Order->setStyleSheet("QTableView {selection-background-color: red;}"); - - Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); - view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); - - QWidget *container = QWidget::createWindowContainer(view); - QSize screenSize = view->screen()->size(); - container->setMinimumSize(QSize(200, 100)); - container->setMaximumSize(screenSize); - - QHBoxLayout *hLayout = new QHBoxLayout(ui->frame_Scene); - QVBoxLayout *vLayout = new QVBoxLayout(); - vLayout->setAlignment(Qt::AlignTop); - hLayout->addWidget(container, 1); - hLayout->addLayout(vLayout); - - // Root entity - Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); - - // Camera - Qt3DRender::QCamera *cameraEntity = view->camera(); - - cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); - cameraEntity->setPosition(QVector3D(0, 0, 50.0f)); // Move farther along Z-axis - cameraEntity->setUpVector(QVector3D(0, 1, 0)); - cameraEntity->setViewCenter(QVector3D(0, 0, 0)); - - Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity); - Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity); - light->setColor("white"); - light->setIntensity(1); - lightEntity->addComponent(light); - - Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity); - lightTransform->setTranslation(cameraEntity->position()); - lightEntity->addComponent(lightTransform); - - // For camera controls - Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity); - camController->setCamera(cameraEntity); - - // Set root object of the scene - view->setRootEntity(rootEntity); - - // Load custom 3D model - Qt3DRender::QMesh *customMesh = new Qt3DRender::QMesh(); - customMesh->setSource(QUrl::fromLocalFile(":/obj/data/obj/defaultactor_LOD0.obj")); - - // Adjust the model transformation - Qt3DCore::QTransform *customTransform = new Qt3DCore::QTransform(); - customTransform->setRotationX(-90); - customTransform->setRotationY(-90); - - // Keep translation if necessary - customTransform->setTranslation(QVector3D(0.0f, -100.0f, -200.0f)); - - Qt3DExtras::QNormalDiffuseMapMaterial *customMaterial = new Qt3DExtras::QNormalDiffuseMapMaterial(); - - Qt3DRender::QTextureLoader *normalMap = new Qt3DRender::QTextureLoader(); - normalMap->setSource(QUrl::fromLocalFile(":/obj/data/obj/normalmap.png")); - customMaterial->setNormal(normalMap); - - Qt3DRender::QTextureLoader *diffuseMap = new Qt3DRender::QTextureLoader(); - diffuseMap->setSource(QUrl::fromLocalFile(":/obj/data/obj/diffusemap.png")); - customMaterial->setDiffuse(diffuseMap); - - Qt3DCore::QEntity *m_torusEntity = new Qt3DCore::QEntity(rootEntity); - m_torusEntity->addComponent(customMesh); - m_torusEntity->addComponent(customMaterial); - m_torusEntity->addComponent(customTransform); - - LoadFile_D3DBSP(":/d3dbsp/data/d3dbsp/barebones.d3dbsp"); - - Reset(); -} - -MainWindow::~MainWindow() { - delete ui; -} - -void MainWindow::Reset() { - // Reset tabwidget to 'General' tab - ui->tabWidget->setCurrentIndex(0); - - // Reset 'General' tab fields - ui->lineEdit_FastFile->clear(); - ui->comboBox_Company->setCurrentIndex(0); - ui->comboBox_FileType->setCurrentIndex(0); - ui->checkBox_Signed->setChecked(false); - ui->lineEdit_Magic->clear(); - ui->spinBox_Magic->clear(); - ui->spinBox_TagCount->clear(); - ui->spinBox_FileSize->clear(); - ui->spinBox_RecordCount->clear(); - - // Reset 'Unknowns' tab fields - ui->lineEdit_U1->clear(); - ui->spinBox_U1->clear(); - ui->lineEdit_U2->clear(); - ui->spinBox_U2->clear(); - ui->lineEdit_U3->clear(); - ui->spinBox_U3->clear(); - ui->lineEdit_U4->clear(); - ui->spinBox_U4->clear(); - ui->lineEdit_U5->clear(); - ui->spinBox_U5->clear(); - ui->lineEdit_U6->clear(); - ui->spinBox_U6->clear(); - ui->lineEdit_U7->clear(); - ui->spinBox_U7->clear(); - ui->lineEdit_U8->clear(); - ui->spinBox_U8->clear(); - ui->lineEdit_U9->clear(); - ui->spinBox_U9->clear(); - ui->lineEdit_U10->clear(); - ui->spinBox_U10->clear(); - ui->lineEdit_U11->clear(); - ui->spinBox_U11->clear(); - - // Reset 'Tags' tab fields - ui->listWidget_Tags->clear(); - - // Reset 'Localized Strings' tab fields - ui->listWidget_LocalString->clear(); - - // Reset 'Asset Index/Order' tab fields - ui->tableWidget_Index->clear(); - ui->tableWidget_Order->clear(); - - // Reset 'Raw Files' tab fields - ui->treeWidget_Scripts->clear(); - ui->plainTextEdit_Scripts->clear(); - - // Reset 'Tech Sets' tab fields - ui->listWidget_TechSets->clear(); - - // Reset 'Zone Dump' tab fields - ui->spinBox_DumpIndex->clear(); - ui->comboBox_DumpAsset->setCurrentIndex(0); - ui->plainTextEdit_ZoneDump->clear(); - - // Reset 'String Tables' tab fields - ui->comboBox_StringTable->setCurrentIndex(0); - ui->tableWidget_StringTable->clear(); - - // Reset '3D Scene' tab fields - ui->treeWidget_Models->clear(); - - // Reset class vars - mTypeMap.clear(); - mTypeOrder.clear(); - mTagCount = 0; - mRecordCount = 0; - mRawFileMap.clear(); - mTreeMap.clear(); - mStrTableMap.clear(); -} - -void MainWindow::StrTableSelected(QString aStrTableName) { - ui->tableWidget_StringTable->clear(); - - ui->tableWidget_StringTable->setColumnCount(2); - int entryIndex = 0; - for (auto strTableEntry : mStrTableMap[aStrTableName]) { - ui->tableWidget_StringTable->insertRow(ui->tableWidget_StringTable->rowCount() + 1); - ui->tableWidget_StringTable->setItem(entryIndex, 0, new QTableWidgetItem(strTableEntry.first)); - ui->tableWidget_StringTable->setItem(entryIndex, 1, new QTableWidgetItem(Utils::AssetTypeToString(strTableEntry.second))); - - entryIndex++; - } -} - -void MainWindow::ScriptSelected() { - QTreeWidgetItem *selectedItem = ui->treeWidget_Scripts->selectedItems()[0]; - if (!selectedItem) { - qDebug() << "Attempted to load invalid tree item!"; - return; - } - - const QString itemName = selectedItem->text(0); - const QStringList scriptExts = {"gsc", "csc", "atr", "shock", "vision", "rmb"}; - if (!scriptExts.contains(itemName.split('.').last())) { - qDebug() << QString("Attempted to parse invalid raw file: %1!").arg(itemName); - return; - } - - ui->plainTextEdit_Scripts->clear(); - for (auto [scriptName, scriptContents] : mRawFileMap.asKeyValueRange()) { - if (scriptName.contains(itemName)) { - ui->plainTextEdit_Scripts->setPlainText(scriptContents); - return; - } - } -} - -QByteArray MainWindow::DecompressZLIB(QByteArray compressedData) { - QByteArray decompressedData; - uLongf decompressedSize = compressedData.size() * 4; - decompressedData.resize(static_cast(decompressedSize)); - - Bytef *destination = reinterpret_cast(decompressedData.data()); - uLongf *destLen = &decompressedSize; - const Bytef *source = reinterpret_cast(compressedData.data()); - uLong sourceLen = compressedData.size(); - - int result = uncompress(destination, destLen, source, sourceLen); - - if (result == Z_OK) { - decompressedData.resize(static_cast(decompressedSize)); - } else { - decompressedData.clear(); - qDebug() << QString("In DecompressZLIB: %1").arg(Utils::ZLibErrorToString(result)).toLatin1(); - } - return decompressedData; -} - -/* - OpenFastFile() - - Opens a file dialog in the steam folder, - and opens the selected file. -*/ -QFile* MainWindow::OpenFastFile() { - // Reset dialog before opening new file - Reset(); - - // Open file dialog to steam apps - const QString steamPath = "C:/Program Files (x86)/Steam/steamapps/common/Call of Duty World at War/zone/english/"; - const QString fastFilePath = QFileDialog::getOpenFileName(this, "Open FastFile", steamPath, "FastFile (*.ff);;All Files (*.*)"); - if (!QFile::exists(fastFilePath)) { - QMessageBox::warning(this, "Warning!", QString("%1 does not exist!.").arg(fastFilePath)); - return nullptr; - } - ui->lineEdit_FastFile->setText(fastFilePath); - - const QString fastFileStem = fastFilePath.split('/').last(); - setWindowTitle(QString("FastFile Wizard - %1").arg(fastFileStem)); - - // Check fastfile can be read - QFile *fastFile = new QFile(fastFilePath); - if (!fastFile->open(QIODevice::ReadOnly)) { - QMessageBox::warning(this, "Warning!", QString("%1 could not be read!.").arg(fastFilePath)); - return nullptr; - } - return fastFile; -} - -/* - OpenZoneFile() - - Opens a file dialog in the steam folder, - and opens the selected file. -*/ -QFile* MainWindow::OpenZoneFile() { - // Reset dialog before opening new file - Reset(); - - // Open file dialog to steam apps - const QString steamPath = "C:/Program Files (x86)/Steam/steamapps/common/Call of Duty World at War/zone/english/"; - const QString zoneFilePath = QFileDialog::getOpenFileName(this, "Open ZoneFile", steamPath, "ZoneFile (*.zone);;All Files (*.*)"); - if (!QFile::exists(zoneFilePath)) { - QMessageBox::warning(this, "Warning!", QString("%1 does not exist!.").arg(zoneFilePath)); - return nullptr; - } - ui->lineEdit_ZoneFile->setText(zoneFilePath); - - const QString zoneFileStem = zoneFilePath.split('/').last(); - setWindowTitle(QString("FastFile Wizard - %1").arg(zoneFileStem)); - - // Check fastfile can be read - QFile *zoneFile = new QFile(zoneFilePath); - if (!zoneFile->open(QIODevice::ReadOnly)) { - QMessageBox::warning(this, "Warning!", QString("%1 could not be read!.").arg(zoneFilePath)); - return nullptr; - } - return zoneFile; -} - -void MainWindow::ParseFFCompany(QDataStream *afastFileStream) { - // Check for null datastream ptr - if (!afastFileStream) { return; } - // Parse company - QByteArray companyData(2, Qt::Uninitialized); - afastFileStream->readRawData(companyData.data(), 2); - if (companyData == "IW") { - qDebug() << "Company found: 'INFINITY_WARD'"; - ui->comboBox_Company->setCurrentIndex(1); - } else if (companyData == "TA") { - qDebug() << "Company found: 'TREYARCH'"; - ui->comboBox_Company->setCurrentIndex(2); - } else if (companyData == "Sl") { - qDebug() << "Company found: 'SLEDGEHAMMER'"; - ui->comboBox_Company->setCurrentIndex(3); - } else if (companyData == "NX") { - qDebug() << "Company found: 'NEVERSOFT'"; - ui->comboBox_Company->setCurrentIndex(4); - } else { - qDebug() << QString("Failed to find company, found '%1'!").arg(companyData); - return; - } -} - -void MainWindow::ParseFFFileType(QDataStream *afastFileStream) { - // Parse filetype - QByteArray fileTypeData(2, Qt::Uninitialized); - afastFileStream->readRawData(fileTypeData.data(), 2); - if (fileTypeData == "ff") { - qDebug() << "File type found: 'FAST_FILE'"; - ui->comboBox_FileType->setCurrentIndex(1); - } else { - qDebug() << "Failed to find file type!"; - return; - } -} - -void MainWindow::ParseFFSignage(QDataStream *afastFileStream) { - // Parse filetype - QByteArray signedData(1, Qt::Uninitialized); - afastFileStream->readRawData(signedData.data(), 1); - if (signedData == "u") { - qDebug() << "Found valid signage: Unsigned"; - ui->checkBox_Signed->setChecked(false); - } else if (signedData == "0") { - qDebug() << "Found valid signage: Signed"; - ui->checkBox_Signed->setChecked(true); - } else { - qDebug() << "Failed to determine signage of fastfile!"; - return; - } -} - -void MainWindow::ParseFFMagic(QDataStream *afastFileStream) { - // Parse magic - QByteArray magicData(3, Qt::Uninitialized); - afastFileStream->readRawData(magicData.data(), 3); - if (magicData == "100") { - qDebug() << QString("Found valid magic: '%1'").arg(magicData); - ui->lineEdit_Magic->setText(magicData.toHex()); - ui->spinBox_Magic->setValue(magicData.toInt()); - } else { - qDebug() << "Magic invalid!"; - return; - } -} - -void MainWindow::ParseFFVersion(QDataStream *afastFileStream) { - // Parse version - quint32 version; - *afastFileStream >> version; - qDebug() << "Version:" << version; - if (version == 387) { - qDebug() << QString("Found valid version: '%1'").arg(version); - ui->spinBox_Version->setValue(version); - } else { - qDebug() << "Version invalid!"; - return; - } -} - -void MainWindow::ParseFFHeader(QFile *aFastFilePtr) { - // Open stream to fastfile - QDataStream afastFileStream(aFastFilePtr); - afastFileStream.setByteOrder(QDataStream::LittleEndian); - - ParseFFCompany(&afastFileStream); - ParseFFFileType(&afastFileStream); - ParseFFSignage(&afastFileStream); - ParseFFMagic(&afastFileStream); - ParseFFVersion(&afastFileStream); -} - -void MainWindow::ParseZoneHeader(QDataStream *aZoneFileStream) { - ParseZoneSize(aZoneFileStream); - ParseZoneUnknownsA(aZoneFileStream); - - ParseZoneTagCount(aZoneFileStream); - ParseZoneUnknownsB(aZoneFileStream); - - ParseZoneRecordCount(aZoneFileStream); - - if (mTagCount) { - ParseZoneUnknownsC(aZoneFileStream); - ParseZoneTags(aZoneFileStream); - } else { - aZoneFileStream->skipRawData(4); - } -} - -void MainWindow::ParseZoneSize(QDataStream *aZoneFileStream) { - // Byte 0-3: (unsigned int?) correlates to the fastfile's - // size after decompression minus 36 bytes (24h) - quint32 zoneFileSize; - *aZoneFileStream >> zoneFileSize; - if (zoneFileSize <= 0) { - qDebug() << "Tried to open empty zone file!"; - exit(-1); - } - zoneFileSize += 36; - ui->spinBox_FileSize->setValue(zoneFileSize); - - qDebug() << QString("Zone file size: '%1'").arg(zoneFileSize); -} - -/* - ParseZoneUnknownsA() - - Parses the 1st section of unknowns as hex vals and uint32s -*/ -void MainWindow::ParseZoneUnknownsA(QDataStream *aZoneFileStream) { - // Byte 4-7, 8-11, 12-15: unknown - QByteArray unknown1(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown1.data(), 4); - ui->lineEdit_U1->setText(unknown1.toHex()); - ui->spinBox_U1->setValue(unknown1.toUInt()); - - QByteArray unknown2(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown2.data(), 4); - ui->lineEdit_U2->setText(unknown2.toHex()); - ui->spinBox_U2->setValue(unknown2.toUInt()); - - QByteArray unknown3(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown3.data(), 4); - ui->lineEdit_U3->setText(unknown3.toHex()); - ui->spinBox_U3->setValue(unknown3.toUInt()); - - // Byte 16-19, 20-23: empty/unknown - QByteArray unknown4(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown4.data(), 4); - ui->lineEdit_U4->setText(unknown4.toHex()); - ui->spinBox_U4->setValue(unknown4.toUInt()); - - QByteArray unknown5(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown5.data(), 4); - ui->lineEdit_U5->setText(unknown5.toHex()); - ui->spinBox_U5->setValue(unknown5.toUInt()); - - // Byte 24-27: somehow related to the filesize, but smaller value - QByteArray unknown6(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown6.data(), 4); - ui->lineEdit_U6->setText(unknown6.toHex()); - ui->spinBox_U6->setValue(unknown6.toUInt()); - - // Byte 28-31, 32-35: unknown - QByteArray unknown7(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown7.data(), 4); - ui->lineEdit_U7->setText(unknown7.toHex()); - ui->spinBox_U7->setValue(unknown7.toUInt()); - - QByteArray unknown8(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown8.data(), 4); - ui->lineEdit_U8->setText(unknown8.toHex()); - ui->spinBox_U8->setValue(unknown8.toUInt()); - - qDebug() << QString("Unknowns A: '%1''%2''%3''%4''%5''%6''%7''%8'") - .arg(unknown1.toHex()) - .arg(unknown2.toHex()) - .arg(unknown3.toHex()) - .arg(unknown4.toHex()) - .arg(unknown5.toHex()) - .arg(unknown6.toHex()) - .arg(unknown7.toHex()) - .arg(unknown8.toHex()); -} - -/* - ParseZoneTagCount() - - Parses the number of string tags in the zone index -*/ -void MainWindow::ParseZoneTagCount(QDataStream *aZoneFileStream) { - // Byte 36-39: might indicate where the index record starts, - // calculation unknown - *aZoneFileStream >> mTagCount; - ui->spinBox_TagCount->setValue(mTagCount); - qDebug() << QString("Tag count: '%1'").arg(mTagCount); -} - -/* - ParseZoneRecordCount() - - Parses the number of records in the zone index -*/ -void MainWindow::ParseZoneRecordCount(QDataStream *aZoneFileStream) { - // Byte 44-47: (unsigned int) number of records - *aZoneFileStream >> mRecordCount; - ui->spinBox_RecordCount->setValue(mRecordCount); - qDebug() << QString("Record count: '%1'").arg(mRecordCount); -} - -/* - ParseZoneUnknownsB() - - Parses the 2nd section of unknowns as hex vals and uint32s -*/ -void MainWindow::ParseZoneUnknownsB(QDataStream *aZoneFileStream) { - // Byte 44-47: Unknown/empty? - QByteArray unknown9(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown9.data(), 4); - ui->lineEdit_U9->setText(unknown9.toHex()); - ui->spinBox_U9->setValue(unknown9.toUInt()); - - qDebug() << QString("Unknowns B: \n\t'%1'") - .arg(unknown9.toHex()); -} - -/* - ParseZoneUnknownsC() - - Parses the 3rd section of unknowns as hex vals and uint32s -*/ -void MainWindow::ParseZoneUnknownsC(QDataStream *aZoneFileStream) { - // Byte 40-43: Unknown/empty? - QByteArray unknown10(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown10.data(), 4); - ui->lineEdit_U10->setText(unknown10.toHex()); - ui->spinBox_U10->setValue(unknown10.toUInt()); - - // Byte 44-47: Unknown/empty? - QByteArray unknown11(4, Qt::Uninitialized); - aZoneFileStream->readRawData(unknown11.data(), 4); - ui->lineEdit_U11->setText(unknown11.toHex()); - ui->spinBox_U11->setValue(unknown11.toUInt()); - - qDebug() << QString("Unknowns C: \n\t'%1'\n\t'%2'") - .arg(unknown10.toHex()) - .arg(unknown11.toHex()); -} - -/* - ParseZoneTags() - - Parses the string tags ate the start of zone file -*/ -void MainWindow::ParseZoneTags(QDataStream *aZoneFileStream) { - // Byte 48-51: Repeated separators? ÿÿÿÿ x i - aZoneFileStream->skipRawData(4 * (mTagCount - 1)); - - // Parse tags/strings before index - QString zoneTag; - char zoneTagChar; - for (quint32 i = 0; i < mTagCount - 1; i++) { - *aZoneFileStream >> zoneTagChar; - while (zoneTagChar != 0) { - zoneTag += zoneTagChar; - *aZoneFileStream >> zoneTagChar; - } - ui->listWidget_Tags->addItem(zoneTag); - // qDebug() << "Tag: " << zoneTag; - zoneTag.clear(); - } -} - -/* - ParseZoneIndex() - - Parse the binary zone index data and populate table -*/ -void MainWindow::ParseZoneIndex(QDataStream *aZoneFileStream) { - // Don't parse if no records - if (!mRecordCount) { return; } - - // Track past assets and counts - int consecutiveIndex = 0; - int consecutiveCount = 0; - QString lastAssetType = ""; - - // Parse index & map found asset types - for (quint32 i = 0; i < mRecordCount; i++) { - // Skip record start - QByteArray rawAssetType(4, Qt::Uninitialized); - aZoneFileStream->readRawData(rawAssetType.data(), 4); - if (!mTypeMap.contains(rawAssetType.toHex())) { - mTypeMap[rawAssetType.toHex()] = 0; - } - mTypeMap[rawAssetType.toHex()]++; - mTypeOrder << rawAssetType.toHex(); - - // Skip separator - aZoneFileStream->skipRawData(4); - - // Get asset description from type - const QString assetType = rawAssetType.toHex(); - - // Set lastAsset as current if first run - if (lastAssetType.isEmpty()) { - lastAssetType = assetType; - } - - // Track counts or populate asset order table - if (lastAssetType == assetType) { - // Count consecutive assets - consecutiveCount++; - } else { - // Insert row and populate for the previous asset type - ui->tableWidget_Order->insertRow(consecutiveIndex); - ui->tableWidget_Order->setItem(consecutiveIndex, 0, new QTableWidgetItem(lastAssetType)); - ui->tableWidget_Order->setItem(consecutiveIndex, 1, new QTableWidgetItem(Utils::AssetTypeToString(lastAssetType))); - ui->tableWidget_Order->setItem(consecutiveIndex, 2, new QTableWidgetItem(QString::number(consecutiveCount))); - - // Update counts and asset type - consecutiveCount = 1; - consecutiveIndex++; - lastAssetType = assetType; - } - } -} - -void MainWindow::ParseAsset_LocalString(QDataStream *aZoneFileStream) { - // Skip separator - qint32 langStrPtr, referenceStrPtr; - *aZoneFileStream >> langStrPtr >> referenceStrPtr; - - // Parse language-specific string if present - QString langStr; - if (langStrPtr == -1) { - char langStrChar; - *aZoneFileStream >> langStrChar; - while (langStrChar != 0) { - langStr += langStrChar; - *aZoneFileStream >> langStrChar; - } - } else { - langStr = "MEMORY_REFERENCE"; - } - - // Parse reference str ig present - QString referenceStr; - if (referenceStrPtr == -1) { - char referenceStrChar; - *aZoneFileStream >> referenceStrChar; - while (referenceStrChar != 0) { - referenceStr += referenceStrChar; - *aZoneFileStream >> referenceStrChar; - } - } else { - referenceStr = "MEMORY_REFERENCE"; - } - - const int localStrIndex = ui->listWidget_LocalString->count() + 1; - ui->listWidget_LocalString->addItem(QString("[%1] %2 = %3").arg(localStrIndex).arg(referenceStr).arg(langStr)); -} - -void MainWindow::ParseAsset_RawFile(QDataStream *aZoneFileStream) { - // Skip start separator FF FF FF FF (pointer?) - aZoneFileStream->skipRawData(4); - - quint32 rawFileLength; - *aZoneFileStream >> rawFileLength; - - // Skip unknown 4 byte data - aZoneFileStream->skipRawData(4); - - bool isBik = false; - - // Parse rawfile path - QString rawFilePath; - char rawFilePathChar; - *aZoneFileStream >> rawFilePathChar; - while (rawFilePathChar != 0) { - rawFilePath += rawFilePathChar; - *aZoneFileStream >> rawFilePathChar; - } - rawFilePath.replace(",", ""); - if (rawFilePath.contains(".bik")) { - isBik = true; - } else { - const QStringList pathParts = rawFilePath.split('/'); - if (pathParts.size() == 0) { - qDebug() << "Failed to parse ff path! " << rawFilePath; - exit(-1); - } else if (pathParts.size() == 1) { - const QString path = pathParts[0]; - QTreeWidgetItem *newRootItem = new QTreeWidgetItem(ui->treeWidget_Scripts); - newRootItem->setText(0, path); - } else { - const QString path = pathParts[0]; - QTreeWidgetItem *newRootItem; - if (mTreeMap.contains(path)) { - newRootItem = mTreeMap[path]; - } else { - newRootItem = new QTreeWidgetItem(ui->treeWidget_Scripts); - newRootItem->setText(0, path); - mTreeMap[path] = newRootItem; - } - - QTreeWidgetItem *parentItem = newRootItem; - for (int i = 1; i < pathParts.size(); i++) { - const QString path = pathParts[i]; - QTreeWidgetItem *newChildItem; - if (mTreeMap.contains(path)) { - newChildItem = mTreeMap[path]; - } else { - newChildItem = new QTreeWidgetItem(); - newChildItem->setText(0, path); - mTreeMap[path] = newChildItem; - } - parentItem->addChild(newChildItem); - parentItem = newChildItem; - } - } - } - - if (false && isBik) { - qDebug() << "rawFileLength: " << rawFileLength; - QByteArray bikData(rawFileLength, Qt::Uninitialized); - aZoneFileStream->readRawData(bikData.data(), rawFileLength); - - //QFile bikFile(QDir::currentPath() + "/" + rawFilePath.split('/').last()); - //qDebug() << bikFile.fileName(); - //if (!bikFile.open(QIODevice::WriteOnly)) { - // qWarning() << "Failed to open .bik file for writing!"; - // return; - //} - //qDebug() << QString("%1: %2").arg(rawFilePath).arg(bikFile.fileName()); - //bikFile.write(bikData); - } else { - // Parse gsc contents - QString rawFileContents; - char rawFileContentsChar; - *aZoneFileStream >> rawFileContentsChar; - while (rawFileContentsChar != 0 && rawFileContentsChar != -1) { - rawFileContents += rawFileContentsChar; - *aZoneFileStream >> rawFileContentsChar; - } - mRawFileMap[rawFilePath] = (rawFileContents.isEmpty()) ? ("EMPTY") : (rawFileContents); - qDebug() << QString("%1: %2").arg(rawFilePath).arg(rawFileContents); - } -} - -void MainWindow::ParseAsset_PhysPreset(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_XModel(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_Material(QDataStream *aZoneFileStream) { - aZoneFileStream->skipRawData(27 * 4); - - qint32 materialNamePtr; - *aZoneFileStream >> materialNamePtr; - qDebug() << "materialNamePtr: " << materialNamePtr; - if (materialNamePtr == -1) { - QString materialName; - char materialNameChar; - *aZoneFileStream >> materialNameChar; - while (materialNameChar != 0) { - materialName += materialNameChar; - *aZoneFileStream >> materialNameChar; - } - qDebug() << "Parsing Material: " << materialName; - } - - aZoneFileStream->skipRawData(3 * 4); - - qint32 compressionPtr, compression, unknownSectionPtr; - *aZoneFileStream >> compressionPtr; - qDebug() << "compressionPtr: " << compressionPtr; - if (compressionPtr == -1) { - *aZoneFileStream >> compression; - qDebug() << QString("Found material with DXT%1 compression!").arg(compression); - - *aZoneFileStream >> unknownSectionPtr; - qDebug() << "unknownSectionPtr: " << unknownSectionPtr; - if (unknownSectionPtr == -2) { - aZoneFileStream->skipRawData(6 * 4); - } - } - - qint32 imageNamePtr; - *aZoneFileStream >> imageNamePtr; - qDebug() << "imageNamePtr: " << imageNamePtr; - if (imageNamePtr == -1) { - QString imageName; - char imageNameChar; - *aZoneFileStream >> imageNameChar; - while (imageNameChar != 0) { - imageName += imageNameChar; - *aZoneFileStream >> imageNameChar; - } - qDebug() << "- Embeded image: " << imageName; - } - - QByteArray compressionData(4, Qt::Uninitialized); - QString compressionStr; - if (compressionPtr == -1) { - aZoneFileStream->skipRawData(2 * 4); - aZoneFileStream->readRawData(compressionData.data(), 4); - aZoneFileStream->skipRawData(4); - compressionStr = QString::fromUtf8(compressionData); - aZoneFileStream->skipRawData(4); - } - aZoneFileStream->skipRawData(4); -} - -void MainWindow::ParseAsset_PixelShader(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_BikFile(QDataStream *aZoneFileStream) { - QByteArray testData(32, Qt::Uninitialized); - aZoneFileStream->readRawData(testData.data(), 32); - qDebug() << "Test Data: " << testData; - - //aZoneFileStream->skipRawData(4); - - quint32 fileSize; - //*aZoneFileStream >> fileSize; - //qDebug() << ".bik file size:" << fileSize; - - // // Parse rawfile path - // QString filePath; - // char filePathChar; - // *aZoneFileStream >> filePathChar; - // while (filePathChar != 0) { - // filePath += filePathChar; - // *aZoneFileStream >> filePathChar; - // } - - // QByteArray bikData(fileSize, Qt::Uninitialized); - // aZoneFileStream->readRawData(bikData.data(), fileSize); - // qDebug() << filePath; - - // QFile bikFile(QDir::currentPath() + "/" + filePath.split('/').last()); - // qDebug() << bikFile.fileName(); - // if (!bikFile.open(QIODevice::WriteOnly)) { - // qWarning() << "Failed to open .bik file for writing!"; - // return; - // } - // bikFile.write(bikData); -} - -void MainWindow::ParseAsset_Image(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_LoadedSound(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_ColMapMP(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_GameMapSP(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_GameMapMP(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_LightDef(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_UIMap(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_AIType(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_FX(QDataStream *aZoneFileStream) { - -} - -void MainWindow::ParseAsset_XAnim(QDataStream *aZoneFileStream) { - // Read in pointer to x_anim name - QByteArray namePtr(4, Qt::Uninitialized); - aZoneFileStream->readRawData(namePtr.data(), 4); - - // Read in counts - quint16 dataByteCount, dataShortCount, - dataIntCount, randomDataByteCount, - randomDataIntCount, numframes; - *aZoneFileStream >> dataByteCount >> dataShortCount >> - dataIntCount >> randomDataByteCount >> - randomDataIntCount >> numframes; - - // Read bool flags - bool isLooped, isDelta; - *aZoneFileStream >> isLooped >> isDelta; - - // Read in more counts - quint8 noneRotatedBoneCount, - twoDRotatedBoneCount, normalRotatedBoneCount, - twoDStaticRotatedBoneCount, normalStaticRotatedBoneCount, - normalTranslatedBoneCount, preciseTranslatedBoneCount, - staticTranslatedBoneCount, noneTranslatedBoneCount, - totalBoneCount, otherBoneCount1, otherBoneCount2; - *aZoneFileStream >> noneRotatedBoneCount >> - twoDRotatedBoneCount >> normalRotatedBoneCount >> - twoDStaticRotatedBoneCount >> normalStaticRotatedBoneCount >> - normalTranslatedBoneCount >> preciseTranslatedBoneCount >> - staticTranslatedBoneCount >> noneTranslatedBoneCount >> - totalBoneCount >> otherBoneCount1 >> otherBoneCount2; - - // Yet more counts - quint8 notifyCount, assetType; - *aZoneFileStream >> notifyCount >> assetType; - - // Read more bool flags - bool pad; - *aZoneFileStream >> pad; - - // Yet more more counts - unsigned int randomDataShortCount, indexCount; - *aZoneFileStream >> randomDataShortCount >> indexCount; - - // Read in floats - float frameRate, frequency; - *aZoneFileStream >> frameRate >> frequency; - - // Read in pointers - quint32 boneIDsPtr, dataBytePtr, dataShortPtr, dataIntPtr, - randomDataShortPtr, randomDataBytePtr, randomDataIntPtr, - longIndiciesPtr, notificationsPtr, deltaPartsPtr; - *aZoneFileStream >> boneIDsPtr >> dataBytePtr >> dataShortPtr - >> dataIntPtr >> randomDataShortPtr >> randomDataBytePtr - >> randomDataIntPtr >> longIndiciesPtr >> notificationsPtr - >> deltaPartsPtr; - - // Read in x_anim file name - QString xAnimName; - char xAnimNameChar; - *aZoneFileStream >> xAnimNameChar; - while (xAnimNameChar != 0) { - xAnimName += xAnimNameChar; - *aZoneFileStream >> xAnimNameChar; - } - - // Parse x_anim index header - QVector sectionLengths; - for (int i = 0; i < numframes; i++) { - quint8 sectionlength; - *aZoneFileStream >> sectionlength; - sectionLengths.push_back(sectionlength); - // Skip padding - aZoneFileStream->skipRawData(1); - } - // Skip unknown section - aZoneFileStream->skipRawData(2 * 8); -} - -void MainWindow::ParseAsset_MenuFile(QDataStream *aZoneFileStream) { - //MENU_FILE -} - -void MainWindow::ParseAsset_Weapon(QDataStream *aZoneFileStream) { - //WEAPON_FILE -} - -void MainWindow::ParseAsset_D3DBSP(QDataStream *aZoneFileStream) { - //D3DBSP_DUMP -} - -void MainWindow::ParseAsset_TechSet(QDataStream *aZoneFileStream) -{ - aZoneFileStream->skipRawData(4); - // Parse techset name - QString techSetName; - char techSetNameChar; - *aZoneFileStream >> techSetNameChar; - while (techSetNameChar == 0) { - *aZoneFileStream >> techSetNameChar; - } - while (techSetNameChar != 0) { - techSetName += techSetNameChar; - *aZoneFileStream >> techSetNameChar; - } - techSetName.replace(",", ""); - ui->listWidget_TechSets->addItem(techSetName); - qDebug() << "Tech Set: " << techSetName; -} - -void MainWindow::ParseAsset_StringTable(QDataStream *aZoneFileStream) { - aZoneFileStream->skipRawData(4); - - quint32 columnCount, rowCount; - *aZoneFileStream >> columnCount >> rowCount; - columnCount = 0; - rowCount = 0; - - aZoneFileStream->skipRawData(4); - - QString stringTableName; - char stringTableNameChar; - *aZoneFileStream >> stringTableNameChar; - while (stringTableNameChar != 0) { - stringTableName += stringTableNameChar; - *aZoneFileStream >> stringTableNameChar; - } - ui->comboBox_StringTable->addItem(stringTableName); - - QVector tablePointers = QVector(); - for (quint32 i = 0; i < rowCount; i++) { - QByteArray pointerData(4, Qt::Uninitialized); - aZoneFileStream->readRawData(pointerData.data(), 4); - tablePointers.push_back(pointerData.toHex()); - - aZoneFileStream->skipRawData(4); - } - - for (const QString &pointerAddr : tablePointers) { - QString leadingContent = ""; - if (pointerAddr == "FFFFFFFF") { - char leadingContentChar; - *aZoneFileStream >> leadingContentChar; - while (leadingContentChar != 0) { - leadingContent += leadingContentChar; - *aZoneFileStream >> leadingContentChar; - } - } else { - leadingContent = pointerAddr; - } - - QString content; - char contentChar; - *aZoneFileStream >> contentChar; - while (contentChar != 0) { - content += contentChar; - *aZoneFileStream >> contentChar; - } - QPair tableEntry = QPair(); - tableEntry.first = leadingContent; - tableEntry.second = content; - if (!mStrTableMap.contains(stringTableName)) { - mStrTableMap[stringTableName] = QVector>(); - } - mStrTableMap[stringTableName].push_back(tableEntry); - } -} - -void MainWindow::on_pushButton_FastFile_clicked() { - // Try to prompt user to open fastfile - QFile *fastFile; - if (!(fastFile = OpenFastFile())) { - QMessageBox::warning(this, "Warning!", QString("Failed to open FastFile!.")); - return; - } - - // Parse data from fast file header - ParseFFHeader(fastFile); - - // Decompress fastfile and close - const QByteArray fastFileData = fastFile->readAll(); - const QByteArray decompressedData = DecompressZLIB(fastFileData); - // ui->plainTextEdit_ZoneDump->setPlainText(decompressedData.toHex()); - - const QString zoneFilePath = fastFile->fileName().replace(".ff", ".zone"); - fastFile->close(); - - // Check zone file is writeable - QFile *zoneFile = new QFile(zoneFilePath); - if (!zoneFile->open(QIODevice::ReadWrite)) { - qDebug() << QString("Zone file could not be written to: '%1'").arg(zoneFilePath); - return; - } - // Write zone data - zoneFile->write(decompressedData); - zoneFile->close(); - - // Open zone file as little endian stream - QDataStream zoneFileStream(decompressedData); - zoneFileStream.setByteOrder(QDataStream::LittleEndian); - - // Parse data from zone file header - ParseZoneHeader(&zoneFileStream); - ParseZoneIndex(&zoneFileStream); - - // Track current and consecutive assets - int assetIndex = 0; - - // Iterate asset types found in index - for (auto [assetType, assetCount] : mTypeMap.asKeyValueRange()) { - // Get asset description from type - QString assetStr = Utils::AssetTypeToString(assetType); - - // Insert row and populate - ui->tableWidget_Index->insertRow(assetIndex); - ui->tableWidget_Index->setItem(assetIndex, 0, new QTableWidgetItem(assetType)); - ui->tableWidget_Index->setItem(assetIndex, 1, new QTableWidgetItem(assetStr)); - ui->tableWidget_Index->setItem(assetIndex, 2, new QTableWidgetItem(QString::number(assetCount))); - - // Update count - assetIndex++; - } - - for (int i = 0; i < mTypeOrder.size(); i++) { - const QString typeHex = mTypeOrder[i]; - const QString typeStr = Utils::AssetTypeToString(typeHex); - - // qDebug() << "Parsing Asset of Type: " << typeHex; - if (typeStr == "LOCAL STRING") { // localized string asset - ParseAsset_LocalString(&zoneFileStream); - } else if (typeStr == "RAW FILE") { // gsc - ParseAsset_RawFile(&zoneFileStream); - } else if (typeStr == "PHYS PRESET") { // physpreset - ParseAsset_PhysPreset(&zoneFileStream); - } else if (typeStr == "MODEL") { // xmodel - ParseAsset_XModel(&zoneFileStream); - } else if (typeStr == "MATERIAL") { // material - ParseAsset_Material(&zoneFileStream); - } else if (typeStr == "SHADER") { // pixelshader - ParseAsset_PixelShader(&zoneFileStream); - } else if (typeStr == "BIK FILE") { // bik file? - ParseAsset_BikFile(&zoneFileStream); - } else if (typeStr == "IMAGE") { // image - ParseAsset_Image(&zoneFileStream); - } else if (typeStr == "SOUND") { // loaded_sound - ParseAsset_LoadedSound(&zoneFileStream); - } else if (typeStr == "COLLISION MAP") { // col_map_mp - ParseAsset_ColMapMP(&zoneFileStream); - } else if (typeStr == "MP MAP") { // game_map_sp - ParseAsset_GameMapSP(&zoneFileStream); - } else if (typeStr == "SP MAP") { // game_map_mp - ParseAsset_GameMapMP(&zoneFileStream); - } else if (typeStr == "LIGHT DEF") { // lightdef - ParseAsset_LightDef(&zoneFileStream); - } else if (typeStr == "UI MAP") { // ui_map - ParseAsset_UIMap(&zoneFileStream); - } else if (typeStr == "SND DRIVER GLOBALS") { // snddriverglobals - ParseAsset_SNDDriverGlobals(&zoneFileStream); - } else if (typeStr == "AI TYPE") { // aitype - ParseAsset_AIType(&zoneFileStream); - } else if (typeStr == "EFFECT") { // aitype - ParseAsset_FX(&zoneFileStream); - } else if (typeStr == "ANIMATION") { // aitype - ParseAsset_XAnim(&zoneFileStream); - } else if (typeStr == "STRING TABLE") { // string_table - ParseAsset_StringTable(&zoneFileStream); - } else if (typeStr == "MENU") { // string_table - ParseAsset_MenuFile(&zoneFileStream); - } else if (typeStr == "WEAPON") { // string_table - ParseAsset_Weapon(&zoneFileStream); - } else if (typeStr == "D3DBSP DUMP") { // string_table - ParseAsset_D3DBSP(&zoneFileStream); - } else if (typeStr == "TECH SET") { // string_table - ParseAsset_TechSet(&zoneFileStream); - } else if (typeStr != "UNKNOWN") { - qDebug() << "Found bad asset type!" << typeStr; - } - } - - // Close zone file - zoneFile->close(); - - // Clean up - delete zoneFile; - delete fastFile; -} - -void MainWindow::on_pushButton_FastFile_2_clicked() { - // Check zone file is writeable - QFile *zoneFile; - if (!(zoneFile = OpenZoneFile())) { - QMessageBox::warning(this, "Warning!", QString("Failed to open FastFile!.")); - return; - } - const QByteArray decompressedData = zoneFile->readAll(); - - // Open zone file as little endian stream - QDataStream zoneFileStream(decompressedData); - zoneFileStream.setByteOrder(QDataStream::LittleEndian); - - // Parse data from zone file header - ParseZoneHeader(&zoneFileStream); - ParseZoneIndex(&zoneFileStream); - - // Track current and consecutive assets - int assetIndex = 0; - - // Iterate asset types found in index - for (auto [assetType, assetCount] : mTypeMap.asKeyValueRange()) { - // Get asset description from type - QString assetStr = Utils::AssetTypeToString(assetType); - - // Insert row and populate - ui->tableWidget_Index->insertRow(assetIndex); - ui->tableWidget_Index->setItem(assetIndex, 0, new QTableWidgetItem(assetType)); - ui->tableWidget_Index->setItem(assetIndex, 1, new QTableWidgetItem(assetStr)); - ui->tableWidget_Index->setItem(assetIndex, 2, new QTableWidgetItem(QString::number(assetCount))); - - // Update count - assetIndex++; - } - - for (int i = 0; i < mTypeOrder.size(); i++) { - const QString typeHex = mTypeOrder[i]; - const QString typeStr = Utils::AssetTypeToString(typeHex); - - // qDebug() << "Parsing Asset of Type: " << typeHex; - if (typeStr == "LOCAL STRING") { // localized string asset - ParseAsset_LocalString(&zoneFileStream); - } else if (typeStr == "RAW FILE") { // gsc - ParseAsset_RawFile(&zoneFileStream); - } else if (typeStr == "PHYS PRESET") { // physpreset - ParseAsset_PhysPreset(&zoneFileStream); - } else if (typeStr == "MODEL") { // xmodel - ParseAsset_XModel(&zoneFileStream); - } else if (typeStr == "MATERIAL") { // material - ParseAsset_Material(&zoneFileStream); - } else if (typeStr == "SHADER") { // pixelshader - ParseAsset_PixelShader(&zoneFileStream); - } else if (typeStr == "BIK FILE") { // .bik file - ParseAsset_BikFile(&zoneFileStream); - } else if (typeStr == "IMAGE") { // image - ParseAsset_Image(&zoneFileStream); - } else if (typeStr == "SOUND") { // loaded_sound - ParseAsset_LoadedSound(&zoneFileStream); - } else if (typeStr == "COLLISION MAP") { // col_map_mp - ParseAsset_ColMapMP(&zoneFileStream); - } else if (typeStr == "MP MAP") { // game_map_sp - ParseAsset_GameMapSP(&zoneFileStream); - } else if (typeStr == "SP MAP") { // game_map_mp - ParseAsset_GameMapMP(&zoneFileStream); - } else if (typeStr == "LIGHT DEF") { // lightdef - ParseAsset_LightDef(&zoneFileStream); - } else if (typeStr == "UI MAP") { // ui_map - ParseAsset_UIMap(&zoneFileStream); - } else if (typeStr == "SND DRIVER GLOBALS") { // snddriverglobals - ParseAsset_SNDDriverGlobals(&zoneFileStream); - } else if (typeStr == "AI TYPE") { // aitype - ParseAsset_AIType(&zoneFileStream); - } else if (typeStr == "EFFECT") { // aitype - ParseAsset_FX(&zoneFileStream); - } else if (typeStr == "ANIMATION") { // aitype - ParseAsset_XAnim(&zoneFileStream); - } else if (typeStr == "STRING TABLE") { // string_table - ParseAsset_StringTable(&zoneFileStream); - } else if (typeStr == "MENU") { // string_table - ParseAsset_MenuFile(&zoneFileStream); - } else if (typeStr == "WEAPON") { // string_table - ParseAsset_Weapon(&zoneFileStream); - } else if (typeStr == "D3DBSP DUMP") { // string_table - ParseAsset_D3DBSP(&zoneFileStream); - } else if (typeStr == "TECH SET") { // string_table - ParseAsset_TechSet(&zoneFileStream); - } else { - qDebug() << "Found bad asset type!" << typeStr; - } - } - - // Close zone file - zoneFile->close(); - - // Clean up - delete zoneFile; -} - -int MainWindow::LoadFile_D3DBSP(const QString aFilePath) { - QFile file(aFilePath); - if (!file.open(QIODevice::ReadOnly)) { - qDebug() << "Error: Unable to open file" << aFilePath; - return 1; // ERR_FILE_NOT_FOUND - } - - QDataStream stream(&file); - stream.setByteOrder(QDataStream::LittleEndian); - - // Read Magic Value - quint32 magicValue; - stream >> magicValue; - if (magicValue != 'PSBI') { - qDebug() << "Error: Not a valid D3DBSP file"; - return 2; // ERR_NOT_A_D3DBSP_FILE - } - - // Read BSP Version and Lump Count - stream >> mBSPVersion; - stream >> mDiskLumpCount; - - // Assign diskLumpOrderSize - mDiskLumpOrder.resize(mDiskLumpCount); - - qDebug() << "BSP Version:" << mBSPVersion; - qDebug() << "Lump Count:" << mDiskLumpCount; - - // Read Lump Index Entries - quint32 lumpOffset = sizeof(quint32) * 3 + sizeof(LumpIndexEntry) * mDiskLumpCount; - - for (quint32 i = 0; i < mDiskLumpCount; i++) { - LumpIndexEntry indexEntry; - stream >> indexEntry.type >> indexEntry.length; - - mDiskLumpOrder[i] = indexEntry.type; - - Lump &lump = mLumps[indexEntry.type]; - lump.size = indexEntry.length; - lump.content.resize(indexEntry.length); - lump.isEmpty = false; - - qDebug() << "Lump Type:" << Utils::LumpTypeToString((LUMP_TYPE)indexEntry.type) << "Lump Size:" << indexEntry.length; - - // Handle offsets and padding - qint64 currentPos = file.pos(); - file.seek(lumpOffset); - file.read(lump.content.data(), lump.size); - file.seek(currentPos); - lumpOffset += Utils::PadInt4(indexEntry.length); - } - - file.close(); - return 0; // Success -} - diff --git a/mainwindow.h b/mainwindow.h deleted file mode 100644 index 058bf8f..0000000 --- a/mainwindow.h +++ /dev/null @@ -1,153 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include "enums.h" -#include "structs.h" -#include "utils.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -namespace Ui { -class MainWindow; -} -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - void Reset(); - - QByteArray DecompressZLIB(QByteArray compressedData); - -private slots: - void on_pushButton_FastFile_clicked(); - void on_pushButton_FastFile_2_clicked(); - - QFile *OpenFastFile(); - QFile *OpenZoneFile(); - void ParseFFHeader(QFile *aFastFilePtr); - void ParseFFCompany(QDataStream *aFastFileStream); - void ParseFFFileType(QDataStream *afastFileStream); - void ParseFFSignage(QDataStream *afastFileStream); - void ParseFFMagic(QDataStream *afastFileStream); - void ParseFFVersion(QDataStream *afastFileStream); - - void ParseZoneHeader(QDataStream *aZoneFileStream); - void ParseZoneSize(QDataStream *aZoneFileStream); - - void ParseZoneUnknownsA(QDataStream *aZoneFileStream); - void ParseZoneUnknownsB(QDataStream *aZoneFileStream); - void ParseZoneUnknownsC(QDataStream *aZoneFileStream); - void ParseZoneTagCount(QDataStream *aZoneFileStream); - void ParseZoneRecordCount(QDataStream *aZoneFileStream); - void ParseZoneTags(QDataStream *aZoneFileStream); - void ParseZoneIndex(QDataStream *aZoneFileStream); - - void ParseAsset_LocalString(QDataStream *aZoneFileStream); - void ParseAsset_RawFile(QDataStream *aZoneFileStream); - void ParseAsset_PhysPreset(QDataStream *aZoneFileStream); - void ParseAsset_XModel(QDataStream *aZoneFileStream); - void ParseAsset_Material(QDataStream *aZoneFileStream); - void ParseAsset_PixelShader(QDataStream *aZoneFileStream); - void ParseAsset_BikFile(QDataStream *aZoneFileStream); - void ParseAsset_Image(QDataStream *aZoneFileStream); - void ParseAsset_LoadedSound(QDataStream *aZoneFileStream); - void ParseAsset_ColMapMP(QDataStream *aZoneFileStream); - void ParseAsset_GameMapSP(QDataStream *aZoneFileStream); - void ParseAsset_GameMapMP(QDataStream *aZoneFileStream); - void ParseAsset_LightDef(QDataStream *aZoneFileStream); - void ParseAsset_UIMap(QDataStream *aZoneFileStream); - void ParseAsset_SNDDriverGlobals(QDataStream *aZoneFileStream); - void ParseAsset_AIType(QDataStream *aZoneFileStream); - void ParseAsset_FX(QDataStream *aZoneFileStream); - void ParseAsset_XAnim(QDataStream *aZoneFileStream); - void ParseAsset_StringTable(QDataStream *aZoneFileStream); - void ParseAsset_MenuFile(QDataStream *aZoneFileStream); - void ParseAsset_Weapon(QDataStream *aZoneFileStream); - void ParseAsset_D3DBSP(QDataStream *aZoneFileStream); - void ParseAsset_TechSet(QDataStream *aZoneFileStream); - - int LoadFile_D3DBSP(const QString aFilePath); - - void ScriptSelected(); - void StrTableSelected(QString aStrTableName); - -private: - Ui::MainWindow *ui; - QMap mTypeMap; - QStringList mTypeOrder; - quint32 mTagCount; - quint32 mRecordCount; - QMap mRawFileMap; - QMap mTreeMap; - QMap>> mStrTableMap; - - quint32 mBSPVersion; - quint32 mDiskLumpCount; - QVector mDiskLumpOrder; - QMap mLumps; - -}; -#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui deleted file mode 100644 index 0476b70..0000000 --- a/mainwindow.ui +++ /dev/null @@ -1,1079 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 850 - 628 - - - - FastFile Wizard - - - QMainWindow { - -} - - - - - - - true - - - - 14 - true - - - - WAW - PC - FastFile Viewer - - - Qt::AlignmentFlag::AlignCenter - - - - - - - true - - - Qt::Orientation::Horizontal - - - - - - - true - - - 0 - - - - General - - - - - - - - true - - - FastFile path... - - - - - - - true - - - Open .ff - - - - - - - - - - - true - - - ZoneFile path... - - - - - - - true - - - Open .zone - - - - - - - - - - - true - - - Company: - - - - - - - true - - - - Select Company - - - - - INFINITY_WARD - - - - - TREYARCH - - - - - SLEDGEHAMMER - - - - - NEVERSOFT - - - - - - - - - - - - true - - - File Type: - - - - - - - true - - - - Select File Type - - - - - FAST_FILE - - - - - - - - true - - - Signed - - - - - - - - - - - true - - - Magic: - - - - - - - true - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - true - - - Tag Count - - - - - - - true - - - 999999999 - - - - - - - - - - - true - - - File Size: - - - - - - - true - - - B - - - 999999999 - - - - - - - - - - - true - - - Version: - - - - - - - true - - - 999999999 - - - - - - - - - - - true - - - Record Count - - - - - - - true - - - 999999999 - - - - - - - - - Qt::Orientation::Vertical - - - - 17 - 242 - - - - - - - - - Unknowns - - - - - - - - Unknown 1: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 2: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 4: - - - - - - - - 0 - 0 - - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 3: - - - - - - - - 0 - 0 - - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 6: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 5: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 8: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 7: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 9: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 10: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - - - Unknown 11: - - - - - - - - 0 - 0 - - - - true - - - - - - - true - - - 999999999 - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - Tags - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - true - - - - - - - - Localized Strings - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - Asset Index/Order - - - - - - Asset Index Table - - - - - - 3 - - - 50 - - - true - - - true - - - false - - - - - - - - - - This table shows the total asset counts per type. - - - - - - - - - - Qt::Orientation::Vertical - - - - - - - Asset Order Table - - - - - - 3 - - - 50 - - - true - - - true - - - false - - - - - - - - - - This table shows the consecutive asset counts in order. - - - - - - - - - - - Raw Files - - - - - - - 0 - 0 - - - - - 200 - 16777215 - - - - - 1 - - - - - - - - - 0 - 0 - - - - - - - - - Tech Sets - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - Zone Dump - - - - - - - - Select Asset: - - - - - - - - - - - - - - - - - - - String Tables - - - - - - - - String Table: - - - - - - - - - - - - - - - - 3D Scene - - - - - - - 200 - 16777215 - - - - - 1 - - - - - - - - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised - - - - - - - - - - - - - true - - - < Back - - - - - - - true - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - true - - - Next > - - - - - - - - - - - diff --git a/tests/360/autotest_cod10_360.cpp b/tests/360/autotest_cod10_360.cpp new file mode 100644 index 0000000..5bebf11 --- /dev/null +++ b/tests/360/autotest_cod10_360.cpp @@ -0,0 +1,127 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod10/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_360::testDecompression() { + QFETCH(QString, fastFilePath_cod10_360); + + const QString testName = "Decompress: " + fastFilePath_cod10_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_360::testCompression() { + QFETCH(QString, zoneFilePath_cod10_360); + + QFile zoneFile(zoneFilePath_cod10_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_360.moc" diff --git a/tests/360/autotest_cod11_360.cpp b/tests/360/autotest_cod11_360.cpp new file mode 100644 index 0000000..9b2a37f --- /dev/null +++ b/tests/360/autotest_cod11_360.cpp @@ -0,0 +1,127 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD11_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod11/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD11_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD11_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod11_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_360::testDecompression() { + QFETCH(QString, fastFilePath_cod11_360); + + const QString testName = "Decompress: " + fastFilePath_cod11_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod11_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod11_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod11_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod11_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD11_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod11_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_360::testCompression() { + QFETCH(QString, zoneFilePath_cod11_360); + + QFile zoneFile(zoneFilePath_cod11_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod11_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod11_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD11_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod11_360.moc" diff --git a/tests/360/autotest_cod12_360.cpp b/tests/360/autotest_cod12_360.cpp new file mode 100644 index 0000000..dd7a1d0 --- /dev/null +++ b/tests/360/autotest_cod12_360.cpp @@ -0,0 +1,139 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD12_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod12/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD12_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD12_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod12_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_360::testDecompression() { + QFETCH(QString, fastFilePath_cod12_360); + + const QString testName = "Decompress: " + fastFilePath_cod12_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod12_360); + bool fastFileOpened = testFastFile.open(QIODevice::ReadOnly); + if (!fastFileOpened) { + recordResult(testName, false); + } + QVERIFY2(fastFileOpened, + qPrintable("Failed to open test fastfile: " + fastFilePath_cod12_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + bool sizeMatches = zoneSize + 44 == testZoneData.size(); + if (!sizeMatches) { + recordResult(testName, false); + } + QVERIFY2(sizeMatches, + qPrintable("Decompression validation failed for: " + fastFilePath_cod12_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod12_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + bool zoneFileOpened = outputFile.open(QIODevice::WriteOnly); + if (!zoneFileOpened) { + recordResult(testName, false); + } + QVERIFY2(zoneFileOpened, + qPrintable("Failed to open output zone file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD12_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod12_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_360::testCompression() { + QFETCH(QString, zoneFilePath_cod12_360); + + QFile zoneFile(zoneFilePath_cod12_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod12_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod12_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD12_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod12_360.moc" diff --git a/tests/360/autotest_cod2_360.cpp b/tests/360/autotest_cod2_360.cpp new file mode 100644 index 0000000..cd82e76 --- /dev/null +++ b/tests/360/autotest_cod2_360.cpp @@ -0,0 +1,152 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD2_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod2/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD2_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD2_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod2_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD2_360::testDecompression() { + QFETCH(QString, fastFilePath_cod2_360); + + const QString testName = "Decompress: " + fastFilePath_cod2_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod2_360); + bool fastFileOpened = testFastFile.open(QIODevice::ReadOnly); + if (!fastFileOpened) { + recordResult(testName, false); + } + QVERIFY2(fastFileOpened + , qPrintable("Failed to open test fastfile: " + fastFilePath_cod2_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(20); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + // TODO: Find new way to verify as cod2 doesn't store size in zone file + //QVERIFY2(zoneSize + 44 == testZoneData.size(), + // qPrintable("Decompression validation failed for: " + fastFilePath_cod2_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod2_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + bool zoneFileOpened = outputFile.open(QIODevice::WriteOnly); + if (!zoneFileOpened) { + recordResult(testName, false); + } + QVERIFY2(zoneFileOpened, + qPrintable("Failed to open output zone file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); + + recordResult(testName, true); +} + +void AutoTest_COD2_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod2_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD2_360::testCompression() { + QFETCH(QString, zoneFilePath_cod2_360); + + const QString testName = "Compress: " + zoneFilePath_cod2_360; + + QFile zoneFile(zoneFilePath_cod2_360); + bool zoneFileOpened = zoneFile.open(QIODevice::ReadOnly); + if (!zoneFileOpened) { + recordResult(testName, false); + } + QVERIFY2(zoneFileOpened, qPrintable("Failed to open zone file: " + zoneFilePath_cod2_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod2_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + bool origFileOpened = originalFile.open(QIODevice::ReadOnly); + if (!origFileOpened) { + recordResult(testName, false); + } + QVERIFY2(origFileOpened, qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(20); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + bool fastFileOpened = recompressedFile.open(QIODevice::WriteOnly); + if (!fastFileOpened) { + recordResult(testName, false); + } + QVERIFY2(fastFileOpened, qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + bool dataMatches = recompressedData == originalFFData; + if (!dataMatches) { + recordResult(testName, false); + } + QCOMPARE(recompressedData, originalFFData); + + recordResult(testName, true); +} + +void AutoTest_COD2_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod2_360.moc" diff --git a/tests/360/autotest_cod4_360.cpp b/tests/360/autotest_cod4_360.cpp new file mode 100644 index 0000000..9446a47 --- /dev/null +++ b/tests/360/autotest_cod4_360.cpp @@ -0,0 +1,129 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD4_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod4/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD4_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD4_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod4_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_360::testDecompression() { + QFETCH(QString, fastFilePath_cod4_360); + + const QString testName = "Decompress: " + fastFilePath_cod4_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod4_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod4_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + const QString magic = testFFData.mid(0, 8); + QVERIFY2(magic == "IWffu100", + qPrintable("Does not support encrypted fastfiles!")); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::BigEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + if (abs(zoneSize - testZoneData.size()) != 36) { + qDebug() << "Zone Size: " << zoneSize; + qDebug() << "Test zone Size: " << testZoneData.size(); + } + QVERIFY2(abs(zoneSize - testZoneData.size()) == 36, + qPrintable("Decompression validation failed for: " + fastFilePath_cod4_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod4_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD4_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod4_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_360::testCompression() { + QFETCH(QString, zoneFilePath_cod4_360); + + QFile zoneFile(zoneFilePath_cod4_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod4_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod4_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD4_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod4_360.moc" diff --git a/tests/360/autotest_cod5_360.cpp b/tests/360/autotest_cod5_360.cpp new file mode 100644 index 0000000..f9dff03 --- /dev/null +++ b/tests/360/autotest_cod5_360.cpp @@ -0,0 +1,133 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD5_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod5/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD5_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD5_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod5_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_360::testDecompression() { + QFETCH(QString, fastFilePath_cod5_360); + return; + + const QString testName = "Decompress: " + fastFilePath_cod5_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod5_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod5_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::BigEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + if (abs(zoneSize - testZoneData.size()) != 36) { + qDebug() << "Zone Size: " << zoneSize; + qDebug() << "Test zone Size: " << testZoneData.size(); + qDebug() << "Difference: " << abs(zoneSize - testZoneData.size()); + } + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod5_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod5_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD5_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod5_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_360::testCompression() { + QFETCH(QString, zoneFilePath_cod5_360); + + QFile zoneFile(zoneFilePath_cod5_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod5_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod5_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD5_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod5_360.moc" diff --git a/tests/360/autotest_cod6_360.cpp b/tests/360/autotest_cod6_360.cpp new file mode 100644 index 0000000..7d550eb --- /dev/null +++ b/tests/360/autotest_cod6_360.cpp @@ -0,0 +1,152 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD6_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod6/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD6_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD6_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod6_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_360::testDecompression() { + QFETCH(QString, fastFilePath_cod6_360); + + const QString testName = "Decompress: " + fastFilePath_cod6_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod6_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod6_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + const QString magic = testFFData.mid(0, 12); + QVERIFY2(magic.contains("IWffu100"), + qPrintable("Encountered signed fastfile: " + magic)); + + QByteArray pattern; + pattern.append(static_cast(0x78)); + pattern.append(static_cast(0xDA)); + pattern.append(static_cast(0xEC)); + + int index = testFFData.indexOf(pattern); + QByteArray compressedData = testFFData.mid(index); + QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + //while (index != -1 && testZoneData.isEmpty()) { + // compressedData = testFFData.mid(index); + // testZoneData = Compression::DecompressZLIB(compressedData); + + // index = testFFData.indexOf(pattern, index + 2); + //} + + QVERIFY2(!testZoneData.isEmpty(), + qPrintable("Zlib decompression failed!")); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::BigEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + if (abs(zoneSize - testZoneData.size()) != 32) { + qDebug() << "Zone Size: " << zoneSize; + qDebug() << "Test zone Size: " << testZoneData.size(); + qDebug() << "Difference: " << abs(zoneSize - testZoneData.size()); + } + QVERIFY2(zoneSize + 32 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod6_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod6_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD6_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod6_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_360::testCompression() { + QFETCH(QString, zoneFilePath_cod6_360); + + QFile zoneFile(zoneFilePath_cod6_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod6_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod6_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray pattern; + pattern.append(static_cast(0x78)); + pattern.append(static_cast(0xDA)); + pattern.append(static_cast(0xEC)); + + int zlibOffset = originalFFData.indexOf(pattern); + + QByteArray header = originalFFData.mid(0, zlibOffset); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD6_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod6_360.moc" diff --git a/tests/360/autotest_cod7_360.cpp b/tests/360/autotest_cod7_360.cpp new file mode 100644 index 0000000..ebdd0dc --- /dev/null +++ b/tests/360/autotest_cod7_360.cpp @@ -0,0 +1,189 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" +#include "encryption.h" + +class AutoTest_COD7_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_360::testDecompression() { + QFETCH(QString, fastFilePath_cod7_360); + + const QString testName = "Decompress: " + fastFilePath_cod7_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + QByteArray decompressedData; + QByteArray key = QByteArray::fromHex("1ac1d12d527c59b40eca619120ff8217ccff09cd16896f81b829c7f52793405d"); + + // Create a QDataStream on the input data. + QDataStream fastFileStream(testFFData); + fastFileStream.setByteOrder(QDataStream::BigEndian); + fastFileStream.skipRawData(16); + + // Read the 8-byte magic. + QByteArray fileMagic(8, Qt::Uninitialized); + fastFileStream.readRawData(fileMagic.data(), 8); + QVERIFY2(fileMagic == "PHEEBs71", + qPrintable("Invalid fast file magic: " + fileMagic)); + fastFileStream.skipRawData(4); + + // Read IV table name (32 bytes). + QByteArray fileName(32, Qt::Uninitialized); + fastFileStream.readRawData(fileName.data(), 32); + + // Build the IV table from the fileName. + QByteArray ivTable = Encryption::InitIVTable(fileName); + + // Skip the RSA signature (256 bytes). + QByteArray rsaSignature(256, Qt::Uninitialized); + fastFileStream.readRawData(rsaSignature.data(), 256); + + // Now the stream should be positioned at 0x13C, where sections begin. + int sectionIndex = 0; + while (true) { + qint32 sectionSize = 0; + fastFileStream >> sectionSize; + if (sectionSize == 0) + break; + + // Read the section data. + QByteArray sectionData; + sectionData.resize(sectionSize); + fastFileStream.readRawData(sectionData.data(), sectionSize); + + // Compute the IV for this section. + QByteArray iv = Encryption::GetIV(ivTable, sectionIndex); + + // Decrypt the section using Salsa20. + QByteArray decData = Encryption::salsa20DecryptSection(sectionData, key, iv); + + // Compute SHA1 hash of the decrypted data. + QByteArray sectionHash = QCryptographicHash::hash(decData, QCryptographicHash::Sha1); + + // Update the IV table based on the section hash. + Encryption::UpdateIVTable(ivTable, sectionIndex, sectionHash); + + // Build a compressed data buffer by prepending the two-byte zlib header. + decompressedData.append(Compression::DecompressDeflate(decData)); + + sectionIndex++; + } + + + const QByteArray testZoneData = decompressedData; + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::BigEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + if (abs(zoneSize - testZoneData.size()) != 36) { + qDebug() << "Zone Size: " << zoneSize; + qDebug() << "Test zone Size: " << testZoneData.size(); + qDebug() << "Difference: " << abs(zoneSize - testZoneData.size()); + } + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_360::testCompression() { + QFETCH(QString, zoneFilePath_cod7_360); + + QFile zoneFile(zoneFilePath_cod7_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod7_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod7_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_360.moc" diff --git a/tests/360/autotest_cod8_360.cpp b/tests/360/autotest_cod8_360.cpp new file mode 100644 index 0000000..954d95d --- /dev/null +++ b/tests/360/autotest_cod8_360.cpp @@ -0,0 +1,152 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD8_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD8_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD8_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod8_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + break; + } +} + +void AutoTest_COD8_360::testDecompression() { + QFETCH(QString, fastFilePath_cod8_360); + + const QString testName = "Decompress: " + fastFilePath_cod8_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod8_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod8_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + //const QByteArray testData = Compression::CompressXMem("Hello World!"); + //const QByteArray testOutData = Compression::DecompressXMem(testData); + //qDebug() << "Input: Hello World! - Output: " << testData.toHex() << " - New: " << testOutData; + + QByteArray pattern; + pattern.append(static_cast(0xFF)); + + QByteArray testZoneData; + + for (int i = 12; i < testFFData.size(); i++) { + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(i); + testZoneData = Compression::DecompressXMem(compressedData); + //QVERIFY2(!testZoneData.isEmpty(), qPrintable("Result was empty!")); + + if (!testZoneData.isEmpty()) { + qDebug() << QString("Suceeded at %1!").arg(i); + //break; + } + qDebug() << QString("Failed at %1!").arg(i); + } + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + if (abs(zoneSize - testZoneData.size()) != 44) { + qDebug() << "Zone Size: " << zoneSize; + qDebug() << "Test zone Size: " << testZoneData.size(); + qDebug() << "Difference: " << abs(zoneSize - testZoneData.size()); + } + //QVERIFY2(zoneSize + 44 == testZoneData.size(), + // qPrintable("Decompression validation failed for: " + fastFilePath_cod8_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod8_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD8_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod8_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + break; + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_360::testCompression() { + QFETCH(QString, zoneFilePath_cod8_360); + + QFile zoneFile(zoneFilePath_cod8_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod8_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod8_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD8_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod8_360.moc" diff --git a/tests/360/autotest_cod9_360.cpp b/tests/360/autotest_cod9_360.cpp new file mode 100644 index 0000000..6807fa0 --- /dev/null +++ b/tests/360/autotest_cod9_360.cpp @@ -0,0 +1,127 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_360 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/360"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_360::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_360::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_360"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_360::testDecompression() { + QFETCH(QString, fastFilePath_cod9_360); + + const QString testName = "Decompress: " + fastFilePath_cod9_360; + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_360); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_360)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_360)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_360); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_360::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_360"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_360::testCompression() { + QFETCH(QString, zoneFilePath_cod9_360); + + QFile zoneFile(zoneFilePath_cod9_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_360::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_360.moc" diff --git a/tests/PC/autotest_cod10_pc.cpp b/tests/PC/autotest_cod10_pc.cpp new file mode 100644 index 0000000..ad2a304 --- /dev/null +++ b/tests/PC/autotest_cod10_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD10_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod10_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod10_pc); + + QFile zoneFile(zoneFilePath_cod10_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_pc.moc" diff --git a/tests/PC/autotest_cod11_pc.cpp b/tests/PC/autotest_cod11_pc.cpp new file mode 100644 index 0000000..999a038 --- /dev/null +++ b/tests/PC/autotest_cod11_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD11_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod11/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD11_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD11_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod11_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD11_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod11_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod11_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod11_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod11_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod11_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD11_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod11_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod11_pc); + + QFile zoneFile(zoneFilePath_cod11_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod11_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod11_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD11_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod11_pc.moc" diff --git a/tests/PC/autotest_cod12_pc.cpp b/tests/PC/autotest_cod12_pc.cpp new file mode 100644 index 0000000..ef8b276 --- /dev/null +++ b/tests/PC/autotest_cod12_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD12_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod12/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD12_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD12_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod12_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD12_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod12_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod12_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod12_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod12_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod12_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD12_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod12_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod12_pc); + + QFile zoneFile(zoneFilePath_cod12_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod12_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod12_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD12_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod12_pc.moc" diff --git a/tests/PC/autotest_cod4_pc.cpp b/tests/PC/autotest_cod4_pc.cpp new file mode 100644 index 0000000..b89ae4f --- /dev/null +++ b/tests/PC/autotest_cod4_pc.cpp @@ -0,0 +1,120 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + + +class AutoTest_COD4_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod4/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD4_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD4_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod4_pc"); + + QStringList fastFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : fastFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod4_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod4_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod4_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod4_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod4_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD4_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod4_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod4_pc); + + QFile zoneFile(zoneFilePath_cod4_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod4_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod4_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD4_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod4_pc.moc" diff --git a/tests/PC/autotest_cod5_pc.cpp b/tests/PC/autotest_cod5_pc.cpp new file mode 100644 index 0000000..4a1608e --- /dev/null +++ b/tests/PC/autotest_cod5_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD5_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod5/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD5_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD5_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod5_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod5_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod5_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod5_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod5_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod5_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD5_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod5_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod5_pc); + + QFile zoneFile(zoneFilePath_cod5_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod5_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod5_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD5_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod5_pc.moc" diff --git a/tests/PC/autotest_cod6_pc.cpp b/tests/PC/autotest_cod6_pc.cpp new file mode 100644 index 0000000..33d0f48 --- /dev/null +++ b/tests/PC/autotest_cod6_pc.cpp @@ -0,0 +1,116 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD6_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod6/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD6_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD6_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod6_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod6_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod6_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod6_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(21); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 40 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod6_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod6_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD6_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod6_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod6_pc); + + QFile zoneFile(zoneFilePath_cod6_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod6_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod6_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(21); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION); + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD6_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod6_pc.moc" diff --git a/tests/PC/autotest_cod7_pc.cpp b/tests/PC/autotest_cod7_pc.cpp new file mode 100644 index 0000000..3d26478 --- /dev/null +++ b/tests/PC/autotest_cod7_pc.cpp @@ -0,0 +1,123 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod7_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod7_pc); + + QFile zoneFile(zoneFilePath_cod7_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod7_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod7_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_pc.moc" diff --git a/tests/PC/autotest_cod8_pc.cpp b/tests/PC/autotest_cod8_pc.cpp new file mode 100644 index 0000000..decf3b3 --- /dev/null +++ b/tests/PC/autotest_cod8_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD8_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD8_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD8_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod8_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD8_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod8_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod8_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod8_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod8_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod8_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD8_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod8_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod8_pc); + + QFile zoneFile(zoneFilePath_cod8_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod8_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod8_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD8_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod8_pc.moc" diff --git a/tests/PC/autotest_cod9_pc.cpp b/tests/PC/autotest_cod9_pc.cpp new file mode 100644 index 0000000..f8a1e64 --- /dev/null +++ b/tests/PC/autotest_cod9_pc.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_PC : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/pc"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_PC::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_PC::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_pc"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + + +void AutoTest_COD9_PC::testDecompression() { + QFETCH(QString, fastFilePath_cod9_pc); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_pc); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_pc)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_pc)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_pc); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_PC::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_pc"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_PC::testCompression() { + QFETCH(QString, zoneFilePath_cod9_pc); + + QFile zoneFile(zoneFilePath_cod9_pc); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_pc)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_pc); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + QByteArray newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_SPEED); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_PC::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_pc.moc" diff --git a/tests/PS3/autotest_cod10_ps3.cpp b/tests/PS3/autotest_cod10_ps3.cpp new file mode 100644 index 0000000..6432d3b --- /dev/null +++ b/tests/PS3/autotest_cod10_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod10/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod10_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod10_ps3); + + QFile zoneFile(zoneFilePath_cod10_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_ps3.moc" diff --git a/tests/PS3/autotest_cod11_ps3.cpp b/tests/PS3/autotest_cod11_ps3.cpp new file mode 100644 index 0000000..e20a48b --- /dev/null +++ b/tests/PS3/autotest_cod11_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD11_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod11/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD11_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD11_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod11_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod11_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod11_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod11_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod11_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod11_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD11_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod11_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD11_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod11_ps3); + + QFile zoneFile(zoneFilePath_cod11_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod11_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod11_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD11_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod11_ps3.moc" diff --git a/tests/PS3/autotest_cod12_ps3.cpp b/tests/PS3/autotest_cod12_ps3.cpp new file mode 100644 index 0000000..8a23cd2 --- /dev/null +++ b/tests/PS3/autotest_cod12_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD12_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod12/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD12_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD12_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod12_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod12_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod12_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod12_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod12_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod12_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD12_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod12_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD12_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod12_ps3); + + QFile zoneFile(zoneFilePath_cod12_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod12_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod12_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD12_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod12_ps3.moc" diff --git a/tests/PS3/autotest_cod4_ps3.cpp b/tests/PS3/autotest_cod4_ps3.cpp new file mode 100644 index 0000000..8ca2dc2 --- /dev/null +++ b/tests/PS3/autotest_cod4_ps3.cpp @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD4_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod4/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD4_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD4_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod4_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod4_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod4_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod4_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressDeflate(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + //QVERIFY2(zoneSize + 44 == testZoneData.size(), + // qPrintable("Decompression validation failed for: " + fastFilePath_cod4_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod4_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD4_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod4_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD4_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod4_ps3); + + QFile zoneFile(zoneFilePath_cod4_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod4_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod4_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData = Compression::CompressDeflateWithSettings(decompressedData, Z_BEST_COMPRESSION); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD4_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod4_ps3.moc" diff --git a/tests/PS3/autotest_cod5_ps3.cpp b/tests/PS3/autotest_cod5_ps3.cpp new file mode 100644 index 0000000..7b1ed14 --- /dev/null +++ b/tests/PS3/autotest_cod5_ps3.cpp @@ -0,0 +1,130 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD5_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod5/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD5_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD5_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod5_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod5_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod5_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod5_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + if (abs(zoneSize - testZoneData.size()) != 36) { + qDebug() << "Zone Size: " << zoneSize; + qDebug() << "Test zone Size: " << testZoneData.size(); + qDebug() << "Difference: " << abs(zoneSize - testZoneData.size()); + } + QVERIFY2(zoneSize + 36 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod5_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod5_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD5_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod5_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD5_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod5_ps3); + + QFile zoneFile(zoneFilePath_cod5_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod5_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod5_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD5_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod5_ps3.moc" diff --git a/tests/PS3/autotest_cod6_ps3.cpp b/tests/PS3/autotest_cod6_ps3.cpp new file mode 100644 index 0000000..b5b5234 --- /dev/null +++ b/tests/PS3/autotest_cod6_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD6_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod6/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD6_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD6_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod6_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod6_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod6_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod6_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod6_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod6_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD6_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod6_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD6_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod6_ps3); + + QFile zoneFile(zoneFilePath_cod6_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod6_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod6_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD6_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod6_ps3.moc" diff --git a/tests/PS3/autotest_cod7_ps3.cpp b/tests/PS3/autotest_cod7_ps3.cpp new file mode 100644 index 0000000..a49fa55 --- /dev/null +++ b/tests/PS3/autotest_cod7_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod7_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod7_ps3); + + QFile zoneFile(zoneFilePath_cod7_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod7_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod7_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_ps3.moc" diff --git a/tests/PS3/autotest_cod8_ps3.cpp b/tests/PS3/autotest_cod8_ps3.cpp new file mode 100644 index 0000000..fdae339 --- /dev/null +++ b/tests/PS3/autotest_cod8_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD8_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod8/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD8_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD8_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod8_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod8_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod8_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod8_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod8_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod8_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD8_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod8_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD8_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod8_ps3); + + QFile zoneFile(zoneFilePath_cod8_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod8_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod8_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD8_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod8_ps3.moc" diff --git a/tests/PS3/autotest_cod9_ps3.cpp b/tests/PS3/autotest_cod9_ps3.cpp new file mode 100644 index 0000000..660f16b --- /dev/null +++ b/tests/PS3/autotest_cod9_ps3.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_PS3 : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/PS3"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_PS3::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_PS3::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_ps3"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_PS3::testDecompression() { + QFETCH(QString, fastFilePath_cod9_ps3); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_ps3); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_ps3)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_ps3)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_ps3); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_PS3::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_ps3"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_PS3::testCompression() { + QFETCH(QString, zoneFilePath_cod9_ps3); + + QFile zoneFile(zoneFilePath_cod9_ps3); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_ps3)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_ps3); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_PS3::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_ps3.moc" diff --git a/tests/Wii/autotest_cod7_wii.cpp b/tests/Wii/autotest_cod7_wii.cpp new file mode 100644 index 0000000..69948a5 --- /dev/null +++ b/tests/Wii/autotest_cod7_wii.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD7_Wii : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod7/Wii"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD7_Wii::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD7_Wii::testDecompression_data() { + QTest::addColumn("fastFilePath_cod7_wii"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_Wii::testDecompression() { + QFETCH(QString, fastFilePath_cod7_wii); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod7_wii); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod7_wii)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod7_wii)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod7_wii); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD7_Wii::testCompression_data() { + QTest::addColumn("zoneFilePath_cod7_wii"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD7_Wii::testCompression() { + QFETCH(QString, zoneFilePath_cod2_360); + + QFile zoneFile(zoneFilePath_cod2_360); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod2_360)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod2_360); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD7_Wii::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod7_wii.moc" diff --git a/tests/WiiU/autotest_cod10_wiiu.cpp b/tests/WiiU/autotest_cod10_wiiu.cpp new file mode 100644 index 0000000..ec487f4 --- /dev/null +++ b/tests/WiiU/autotest_cod10_wiiu.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD10_WiiU : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod10/WiiU"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD10_WiiU::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD10_WiiU::testDecompression_data() { + QTest::addColumn("fastFilePath_cod10_wiiu"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_WiiU::testDecompression() { + QFETCH(QString, fastFilePath_cod10_wiiu); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod10_wiiu); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod10_wiiu)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod10_wiiu)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod10_wiiu); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD10_WiiU::testCompression_data() { + QTest::addColumn("zoneFilePath_cod10_wiiu"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD10_WiiU::testCompression() { + QFETCH(QString, zoneFilePath_cod10_wiiu); + + QFile zoneFile(zoneFilePath_cod10_wiiu); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod10_wiiu)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod10_wiiu); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD10_WiiU::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod10_wiiu.moc" diff --git a/tests/WiiU/autotest_cod9_wiiu.cpp b/tests/WiiU/autotest_cod9_wiiu.cpp new file mode 100644 index 0000000..819f170 --- /dev/null +++ b/tests/WiiU/autotest_cod9_wiiu.cpp @@ -0,0 +1,125 @@ +#include +#include +#include + +#include "autotest_cod.h" +#include "compression.h" + +class AutoTest_COD9_WiiU : public AutoTest_COD { + Q_OBJECT + + const QString EXPORT_DIR = "./exports/cod9/WiiU"; + +private slots: + void initTestCase(); + // Data-driven test for decompression + void testDecompression_data(); + void testDecompression(); + // Data-driven test for recompression (compression) + void testCompression_data(); + void testCompression(); + void cleanupTestCase(); +}; + +void AutoTest_COD9_WiiU::initTestCase() { + // Ensure the exports directory exists. + createDirectory(EXPORT_DIR); +} + +void AutoTest_COD9_WiiU::testDecompression_data() { + QTest::addColumn("fastFilePath_cod9_wiiu"); + + QStringList ffFiles = findFastFiles(getFastFileDirectory()); + for (const QString &filePath : ffFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_WiiU::testDecompression() { + QFETCH(QString, fastFilePath_cod9_wiiu); + + // Open the original .ff file. + QFile testFastFile(fastFilePath_cod9_wiiu); + QVERIFY2(testFastFile.open(QIODevice::ReadOnly), + qPrintable("Failed to open test fastfile: " + fastFilePath_cod9_wiiu)); + const QByteArray testFFData = testFastFile.readAll(); + testFastFile.close(); + + // Assume the first 12 bytes are a header; the rest is zlib-compressed zone data. + const QByteArray compressedData = testFFData.mid(12); + const QByteArray testZoneData = Compression::DecompressZLIB(compressedData); + + // Verify the decompressed data via its embedded zone size. + QDataStream zoneStream(testZoneData); + zoneStream.setByteOrder(QDataStream::LittleEndian); + quint32 zoneSize; + zoneStream >> zoneSize; + QVERIFY2(zoneSize + 44 == testZoneData.size(), + qPrintable("Decompression validation failed for: " + fastFilePath_cod9_wiiu)); + + // Write the decompressed zone data to the exports folder with a .zone extension. + QFileInfo fi(fastFilePath_cod9_wiiu); + QString outputFileName = fi.completeBaseName() + ".zone"; + QString outputFilePath = QDir(EXPORT_DIR).filePath(outputFileName); + QFile outputFile(outputFilePath); + QVERIFY2(outputFile.open(QIODevice::WriteOnly), + qPrintable("Failed to open output file for writing: " + outputFilePath)); + outputFile.write(testZoneData); + outputFile.close(); +} + +void AutoTest_COD9_WiiU::testCompression_data() { + QTest::addColumn("zoneFilePath_cod9_wiiu"); + + QStringList zoneFiles = findZoneFiles(getZoneFileDirectory()); + for (const QString &filePath : zoneFiles) { + QString fileName = QFileInfo(filePath).fileName(); + QTest::newRow(qPrintable(fileName)) << filePath; + } +} + +void AutoTest_COD9_WiiU::testCompression() { + QFETCH(QString, zoneFilePath_cod9_wiiu); + + QFile zoneFile(zoneFilePath_cod9_wiiu); + QVERIFY2(zoneFile.open(QIODevice::ReadOnly), qPrintable("Failed to open zone file: " + zoneFilePath_cod9_wiiu)); + QByteArray decompressedData = zoneFile.readAll(); + zoneFile.close(); + + QFileInfo fi(zoneFilePath_cod9_wiiu); + QString originalFFPath = QDir(getFastFileDirectory()).filePath(fi.completeBaseName() + ".ff"); + + QFile originalFile(originalFFPath); + QVERIFY2(originalFile.open(QIODevice::ReadOnly), qPrintable("Failed to open original .ff file: " + originalFFPath)); + QByteArray originalFFData = originalFile.readAll(); + originalFile.close(); + + QByteArray header = originalFFData.left(12); + + QByteArray newCompressedData;// = Compressor::CompressZLIB(decompressedData, Z_BEST_COMPRESSION); + newCompressedData = Compression::CompressZLIBWithSettings(decompressedData, Z_BEST_COMPRESSION, MAX_WBITS, 8, Z_DEFAULT_STRATEGY, {}); + + int remainder = (newCompressedData.size() + 12) % 32; + if (remainder != 0) { + int paddingNeeded = 32 - remainder; + newCompressedData.append(QByteArray(paddingNeeded, '\0')); + } + + QByteArray recompressedData = header + newCompressedData; + + QString recompressedFilePath = QDir(EXPORT_DIR).filePath(fi.completeBaseName() + ".ff"); + QFile recompressedFile(recompressedFilePath); + QVERIFY2(recompressedFile.open(QIODevice::WriteOnly), qPrintable("Failed to write recompressed file.")); + recompressedFile.write(recompressedData); + recompressedFile.close(); + + QCOMPARE(recompressedData, originalFFData); +} + +void AutoTest_COD9_WiiU::cleanupTestCase() { + // Any cleanup if necessary. +} + +// Don't generate a main() function +#include "autotest_cod9_wiiu.moc" diff --git a/tests/autotest_cod.h b/tests/autotest_cod.h new file mode 100644 index 0000000..aa45d15 --- /dev/null +++ b/tests/autotest_cod.h @@ -0,0 +1,76 @@ +#ifndef AUTOTEST_COD_CPP +#define AUTOTEST_COD_CPP + +#include + +class AutoTest_COD : public QObject { + Q_OBJECT + +protected: + QList> m_subtestResults; + +public: + const QList>& getCollectedTestResults() const { + return m_subtestResults; + } + void recordResult(const QString& name, bool passed) { + m_subtestResults.append({ name, passed }); + } + void setFastFileDirectory(const QString aFastFileDir) { + mFastFileDirectory = aFastFileDir; + } + QString getFastFileDirectory() { + return mFastFileDirectory; + } + + void setZoneFileDirectory(const QString aZoneFileDir) { + mZoneFileDirectory = aZoneFileDir; + } + QString getZoneFileDirectory() { + return mZoneFileDirectory; + } + + void createDirectory(const QString aDir) { + QDir newDir("."); + newDir.mkpath(aDir); + } + QStringList findFastFiles(const QString &aBaseDir, int aMaxIter = MAX_ITER) { + QStringList fastFiles; + + QDirIterator it(aBaseDir, QStringList() << "*.ff", QDir::Files, QDirIterator::Subdirectories); + + int i = 0; + while (it.hasNext() && i < aMaxIter) { + fastFiles << it.next(); + ++i; + } + + return fastFiles; + } + QStringList findZoneFiles(const QString &aBaseDir, int aMaxIter = MAX_ITER) { + QStringList zoneFiles; + + QDirIterator it(aBaseDir, QStringList() << "*.zone", QDir::Files, QDirIterator::Subdirectories); + + int i = 0; + while (it.hasNext() && i < aMaxIter) { + zoneFiles << it.next(); + ++i; + } + + return zoneFiles; + } + virtual void initTestCase() = 0; + virtual void testDecompression_data() = 0; + virtual void testDecompression() = 0; + virtual void testCompression_data() = 0; + virtual void testCompression() = 0; + virtual void cleanupTestCase() = 0; + +private: + static const int MAX_ITER = 10000; + QString mFastFileDirectory; + QString mZoneFileDirectory; +}; + +#endif // AUTOTEST_COD_CPP diff --git a/tests/autotest_xplor.cpp b/tests/autotest_xplor.cpp new file mode 100644 index 0000000..bb24eb4 --- /dev/null +++ b/tests/autotest_xplor.cpp @@ -0,0 +1,9 @@ +#include + +class AutoTest_XPlor : public QObject { + Q_OBJECT + +private slots: +}; + +#include "autotest_xplor.moc" diff --git a/tests/data.qrc b/tests/data.qrc new file mode 100644 index 0000000..fa64d6c --- /dev/null +++ b/tests/data.qrc @@ -0,0 +1,194 @@ + + + data/cod5/zonefile/ber1.zone + data/cod5/zonefile/ber1_load.zone + data/cod5/zonefile/ber2.zone + data/cod5/zonefile/ber2_load.zone + data/cod5/zonefile/ber3.zone + data/cod5/zonefile/ber3_load.zone + data/cod5/zonefile/ber3b.zone + data/cod5/zonefile/ber3b_load.zone + data/cod5/zonefile/code_post_gfx_mp.zone + data/cod5/zonefile/common_ignore.zone + data/cod5/zonefile/default.zone + data/cod5/zonefile/localized_mp_asylum.zone + data/cod5/zonefile/localized_mp_castle.zone + data/cod5/zonefile/localized_mp_kneedeep.zone + data/cod5/zonefile/mak.zone + data/cod5/zonefile/mak_load.zone + data/cod5/zonefile/mp_airfield_load.zone + data/cod5/zonefile/mp_asylum.zone + data/cod5/zonefile/mp_asylum_load.zone + data/cod5/zonefile/mp_bgate.zone + data/cod5/zonefile/mp_bgate_load.zone + data/cod5/zonefile/mp_castle_load.zone + data/cod5/zonefile/mp_courtyard_load.zone + data/cod5/zonefile/mp_docks.zone + data/cod5/zonefile/mp_docks_load.zone + data/cod5/zonefile/mp_dome_load.zone + data/cod5/zonefile/mp_downfall.zone + data/cod5/zonefile/mp_downfall_load.zone + data/cod5/zonefile/mp_drum_load.zone + data/cod5/zonefile/mp_hangar.zone + data/cod5/zonefile/mp_hangar_load.zone + data/cod5/zonefile/mp_kneedeep.zone + data/cod5/zonefile/mp_kneedeep_load.zone + data/cod5/zonefile/mp_kwai.zone + data/cod5/zonefile/mp_kwai_load.zone + data/cod5/zonefile/mp_makin.zone + data/cod5/zonefile/mp_makin_day.zone + data/cod5/zonefile/mp_makin_day_load.zone + data/cod5/zonefile/mp_makin_load.zone + data/cod5/zonefile/mp_nachtfeuer.zone + data/cod5/zonefile/mp_nachtfeuer_load.zone + data/cod5/zonefile/mp_outskirts.zone + data/cod5/zonefile/mp_outskirts_load.zone + data/cod5/zonefile/mp_roundhouse.zone + data/cod5/zonefile/mp_roundhouse_load.zone + data/cod5/zonefile/mp_seelow.zone + data/cod5/zonefile/mp_seelow_load.zone + data/cod5/zonefile/mp_shrine.zone + data/cod5/zonefile/mp_shrine_load.zone + data/cod5/zonefile/mp_stalingrad.zone + data/cod5/zonefile/mp_stalingrad_load.zone + data/cod5/zonefile/mp_suburban.zone + data/cod5/zonefile/mp_suburban_load.zone + data/cod5/zonefile/mp_subway.zone + data/cod5/zonefile/mp_subway_load.zone + data/cod5/zonefile/mp_vodka.zone + data/cod5/zonefile/mp_vodka_load.zone + data/cod5/zonefile/nazi_zombie_asylum.zone + data/cod5/zonefile/nazi_zombie_asylum_load.zone + data/cod5/zonefile/nazi_zombie_asylum_patch.zone + data/cod5/zonefile/nazi_zombie_factory.zone + data/cod5/zonefile/nazi_zombie_factory_load.zone + data/cod5/zonefile/nazi_zombie_factory_patch.zone + data/cod5/zonefile/nazi_zombie_prototype.zone + data/cod5/zonefile/nazi_zombie_prototype_load.zone + data/cod5/zonefile/nazi_zombie_sumpf.zone + data/cod5/zonefile/nazi_zombie_sumpf_load.zone + data/cod5/zonefile/nazi_zombie_sumpf_patch.zone + data/cod5/zonefile/oki2.zone + data/cod5/zonefile/oki2_load.zone + data/cod5/zonefile/oki3.zone + data/cod5/zonefile/oki3_load.zone + data/cod5/zonefile/outro.zone + data/cod5/zonefile/patch.zone + data/cod5/zonefile/patch_mp.zone + data/cod5/zonefile/pby_fly.zone + data/cod5/zonefile/pby_fly_load.zone + data/cod5/zonefile/pel1.zone + data/cod5/zonefile/pel1_load.zone + data/cod5/zonefile/pel1a.zone + data/cod5/zonefile/pel1a_load.zone + data/cod5/zonefile/pel1b.zone + data/cod5/zonefile/pel1b_load.zone + data/cod5/zonefile/pel2.zone + data/cod5/zonefile/pel2_load.zone + data/cod5/zonefile/see1.zone + data/cod5/zonefile/see1_load.zone + data/cod5/zonefile/see2.zone + data/cod5/zonefile/see2_load.zone + data/cod5/zonefile/sniper.zone + data/cod5/zonefile/sniper_load.zone + data/cod5/zonefile/ui.zone + data/cod5/zonefile/ui_mp.zone + data/cod5/zonefile/xcommon_rtx.zone + + + data/cod5/fastfile/ber1.ff + data/cod5/fastfile/ber1_load.ff + data/cod5/fastfile/ber2.ff + data/cod5/fastfile/ber2_load.ff + data/cod5/fastfile/ber3.ff + data/cod5/fastfile/ber3_load.ff + data/cod5/fastfile/ber3b.ff + data/cod5/fastfile/ber3b_load.ff + data/cod5/fastfile/code_post_gfx_mp.ff + data/cod5/fastfile/common_ignore.ff + data/cod5/fastfile/default.ff + data/cod5/fastfile/localized_mp_asylum.ff + data/cod5/fastfile/localized_mp_castle.ff + data/cod5/fastfile/localized_mp_kneedeep.ff + data/cod5/fastfile/mak.ff + data/cod5/fastfile/mak_load.ff + data/cod5/fastfile/mp_airfield_load.ff + data/cod5/fastfile/mp_asylum.ff + data/cod5/fastfile/mp_asylum_load.ff + data/cod5/fastfile/mp_bgate.ff + data/cod5/fastfile/mp_bgate_load.ff + data/cod5/fastfile/mp_castle_load.ff + data/cod5/fastfile/mp_courtyard_load.ff + data/cod5/fastfile/mp_docks.ff + data/cod5/fastfile/mp_docks_load.ff + data/cod5/fastfile/mp_dome_load.ff + data/cod5/fastfile/mp_downfall.ff + data/cod5/fastfile/mp_downfall_load.ff + data/cod5/fastfile/mp_drum_load.ff + data/cod5/fastfile/mp_hangar.ff + data/cod5/fastfile/mp_hangar_load.ff + data/cod5/fastfile/mp_kneedeep.ff + data/cod5/fastfile/mp_kneedeep_load.ff + data/cod5/fastfile/mp_kwai.ff + data/cod5/fastfile/mp_kwai_load.ff + data/cod5/fastfile/mp_makin.ff + data/cod5/fastfile/mp_makin_day.ff + data/cod5/fastfile/mp_makin_day_load.ff + data/cod5/fastfile/mp_makin_load.ff + data/cod5/fastfile/mp_nachtfeuer.ff + data/cod5/fastfile/mp_nachtfeuer_load.ff + data/cod5/fastfile/mp_outskirts.ff + data/cod5/fastfile/mp_outskirts_load.ff + data/cod5/fastfile/mp_roundhouse.ff + data/cod5/fastfile/mp_roundhouse_load.ff + data/cod5/fastfile/mp_seelow.ff + data/cod5/fastfile/mp_seelow_load.ff + data/cod5/fastfile/mp_shrine.ff + data/cod5/fastfile/mp_shrine_load.ff + data/cod5/fastfile/mp_stalingrad.ff + data/cod5/fastfile/mp_stalingrad_load.ff + data/cod5/fastfile/mp_suburban.ff + data/cod5/fastfile/mp_suburban_load.ff + data/cod5/fastfile/mp_subway.ff + data/cod5/fastfile/mp_subway_load.ff + data/cod5/fastfile/mp_vodka.ff + data/cod5/fastfile/mp_vodka_load.ff + data/cod5/fastfile/nazi_zombie_asylum.ff + data/cod5/fastfile/nazi_zombie_asylum_load.ff + data/cod5/fastfile/nazi_zombie_asylum_patch.ff + data/cod5/fastfile/nazi_zombie_factory.ff + data/cod5/fastfile/nazi_zombie_factory_load.ff + data/cod5/fastfile/nazi_zombie_factory_patch.ff + data/cod5/fastfile/nazi_zombie_prototype.ff + data/cod5/fastfile/nazi_zombie_prototype_load.ff + data/cod5/fastfile/nazi_zombie_sumpf.ff + data/cod5/fastfile/nazi_zombie_sumpf_load.ff + data/cod5/fastfile/nazi_zombie_sumpf_patch.ff + data/cod5/fastfile/oki2.ff + data/cod5/fastfile/oki2_load.ff + data/cod5/fastfile/oki3.ff + data/cod5/fastfile/oki3_load.ff + data/cod5/fastfile/outro.ff + data/cod5/fastfile/patch.ff + data/cod5/fastfile/patch_mp.ff + data/cod5/fastfile/pby_fly.ff + data/cod5/fastfile/pby_fly_load.ff + data/cod5/fastfile/pel1.ff + data/cod5/fastfile/pel1_load.ff + data/cod5/fastfile/pel1a.ff + data/cod5/fastfile/pel1a_load.ff + data/cod5/fastfile/pel1b.ff + data/cod5/fastfile/pel1b_load.ff + data/cod5/fastfile/pel2.ff + data/cod5/fastfile/pel2_load.ff + data/cod5/fastfile/see1.ff + data/cod5/fastfile/see1_load.ff + data/cod5/fastfile/see2.ff + data/cod5/fastfile/see2_load.ff + data/cod5/fastfile/sniper.ff + data/cod5/fastfile/sniper_load.ff + data/cod5/fastfile/ui.ff + data/cod5/fastfile/ui_mp.ff + data/cod5/fastfile/xcommon_rtx.ff + + diff --git a/tests/test_main.cpp b/tests/test_main.cpp new file mode 100644 index 0000000..9860a28 --- /dev/null +++ b/tests/test_main.cpp @@ -0,0 +1,435 @@ +#include +//#include "autotest_xplor.cpp" + +#include "360/autotest_cod2_360.cpp" +#include "360/autotest_cod4_360.cpp" +#include "360/autotest_cod5_360.cpp" +#include "360/autotest_cod6_360.cpp" +#include "360/autotest_cod7_360.cpp" +#include "360/autotest_cod8_360.cpp" +#include "360/autotest_cod9_360.cpp" +#include "360/autotest_cod10_360.cpp" +#include "360/autotest_cod11_360.cpp" +#include "360/autotest_cod12_360.cpp" + +#include "PC/autotest_cod4_pc.cpp" +#include "PC/autotest_cod5_pc.cpp" +#include "PC/autotest_cod6_pc.cpp" +#include "PC/autotest_cod7_pc.cpp" +#include "PC/autotest_cod8_pc.cpp" +#include "PC/autotest_cod9_pc.cpp" +#include "PC/autotest_cod10_pc.cpp" +#include "PC/autotest_cod11_pc.cpp" +#include "PC/autotest_cod12_pc.cpp" + +#include "PS3/autotest_cod4_ps3.cpp" +#include "PS3/autotest_cod5_ps3.cpp" +#include "PS3/autotest_cod6_ps3.cpp" +#include "PS3/autotest_cod7_ps3.cpp" +#include "PS3/autotest_cod8_ps3.cpp" +#include "PS3/autotest_cod9_ps3.cpp" +#include "PS3/autotest_cod10_ps3.cpp" +#include "PS3/autotest_cod11_ps3.cpp" +#include "PS3/autotest_cod12_ps3.cpp" + +#include "Wii/autotest_cod7_wii.cpp" + +#include "WiiU/autotest_cod9_wiiu.cpp" +#include "WiiU/autotest_cod10_wiiu.cpp" + +// clearly named defines for filtering logic +#define TEST_EVERYTHING 0 + +// Global filters +#define TEST_ALL_PLATFORMS 0 +#define TEST_ALL_COD_GAMES 0 + +// individual games +#define TEST_COD2 0 +#define TEST_COD4 0 +#define TEST_COD5 0 +#define TEST_COD6 0 +#define TEST_COD7 0 +#define TEST_COD8 1 +#define TEST_COD9 0 +#define TEST_COD10 0 +#define TEST_COD11 0 +#define TEST_COD12 0 + +// individual platforms +#define TEST_360 0 +#define TEST_PC 0 +#define TEST_PS3 0 +#define TEST_WII 0 +#define TEST_WIIU 0 + +int main(int argc, char *argv[]) { + /**********************************/ + /********* XPLOR UI TESTS *********/ + /**********************************/ + + // AutoTest_XPlor test_xplor; + // if (!QTest::qExec(&test_xplor, argc, argv)) { + // return -1; + // } + + /**********************************/ + /********* 360 COD TESTS *********/ + /**********************************/ + + QVector cod2Tests; + QVector cod4Tests; + QVector cod5Tests; + QVector cod6Tests; + QVector cod7Tests; + QVector cod8Tests; + QVector cod9Tests; + QVector cod10Tests; + QVector cod11Tests; + QVector cod12Tests; + + QVector xbox360Tests; + QVector pcTests; + QVector ps3Tests; + QVector wiiTests; + QVector wiiUTests; + + AutoTest_COD2_360 *test_cod2_360 = new AutoTest_COD2_360(); + test_cod2_360->setFastFileDirectory("G:/Fast Files/360/COD2"); + test_cod2_360->setZoneFileDirectory("./exports/cod2/360"); + cod2Tests << test_cod2_360; + xbox360Tests << test_cod2_360; + + AutoTest_COD4_360 *test_cod4_360 = new AutoTest_COD4_360(); + test_cod4_360->setFastFileDirectory("G:/Fast Files/360/COD4"); + test_cod4_360->setZoneFileDirectory("./exports/cod4/360"); + cod4Tests << test_cod4_360; + xbox360Tests << test_cod4_360; + + AutoTest_COD5_360 *test_cod5_360 = new AutoTest_COD5_360(); + test_cod5_360->setFastFileDirectory("G:/Fast Files/360/COD5"); + test_cod5_360->setZoneFileDirectory("./exports/cod5/360"); + cod5Tests << test_cod5_360; + xbox360Tests << test_cod5_360; + + AutoTest_COD6_360 *test_cod6_360 = new AutoTest_COD6_360(); + test_cod6_360->setFastFileDirectory("G:/Fast Files/360/COD6"); + test_cod6_360->setZoneFileDirectory("./exports/cod6/360"); + cod6Tests << test_cod6_360; + xbox360Tests << test_cod6_360; + + AutoTest_COD7_360 *test_cod7_360 = new AutoTest_COD7_360(); + test_cod7_360->setFastFileDirectory("G:/Fast Files/360/COD7"); + test_cod7_360->setZoneFileDirectory("./exports/cod7/360"); + cod7Tests << test_cod7_360; + xbox360Tests << test_cod7_360; + + AutoTest_COD8_360 *test_cod8_360 = new AutoTest_COD8_360(); + test_cod8_360->setFastFileDirectory("G:/Fast Files/360/COD8"); + test_cod8_360->setZoneFileDirectory("./exports/cod8/360"); + cod8Tests << test_cod8_360; + xbox360Tests << test_cod8_360; + + AutoTest_COD9_360 *test_cod9_360 = new AutoTest_COD9_360(); + test_cod9_360->setFastFileDirectory("G:/Fast Files/360/COD9"); + test_cod9_360->setZoneFileDirectory("./exports/cod9/360"); + cod9Tests << test_cod9_360; + xbox360Tests << test_cod9_360; + + AutoTest_COD10_360 *test_cod10_360 = new AutoTest_COD10_360(); + test_cod10_360->setFastFileDirectory("G:/Fast Files/360/COD10"); + test_cod10_360->setZoneFileDirectory("./exports/cod10/360"); + cod10Tests << test_cod10_360; + xbox360Tests << test_cod10_360; + + AutoTest_COD11_360 *test_cod11_360 = new AutoTest_COD11_360(); + test_cod11_360->setFastFileDirectory("G:/Fast Files/360/COD11"); + test_cod11_360->setZoneFileDirectory("./exports/cod11/360"); + cod11Tests << test_cod11_360; + xbox360Tests << test_cod11_360; + + AutoTest_COD12_360 *test_cod12_360 = new AutoTest_COD12_360(); + test_cod12_360->setFastFileDirectory("G:/Fast Files/360/COD12"); + test_cod12_360->setZoneFileDirectory("./exports/cod12/360"); + cod12Tests << test_cod12_360; + xbox360Tests << test_cod12_360; + + /**********************************/ + /********* PC COD TESTS *********/ + /**********************************/ + + AutoTest_COD4_PC *test_cod4_pc = new AutoTest_COD4_PC(); + test_cod4_pc->setFastFileDirectory("G:/Fast Files/PC/COD4"); + test_cod4_pc->setZoneFileDirectory("./exports/cod4/PC"); + cod4Tests << test_cod4_pc; + pcTests << test_cod4_pc; + + AutoTest_COD5_PC *test_cod5_pc = new AutoTest_COD5_PC(); + test_cod5_pc->setFastFileDirectory("G:/Fast Files/PC/COD5"); + test_cod5_pc->setZoneFileDirectory("./exports/cod5/PC"); + cod5Tests << test_cod5_pc; + pcTests << test_cod5_pc; + + AutoTest_COD6_PC *test_cod6_pc = new AutoTest_COD6_PC(); + test_cod6_pc->setFastFileDirectory("G:/Fast Files/PC/COD6"); + test_cod6_pc->setZoneFileDirectory("./exports/cod6/PC"); + cod6Tests << test_cod6_pc; + pcTests << test_cod6_pc; + + AutoTest_COD7_PC *test_cod7_pc = new AutoTest_COD7_PC(); + test_cod7_pc->setFastFileDirectory("G:/Fast Files/PC/COD7"); + test_cod7_pc->setZoneFileDirectory("./exports/cod7/PC"); + cod7Tests << test_cod7_pc; + pcTests << test_cod7_pc; + + AutoTest_COD8_PC *test_cod8_pc = new AutoTest_COD8_PC(); + test_cod8_pc->setFastFileDirectory("G:/Fast Files/PC/COD8"); + test_cod8_pc->setZoneFileDirectory("./exports/cod8/PC"); + //cod8Tests << test_cod8_pc; + pcTests << test_cod8_pc; + + AutoTest_COD9_PC *test_cod9_pc = new AutoTest_COD9_PC(); + test_cod9_pc->setFastFileDirectory("G:/Fast Files/PC/COD9"); + test_cod9_pc->setZoneFileDirectory("./exports/cod9/PC"); + cod9Tests << test_cod9_pc; + pcTests << test_cod9_pc; + + AutoTest_COD10_PC *test_cod10_pc = new AutoTest_COD10_PC(); + test_cod10_pc->setFastFileDirectory("G:/Fast Files/PC/COD10"); + test_cod10_pc->setZoneFileDirectory("./exports/cod10/PC"); + cod10Tests << test_cod10_pc; + pcTests << test_cod10_pc; + + AutoTest_COD11_PC *test_cod11_pc = new AutoTest_COD11_PC(); + test_cod11_pc->setFastFileDirectory("G:/Fast Files/PC/COD11"); + test_cod11_pc->setZoneFileDirectory("./exports/cod11/PC"); + cod11Tests << test_cod11_pc; + pcTests << test_cod11_pc; + + AutoTest_COD12_PC *test_cod12_pc = new AutoTest_COD12_PC(); + test_cod12_pc->setFastFileDirectory("G:/Fast Files/PC/COD12"); + test_cod12_pc->setZoneFileDirectory("./exports/cod12/PC"); + cod12Tests << test_cod12_pc; + pcTests << test_cod12_pc; + + /**********************************/ + /********* PS3 COD TESTS *********/ + /**********************************/ + + AutoTest_COD4_PS3 *test_cod4_ps3 = new AutoTest_COD4_PS3(); + test_cod4_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD4"); + test_cod4_ps3->setZoneFileDirectory("./exports/cod4/PS3"); + cod4Tests << test_cod4_ps3; + ps3Tests << test_cod4_ps3; + + AutoTest_COD5_PS3 *test_cod5_ps3 = new AutoTest_COD5_PS3(); + test_cod5_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD5"); + test_cod5_ps3->setZoneFileDirectory("./exports/cod5/PS3"); + //cod5Tests << test_cod5_ps3; + ps3Tests << test_cod5_ps3; + + AutoTest_COD6_PS3 *test_cod6_ps3 = new AutoTest_COD6_PS3(); + test_cod6_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD6"); + test_cod6_ps3->setZoneFileDirectory("./exports/cod6/PS3"); + cod6Tests << test_cod6_ps3; + ps3Tests << test_cod6_ps3; + + AutoTest_COD7_PS3 *test_cod7_ps3 = new AutoTest_COD7_PS3(); + test_cod7_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD7"); + test_cod7_ps3->setZoneFileDirectory("./exports/cod7/PS3"); + cod7Tests << test_cod7_ps3; + ps3Tests << test_cod7_ps3; + + AutoTest_COD8_PS3 *test_cod8_ps3 = new AutoTest_COD8_PS3(); + test_cod8_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD8"); + test_cod8_ps3->setZoneFileDirectory("./exports/cod8/PS3"); + //cod8Tests << test_cod8_ps3; + ps3Tests << test_cod8_ps3; + + AutoTest_COD9_PS3 *test_cod9_ps3 = new AutoTest_COD9_PS3(); + test_cod9_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD9"); + test_cod9_ps3->setZoneFileDirectory("./exports/cod9/PS3"); + cod9Tests << test_cod9_ps3; + ps3Tests << test_cod9_ps3; + + AutoTest_COD10_PS3 *test_cod10_ps3 = new AutoTest_COD10_PS3(); + test_cod10_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD10"); + test_cod10_ps3->setZoneFileDirectory("./exports/cod10/PS3"); + cod10Tests << test_cod10_ps3; + ps3Tests << test_cod10_ps3; + + AutoTest_COD11_PS3 *test_cod11_ps3 = new AutoTest_COD11_PS3(); + test_cod11_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD11"); + test_cod11_ps3->setZoneFileDirectory("./exports/cod11/PS3"); + cod11Tests << test_cod11_ps3; + ps3Tests << test_cod11_ps3; + + AutoTest_COD12_PS3 *test_cod12_ps3 = new AutoTest_COD12_PS3(); + test_cod12_ps3->setFastFileDirectory("G:/Fast Files/PS3/COD12"); + test_cod12_ps3->setZoneFileDirectory("./exports/cod12/PS3"); + cod12Tests << test_cod12_ps3; + ps3Tests << test_cod12_ps3; + + /**********************************/ + /********* Wii COD TESTS *********/ + /**********************************/ + + AutoTest_COD7_Wii *test_cod7_wii = new AutoTest_COD7_Wii(); + test_cod7_wii->setFastFileDirectory("G:/Fast Files/Wii/COD7"); + test_cod7_wii->setZoneFileDirectory("./exports/cod7/Wii"); + cod7Tests << test_cod7_wii; + wiiTests << test_cod7_wii; + + /**********************************/ + /********* WiiU COD TESTS *********/ + /**********************************/ + + AutoTest_COD9_WiiU *test_cod9_wiiu = new AutoTest_COD9_WiiU(); + test_cod9_wiiu->setFastFileDirectory("G:/Fast Files/WiiU/COD9"); + test_cod9_wiiu->setZoneFileDirectory("./exports/cod9/WiiU"); + cod9Tests << test_cod9_wiiu; + wiiUTests << test_cod9_wiiu; + + AutoTest_COD10_WiiU *test_cod10_wiiu = new AutoTest_COD10_WiiU(); + test_cod10_wiiu->setFastFileDirectory("G:/Fast Files/WiiU/COD10"); + test_cod10_wiiu->setZoneFileDirectory("./exports/cod10/PS3"); + cod10Tests << test_cod10_wiiu; + wiiUTests << test_cod10_wiiu; + + QList>>> allResults; + + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD2) { + qDebug() << "-- RUNNING TEST_COD2 --"; + foreach (auto test, cod2Tests) { + QTest::qExec(test, argc, argv); + allResults.append({ test->metaObject()->className(), test->getCollectedTestResults() }); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD4) { + qDebug() << "-- RUNNING TEST_COD4 --"; + foreach (auto test, cod4Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD5) { + qDebug() << "-- RUNNING TEST_COD5 --"; + foreach (auto test, cod5Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD6) { + qDebug() << "-- RUNNING TEST_COD6 --"; + foreach (auto test, cod6Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD7) { + qDebug() << "-- RUNNING TEST_COD7 --"; + foreach (auto test, cod7Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD8) { + qDebug() << "-- RUNNING TEST_COD8 --"; + foreach (auto test, cod8Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD9) { + qDebug() << "-- RUNNING TEST_COD9 --"; + foreach (auto test, cod9Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD10) { + qDebug() << "-- RUNNING TEST_COD10 --"; + foreach (auto test, cod10Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD11) { + qDebug() << "-- RUNNING TEST_COD11 --"; + foreach (auto test, cod11Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_COD_GAMES || TEST_COD12) { + qDebug() << "-- RUNNING TEST_COD12 --"; + foreach (auto test, cod12Tests) { + QTest::qExec(test, argc, argv); + } + } + + if (TEST_EVERYTHING || TEST_ALL_PLATFORMS || TEST_360) { + qDebug() << "-- RUNNING TEST_360 --"; + foreach (auto test, xbox360Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_PLATFORMS || TEST_PC) { + qDebug() << "-- RUNNING TEST_PC --"; + foreach (auto test, pcTests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_PLATFORMS || TEST_PS3) { + qDebug() << "-- RUNNING TEST_PS3 --"; + foreach (auto test, ps3Tests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_PLATFORMS || TEST_WII) { + qDebug() << "-- RUNNING TEST_WII --"; + foreach (auto test, wiiTests) { + QTest::qExec(test, argc, argv); + } + } + if (TEST_EVERYTHING || TEST_ALL_PLATFORMS || TEST_WIIU) { + qDebug() << "-- RUNNING TEST_WIIU --"; + foreach (auto test, wiiUTests) { + QTest::qExec(test, argc, argv); + } + } + + QJsonObject root; + root["project"] = "XPlor"; + root["lastRun"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate); + + bool allPassed = true; + QJsonArray testFiles; + + for (const auto& [className, subtests] : allResults) { + QJsonObject fileEntry; + fileEntry["name"] = className; + + QJsonArray testArray; + bool filePassed = true; + + for (const auto& [testName, passed] : subtests) { + testArray.append(QJsonObject{ + {"name", testName}, + {"status", passed ? "passed" : "failed"} + }); + if (!passed) + filePassed = false; + } + + fileEntry["status"] = filePassed ? "passed" : "failed"; + fileEntry["tests"] = testArray; + testFiles.append(fileEntry); + + if (!filePassed) + allPassed = false; + } + + root["status"] = allPassed ? "passed" : "failed"; + root["tests"] = testFiles; + + QFile file("G:/FileServer/files/auto_test.json"); + if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) + file.write(QJsonDocument(root).toJson(QJsonDocument::Indented)); + else + qWarning() << "Failed to write JSON output"; + + return 0; +} diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..798cf98 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,94 @@ +TEMPLATE = app +CONFIG += no_main + +# Enable the testlib module +QT += testlib concurrent core-private + +# Define a test-specific flag +DEFINES += QT_TESTS + +TARGET = tests + +# List all test source files +SOURCES += \ + # 360 autotests + 360/autotest_cod2_360.cpp \ + 360/autotest_cod4_360.cpp \ + 360/autotest_cod5_360.cpp \ + 360/autotest_cod6_360.cpp \ + 360/autotest_cod7_360.cpp \ + 360/autotest_cod8_360.cpp \ + 360/autotest_cod9_360.cpp \ + 360/autotest_cod10_360.cpp \ + 360/autotest_cod11_360.cpp \ + 360/autotest_cod12_360.cpp \ + # PC autotests + PC/autotest_cod4_pc.cpp \ + PC/autotest_cod5_pc.cpp \ + PC/autotest_cod6_pc.cpp \ + PC/autotest_cod7_pc.cpp \ + PC/autotest_cod8_pc.cpp \ + PC/autotest_cod9_pc.cpp \ + PC/autotest_cod10_pc.cpp \ + PC/autotest_cod11_pc.cpp \ + PC/autotest_cod12_pc.cpp \ + # PS3 autotests + PS3/autotest_cod4_ps3.cpp \ + PS3/autotest_cod5_ps3.cpp \ + PS3/autotest_cod6_ps3.cpp \ + PS3/autotest_cod7_ps3.cpp \ + PS3/autotest_cod8_ps3.cpp \ + PS3/autotest_cod9_ps3.cpp \ + PS3/autotest_cod10_ps3.cpp \ + PS3/autotest_cod11_ps3.cpp \ + PS3/autotest_cod12_ps3.cpp \ + # Wii autotests + Wii/autotest_cod7_wii.cpp \ + # WiiU autotests + WiiU/autotest_cod9_wiiu.cpp \ + WiiU/autotest_cod10_wiiu.cpp \ + # XPlor autotests + autotest_xplor.cpp \ + # Main test function + test_main.cpp + +HEADERS += \ + autotest_cod.h + + +# Prevent tests from being built in release mode (optional) +# CONFIG(debug, debug|release) { +# message("Including test files in Debug mode") +# } else { +# SOURCES -= autotest_cod5.cpp +# } + +app.depends += \ + libs/core \ + libs/compression \ + libs/encryption \ + libs/fastfile + +LIBS += \ + -L$$OUT_PWD/../libs/ -lcore -lencryption -lcompression -lfastfile \ + -L$$PWD/../third_party/xbox_sdk/lib -lxcompress64 + +INCLUDEPATH += \ + $$PWD/../third_party/xbox_sdk/include \ + $$PWD/../libs/core \ + $$PWD/../libs/encryption \ + $$PWD/../libs/compression \ + $$PWD/../libs/fastfile + +DEPENDPATH += \ + $$PWD/../third_party/xbox_sdk/include \ + $$PWD/../libs/core \ + $$PWD/../libs/encryption \ + $$PWD/../libs/compression \ + $$PWD/../libs/fastfile + +RESOURCES += + +# Copy DLLs to Debug & Release folder +QMAKE_POST_LINK += xcopy /Y /E /I \"$$PWD/../third_party/xbox_sdk/lib\\*.dll\" \"$$OUT_PWD/debug/\" $$escape_expand(\\n\\t) +QMAKE_POST_LINK += xcopy /Y /E /I \"$$PWD/../third_party/xbox_sdk/lib\\*.dll\" \"$$OUT_PWD/release/\" $$escape_expand(\\n\\t) diff --git a/third_party/devil_sdk/include/IL/DevIL.i b/third_party/devil_sdk/include/IL/DevIL.i new file mode 100644 index 0000000..820449d --- /dev/null +++ b/third_party/devil_sdk/include/IL/DevIL.i @@ -0,0 +1,13 @@ +%module DevIL +%{ +#include "il.h" +#include "ilu.h" +#include "ilut.h" +//#include "ilu_region.h" +%} + +%include "il.h" +%include "ilu.h" +%include "ilut.h" +//%include "ilu_region.h" + diff --git a/third_party/devil_sdk/include/IL/build-lua b/third_party/devil_sdk/include/IL/build-lua new file mode 100644 index 0000000..ed45659 --- /dev/null +++ b/third_party/devil_sdk/include/IL/build-lua @@ -0,0 +1,51 @@ +IL_INCLUDE_PATH="/usr/include" +IL_LIB_PATH="/usr/lib" +LUA_INCLUDE_PATH="/usr/include/lua5.1" +LUA_LIB_PATH="/usr/lib" +OSX=no + +echo "Building the lua binding!" + +export SWIG_FEATURES="-I$IL_INCLUDE_PATH" +swig -lua DevIL.i +if [ $? -ne 0 ] ; then + echo "swig Failed to build the lua interface" + exit 1 +fi + +compile() { + gcc luadevil.c "$1" -o luadevil "-L$LUA_LIB_PATH" "-I$LUA_INCLUDE_PATH" "-I$IL_LIB_PATH" -lIL -lILU -lILUT -llua5.1 &>/dev/null + err=$? + if [ "$OSX" = "no" ] ; then + gcc -shared "$1" -o DevIL.so "-L$LUA_LIB_PATH" "-I$LUA_INCLUDE_PATH" "-I$IL_LIB_PATH" -lIL -lILU -lILUT &>/dev/null + else + gcc -bundle -undefined dynamic_lookup "$1" -o DevIL.so "-L$LUA_LIB_PATH" "-I$LUA_INCLUDE_PATH" "-I$IL_LIB_PATH" -lIL -lILU -lILUT &>/dev/null + fi + return $err +} + +compile DevIL_wrap.c +if [ $? -ne 0 ] ; then + echo 'Failed compilation' + echo 'On some platform the file malloc.h is not present and produces a compilation error' + echo -n 'it can be removed safely, try [y/n] ? ' + while read i ; do + if [ "$i" = "y" ] ; then + sed 's/\#include\ \//' < DevIL_wrap.c > DevIL_wrap.mod.c + compile "DevIL_wrap.mod.c" + if [ $? -ne 0 ] ; then + echo 'still failing...' + exit 2 + fi + exit 0 + elif [ "$i" = "n" ] ; then + echo 'ok, failing...' + exit 3 + else + echo 'Unknown command [y/n] ? ' + fi + done +fi + +echo "ok!" +exit 0 diff --git a/third_party/devil_sdk/include/IL/build-python b/third_party/devil_sdk/include/IL/build-python new file mode 100644 index 0000000..bb16b6f --- /dev/null +++ b/third_party/devil_sdk/include/IL/build-python @@ -0,0 +1,17 @@ +#! /bin/bash + +IL_INCLUDE_PATH="/usr/local/include" +IL_LIB_PATH="/usr/local/lib" +PYTHON_INCLUDE_PATH="/usr/include/python2.5" + +swig "-I$IL_INCLUDE_PATH" -python -interface DevIL DevIL.i +if [ $? -ne 0 ] ; then + echo Error while building the swig interface + exit 1 +fi + +gcc -shared "-I$IL_INCLUDE_PATH" "-I$PYTHON_INCLUDE_PATH" "-L$IL_LIB_PATH" -lIL -lILU -lILUT DevIL_wrap.c -o DevIL.so +if [ $? -ne 0 ] ; then + echo Error while compiling the python module +fi +echo "DevIL.py and DevIL.so are ready" diff --git a/third_party/devil_sdk/include/IL/config.h.win b/third_party/devil_sdk/include/IL/config.h.win new file mode 100644 index 0000000..659f4ca --- /dev/null +++ b/third_party/devil_sdk/include/IL/config.h.win @@ -0,0 +1,79 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#define IL_USE_PRAGMA_LIBS // Links to only the libraries that are requested. +#define IL_INLINE_ASM 1 // Define if you can support at least some ASM + +// Supported images formats (IL) + +// #define IL_NO_BLP +// #define IL_NO_BMP +// #define IL_NO_CUT +// #define IL_NO_CHEAD +// #define IL_NO_DCX +// #define IL_NO_DDS +// #define IL_NO_DICOM +// #define IL_NO_DOOM +// #define IL_NO_EXR +// #define IL_NO_FITS +// #define IL_NO_FTX +// #define IL_NO_GIF +// #define IL_NO_HDR +// #define IL_NO_ICO +// #define IL_NO_ICNS +// #define IL_NO_IWI +// #define IL_NO_JP2 +// #define IL_NO_JPG +// #define IL_NO_LCMS +// #define IL_NO_LIF +// #define IL_NO_MDL +// #define IL_NO_MNG +// #define IL_NO_PCD +// #define IL_NO_PCX +// #define IL_NO_PIC +// #define IL_NO_PIX +// #define IL_NO_PNG +// #define IL_NO_PNM +// #define IL_NO_PSD +// #define IL_NO_PSP +// #define IL_NO_PXR +// #define IL_NO_RAW +// #define IL_NO_ROT +// #define IL_NO_SGI +// #define IL_NO_SUN +// #define IL_NO_TGA +// #define IL_NO_TIF +// #define IL_NO_TPL +// #define IL_NO_WAL +// #define IL_NO_WDP +// #define IL_NO_XPM + +#define IL_USE_JPEGLIB_UNMODIFIED 1 +#define IL_USE_DXTC_NVIDIA +#define IL_USE_DXTC_SQUISH + +//#define IL_NO_GAMES + +/* Supported api (ilut) */ + + +// +// sorry just +// cant get this one to work under windows +// have disabled for the now +// +// will look at it some more later +// +// Kriss +// +#undef ILUT_USE_ALLEGRO + +#undef ILUT_USE_DIRECTX8 +#define ILUT_USE_DIRECTX9 +#define ILUT_USE_DIRECTX10 +#define ILUT_USE_OPENGL +#define ILUT_USE_SDL +#define ILUT_USE_WIN32 + + +#endif /* __CONFIG_H__ */ diff --git a/third_party/devil_sdk/include/IL/devil_cpp_wrapper.hpp b/third_party/devil_sdk/include/IL/devil_cpp_wrapper.hpp new file mode 100644 index 0000000..95c7f77 --- /dev/null +++ b/third_party/devil_sdk/include/IL/devil_cpp_wrapper.hpp @@ -0,0 +1,952 @@ +#ifndef DEVIL_CPP_WRAPPER_HPP +#define DEVIL_CPP_WRAPPER_HPP + +#include // Probably only have to #include this one + +class ilImage +{ +public: + ilImage(); + ilImage(ILconst_string); + ilImage(const ilImage &); + virtual ~ilImage(); + + ILboolean Load(ILconst_string); + ILboolean Load(ILconst_string, ILenum); + ILboolean Save(ILconst_string); + ILboolean Save(ILconst_string, ILenum); + + // ImageLib functions + ILboolean ActiveImage(ILuint); + ILboolean ActiveLayer(ILuint); + ILboolean ActiveMipmap(ILuint); + ILboolean Clear(void); + void ClearColour(ILclampf, ILclampf, ILclampf, ILclampf); + ILboolean Convert(ILenum); + ILboolean Copy(ILuint); + ILboolean Default(void); + ILboolean Flip(void); + ILboolean SwapColours(void); + ILboolean Resize(ILuint, ILuint, ILuint); + ILboolean TexImage(ILuint, ILuint, ILuint, ILubyte, ILenum, ILenum, void*); + + // Image handling + void Bind(void) const; + void Bind(ILuint); + void Close(void) { this->Delete(); } + void Delete(void); + void iGenBind(); + ILenum PaletteAlphaIndex(); + + // Image characteristics + ILuint Width(void); + ILuint Height(void); + ILuint Depth(void); + ILubyte Bpp(void); + ILubyte Bitpp(void); + ILenum PaletteType(void); + ILenum Format(void); + ILenum Type(void); + ILuint NumImages(void); + ILuint NumMipmaps(void); + ILuint GetId(void) const; + ILenum GetOrigin(void); + ILubyte *GetData(void); + ILubyte *GetPalette(void); + + // Rendering + ILuint BindImage(void); + ILuint BindImage(ILenum); + + // Operators + ilImage& operator = (ILuint); + ilImage& operator = (const ilImage &); + +protected: + ILuint Id; + +private: + static int ilStartUp(); + static ILboolean ilStartedUp; +}; + +// ensure that init is called exactly once +int ilImage::ilStartUp() +{ + ilInit(); + iluInit(); + //ilutInit(); + return true; +} +ILboolean ilImage::ilStartedUp = ilStartUp(); + +class ilFilters +{ +public: + static ILboolean Alienify(ilImage &); + static ILboolean BlurAvg(ilImage &, ILuint Iter); + static ILboolean BlurGaussian(ilImage &, ILuint Iter); + static ILboolean Contrast(ilImage &, ILfloat Contrast); + static ILboolean EdgeDetectE(ilImage &); + static ILboolean EdgeDetectP(ilImage &); + static ILboolean EdgeDetectS(ilImage &); + static ILboolean Emboss(ilImage &); + static ILboolean Gamma(ilImage &, ILfloat Gamma); + static ILboolean Negative(ilImage &); + static ILboolean Noisify(ilImage &, ILubyte Factor); + static ILboolean Pixelize(ilImage &, ILuint PixSize); + static ILboolean Saturate(ilImage &, ILfloat Saturation); + static ILboolean Saturate(ilImage &, ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation); + static ILboolean ScaleColours(ilImage &, ILfloat r, ILfloat g, ILfloat b); + static ILboolean Sharpen(ilImage &, ILfloat Factor, ILuint Iter); +}; + +#ifdef ILUT_USE_OPENGL +class ilOgl +{ +public: + static void Init(void); + static GLuint BindTex(ilImage &); + static ILboolean Upload(ilImage &, ILuint); + static GLuint Mipmap(ilImage &); + static ILboolean Screen(void); + static ILboolean Screenie(void); +}; +#endif//ILUT_USE_OPENGL + + +#ifdef ILUT_USE_ALLEGRO +class ilAlleg +{ +public: + static void Init(void); + static BITMAP *Convert(ilImage &); +}; +#endif//ILUT_USE_ALLEGRO + + +#ifdef ILUT_USE_WIN32 +class ilWin32 +{ +public: + static void Init(void); + static HBITMAP Convert(ilImage &); + static ILboolean GetClipboard(ilImage &); + static void GetInfo(ilImage &, BITMAPINFO *Info); + static ILubyte *GetPadData(ilImage &); + static HPALETTE GetPal(ilImage &); + static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType); + static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType, ILenum Type); + static ILboolean SetClipboard(ilImage &); +}; +#endif//ILUT_USE_WIN32 + + +class ilValidate +{ +public: + static ILboolean Valid(ILenum, ILconst_string); + static ILboolean Valid(ILenum, FILE *); + static ILboolean Valid(ILenum, void *, ILuint); + +protected: + +private: + +}; + +class ilState +{ +public: + static ILboolean Disable(ILenum); + static ILboolean Enable(ILenum); + static void Get(ILenum, ILboolean &); + static void Get(ILenum, ILint &); + static ILboolean GetBool(ILenum); + static ILint GetInt(ILenum); + static const char *GetString(ILenum); + static ILboolean IsDisabled(ILenum); + static ILboolean IsEnabled(ILenum); + static ILboolean Origin(ILenum); + static void Pop(void); + static void Push(ILuint); + +protected: + +private: + +}; + + +class ilError +{ +public: + static void Check(void (*Callback)(const char*)); + static void Check(void (*Callback)(ILenum)); + static ILenum Get(void); + static const char *String(void); + static const char *String(ILenum); + +protected: + +private: + +}; + + +// +// ILIMAGE +// +ilImage::ilImage() +{ + this->Id = 0; + //this->iStartUp(); // This was commented out, but it needs to be somewhere... + this->iGenBind(); + return; +} + + +ilImage::ilImage(ILconst_string FileName) +{ + this->Id = 0; + //this->iStartUp(); // This was commented out, but it needs to be somewhere... + this->iGenBind(); + ilLoadImage(FileName); + return; +} + + +ilImage::ilImage(const ilImage &Image) +{ + this->Id = 0; + // this->iStartUp(); + this->iGenBind(); + *this = Image; + return; +} + + +ilImage::~ilImage() +{ + if (this->Id) + ilDeleteImages(1, &this->Id); + this->Id = 0; + return; +} + + +ILboolean ilImage::Load(ILconst_string FileName) +{ + this->iGenBind(); + return ilLoadImage(FileName); +} + + +ILboolean ilImage::Load(ILconst_string FileName, ILenum Type) +{ + this->iGenBind(); + return ilLoad(Type, FileName); +} + + +ILboolean ilImage::Save(ILconst_string FileName) +{ + this->iGenBind(); + return ilSaveImage(FileName); +} + + +ILboolean ilImage::Save(ILconst_string FileName, ILenum Type) +{ + this->iGenBind(); + return ilSave(Type, FileName); +} + + + +// +// ImageLib functions +// +ILboolean ilImage::ActiveImage(ILuint Number) +{ + if (this->Id) { + this->Bind(); + return ilActiveImage(Number); + } + return IL_FALSE; +} + + +ILboolean ilImage::ActiveLayer(ILuint Number) +{ + if (this->Id) { + this->Bind(); + return ilActiveLayer(Number); + } + return IL_FALSE; +} + + +ILboolean ilImage::ActiveMipmap(ILuint Number) +{ + if (this->Id) { + this->Bind(); + return ilActiveMipmap(Number); + } + return IL_FALSE; +} + + +ILboolean ilImage::Clear() +{ + if (this->Id) { + this->Bind(); + return ilClearImage(); + } + return IL_FALSE; +} + + +void ilImage::ClearColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha) +{ + ilClearColour(Red, Green, Blue, Alpha); + return; +} + + +ILboolean ilImage::Convert(ILenum NewFormat) +{ + if (this->Id) { + this->Bind(); + return ilConvertImage(NewFormat, IL_UNSIGNED_BYTE); + } + return IL_FALSE; +} + + +ILboolean ilImage::Copy(ILuint Src) +{ + if (this->Id) { + this->Bind(); + return ilCopyImage(Src); + } + return IL_FALSE; +} + + +ILboolean ilImage::Default() +{ + if (this->Id) { + this->Bind(); + return ilDefaultImage(); + } + return IL_FALSE; +} + + +ILboolean ilImage::Flip() +{ + if (this->Id) { + this->Bind(); + return iluFlipImage(); + } + return IL_FALSE; +} + + +ILboolean ilImage::SwapColours() +{ + if (this->Id) { + this->Bind(); + return iluSwapColours(); + } + return IL_FALSE; +} + + +ILboolean ilImage::Resize(ILuint Width, ILuint Height, ILuint Depth) +{ + if (this->Id) { + this->Bind(); + return iluScale(Width, Height, Depth); + } + return IL_FALSE; +} + + +ILboolean ilImage::TexImage(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data) +{ + if (this->Id) { + this->Bind(); + return ilTexImage(Width, Height, Depth, Bpp, Format, Type, Data); + } + return IL_FALSE; +} + + + +// +// Image handling +// +void ilImage::Bind() const +{ + if (this->Id) + ilBindImage(this->Id); + return; +} + +// Note: Behaviour may be changed! +void ilImage::Bind(ILuint Image) +{ + if (this->Id == Image) + return; + this->Delete(); // Should we delete it? + this->Id = Image; + ilBindImage(this->Id); + return; +} + + +void ilImage::Delete() +{ + if (this->Id == 0) + return; + ilDeleteImages(1, &this->Id); + this->Id = 0; + return; +} + + + + +// +// Image characteristics +// +ILuint ilImage::Width() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_WIDTH); + } + return 0; +} + + +ILuint ilImage::Height() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_HEIGHT); + } + return 0; +} + +ILuint ilImage::Depth() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_DEPTH); + } + return 0; +} + +ILubyte ilImage::Bpp() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); + } + return 0; +} + +ILubyte ilImage::Bitpp() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); + } + return 0; +} + +ILenum ilImage::Format() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_FORMAT); + } + return 0; +} + +ILenum ilImage::PaletteType() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_PALETTE_TYPE); + } + return 0; +} + +ILenum ilImage::PaletteAlphaIndex() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_PNG_ALPHA_INDEX); + } + return 0; +} + +ILenum ilImage::Type() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_IMAGE_TYPE); + } + return 0; +} + +ILenum ilImage::NumImages() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_NUM_IMAGES); + } + return 0; +} + +ILenum ilImage::NumMipmaps() +{ + if (this->Id) { + this->Bind(); + return ilGetInteger(IL_NUM_MIPMAPS); + } + return 0; +} + +ILuint ilImage::GetId() const +{ + return this->Id; +} + +ILenum ilImage::GetOrigin(void) +{ + ILinfo Info; + + if (this->Id) { + this->Bind(); + iluGetImageInfo(&Info); + return Info.Origin; + } + return 0; +} + +ILubyte* ilImage::GetData() +{ + if (this->Id) { + this->Bind(); + return ilGetData(); + } + return 0; +} + +ILubyte* ilImage::GetPalette() +{ + if (this->Id) { + this->Bind(); + return ilGetPalette(); + } + return 0; +} + +// +// Private members +// +/*void ilImage::iStartUp() +{ + ilInit(); + iluInit(); + ilutInit(); + return; +}*/ + +void ilImage::iGenBind() +{ + if (this->Id == 0) { + ilGenImages(1, &this->Id); + } + ilBindImage(this->Id); + return; +} + +// +// Operators +// +ilImage& ilImage::operator = (ILuint Image) +{ + if (this->Id == 0) + this->Id = Image; + else { + this->Bind(); + ilCopyImage(Image); + } + + return *this; +} + +ilImage& ilImage::operator = (const ilImage &Image) +{ + if (Id == 0) + Id = Image.GetId(); + else { + Bind(); + ilCopyImage(Image.GetId()); + } + + return *this; +} + +// +// ILFILTERS +// +ILboolean ilFilters::Alienify(ilImage &Image) +{ + Image.Bind(); + return iluAlienify(); +} + +ILboolean ilFilters::BlurAvg(ilImage &Image, ILuint Iter) +{ + Image.Bind(); + return iluBlurAvg(Iter); +} + +ILboolean ilFilters::BlurGaussian(ilImage &Image, ILuint Iter) +{ + Image.Bind(); + return iluBlurGaussian(Iter); +} + +ILboolean ilFilters::Contrast(ilImage &Image, ILfloat Contrast) +{ + Image.Bind(); + return iluContrast(Contrast); +} + +ILboolean ilFilters::EdgeDetectE(ilImage &Image) +{ + Image.Bind(); + return iluEdgeDetectP(); +} + +ILboolean ilFilters::EdgeDetectP(ilImage &Image) +{ + Image.Bind(); + return iluEdgeDetectP(); +} + +ILboolean ilFilters::EdgeDetectS(ilImage &Image) +{ + Image.Bind(); + return iluEdgeDetectS(); +} + +ILboolean ilFilters::Emboss(ilImage &Image) +{ + Image.Bind(); + return iluEmboss(); +} + +ILboolean ilFilters::Gamma(ilImage &Image, ILfloat Gamma) +{ + Image.Bind(); + return iluGammaCorrect(Gamma); +} + +ILboolean ilFilters::Negative(ilImage &Image) +{ + Image.Bind(); + return iluNegative(); +} + +ILboolean ilFilters::Noisify(ilImage &Image, ILubyte Factor) +{ + Image.Bind(); + return iluNoisify(Factor); +} + +ILboolean ilFilters::Pixelize(ilImage &Image, ILuint PixSize) +{ + Image.Bind(); + return iluPixelize(PixSize); +} + +ILboolean ilFilters::Saturate(ilImage &Image, ILfloat Saturation) +{ + Image.Bind(); + return iluSaturate1f(Saturation); +} + +ILboolean ilFilters::Saturate(ilImage &Image, ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation) +{ + Image.Bind(); + return iluSaturate4f(r, g, b, Saturation); +} + +ILboolean ilFilters::ScaleColours(ilImage &Image, ILfloat r, ILfloat g, ILfloat b) +{ + Image.Bind(); + return iluScaleColours(r, g, b); +} + + +ILboolean ilFilters::Sharpen(ilImage &Image, ILfloat Factor, ILuint Iter) +{ + Image.Bind(); + return iluSharpen(Factor, Iter); +} + + +// +// ILOPENGL +// +#ifdef ILUT_USE_OPENGL +void ilOgl::Init() +{ + ilutRenderer(ILUT_OPENGL); + return; +} + + +GLuint ilOgl::BindTex(ilImage &Image) +{ + Image.Bind(); + return ilutGLBindTexImage(); +} + +ILboolean ilOgl::Upload(ilImage &Image, ILuint Level) +{ + Image.Bind(); + return ilutGLTexImage(Level); +} + + +GLuint ilOgl::Mipmap(ilImage &Image) +{ + Image.Bind(); + return ilutGLBuildMipmaps(); +} + +ILboolean ilOgl::Screen() +{ + return ilutGLScreen(); +} + + +ILboolean ilOgl::Screenie() +{ + return ilutGLScreenie(); +} +#endif//ILUT_USE_OPENGL + +// +// ILALLEGRO +// +#ifdef ILUT_USE_ALLEGRO +void ilAlleg::Init() +{ + ilutRenderer(IL_ALLEGRO); + return; +} + +BITMAP *ilAlleg::Convert(ilImage &Image, PALETTE Pal) +{ + Image.Bind(); + return ilutConvertToAlleg(Pal); +} +#endif//ILUT_USE_ALLEGRO + +// +// ILWIN32 +// +#ifdef ILUT_USE_WIN32 +void ilWin32::Init() +{ + ilutRenderer(ILUT_WIN32); + return; +} + +HBITMAP ilWin32::Convert(ilImage &Image) +{ + Image.Bind(); + return ilutConvertToHBitmap(GetDC(NULL)); +} + +ILboolean ilWin32::GetClipboard(ilImage &Image) +{ + Image.Bind(); + return ilutGetWinClipboard(); +} + +void ilWin32::GetInfo(ilImage &Image, BITMAPINFO *Info) +{ + Image.Bind(); + ilutGetBmpInfo(Info); + return; +} + +ILubyte* ilWin32::GetPadData(ilImage &Image) +{ + Image.Bind(); + return ilutGetPaddedData(); +} + +HPALETTE ilWin32::GetPal(ilImage &Image) +{ + Image.Bind(); + return ilutGetHPal(); +} + +ILboolean ilWin32::GetResource(ilImage &Image, HINSTANCE hInst, ILint ID, char *ResourceType) +{ + Image.Bind(); + return ilutLoadResource(hInst, ID, ResourceType, IL_TYPE_UNKNOWN); +} + +ILboolean ilWin32::GetResource(ilImage &Image, HINSTANCE hInst, ILint ID, char *ResourceType, ILenum Type) +{ + Image.Bind(); + return ilutLoadResource(hInst, ID, ResourceType, Type); +} + +ILboolean ilWin32::SetClipboard(ilImage &Image) +{ + Image.Bind(); + return ilutSetWinClipboard(); +} +#endif//ILUT_USE_WIN32 + +// +// ILVALIDATE +// +ILboolean ilValidate::Valid(ILenum Type, ILconst_string FileName) +{ + return ilIsValid(Type, FileName); +} + +ILboolean ilValidate::Valid(ILenum Type, FILE *File) +{ + return ilIsValidF(Type, File); +} + +ILboolean ilValidate::Valid(ILenum Type, void *Lump, ILuint Size) +{ + return ilIsValidL(Type, Lump, Size); +} + +// +// ILSTATE +// +ILboolean ilState::Disable(ILenum State) +{ + return ilDisable(State); +} + +ILboolean ilState::Enable(ILenum State) +{ + return ilEnable(State); +} + +void ilState::Get(ILenum Mode, ILboolean &Param) +{ + ilGetBooleanv(Mode, &Param); + return; +} + +void ilState::Get(ILenum Mode, ILint &Param) +{ + ilGetIntegerv(Mode, &Param); + return; +} + +ILboolean ilState::GetBool(ILenum Mode) +{ + return ilGetBoolean(Mode); +} + +ILint ilState::GetInt(ILenum Mode) +{ + return ilGetInteger(Mode); +} + +const char *ilState::GetString(ILenum StringName) +{ + return ilGetString(StringName); +} + +ILboolean ilState::IsDisabled(ILenum Mode) +{ + return ilIsDisabled(Mode); +} + +ILboolean ilState::IsEnabled(ILenum Mode) +{ + return ilIsEnabled(Mode); +} + +ILboolean ilState::Origin(ILenum Mode) +{ + return ilOriginFunc(Mode); +} + +void ilState::Pop() +{ + ilPopAttrib(); + return; +} + +void ilState::Push(ILuint Bits = IL_ALL_ATTRIB_BITS) +{ + ilPushAttrib(Bits); + return; +} + +// +// ILERROR +// +void ilError::Check(void (*Callback)(const char*)) +{ + static ILenum Error; + + while ((Error = ilGetError()) != IL_NO_ERROR) { + Callback(iluErrorString(Error)); + } + + return; +} + +void ilError::Check(void (*Callback)(ILenum)) +{ + static ILenum Error; + + while ((Error = ilGetError()) != IL_NO_ERROR) { + Callback(Error); + } + + return; +} + +ILenum ilError::Get() +{ + return ilGetError(); +} + +const char *ilError::String() +{ + return iluErrorString(ilGetError()); +} + +const char *ilError::String(ILenum Error) +{ + return iluErrorString(Error); +} + +#endif// DEVIL_CPP_WRAPPER_HPP diff --git a/third_party/devil_sdk/include/IL/devil_internal_exports.h b/third_party/devil_sdk/include/IL/devil_internal_exports.h new file mode 100644 index 0000000..fd07d06 --- /dev/null +++ b/third_party/devil_sdk/include/IL/devil_internal_exports.h @@ -0,0 +1,159 @@ +//----------------------------------------------------------------------------- +// +// ImageLib Sources +// Copyright (C) 2000-2017 by Denton Woods +// Last modified: 01/06/2009 +// +// Filename: IL/devil_internal_exports.h +// +// Description: Internal stuff for DevIL (IL, ILU and ILUT) +// +//----------------------------------------------------------------------------- + +#ifndef IL_EXPORTS_H +#define IL_EXPORTS_H + +#include "IL/il.h" + +#ifdef DEBUG + #include +#else + #define assert(x) +#endif + + +#ifdef NOINLINE + // No inlining. Treat all inline funcs as static. + // Functions will be replicated in all translation units + // use them. + #define STATIC_INLINE static +#else + #if defined(_MSC_VER) && !defined(__cplusplus) + // MSVC compiler uses __inline when compiling C (not C++) + #define STATIC_INLINE static __inline + #else + // Portable across C99, GNU89, C++... + #define STATIC_INLINE static inline + #endif +#endif // NOINLINE + + +#ifdef __cplusplus +extern "C" { +#endif + +#define IL_MAX(a,b) (((a) > (b)) ? (a) : (b)) +#define IL_MIN(a,b) (((a) < (b)) ? (a) : (b)) + + +//! Basic Palette struct +typedef struct ILpal +{ + ILubyte* Palette; //!< the image palette (if any) + ILuint PalSize; //!< size of the palette (in bytes) + ILenum PalType; //!< the palette types in il.h (0x0500 range) +} ILpal; + + +//! The Fundamental Image structure +/*! Every bit of information about an image is stored in this internal structure.*/ +typedef struct ILimage +{ + ILuint Width; //!< the image's width + ILuint Height; //!< the image's height + ILuint Depth; //!< the image's depth + ILubyte Bpp; //!< bytes per pixel (now number of channels) + ILubyte Bpc; //!< bytes per channel + ILuint Bps; //!< bytes per scanline (components for IL) + ILubyte* Data; //!< the image data + ILuint SizeOfData; //!< the total size of the data (in bytes) + ILuint SizeOfPlane; //!< SizeOfData in a 2d image, size of each plane slice in a 3d image (in bytes) + ILenum Format; //!< image format (in IL enum style) + ILenum Type; //!< image type (in IL enum style) + ILenum Origin; //!< origin of the image + ILpal Pal; //!< palette details + ILuint Duration; //!< length of the time to display this "frame" + ILenum CubeFlags; //!< cube map flags for sides present in chain + struct ILimage* Mipmaps; //!< mipmapped versions of this image terminated by a NULL - usu. NULL + struct ILimage* Next; //!< next image in the chain - usu. NULL + struct ILimage* Faces; //!< next cubemap face in the chain - usu. NULL + struct ILimage* Layers; //!< subsequent layers in the chain - usu. NULL + ILuint* AnimList; //!< animation list + ILuint AnimSize; //!< animation list size + void* Profile; //!< colour profile + ILuint ProfileSize; //!< colour profile size + ILuint OffX; //!< x-offset of the image + ILuint OffY; //!< y-offset of the image + ILubyte* DxtcData; //!< compressed data + ILenum DxtcFormat; //!< compressed data format + ILuint DxtcSize; //!< compressed data size +} ILimage; + + +// Memory functions +ILAPI void* ILAPIENTRY ialloc(const ILsizei Size); +ILAPI void ILAPIENTRY ifree(const void *Ptr); +ILAPI void* ILAPIENTRY icalloc(const ILsizei Size, const ILsizei Num); +#ifdef ALTIVEC_GCC +ILAPI void* ILAPIENTRY ivec_align_buffer(void *buffer, const ILuint size); +#endif + +// Internal library functions in IL +ILAPI ILimage* ILAPIENTRY ilGetCurImage(void); +ILAPI void ILAPIENTRY ilSetCurImage(ILimage *Image); +ILAPI void ILAPIENTRY ilSetError(ILenum Error); +ILAPI void ILAPIENTRY ilSetPal(ILpal *Pal); + +// +// Utility functions +// +ILAPI ILubyte ILAPIENTRY ilGetBppFormat(ILenum Format); +ILAPI ILenum ILAPIENTRY ilGetFormatBpp(ILubyte Bpp); +ILAPI ILubyte ILAPIENTRY ilGetBpcType(ILenum Type); +ILAPI ILenum ILAPIENTRY ilGetTypeBpc(ILubyte Bpc); +ILAPI ILubyte ILAPIENTRY ilGetBppPal(ILenum PalType); +ILAPI ILenum ILAPIENTRY ilGetPalBaseType(ILenum PalType); +ILAPI ILuint ILAPIENTRY ilNextPower2(ILuint Num); +ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName); +ILAPI void ILAPIENTRY ilReplaceCurImage(ILimage *Image); +ILAPI void ILAPIENTRY iMemSwap(ILubyte *, ILubyte *, const ILuint); + +// +// Image functions +// +ILAPI void ILAPIENTRY iBindImageTemp (void); +ILAPI ILboolean ILAPIENTRY ilClearImage_ (ILimage *Image); +ILAPI void ILAPIENTRY ilCloseImage (ILimage *Image); +ILAPI void ILAPIENTRY ilClosePal (ILpal *Palette); +ILAPI ILpal* ILAPIENTRY iCopyPal (void); +ILAPI ILboolean ILAPIENTRY ilCopyImageAttr (ILimage *Dest, ILimage *Src); +ILAPI ILimage* ILAPIENTRY ilCopyImage_ (ILimage *Src); +ILAPI void ILAPIENTRY ilGetClear (void *Colours, ILenum Format, ILenum Type); +ILAPI ILuint ILAPIENTRY ilGetCurName (void); +ILAPI ILboolean ILAPIENTRY ilIsValidPal (ILpal *Palette); +ILAPI ILimage* ILAPIENTRY ilNewImage (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc); +ILAPI ILimage* ILAPIENTRY ilNewImageFull (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); +ILAPI ILboolean ILAPIENTRY ilInitImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); +ILAPI ILboolean ILAPIENTRY ilResizeImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc); +ILAPI ILboolean ILAPIENTRY ilTexImage_ (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); +ILAPI ILboolean ILAPIENTRY ilTexImageSurface_(ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data); +ILAPI ILboolean ILAPIENTRY ilTexSubImage_ (ILimage *Image, void *Data); +ILAPI void* ILAPIENTRY ilConvertBuffer (ILuint SizeOfData, ILenum SrcFormat, ILenum DestFormat, ILenum SrcType, ILenum DestType, ILpal *SrcPal, void *Buffer); +ILAPI ILimage* ILAPIENTRY iConvertImage (ILimage *Image, ILenum DestFormat, ILenum DestType); +ILAPI ILpal* ILAPIENTRY iConvertPal (ILpal *Pal, ILenum DestFormat); +ILAPI ILubyte* ILAPIENTRY iGetFlipped (ILimage *Image); +ILAPI ILboolean ILAPIENTRY iMirror(); +ILAPI void ILAPIENTRY iFlipBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num); +ILubyte* iFlipNewBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num); +ILAPI void ILAPIENTRY iGetIntegervImage(ILimage *Image, ILenum Mode, ILint *Param); + +// Internal library functions in ILU +ILAPI ILimage* ILAPIENTRY iluRotate_(ILimage *Image, ILfloat Angle); +ILAPI ILimage* ILAPIENTRY iluRotate3D_(ILimage *Image, ILfloat x, ILfloat y, ILfloat z, ILfloat Angle); +ILAPI ILimage* ILAPIENTRY iluScale_(ILimage *Image, ILuint Width, ILuint Height, ILuint Depth); + +#ifdef __cplusplus +} +#endif + +#endif//IL_EXPORTS_H diff --git a/third_party/devil_sdk/include/IL/il.h b/third_party/devil_sdk/include/IL/il.h new file mode 100644 index 0000000..47dfcd7 --- /dev/null +++ b/third_party/devil_sdk/include/IL/il.h @@ -0,0 +1,645 @@ +//----------------------------------------------------------------------------- +// +// ImageLib Sources +// Copyright (C) 2000-2017 by Denton Woods +// Last modified: 03/07/2009 +// +// Filename: IL/il.h +// +// Description: The main include file for DevIL +// +//----------------------------------------------------------------------------- + +// Doxygen comment +/*! \file il.h + The main include file for DevIL +*/ + +#ifndef __il_h_ +#ifndef __IL_H__ + +#define __il_h_ +#define __IL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//this define controls if floats and doubles are clamped to [0..1] +//during conversion. It takes a little more time, but it is the correct +//way of doing this. If you are sure your floats are always valid, +//you can undefine this value... +#define CLAMP_HALF 1 +#define CLAMP_FLOATS 1 +#define CLAMP_DOUBLES 1 + +/*#ifdef _WIN32_WCE + #define IL_NO_EXR + #define IL_NO_GIF + #define IL_NO_JP2 + #define IL_NO_JPG + #define IL_NO_MNG + #define IL_NO_PNG + #define IL_NO_TIF + #define IL_NO_LCMS +#endif //_WIN32_WCE + +#ifdef DJGPP + #define IL_NO_EXR + #define IL_NO_GIF + #define IL_NO_JP2 + #define IL_NO_JPG + #define IL_NO_MNG + #define IL_NO_PNG + #define IL_NO_TIF + #define IL_NO_LCMS +#endif //DJGPP*/ + +#ifdef _WIN32 + #if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY)) + #if defined(_MSC_VER) || defined(__BORLANDC__) + #pragma comment(lib, "DevIL.lib") + #endif + #endif +#endif + +#if defined(RESTRICT_KEYWORD) && !defined(__cplusplus) +#define RESTRICT restrict +#define CONST_RESTRICT const restrict +#else +#define RESTRICT +#define CONST_RESTRICT const +#endif + +#include + +typedef unsigned int ILenum; +typedef unsigned char ILboolean; +typedef unsigned int ILbitfield; +typedef signed char ILbyte; +typedef signed short ILshort; +typedef int ILint; +typedef size_t ILsizei; +typedef unsigned char ILubyte; +typedef unsigned short ILushort; +typedef unsigned int ILuint; +typedef float ILfloat; +typedef float ILclampf; +typedef double ILdouble; +typedef double ILclampd; + +#ifdef _MSC_VER +typedef __int64 ILint64; +typedef unsigned __int64 ILuint64; +#else +typedef long long int ILint64; +typedef long long unsigned int ILuint64; +#endif + + +#include +#ifdef _UNICODE + #ifndef _WIN32_WCE + #include + #endif + //if we use a define instead of a typedef, + //ILconst_string works as intended + #define ILchar wchar_t + #define ILstring wchar_t* + #define ILconst_string wchar_t const * +#else + //if we use a define instead of a typedef, + //ILconst_string works as intended + #define ILchar char + #define ILstring char* + #define ILconst_string char const * +#endif //_UNICODE + +#define IL_FALSE 0 +#define IL_TRUE 1 + +// Matches OpenGL's right now. +//! Data formats \link Formats Formats\endlink +#define IL_COLOUR_INDEX 0x1900 +#define IL_COLOR_INDEX 0x1900 +#define IL_ALPHA 0x1906 +#define IL_RGB 0x1907 +#define IL_RGBA 0x1908 +#define IL_BGR 0x80E0 +#define IL_BGRA 0x80E1 +#define IL_LUMINANCE 0x1909 +#define IL_LUMINANCE_ALPHA 0x190A + +//! Data types \link Types Types\endlink +#define IL_BYTE 0x1400 +#define IL_UNSIGNED_BYTE 0x1401 +#define IL_SHORT 0x1402 +#define IL_UNSIGNED_SHORT 0x1403 +#define IL_INT 0x1404 +#define IL_UNSIGNED_INT 0x1405 +#define IL_FLOAT 0x1406 +#define IL_DOUBLE 0x140A +#define IL_HALF 0x140B + + +#define IL_MAX_BYTE SCHAR_MAX +#define IL_MAX_UNSIGNED_BYTE UCHAR_MAX +#define IL_MAX_SHORT SHRT_MAX +#define IL_MAX_UNSIGNED_SHORT USHRT_MAX +#define IL_MAX_INT INT_MAX +#define IL_MAX_UNSIGNED_INT UINT_MAX + +#define IL_LIMIT(x,m,M) (xM?M:x)) +#define IL_CLAMP(x) IL_LIMIT(x,0,1) + +#define IL_VENDOR 0x1F00 +#define IL_LOAD_EXT 0x1F01 +#define IL_SAVE_EXT 0x1F02 + + +// +// IL-specific #define's +// + +#define IL_VERSION_1_8_0 1 +#define IL_VERSION 180 + + +// Attribute Bits +#define IL_ORIGIN_BIT 0x00000001 +#define IL_FILE_BIT 0x00000002 +#define IL_PAL_BIT 0x00000004 +#define IL_FORMAT_BIT 0x00000008 +#define IL_TYPE_BIT 0x00000010 +#define IL_COMPRESS_BIT 0x00000020 +#define IL_LOADFAIL_BIT 0x00000040 +#define IL_FORMAT_SPECIFIC_BIT 0x00000080 +#define IL_ALL_ATTRIB_BITS 0x000FFFFF + + +// Palette types +#define IL_PAL_NONE 0x0400 +#define IL_PAL_RGB24 0x0401 +#define IL_PAL_RGB32 0x0402 +#define IL_PAL_RGBA32 0x0403 +#define IL_PAL_BGR24 0x0404 +#define IL_PAL_BGR32 0x0405 +#define IL_PAL_BGRA32 0x0406 + + +// Image types +#define IL_TYPE_UNKNOWN 0x0000 +#define IL_BMP 0x0420 //!< Microsoft Windows Bitmap - .bmp extension +#define IL_CUT 0x0421 //!< Dr. Halo - .cut extension +#define IL_DOOM 0x0422 //!< DooM walls - no specific extension +#define IL_DOOM_FLAT 0x0423 //!< DooM flats - no specific extension +#define IL_ICO 0x0424 //!< Microsoft Windows Icons and Cursors - .ico and .cur extensions +#define IL_JPG 0x0425 //!< JPEG - .jpg, .jpe and .jpeg extensions +#define IL_JFIF 0x0425 //!< +#define IL_ILBM 0x0426 //!< Amiga IFF (FORM ILBM) - .iff, .ilbm, .lbm extensions +#define IL_PCD 0x0427 //!< Kodak PhotoCD - .pcd extension +#define IL_PCX 0x0428 //!< ZSoft PCX - .pcx extension +#define IL_PIC 0x0429 //!< PIC - .pic extension +#define IL_PNG 0x042A //!< Portable Network Graphics - .png extension +#define IL_PNM 0x042B //!< Portable Any Map - .pbm, .pgm, .ppm and .pnm extensions +#define IL_SGI 0x042C //!< Silicon Graphics - .sgi, .bw, .rgb and .rgba extensions +#define IL_TGA 0x042D //!< TrueVision Targa File - .tga, .vda, .icb and .vst extensions +#define IL_TIF 0x042E //!< Tagged Image File Format - .tif and .tiff extensions +#define IL_CHEAD 0x042F //!< C-Style Header - .h extension +#define IL_RAW 0x0430 //!< Raw Image Data - any extension +#define IL_MDL 0x0431 //!< Half-Life Model Texture - .mdl extension +#define IL_WAL 0x0432 //!< Quake 2 Texture - .wal extension +#define IL_LIF 0x0434 //!< Homeworld Texture - .lif extension +#define IL_MNG 0x0435 //!< Multiple-image Network Graphics - .mng extension +#define IL_JNG 0x0435 //!< +#define IL_GIF 0x0436 //!< Graphics Interchange Format - .gif extension +#define IL_DDS 0x0437 //!< DirectDraw Surface - .dds extension +#define IL_DCX 0x0438 //!< ZSoft Multi-PCX - .dcx extension +#define IL_PSD 0x0439 //!< Adobe PhotoShop - .psd extension +#define IL_EXIF 0x043A //!< +#define IL_PSP 0x043B //!< PaintShop Pro - .psp extension +#define IL_PIX 0x043C //!< PIX - .pix extension +#define IL_PXR 0x043D //!< Pixar - .pxr extension +#define IL_XPM 0x043E //!< X Pixel Map - .xpm extension +#define IL_HDR 0x043F //!< Radiance High Dynamic Range - .hdr extension +#define IL_ICNS 0x0440 //!< Macintosh Icon - .icns extension +#define IL_JP2 0x0441 //!< Jpeg 2000 - .jp2 extension +#define IL_EXR 0x0442 //!< OpenEXR - .exr extension +#define IL_WDP 0x0443 //!< Microsoft HD Photo - .wdp and .hdp extension +#define IL_VTF 0x0444 //!< Valve Texture Format - .vtf extension +#define IL_WBMP 0x0445 //!< Wireless Bitmap - .wbmp extension +#define IL_SUN 0x0446 //!< Sun Raster - .sun, .ras, .rs, .im1, .im8, .im24 and .im32 extensions +#define IL_IFF 0x0447 //!< Interchange File Format - .iff extension +#define IL_TPL 0x0448 //!< Gamecube Texture - .tpl extension +#define IL_FITS 0x0449 //!< Flexible Image Transport System - .fit and .fits extensions +#define IL_DICOM 0x044A //!< Digital Imaging and Communications in Medicine (DICOM) - .dcm and .dicom extensions +#define IL_IWI 0x044B //!< Call of Duty Infinity Ward Image - .iwi extension +#define IL_BLP 0x044C //!< Blizzard Texture Format - .blp extension +#define IL_FTX 0x044D //!< Heavy Metal: FAKK2 Texture - .ftx extension +#define IL_ROT 0x044E //!< Homeworld 2 - Relic Texture - .rot extension +#define IL_TEXTURE 0x044F //!< Medieval II: Total War Texture - .texture extension +#define IL_DPX 0x0450 //!< Digital Picture Exchange - .dpx extension +#define IL_UTX 0x0451 //!< Unreal (and Unreal Tournament) Texture - .utx extension +#define IL_MP3 0x0452 //!< MPEG-1 Audio Layer 3 - .mp3 extension +#define IL_KTX 0x0453 //!< Khronos Texture - .ktx extension + + +#define IL_JASC_PAL 0x0475 //!< PaintShop Pro Palette + + +// Error Types +#define IL_NO_ERROR 0x0000 +#define IL_INVALID_ENUM 0x0501 +#define IL_OUT_OF_MEMORY 0x0502 +#define IL_FORMAT_NOT_SUPPORTED 0x0503 +#define IL_INTERNAL_ERROR 0x0504 +#define IL_INVALID_VALUE 0x0505 +#define IL_ILLEGAL_OPERATION 0x0506 +#define IL_ILLEGAL_FILE_VALUE 0x0507 +#define IL_INVALID_FILE_HEADER 0x0508 +#define IL_INVALID_PARAM 0x0509 +#define IL_COULD_NOT_OPEN_FILE 0x050A +#define IL_INVALID_EXTENSION 0x050B +#define IL_FILE_ALREADY_EXISTS 0x050C +#define IL_OUT_FORMAT_SAME 0x050D +#define IL_STACK_OVERFLOW 0x050E +#define IL_STACK_UNDERFLOW 0x050F +#define IL_INVALID_CONVERSION 0x0510 +#define IL_BAD_DIMENSIONS 0x0511 +#define IL_FILE_READ_ERROR 0x0512 // 05/12/2002: Addition by Sam. +#define IL_FILE_WRITE_ERROR 0x0512 + +#define IL_LIB_GIF_ERROR 0x05E1 +#define IL_LIB_JPEG_ERROR 0x05E2 +#define IL_LIB_PNG_ERROR 0x05E3 +#define IL_LIB_TIFF_ERROR 0x05E4 +#define IL_LIB_MNG_ERROR 0x05E5 +#define IL_LIB_JP2_ERROR 0x05E6 +#define IL_LIB_EXR_ERROR 0x05E7 +#define IL_UNKNOWN_ERROR 0x05FF + + +// Origin Definitions +#define IL_ORIGIN_SET 0x0600 +#define IL_ORIGIN_LOWER_LEFT 0x0601 +#define IL_ORIGIN_UPPER_LEFT 0x0602 +#define IL_ORIGIN_MODE 0x0603 + + +// Format and Type Mode Definitions +#define IL_FORMAT_SET 0x0610 +#define IL_FORMAT_MODE 0x0611 +#define IL_TYPE_SET 0x0612 +#define IL_TYPE_MODE 0x0613 + + +// File definitions +#define IL_FILE_OVERWRITE 0x0620 +#define IL_FILE_MODE 0x0621 + + +// Palette definitions +#define IL_CONV_PAL 0x0630 + + +// Load fail definitions +#define IL_DEFAULT_ON_FAIL 0x0632 + + +// Key colour and alpha definitions +#define IL_USE_KEY_COLOUR 0x0635 +#define IL_USE_KEY_COLOR 0x0635 +#define IL_BLIT_BLEND 0x0636 + + +// Interlace definitions +#define IL_SAVE_INTERLACED 0x0639 +#define IL_INTERLACE_MODE 0x063A + + +// Quantization definitions +#define IL_QUANTIZATION_MODE 0x0640 +#define IL_WU_QUANT 0x0641 +#define IL_NEU_QUANT 0x0642 +#define IL_NEU_QUANT_SAMPLE 0x0643 +#define IL_MAX_QUANT_INDEXS 0x0644 //XIX : ILint : Maximum number of colors to reduce to, default of 256. and has a range of 2-256 +#define IL_MAX_QUANT_INDICES 0x0644 // Redefined, since the above #define is misspelled + + +// Hints +#define IL_FASTEST 0x0660 +#define IL_LESS_MEM 0x0661 +#define IL_DONT_CARE 0x0662 +#define IL_MEM_SPEED_HINT 0x0665 +#define IL_USE_COMPRESSION 0x0666 +#define IL_NO_COMPRESSION 0x0667 +#define IL_COMPRESSION_HINT 0x0668 + + +// Compression +#define IL_NVIDIA_COMPRESS 0x0670 +#define IL_SQUISH_COMPRESS 0x0671 + + +// Subimage types +#define IL_SUB_NEXT 0x0680 +#define IL_SUB_MIPMAP 0x0681 +#define IL_SUB_LAYER 0x0682 + + +// Compression definitions +#define IL_COMPRESS_MODE 0x0700 +#define IL_COMPRESS_NONE 0x0701 +#define IL_COMPRESS_RLE 0x0702 +#define IL_COMPRESS_LZO 0x0703 +#define IL_COMPRESS_ZLIB 0x0704 + + +// File format-specific values +#define IL_TGA_CREATE_STAMP 0x0710 +#define IL_JPG_QUALITY 0x0711 +#define IL_PNG_INTERLACE 0x0712 +#define IL_TGA_RLE 0x0713 +#define IL_BMP_RLE 0x0714 +#define IL_SGI_RLE 0x0715 +#define IL_TGA_ID_STRING 0x0717 +#define IL_TGA_AUTHNAME_STRING 0x0718 +#define IL_TGA_AUTHCOMMENT_STRING 0x0719 +#define IL_PNG_AUTHNAME_STRING 0x071A +#define IL_PNG_TITLE_STRING 0x071B +#define IL_PNG_DESCRIPTION_STRING 0x071C +#define IL_TIF_DESCRIPTION_STRING 0x071D +#define IL_TIF_HOSTCOMPUTER_STRING 0x071E +#define IL_TIF_DOCUMENTNAME_STRING 0x071F +#define IL_TIF_AUTHNAME_STRING 0x0720 +#define IL_JPG_SAVE_FORMAT 0x0721 +#define IL_CHEAD_HEADER_STRING 0x0722 +#define IL_PCD_PICNUM 0x0723 +#define IL_PNG_ALPHA_INDEX 0x0724 // currently has no effect! +#define IL_JPG_PROGRESSIVE 0x0725 +#define IL_VTF_COMP 0x0726 + + +// DXTC definitions +#define IL_DXTC_FORMAT 0x0705 +#define IL_DXT1 0x0706 +#define IL_DXT2 0x0707 +#define IL_DXT3 0x0708 +#define IL_DXT4 0x0709 +#define IL_DXT5 0x070A +#define IL_DXT_NO_COMP 0x070B +#define IL_KEEP_DXTC_DATA 0x070C +#define IL_DXTC_DATA_FORMAT 0x070D +#define IL_3DC 0x070E +#define IL_RXGB 0x070F +#define IL_ATI1N 0x0710 +#define IL_DXT1A 0x0711 // Normally the same as IL_DXT1, except for nVidia Texture Tools. + +// Environment map definitions +#define IL_CUBEMAP_POSITIVEX 0x00000400 +#define IL_CUBEMAP_NEGATIVEX 0x00000800 +#define IL_CUBEMAP_POSITIVEY 0x00001000 +#define IL_CUBEMAP_NEGATIVEY 0x00002000 +#define IL_CUBEMAP_POSITIVEZ 0x00004000 +#define IL_CUBEMAP_NEGATIVEZ 0x00008000 +#define IL_SPHEREMAP 0x00010000 + + +// Values +#define IL_VERSION_NUM 0x0DE2 +#define IL_IMAGE_WIDTH 0x0DE4 +#define IL_IMAGE_HEIGHT 0x0DE5 +#define IL_IMAGE_DEPTH 0x0DE6 +#define IL_IMAGE_SIZE_OF_DATA 0x0DE7 +#define IL_IMAGE_BPP 0x0DE8 +#define IL_IMAGE_BYTES_PER_PIXEL 0x0DE8 +#define IL_IMAGE_BPP 0x0DE8 +#define IL_IMAGE_BITS_PER_PIXEL 0x0DE9 +#define IL_IMAGE_FORMAT 0x0DEA +#define IL_IMAGE_TYPE 0x0DEB +#define IL_PALETTE_TYPE 0x0DEC +#define IL_PALETTE_SIZE 0x0DED +#define IL_PALETTE_BPP 0x0DEE +#define IL_PALETTE_NUM_COLS 0x0DEF +#define IL_PALETTE_BASE_TYPE 0x0DF0 +#define IL_NUM_FACES 0x0DE1 +#define IL_NUM_IMAGES 0x0DF1 +#define IL_NUM_MIPMAPS 0x0DF2 +#define IL_NUM_LAYERS 0x0DF3 +#define IL_ACTIVE_IMAGE 0x0DF4 +#define IL_ACTIVE_MIPMAP 0x0DF5 +#define IL_ACTIVE_LAYER 0x0DF6 +#define IL_ACTIVE_FACE 0x0E00 +#define IL_CUR_IMAGE 0x0DF7 +#define IL_IMAGE_DURATION 0x0DF8 +#define IL_IMAGE_PLANESIZE 0x0DF9 +#define IL_IMAGE_BPC 0x0DFA +#define IL_IMAGE_OFFX 0x0DFB +#define IL_IMAGE_OFFY 0x0DFC +#define IL_IMAGE_CUBEFLAGS 0x0DFD +#define IL_IMAGE_ORIGIN 0x0DFE +#define IL_IMAGE_CHANNELS 0x0DFF + +# if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) +// __attribute__((deprecated)) is supported by GCC 3.1 and later. +# define DEPRECATED(D) D __attribute__((deprecated)) +# elif defined _MSC_VER && _MSC_VER >= 1300 +// __declspec(deprecated) is supported by MSVC 7.0 and later. +# define DEPRECATED(D) __declspec(deprecated) D +# else +# define DEPRECATED (D) D +# endif + +// +// Section shamelessly modified from the glut header. +// + +// This is from Win32's +#if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__) + #define ILAPIENTRY __stdcall + #define IL_PACKSTRUCT +//#elif defined(linux) || defined(MACOSX) || defined(__CYGWIN__) //fix bug 840364 +#elif defined( __GNUC__ ) + // this should work for any of the above commented platforms + // plus any platform using GCC + #ifdef __MINGW32__ + #define ILAPIENTRY __stdcall + #else + #define ILAPIENTRY + #endif + #define IL_PACKSTRUCT __attribute__ ((packed)) +#else + #define ILAPIENTRY + #define IL_PACKSTRUCT +#endif + +// This is from Win32's and +#if defined(__LCC__) + #define ILAPI __stdcall +#elif defined(_WIN32) //changed 20031221 to fix bug 840421 + #ifdef IL_STATIC_LIB + #define ILAPI + #else + #ifdef _IL_BUILD_LIBRARY + #define ILAPI __declspec(dllexport) + #else + #define ILAPI __declspec(dllimport) + #endif + #endif +#elif __APPLE__ + #define ILAPI extern +#else + #define ILAPI +#endif + + +#define IL_SEEK_SET 0 +#define IL_SEEK_CUR 1 +#define IL_SEEK_END 2 +#define IL_EOF -1 + + +// Callback functions for file reading +typedef void* ILHANDLE; +typedef void (ILAPIENTRY *fCloseRProc)(ILHANDLE); +typedef ILboolean (ILAPIENTRY *fEofProc) (ILHANDLE); +typedef ILint (ILAPIENTRY *fGetcProc) (ILHANDLE); +typedef ILHANDLE (ILAPIENTRY *fOpenRProc) (ILconst_string); +typedef ILint (ILAPIENTRY *fReadProc) (void*, ILuint, ILuint, ILHANDLE); +typedef ILint (ILAPIENTRY *fSeekRProc) (ILHANDLE, ILint, ILint); +typedef ILint (ILAPIENTRY *fTellRProc) (ILHANDLE); + +// Callback functions for file writing +typedef void (ILAPIENTRY *fCloseWProc)(ILHANDLE); +typedef ILHANDLE (ILAPIENTRY *fOpenWProc) (ILconst_string); +typedef ILint (ILAPIENTRY *fPutcProc) (ILubyte, ILHANDLE); +typedef ILint (ILAPIENTRY *fSeekWProc) (ILHANDLE, ILint, ILint); +typedef ILint (ILAPIENTRY *fTellWProc) (ILHANDLE); +typedef ILint (ILAPIENTRY *fWriteProc) (const void*, ILuint, ILuint, ILHANDLE); + +// Callback functions for allocation and deallocation +typedef void* (ILAPIENTRY *mAlloc)(const ILsizei); +typedef void (ILAPIENTRY *mFree) (const void* CONST_RESTRICT); + +// Registered format procedures +typedef ILenum (ILAPIENTRY *IL_LOADPROC)(ILconst_string); +typedef ILenum (ILAPIENTRY *IL_SAVEPROC)(ILconst_string); + + +// ImageLib Functions +ILAPI ILboolean ILAPIENTRY ilActiveFace(ILuint Number); +ILAPI ILboolean ILAPIENTRY ilActiveImage(ILuint Number); +ILAPI ILboolean ILAPIENTRY ilActiveLayer(ILuint Number); +ILAPI ILboolean ILAPIENTRY ilActiveMipmap(ILuint Number); +ILAPI ILboolean ILAPIENTRY ilApplyPal(ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY ilApplyProfile(ILstring InProfile, ILstring OutProfile); +ILAPI void ILAPIENTRY ilBindImage(ILuint Image); +ILAPI ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ, ILuint SrcX, ILuint SrcY, ILuint SrcZ, ILuint Width, ILuint Height, ILuint Depth); +ILAPI ILboolean ILAPIENTRY ilClampNTSC(void); +ILAPI void ILAPIENTRY ilClearColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha); +ILAPI ILboolean ILAPIENTRY ilClearImage(void); +ILAPI ILuint ILAPIENTRY ilCloneCurImage(void); +ILAPI ILubyte* ILAPIENTRY ilCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILuint Depth, ILenum DXTCFormat, ILuint *DXTCSize); +ILAPI ILboolean ILAPIENTRY ilCompressFunc(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilConvertImage(ILenum DestFormat, ILenum DestType); +ILAPI ILboolean ILAPIENTRY ilConvertPal(ILenum DestFormat); +ILAPI ILboolean ILAPIENTRY ilCopyImage(ILuint Src); +ILAPI ILuint ILAPIENTRY ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data); +ILAPI ILuint ILAPIENTRY ilCreateSubImage(ILenum Type, ILuint Num); +ILAPI ILboolean ILAPIENTRY ilDefaultImage(void); +ILAPI void ILAPIENTRY ilDeleteImage(const ILuint Num); +ILAPI void ILAPIENTRY ilDeleteImages(ILsizei Num, const ILuint *Images); +ILAPI ILenum ILAPIENTRY ilDetermineType(ILconst_string FileName); +ILAPI ILenum ILAPIENTRY ilDetermineTypeF(ILHANDLE File); +ILAPI ILenum ILAPIENTRY ilDetermineTypeL(const void *Lump, ILuint Size); +ILAPI ILboolean ILAPIENTRY ilDisable(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilDxtcDataToImage(void); +ILAPI ILboolean ILAPIENTRY ilDxtcDataToSurface(void); +ILAPI ILboolean ILAPIENTRY ilEnable(ILenum Mode); +ILAPI void ILAPIENTRY ilFlipSurfaceDxtcData(void); +ILAPI ILboolean ILAPIENTRY ilFormatFunc(ILenum Mode); +ILAPI void ILAPIENTRY ilGenImages(ILsizei Num, ILuint *Images); +ILAPI ILuint ILAPIENTRY ilGenImage(void); +ILAPI ILubyte* ILAPIENTRY ilGetAlpha(ILenum Type); +ILAPI ILboolean ILAPIENTRY ilGetBoolean(ILenum Mode); +ILAPI void ILAPIENTRY ilGetBooleanv(ILenum Mode, ILboolean *Param); +ILAPI ILubyte* ILAPIENTRY ilGetData(void); +ILAPI ILuint ILAPIENTRY ilGetDXTCData(void *Buffer, ILuint BufferSize, ILenum DXTCFormat); +ILAPI ILenum ILAPIENTRY ilGetError(void); +ILAPI ILint ILAPIENTRY ilGetInteger(ILenum Mode); +ILAPI void ILAPIENTRY ilGetIntegerv(ILenum Mode, ILint *Param); +ILAPI ILuint ILAPIENTRY ilGetLumpPos(void); +ILAPI ILubyte* ILAPIENTRY ilGetPalette(void); +ILAPI ILconst_string ILAPIENTRY ilGetString(ILenum StringName); +ILAPI void ILAPIENTRY ilHint(ILenum Target, ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilInvertSurfaceDxtcDataAlpha(void); +ILAPI void ILAPIENTRY ilInit(void); +ILAPI ILboolean ILAPIENTRY ilImageToDxtcData(ILenum Format); +ILAPI ILboolean ILAPIENTRY ilIsDisabled(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilIsEnabled(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilIsImage(ILuint Image); +ILAPI ILboolean ILAPIENTRY ilIsValid(ILenum Type, ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY ilIsValidF(ILenum Type, ILHANDLE File); +ILAPI ILboolean ILAPIENTRY ilIsValidL(ILenum Type, void *Lump, ILuint Size); +ILAPI void ILAPIENTRY ilKeyColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha); +ILAPI ILboolean ILAPIENTRY ilLoad(ILenum Type, ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY ilLoadF(ILenum Type, ILHANDLE File); +ILAPI ILboolean ILAPIENTRY ilLoadImage(ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY ilLoadL(ILenum Type, const void *Lump, ILuint Size); +ILAPI ILboolean ILAPIENTRY ilLoadPal(ILconst_string FileName); +ILAPI void ILAPIENTRY ilModAlpha(ILdouble AlphaValue); +ILAPI ILboolean ILAPIENTRY ilOriginFunc(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, ILint ZCoord); +ILAPI void ILAPIENTRY ilPopAttrib(void); +ILAPI void ILAPIENTRY ilPushAttrib(ILuint Bits); +ILAPI void ILAPIENTRY ilRegisterFormat(ILenum Format); +ILAPI ILboolean ILAPIENTRY ilRegisterLoad(ILconst_string Ext, IL_LOADPROC Load); +ILAPI ILboolean ILAPIENTRY ilRegisterMipNum(ILuint Num); +ILAPI ILboolean ILAPIENTRY ilRegisterNumFaces(ILuint Num); +ILAPI ILboolean ILAPIENTRY ilRegisterNumImages(ILuint Num); +ILAPI void ILAPIENTRY ilRegisterOrigin(ILenum Origin); +ILAPI void ILAPIENTRY ilRegisterPal(void *Pal, ILuint Size, ILenum Type); +ILAPI ILboolean ILAPIENTRY ilRegisterSave(ILconst_string Ext, IL_SAVEPROC Save); +ILAPI void ILAPIENTRY ilRegisterType(ILenum Type); +ILAPI ILboolean ILAPIENTRY ilRemoveLoad(ILconst_string Ext); +ILAPI ILboolean ILAPIENTRY ilRemoveSave(ILconst_string Ext); +ILAPI void ILAPIENTRY ilResetMemory(void); // Deprecated +ILAPI void ILAPIENTRY ilResetRead(void); +ILAPI void ILAPIENTRY ilResetWrite(void); +ILAPI ILboolean ILAPIENTRY ilSave(ILenum Type, ILconst_string FileName); +ILAPI ILuint ILAPIENTRY ilSaveF(ILenum Type, ILHANDLE File); +ILAPI ILboolean ILAPIENTRY ilSaveImage(ILconst_string FileName); +ILAPI ILuint ILAPIENTRY ilSaveL(ILenum Type, void *Lump, ILuint Size); +ILAPI ILboolean ILAPIENTRY ilSavePal(ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY ilSetAlpha(ILdouble AlphaValue); +ILAPI ILboolean ILAPIENTRY ilSetData(void *Data); +ILAPI ILboolean ILAPIENTRY ilSetDuration(ILuint Duration); +ILAPI void ILAPIENTRY ilSetInteger(ILenum Mode, ILint Param); +ILAPI void ILAPIENTRY ilSetMemory(mAlloc, mFree); +ILAPI void ILAPIENTRY ilSetPixels(ILint XOff, ILint YOff, ILint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data); +ILAPI void ILAPIENTRY ilSetRead(fOpenRProc, fCloseRProc, fEofProc, fGetcProc, fReadProc, fSeekRProc, fTellRProc); +ILAPI void ILAPIENTRY ilSetString(ILenum Mode, const char *String); +ILAPI void ILAPIENTRY ilSetWrite(fOpenWProc, fCloseWProc, fPutcProc, fSeekWProc, fTellWProc, fWriteProc); +ILAPI void ILAPIENTRY ilShutDown(void); +ILAPI ILboolean ILAPIENTRY ilSurfaceToDxtcData(ILenum Format); +ILAPI ILboolean ILAPIENTRY ilTexImage(ILuint Width, ILuint Height, ILuint Depth, ILubyte NumChannels, ILenum Format, ILenum Type, void *Data); +ILAPI ILboolean ILAPIENTRY ilTexImageDxtc(ILint w, ILint h, ILint d, ILenum DxtFormat, const ILubyte* data); +ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY ilTypeFunc(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilLoadData(ILconst_string FileName, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp); +ILAPI ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp); +ILAPI ILboolean ILAPIENTRY ilLoadDataL(void *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp); +ILAPI ILboolean ILAPIENTRY ilSaveData(ILconst_string FileName); + +// For all those weirdos that spell "colour" without the 'u'. +#define ilClearColor ilClearColour +#define ilKeyColor ilKeyColour + +#define imemclear(x,y) memset(x,0,y); + +#ifdef __cplusplus +} +#endif + +#endif // __IL_H__ +#endif // __il_h__ diff --git a/third_party/devil_sdk/include/IL/il_wrap.h b/third_party/devil_sdk/include/IL/il_wrap.h new file mode 100644 index 0000000..5cf9b0e --- /dev/null +++ b/third_party/devil_sdk/include/IL/il_wrap.h @@ -0,0 +1,205 @@ +#ifndef WRAPPER_H +#define WRAPPER_H + +/*#include +#include */ +#include // Probably only have to #include this one + +#ifdef _MSC_VER + #ifndef _IL_WRAP_BUILD_LIB + #pragma comment(lib, "il_wrap.lib") + #endif +#endif + +class ilImage +{ +public: + ilImage(); + ilImage(char *); + ilImage(const ilImage &); + virtual ~ilImage(); + + ILboolean Load(char *); + ILboolean Load(char *, ILenum); + ILboolean Save(char *); + ILboolean Save(char *, ILenum); + + + // ImageLib functions + ILboolean ActiveImage(ILuint); + ILboolean ActiveLayer(ILuint); + ILboolean ActiveMipmap(ILuint); + ILboolean Clear(void); + ILvoid ClearColour(ILclampf, ILclampf, ILclampf, ILclampf); + ILboolean Convert(ILenum); + ILboolean Copy(ILuint); + ILboolean Default(void); + ILboolean Flip(void); + ILboolean SwapColours(void); + ILboolean Resize(ILuint, ILuint, ILuint); + ILboolean TexImage(ILuint, ILuint, ILuint, ILubyte, ILenum, ILenum, ILvoid*); + + + // Image handling + ILvoid Bind(void) const; + ILvoid Bind(ILuint); + ILvoid Close(void) { this->Delete(); } + ILvoid Delete(void); + ILvoid iGenBind(); + ILenum PaletteAlphaIndex(); + + // Image characteristics + ILuint Width(void); + ILuint Height(void); + ILuint Depth(void); + ILubyte Bpp(void); + ILubyte Bitpp(void); + ILenum PaletteType(void); + ILenum Format(void); + ILenum Type(void); + ILuint NumImages(void); + ILuint NumMipmaps(void); + ILuint GetId(void) const; + ILenum GetOrigin(void); + ILubyte *GetData(void); + ILubyte *GetPalette(void); + + + // Rendering + ILuint BindImage(void); + ILuint BindImage(ILenum); + + + // Operators + ilImage& operator = (ILuint); + ilImage& operator = (const ilImage &); + + +protected: + ILuint Id; + +private: + ILvoid iStartUp(); + + +}; + + +class ilFilters +{ +public: + static ILboolean Alienify(ilImage &); + static ILboolean BlurAvg(ilImage &, ILuint Iter); + static ILboolean BlurGaussian(ilImage &, ILuint Iter); + static ILboolean Contrast(ilImage &, ILfloat Contrast); + static ILboolean EdgeDetectE(ilImage &); + static ILboolean EdgeDetectP(ilImage &); + static ILboolean EdgeDetectS(ilImage &); + static ILboolean Emboss(ilImage &); + static ILboolean Gamma(ilImage &, ILfloat Gamma); + static ILboolean Negative(ilImage &); + static ILboolean Noisify(ilImage &, ILubyte Factor); + static ILboolean Pixelize(ilImage &, ILuint PixSize); + static ILboolean Saturate(ilImage &, ILfloat Saturation); + static ILboolean Saturate(ilImage &, ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation); + static ILboolean ScaleColours(ilImage &, ILfloat r, ILfloat g, ILfloat b); + static ILboolean Sharpen(ilImage &, ILfloat Factor, ILuint Iter); +}; + + +#ifdef ILUT_USE_OPENGL +class ilOgl +{ +public: + static ILvoid Init(void); + static GLuint BindTex(ilImage &); + static ILboolean Upload(ilImage &, ILuint); + static GLuint Mipmap(ilImage &); + static ILboolean Screen(void); + static ILboolean Screenie(void); +}; +#endif//ILUT_USE_OPENGL + + +#ifdef ILUT_USE_ALLEGRO +class ilAlleg +{ +public: + static ILvoid Init(void); + static BITMAP *Convert(ilImage &); +}; +#endif//ILUT_USE_ALLEGRO + + +#ifdef ILUT_USE_WIN32 +class ilWin32 +{ +public: + static ILvoid Init(void); + static HBITMAP Convert(ilImage &); + static ILboolean GetClipboard(ilImage &); + static ILvoid GetInfo(ilImage &, BITMAPINFO *Info); + static ILubyte *GetPadData(ilImage &); + static HPALETTE GetPal(ilImage &); + static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType); + static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType, ILenum Type); + static ILboolean SetClipboard(ilImage &); +}; +#endif//ILUT_USE_WIN32 + + +class ilValidate +{ +public: + static ILboolean Valid(ILenum, char *); + static ILboolean Valid(ILenum, FILE *); + static ILboolean Valid(ILenum, ILvoid *, ILuint); + +protected: + +private: + +}; + + +class ilState +{ +public: + static ILboolean Disable(ILenum); + static ILboolean Enable(ILenum); + static ILvoid Get(ILenum, ILboolean &); + static ILvoid Get(ILenum, ILint &); + static ILboolean GetBool(ILenum); + static ILint GetInt(ILenum); + static const char *GetString(ILenum); + static ILboolean IsDisabled(ILenum); + static ILboolean IsEnabled(ILenum); + static ILboolean Origin(ILenum); + static ILvoid Pop(void); + static ILvoid Push(ILuint); + + +protected: + +private: + +}; + + +class ilError +{ +public: + static ILvoid Check(ILvoid (*Callback)(const char*)); + static ILvoid Check(ILvoid (*Callback)(ILenum)); + static ILenum Get(void); + static const char *String(void); + static const char *String(ILenum); + +protected: + +private: + +}; + + +#endif//WRAPPER_H diff --git a/third_party/devil_sdk/include/IL/ilu.h b/third_party/devil_sdk/include/IL/ilu.h new file mode 100644 index 0000000..30d33a4 --- /dev/null +++ b/third_party/devil_sdk/include/IL/ilu.h @@ -0,0 +1,198 @@ +//----------------------------------------------------------------------------- +// +// ImageLib Utility Sources +// Copyright (C) 2000-2017 by Denton Woods +// Last modified: 03/07/2009 +// +// Filename: IL/ilu.h +// +// Description: The main include file for ILU +// +//----------------------------------------------------------------------------- + +// Doxygen comment +/*! \file ilu.h + The main include file for ILU +*/ + +#ifndef __ilu_h_ +#ifndef __ILU_H__ + +#define __ilu_h_ +#define __ILU_H__ + +#include "DevILSDK/include/IL/il.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef _WIN32 + #if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY)) + #if defined(_MSC_VER) || defined(__BORLANDC__) + #pragma comment(lib, "ILU.lib") + #endif + #endif +#endif + + +#define ILU_VERSION_1_8_0 1 +#define ILU_VERSION 180 + + +#define ILU_FILTER 0x2600 +#define ILU_NEAREST 0x2601 +#define ILU_LINEAR 0x2602 +#define ILU_BILINEAR 0x2603 +#define ILU_SCALE_BOX 0x2604 +#define ILU_SCALE_TRIANGLE 0x2605 +#define ILU_SCALE_BELL 0x2606 +#define ILU_SCALE_BSPLINE 0x2607 +#define ILU_SCALE_LANCZOS3 0x2608 +#define ILU_SCALE_MITCHELL 0x2609 + + +// Error types +#define ILU_INVALID_ENUM 0x0501 +#define ILU_OUT_OF_MEMORY 0x0502 +#define ILU_INTERNAL_ERROR 0x0504 +#define ILU_INVALID_VALUE 0x0505 +#define ILU_ILLEGAL_OPERATION 0x0506 +#define ILU_INVALID_PARAM 0x0509 + + +// Values +#define ILU_PLACEMENT 0x0700 +#define ILU_LOWER_LEFT 0x0701 +#define ILU_LOWER_RIGHT 0x0702 +#define ILU_UPPER_LEFT 0x0703 +#define ILU_UPPER_RIGHT 0x0704 +#define ILU_CENTER 0x0705 +#define ILU_CONVOLUTION_MATRIX 0x0710 + +#define ILU_VERSION_NUM IL_VERSION_NUM +#define ILU_VENDOR IL_VENDOR + + +// Languages +#define ILU_ENGLISH 0x0800 +#define ILU_ARABIC 0x0801 +#define ILU_DUTCH 0x0802 +#define ILU_JAPANESE 0x0803 +#define ILU_SPANISH 0x0804 +#define ILU_GERMAN 0x0805 +#define ILU_FRENCH 0x0806 +#define ILU_ITALIAN 0x0807 + + +// Filters +/* +#define ILU_FILTER_BLUR 0x0803 +#define ILU_FILTER_GAUSSIAN_3x3 0x0804 +#define ILU_FILTER_GAUSSIAN_5X5 0x0805 +#define ILU_FILTER_EMBOSS1 0x0807 +#define ILU_FILTER_EMBOSS2 0x0808 +#define ILU_FILTER_LAPLACIAN1 0x080A +#define ILU_FILTER_LAPLACIAN2 0x080B +#define ILU_FILTER_LAPLACIAN3 0x080C +#define ILU_FILTER_LAPLACIAN4 0x080D +#define ILU_FILTER_SHARPEN1 0x080E +#define ILU_FILTER_SHARPEN2 0x080F +#define ILU_FILTER_SHARPEN3 0x0810 +*/ + + +typedef struct ILinfo +{ + ILuint Id; // the image's id + ILubyte *Data; // the image's data + ILuint Width; // the image's width + ILuint Height; // the image's height + ILuint Depth; // the image's depth + ILubyte Bpp; // bytes per pixel (not bits) of the image + ILuint SizeOfData; // the total size of the data (in bytes) + ILenum Format; // image format (in IL enum style) + ILenum Type; // image type (in IL enum style) + ILenum Origin; // origin of the image + ILubyte *Palette; // the image's palette + ILenum PalType; // palette type + ILuint PalSize; // palette size + ILenum CubeFlags; // flags for what cube map sides are present + ILuint NumNext; // number of images following + ILuint NumMips; // number of mipmaps + ILuint NumLayers; // number of layers +} ILinfo; + + +typedef struct ILpointf { + ILfloat x; + ILfloat y; +} ILpointf; + +typedef struct ILpointi { + ILint x; + ILint y; +} ILpointi; + +ILAPI ILboolean ILAPIENTRY iluAlienify(void); +ILAPI ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter); +ILAPI ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter); +ILAPI ILboolean ILAPIENTRY iluBuildMipmaps(void); +ILAPI ILuint ILAPIENTRY iluColoursUsed(void); +ILAPI ILboolean ILAPIENTRY iluCompareImage(ILuint Comp); +ILAPI ILboolean ILAPIENTRY iluContrast(ILfloat Contrast); +ILAPI ILboolean ILAPIENTRY iluCrop(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth); +ILAPI void ILAPIENTRY iluDeleteImage(ILuint Id); // Deprecated +ILAPI ILboolean ILAPIENTRY iluEdgeDetectE(void); +ILAPI ILboolean ILAPIENTRY iluEdgeDetectP(void); +ILAPI ILboolean ILAPIENTRY iluEdgeDetectS(void); +ILAPI ILboolean ILAPIENTRY iluEmboss(void); +ILAPI ILboolean ILAPIENTRY iluEnlargeCanvas(ILuint Width, ILuint Height, ILuint Depth); +ILAPI ILboolean ILAPIENTRY iluEnlargeImage(ILfloat XDim, ILfloat YDim, ILfloat ZDim); +ILAPI ILboolean ILAPIENTRY iluEqualize(void); +ILAPI ILboolean ILAPIENTRY iluEqualize2(void); +ILAPI ILconst_string ILAPIENTRY iluErrorString(ILenum Error); +ILAPI ILboolean ILAPIENTRY iluConvolution(ILint *matrix, ILint scale, ILint bias); +ILAPI ILboolean ILAPIENTRY iluFlipImage(void); +ILAPI ILboolean ILAPIENTRY iluGammaCorrect(ILfloat Gamma); +ILAPI ILuint ILAPIENTRY iluGenImage(void); // Deprecated +ILAPI void ILAPIENTRY iluGetImageInfo(ILinfo *Info); +ILAPI ILint ILAPIENTRY iluGetInteger(ILenum Mode); +ILAPI void ILAPIENTRY iluGetIntegerv(ILenum Mode, ILint *Param); +ILAPI ILstring ILAPIENTRY iluGetString(ILenum StringName); +ILAPI void ILAPIENTRY iluImageParameter(ILenum PName, ILenum Param); +ILAPI void ILAPIENTRY iluInit(void); +ILAPI ILboolean ILAPIENTRY iluInvertAlpha(void); +ILAPI ILuint ILAPIENTRY iluLoadImage(ILconst_string FileName); +ILAPI ILboolean ILAPIENTRY iluMirror(void); +ILAPI ILboolean ILAPIENTRY iluNegative(void); +ILAPI ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance); +ILAPI ILboolean ILAPIENTRY iluPixelize(ILuint PixSize); +ILAPI void ILAPIENTRY iluRegionfv(ILpointf *Points, ILuint n); +ILAPI void ILAPIENTRY iluRegioniv(ILpointi *Points, ILuint n); +ILAPI ILboolean ILAPIENTRY iluReplaceColour(ILubyte Red, ILubyte Green, ILubyte Blue, ILfloat Tolerance); +ILAPI ILboolean ILAPIENTRY iluRotate(ILfloat Angle); +ILAPI ILboolean ILAPIENTRY iluRotate3D(ILfloat x, ILfloat y, ILfloat z, ILfloat Angle); +ILAPI ILboolean ILAPIENTRY iluSaturate1f(ILfloat Saturation); +ILAPI ILboolean ILAPIENTRY iluSaturate4f(ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation); +ILAPI ILboolean ILAPIENTRY iluScale(ILuint Width, ILuint Height, ILuint Depth); +ILAPI ILboolean ILAPIENTRY iluScaleAlpha(ILfloat scale); +ILAPI ILboolean ILAPIENTRY iluScaleColours(ILfloat r, ILfloat g, ILfloat b); +ILAPI ILboolean ILAPIENTRY iluSepia(void); +ILAPI ILboolean ILAPIENTRY iluSetLanguage(ILenum Language); +ILAPI ILboolean ILAPIENTRY iluSharpen(ILfloat Factor, ILuint Iter); +ILAPI ILboolean ILAPIENTRY iluSwapColours(void); +ILAPI ILboolean ILAPIENTRY iluWave(ILfloat Angle); + +#define iluColorsUsed iluColoursUsed +#define iluSwapColors iluSwapColours +#define iluReplaceColor iluReplaceColour +#define iluScaleColor iluScaleColour + +#ifdef __cplusplus +} +#endif + +#endif // __ILU_H__ +#endif // __ilu_h_ diff --git a/third_party/devil_sdk/include/IL/ilu_region.h b/third_party/devil_sdk/include/IL/ilu_region.h new file mode 100644 index 0000000..b5b3adc --- /dev/null +++ b/third_party/devil_sdk/include/IL/ilu_region.h @@ -0,0 +1,25 @@ +//----------------------------------------------------------------------------- +// +// ImageLib Utility Sources +// Copyright (C) 2000-2002 by Denton Woods +// Last modified: 07/09/2002 <--Y2K Compliant! =] +// +// Filename: src-ILU/src/ilu_region.h +// +// Description: Creates an image region. +// +//----------------------------------------------------------------------------- + +#ifndef ILU_REGION_H +#define ILU_REGION_H + +typedef struct Edge +{ + ILint yUpper; + ILfloat xIntersect, dxPerScan; + struct Edge *next; +} Edge; + + +#endif//ILU_REGION_H + diff --git a/third_party/devil_sdk/include/IL/ilut.h b/third_party/devil_sdk/include/IL/ilut.h new file mode 100644 index 0000000..8c1feda --- /dev/null +++ b/third_party/devil_sdk/include/IL/ilut.h @@ -0,0 +1,354 @@ +//----------------------------------------------------------------------------- +// +// ImageLib Utility Toolkit Sources +// Copyright (C) 2000-2017 by Denton Woods +// Last modified: 03/07/2009 +// +// Filename: IL/ilut.h +// +// Description: The main include file for ILUT +// +//----------------------------------------------------------------------------- + +// Doxygen comment +/*! \file ilut.h + The main include file for ILUT +*/ + +#ifndef __ilut_h_ +#ifndef __ILUT_H__ + +#define __ilut_h_ +#define __ILUT_H__ + +#include "DevILSDK/include/IL/il.h" +#include "DevILSDK/include/IL/ilu.h" + + +//----------------------------------------------------------------------------- +// Defines +//----------------------------------------------------------------------------- + +#define ILUT_VERSION_1_8_0 1 +#define ILUT_VERSION 180 + + +// Attribute Bits +#define ILUT_OPENGL_BIT 0x00000001 +#define ILUT_D3D_BIT 0x00000002 +#define ILUT_ALL_ATTRIB_BITS 0x000FFFFF + + +// Error Types +#define ILUT_INVALID_ENUM 0x0501 +#define ILUT_OUT_OF_MEMORY 0x0502 +#define ILUT_INVALID_VALUE 0x0505 +#define ILUT_ILLEGAL_OPERATION 0x0506 +#define ILUT_INVALID_PARAM 0x0509 +#define ILUT_COULD_NOT_OPEN_FILE 0x050A +#define ILUT_STACK_OVERFLOW 0x050E +#define ILUT_STACK_UNDERFLOW 0x050F +#define ILUT_BAD_DIMENSIONS 0x0511 +#define ILUT_NOT_SUPPORTED 0x0550 + + +// State Definitions +#define ILUT_PALETTE_MODE 0x0600 +#define ILUT_OPENGL_CONV 0x0610 +#define ILUT_D3D_MIPLEVELS 0x0620 +#define ILUT_MAXTEX_WIDTH 0x0630 +#define ILUT_MAXTEX_HEIGHT 0x0631 +#define ILUT_MAXTEX_DEPTH 0x0632 +#define ILUT_GL_USE_S3TC 0x0634 +#define ILUT_D3D_USE_DXTC 0x0634 +#define ILUT_GL_GEN_S3TC 0x0635 +#define ILUT_D3D_GEN_DXTC 0x0635 +#define ILUT_S3TC_FORMAT 0x0705 +#define ILUT_DXTC_FORMAT 0x0705 +#define ILUT_D3D_POOL 0x0706 +#define ILUT_D3D_ALPHA_KEY_COLOR 0x0707 +#define ILUT_D3D_ALPHA_KEY_COLOUR 0x0707 +#define ILUT_FORCE_INTEGER_FORMAT 0x0636 + +//This new state does automatic texture target detection +//if enabled. Currently, only cubemap detection is supported. +//if the current image is no cubemap, the 2d texture is chosen. +#define ILUT_GL_AUTODETECT_TEXTURE_TARGET 0x0807 + + +// Values +#define ILUT_VERSION_NUM IL_VERSION_NUM +#define ILUT_VENDOR IL_VENDOR + +// The different rendering api's...more to be added later? +#define ILUT_OPENGL 0 +#define ILUT_ALLEGRO 1 +#define ILUT_WIN32 2 +#define ILUT_DIRECT3D8 3 +#define ILUT_DIRECT3D9 4 +#define ILUT_X11 5 +#define ILUT_DIRECT3D10 6 + + +#if (defined(_WIN32) || defined(_WIN64)) + #if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY)) + #if defined(_MSC_VER) || defined(__BORLANDC__) + #pragma comment(lib, "ILUT.lib") + #endif + #endif + + #include +#endif + + + + +////////////// +// OpenGL +////////////// + +#ifdef ILUT_USE_OPENGL + #if defined(_MSC_VER) || defined(_WIN32) + //#define WIN32_LEAN_AND_MEAN + #include + #endif//_MSC_VER + + #ifdef __APPLE__ + #include + #include + #else + #include + #include + #endif//__APPLE__ +#endif + + +#ifdef ILUT_USE_WIN32 + //#define WIN32_LEAN_AND_MEAN + #ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #ifndef _WIN32_WCE + #include + #endif + #endif + #include +#endif + + +// +// If we can avoid including these in all cases thing tend to break less +// and we can keep all of them defined as available +// +// Kriss +// + +// ImageLib Utility Toolkit's Allegro Functions +#ifdef ILUT_USE_ALLEGRO +// #include +#endif//ILUT_USE_ALLEGRO + +#ifdef ILUT_USE_SDL +// #include +#endif + +#ifdef ILUT_USE_DIRECTX8 + #include +#endif//ILUT_USE_DIRECTX9 + +#ifdef ILUT_USE_DIRECTX9 + #include +#endif//ILUT_USE_DIRECTX9 + +#ifdef ILUT_USE_DIRECTX10 + #pragma warning(push) + #pragma warning(disable : 4201) // Disables 'nonstandard extension used : nameless struct/union' warning + #include + #include + #include + #pragma warning(pop) +#endif//ILUT_USE_DIRECTX10 + +#ifdef ILUT_USE_X11 + #include + #include +#ifdef ILUT_USE_XSHM + #include + #include + #include +#endif//ILUT_USE_XSHM +#endif//ILUT_USE_X11 + + + +//----------------------------------------------------------------------------- +// Functions +//----------------------------------------------------------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +// ImageLib Utility Toolkit Functions +ILAPI ILboolean ILAPIENTRY ilutDisable(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilutEnable(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilutGetBoolean(ILenum Mode); +ILAPI void ILAPIENTRY ilutGetBooleanv(ILenum Mode, ILboolean *Param); +ILAPI ILint ILAPIENTRY ilutGetInteger(ILenum Mode); +ILAPI void ILAPIENTRY ilutGetIntegerv(ILenum Mode, ILint *Param); +ILAPI ILstring ILAPIENTRY ilutGetString(ILenum StringName); +ILAPI void ILAPIENTRY ilutInit(void); +ILAPI ILboolean ILAPIENTRY ilutIsDisabled(ILenum Mode); +ILAPI ILboolean ILAPIENTRY ilutIsEnabled(ILenum Mode); +ILAPI void ILAPIENTRY ilutPopAttrib(void); +ILAPI void ILAPIENTRY ilutPushAttrib(ILuint Bits); +ILAPI void ILAPIENTRY ilutSetInteger(ILenum Mode, ILint Param); + +ILAPI ILboolean ILAPIENTRY ilutRenderer(ILenum Renderer); + + +// ImageLib Utility Toolkit's OpenGL Functions +#ifdef ILUT_USE_OPENGL + ILAPI GLuint ILAPIENTRY ilutGLBindTexImage(); + ILAPI GLuint ILAPIENTRY ilutGLBindMipmaps(void); + ILAPI ILboolean ILAPIENTRY ilutGLBuildMipmaps(void); + ILAPI GLuint ILAPIENTRY ilutGLLoadImage(ILstring FileName); + ILAPI ILboolean ILAPIENTRY ilutGLScreen(void); + ILAPI ILboolean ILAPIENTRY ilutGLScreenie(void); + ILAPI ILboolean ILAPIENTRY ilutGLSaveImage(ILstring FileName, GLuint TexID); + ILAPI ILboolean ILAPIENTRY ilutGLSubTex2D(GLuint TexID, ILuint XOff, ILuint YOff); + ILAPI ILboolean ILAPIENTRY ilutGLSubTex3D(GLuint TexID, ILuint XOff, ILuint YOff, ILuint ZOff); + ILAPI ILboolean ILAPIENTRY ilutGLSetTex2D(GLuint TexID); + ILAPI ILboolean ILAPIENTRY ilutGLSetTex3D(GLuint TexID); + ILAPI ILboolean ILAPIENTRY ilutGLTexImage(GLuint Level); + ILAPI ILboolean ILAPIENTRY ilutGLSubTex(GLuint TexID, ILuint XOff, ILuint YOff); + + ILAPI ILboolean ILAPIENTRY ilutGLSetTex(GLuint TexID); // Deprecated - use ilutGLSetTex2D. + ILAPI ILboolean ILAPIENTRY ilutGLSubTex(GLuint TexID, ILuint XOff, ILuint YOff); // Use ilutGLSubTex2D. +#endif//ILUT_USE_OPENGL + + +// ImageLib Utility Toolkit's Allegro Functions +#ifdef ILUT_USE_ALLEGRO + #ifdef __cplusplus + extern "C" { + #endif + #include + #ifdef __cplusplus + } + #endif + + ILAPI BITMAP* ILAPIENTRY ilutAllegLoadImage(ILstring FileName); + ILAPI BITMAP* ILAPIENTRY ilutConvertToAlleg(PALETTE Pal); +#endif//ILUT_USE_ALLEGRO + + +// ImageLib Utility Toolkit's SDL Functions +#ifdef ILUT_USE_SDL + ILAPI struct SDL_Surface* ILAPIENTRY ilutConvertToSDLSurface(unsigned int flags); + ILAPI struct SDL_Surface* ILAPIENTRY ilutSDLSurfaceLoadImage(ILstring FileName); + ILAPI ILboolean ILAPIENTRY ilutSDLSurfaceFromBitmap(struct SDL_Surface *Bitmap); +#endif//ILUT_USE_SDL + + +// ImageLib Utility Toolkit's BeOS Functions +#ifdef ILUT_USE_BEOS + ILAPI BBitmap ILAPIENTRY ilutConvertToBBitmap(void); +#endif//ILUT_USE_BEOS + + +// ImageLib Utility Toolkit's Win32 GDI Functions +#ifdef ILUT_USE_WIN32 + ILAPI HBITMAP ILAPIENTRY ilutConvertToHBitmap(HDC hDC); + ILAPI HBITMAP ILAPIENTRY ilutConvertSliceToHBitmap(HDC hDC, ILuint slice); + ILAPI void ILAPIENTRY ilutFreePaddedData(ILubyte *Data); + ILAPI void ILAPIENTRY ilutGetBmpInfo(BITMAPINFO *Info); + ILAPI HPALETTE ILAPIENTRY ilutGetHPal(void); + ILAPI ILubyte* ILAPIENTRY ilutGetPaddedData(void); + ILAPI ILboolean ILAPIENTRY ilutGetWinClipboard(void); + ILAPI ILboolean ILAPIENTRY ilutLoadResource(HINSTANCE hInst, ILint ID, ILstring ResourceType, ILenum Type); + ILAPI ILboolean ILAPIENTRY ilutSetHBitmap(HBITMAP Bitmap); + ILAPI ILboolean ILAPIENTRY ilutSetHPal(HPALETTE Pal); + ILAPI ILboolean ILAPIENTRY ilutSetWinClipboard(void); + ILAPI HBITMAP ILAPIENTRY ilutWinLoadImage(ILstring FileName, HDC hDC); + ILAPI ILboolean ILAPIENTRY ilutWinLoadUrl(ILstring Url); + ILAPI ILboolean ILAPIENTRY ilutWinPrint(ILuint XPos, ILuint YPos, ILuint Width, ILuint Height, HDC hDC); + ILAPI ILboolean ILAPIENTRY ilutWinSaveImage(ILstring FileName, HBITMAP Bitmap); +#endif//ILUT_USE_WIN32 + +// ImageLib Utility Toolkit's DirectX 8 Functions +#ifdef ILUT_USE_DIRECTX8 +// ILAPI void ILAPIENTRY ilutD3D8MipFunc(ILuint NumLevels); + ILAPI struct IDirect3DTexture8* ILAPIENTRY ilutD3D8Texture(struct IDirect3DDevice8 *Device); + ILAPI struct IDirect3DVolumeTexture8* ILAPIENTRY ilutD3D8VolumeTexture(struct IDirect3DDevice8 *Device); + ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFile(struct IDirect3DDevice8 *Device, char *FileName, struct IDirect3DTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFile(struct IDirect3DDevice8 *Device, char *FileName, struct IDirect3DVolumeTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFileInMemory(struct IDirect3DDevice8 *Device, void *Lump, ILuint Size, struct IDirect3DTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFileInMemory(struct IDirect3DDevice8 *Device, void *Lump, ILuint Size, struct IDirect3DVolumeTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFileHandle(struct IDirect3DDevice8 *Device, ILHANDLE File, struct IDirect3DTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFileHandle(struct IDirect3DDevice8 *Device, ILHANDLE File, struct IDirect3DVolumeTexture8 **Texture); + // These two are not tested yet. + ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromResource(struct IDirect3DDevice8 *Device, HMODULE SrcModule, char *SrcResource, struct IDirect3DTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromResource(struct IDirect3DDevice8 *Device, HMODULE SrcModule, char *SrcResource, struct IDirect3DVolumeTexture8 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D8LoadSurface(struct IDirect3DDevice8 *Device, struct IDirect3DSurface8 *Surface); +#endif//ILUT_USE_DIRECTX8 + +#ifdef ILUT_USE_DIRECTX9 + #pragma warning(push) + #pragma warning(disable : 4115) // Disables 'named type definition in parentheses' warning +// ILAPI void ILAPIENTRY ilutD3D9MipFunc(ILuint NumLevels); + ILAPI struct IDirect3DTexture9* ILAPIENTRY ilutD3D9Texture (struct IDirect3DDevice9* Device); + ILAPI struct IDirect3DVolumeTexture9* ILAPIENTRY ilutD3D9VolumeTexture (struct IDirect3DDevice9* Device); + ILAPI struct IDirect3DCubeTexture9* ILAPIENTRY ilutD3D9CubeTexture (struct IDirect3DDevice9* Device); + + ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DCubeTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DCubeTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DCubeTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DCubeTexture9 **Texture); + + ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DVolumeTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DVolumeTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DVolumeTexture9 **Texture); + + // These three are not tested yet. + ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DVolumeTexture9 **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D9LoadSurface(struct IDirect3DDevice9 *Device, struct IDirect3DSurface9 *Surface); + #pragma warning(pop) +#endif//ILUT_USE_DIRECTX9 + +#ifdef ILUT_USE_DIRECTX10 + ILAPI ID3D10Texture2D* ILAPIENTRY ilutD3D10Texture(ID3D10Device *Device); + ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFile(ID3D10Device *Device, ILconst_string FileName, ID3D10Texture2D **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFileInMemory(ID3D10Device *Device, void *Lump, ILuint Size, ID3D10Texture2D **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromResource(ID3D10Device *Device, HMODULE SrcModule, ILconst_string SrcResource, ID3D10Texture2D **Texture); + ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFileHandle(ID3D10Device *Device, ILHANDLE File, ID3D10Texture2D **Texture); +#endif//ILUT_USE_DIRECTX10 + + + +#ifdef ILUT_USE_X11 + ILAPI XImage * ILAPIENTRY ilutXCreateImage( Display* ); + ILAPI Pixmap ILAPIENTRY ilutXCreatePixmap( Display*,Drawable ); + ILAPI XImage * ILAPIENTRY ilutXLoadImage( Display*,char* ); + ILAPI Pixmap ILAPIENTRY ilutXLoadPixmap( Display*,Drawable,char* ); +#ifdef ILUT_USE_XSHM + ILAPI XImage * ILAPIENTRY ilutXShmCreateImage( Display*,XShmSegmentInfo* ); + ILAPI void ILAPIENTRY ilutXShmDestroyImage( Display*,XImage*,XShmSegmentInfo* ); + ILAPI Pixmap ILAPIENTRY ilutXShmCreatePixmap( Display*,Drawable,XShmSegmentInfo* ); + ILAPI void ILAPIENTRY ilutXShmFreePixmap( Display*,Pixmap,XShmSegmentInfo* ); + ILAPI XImage * ILAPIENTRY ilutXShmLoadImage( Display*,char*,XShmSegmentInfo* ); + ILAPI Pixmap ILAPIENTRY ilutXShmLoadPixmap( Display*,Drawable,char*,XShmSegmentInfo* ); +#endif//ILUT_USE_XSHM +#endif//ILUT_USE_X11 + + +#ifdef __cplusplus +} +#endif + +#endif // __ILUT_H__ +#endif // __ilut_h_ diff --git a/third_party/devil_sdk/include/IL/ilut_config.h b/third_party/devil_sdk/include/IL/ilut_config.h new file mode 100644 index 0000000..8b187a4 --- /dev/null +++ b/third_party/devil_sdk/include/IL/ilut_config.h @@ -0,0 +1,26 @@ +#ifndef __ILUT_CONFIG_H__ +#define __ILUT_CONFIG_H__ + +//#define IL_USE_PRAGMA_LIBS + +// Supported APIs (ILUT) + +// +// sorry just +// cant get this one to work under windows +// have disabled for the now +// +// will look at it some more later +// +// Kriss +// +#undef ILUT_USE_ALLEGRO + +#undef ILUT_USE_DIRECTX8 +//#define ILUT_USE_DIRECTX9 +//#define ILUT_USE_DIRECTX10 +#define ILUT_USE_OPENGL +//#define ILUT_USE_SDL +#define ILUT_USE_WIN32 + +#endif//__ILUT_CONFIG_H__ diff --git a/third_party/devil_sdk/include/IL/luadevil.c b/third_party/devil_sdk/include/IL/luadevil.c new file mode 100644 index 0000000..1094e1a --- /dev/null +++ b/third_party/devil_sdk/include/IL/luadevil.c @@ -0,0 +1,393 @@ +/* +** $Id: luadevil.c,v 1.1 2007-02-12 21:03:04 darkyojimbo Exp $ +** Lua stand-alone interpreter +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include +#include + +#define lua_c + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static lua_State *globalL = NULL; + +static const char *progname = LUA_PROGNAME; + + + +static void lstop (lua_State *L, lua_Debug *ar) { + (void)ar; /* unused arg. */ + lua_sethook(L, NULL, 0, 0); + luaL_error(L, "interrupted!"); +} + + +static void laction (int i) { + signal(i, SIG_DFL); /* if another SIGINT happens before lstop, + terminate process (default action) */ + lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +} + + +static void print_usage (void) { + fprintf(stderr, + "usage: %s [options] [script [args]].\n" + "Available options are:\n" + " -e stat execute string " LUA_QL("stat") "\n" + " -l name require library " LUA_QL("name") "\n" + " -i enter interactive mode after executing " LUA_QL("script") "\n" + " -v show version information\n" + " -- stop handling options\n" + " - execute stdin and stop handling options\n" + , + progname); + fflush(stderr); +} + + +static void l_message (const char *pname, const char *msg) { + if (pname) fprintf(stderr, "%s: ", pname); + fprintf(stderr, "%s\n", msg); + fflush(stderr); +} + + +static int report (lua_State *L, int status) { + if (status && !lua_isnil(L, -1)) { + const char *msg = lua_tostring(L, -1); + if (msg == NULL) msg = "(error object is not a string)"; + l_message(progname, msg); + lua_pop(L, 1); + } + return status; +} + + +static int traceback (lua_State *L) { + lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + return 1; + } + lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + lua_pop(L, 2); + return 1; + } + lua_pushvalue(L, 1); /* pass error message */ + lua_pushinteger(L, 2); /* skip this function and traceback */ + lua_call(L, 2, 1); /* call debug.traceback */ + return 1; +} + + +static int docall (lua_State *L, int narg, int clear) { + int status; + int base = lua_gettop(L) - narg; /* function index */ + lua_pushcfunction(L, traceback); /* push traceback function */ + lua_insert(L, base); /* put it under chunk and args */ + signal(SIGINT, laction); + status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); + signal(SIGINT, SIG_DFL); + lua_remove(L, base); /* remove traceback function */ + /* force a complete garbage collection in case of errors */ + if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); + return status; +} + + +static void print_version (void) { + l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT); +} + + +static int getargs (lua_State *L, char **argv, int n) { + int narg; + int i; + int argc = 0; + while (argv[argc]) argc++; /* count total number of arguments */ + narg = argc - (n + 1); /* number of arguments to the script */ + luaL_checkstack(L, narg + 3, "too many arguments to script"); + for (i=n+1; i < argc; i++) + lua_pushstring(L, argv[i]); + lua_createtable(L, narg, n + 1); + for (i=0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i - n); + } + return narg; +} + + +static int dofile (lua_State *L, const char *name) { + int status = luaL_loadfile(L, name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dostring (lua_State *L, const char *s, const char *name) { + int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); + return report(L, status); +} + + +static int dolibrary (lua_State *L, const char *name) { + lua_getglobal(L, "require"); + lua_pushstring(L, name); + return report(L, lua_pcall(L, 1, 0, 0)); +} + + +static const char *get_prompt (lua_State *L, int firstline) { + const char *p; + lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); + p = lua_tostring(L, -1); + if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); + lua_pop(L, 1); /* remove global */ + return p; +} + + +static int incomplete (lua_State *L, int status) { + if (status == LUA_ERRSYNTAX) { + size_t lmsg; + const char *msg = lua_tolstring(L, -1, &lmsg); + const char *tp = msg + lmsg - (sizeof(LUA_QL("")) - 1); + if (strstr(msg, LUA_QL("")) == tp) { + lua_pop(L, 1); + return 1; + } + } + return 0; /* else... */ +} + + +static int pushline (lua_State *L, int firstline) { + char buffer[LUA_MAXINPUT]; + char *b = buffer; + size_t l; + const char *prmt = get_prompt(L, firstline); + if (lua_readline(L, b, prmt) == 0) + return 0; /* no input */ + l = strlen(b); + if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ + b[l-1] = '\0'; /* remove it */ + if (firstline && b[0] == '=') /* first line starts with `=' ? */ + lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ + else + lua_pushstring(L, b); + lua_freeline(L, b); + return 1; +} + + +static int loadline (lua_State *L) { + int status; + lua_settop(L, 0); + if (!pushline(L, 1)) + return -1; /* no input */ + for (;;) { /* repeat until gets a complete line */ + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + if (!incomplete(L, status)) break; /* cannot try to add lines? */ + if (!pushline(L, 0)) /* no more input? */ + return -1; + lua_pushliteral(L, "\n"); /* add a new line... */ + lua_insert(L, -2); /* ...between the two lines */ + lua_concat(L, 3); /* join them */ + } + lua_saveline(L, 1); + lua_remove(L, 1); /* remove line */ + return status; +} + + +static void dotty (lua_State *L) { + int status; + const char *oldprogname = progname; + progname = NULL; + while ((status = loadline(L)) != -1) { + if (status == 0) status = docall(L, 0, 0); + report(L, status); + if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ + lua_getglobal(L, "print"); + lua_insert(L, 1); + if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) + l_message(progname, lua_pushfstring(L, + "error calling " LUA_QL("print") " (%s)", + lua_tostring(L, -1))); + } + } + lua_settop(L, 0); /* clear stack */ + fputs("\n", stdout); + fflush(stdout); + progname = oldprogname; +} + + +static int handle_script (lua_State *L, char **argv, int n) { + int status; + const char *fname; + int narg = getargs(L, argv, n); /* collect arguments */ + lua_setglobal(L, "arg"); + fname = argv[n]; + if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) + fname = NULL; /* stdin */ + status = luaL_loadfile(L, fname); + lua_insert(L, -(narg+1)); + if (status == 0) + status = docall(L, narg, 0); + else + lua_pop(L, narg); + return report(L, status); +} + + +/* check that argument has no extra characters at the end */ +#define notail(x) {if ((x)[2] != '\0') return -1;} + + +static int collectargs (char **argv, int *pi, int *pv, int *pe) { + int i; + for (i = 1; argv[i] != NULL; i++) { + if (argv[i][0] != '-') /* not an option? */ + return i; + switch (argv[i][1]) { /* option */ + case '-': + notail(argv[i]); + return (argv[i+1] != NULL ? i+1 : 0); + case '\0': + return i; + case 'i': + notail(argv[i]); + *pi = 1; /* go through */ + case 'v': + notail(argv[i]); + *pv = 1; + break; + case 'e': + *pe = 1; /* go through */ + case 'l': + if (argv[i][2] == '\0') { + i++; + if (argv[i] == NULL) return -1; + } + break; + default: return -1; /* invalid option */ + } + } + return 0; +} + + +static int runargs (lua_State *L, char **argv, int n) { + int i; + for (i = 1; i < n; i++) { + if (argv[i] == NULL) continue; + lua_assert(argv[i][0] == '-'); + switch (argv[i][1]) { /* option */ + case 'e': { + const char *chunk = argv[i] + 2; + if (*chunk == '\0') chunk = argv[++i]; + lua_assert(chunk != NULL); + if (dostring(L, chunk, "=(command line)") != 0) + return 1; + break; + } + case 'l': { + const char *filename = argv[i] + 2; + if (*filename == '\0') filename = argv[++i]; + lua_assert(filename != NULL); + if (dolibrary(L, filename)) + return 1; /* stop if file fails */ + break; + } + default: break; + } + } + return 0; +} + + +static int handle_luainit (lua_State *L) { + const char *init = getenv(LUA_INIT); + if (init == NULL) return 0; /* status OK */ + else if (init[0] == '@') + return dofile(L, init+1); + else + return dostring(L, init, "=" LUA_INIT); +} + + +struct Smain { + int argc; + char **argv; + int status; +}; + + +static int pmain (lua_State *L) { + struct Smain *s = (struct Smain *)lua_touserdata(L, 1); + char **argv = s->argv; + int script; + int has_i = 0, has_v = 0, has_e = 0; + globalL = L; + if (argv[0] && argv[0][0]) progname = argv[0]; + lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ + luaL_openlibs(L); /* open libraries */ + lua_gc(L, LUA_GCRESTART, 0); + s->status = handle_luainit(L); + if (s->status != 0) return 0; + script = collectargs(argv, &has_i, &has_v, &has_e); + if (script < 0) { /* invalid args? */ + print_usage(); + s->status = 1; + return 0; + } + if (has_v) print_version(); + s->status = runargs(L, argv, (script > 0) ? script : s->argc); + if (s->status != 0) return 0; + if (script) + s->status = handle_script(L, argv, script); + if (s->status != 0) return 0; + if (has_i) + dotty(L); + else if (script == 0 && !has_e && !has_v) { + if (lua_stdin_is_tty()) { + print_version(); + dotty(L); + } + else dofile(L, NULL); /* executes stdin as a file */ + } + return 0; +} + + +int main (int argc, char **argv) { + int status; + struct Smain s; + lua_State *L = lua_open(); /* create state */ + printf("DevIL embedded lua interpreter\n"); +//@TODO: Where the heck is this defined? + //Devil_Init(L); + if (L == NULL) { + l_message(argv[0], "cannot create state: not enough memory"); + return EXIT_FAILURE; + } + s.argc = argc; + s.argv = argv; + status = lua_cpcall(L, &pmain, &s); + report(L, status); + lua_close(L); + return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/third_party/devil_sdk/include/IL/stamp-h.in b/third_party/devil_sdk/include/IL/stamp-h.in new file mode 100644 index 0000000..9788f70 --- /dev/null +++ b/third_party/devil_sdk/include/IL/stamp-h.in @@ -0,0 +1 @@ +timestamp diff --git a/third_party/devil_sdk/lib/DevIL.dll b/third_party/devil_sdk/lib/DevIL.dll new file mode 100644 index 0000000..51b3450 Binary files /dev/null and b/third_party/devil_sdk/lib/DevIL.dll differ diff --git a/third_party/devil_sdk/lib/DevIL.lib b/third_party/devil_sdk/lib/DevIL.lib new file mode 100644 index 0000000..504d364 Binary files /dev/null and b/third_party/devil_sdk/lib/DevIL.lib differ diff --git a/third_party/devil_sdk/lib/ILU.dll b/third_party/devil_sdk/lib/ILU.dll new file mode 100644 index 0000000..5959615 Binary files /dev/null and b/third_party/devil_sdk/lib/ILU.dll differ diff --git a/third_party/devil_sdk/lib/ILU.lib b/third_party/devil_sdk/lib/ILU.lib new file mode 100644 index 0000000..bc44ef7 Binary files /dev/null and b/third_party/devil_sdk/lib/ILU.lib differ diff --git a/third_party/devil_sdk/lib/ILUT.dll b/third_party/devil_sdk/lib/ILUT.dll new file mode 100644 index 0000000..4eaafcb Binary files /dev/null and b/third_party/devil_sdk/lib/ILUT.dll differ diff --git a/third_party/devil_sdk/lib/ILUT.lib b/third_party/devil_sdk/lib/ILUT.lib new file mode 100644 index 0000000..6bb2aad Binary files /dev/null and b/third_party/devil_sdk/lib/ILUT.lib differ diff --git a/third_party/xbox_sdk/include/NuiTools.h b/third_party/xbox_sdk/include/NuiTools.h new file mode 100644 index 0000000..4f019a8 --- /dev/null +++ b/third_party/xbox_sdk/include/NuiTools.h @@ -0,0 +1,291 @@ +/************************************************************************ +* * +* NuiTools.h -- This module aggregates all the Natural User * +* Interface(NUI) API structures and definitions * +* needed by Windows based NUI tools. * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +// +// Define NUI error codes derived from win32 errors +// + +#define E_NUI_DEVICE_NOT_CONNECTED __HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_CONNECTED) +#define E_NUI_DEVICE_NOT_READY __HRESULT_FROM_WIN32(ERROR_NOT_READY) +#define E_NUI_ALREADY_INITIALIZED __HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED) +#define E_NUI_IDENTITY_BUSY __HRESULT_FROM_WIN32(ERROR_BUSY) +#define E_NUI_NO_MORE_ITEMS __HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) +#define E_NUI_NOACCESS __HRESULT_FROM_WIN32(ERROR_NOACCESS) +#define E_NUI_NOT_FOUND __HRESULT_FROM_WIN32(ERROR_NOT_FOUND) + +// +// Define NUI specific error codes +// + +#define FACILITY_NUI 0x301 +#define E_NUI_FRAME_NO_DATA MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 1) +#define E_NUI_STREAM_NOT_ENABLED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 2) +#define E_NUI_IMAGE_STREAM_IN_USE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 3) +#define E_NUI_FRAME_LIMIT_EXCEEDED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 4) +#define E_NUI_FEATURE_NOT_INITIALIZED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 5) +#define E_NUI_IDENTITY_ENROLLMENT_LIMIT MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 6) +#define E_NUI_IDENTITY_UI_REQUIRED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 7) +#define E_NUI_IDENTITY_LOST_TRACK MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 8) +#define E_NUI_IDENTITY_QUALITY_ISSUE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 9) +#define E_NUI_IDENTITY_NO_UNENROLL_SIGN_IN MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 10) +#define E_NUI_SYSTEM_UI_PRESENT MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 11) +#define E_NUI_MUST_CALL_IDENTIFY MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 12) +#define E_NUI_DATABASE_NOT_FOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 13) +#define E_NUI_DATABASE_VERSION_MISMATCH MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 14) +#define E_NUI_DATABASE_CORRUPTED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 15) +#define E_NUI_TRACKED_PLAYER_LIMIT_EXCEEDED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 16) +#define E_NUI_TRACKING_ID_IN_USE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 17) +#define E_NUI_LOST_TRACKING MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 18) +#define E_NUI_GESTURE_NOT_INITIALIZED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 19) +#define E_NUI_GESTURE_ALREADY_INITIALIZED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 20) +#define E_NUI_NOT_LIVE_USER MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 21) +#define E_NUI_LIVE_USER_NOT_LOGGED_IN MAKE_HRESULT(SEVERITY_ERROR, FACILITY_NUI, 22) + +// NOTE: Error codes in the range 100-199 associated with FACILITY_NUI are +// assigned to the NUI Handles API subsystem of NUI. See NuiHandles.h for +// details on those error codes. + +typedef enum _NUI_IMAGE_TYPE +{ + NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX = 0, + NUI_IMAGE_TYPE_COLOR, + NUI_IMAGE_TYPE_COLOR_YUV, + NUI_IMAGE_TYPE_DEPTH, + NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX_IN_COLOR_SPACE, + NUI_IMAGE_TYPE_DEPTH_IN_COLOR_SPACE, + NUI_IMAGE_TYPE_COLOR_IN_DEPTH_SPACE, + NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX_80x60, + NUI_IMAGE_TYPE_DEPTH_80x60, +} NUI_IMAGE_TYPE; + +typedef enum _NUI_IMAGE_RESOLUTION +{ + NUI_IMAGE_RESOLUTION_80x60, + NUI_IMAGE_RESOLUTION_320x240, + NUI_IMAGE_RESOLUTION_640x480 +} NUI_IMAGE_RESOLUTION; + +#define NUI_IMAGE_PLAYER_INDEX_SHIFT 3 +#define NUI_IMAGE_PLAYER_INDEX_MASK ((1 << NUI_IMAGE_PLAYER_INDEX_SHIFT)-1) +#define NUI_IMAGE_DEPTH_MAXIMUM ((4000 << NUI_IMAGE_PLAYER_INDEX_SHIFT) | NUI_IMAGE_PLAYER_INDEX_MASK) +#define NUI_IMAGE_DEPTH_MINIMUM (800 << NUI_IMAGE_PLAYER_INDEX_SHIFT) +#define NUI_IMAGE_DEPTH_NO_VALUE 0 +#define NUI_IMAGE_DEPTH_BUFFER_SIZE (384*240*2) +#define NUI_IMAGE_DEPTH_80x60_BUFFER_SIZE (128*60*2) +#define NUI_IMAGE_COLOR_640x480_BUFFER_SIZE (640*480*4) +#define NUI_IMAGE_COLOR_YUV_640x480_BUFFER_SIZE (640*480*2) + +#define NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS (285.63f) // Based on 320x240 pixel size. +#define NUI_CAMERA_DEPTH_NOMINAL_INVERSE_FOCAL_LENGTH_IN_PIXELS (3.501e-3f) // (1/NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS) +#define NUI_CAMERA_DEPTH_NOMINAL_DIAGONAL_FOV (70.0f) +#define NUI_CAMERA_DEPTH_NOMINAL_HORIZONTAL_FOV (58.5f) +#define NUI_CAMERA_DEPTH_NOMINAL_VERTICAL_FOV (45.6f) + +#define NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS (531.15f) // Based on 640x480 pixel size. +#define NUI_CAMERA_COLOR_NOMINAL_INVERSE_FOCAL_LENGTH_IN_PIXELS (1.83e-3f) // (1/NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS) +#define NUI_CAMERA_COLOR_NOMINAL_DIAGONAL_FOV ( 73.9f) +#define NUI_CAMERA_COLOR_NOMINAL_HORIZONTAL_FOV ( 62.0f) +#define NUI_CAMERA_COLOR_NOMINAL_VERTICAL_FOV ( 48.6f) + +typedef enum _NUI_IMAGE_DIGITALZOOM +{ + NUI_IMAGE_DIGITAL_ZOOM_1X = 0, + NUI_IMAGE_DIGITAL_ZOOM_2X = 1 +} NUI_IMAGE_DIGITALZOOM; +typedef struct _NUI_IMAGE_VIEW_AREA +{ + NUI_IMAGE_DIGITALZOOM eDigitalZoom; + LONG lCenterX; + LONG lCenterY; +} NUI_IMAGE_VIEW_AREA; +typedef enum _NUI_SKELETON_POSITION_INDEX +{ + NUI_SKELETON_POSITION_HIP_CENTER = 0, + NUI_SKELETON_POSITION_SPINE, + NUI_SKELETON_POSITION_SHOULDER_CENTER, + NUI_SKELETON_POSITION_HEAD, + NUI_SKELETON_POSITION_SHOULDER_LEFT, + NUI_SKELETON_POSITION_ELBOW_LEFT, + NUI_SKELETON_POSITION_WRIST_LEFT, + NUI_SKELETON_POSITION_HAND_LEFT, + NUI_SKELETON_POSITION_SHOULDER_RIGHT, + NUI_SKELETON_POSITION_ELBOW_RIGHT, + NUI_SKELETON_POSITION_WRIST_RIGHT, + NUI_SKELETON_POSITION_HAND_RIGHT, + NUI_SKELETON_POSITION_HIP_LEFT, + NUI_SKELETON_POSITION_KNEE_LEFT, + NUI_SKELETON_POSITION_ANKLE_LEFT, + NUI_SKELETON_POSITION_FOOT_LEFT, + NUI_SKELETON_POSITION_HIP_RIGHT, + NUI_SKELETON_POSITION_KNEE_RIGHT, + NUI_SKELETON_POSITION_ANKLE_RIGHT, + NUI_SKELETON_POSITION_FOOT_RIGHT, + NUI_SKELETON_POSITION_COUNT +} NUI_SKELETON_POSITION_INDEX; + +// +// Number of NUI_SKELETON_DATA elements in NUI_SKELETON_FRAME +// + +#define NUI_SKELETON_COUNT 6 + +// +// Number of NUI_SKELETON_DATA elements that can be in the NUI_SKELETON_TRACKED state +// + +#define NUI_SKELETON_MAX_TRACKED_COUNT 2 + +// +// Tracking IDs start at 1 +// + +#define NUI_SKELETON_INVALID_TRACKING_ID 0 + +typedef enum _NUI_SKELETON_POSITION_TRACKING_STATE +{ + NUI_SKELETON_POSITION_NOT_TRACKED = 0, + NUI_SKELETON_POSITION_INFERRED, + NUI_SKELETON_POSITION_TRACKED +} NUI_SKELETON_POSITION_TRACKING_STATE; + +typedef enum _NUI_SKELETON_TRACKING_STATE +{ + NUI_SKELETON_NOT_TRACKED = 0, + NUI_SKELETON_POSITION_ONLY, + NUI_SKELETON_TRACKED +} NUI_SKELETON_TRACKING_STATE; + +typedef struct _NUI_SKELETON_DATA +{ + NUI_SKELETON_TRACKING_STATE eTrackingState; + DWORD dwTrackingID; + DWORD dwEnrollmentIndex; + DWORD dwUserIndex; + XMVECTOR Position; + XMVECTOR SkeletonPositions[NUI_SKELETON_POSITION_COUNT]; + NUI_SKELETON_POSITION_TRACKING_STATE eSkeletonPositionTrackingState[NUI_SKELETON_POSITION_COUNT]; + DWORD dwQualityFlags; +} NUI_SKELETON_DATA; + + +#define NUI_SKELETON_QUALITY_CLIPPED_RIGHT 0x00000001 +#define NUI_SKELETON_QUALITY_CLIPPED_LEFT 0x00000002 +#define NUI_SKELETON_QUALITY_CLIPPED_TOP 0x00000004 +#define NUI_SKELETON_QUALITY_CLIPPED_BOTTOM 0x00000008 + +//#pragma pack(push, 16) +typedef struct _NUI_SKELETON_FRAME +{ + LARGE_INTEGER liTimeStamp; + DWORD dwFrameNumber; + DWORD dwFlags; + XMVECTOR vFloorClipPlane; + XMVECTOR vNormalToGravity; + NUI_SKELETON_DATA SkeletonData[NUI_SKELETON_COUNT]; +} NUI_SKELETON_FRAME; +//#pragma pack(pop) + + +#define NUI_SKELETON_FRAME_FLAG_CAMERA_MOTION 0x00000001 +#define NUI_SKELETON_FRAME_FLAG_EXTRAPOLATED_FLOOR 0x00000002 +#define NUI_SKELETON_FRAME_FLAG_UPPER_BODY_SKELETON 0x00000004 +#define NUI_SKELETON_FRAME_FLAG_SEATED_SUPPORT_ENABLED 0x00000008 + +#define NUI_IDENTITY_QUALITY_ENVIRONMENT_FACE_DETECT_FAILURE 0x00000001 +#define NUI_IDENTITY_QUALITY_USER_BODY_TURNED 0x00000002 +#define NUI_IDENTITY_QUALITY_USER_NOT_UPRIGHT 0x00000004 +#define NUI_IDENTITY_QUALITY_USER_OCCLUDED_FACE 0x00000008 +#define NUI_IDENTITY_QUALITY_USER_OCCLUDED_BODY 0x00000010 +#define NUI_IDENTITY_QUALITY_USER_FAR_AWAY 0x00000020 +#define NUI_IDENTITY_QUALITY_USER_CLOSE 0x00000040 +#define NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_LEFT 0x00000080 +#define NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_RIGHT 0x00000100 +#define NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_TOP 0x00000200 +#define NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_BOTTOM 0x00000400 +#define NUI_IDENTITY_QUALITY_ENVIRONMENT_TOO_DARK 0x00000800 +#define NUI_IDENTITY_QUALITY_ENVIRONMENT_TOO_BRIGHT 0x00001000 + +#define NUI_IDENTITY_QUALITY_ENVIRONMENT_MASK \ + (NUI_IDENTITY_QUALITY_ENVIRONMENT_FACE_DETECT_FAILURE | \ + NUI_IDENTITY_QUALITY_ENVIRONMENT_TOO_DARK | \ + NUI_IDENTITY_QUALITY_ENVIRONMENT_TOO_BRIGHT) + +#define NUI_IDENTITY_QUALITY_USER_MASK \ + (NUI_IDENTITY_QUALITY_USER_BODY_TURNED | \ + NUI_IDENTITY_QUALITY_USER_NOT_UPRIGHT | \ + NUI_IDENTITY_QUALITY_USER_OCCLUDED_FACE | \ + NUI_IDENTITY_QUALITY_USER_OCCLUDED_BODY | \ + NUI_IDENTITY_QUALITY_USER_FAR_AWAY | \ + NUI_IDENTITY_QUALITY_USER_CLOSE | \ + NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_LEFT | \ + NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_RIGHT | \ + NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_TOP | \ + NUI_IDENTITY_QUALITY_USER_CLIPPED_AT_BOTTOM) + +typedef enum _NUI_IDENTITY_MESSAGE_ID +{ + NUI_IDENTITY_MESSAGE_ID_FRAME_PROCESSED, + NUI_IDENTITY_MESSAGE_ID_COMPLETE, +}NUI_IDENTITY_MESSAGE_ID; + +typedef enum _NUI_IDENTITY_OPERATION_ID +{ + NUI_IDENTITY_OPERATION_ID_NONE, + NUI_IDENTITY_OPERATION_ID_IDENTIFY, + NUI_IDENTITY_OPERATION_ID_ENROLL, + NUI_IDENTITY_OPERATION_ID_TUNER, +}NUI_IDENTITY_OPERATION_ID; + +typedef struct _NUI_IDENTITY_MESSAGE_FRAME_PROCESSED +{ + DWORD dwQualityFlags; +} NUI_IDENTITY_MESSAGE_FRAME_PROCESSED; + +typedef struct _NUI_IDENTITY_MESSAGE_COMPLETE +{ + HRESULT hrResult; + DWORD dwEnrollmentIndex; + BOOL bProfileMatched; +} NUI_IDENTITY_MESSAGE_COMPLETE; + +typedef struct _NUI_IDENTITY_MESSAGE +{ + NUI_IDENTITY_MESSAGE_ID MessageId; + NUI_IDENTITY_OPERATION_ID OperationId; + DWORD dwTrackingID; + DWORD dwSkeletonFrameNumber; + union + { + NUI_IDENTITY_MESSAGE_FRAME_PROCESSED FrameProcessed; + NUI_IDENTITY_MESSAGE_COMPLETE Complete; + } Data; +} NUI_IDENTITY_MESSAGE; +#ifdef __cplusplus +} //end of extern "C" +#endif +#ifdef __cplusplus +extern "C" { +#endif + +// +// Gesture preprocess flags for input skeletons +// +#define NUI_GESTURE_PREPROCESS_NONE 0x00000000 +#define NUI_GESTURE_PREPROCESS_MIRROR_LEFT_RIGHT 0x00000001 +#define NUI_GESTURE_PREPROCESS_MAKE_SEATED 0x00000002 + +#ifdef __cplusplus +} //close extern "C" +#endif diff --git a/third_party/xbox_sdk/include/XDevkit.h b/third_party/xbox_sdk/include/XDevkit.h new file mode 100644 index 0000000..55ccd4c --- /dev/null +++ b/third_party/xbox_sdk/include/XDevkit.h @@ -0,0 +1,9226 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 6.00.0366 */ +/* at Thu Sep 05 16:44:27 2013 + */ +/* Compiler settings for ..\xdevkit.idl: + Oicf, W1, Zp8, env=Win32 (32b run) + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +//@@MIDL_FILE_HEADING( ) + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif // __RPCNDR_H_VERSION__ + +#ifndef COM_NO_WINDOWS_H +#include "windows.h" +#include "ole2.h" +#endif /*COM_NO_WINDOWS_H*/ + +#ifndef __xdevkit_h__ +#define __xdevkit_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +/* Forward Declarations */ + +#ifndef __IXboxManager_FWD_DEFINED__ +#define __IXboxManager_FWD_DEFINED__ +typedef interface IXboxManager IXboxManager; +#endif /* __IXboxManager_FWD_DEFINED__ */ + + +#ifndef __IXboxExecutableInfo_FWD_DEFINED__ +#define __IXboxExecutableInfo_FWD_DEFINED__ +typedef interface IXboxExecutableInfo IXboxExecutableInfo; +#endif /* __IXboxExecutableInfo_FWD_DEFINED__ */ + + +#ifndef __IXboxExecutableDatabase_FWD_DEFINED__ +#define __IXboxExecutableDatabase_FWD_DEFINED__ +typedef interface IXboxExecutableDatabase IXboxExecutableDatabase; +#endif /* __IXboxExecutableDatabase_FWD_DEFINED__ */ + + +#ifndef __IXboxConsole_FWD_DEFINED__ +#define __IXboxConsole_FWD_DEFINED__ +typedef interface IXboxConsole IXboxConsole; +#endif /* __IXboxConsole_FWD_DEFINED__ */ + + +#ifndef __IXboxConsoles_FWD_DEFINED__ +#define __IXboxConsoles_FWD_DEFINED__ +typedef interface IXboxConsoles IXboxConsoles; +#endif /* __IXboxConsoles_FWD_DEFINED__ */ + + +#ifndef __IXboxFile_FWD_DEFINED__ +#define __IXboxFile_FWD_DEFINED__ +typedef interface IXboxFile IXboxFile; +#endif /* __IXboxFile_FWD_DEFINED__ */ + + +#ifndef __IXboxFiles_FWD_DEFINED__ +#define __IXboxFiles_FWD_DEFINED__ +typedef interface IXboxFiles IXboxFiles; +#endif /* __IXboxFiles_FWD_DEFINED__ */ + + +#ifndef __IXboxUser_FWD_DEFINED__ +#define __IXboxUser_FWD_DEFINED__ +typedef interface IXboxUser IXboxUser; +#endif /* __IXboxUser_FWD_DEFINED__ */ + + +#ifndef __IXboxUsers_FWD_DEFINED__ +#define __IXboxUsers_FWD_DEFINED__ +typedef interface IXboxUsers IXboxUsers; +#endif /* __IXboxUsers_FWD_DEFINED__ */ + + +#ifndef __IXboxDebugTarget_FWD_DEFINED__ +#define __IXboxDebugTarget_FWD_DEFINED__ +typedef interface IXboxDebugTarget IXboxDebugTarget; +#endif /* __IXboxDebugTarget_FWD_DEFINED__ */ + + +#ifndef __IXboxAutomation_FWD_DEFINED__ +#define __IXboxAutomation_FWD_DEFINED__ +typedef interface IXboxAutomation IXboxAutomation; +#endif /* __IXboxAutomation_FWD_DEFINED__ */ + + +#ifndef __IXboxModule_FWD_DEFINED__ +#define __IXboxModule_FWD_DEFINED__ +typedef interface IXboxModule IXboxModule; +#endif /* __IXboxModule_FWD_DEFINED__ */ + + +#ifndef __IXboxModules_FWD_DEFINED__ +#define __IXboxModules_FWD_DEFINED__ +typedef interface IXboxModules IXboxModules; +#endif /* __IXboxModules_FWD_DEFINED__ */ + + +#ifndef __IXboxExecutable_FWD_DEFINED__ +#define __IXboxExecutable_FWD_DEFINED__ +typedef interface IXboxExecutable IXboxExecutable; +#endif /* __IXboxExecutable_FWD_DEFINED__ */ + + +#ifndef __IXboxSection_FWD_DEFINED__ +#define __IXboxSection_FWD_DEFINED__ +typedef interface IXboxSection IXboxSection; +#endif /* __IXboxSection_FWD_DEFINED__ */ + + +#ifndef __IXboxSections_FWD_DEFINED__ +#define __IXboxSections_FWD_DEFINED__ +typedef interface IXboxSections IXboxSections; +#endif /* __IXboxSections_FWD_DEFINED__ */ + + +#ifndef __IXboxThread_FWD_DEFINED__ +#define __IXboxThread_FWD_DEFINED__ +typedef interface IXboxThread IXboxThread; +#endif /* __IXboxThread_FWD_DEFINED__ */ + + +#ifndef __IXboxThreads_FWD_DEFINED__ +#define __IXboxThreads_FWD_DEFINED__ +typedef interface IXboxThreads IXboxThreads; +#endif /* __IXboxThreads_FWD_DEFINED__ */ + + +#ifndef __IXboxStackFrame_FWD_DEFINED__ +#define __IXboxStackFrame_FWD_DEFINED__ +typedef interface IXboxStackFrame IXboxStackFrame; +#endif /* __IXboxStackFrame_FWD_DEFINED__ */ + + +#ifndef __IXboxMemoryRegions_FWD_DEFINED__ +#define __IXboxMemoryRegions_FWD_DEFINED__ +typedef interface IXboxMemoryRegions IXboxMemoryRegions; +#endif /* __IXboxMemoryRegions_FWD_DEFINED__ */ + + +#ifndef __IXboxMemoryRegion_FWD_DEFINED__ +#define __IXboxMemoryRegion_FWD_DEFINED__ +typedef interface IXboxMemoryRegion IXboxMemoryRegion; +#endif /* __IXboxMemoryRegion_FWD_DEFINED__ */ + + +#ifndef __IXboxEventInfo_FWD_DEFINED__ +#define __IXboxEventInfo_FWD_DEFINED__ +typedef interface IXboxEventInfo IXboxEventInfo; +#endif /* __IXboxEventInfo_FWD_DEFINED__ */ + + +#ifndef __XboxEvents_FWD_DEFINED__ +#define __XboxEvents_FWD_DEFINED__ +typedef interface XboxEvents XboxEvents; +#endif /* __XboxEvents_FWD_DEFINED__ */ + + +#ifndef __IXboxEvents_FWD_DEFINED__ +#define __IXboxEvents_FWD_DEFINED__ +typedef interface IXboxEvents IXboxEvents; +#endif /* __IXboxEvents_FWD_DEFINED__ */ + + +#ifndef __IXboxManager_FWD_DEFINED__ +#define __IXboxManager_FWD_DEFINED__ +typedef interface IXboxManager IXboxManager; +#endif /* __IXboxManager_FWD_DEFINED__ */ + + +#ifndef __IXboxConsole_FWD_DEFINED__ +#define __IXboxConsole_FWD_DEFINED__ +typedef interface IXboxConsole IXboxConsole; +#endif /* __IXboxConsole_FWD_DEFINED__ */ + + +#ifndef __IXboxConsoles_FWD_DEFINED__ +#define __IXboxConsoles_FWD_DEFINED__ +typedef interface IXboxConsoles IXboxConsoles; +#endif /* __IXboxConsoles_FWD_DEFINED__ */ + + +#ifndef __IXboxFile_FWD_DEFINED__ +#define __IXboxFile_FWD_DEFINED__ +typedef interface IXboxFile IXboxFile; +#endif /* __IXboxFile_FWD_DEFINED__ */ + + +#ifndef __IXboxFiles_FWD_DEFINED__ +#define __IXboxFiles_FWD_DEFINED__ +typedef interface IXboxFiles IXboxFiles; +#endif /* __IXboxFiles_FWD_DEFINED__ */ + + +#ifndef __IXboxUser_FWD_DEFINED__ +#define __IXboxUser_FWD_DEFINED__ +typedef interface IXboxUser IXboxUser; +#endif /* __IXboxUser_FWD_DEFINED__ */ + + +#ifndef __IXboxUsers_FWD_DEFINED__ +#define __IXboxUsers_FWD_DEFINED__ +typedef interface IXboxUsers IXboxUsers; +#endif /* __IXboxUsers_FWD_DEFINED__ */ + + +#ifndef __IXboxDebugTarget_FWD_DEFINED__ +#define __IXboxDebugTarget_FWD_DEFINED__ +typedef interface IXboxDebugTarget IXboxDebugTarget; +#endif /* __IXboxDebugTarget_FWD_DEFINED__ */ + + +#ifndef __IXboxModule_FWD_DEFINED__ +#define __IXboxModule_FWD_DEFINED__ +typedef interface IXboxModule IXboxModule; +#endif /* __IXboxModule_FWD_DEFINED__ */ + + +#ifndef __IXboxModules_FWD_DEFINED__ +#define __IXboxModules_FWD_DEFINED__ +typedef interface IXboxModules IXboxModules; +#endif /* __IXboxModules_FWD_DEFINED__ */ + + +#ifndef __IXboxSection_FWD_DEFINED__ +#define __IXboxSection_FWD_DEFINED__ +typedef interface IXboxSection IXboxSection; +#endif /* __IXboxSection_FWD_DEFINED__ */ + + +#ifndef __IXboxSections_FWD_DEFINED__ +#define __IXboxSections_FWD_DEFINED__ +typedef interface IXboxSections IXboxSections; +#endif /* __IXboxSections_FWD_DEFINED__ */ + + +#ifndef __IXboxThread_FWD_DEFINED__ +#define __IXboxThread_FWD_DEFINED__ +typedef interface IXboxThread IXboxThread; +#endif /* __IXboxThread_FWD_DEFINED__ */ + + +#ifndef __IXboxThreads_FWD_DEFINED__ +#define __IXboxThreads_FWD_DEFINED__ +typedef interface IXboxThreads IXboxThreads; +#endif /* __IXboxThreads_FWD_DEFINED__ */ + + +#ifndef __IXboxStackFrame_FWD_DEFINED__ +#define __IXboxStackFrame_FWD_DEFINED__ +typedef interface IXboxStackFrame IXboxStackFrame; +#endif /* __IXboxStackFrame_FWD_DEFINED__ */ + + +#ifndef __IXboxMemoryRegions_FWD_DEFINED__ +#define __IXboxMemoryRegions_FWD_DEFINED__ +typedef interface IXboxMemoryRegions IXboxMemoryRegions; +#endif /* __IXboxMemoryRegions_FWD_DEFINED__ */ + + +#ifndef __IXboxMemoryRegion_FWD_DEFINED__ +#define __IXboxMemoryRegion_FWD_DEFINED__ +typedef interface IXboxMemoryRegion IXboxMemoryRegion; +#endif /* __IXboxMemoryRegion_FWD_DEFINED__ */ + + +#ifndef __IXboxEventInfo_FWD_DEFINED__ +#define __IXboxEventInfo_FWD_DEFINED__ +typedef interface IXboxEventInfo IXboxEventInfo; +#endif /* __IXboxEventInfo_FWD_DEFINED__ */ + + +#ifndef __XboxEvents_FWD_DEFINED__ +#define __XboxEvents_FWD_DEFINED__ +typedef interface XboxEvents XboxEvents; +#endif /* __XboxEvents_FWD_DEFINED__ */ + + +#ifndef __IXboxEvents_FWD_DEFINED__ +#define __IXboxEvents_FWD_DEFINED__ +typedef interface IXboxEvents IXboxEvents; +#endif /* __IXboxEvents_FWD_DEFINED__ */ + + +#ifndef __XboxConsole_FWD_DEFINED__ +#define __XboxConsole_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class XboxConsole XboxConsole; +#else +typedef struct XboxConsole XboxConsole; +#endif /* __cplusplus */ + +#endif /* __XboxConsole_FWD_DEFINED__ */ + + +#ifndef __XboxManager_FWD_DEFINED__ +#define __XboxManager_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class XboxManager XboxManager; +#else +typedef struct XboxManager XboxManager; +#endif /* __cplusplus */ + +#endif /* __XboxManager_FWD_DEFINED__ */ + + +#ifndef __XboxExecutableDatabase_FWD_DEFINED__ +#define __XboxExecutableDatabase_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class XboxExecutableDatabase XboxExecutableDatabase; +#else +typedef struct XboxExecutableDatabase XboxExecutableDatabase; +#endif /* __cplusplus */ + +#endif /* __XboxExecutableDatabase_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "oaidl.h" +#include "ocidl.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +void * __RPC_USER MIDL_user_allocate(size_t); +void __RPC_USER MIDL_user_free( void * ); + +/* interface __MIDL_itf_xdevkit_0000 */ +/* [local] */ + + + + + + + + + + + + + + + + + + + + + + +#define FACILITY_XDEVKIT 0x2da +#ifndef MAKE_HRESULT +#define MAKE_HRESULT(sev,fac,code) ((HRESULT)(((unsigned long)sev<<31)|((unsigned long)fac<<16)|((unsigned long)code))) +#endif +#define MAKE_E_XDEVKIT(code) MAKE_HRESULT(1, FACILITY_XDEVKIT, code) +#define MAKE_S_XDEVKIT(code) MAKE_HRESULT(0, FACILITY_XDEVKIT, code) +#define S_XDEVKIT_NOERR MAKE_S_XDEVKIT(0) +#define S_XDEVKIT_CONNECTED MAKE_S_XDEVKIT(1) +#define S_XDEVKIT_MULTIRESPONSE MAKE_S_XDEVKIT(2) +#define S_XDEVKIT_BINRESPONSE MAKE_S_XDEVKIT(3) +#define S_XDEVKIT_READYFORBIN MAKE_S_XDEVKIT(4) +#define S_XDEVKIT_DEDICATED MAKE_S_XDEVKIT(5) +#define S_XDEVKIT_PROFILERESTARTED MAKE_S_XDEVKIT(6) +#define S_XDEVKIT_FASTCAPENABLED MAKE_S_XDEVKIT(7) +#define S_XDEVKIT_CALLCAPENABLED MAKE_S_XDEVKIT(8) +#define E_XDEVKIT_UNDEFINED MAKE_E_XDEVKIT(0) +#define E_XDEVKIT_MAXCONNECT MAKE_E_XDEVKIT(1) +#define E_XDEVKIT_NOSUCHFILE MAKE_E_XDEVKIT(2) +#define E_XDEVKIT_NOMODULE MAKE_E_XDEVKIT(3) +#define E_XDEVKIT_MEMUNMAPPED MAKE_E_XDEVKIT(4) +#define E_XDEVKIT_NOTHREAD MAKE_E_XDEVKIT(5) +#define E_XDEVKIT_CLOCKNOTSET MAKE_E_XDEVKIT(6) +#define E_XDEVKIT_INVALIDCMD MAKE_E_XDEVKIT(7) +#define E_XDEVKIT_NOTSTOPPED MAKE_E_XDEVKIT(8) +#define E_XDEVKIT_MUSTCOPY MAKE_E_XDEVKIT(9) +#define E_XDEVKIT_ALREADYEXISTS MAKE_E_XDEVKIT(10) +#define E_XDEVKIT_DIRNOTEMPTY MAKE_E_XDEVKIT(11) +#define E_XDEVKIT_BADFILENAME MAKE_E_XDEVKIT(12) +#define E_XDEVKIT_CANNOTCREATE MAKE_E_XDEVKIT(13) +#define E_XDEVKIT_CANNOTACCESS MAKE_E_XDEVKIT(14) +#define E_XDEVKIT_DEVICEFULL MAKE_E_XDEVKIT(15) +#define E_XDEVKIT_NOTDEBUGGABLE MAKE_E_XDEVKIT(16) +#define E_XDEVKIT_BADCOUNTTYPE MAKE_E_XDEVKIT(17) +#define E_XDEVKIT_COUNTUNAVAILABLE MAKE_E_XDEVKIT(18) +#define E_XDEVKIT_NOTLOCKED MAKE_E_XDEVKIT(20) +#define E_XDEVKIT_KEYXCHG MAKE_E_XDEVKIT(21) +#define E_XDEVKIT_MUSTBEDEDICATED MAKE_E_XDEVKIT(22) +#define E_XDEVKIT_INVALIDARG MAKE_E_XDEVKIT(23) +#define E_XDEVKIT_PROFILENOTSTARTED MAKE_E_XDEVKIT(24) +#define E_XDEVKIT_PROFILEALREADYSTARTED MAKE_E_XDEVKIT(25) +#define E_XDEVKIT_ALREADYSTOPPED MAKE_E_XDEVKIT(26) +#define E_XDEVKIT_FASTCAPNOTENABLED MAKE_E_XDEVKIT(27) +#define E_XDEVKIT_NOMEMORY MAKE_E_XDEVKIT(28) +#define E_XDEVKIT_TIMEOUT MAKE_E_XDEVKIT(29) +#define E_XDEVKIT_NOSUCHPATH MAKE_E_XDEVKIT(30) +#define E_XDEVKIT_INVALID_SCREEN_INPUT_FORMAT MAKE_E_XDEVKIT(31) +#define E_XDEVKIT_INVALID_SCREEN_OUTPUT_FORMAT MAKE_E_XDEVKIT(32) +#define E_XDEVKIT_CALLCAPNOTENABLED MAKE_E_XDEVKIT(33) +#define E_XDEVKIT_INVALIDCAPCFG MAKE_E_XDEVKIT(34) +#define E_XDEVKIT_CAPNOTENABLED MAKE_E_XDEVKIT(35) +#define E_XDEVKIT_TOOBIGJUMP MAKE_E_XDEVKIT(36) +#define E_XDEVKIT_OUTPUTBUFFERTOOSMALL MAKE_E_XDEVKIT(38) +#define E_XDEVKIT_PROFILEREBOOT MAKE_E_XDEVKIT(39) +#define E_XDEVKIT_MAXDURATIONEXCEEDED MAKE_E_XDEVKIT(41) +#define E_XDEVKIT_INVALIDSTATE MAKE_E_XDEVKIT(42) +#define E_XDEVKIT_MAXEXTENSIONS MAKE_E_XDEVKIT(43) +#define E_XDEVKIT_PMCSESSIONALREADYACTIVE MAKE_E_XDEVKIT(44) +#define E_XDEVKIT_PMCSESSIONNOTACTIVE MAKE_E_XDEVKIT(45) +#define E_XDEVKIT_LINE_TOO_LONG MAKE_E_XDEVKIT(46) +#define E_XDEVKIT_D3D_DEBUG_COMMAND_NOT_IMPLEMENTED MAKE_E_XDEVKIT(0x50) +#define E_XDEVKIT_D3D_INVALID_SURFACE MAKE_E_XDEVKIT(0x51) +#define E_XDEVKIT_CANNOTCONNECT MAKE_E_XDEVKIT(0x100) +#define E_XDEVKIT_CONNECTIONLOST MAKE_E_XDEVKIT(0x101) +#define E_XDEVKIT_FILEERROR MAKE_E_XDEVKIT(0x103) +#define E_XDEVKIT_ENDOFLIST MAKE_E_XDEVKIT(0x104) +#define E_XDEVKIT_BUFFER_TOO_SMALL MAKE_E_XDEVKIT(0x105) +#define E_XDEVKIT_NOTXBEFILE MAKE_E_XDEVKIT(0x106) +#define E_XDEVKIT_MEMSETINCOMPLETE MAKE_E_XDEVKIT(0x107) +#define E_XDEVKIT_NOXBOXNAME MAKE_E_XDEVKIT(0x108) +#define E_XDEVKIT_NOERRORSTRING MAKE_E_XDEVKIT(0x109) +#define E_XDEVKIT_INVALIDSTATUS MAKE_E_XDEVKIT(0x10A) +#define E_XDEVKIT_TASK_PENDING MAKE_E_XDEVKIT(0x150) +#define FACILITY_XEXECDB 0x2da +#define MAKE_E_XEXECDB(code) MAKE_HRESULT(1, FACILITY_XEXECDB, code) +#define MAKE_S_XEXECDB(code) MAKE_HRESULT(0, FACILITY_XEXECDB, code) +#define E_XEXECDB_UNRECOGNIZED_FILE MAKE_E_XEXECDB(0x400) +#define E_XEXECDB_WRONG_VERSION MAKE_E_XEXECDB(0x401) +typedef struct XBOX_PROCESS_INFO + { + DWORD ProcessId; + BSTR ProgramName; + } XBOX_PROCESS_INFO; + +typedef struct XBOX_PROCESS_INFO *PXBOX_PROCESS_INFO; + +namespace eXboxAccessFlags { +/* [v1_enum] */ +enum XboxAccessFlags + { Read = 1, + Write = 2, + Control = 4, + Configure = 8, + Manage = 16 + } ; +} +/* +typedef enum XboxAccessFlags _XboxAccessFlags; + +*/ typedef int _XboxAccessFlags; +typedef struct XBOX_USER + { + BSTR UserName; + _XboxAccessFlags Access; + } XBOX_USER; + +typedef struct XBOX_USER *PXBOX_USER; + +namespace eXboxModuleInfoFlags { +/* [v1_enum] */ +enum XboxModuleInfoFlags + { Main = 1, + Tls = 2, + Dll = 4 + } ; +} +/* +typedef enum XboxModuleInfoFlags _XboxModuleInfoFlags; + +*/ typedef int _XboxModuleInfoFlags; +typedef struct XBOX_MODULE_INFO + { + BSTR Name; + BSTR FullName; + DWORD BaseAddress; + DWORD Size; + DWORD TimeStamp; + DWORD CheckSum; + _XboxModuleInfoFlags Flags; + } XBOX_MODULE_INFO; + +typedef struct XBOX_MODULE_INFO *PXBOX_MODULE_INFO; + +namespace eXboxSectionInfoFlags { +/* [v1_enum] */ +enum XboxSectionInfoFlags + { Loaded = 1, + Readable = 2, + Writeable = 4, + Executable = 8, + Uninitialized = 16 + } ; +} +/* +typedef enum XboxSectionInfoFlags _XboxSectionInfoFlags; + +*/ typedef int _XboxSectionInfoFlags; +typedef struct XBOX_SECTION_INFO + { + BSTR Name; + DWORD BaseAddress; + DWORD Size; + DWORD Index; + _XboxSectionInfoFlags Flags; + } XBOX_SECTION_INFO; + +typedef struct XBOX_SECTION_INFO *PXBOX_SECTION_INFO; + +typedef struct XBOX_THREAD_INFO + { + DWORD ThreadId; + DWORD SuspendCount; + DWORD Priority; + DWORD TlsBase; + DWORD StartAddress; + DWORD StackBase; + DWORD StackLimit; + DWORD StackSlackSpace; + VARIANT CreateTime; + BSTR Name; + } XBOX_THREAD_INFO; + +typedef struct XBOX_THREAD_INFO *PXBOX_THREAD_INFO; + +namespace eXboxFunctionType { +/* [v1_enum] */ +enum XboxFunctionType + { NoPData = 0xffffffff, + SaveMillicode = 0, + NoHandler = 1, + RestoreMillicode = 2, + Handler = 3 + } ; +} +/* +typedef enum XboxFunctionType _XboxFunctionType; + +*/ typedef eXboxFunctionType::XboxFunctionType _XboxFunctionType; +typedef struct XBOX_FUNCTION_INFO + { + _XboxFunctionType FunctionType; + DWORD BeginAddress; + DWORD PrologEndAddress; + DWORD FunctionEndAddress; + } XBOX_FUNCTION_INFO; + +typedef struct XBOX_FUNCTION_INFO *PXBOX_FUNCTION_INFO; + +namespace eXboxDebugEventType { +/* [v1_enum] */ +enum XboxDebugEventType + { NoEvent = 0, + ExecutionBreak = NoEvent + 1, + DebugString = ExecutionBreak + 1, + ExecStateChange = DebugString + 1, + SingleStep = ExecStateChange + 1, + ModuleLoad = SingleStep + 1, + ModuleUnload = ModuleLoad + 1, + ThreadCreate = ModuleUnload + 1, + ThreadDestroy = ThreadCreate + 1, + Exception = ThreadDestroy + 1, + AssertionFailed = Exception + 1, + AssertionFailedEx = AssertionFailed + 1, + DataBreak = AssertionFailedEx + 1, + RIP = DataBreak + 1, + SectionLoad = RIP + 1, + SectionUnload = SectionLoad + 1, + StackTrace = SectionUnload + 1, + FiberCreate = StackTrace + 1, + FiberDestroy = FiberCreate + 1, + BugCheck = FiberDestroy + 1, + PgoModuleStartup = BugCheck + 1 + } ; +} +/* +typedef enum XboxDebugEventType _XboxDebugEventType; + +*/ typedef eXboxDebugEventType::XboxDebugEventType _XboxDebugEventType; +namespace eXboxExecutionState { +/* [v1_enum] */ +enum XboxExecutionState + { Stopped = 0, + Running = Stopped + 1, + Rebooting = Running + 1, + Pending = Rebooting + 1, + RebootingTitle = Pending + 1, + PendingTitle = RebootingTitle + 1 + } ; +} +/* +typedef enum XboxExecutionState _XboxExecutionState; + +*/ typedef eXboxExecutionState::XboxExecutionState _XboxExecutionState; +// Must match DMSTOP_ constants +namespace eXboxStopOnFlags { +/* [v1_enum] */ +enum XboxStopOnFlags + { OnThreadCreate = 0x1, + OnFirstChanceException = 0x2, + OnDebugString = 0x4, + OnStackTrace = 0x8, + OnModuleLoad = 0x10, + OnTitleLaunch = 0x20, + OnPgoModuleStartup = 0x40 + } ; +} +/* +typedef enum XboxStopOnFlags _XboxStopOnFlags; + +*/ typedef int _XboxStopOnFlags; +namespace eXboxRebootFlags { +/* [v1_enum] */ +enum XboxRebootFlags + { Title = 0, + Wait = 1, + Cold = 2, + Warm = 4, + Stop = 8 + } ; +#pragma deprecated(Warm) +} +/* +typedef enum XboxRebootFlags _XboxRebootFlags; + +*/ typedef int _XboxRebootFlags; +namespace eXboxExceptionFlags { +/* [v1_enum] */ +enum XboxExceptionFlags + { Noncontinuable = 1, + FirstChance = 2 + } ; +} +/* +typedef enum XboxExceptionFlags _XboxExceptionFlags; + +*/ typedef int _XboxExceptionFlags; +typedef struct XBOX_EVENT_INFO + { + _XboxDebugEventType Event; + VARIANT_BOOL IsThreadStopped; + IXboxThread *Thread; + IXboxModule *Module; + IXboxSection *Section; + _XboxExecutionState ExecState; + BSTR Message; + DWORD Code; + DWORD Address; + _XboxExceptionFlags Flags; + DWORD ParameterCount; + DWORD Parameters[ 15 ]; + } XBOX_EVENT_INFO; + +typedef struct XBOX_EVENT_INFO *PXBOX_EVENT_INFO; + +namespace eXboxBreakpointType { +/* [v1_enum] */ +enum XboxBreakpointType + { NoBreakpoint = 0, + OnWrite = NoBreakpoint + 1, + OnRead = OnWrite + 1, + OnExecuteHW = OnRead + 1, + OnExecute = OnExecuteHW + 1 + } ; +} +/* +typedef enum XboxBreakpointType _XboxBreakpointType; + +*/ typedef eXboxBreakpointType::XboxBreakpointType _XboxBreakpointType; +namespace eXboxSelectConsoleFlags { +/* [v1_enum] */ +enum XboxSelectConsoleFlags + { NoPromptIfDefaultExists = 0, + NoPromptIfOnlyOne = NoPromptIfDefaultExists + 1, + FilterByAccess = NoPromptIfOnlyOne + 1 + } ; +} +/* +typedef enum XboxSelectConsoleFlags _XboxSelectConsoleFlags; + +*/ typedef int _XboxSelectConsoleFlags; +namespace eXboxDebugConnectFlags{ +/* [v1_enum] */ +enum XboxDebugConnectFlags + { Force = 0x1, + MonitorOnly = 0x2 + } ; +} +/* +typedef enum XboxDebugConnectFlags _XboxDebugConnectFlags; + +*/ typedef int _XboxDebugConnectFlags; +namespace eXboxDumpFlags{ +/* [v1_enum] */ +enum XboxDumpFlags + { Normal = 0, + WithDataSegs = 0x1, + WithFullMemory = 0x2, + WithHandleData = 0x4, + FilterMemory = 0x8, + ScanMemory = 0x10, + WithUnloadedModules = 0x20, + WithIndirectlyReferencedMemory = 0x40, + FilterModulePaths = 0x80, + WithProcessThreadData = 0x100, + WithPrivateReadWriteMemory = 0x200 + } ; +} +/* +typedef enum XboxDumpFlags _XboxDumpFlags; + +*/ typedef int _XboxDumpFlags; +namespace eXboxDumpMode{ +/* [v1_enum] */ +enum XboxDumpMode + { Smart = 0, + Enabled = 0x1, + Disabled = 0x2 + } ; +} +/* +typedef enum XboxDumpMode _XboxDumpMode; + +*/ typedef eXboxDumpMode::XboxDumpMode _XboxDumpMode; +namespace eXboxEventDeferFlags { +/* [v1_enum] */ +enum XboxEventDeferFlags + { CanDeferExecutionBreak = 0x1, + CanDeferDebugString = 0x2, + CanDeferSingleStep = 0x4, + CanDeferAssertionFailed = 0x8, + CanDeferAssertionFailedEx = 0x10, + CanDeferDataBreak = 0x20, + CanDeferRIP = 0x40 + } ; +} +/* +typedef enum XboxEventDeferFlags _XboxEventDeferFlags; + +*/ typedef int _XboxEventDeferFlags; +namespace eXboxDumpReportFlags { +/* [v1_enum] */ +enum XboxDumpReportFlags + { PromptToReport = 0, + AlwaysReport = 0x1, + NeverReport = 0x2, + ReportGroup = 0xf, + LocalDestination = 0, + RemoteDestination = 0x10, + DestinationGroup = 0xf, + FormatFullHeap = 0, + FormatPartialHeap = 0x100, + FormatNoHeap = 0x200, + FormatRetail = 0x400, + FormatGroup = 0xf00 + } ; +} +/* +typedef enum XboxDumpReportFlags _XboxDumpReportFlags; + +*/ typedef int _XboxDumpReportFlags; +namespace eXboxConsoleType { +/* [v1_enum] */ +enum XboxConsoleType + { DevelopmentKit = 0, + TestKit = 1, + ReviewerKit = 2 + } ; +} +/* +typedef enum XboxConsoleType _XboxConsoleType; + +*/ typedef eXboxConsoleType::XboxConsoleType _XboxConsoleType; +namespace eXboxConsoleFeatures { +/* [v1_enum] */ +enum XboxConsoleFeatures + { Debugging = 1, + SecondaryNIC = 2, + GB_RAM = 4 + } ; +} +/* +typedef enum XboxConsoleFeatures _XboxConsoleFeatures; + +*/ typedef int _XboxConsoleFeatures; +typedef struct XBOX_DUMP_SETTINGS + { + _XboxDumpReportFlags Flags; + BSTR NetworkPath; + } XBOX_DUMP_SETTINGS; + +typedef struct XBOX_DUMP_SETTINGS *PXBOX_DUMP_SETTINGS; + + + +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0000_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0000_v0_0_s_ifspec; + +#ifndef __IXboxManager_INTERFACE_DEFINED__ +#define __IXboxManager_INTERFACE_DEFINED__ + +/* interface IXboxManager */ +/* [helpstring][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxManager; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("c4c077e9-bf83-4657-ad8b-1e5abb9bb9a8") + IXboxManager : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_DefaultConsole( + /* [retval][out] */ BSTR *DefaultXbox) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_DefaultConsole( + /* [in] */ BSTR DefaultXbox) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Consoles( + /* [retval][out] */ IXboxConsoles **Consoles) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE AddConsole( + /* [in] */ BSTR Xbox) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RemoveConsole( + /* [in] */ BSTR Xbox) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE OpenConsole( + /* [in] */ BSTR XboxName, + /* [retval][out] */ IXboxConsole **Console) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE OpenDumpFile( + /* [in] */ BSTR FileName, + /* [in] */ BSTR ImageSearchPath, + /* [retval][out] */ IXboxDebugTarget **DebugTarget) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SelectConsole( + /* [in] */ LONG ParentWindow, + /* [out] */ BSTR *SelectedXbox, + /* [in] */ _XboxAccessFlags DesiredAccess, + /* [in] */ _XboxSelectConsoleFlags Flags) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RunAddConsoleWizard( + /* [in] */ LONG ParentWindow, + /* [in] */ VARIANT_BOOL Modal) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE OpenWindowsExplorer( + /* [in] */ BSTR XboxName, + /* [in] */ BSTR Path) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE TranslateError( + /* [in] */ HRESULT hr, + /* [retval][out] */ BSTR *ErrorString) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_SystemSymbolServerPath( + /* [retval][out] */ BSTR *SymbolServerPath) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SelectConsoleEx( + /* [in] */ LONGLONG ParentWindow, + /* [out] */ BSTR *SelectedXbox, + /* [in] */ _XboxAccessFlags DesiredAccess, + /* [in] */ _XboxSelectConsoleFlags Flags) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RunAddConsoleWizardEx( + /* [in] */ LONGLONG ParentWindow, + /* [in] */ VARIANT_BOOL Modal) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxManagerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxManager * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxManager * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxManager * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxManager * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxManager * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxManager * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxManager * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DefaultConsole )( + IXboxManager * This, + /* [retval][out] */ BSTR *DefaultXbox); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DefaultConsole )( + IXboxManager * This, + /* [in] */ BSTR DefaultXbox); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Consoles )( + IXboxManager * This, + /* [retval][out] */ IXboxConsoles **Consoles); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *AddConsole )( + IXboxManager * This, + /* [in] */ BSTR Xbox); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RemoveConsole )( + IXboxManager * This, + /* [in] */ BSTR Xbox); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *OpenConsole )( + IXboxManager * This, + /* [in] */ BSTR XboxName, + /* [retval][out] */ IXboxConsole **Console); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *OpenDumpFile )( + IXboxManager * This, + /* [in] */ BSTR FileName, + /* [in] */ BSTR ImageSearchPath, + /* [retval][out] */ IXboxDebugTarget **DebugTarget); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SelectConsole )( + IXboxManager * This, + /* [in] */ LONG ParentWindow, + /* [out] */ BSTR *SelectedXbox, + /* [in] */ _XboxAccessFlags DesiredAccess, + /* [in] */ _XboxSelectConsoleFlags Flags); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RunAddConsoleWizard )( + IXboxManager * This, + /* [in] */ LONG ParentWindow, + /* [in] */ VARIANT_BOOL Modal); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *OpenWindowsExplorer )( + IXboxManager * This, + /* [in] */ BSTR XboxName, + /* [in] */ BSTR Path); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *TranslateError )( + IXboxManager * This, + /* [in] */ HRESULT hr, + /* [retval][out] */ BSTR *ErrorString); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_SystemSymbolServerPath )( + IXboxManager * This, + /* [retval][out] */ BSTR *SymbolServerPath); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SelectConsoleEx )( + IXboxManager * This, + /* [in] */ LONGLONG ParentWindow, + /* [out] */ BSTR *SelectedXbox, + /* [in] */ _XboxAccessFlags DesiredAccess, + /* [in] */ _XboxSelectConsoleFlags Flags); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RunAddConsoleWizardEx )( + IXboxManager * This, + /* [in] */ LONGLONG ParentWindow, + /* [in] */ VARIANT_BOOL Modal); + + END_INTERFACE + } IXboxManagerVtbl; + + interface IXboxManager + { + CONST_VTBL struct IXboxManagerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxManager_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxManager_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxManager_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxManager_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxManager_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxManager_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxManager_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxManager_get_DefaultConsole(This,DefaultXbox) \ + (This)->lpVtbl -> get_DefaultConsole(This,DefaultXbox) + +#define IXboxManager_put_DefaultConsole(This,DefaultXbox) \ + (This)->lpVtbl -> put_DefaultConsole(This,DefaultXbox) + +#define IXboxManager_get_Consoles(This,Consoles) \ + (This)->lpVtbl -> get_Consoles(This,Consoles) + +#define IXboxManager_AddConsole(This,Xbox) \ + (This)->lpVtbl -> AddConsole(This,Xbox) + +#define IXboxManager_RemoveConsole(This,Xbox) \ + (This)->lpVtbl -> RemoveConsole(This,Xbox) + +#define IXboxManager_OpenConsole(This,XboxName,Console) \ + (This)->lpVtbl -> OpenConsole(This,XboxName,Console) + +#define IXboxManager_OpenDumpFile(This,FileName,ImageSearchPath,DebugTarget) \ + (This)->lpVtbl -> OpenDumpFile(This,FileName,ImageSearchPath,DebugTarget) + +#define IXboxManager_SelectConsole(This,ParentWindow,SelectedXbox,DesiredAccess,Flags) \ + (This)->lpVtbl -> SelectConsole(This,ParentWindow,SelectedXbox,DesiredAccess,Flags) + +#define IXboxManager_RunAddConsoleWizard(This,ParentWindow,Modal) \ + (This)->lpVtbl -> RunAddConsoleWizard(This,ParentWindow,Modal) + +#define IXboxManager_OpenWindowsExplorer(This,XboxName,Path) \ + (This)->lpVtbl -> OpenWindowsExplorer(This,XboxName,Path) + +#define IXboxManager_TranslateError(This,hr,ErrorString) \ + (This)->lpVtbl -> TranslateError(This,hr,ErrorString) + +#define IXboxManager_get_SystemSymbolServerPath(This,SymbolServerPath) \ + (This)->lpVtbl -> get_SystemSymbolServerPath(This,SymbolServerPath) + +#define IXboxManager_SelectConsoleEx(This,ParentWindow,SelectedXbox,DesiredAccess,Flags) \ + (This)->lpVtbl -> SelectConsoleEx(This,ParentWindow,SelectedXbox,DesiredAccess,Flags) + +#define IXboxManager_RunAddConsoleWizardEx(This,ParentWindow,Modal) \ + (This)->lpVtbl -> RunAddConsoleWizardEx(This,ParentWindow,Modal) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxManager_get_DefaultConsole_Proxy( + IXboxManager * This, + /* [retval][out] */ BSTR *DefaultXbox); + + +void __RPC_STUB IXboxManager_get_DefaultConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxManager_put_DefaultConsole_Proxy( + IXboxManager * This, + /* [in] */ BSTR DefaultXbox); + + +void __RPC_STUB IXboxManager_put_DefaultConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxManager_get_Consoles_Proxy( + IXboxManager * This, + /* [retval][out] */ IXboxConsoles **Consoles); + + +void __RPC_STUB IXboxManager_get_Consoles_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_AddConsole_Proxy( + IXboxManager * This, + /* [in] */ BSTR Xbox); + + +void __RPC_STUB IXboxManager_AddConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_RemoveConsole_Proxy( + IXboxManager * This, + /* [in] */ BSTR Xbox); + + +void __RPC_STUB IXboxManager_RemoveConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_OpenConsole_Proxy( + IXboxManager * This, + /* [in] */ BSTR XboxName, + /* [retval][out] */ IXboxConsole **Console); + + +void __RPC_STUB IXboxManager_OpenConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_OpenDumpFile_Proxy( + IXboxManager * This, + /* [in] */ BSTR FileName, + /* [in] */ BSTR ImageSearchPath, + /* [retval][out] */ IXboxDebugTarget **DebugTarget); + + +void __RPC_STUB IXboxManager_OpenDumpFile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_SelectConsole_Proxy( + IXboxManager * This, + /* [in] */ LONG ParentWindow, + /* [out] */ BSTR *SelectedXbox, + /* [in] */ _XboxAccessFlags DesiredAccess, + /* [in] */ _XboxSelectConsoleFlags Flags); + + +void __RPC_STUB IXboxManager_SelectConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_RunAddConsoleWizard_Proxy( + IXboxManager * This, + /* [in] */ LONG ParentWindow, + /* [in] */ VARIANT_BOOL Modal); + + +void __RPC_STUB IXboxManager_RunAddConsoleWizard_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_OpenWindowsExplorer_Proxy( + IXboxManager * This, + /* [in] */ BSTR XboxName, + /* [in] */ BSTR Path); + + +void __RPC_STUB IXboxManager_OpenWindowsExplorer_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_TranslateError_Proxy( + IXboxManager * This, + /* [in] */ HRESULT hr, + /* [retval][out] */ BSTR *ErrorString); + + +void __RPC_STUB IXboxManager_TranslateError_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxManager_get_SystemSymbolServerPath_Proxy( + IXboxManager * This, + /* [retval][out] */ BSTR *SymbolServerPath); + + +void __RPC_STUB IXboxManager_get_SystemSymbolServerPath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_SelectConsoleEx_Proxy( + IXboxManager * This, + /* [in] */ LONGLONG ParentWindow, + /* [out] */ BSTR *SelectedXbox, + /* [in] */ _XboxAccessFlags DesiredAccess, + /* [in] */ _XboxSelectConsoleFlags Flags); + + +void __RPC_STUB IXboxManager_SelectConsoleEx_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxManager_RunAddConsoleWizardEx_Proxy( + IXboxManager * This, + /* [in] */ LONGLONG ParentWindow, + /* [in] */ VARIANT_BOOL Modal); + + +void __RPC_STUB IXboxManager_RunAddConsoleWizardEx_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxManager_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_xdevkit_0262 */ +/* [local] */ + +namespace eXboxShareMode { +/* [v1_enum] */ +enum XboxShareMode + { ShareNone = 0, + ShareRead = 0x1, + ShareWrite = 0x2, + ShareDelete = 0x4 + } ; +} +/* +typedef enum XboxShareMode _XboxShareMode; + +*/ typedef int _XboxShareMode; +namespace eXboxCreateDisposition { +/* [v1_enum] */ +enum XboxCreateDisposition + { CreateNew = 1, + CreateAlways = 2, + OpenExisting = 3, + OpenAlways = 4 + } ; +} +/* +typedef enum XboxCreateDisposition _XboxCreateDisposition; + +*/ typedef eXboxCreateDisposition::XboxCreateDisposition _XboxCreateDisposition; + + +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0262_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0262_v0_0_s_ifspec; + +#ifndef __IXboxExecutableInfo_INTERFACE_DEFINED__ +#define __IXboxExecutableInfo_INTERFACE_DEFINED__ + +/* interface IXboxExecutableInfo */ +/* [helpstring][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxExecutableInfo; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("978B90D1-1F44-4adc-B992-12AF5DBE16E2") + IXboxExecutableInfo : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_SymbolGuid( + /* [retval][out] */ BSTR *Guid) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_XboxExecutablePath( + /* [retval][out] */ BSTR *Path) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_PortableExecutablePath( + /* [retval][out] */ BSTR *Path) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_SymbolPath( + /* [retval][out] */ BSTR *Path) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_PublicSymbolPath( + /* [retval][out] */ BSTR *Path) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ModuleName( + /* [retval][out] */ BSTR *Name) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_TimeDateStamp( + /* [retval][out] */ DWORD *Time) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_SizeOfImage( + /* [retval][out] */ DWORD *Size) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_StoreRelativePath( + /* [retval][out] */ VARIANT_BOOL *RelativePath) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_BasePath( + /* [retval][out] */ BSTR *Path) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_BasePath( + /* [in] */ BSTR Path) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_PropGetRelativePath( + /* [retval][out] */ VARIANT_BOOL *Relative) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_PropGetRelativePath( + /* [in] */ VARIANT_BOOL Relative) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxExecutableInfoVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxExecutableInfo * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxExecutableInfo * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxExecutableInfo * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxExecutableInfo * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxExecutableInfo * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxExecutableInfo * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxExecutableInfo * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_SymbolGuid )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Guid); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_XboxExecutablePath )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_PortableExecutablePath )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_SymbolPath )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_PublicSymbolPath )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ModuleName )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Name); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_TimeDateStamp )( + IXboxExecutableInfo * This, + /* [retval][out] */ DWORD *Time); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_SizeOfImage )( + IXboxExecutableInfo * This, + /* [retval][out] */ DWORD *Size); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_StoreRelativePath )( + IXboxExecutableInfo * This, + /* [retval][out] */ VARIANT_BOOL *RelativePath); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_BasePath )( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_BasePath )( + IXboxExecutableInfo * This, + /* [in] */ BSTR Path); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_PropGetRelativePath )( + IXboxExecutableInfo * This, + /* [retval][out] */ VARIANT_BOOL *Relative); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_PropGetRelativePath )( + IXboxExecutableInfo * This, + /* [in] */ VARIANT_BOOL Relative); + + END_INTERFACE + } IXboxExecutableInfoVtbl; + + interface IXboxExecutableInfo + { + CONST_VTBL struct IXboxExecutableInfoVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxExecutableInfo_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxExecutableInfo_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxExecutableInfo_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxExecutableInfo_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxExecutableInfo_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxExecutableInfo_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxExecutableInfo_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxExecutableInfo_get_SymbolGuid(This,Guid) \ + (This)->lpVtbl -> get_SymbolGuid(This,Guid) + +#define IXboxExecutableInfo_get_XboxExecutablePath(This,Path) \ + (This)->lpVtbl -> get_XboxExecutablePath(This,Path) + +#define IXboxExecutableInfo_get_PortableExecutablePath(This,Path) \ + (This)->lpVtbl -> get_PortableExecutablePath(This,Path) + +#define IXboxExecutableInfo_get_SymbolPath(This,Path) \ + (This)->lpVtbl -> get_SymbolPath(This,Path) + +#define IXboxExecutableInfo_get_PublicSymbolPath(This,Path) \ + (This)->lpVtbl -> get_PublicSymbolPath(This,Path) + +#define IXboxExecutableInfo_get_ModuleName(This,Name) \ + (This)->lpVtbl -> get_ModuleName(This,Name) + +#define IXboxExecutableInfo_get_TimeDateStamp(This,Time) \ + (This)->lpVtbl -> get_TimeDateStamp(This,Time) + +#define IXboxExecutableInfo_get_SizeOfImage(This,Size) \ + (This)->lpVtbl -> get_SizeOfImage(This,Size) + +#define IXboxExecutableInfo_get_StoreRelativePath(This,RelativePath) \ + (This)->lpVtbl -> get_StoreRelativePath(This,RelativePath) + +#define IXboxExecutableInfo_get_BasePath(This,Path) \ + (This)->lpVtbl -> get_BasePath(This,Path) + +#define IXboxExecutableInfo_put_BasePath(This,Path) \ + (This)->lpVtbl -> put_BasePath(This,Path) + +#define IXboxExecutableInfo_get_PropGetRelativePath(This,Relative) \ + (This)->lpVtbl -> get_PropGetRelativePath(This,Relative) + +#define IXboxExecutableInfo_put_PropGetRelativePath(This,Relative) \ + (This)->lpVtbl -> put_PropGetRelativePath(This,Relative) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_SymbolGuid_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Guid); + + +void __RPC_STUB IXboxExecutableInfo_get_SymbolGuid_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_XboxExecutablePath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + +void __RPC_STUB IXboxExecutableInfo_get_XboxExecutablePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_PortableExecutablePath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + +void __RPC_STUB IXboxExecutableInfo_get_PortableExecutablePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_SymbolPath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + +void __RPC_STUB IXboxExecutableInfo_get_SymbolPath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_PublicSymbolPath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + +void __RPC_STUB IXboxExecutableInfo_get_PublicSymbolPath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_ModuleName_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Name); + + +void __RPC_STUB IXboxExecutableInfo_get_ModuleName_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_TimeDateStamp_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ DWORD *Time); + + +void __RPC_STUB IXboxExecutableInfo_get_TimeDateStamp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_SizeOfImage_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ DWORD *Size); + + +void __RPC_STUB IXboxExecutableInfo_get_SizeOfImage_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_StoreRelativePath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ VARIANT_BOOL *RelativePath); + + +void __RPC_STUB IXboxExecutableInfo_get_StoreRelativePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_BasePath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ BSTR *Path); + + +void __RPC_STUB IXboxExecutableInfo_get_BasePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_put_BasePath_Proxy( + IXboxExecutableInfo * This, + /* [in] */ BSTR Path); + + +void __RPC_STUB IXboxExecutableInfo_put_BasePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_get_PropGetRelativePath_Proxy( + IXboxExecutableInfo * This, + /* [retval][out] */ VARIANT_BOOL *Relative); + + +void __RPC_STUB IXboxExecutableInfo_get_PropGetRelativePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxExecutableInfo_put_PropGetRelativePath_Proxy( + IXboxExecutableInfo * This, + /* [in] */ VARIANT_BOOL Relative); + + +void __RPC_STUB IXboxExecutableInfo_put_PropGetRelativePath_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxExecutableInfo_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxExecutableDatabase_INTERFACE_DEFINED__ +#define __IXboxExecutableDatabase_INTERFACE_DEFINED__ + +/* interface IXboxExecutableDatabase */ +/* [helpstring][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxExecutableDatabase; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("CB8E47BA-2673-48af-B0C5-FD5738FFCC6B") + IXboxExecutableDatabase : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_IsDirty( + /* [retval][out] */ VARIANT_BOOL *DirtyFlag) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_CurrentFileName( + /* [retval][out] */ BSTR *Path) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE LoadDatabase( + /* [in] */ BSTR DatabaseFile, + /* [in] */ VARIANT_BOOL ReadOnly, + /* [in] */ _XboxCreateDisposition CreateDisposition, + /* [in] */ _XboxShareMode ShareMode) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SaveDatabase( + /* [in] */ BSTR DatabaseFile, + /* [in] */ VARIANT_BOOL Remember) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE CloseDatabase( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ResetDatabase( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE AddExecutable( + /* [in] */ BSTR XboxExecutablePath, + /* [in] */ BSTR PortableExecutablePath, + /* [in] */ BSTR SymbolPath, + /* [in] */ BSTR PublicSymbolPath, + /* [in] */ VARIANT_BOOL ExplictFilesOnly, + /* [in] */ VARIANT_BOOL StoreRelativePath) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RemoveExecutable( + /* [in] */ BSTR Guid) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE FindExecutableByGuid( + /* [in] */ BSTR Guid, + /* [out] */ IXboxExecutableInfo **Info, + /* [retval][out] */ VARIANT_BOOL *Found) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE FindExecutableForSymServ( + /* [in] */ BSTR ModuleName, + /* [in] */ DWORD TimeDateStamp, + /* [in] */ DWORD SizeOfImage, + /* [out] */ IXboxExecutableInfo **Info, + /* [retval][out] */ VARIANT_BOOL *Found) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxExecutableDatabaseVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxExecutableDatabase * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxExecutableDatabase * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxExecutableDatabase * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxExecutableDatabase * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxExecutableDatabase * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxExecutableDatabase * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxExecutableDatabase * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsDirty )( + IXboxExecutableDatabase * This, + /* [retval][out] */ VARIANT_BOOL *DirtyFlag); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_CurrentFileName )( + IXboxExecutableDatabase * This, + /* [retval][out] */ BSTR *Path); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *LoadDatabase )( + IXboxExecutableDatabase * This, + /* [in] */ BSTR DatabaseFile, + /* [in] */ VARIANT_BOOL ReadOnly, + /* [in] */ _XboxCreateDisposition CreateDisposition, + /* [in] */ _XboxShareMode ShareMode); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SaveDatabase )( + IXboxExecutableDatabase * This, + /* [in] */ BSTR DatabaseFile, + /* [in] */ VARIANT_BOOL Remember); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *CloseDatabase )( + IXboxExecutableDatabase * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ResetDatabase )( + IXboxExecutableDatabase * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *AddExecutable )( + IXboxExecutableDatabase * This, + /* [in] */ BSTR XboxExecutablePath, + /* [in] */ BSTR PortableExecutablePath, + /* [in] */ BSTR SymbolPath, + /* [in] */ BSTR PublicSymbolPath, + /* [in] */ VARIANT_BOOL ExplictFilesOnly, + /* [in] */ VARIANT_BOOL StoreRelativePath); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RemoveExecutable )( + IXboxExecutableDatabase * This, + /* [in] */ BSTR Guid); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *FindExecutableByGuid )( + IXboxExecutableDatabase * This, + /* [in] */ BSTR Guid, + /* [out] */ IXboxExecutableInfo **Info, + /* [retval][out] */ VARIANT_BOOL *Found); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *FindExecutableForSymServ )( + IXboxExecutableDatabase * This, + /* [in] */ BSTR ModuleName, + /* [in] */ DWORD TimeDateStamp, + /* [in] */ DWORD SizeOfImage, + /* [out] */ IXboxExecutableInfo **Info, + /* [retval][out] */ VARIANT_BOOL *Found); + + END_INTERFACE + } IXboxExecutableDatabaseVtbl; + + interface IXboxExecutableDatabase + { + CONST_VTBL struct IXboxExecutableDatabaseVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxExecutableDatabase_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxExecutableDatabase_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxExecutableDatabase_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxExecutableDatabase_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxExecutableDatabase_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxExecutableDatabase_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxExecutableDatabase_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxExecutableDatabase_get_IsDirty(This,DirtyFlag) \ + (This)->lpVtbl -> get_IsDirty(This,DirtyFlag) + +#define IXboxExecutableDatabase_get_CurrentFileName(This,Path) \ + (This)->lpVtbl -> get_CurrentFileName(This,Path) + +#define IXboxExecutableDatabase_LoadDatabase(This,DatabaseFile,ReadOnly,CreateDisposition,ShareMode) \ + (This)->lpVtbl -> LoadDatabase(This,DatabaseFile,ReadOnly,CreateDisposition,ShareMode) + +#define IXboxExecutableDatabase_SaveDatabase(This,DatabaseFile,Remember) \ + (This)->lpVtbl -> SaveDatabase(This,DatabaseFile,Remember) + +#define IXboxExecutableDatabase_CloseDatabase(This) \ + (This)->lpVtbl -> CloseDatabase(This) + +#define IXboxExecutableDatabase_ResetDatabase(This) \ + (This)->lpVtbl -> ResetDatabase(This) + +#define IXboxExecutableDatabase_AddExecutable(This,XboxExecutablePath,PortableExecutablePath,SymbolPath,PublicSymbolPath,ExplictFilesOnly,StoreRelativePath) \ + (This)->lpVtbl -> AddExecutable(This,XboxExecutablePath,PortableExecutablePath,SymbolPath,PublicSymbolPath,ExplictFilesOnly,StoreRelativePath) + +#define IXboxExecutableDatabase_RemoveExecutable(This,Guid) \ + (This)->lpVtbl -> RemoveExecutable(This,Guid) + +#define IXboxExecutableDatabase_FindExecutableByGuid(This,Guid,Info,Found) \ + (This)->lpVtbl -> FindExecutableByGuid(This,Guid,Info,Found) + +#define IXboxExecutableDatabase_FindExecutableForSymServ(This,ModuleName,TimeDateStamp,SizeOfImage,Info,Found) \ + (This)->lpVtbl -> FindExecutableForSymServ(This,ModuleName,TimeDateStamp,SizeOfImage,Info,Found) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_get_IsDirty_Proxy( + IXboxExecutableDatabase * This, + /* [retval][out] */ VARIANT_BOOL *DirtyFlag); + + +void __RPC_STUB IXboxExecutableDatabase_get_IsDirty_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_get_CurrentFileName_Proxy( + IXboxExecutableDatabase * This, + /* [retval][out] */ BSTR *Path); + + +void __RPC_STUB IXboxExecutableDatabase_get_CurrentFileName_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_LoadDatabase_Proxy( + IXboxExecutableDatabase * This, + /* [in] */ BSTR DatabaseFile, + /* [in] */ VARIANT_BOOL ReadOnly, + /* [in] */ _XboxCreateDisposition CreateDisposition, + /* [in] */ _XboxShareMode ShareMode); + + +void __RPC_STUB IXboxExecutableDatabase_LoadDatabase_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_SaveDatabase_Proxy( + IXboxExecutableDatabase * This, + /* [in] */ BSTR DatabaseFile, + /* [in] */ VARIANT_BOOL Remember); + + +void __RPC_STUB IXboxExecutableDatabase_SaveDatabase_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_CloseDatabase_Proxy( + IXboxExecutableDatabase * This); + + +void __RPC_STUB IXboxExecutableDatabase_CloseDatabase_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_ResetDatabase_Proxy( + IXboxExecutableDatabase * This); + + +void __RPC_STUB IXboxExecutableDatabase_ResetDatabase_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_AddExecutable_Proxy( + IXboxExecutableDatabase * This, + /* [in] */ BSTR XboxExecutablePath, + /* [in] */ BSTR PortableExecutablePath, + /* [in] */ BSTR SymbolPath, + /* [in] */ BSTR PublicSymbolPath, + /* [in] */ VARIANT_BOOL ExplictFilesOnly, + /* [in] */ VARIANT_BOOL StoreRelativePath); + + +void __RPC_STUB IXboxExecutableDatabase_AddExecutable_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_RemoveExecutable_Proxy( + IXboxExecutableDatabase * This, + /* [in] */ BSTR Guid); + + +void __RPC_STUB IXboxExecutableDatabase_RemoveExecutable_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_FindExecutableByGuid_Proxy( + IXboxExecutableDatabase * This, + /* [in] */ BSTR Guid, + /* [out] */ IXboxExecutableInfo **Info, + /* [retval][out] */ VARIANT_BOOL *Found); + + +void __RPC_STUB IXboxExecutableDatabase_FindExecutableByGuid_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutableDatabase_FindExecutableForSymServ_Proxy( + IXboxExecutableDatabase * This, + /* [in] */ BSTR ModuleName, + /* [in] */ DWORD TimeDateStamp, + /* [in] */ DWORD SizeOfImage, + /* [out] */ IXboxExecutableInfo **Info, + /* [retval][out] */ VARIANT_BOOL *Found); + + +void __RPC_STUB IXboxExecutableDatabase_FindExecutableForSymServ_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxExecutableDatabase_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxConsole_INTERFACE_DEFINED__ +#define __IXboxConsole_INTERFACE_DEFINED__ + +/* interface IXboxConsole */ +/* [helpstring][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxConsole; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("75dd80a9-5a33-42d4-8a39-ab07c9b17cc3") + IXboxConsole : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Name( + /* [retval][out] */ BSTR *XboxName) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_Name( + /* [in] */ BSTR XboxName) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_IPAddress( + /* [retval][out] */ DWORD *IPAddress) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_IPAddressTitle( + /* [retval][out] */ DWORD *IPAddress) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_SystemTime( + /* [retval][out] */ VARIANT *Date) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_SystemTime( + /* [in] */ VARIANT Date) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Shared( + /* [retval][out] */ VARIANT_BOOL *Shared) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_Shared( + /* [in] */ VARIANT_BOOL Shared) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ConnectTimeout( + /* [retval][out] */ DWORD *Timeout) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_ConnectTimeout( + /* [in] */ DWORD Timeout) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ConversationTimeout( + /* [retval][out] */ DWORD *Timeout) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_ConversationTimeout( + /* [in] */ DWORD Timeout) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE FindConsole( + /* [in] */ DWORD Retries, + /* [in] */ DWORD RetryDelay) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_XboxManager( + /* [retval][out] */ IXboxManager **XboxManager) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_DebugTarget( + /* [retval][out] */ IXboxDebugTarget **DebugTarget) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Reboot( + /* [in] */ BSTR Name, + /* [in] */ BSTR MediaDirectory, + /* [in] */ BSTR CmdLine, + /* [in] */ _XboxRebootFlags Flags) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetDefaultTitle( + /* [in] */ BSTR TitleName, + /* [in] */ BSTR MediaDirectory, + /* [in] */ DWORD Flags) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_RunningProcessInfo( + /* [retval][out] */ PXBOX_PROCESS_INFO ProcessInfo) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE OpenConnection( + /* [in] */ BSTR Handler, + /* [retval][out] */ DWORD *Connection) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE CloseConnection( + /* [in] */ DWORD Connection) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SendTextCommand( + /* [in] */ DWORD Connection, + /* [in] */ BSTR Command, + /* [out] */ BSTR *Response) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ReceiveSocketLine( + /* [in] */ DWORD Connection, + /* [out] */ BSTR *Line) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ReceiveStatusResponse( + /* [in] */ DWORD Connection, + /* [out] */ BSTR *Line, + /* [retval][out] */ HRESULT *status) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SendBinary( + /* [in] */ DWORD Connection, + /* [in] */ SAFEARRAY * Data, + /* [in] */ DWORD Count) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ReceiveBinary( + /* [in] */ DWORD Connection, + /* [out][in] */ SAFEARRAY * Data, + /* [in] */ DWORD Count, + /* [out] */ DWORD *BytesReceived) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE SendBinary_cpp( + /* [in] */ DWORD Connection, + /* [size_is][in] */ BYTE *Data, + /* [in] */ DWORD Count) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE ReceiveBinary_cpp( + /* [in] */ DWORD Connection, + /* [size_is][in] */ BYTE *Data, + /* [in] */ DWORD Count, + /* [out] */ DWORD *BytesReceived) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Drives( + /* [retval][out] */ BSTR *Drives) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetDiskFreeSpace( + /* [in] */ WCHAR Drive, + /* [out] */ ULONGLONG *FreeBytesAvailableToCaller, + /* [out] */ ULONGLONG *TotalNumberOfBytes, + /* [out] */ ULONGLONG *TotalNumberOfFreeBytes) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE MakeDirectory( + /* [in] */ BSTR Directory) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RemoveDirectory( + /* [in] */ BSTR Directory) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE DirectoryFiles( + /* [in] */ BSTR Directory, + /* [retval][out] */ IXboxFiles **Files) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SendFile( + /* [in] */ BSTR LocalName, + /* [in] */ BSTR RemoteName) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ReceiveFile( + /* [in] */ BSTR LocalName, + /* [in] */ BSTR RemoteName) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ReadFileBytes( + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [out][in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesRead) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE WriteFileBytes( + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesWritten) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE ReadFileBytes_cpp( + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [length_is][size_is][out] */ BYTE *Data, + /* [out] */ DWORD *BytesRead) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE WriteFileBytes_cpp( + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [size_is][in] */ BYTE *Data, + /* [out] */ DWORD *BytesWritten) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetFileSize( + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ _XboxCreateDisposition CreateDisposition) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetFileObject( + /* [in] */ BSTR FileName, + /* [retval][out] */ IXboxFile **FileObject) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RenameFile( + /* [in] */ BSTR OldName, + /* [in] */ BSTR NewName) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE DeleteFile( + /* [in] */ BSTR FileName) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ScreenShot( + BSTR FileName) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_DumpMode( + /* [retval][out] */ _XboxDumpMode *DumpMode) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_DumpMode( + /* [in] */ _XboxDumpMode DumpMode) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetDumpSettings( + /* [out] */ PXBOX_DUMP_SETTINGS DumpMode) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetDumpSettings( + /* [in] */ PXBOX_DUMP_SETTINGS DumpMode) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_EventDeferFlags( + /* [retval][out] */ _XboxEventDeferFlags *EventDeferFlags) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_EventDeferFlags( + /* [in] */ _XboxEventDeferFlags EventDeferFlags) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ConsoleType( + /* [retval][out] */ _XboxConsoleType *ConsoleType) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE StartFileEventCapture( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE StopFileEventCapture( void) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_XboxAutomation( + /* [retval][out] */ IXboxAutomation **Automation) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE LoadDebuggerExtension( + /* [in] */ BSTR ExtensionName, + /* [retval][out] */ DWORD *ModuleHandle) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE UnloadDebuggerExtension( + /* [in] */ DWORD ModuleHandle) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ConsoleFeatures( + /* [retval][out] */ _XboxConsoleFeatures *ConsoleFeatures) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxConsoleVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxConsole * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxConsole * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxConsole * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxConsole * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxConsole * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxConsole * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxConsole * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Name )( + IXboxConsole * This, + /* [retval][out] */ BSTR *XboxName); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Name )( + IXboxConsole * This, + /* [in] */ BSTR XboxName); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_IPAddress )( + IXboxConsole * This, + /* [retval][out] */ DWORD *IPAddress); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_IPAddressTitle )( + IXboxConsole * This, + /* [retval][out] */ DWORD *IPAddress); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_SystemTime )( + IXboxConsole * This, + /* [retval][out] */ VARIANT *Date); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_SystemTime )( + IXboxConsole * This, + /* [in] */ VARIANT Date); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Shared )( + IXboxConsole * This, + /* [retval][out] */ VARIANT_BOOL *Shared); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Shared )( + IXboxConsole * This, + /* [in] */ VARIANT_BOOL Shared); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ConnectTimeout )( + IXboxConsole * This, + /* [retval][out] */ DWORD *Timeout); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_ConnectTimeout )( + IXboxConsole * This, + /* [in] */ DWORD Timeout); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ConversationTimeout )( + IXboxConsole * This, + /* [retval][out] */ DWORD *Timeout); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_ConversationTimeout )( + IXboxConsole * This, + /* [in] */ DWORD Timeout); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *FindConsole )( + IXboxConsole * This, + /* [in] */ DWORD Retries, + /* [in] */ DWORD RetryDelay); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_XboxManager )( + IXboxConsole * This, + /* [retval][out] */ IXboxManager **XboxManager); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DebugTarget )( + IXboxConsole * This, + /* [retval][out] */ IXboxDebugTarget **DebugTarget); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Reboot )( + IXboxConsole * This, + /* [in] */ BSTR Name, + /* [in] */ BSTR MediaDirectory, + /* [in] */ BSTR CmdLine, + /* [in] */ _XboxRebootFlags Flags); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetDefaultTitle )( + IXboxConsole * This, + /* [in] */ BSTR TitleName, + /* [in] */ BSTR MediaDirectory, + /* [in] */ DWORD Flags); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_RunningProcessInfo )( + IXboxConsole * This, + /* [retval][out] */ PXBOX_PROCESS_INFO ProcessInfo); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *OpenConnection )( + IXboxConsole * This, + /* [in] */ BSTR Handler, + /* [retval][out] */ DWORD *Connection); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *CloseConnection )( + IXboxConsole * This, + /* [in] */ DWORD Connection); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SendTextCommand )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [in] */ BSTR Command, + /* [out] */ BSTR *Response); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ReceiveSocketLine )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [out] */ BSTR *Line); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ReceiveStatusResponse )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [out] */ BSTR *Line, + /* [retval][out] */ HRESULT *status); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SendBinary )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [in] */ SAFEARRAY * Data, + /* [in] */ DWORD Count); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ReceiveBinary )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [out][in] */ SAFEARRAY * Data, + /* [in] */ DWORD Count, + /* [out] */ DWORD *BytesReceived); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *SendBinary_cpp )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [size_is][in] */ BYTE *Data, + /* [in] */ DWORD Count); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *ReceiveBinary_cpp )( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [size_is][in] */ BYTE *Data, + /* [in] */ DWORD Count, + /* [out] */ DWORD *BytesReceived); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Drives )( + IXboxConsole * This, + /* [retval][out] */ BSTR *Drives); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetDiskFreeSpace )( + IXboxConsole * This, + /* [in] */ WCHAR Drive, + /* [out] */ ULONGLONG *FreeBytesAvailableToCaller, + /* [out] */ ULONGLONG *TotalNumberOfBytes, + /* [out] */ ULONGLONG *TotalNumberOfFreeBytes); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *MakeDirectory )( + IXboxConsole * This, + /* [in] */ BSTR Directory); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RemoveDirectory )( + IXboxConsole * This, + /* [in] */ BSTR Directory); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *DirectoryFiles )( + IXboxConsole * This, + /* [in] */ BSTR Directory, + /* [retval][out] */ IXboxFiles **Files); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SendFile )( + IXboxConsole * This, + /* [in] */ BSTR LocalName, + /* [in] */ BSTR RemoteName); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ReceiveFile )( + IXboxConsole * This, + /* [in] */ BSTR LocalName, + /* [in] */ BSTR RemoteName); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ReadFileBytes )( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [out][in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesRead); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *WriteFileBytes )( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesWritten); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *ReadFileBytes_cpp )( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [length_is][size_is][out] */ BYTE *Data, + /* [out] */ DWORD *BytesRead); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *WriteFileBytes_cpp )( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [size_is][in] */ BYTE *Data, + /* [out] */ DWORD *BytesWritten); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetFileSize )( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ _XboxCreateDisposition CreateDisposition); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetFileObject )( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [retval][out] */ IXboxFile **FileObject); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RenameFile )( + IXboxConsole * This, + /* [in] */ BSTR OldName, + /* [in] */ BSTR NewName); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *DeleteFile )( + IXboxConsole * This, + /* [in] */ BSTR FileName); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ScreenShot )( + IXboxConsole * This, + BSTR FileName); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_DumpMode )( + IXboxConsole * This, + /* [retval][out] */ _XboxDumpMode *DumpMode); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_DumpMode )( + IXboxConsole * This, + /* [in] */ _XboxDumpMode DumpMode); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetDumpSettings )( + IXboxConsole * This, + /* [out] */ PXBOX_DUMP_SETTINGS DumpMode); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetDumpSettings )( + IXboxConsole * This, + /* [in] */ PXBOX_DUMP_SETTINGS DumpMode); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_EventDeferFlags )( + IXboxConsole * This, + /* [retval][out] */ _XboxEventDeferFlags *EventDeferFlags); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_EventDeferFlags )( + IXboxConsole * This, + /* [in] */ _XboxEventDeferFlags EventDeferFlags); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ConsoleType )( + IXboxConsole * This, + /* [retval][out] */ _XboxConsoleType *ConsoleType); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *StartFileEventCapture )( + IXboxConsole * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *StopFileEventCapture )( + IXboxConsole * This); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_XboxAutomation )( + IXboxConsole * This, + /* [retval][out] */ IXboxAutomation **Automation); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *LoadDebuggerExtension )( + IXboxConsole * This, + /* [in] */ BSTR ExtensionName, + /* [retval][out] */ DWORD *ModuleHandle); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *UnloadDebuggerExtension )( + IXboxConsole * This, + /* [in] */ DWORD ModuleHandle); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ConsoleFeatures )( + IXboxConsole * This, + /* [retval][out] */ _XboxConsoleFeatures *ConsoleFeatures); + + END_INTERFACE + } IXboxConsoleVtbl; + + interface IXboxConsole + { + CONST_VTBL struct IXboxConsoleVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxConsole_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxConsole_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxConsole_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxConsole_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxConsole_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxConsole_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxConsole_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxConsole_get_Name(This,XboxName) \ + (This)->lpVtbl -> get_Name(This,XboxName) + +#define IXboxConsole_put_Name(This,XboxName) \ + (This)->lpVtbl -> put_Name(This,XboxName) + +#define IXboxConsole_get_IPAddress(This,IPAddress) \ + (This)->lpVtbl -> get_IPAddress(This,IPAddress) + +#define IXboxConsole_get_IPAddressTitle(This,IPAddress) \ + (This)->lpVtbl -> get_IPAddressTitle(This,IPAddress) + +#define IXboxConsole_get_SystemTime(This,Date) \ + (This)->lpVtbl -> get_SystemTime(This,Date) + +#define IXboxConsole_put_SystemTime(This,Date) \ + (This)->lpVtbl -> put_SystemTime(This,Date) + +#define IXboxConsole_get_Shared(This,Shared) \ + (This)->lpVtbl -> get_Shared(This,Shared) + +#define IXboxConsole_put_Shared(This,Shared) \ + (This)->lpVtbl -> put_Shared(This,Shared) + +#define IXboxConsole_get_ConnectTimeout(This,Timeout) \ + (This)->lpVtbl -> get_ConnectTimeout(This,Timeout) + +#define IXboxConsole_put_ConnectTimeout(This,Timeout) \ + (This)->lpVtbl -> put_ConnectTimeout(This,Timeout) + +#define IXboxConsole_get_ConversationTimeout(This,Timeout) \ + (This)->lpVtbl -> get_ConversationTimeout(This,Timeout) + +#define IXboxConsole_put_ConversationTimeout(This,Timeout) \ + (This)->lpVtbl -> put_ConversationTimeout(This,Timeout) + +#define IXboxConsole_FindConsole(This,Retries,RetryDelay) \ + (This)->lpVtbl -> FindConsole(This,Retries,RetryDelay) + +#define IXboxConsole_get_XboxManager(This,XboxManager) \ + (This)->lpVtbl -> get_XboxManager(This,XboxManager) + +#define IXboxConsole_get_DebugTarget(This,DebugTarget) \ + (This)->lpVtbl -> get_DebugTarget(This,DebugTarget) + +#define IXboxConsole_Reboot(This,Name,MediaDirectory,CmdLine,Flags) \ + (This)->lpVtbl -> Reboot(This,Name,MediaDirectory,CmdLine,Flags) + +#define IXboxConsole_SetDefaultTitle(This,TitleName,MediaDirectory,Flags) \ + (This)->lpVtbl -> SetDefaultTitle(This,TitleName,MediaDirectory,Flags) + +#define IXboxConsole_get_RunningProcessInfo(This,ProcessInfo) \ + (This)->lpVtbl -> get_RunningProcessInfo(This,ProcessInfo) + +#define IXboxConsole_OpenConnection(This,Handler,Connection) \ + (This)->lpVtbl -> OpenConnection(This,Handler,Connection) + +#define IXboxConsole_CloseConnection(This,Connection) \ + (This)->lpVtbl -> CloseConnection(This,Connection) + +#define IXboxConsole_SendTextCommand(This,Connection,Command,Response) \ + (This)->lpVtbl -> SendTextCommand(This,Connection,Command,Response) + +#define IXboxConsole_ReceiveSocketLine(This,Connection,Line) \ + (This)->lpVtbl -> ReceiveSocketLine(This,Connection,Line) + +#define IXboxConsole_ReceiveStatusResponse(This,Connection,Line,status) \ + (This)->lpVtbl -> ReceiveStatusResponse(This,Connection,Line,status) + +#define IXboxConsole_SendBinary(This,Connection,Data,Count) \ + (This)->lpVtbl -> SendBinary(This,Connection,Data,Count) + +#define IXboxConsole_ReceiveBinary(This,Connection,Data,Count,BytesReceived) \ + (This)->lpVtbl -> ReceiveBinary(This,Connection,Data,Count,BytesReceived) + +#define IXboxConsole_SendBinary_cpp(This,Connection,Data,Count) \ + (This)->lpVtbl -> SendBinary_cpp(This,Connection,Data,Count) + +#define IXboxConsole_ReceiveBinary_cpp(This,Connection,Data,Count,BytesReceived) \ + (This)->lpVtbl -> ReceiveBinary_cpp(This,Connection,Data,Count,BytesReceived) + +#define IXboxConsole_get_Drives(This,Drives) \ + (This)->lpVtbl -> get_Drives(This,Drives) + +#define IXboxConsole_GetDiskFreeSpace(This,Drive,FreeBytesAvailableToCaller,TotalNumberOfBytes,TotalNumberOfFreeBytes) \ + (This)->lpVtbl -> GetDiskFreeSpace(This,Drive,FreeBytesAvailableToCaller,TotalNumberOfBytes,TotalNumberOfFreeBytes) + +#define IXboxConsole_MakeDirectory(This,Directory) \ + (This)->lpVtbl -> MakeDirectory(This,Directory) + +#define IXboxConsole_RemoveDirectory(This,Directory) \ + (This)->lpVtbl -> RemoveDirectory(This,Directory) + +#define IXboxConsole_DirectoryFiles(This,Directory,Files) \ + (This)->lpVtbl -> DirectoryFiles(This,Directory,Files) + +#define IXboxConsole_SendFile(This,LocalName,RemoteName) \ + (This)->lpVtbl -> SendFile(This,LocalName,RemoteName) + +#define IXboxConsole_ReceiveFile(This,LocalName,RemoteName) \ + (This)->lpVtbl -> ReceiveFile(This,LocalName,RemoteName) + +#define IXboxConsole_ReadFileBytes(This,FileName,FileOffset,Count,Data,BytesRead) \ + (This)->lpVtbl -> ReadFileBytes(This,FileName,FileOffset,Count,Data,BytesRead) + +#define IXboxConsole_WriteFileBytes(This,FileName,FileOffset,Count,Data,BytesWritten) \ + (This)->lpVtbl -> WriteFileBytes(This,FileName,FileOffset,Count,Data,BytesWritten) + +#define IXboxConsole_ReadFileBytes_cpp(This,FileName,FileOffset,Count,Data,BytesRead) \ + (This)->lpVtbl -> ReadFileBytes_cpp(This,FileName,FileOffset,Count,Data,BytesRead) + +#define IXboxConsole_WriteFileBytes_cpp(This,FileName,FileOffset,Count,Data,BytesWritten) \ + (This)->lpVtbl -> WriteFileBytes_cpp(This,FileName,FileOffset,Count,Data,BytesWritten) + +#define IXboxConsole_SetFileSize(This,FileName,FileOffset,CreateDisposition) \ + (This)->lpVtbl -> SetFileSize(This,FileName,FileOffset,CreateDisposition) + +#define IXboxConsole_GetFileObject(This,FileName,FileObject) \ + (This)->lpVtbl -> GetFileObject(This,FileName,FileObject) + +#define IXboxConsole_RenameFile(This,OldName,NewName) \ + (This)->lpVtbl -> RenameFile(This,OldName,NewName) + +#define IXboxConsole_DeleteFile(This,FileName) \ + (This)->lpVtbl -> DeleteFile(This,FileName) + +#define IXboxConsole_ScreenShot(This,FileName) \ + (This)->lpVtbl -> ScreenShot(This,FileName) + +#define IXboxConsole_get_DumpMode(This,DumpMode) \ + (This)->lpVtbl -> get_DumpMode(This,DumpMode) + +#define IXboxConsole_put_DumpMode(This,DumpMode) \ + (This)->lpVtbl -> put_DumpMode(This,DumpMode) + +#define IXboxConsole_GetDumpSettings(This,DumpMode) \ + (This)->lpVtbl -> GetDumpSettings(This,DumpMode) + +#define IXboxConsole_SetDumpSettings(This,DumpMode) \ + (This)->lpVtbl -> SetDumpSettings(This,DumpMode) + +#define IXboxConsole_get_EventDeferFlags(This,EventDeferFlags) \ + (This)->lpVtbl -> get_EventDeferFlags(This,EventDeferFlags) + +#define IXboxConsole_put_EventDeferFlags(This,EventDeferFlags) \ + (This)->lpVtbl -> put_EventDeferFlags(This,EventDeferFlags) + +#define IXboxConsole_get_ConsoleType(This,ConsoleType) \ + (This)->lpVtbl -> get_ConsoleType(This,ConsoleType) + +#define IXboxConsole_StartFileEventCapture(This) \ + (This)->lpVtbl -> StartFileEventCapture(This) + +#define IXboxConsole_StopFileEventCapture(This) \ + (This)->lpVtbl -> StopFileEventCapture(This) + +#define IXboxConsole_get_XboxAutomation(This,Automation) \ + (This)->lpVtbl -> get_XboxAutomation(This,Automation) + +#define IXboxConsole_LoadDebuggerExtension(This,ExtensionName,ModuleHandle) \ + (This)->lpVtbl -> LoadDebuggerExtension(This,ExtensionName,ModuleHandle) + +#define IXboxConsole_UnloadDebuggerExtension(This,ModuleHandle) \ + (This)->lpVtbl -> UnloadDebuggerExtension(This,ModuleHandle) + +#define IXboxConsole_get_ConsoleFeatures(This,ConsoleFeatures) \ + (This)->lpVtbl -> get_ConsoleFeatures(This,ConsoleFeatures) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_Name_Proxy( + IXboxConsole * This, + /* [retval][out] */ BSTR *XboxName); + + +void __RPC_STUB IXboxConsole_get_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_Name_Proxy( + IXboxConsole * This, + /* [in] */ BSTR XboxName); + + +void __RPC_STUB IXboxConsole_put_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_IPAddress_Proxy( + IXboxConsole * This, + /* [retval][out] */ DWORD *IPAddress); + + +void __RPC_STUB IXboxConsole_get_IPAddress_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_IPAddressTitle_Proxy( + IXboxConsole * This, + /* [retval][out] */ DWORD *IPAddress); + + +void __RPC_STUB IXboxConsole_get_IPAddressTitle_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_SystemTime_Proxy( + IXboxConsole * This, + /* [retval][out] */ VARIANT *Date); + + +void __RPC_STUB IXboxConsole_get_SystemTime_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_SystemTime_Proxy( + IXboxConsole * This, + /* [in] */ VARIANT Date); + + +void __RPC_STUB IXboxConsole_put_SystemTime_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_Shared_Proxy( + IXboxConsole * This, + /* [retval][out] */ VARIANT_BOOL *Shared); + + +void __RPC_STUB IXboxConsole_get_Shared_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_Shared_Proxy( + IXboxConsole * This, + /* [in] */ VARIANT_BOOL Shared); + + +void __RPC_STUB IXboxConsole_put_Shared_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_ConnectTimeout_Proxy( + IXboxConsole * This, + /* [retval][out] */ DWORD *Timeout); + + +void __RPC_STUB IXboxConsole_get_ConnectTimeout_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_ConnectTimeout_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Timeout); + + +void __RPC_STUB IXboxConsole_put_ConnectTimeout_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_ConversationTimeout_Proxy( + IXboxConsole * This, + /* [retval][out] */ DWORD *Timeout); + + +void __RPC_STUB IXboxConsole_get_ConversationTimeout_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_ConversationTimeout_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Timeout); + + +void __RPC_STUB IXboxConsole_put_ConversationTimeout_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_FindConsole_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Retries, + /* [in] */ DWORD RetryDelay); + + +void __RPC_STUB IXboxConsole_FindConsole_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_XboxManager_Proxy( + IXboxConsole * This, + /* [retval][out] */ IXboxManager **XboxManager); + + +void __RPC_STUB IXboxConsole_get_XboxManager_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_DebugTarget_Proxy( + IXboxConsole * This, + /* [retval][out] */ IXboxDebugTarget **DebugTarget); + + +void __RPC_STUB IXboxConsole_get_DebugTarget_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_Reboot_Proxy( + IXboxConsole * This, + /* [in] */ BSTR Name, + /* [in] */ BSTR MediaDirectory, + /* [in] */ BSTR CmdLine, + /* [in] */ _XboxRebootFlags Flags); + + +void __RPC_STUB IXboxConsole_Reboot_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SetDefaultTitle_Proxy( + IXboxConsole * This, + /* [in] */ BSTR TitleName, + /* [in] */ BSTR MediaDirectory, + /* [in] */ DWORD Flags); + + +void __RPC_STUB IXboxConsole_SetDefaultTitle_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_RunningProcessInfo_Proxy( + IXboxConsole * This, + /* [retval][out] */ PXBOX_PROCESS_INFO ProcessInfo); + + +void __RPC_STUB IXboxConsole_get_RunningProcessInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_OpenConnection_Proxy( + IXboxConsole * This, + /* [in] */ BSTR Handler, + /* [retval][out] */ DWORD *Connection); + + +void __RPC_STUB IXboxConsole_OpenConnection_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_CloseConnection_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection); + + +void __RPC_STUB IXboxConsole_CloseConnection_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SendTextCommand_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [in] */ BSTR Command, + /* [out] */ BSTR *Response); + + +void __RPC_STUB IXboxConsole_SendTextCommand_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReceiveSocketLine_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [out] */ BSTR *Line); + + +void __RPC_STUB IXboxConsole_ReceiveSocketLine_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReceiveStatusResponse_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [out] */ BSTR *Line, + /* [retval][out] */ HRESULT *status); + + +void __RPC_STUB IXboxConsole_ReceiveStatusResponse_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SendBinary_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [in] */ SAFEARRAY * Data, + /* [in] */ DWORD Count); + + +void __RPC_STUB IXboxConsole_SendBinary_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReceiveBinary_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [out][in] */ SAFEARRAY * Data, + /* [in] */ DWORD Count, + /* [out] */ DWORD *BytesReceived); + + +void __RPC_STUB IXboxConsole_ReceiveBinary_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SendBinary_cpp_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [size_is][in] */ BYTE *Data, + /* [in] */ DWORD Count); + + +void __RPC_STUB IXboxConsole_SendBinary_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReceiveBinary_cpp_Proxy( + IXboxConsole * This, + /* [in] */ DWORD Connection, + /* [size_is][in] */ BYTE *Data, + /* [in] */ DWORD Count, + /* [out] */ DWORD *BytesReceived); + + +void __RPC_STUB IXboxConsole_ReceiveBinary_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_Drives_Proxy( + IXboxConsole * This, + /* [retval][out] */ BSTR *Drives); + + +void __RPC_STUB IXboxConsole_get_Drives_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_GetDiskFreeSpace_Proxy( + IXboxConsole * This, + /* [in] */ WCHAR Drive, + /* [out] */ ULONGLONG *FreeBytesAvailableToCaller, + /* [out] */ ULONGLONG *TotalNumberOfBytes, + /* [out] */ ULONGLONG *TotalNumberOfFreeBytes); + + +void __RPC_STUB IXboxConsole_GetDiskFreeSpace_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_MakeDirectory_Proxy( + IXboxConsole * This, + /* [in] */ BSTR Directory); + + +void __RPC_STUB IXboxConsole_MakeDirectory_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_RemoveDirectory_Proxy( + IXboxConsole * This, + /* [in] */ BSTR Directory); + + +void __RPC_STUB IXboxConsole_RemoveDirectory_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_DirectoryFiles_Proxy( + IXboxConsole * This, + /* [in] */ BSTR Directory, + /* [retval][out] */ IXboxFiles **Files); + + +void __RPC_STUB IXboxConsole_DirectoryFiles_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SendFile_Proxy( + IXboxConsole * This, + /* [in] */ BSTR LocalName, + /* [in] */ BSTR RemoteName); + + +void __RPC_STUB IXboxConsole_SendFile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReceiveFile_Proxy( + IXboxConsole * This, + /* [in] */ BSTR LocalName, + /* [in] */ BSTR RemoteName); + + +void __RPC_STUB IXboxConsole_ReceiveFile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReadFileBytes_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [out][in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesRead); + + +void __RPC_STUB IXboxConsole_ReadFileBytes_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_WriteFileBytes_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesWritten); + + +void __RPC_STUB IXboxConsole_WriteFileBytes_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ReadFileBytes_cpp_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [length_is][size_is][out] */ BYTE *Data, + /* [out] */ DWORD *BytesRead); + + +void __RPC_STUB IXboxConsole_ReadFileBytes_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_WriteFileBytes_cpp_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ DWORD Count, + /* [size_is][in] */ BYTE *Data, + /* [out] */ DWORD *BytesWritten); + + +void __RPC_STUB IXboxConsole_WriteFileBytes_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SetFileSize_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [in] */ DWORD FileOffset, + /* [in] */ _XboxCreateDisposition CreateDisposition); + + +void __RPC_STUB IXboxConsole_SetFileSize_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_GetFileObject_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName, + /* [retval][out] */ IXboxFile **FileObject); + + +void __RPC_STUB IXboxConsole_GetFileObject_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_RenameFile_Proxy( + IXboxConsole * This, + /* [in] */ BSTR OldName, + /* [in] */ BSTR NewName); + + +void __RPC_STUB IXboxConsole_RenameFile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_DeleteFile_Proxy( + IXboxConsole * This, + /* [in] */ BSTR FileName); + + +void __RPC_STUB IXboxConsole_DeleteFile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_ScreenShot_Proxy( + IXboxConsole * This, + BSTR FileName); + + +void __RPC_STUB IXboxConsole_ScreenShot_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_DumpMode_Proxy( + IXboxConsole * This, + /* [retval][out] */ _XboxDumpMode *DumpMode); + + +void __RPC_STUB IXboxConsole_get_DumpMode_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_DumpMode_Proxy( + IXboxConsole * This, + /* [in] */ _XboxDumpMode DumpMode); + + +void __RPC_STUB IXboxConsole_put_DumpMode_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_GetDumpSettings_Proxy( + IXboxConsole * This, + /* [out] */ PXBOX_DUMP_SETTINGS DumpMode); + + +void __RPC_STUB IXboxConsole_GetDumpSettings_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_SetDumpSettings_Proxy( + IXboxConsole * This, + /* [in] */ PXBOX_DUMP_SETTINGS DumpMode); + + +void __RPC_STUB IXboxConsole_SetDumpSettings_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_EventDeferFlags_Proxy( + IXboxConsole * This, + /* [retval][out] */ _XboxEventDeferFlags *EventDeferFlags); + + +void __RPC_STUB IXboxConsole_get_EventDeferFlags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxConsole_put_EventDeferFlags_Proxy( + IXboxConsole * This, + /* [in] */ _XboxEventDeferFlags EventDeferFlags); + + +void __RPC_STUB IXboxConsole_put_EventDeferFlags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_ConsoleType_Proxy( + IXboxConsole * This, + /* [retval][out] */ _XboxConsoleType *ConsoleType); + + +void __RPC_STUB IXboxConsole_get_ConsoleType_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_StartFileEventCapture_Proxy( + IXboxConsole * This); + + +void __RPC_STUB IXboxConsole_StartFileEventCapture_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_StopFileEventCapture_Proxy( + IXboxConsole * This); + + +void __RPC_STUB IXboxConsole_StopFileEventCapture_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_XboxAutomation_Proxy( + IXboxConsole * This, + /* [retval][out] */ IXboxAutomation **Automation); + + +void __RPC_STUB IXboxConsole_get_XboxAutomation_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_LoadDebuggerExtension_Proxy( + IXboxConsole * This, + /* [in] */ BSTR ExtensionName, + /* [retval][out] */ DWORD *ModuleHandle); + + +void __RPC_STUB IXboxConsole_LoadDebuggerExtension_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxConsole_UnloadDebuggerExtension_Proxy( + IXboxConsole * This, + /* [in] */ DWORD ModuleHandle); + + +void __RPC_STUB IXboxConsole_UnloadDebuggerExtension_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxConsole_get_ConsoleFeatures_Proxy( + IXboxConsole * This, + /* [retval][out] */ _XboxConsoleFeatures *ConsoleFeatures); + + +void __RPC_STUB IXboxConsole_get_ConsoleFeatures_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxConsole_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxConsoles_INTERFACE_DEFINED__ +#define __IXboxConsoles_INTERFACE_DEFINED__ + +/* interface IXboxConsoles */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxConsoles; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("110980e4-f8d4-45f1-8a86-90d86fd4a879") + IXboxConsoles : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ BSTR *ConsoleName) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxConsolesVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxConsoles * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxConsoles * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxConsoles * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxConsoles * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxConsoles * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxConsoles * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxConsoles * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxConsoles * This, + /* [in] */ LONG Index, + /* [retval][out] */ BSTR *ConsoleName); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxConsoles * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxConsoles * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxConsolesVtbl; + + interface IXboxConsoles + { + CONST_VTBL struct IXboxConsolesVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxConsoles_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxConsoles_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxConsoles_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxConsoles_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxConsoles_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxConsoles_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxConsoles_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxConsoles_get_Item(This,Index,ConsoleName) \ + (This)->lpVtbl -> get_Item(This,Index,ConsoleName) + +#define IXboxConsoles_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxConsoles_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxConsoles_get_Item_Proxy( + IXboxConsoles * This, + /* [in] */ LONG Index, + /* [retval][out] */ BSTR *ConsoleName); + + +void __RPC_STUB IXboxConsoles_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxConsoles_get_Count_Proxy( + IXboxConsoles * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxConsoles_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxConsoles_get__NewEnum_Proxy( + IXboxConsoles * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxConsoles_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxConsoles_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxFile_INTERFACE_DEFINED__ +#define __IXboxFile_INTERFACE_DEFINED__ + +/* interface IXboxFile */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxFile; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("b9dbc76d-8a06-4eeb-84bd-1ad42f0afe28") + IXboxFile : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Name( + /* [retval][out] */ BSTR *Name) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_Name( + /* [in] */ BSTR Name) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_CreationTime( + /* [retval][out] */ VARIANT *CreationTime) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_CreationTime( + /* [in] */ VARIANT CreationTime) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ChangeTime( + /* [retval][out] */ VARIANT *ChangeTime) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_ChangeTime( + /* [in] */ VARIANT ChangeTime) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Size( + /* [retval][out] */ ULONGLONG *Size) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_Size( + /* [in] */ ULONGLONG Size) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_IsReadOnly( + /* [retval][out] */ VARIANT_BOOL *ReadOnly) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_IsReadOnly( + /* [in] */ VARIANT_BOOL ReadOnly) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_IsDirectory( + /* [retval][out] */ VARIANT_BOOL *Directory) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxFileVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxFile * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxFile * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxFile * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxFile * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxFile * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxFile * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxFile * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Name )( + IXboxFile * This, + /* [retval][out] */ BSTR *Name); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Name )( + IXboxFile * This, + /* [in] */ BSTR Name); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_CreationTime )( + IXboxFile * This, + /* [retval][out] */ VARIANT *CreationTime); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_CreationTime )( + IXboxFile * This, + /* [in] */ VARIANT CreationTime); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ChangeTime )( + IXboxFile * This, + /* [retval][out] */ VARIANT *ChangeTime); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_ChangeTime )( + IXboxFile * This, + /* [in] */ VARIANT ChangeTime); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Size )( + IXboxFile * This, + /* [retval][out] */ ULONGLONG *Size); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Size )( + IXboxFile * This, + /* [in] */ ULONGLONG Size); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsReadOnly )( + IXboxFile * This, + /* [retval][out] */ VARIANT_BOOL *ReadOnly); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsReadOnly )( + IXboxFile * This, + /* [in] */ VARIANT_BOOL ReadOnly); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsDirectory )( + IXboxFile * This, + /* [retval][out] */ VARIANT_BOOL *Directory); + + END_INTERFACE + } IXboxFileVtbl; + + interface IXboxFile + { + CONST_VTBL struct IXboxFileVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxFile_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxFile_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxFile_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxFile_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxFile_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxFile_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxFile_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxFile_get_Name(This,Name) \ + (This)->lpVtbl -> get_Name(This,Name) + +#define IXboxFile_put_Name(This,Name) \ + (This)->lpVtbl -> put_Name(This,Name) + +#define IXboxFile_get_CreationTime(This,CreationTime) \ + (This)->lpVtbl -> get_CreationTime(This,CreationTime) + +#define IXboxFile_put_CreationTime(This,CreationTime) \ + (This)->lpVtbl -> put_CreationTime(This,CreationTime) + +#define IXboxFile_get_ChangeTime(This,ChangeTime) \ + (This)->lpVtbl -> get_ChangeTime(This,ChangeTime) + +#define IXboxFile_put_ChangeTime(This,ChangeTime) \ + (This)->lpVtbl -> put_ChangeTime(This,ChangeTime) + +#define IXboxFile_get_Size(This,Size) \ + (This)->lpVtbl -> get_Size(This,Size) + +#define IXboxFile_put_Size(This,Size) \ + (This)->lpVtbl -> put_Size(This,Size) + +#define IXboxFile_get_IsReadOnly(This,ReadOnly) \ + (This)->lpVtbl -> get_IsReadOnly(This,ReadOnly) + +#define IXboxFile_put_IsReadOnly(This,ReadOnly) \ + (This)->lpVtbl -> put_IsReadOnly(This,ReadOnly) + +#define IXboxFile_get_IsDirectory(This,Directory) \ + (This)->lpVtbl -> get_IsDirectory(This,Directory) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxFile_get_Name_Proxy( + IXboxFile * This, + /* [retval][out] */ BSTR *Name); + + +void __RPC_STUB IXboxFile_get_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxFile_put_Name_Proxy( + IXboxFile * This, + /* [in] */ BSTR Name); + + +void __RPC_STUB IXboxFile_put_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxFile_get_CreationTime_Proxy( + IXboxFile * This, + /* [retval][out] */ VARIANT *CreationTime); + + +void __RPC_STUB IXboxFile_get_CreationTime_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxFile_put_CreationTime_Proxy( + IXboxFile * This, + /* [in] */ VARIANT CreationTime); + + +void __RPC_STUB IXboxFile_put_CreationTime_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxFile_get_ChangeTime_Proxy( + IXboxFile * This, + /* [retval][out] */ VARIANT *ChangeTime); + + +void __RPC_STUB IXboxFile_get_ChangeTime_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxFile_put_ChangeTime_Proxy( + IXboxFile * This, + /* [in] */ VARIANT ChangeTime); + + +void __RPC_STUB IXboxFile_put_ChangeTime_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxFile_get_Size_Proxy( + IXboxFile * This, + /* [retval][out] */ ULONGLONG *Size); + + +void __RPC_STUB IXboxFile_get_Size_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxFile_put_Size_Proxy( + IXboxFile * This, + /* [in] */ ULONGLONG Size); + + +void __RPC_STUB IXboxFile_put_Size_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxFile_get_IsReadOnly_Proxy( + IXboxFile * This, + /* [retval][out] */ VARIANT_BOOL *ReadOnly); + + +void __RPC_STUB IXboxFile_get_IsReadOnly_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxFile_put_IsReadOnly_Proxy( + IXboxFile * This, + /* [in] */ VARIANT_BOOL ReadOnly); + + +void __RPC_STUB IXboxFile_put_IsReadOnly_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxFile_get_IsDirectory_Proxy( + IXboxFile * This, + /* [retval][out] */ VARIANT_BOOL *Directory); + + +void __RPC_STUB IXboxFile_get_IsDirectory_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxFile_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxFiles_INTERFACE_DEFINED__ +#define __IXboxFiles_INTERFACE_DEFINED__ + +/* interface IXboxFiles */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxFiles; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("dfcf3f84-5394-448d-bcac-e30af6c840e1") + IXboxFiles : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ IXboxFile **File) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxFilesVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxFiles * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxFiles * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxFiles * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxFiles * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxFiles * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxFiles * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxFiles * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxFiles * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxFile **File); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxFiles * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxFiles * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxFilesVtbl; + + interface IXboxFiles + { + CONST_VTBL struct IXboxFilesVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxFiles_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxFiles_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxFiles_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxFiles_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxFiles_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxFiles_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxFiles_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxFiles_get_Item(This,Index,File) \ + (This)->lpVtbl -> get_Item(This,Index,File) + +#define IXboxFiles_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxFiles_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxFiles_get_Item_Proxy( + IXboxFiles * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxFile **File); + + +void __RPC_STUB IXboxFiles_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxFiles_get_Count_Proxy( + IXboxFiles * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxFiles_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxFiles_get__NewEnum_Proxy( + IXboxFiles * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxFiles_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxFiles_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxUser_INTERFACE_DEFINED__ +#define __IXboxUser_INTERFACE_DEFINED__ + +/* interface IXboxUser */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxUser; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("6bb90673-5c3c-4b63-8d3c-479a5ede82c3") + IXboxUser : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Name( + /* [retval][out] */ BSTR *UserName) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_Name( + /* [in] */ BSTR UserName) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_HasReadAccess( + /* [retval][out] */ VARIANT_BOOL *ReadAccess) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_HasReadAccess( + /* [in] */ VARIANT_BOOL ReadAccess) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_HasWriteAccess( + /* [retval][out] */ VARIANT_BOOL *WriteAccess) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_HasWriteAccess( + /* [in] */ VARIANT_BOOL WriteAccess) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_HasControlAccess( + /* [retval][out] */ VARIANT_BOOL *ControlAccess) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_HasControlAccess( + /* [in] */ VARIANT_BOOL ControlAccess) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_HasConfigureAccess( + /* [retval][out] */ VARIANT_BOOL *ConfigureAccess) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_HasConfigureAccess( + /* [in] */ VARIANT_BOOL ConfigureAccess) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_HasManageAccess( + /* [retval][out] */ VARIANT_BOOL *ManageAccess) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_HasManageAccess( + /* [in] */ VARIANT_BOOL ManageAccess) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxUserVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxUser * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxUser * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxUser * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxUser * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxUser * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxUser * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxUser * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Name )( + IXboxUser * This, + /* [retval][out] */ BSTR *UserName); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_Name )( + IXboxUser * This, + /* [in] */ BSTR UserName); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasReadAccess )( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ReadAccess); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_HasReadAccess )( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ReadAccess); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasWriteAccess )( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *WriteAccess); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_HasWriteAccess )( + IXboxUser * This, + /* [in] */ VARIANT_BOOL WriteAccess); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasControlAccess )( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ControlAccess); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_HasControlAccess )( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ControlAccess); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasConfigureAccess )( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ConfigureAccess); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_HasConfigureAccess )( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ConfigureAccess); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasManageAccess )( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ManageAccess); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_HasManageAccess )( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ManageAccess); + + END_INTERFACE + } IXboxUserVtbl; + + interface IXboxUser + { + CONST_VTBL struct IXboxUserVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxUser_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxUser_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxUser_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxUser_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxUser_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxUser_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxUser_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxUser_get_Name(This,UserName) \ + (This)->lpVtbl -> get_Name(This,UserName) + +#define IXboxUser_put_Name(This,UserName) \ + (This)->lpVtbl -> put_Name(This,UserName) + +#define IXboxUser_get_HasReadAccess(This,ReadAccess) \ + (This)->lpVtbl -> get_HasReadAccess(This,ReadAccess) + +#define IXboxUser_put_HasReadAccess(This,ReadAccess) \ + (This)->lpVtbl -> put_HasReadAccess(This,ReadAccess) + +#define IXboxUser_get_HasWriteAccess(This,WriteAccess) \ + (This)->lpVtbl -> get_HasWriteAccess(This,WriteAccess) + +#define IXboxUser_put_HasWriteAccess(This,WriteAccess) \ + (This)->lpVtbl -> put_HasWriteAccess(This,WriteAccess) + +#define IXboxUser_get_HasControlAccess(This,ControlAccess) \ + (This)->lpVtbl -> get_HasControlAccess(This,ControlAccess) + +#define IXboxUser_put_HasControlAccess(This,ControlAccess) \ + (This)->lpVtbl -> put_HasControlAccess(This,ControlAccess) + +#define IXboxUser_get_HasConfigureAccess(This,ConfigureAccess) \ + (This)->lpVtbl -> get_HasConfigureAccess(This,ConfigureAccess) + +#define IXboxUser_put_HasConfigureAccess(This,ConfigureAccess) \ + (This)->lpVtbl -> put_HasConfigureAccess(This,ConfigureAccess) + +#define IXboxUser_get_HasManageAccess(This,ManageAccess) \ + (This)->lpVtbl -> get_HasManageAccess(This,ManageAccess) + +#define IXboxUser_put_HasManageAccess(This,ManageAccess) \ + (This)->lpVtbl -> put_HasManageAccess(This,ManageAccess) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxUser_get_Name_Proxy( + IXboxUser * This, + /* [retval][out] */ BSTR *UserName); + + +void __RPC_STUB IXboxUser_get_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxUser_put_Name_Proxy( + IXboxUser * This, + /* [in] */ BSTR UserName); + + +void __RPC_STUB IXboxUser_put_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxUser_get_HasReadAccess_Proxy( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ReadAccess); + + +void __RPC_STUB IXboxUser_get_HasReadAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxUser_put_HasReadAccess_Proxy( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ReadAccess); + + +void __RPC_STUB IXboxUser_put_HasReadAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxUser_get_HasWriteAccess_Proxy( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *WriteAccess); + + +void __RPC_STUB IXboxUser_get_HasWriteAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxUser_put_HasWriteAccess_Proxy( + IXboxUser * This, + /* [in] */ VARIANT_BOOL WriteAccess); + + +void __RPC_STUB IXboxUser_put_HasWriteAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxUser_get_HasControlAccess_Proxy( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ControlAccess); + + +void __RPC_STUB IXboxUser_get_HasControlAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxUser_put_HasControlAccess_Proxy( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ControlAccess); + + +void __RPC_STUB IXboxUser_put_HasControlAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxUser_get_HasConfigureAccess_Proxy( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ConfigureAccess); + + +void __RPC_STUB IXboxUser_get_HasConfigureAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxUser_put_HasConfigureAccess_Proxy( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ConfigureAccess); + + +void __RPC_STUB IXboxUser_put_HasConfigureAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxUser_get_HasManageAccess_Proxy( + IXboxUser * This, + /* [retval][out] */ VARIANT_BOOL *ManageAccess); + + +void __RPC_STUB IXboxUser_get_HasManageAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxUser_put_HasManageAccess_Proxy( + IXboxUser * This, + /* [in] */ VARIANT_BOOL ManageAccess); + + +void __RPC_STUB IXboxUser_put_HasManageAccess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxUser_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxUsers_INTERFACE_DEFINED__ +#define __IXboxUsers_INTERFACE_DEFINED__ + +/* interface IXboxUsers */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxUsers; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("d5ee3179-7955-41b4-a507-bd78efc462c9") + IXboxUsers : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ IXboxUser **User) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxUsersVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxUsers * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxUsers * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxUsers * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxUsers * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxUsers * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxUsers * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxUsers * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxUsers * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxUser **User); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxUsers * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxUsers * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxUsersVtbl; + + interface IXboxUsers + { + CONST_VTBL struct IXboxUsersVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxUsers_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxUsers_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxUsers_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxUsers_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxUsers_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxUsers_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxUsers_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxUsers_get_Item(This,Index,User) \ + (This)->lpVtbl -> get_Item(This,Index,User) + +#define IXboxUsers_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxUsers_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxUsers_get_Item_Proxy( + IXboxUsers * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxUser **User); + + +void __RPC_STUB IXboxUsers_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxUsers_get_Count_Proxy( + IXboxUsers * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxUsers_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxUsers_get__NewEnum_Proxy( + IXboxUsers * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxUsers_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxUsers_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxDebugTarget_INTERFACE_DEFINED__ +#define __IXboxDebugTarget_INTERFACE_DEFINED__ + +/* interface IXboxDebugTarget */ +/* [helpstring][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxDebugTarget; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("43ccafd7-4636-43aa-b468-b7f6edca6651") + IXboxDebugTarget : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Name( + /* [retval][out] */ BSTR *Name) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_IsDump( + /* [retval][out] */ VARIANT_BOOL *IsDump) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_XboxManager( + /* [retval][out] */ IXboxManager **XboxManager) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Console( + /* [retval][out] */ IXboxConsole **Console) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ConnectAsDebugger( + /* [in] */ BSTR DebuggerName, + /* [in] */ _XboxDebugConnectFlags Flags) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE DisconnectAsDebugger( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsDebuggerConnected( + /* [out] */ BSTR *DebuggerName, + /* [out] */ BSTR *UserName, + /* [retval][out] */ VARIANT_BOOL *Connected) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Modules( + /* [retval][out] */ IXboxModules **Modules) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Threads( + /* [retval][out] */ IXboxThreads **Threads) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetMemory( + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToRead, + /* [out][in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesRead) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetMemory( + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToWrite, + /* [in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesWritten) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE GetMemory_cpp( + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToRead, + /* [length_is][size_is][out] */ BYTE *Data, + /* [out] */ DWORD *BytesRead) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE SetMemory_cpp( + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToWrite, + /* [size_is][in] */ BYTE *Data, + /* [out] */ DWORD *BytesWritten) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE InvalidateMemoryCache( + /* [in] */ VARIANT_BOOL ExecutablePages, + /* [in] */ DWORD Address, + /* [in] */ DWORD Size) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_MemoryCacheEnabled( + /* [retval][out] */ VARIANT_BOOL *Enabled) = 0; + + virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_MemoryCacheEnabled( + /* [in] */ VARIANT_BOOL Enabled) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_MemoryRegions( + /* [retval][out] */ IXboxMemoryRegions **MemoryRegions) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_RunningProcessInfo( + /* [retval][out] */ PXBOX_PROCESS_INFO ProcessInfo) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE StopOn( + /* [in] */ _XboxStopOnFlags StopOn, + /* [in] */ VARIANT_BOOL Stop) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Stop( + /* [out] */ VARIANT_BOOL *AlreadyStopped) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Go( + /* [out] */ VARIANT_BOOL *NotStopped) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetBreakpoint( + /* [in] */ DWORD Address) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RemoveBreakpoint( + /* [in] */ DWORD Address) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE RemoveAllBreakpoints( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetInitialBreakpoint( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetDataBreakpoint( + /* [in] */ DWORD Address, + /* [in] */ _XboxBreakpointType Type, + /* [in] */ DWORD Size) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsBreakpoint( + /* [in] */ DWORD Address, + /* [out] */ _XboxBreakpointType *Type) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE WriteDump( + /* [in] */ BSTR Filename, + /* [in] */ _XboxDumpFlags Type) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE CopyEventInfo( + /* [out] */ XBOX_EVENT_INFO *EventInfoDest, + /* [in] */ XBOX_EVENT_INFO *EventInfoSource) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE FreeEventInfo( + /* [out][in] */ XBOX_EVENT_INFO *EventInfo) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE PgoStartDataCollection( + DWORD PgoModule) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE PgoStopDataCollection( + DWORD PgoModule) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE PgoSaveSnapshot( + BSTR Phase, + VARIANT_BOOL Reset, + DWORD PgoModule) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE PgoSetAllocScale( + DWORD PgoModule, + DWORD BufferAllocScale) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxDebugTargetVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxDebugTarget * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxDebugTarget * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxDebugTarget * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxDebugTarget * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxDebugTarget * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxDebugTarget * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxDebugTarget * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Name )( + IXboxDebugTarget * This, + /* [retval][out] */ BSTR *Name); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsDump )( + IXboxDebugTarget * This, + /* [retval][out] */ VARIANT_BOOL *IsDump); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_XboxManager )( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxManager **XboxManager); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Console )( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxConsole **Console); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ConnectAsDebugger )( + IXboxDebugTarget * This, + /* [in] */ BSTR DebuggerName, + /* [in] */ _XboxDebugConnectFlags Flags); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *DisconnectAsDebugger )( + IXboxDebugTarget * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *IsDebuggerConnected )( + IXboxDebugTarget * This, + /* [out] */ BSTR *DebuggerName, + /* [out] */ BSTR *UserName, + /* [retval][out] */ VARIANT_BOOL *Connected); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Modules )( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxModules **Modules); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Threads )( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxThreads **Threads); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetMemory )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToRead, + /* [out][in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesRead); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetMemory )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToWrite, + /* [in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesWritten); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *GetMemory_cpp )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToRead, + /* [length_is][size_is][out] */ BYTE *Data, + /* [out] */ DWORD *BytesRead); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *SetMemory_cpp )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToWrite, + /* [size_is][in] */ BYTE *Data, + /* [out] */ DWORD *BytesWritten); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *InvalidateMemoryCache )( + IXboxDebugTarget * This, + /* [in] */ VARIANT_BOOL ExecutablePages, + /* [in] */ DWORD Address, + /* [in] */ DWORD Size); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_MemoryCacheEnabled )( + IXboxDebugTarget * This, + /* [retval][out] */ VARIANT_BOOL *Enabled); + + /* [id][propput] */ HRESULT ( STDMETHODCALLTYPE *put_MemoryCacheEnabled )( + IXboxDebugTarget * This, + /* [in] */ VARIANT_BOOL Enabled); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_MemoryRegions )( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxMemoryRegions **MemoryRegions); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_RunningProcessInfo )( + IXboxDebugTarget * This, + /* [retval][out] */ PXBOX_PROCESS_INFO ProcessInfo); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *StopOn )( + IXboxDebugTarget * This, + /* [in] */ _XboxStopOnFlags StopOn, + /* [in] */ VARIANT_BOOL Stop); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Stop )( + IXboxDebugTarget * This, + /* [out] */ VARIANT_BOOL *AlreadyStopped); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Go )( + IXboxDebugTarget * This, + /* [out] */ VARIANT_BOOL *NotStopped); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetBreakpoint )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RemoveBreakpoint )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *RemoveAllBreakpoints )( + IXboxDebugTarget * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetInitialBreakpoint )( + IXboxDebugTarget * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetDataBreakpoint )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ _XboxBreakpointType Type, + /* [in] */ DWORD Size); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *IsBreakpoint )( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [out] */ _XboxBreakpointType *Type); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *WriteDump )( + IXboxDebugTarget * This, + /* [in] */ BSTR Filename, + /* [in] */ _XboxDumpFlags Type); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *CopyEventInfo )( + IXboxDebugTarget * This, + /* [out] */ XBOX_EVENT_INFO *EventInfoDest, + /* [in] */ XBOX_EVENT_INFO *EventInfoSource); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *FreeEventInfo )( + IXboxDebugTarget * This, + /* [out][in] */ XBOX_EVENT_INFO *EventInfo); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *PgoStartDataCollection )( + IXboxDebugTarget * This, + DWORD PgoModule); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *PgoStopDataCollection )( + IXboxDebugTarget * This, + DWORD PgoModule); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *PgoSaveSnapshot )( + IXboxDebugTarget * This, + BSTR Phase, + VARIANT_BOOL Reset, + DWORD PgoModule); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *PgoSetAllocScale )( + IXboxDebugTarget * This, + DWORD PgoModule, + DWORD BufferAllocScale); + + END_INTERFACE + } IXboxDebugTargetVtbl; + + interface IXboxDebugTarget + { + CONST_VTBL struct IXboxDebugTargetVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxDebugTarget_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxDebugTarget_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxDebugTarget_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxDebugTarget_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxDebugTarget_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxDebugTarget_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxDebugTarget_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxDebugTarget_get_Name(This,Name) \ + (This)->lpVtbl -> get_Name(This,Name) + +#define IXboxDebugTarget_get_IsDump(This,IsDump) \ + (This)->lpVtbl -> get_IsDump(This,IsDump) + +#define IXboxDebugTarget_get_XboxManager(This,XboxManager) \ + (This)->lpVtbl -> get_XboxManager(This,XboxManager) + +#define IXboxDebugTarget_get_Console(This,Console) \ + (This)->lpVtbl -> get_Console(This,Console) + +#define IXboxDebugTarget_ConnectAsDebugger(This,DebuggerName,Flags) \ + (This)->lpVtbl -> ConnectAsDebugger(This,DebuggerName,Flags) + +#define IXboxDebugTarget_DisconnectAsDebugger(This) \ + (This)->lpVtbl -> DisconnectAsDebugger(This) + +#define IXboxDebugTarget_IsDebuggerConnected(This,DebuggerName,UserName,Connected) \ + (This)->lpVtbl -> IsDebuggerConnected(This,DebuggerName,UserName,Connected) + +#define IXboxDebugTarget_get_Modules(This,Modules) \ + (This)->lpVtbl -> get_Modules(This,Modules) + +#define IXboxDebugTarget_get_Threads(This,Threads) \ + (This)->lpVtbl -> get_Threads(This,Threads) + +#define IXboxDebugTarget_GetMemory(This,Address,BytesToRead,Data,BytesRead) \ + (This)->lpVtbl -> GetMemory(This,Address,BytesToRead,Data,BytesRead) + +#define IXboxDebugTarget_SetMemory(This,Address,BytesToWrite,Data,BytesWritten) \ + (This)->lpVtbl -> SetMemory(This,Address,BytesToWrite,Data,BytesWritten) + +#define IXboxDebugTarget_GetMemory_cpp(This,Address,BytesToRead,Data,BytesRead) \ + (This)->lpVtbl -> GetMemory_cpp(This,Address,BytesToRead,Data,BytesRead) + +#define IXboxDebugTarget_SetMemory_cpp(This,Address,BytesToWrite,Data,BytesWritten) \ + (This)->lpVtbl -> SetMemory_cpp(This,Address,BytesToWrite,Data,BytesWritten) + +#define IXboxDebugTarget_InvalidateMemoryCache(This,ExecutablePages,Address,Size) \ + (This)->lpVtbl -> InvalidateMemoryCache(This,ExecutablePages,Address,Size) + +#define IXboxDebugTarget_get_MemoryCacheEnabled(This,Enabled) \ + (This)->lpVtbl -> get_MemoryCacheEnabled(This,Enabled) + +#define IXboxDebugTarget_put_MemoryCacheEnabled(This,Enabled) \ + (This)->lpVtbl -> put_MemoryCacheEnabled(This,Enabled) + +#define IXboxDebugTarget_get_MemoryRegions(This,MemoryRegions) \ + (This)->lpVtbl -> get_MemoryRegions(This,MemoryRegions) + +#define IXboxDebugTarget_get_RunningProcessInfo(This,ProcessInfo) \ + (This)->lpVtbl -> get_RunningProcessInfo(This,ProcessInfo) + +#define IXboxDebugTarget_StopOn(This,StopOn,Stop) \ + (This)->lpVtbl -> StopOn(This,StopOn,Stop) + +#define IXboxDebugTarget_Stop(This,AlreadyStopped) \ + (This)->lpVtbl -> Stop(This,AlreadyStopped) + +#define IXboxDebugTarget_Go(This,NotStopped) \ + (This)->lpVtbl -> Go(This,NotStopped) + +#define IXboxDebugTarget_SetBreakpoint(This,Address) \ + (This)->lpVtbl -> SetBreakpoint(This,Address) + +#define IXboxDebugTarget_RemoveBreakpoint(This,Address) \ + (This)->lpVtbl -> RemoveBreakpoint(This,Address) + +#define IXboxDebugTarget_RemoveAllBreakpoints(This) \ + (This)->lpVtbl -> RemoveAllBreakpoints(This) + +#define IXboxDebugTarget_SetInitialBreakpoint(This) \ + (This)->lpVtbl -> SetInitialBreakpoint(This) + +#define IXboxDebugTarget_SetDataBreakpoint(This,Address,Type,Size) \ + (This)->lpVtbl -> SetDataBreakpoint(This,Address,Type,Size) + +#define IXboxDebugTarget_IsBreakpoint(This,Address,Type) \ + (This)->lpVtbl -> IsBreakpoint(This,Address,Type) + +#define IXboxDebugTarget_WriteDump(This,Filename,Type) \ + (This)->lpVtbl -> WriteDump(This,Filename,Type) + +#define IXboxDebugTarget_CopyEventInfo(This,EventInfoDest,EventInfoSource) \ + (This)->lpVtbl -> CopyEventInfo(This,EventInfoDest,EventInfoSource) + +#define IXboxDebugTarget_FreeEventInfo(This,EventInfo) \ + (This)->lpVtbl -> FreeEventInfo(This,EventInfo) + +#define IXboxDebugTarget_PgoStartDataCollection(This,PgoModule) \ + (This)->lpVtbl -> PgoStartDataCollection(This,PgoModule) + +#define IXboxDebugTarget_PgoStopDataCollection(This,PgoModule) \ + (This)->lpVtbl -> PgoStopDataCollection(This,PgoModule) + +#define IXboxDebugTarget_PgoSaveSnapshot(This,Phase,Reset,PgoModule) \ + (This)->lpVtbl -> PgoSaveSnapshot(This,Phase,Reset,PgoModule) + +#define IXboxDebugTarget_PgoSetAllocScale(This,PgoModule,BufferAllocScale) \ + (This)->lpVtbl -> PgoSetAllocScale(This,PgoModule,BufferAllocScale) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_Name_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ BSTR *Name); + + +void __RPC_STUB IXboxDebugTarget_get_Name_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_IsDump_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ VARIANT_BOOL *IsDump); + + +void __RPC_STUB IXboxDebugTarget_get_IsDump_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_XboxManager_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxManager **XboxManager); + + +void __RPC_STUB IXboxDebugTarget_get_XboxManager_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_Console_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxConsole **Console); + + +void __RPC_STUB IXboxDebugTarget_get_Console_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_ConnectAsDebugger_Proxy( + IXboxDebugTarget * This, + /* [in] */ BSTR DebuggerName, + /* [in] */ _XboxDebugConnectFlags Flags); + + +void __RPC_STUB IXboxDebugTarget_ConnectAsDebugger_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_DisconnectAsDebugger_Proxy( + IXboxDebugTarget * This); + + +void __RPC_STUB IXboxDebugTarget_DisconnectAsDebugger_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_IsDebuggerConnected_Proxy( + IXboxDebugTarget * This, + /* [out] */ BSTR *DebuggerName, + /* [out] */ BSTR *UserName, + /* [retval][out] */ VARIANT_BOOL *Connected); + + +void __RPC_STUB IXboxDebugTarget_IsDebuggerConnected_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_Modules_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxModules **Modules); + + +void __RPC_STUB IXboxDebugTarget_get_Modules_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_Threads_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxThreads **Threads); + + +void __RPC_STUB IXboxDebugTarget_get_Threads_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_GetMemory_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToRead, + /* [out][in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesRead); + + +void __RPC_STUB IXboxDebugTarget_GetMemory_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_SetMemory_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToWrite, + /* [in] */ SAFEARRAY * Data, + /* [out] */ DWORD *BytesWritten); + + +void __RPC_STUB IXboxDebugTarget_SetMemory_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_GetMemory_cpp_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToRead, + /* [length_is][size_is][out] */ BYTE *Data, + /* [out] */ DWORD *BytesRead); + + +void __RPC_STUB IXboxDebugTarget_GetMemory_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_SetMemory_cpp_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ DWORD BytesToWrite, + /* [size_is][in] */ BYTE *Data, + /* [out] */ DWORD *BytesWritten); + + +void __RPC_STUB IXboxDebugTarget_SetMemory_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_InvalidateMemoryCache_Proxy( + IXboxDebugTarget * This, + /* [in] */ VARIANT_BOOL ExecutablePages, + /* [in] */ DWORD Address, + /* [in] */ DWORD Size); + + +void __RPC_STUB IXboxDebugTarget_InvalidateMemoryCache_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_MemoryCacheEnabled_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ VARIANT_BOOL *Enabled); + + +void __RPC_STUB IXboxDebugTarget_get_MemoryCacheEnabled_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propput] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_put_MemoryCacheEnabled_Proxy( + IXboxDebugTarget * This, + /* [in] */ VARIANT_BOOL Enabled); + + +void __RPC_STUB IXboxDebugTarget_put_MemoryCacheEnabled_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_MemoryRegions_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ IXboxMemoryRegions **MemoryRegions); + + +void __RPC_STUB IXboxDebugTarget_get_MemoryRegions_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_get_RunningProcessInfo_Proxy( + IXboxDebugTarget * This, + /* [retval][out] */ PXBOX_PROCESS_INFO ProcessInfo); + + +void __RPC_STUB IXboxDebugTarget_get_RunningProcessInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_StopOn_Proxy( + IXboxDebugTarget * This, + /* [in] */ _XboxStopOnFlags StopOn, + /* [in] */ VARIANT_BOOL Stop); + + +void __RPC_STUB IXboxDebugTarget_StopOn_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_Stop_Proxy( + IXboxDebugTarget * This, + /* [out] */ VARIANT_BOOL *AlreadyStopped); + + +void __RPC_STUB IXboxDebugTarget_Stop_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_Go_Proxy( + IXboxDebugTarget * This, + /* [out] */ VARIANT_BOOL *NotStopped); + + +void __RPC_STUB IXboxDebugTarget_Go_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_SetBreakpoint_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address); + + +void __RPC_STUB IXboxDebugTarget_SetBreakpoint_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_RemoveBreakpoint_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address); + + +void __RPC_STUB IXboxDebugTarget_RemoveBreakpoint_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_RemoveAllBreakpoints_Proxy( + IXboxDebugTarget * This); + + +void __RPC_STUB IXboxDebugTarget_RemoveAllBreakpoints_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_SetInitialBreakpoint_Proxy( + IXboxDebugTarget * This); + + +void __RPC_STUB IXboxDebugTarget_SetInitialBreakpoint_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_SetDataBreakpoint_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [in] */ _XboxBreakpointType Type, + /* [in] */ DWORD Size); + + +void __RPC_STUB IXboxDebugTarget_SetDataBreakpoint_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_IsBreakpoint_Proxy( + IXboxDebugTarget * This, + /* [in] */ DWORD Address, + /* [out] */ _XboxBreakpointType *Type); + + +void __RPC_STUB IXboxDebugTarget_IsBreakpoint_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_WriteDump_Proxy( + IXboxDebugTarget * This, + /* [in] */ BSTR Filename, + /* [in] */ _XboxDumpFlags Type); + + +void __RPC_STUB IXboxDebugTarget_WriteDump_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_CopyEventInfo_Proxy( + IXboxDebugTarget * This, + /* [out] */ XBOX_EVENT_INFO *EventInfoDest, + /* [in] */ XBOX_EVENT_INFO *EventInfoSource); + + +void __RPC_STUB IXboxDebugTarget_CopyEventInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_FreeEventInfo_Proxy( + IXboxDebugTarget * This, + /* [out][in] */ XBOX_EVENT_INFO *EventInfo); + + +void __RPC_STUB IXboxDebugTarget_FreeEventInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_PgoStartDataCollection_Proxy( + IXboxDebugTarget * This, + DWORD PgoModule); + + +void __RPC_STUB IXboxDebugTarget_PgoStartDataCollection_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_PgoStopDataCollection_Proxy( + IXboxDebugTarget * This, + DWORD PgoModule); + + +void __RPC_STUB IXboxDebugTarget_PgoStopDataCollection_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_PgoSaveSnapshot_Proxy( + IXboxDebugTarget * This, + BSTR Phase, + VARIANT_BOOL Reset, + DWORD PgoModule); + + +void __RPC_STUB IXboxDebugTarget_PgoSaveSnapshot_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxDebugTarget_PgoSetAllocScale_Proxy( + IXboxDebugTarget * This, + DWORD PgoModule, + DWORD BufferAllocScale); + + +void __RPC_STUB IXboxDebugTarget_PgoSetAllocScale_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxDebugTarget_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_xdevkit_0271 */ +/* [local] */ + +namespace eXboxAutomationButtonFlags { +/* [v1_enum] */ +enum XboxAutomationButtonFlags + { DPadUp = 0x1, + DPadDown = 0x2, + DPadLeft = 0x4, + DPadRight = 0x8, + StartButton = 0x10, + BackButton = 0x20, + LeftThumbButton = 0x40, + RightThumbButton = 0x80, + LeftShoulderButton = 0x100, + RightShoulderButton = 0x200, + A_Button = 0x1000, + B_Button = 0x2000, + X_Button = 0x4000, + Y_Button = 0x8000, + Xbox360_Button = 0x400, + Bind_Button = 0x800 + } ; +} +/* +typedef enum XboxAutomationButtonFlags _XboxAutomationButtonFlags; + +*/ typedef int _XboxAutomationButtonFlags; +typedef struct XBOX_AUTOMATION_GAMEPAD + { + _XboxAutomationButtonFlags Buttons; + DWORD LeftTrigger; + DWORD RightTrigger; + long LeftThumbX; + long LeftThumbY; + long RightThumbX; + long RightThumbY; + } XBOX_AUTOMATION_GAMEPAD; + +typedef struct XBOX_AUTOMATION_GAMEPAD *PXBOX_AUTOMATION_GAMEPAD; + + + +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0271_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0271_v0_0_s_ifspec; + +#ifndef __IXboxAutomation_INTERFACE_DEFINED__ +#define __IXboxAutomation_INTERFACE_DEFINED__ + +/* interface IXboxAutomation */ +/* [helpstring][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxAutomation; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("D81F3E2E-8304-4024-8997-BB1C893516B0") + IXboxAutomation : public IDispatch + { + public: + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetInputProcess( + /* [in] */ DWORD UserIndex, + /* [out] */ VARIANT_BOOL *SystemProcess) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE BindController( + /* [in] */ DWORD UserIndex, + /* [in] */ DWORD QueueLength) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE UnbindController( + /* [in] */ DWORD UserIndex) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ConnectController( + /* [in] */ DWORD UserIndex) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE DisconnectController( + /* [in] */ DWORD UserIndex) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetGamepadState( + /* [in] */ DWORD UserIndex, + /* [in] */ PXBOX_AUTOMATION_GAMEPAD Gamepad) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE QueueGamepadState_cpp( + /* [in] */ DWORD UserIndex, + /* [size_is][in] */ PXBOX_AUTOMATION_GAMEPAD GamepadArray, + /* [size_is][in] */ DWORD *TimedDurationArray, + /* [size_is][in] */ DWORD *CountDurationArray, + /* [in] */ DWORD ItemCount, + /* [out] */ DWORD *ItemsAddedToQueue) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE QueueGamepadState( + /* [in] */ DWORD UserIndex, + /* [in] */ XBOX_AUTOMATION_GAMEPAD *Gamepad, + /* [in] */ DWORD TimedDuration, + /* [in] */ DWORD CountDuration, + /* [retval][out] */ VARIANT_BOOL *AddedToQueue) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE ClearGamepadQueue( + /* [in] */ DWORD UserIndex) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE QueryGamepadQueue( + /* [in] */ DWORD UserIndex, + /* [out] */ DWORD *QueueLength, + /* [out] */ DWORD *ItemsInQueue, + /* [out] */ DWORD *TimedDurationRemaining, + /* [out] */ DWORD *CountDurationRemaining) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetUserDefaultProfile( + /* [out] */ LONGLONG *Xuid) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetUserDefaultProfile( + /* [in] */ LONGLONG Xuid) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxAutomationVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxAutomation * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxAutomation * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxAutomation * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxAutomation * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxAutomation * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxAutomation * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxAutomation * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetInputProcess )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [out] */ VARIANT_BOOL *SystemProcess); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *BindController )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [in] */ DWORD QueueLength); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *UnbindController )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ConnectController )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *DisconnectController )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetGamepadState )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [in] */ PXBOX_AUTOMATION_GAMEPAD Gamepad); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *QueueGamepadState_cpp )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [size_is][in] */ PXBOX_AUTOMATION_GAMEPAD GamepadArray, + /* [size_is][in] */ DWORD *TimedDurationArray, + /* [size_is][in] */ DWORD *CountDurationArray, + /* [in] */ DWORD ItemCount, + /* [out] */ DWORD *ItemsAddedToQueue); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *QueueGamepadState )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [in] */ XBOX_AUTOMATION_GAMEPAD *Gamepad, + /* [in] */ DWORD TimedDuration, + /* [in] */ DWORD CountDuration, + /* [retval][out] */ VARIANT_BOOL *AddedToQueue); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *ClearGamepadQueue )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *QueryGamepadQueue )( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [out] */ DWORD *QueueLength, + /* [out] */ DWORD *ItemsInQueue, + /* [out] */ DWORD *TimedDurationRemaining, + /* [out] */ DWORD *CountDurationRemaining); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetUserDefaultProfile )( + IXboxAutomation * This, + /* [out] */ LONGLONG *Xuid); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetUserDefaultProfile )( + IXboxAutomation * This, + /* [in] */ LONGLONG Xuid); + + END_INTERFACE + } IXboxAutomationVtbl; + + interface IXboxAutomation + { + CONST_VTBL struct IXboxAutomationVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxAutomation_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxAutomation_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxAutomation_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxAutomation_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxAutomation_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxAutomation_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxAutomation_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxAutomation_GetInputProcess(This,UserIndex,SystemProcess) \ + (This)->lpVtbl -> GetInputProcess(This,UserIndex,SystemProcess) + +#define IXboxAutomation_BindController(This,UserIndex,QueueLength) \ + (This)->lpVtbl -> BindController(This,UserIndex,QueueLength) + +#define IXboxAutomation_UnbindController(This,UserIndex) \ + (This)->lpVtbl -> UnbindController(This,UserIndex) + +#define IXboxAutomation_ConnectController(This,UserIndex) \ + (This)->lpVtbl -> ConnectController(This,UserIndex) + +#define IXboxAutomation_DisconnectController(This,UserIndex) \ + (This)->lpVtbl -> DisconnectController(This,UserIndex) + +#define IXboxAutomation_SetGamepadState(This,UserIndex,Gamepad) \ + (This)->lpVtbl -> SetGamepadState(This,UserIndex,Gamepad) + +#define IXboxAutomation_QueueGamepadState_cpp(This,UserIndex,GamepadArray,TimedDurationArray,CountDurationArray,ItemCount,ItemsAddedToQueue) \ + (This)->lpVtbl -> QueueGamepadState_cpp(This,UserIndex,GamepadArray,TimedDurationArray,CountDurationArray,ItemCount,ItemsAddedToQueue) + +#define IXboxAutomation_QueueGamepadState(This,UserIndex,Gamepad,TimedDuration,CountDuration,AddedToQueue) \ + (This)->lpVtbl -> QueueGamepadState(This,UserIndex,Gamepad,TimedDuration,CountDuration,AddedToQueue) + +#define IXboxAutomation_ClearGamepadQueue(This,UserIndex) \ + (This)->lpVtbl -> ClearGamepadQueue(This,UserIndex) + +#define IXboxAutomation_QueryGamepadQueue(This,UserIndex,QueueLength,ItemsInQueue,TimedDurationRemaining,CountDurationRemaining) \ + (This)->lpVtbl -> QueryGamepadQueue(This,UserIndex,QueueLength,ItemsInQueue,TimedDurationRemaining,CountDurationRemaining) + +#define IXboxAutomation_GetUserDefaultProfile(This,Xuid) \ + (This)->lpVtbl -> GetUserDefaultProfile(This,Xuid) + +#define IXboxAutomation_SetUserDefaultProfile(This,Xuid) \ + (This)->lpVtbl -> SetUserDefaultProfile(This,Xuid) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_GetInputProcess_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [out] */ VARIANT_BOOL *SystemProcess); + + +void __RPC_STUB IXboxAutomation_GetInputProcess_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_BindController_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [in] */ DWORD QueueLength); + + +void __RPC_STUB IXboxAutomation_BindController_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_UnbindController_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + +void __RPC_STUB IXboxAutomation_UnbindController_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_ConnectController_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + +void __RPC_STUB IXboxAutomation_ConnectController_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_DisconnectController_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + +void __RPC_STUB IXboxAutomation_DisconnectController_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_SetGamepadState_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [in] */ PXBOX_AUTOMATION_GAMEPAD Gamepad); + + +void __RPC_STUB IXboxAutomation_SetGamepadState_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_QueueGamepadState_cpp_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [size_is][in] */ PXBOX_AUTOMATION_GAMEPAD GamepadArray, + /* [size_is][in] */ DWORD *TimedDurationArray, + /* [size_is][in] */ DWORD *CountDurationArray, + /* [in] */ DWORD ItemCount, + /* [out] */ DWORD *ItemsAddedToQueue); + + +void __RPC_STUB IXboxAutomation_QueueGamepadState_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_QueueGamepadState_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [in] */ XBOX_AUTOMATION_GAMEPAD *Gamepad, + /* [in] */ DWORD TimedDuration, + /* [in] */ DWORD CountDuration, + /* [retval][out] */ VARIANT_BOOL *AddedToQueue); + + +void __RPC_STUB IXboxAutomation_QueueGamepadState_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_ClearGamepadQueue_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex); + + +void __RPC_STUB IXboxAutomation_ClearGamepadQueue_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_QueryGamepadQueue_Proxy( + IXboxAutomation * This, + /* [in] */ DWORD UserIndex, + /* [out] */ DWORD *QueueLength, + /* [out] */ DWORD *ItemsInQueue, + /* [out] */ DWORD *TimedDurationRemaining, + /* [out] */ DWORD *CountDurationRemaining); + + +void __RPC_STUB IXboxAutomation_QueryGamepadQueue_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_GetUserDefaultProfile_Proxy( + IXboxAutomation * This, + /* [out] */ LONGLONG *Xuid); + + +void __RPC_STUB IXboxAutomation_GetUserDefaultProfile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxAutomation_SetUserDefaultProfile_Proxy( + IXboxAutomation * This, + /* [in] */ LONGLONG Xuid); + + +void __RPC_STUB IXboxAutomation_SetUserDefaultProfile_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxAutomation_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxModule_INTERFACE_DEFINED__ +#define __IXboxModule_INTERFACE_DEFINED__ + +/* interface IXboxModule */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxModule; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("0eee2aa0-60f0-4c18-b4ed-e3933e659847") + IXboxModule : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ModuleInfo( + /* [retval][out] */ XBOX_MODULE_INFO *ModuleInfo) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Sections( + /* [retval][out] */ IXboxSections **Sections) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetFunctionInfo( + /* [in] */ DWORD Address, + /* [out] */ XBOX_FUNCTION_INFO *FunctionInfo) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_OriginalSize( + /* [retval][out] */ DWORD *OriginalSize) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Executable( + /* [retval][out] */ IXboxExecutable **Executable) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetEntryPointAddress( + /* [retval][out] */ DWORD *EntryPointAddress) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxModuleVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxModule * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxModule * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxModule * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxModule * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxModule * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxModule * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxModule * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ModuleInfo )( + IXboxModule * This, + /* [retval][out] */ XBOX_MODULE_INFO *ModuleInfo); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Sections )( + IXboxModule * This, + /* [retval][out] */ IXboxSections **Sections); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetFunctionInfo )( + IXboxModule * This, + /* [in] */ DWORD Address, + /* [out] */ XBOX_FUNCTION_INFO *FunctionInfo); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_OriginalSize )( + IXboxModule * This, + /* [retval][out] */ DWORD *OriginalSize); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Executable )( + IXboxModule * This, + /* [retval][out] */ IXboxExecutable **Executable); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetEntryPointAddress )( + IXboxModule * This, + /* [retval][out] */ DWORD *EntryPointAddress); + + END_INTERFACE + } IXboxModuleVtbl; + + interface IXboxModule + { + CONST_VTBL struct IXboxModuleVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxModule_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxModule_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxModule_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxModule_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxModule_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxModule_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxModule_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxModule_get_ModuleInfo(This,ModuleInfo) \ + (This)->lpVtbl -> get_ModuleInfo(This,ModuleInfo) + +#define IXboxModule_get_Sections(This,Sections) \ + (This)->lpVtbl -> get_Sections(This,Sections) + +#define IXboxModule_GetFunctionInfo(This,Address,FunctionInfo) \ + (This)->lpVtbl -> GetFunctionInfo(This,Address,FunctionInfo) + +#define IXboxModule_get_OriginalSize(This,OriginalSize) \ + (This)->lpVtbl -> get_OriginalSize(This,OriginalSize) + +#define IXboxModule_get_Executable(This,Executable) \ + (This)->lpVtbl -> get_Executable(This,Executable) + +#define IXboxModule_GetEntryPointAddress(This,EntryPointAddress) \ + (This)->lpVtbl -> GetEntryPointAddress(This,EntryPointAddress) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxModule_get_ModuleInfo_Proxy( + IXboxModule * This, + /* [retval][out] */ XBOX_MODULE_INFO *ModuleInfo); + + +void __RPC_STUB IXboxModule_get_ModuleInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxModule_get_Sections_Proxy( + IXboxModule * This, + /* [retval][out] */ IXboxSections **Sections); + + +void __RPC_STUB IXboxModule_get_Sections_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxModule_GetFunctionInfo_Proxy( + IXboxModule * This, + /* [in] */ DWORD Address, + /* [out] */ XBOX_FUNCTION_INFO *FunctionInfo); + + +void __RPC_STUB IXboxModule_GetFunctionInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxModule_get_OriginalSize_Proxy( + IXboxModule * This, + /* [retval][out] */ DWORD *OriginalSize); + + +void __RPC_STUB IXboxModule_get_OriginalSize_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxModule_get_Executable_Proxy( + IXboxModule * This, + /* [retval][out] */ IXboxExecutable **Executable); + + +void __RPC_STUB IXboxModule_get_Executable_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxModule_GetEntryPointAddress_Proxy( + IXboxModule * This, + /* [retval][out] */ DWORD *EntryPointAddress); + + +void __RPC_STUB IXboxModule_GetEntryPointAddress_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxModule_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxModules_INTERFACE_DEFINED__ +#define __IXboxModules_INTERFACE_DEFINED__ + +/* interface IXboxModules */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxModules; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e4f0c350-d2da-426e-adec-3d01f60fc842") + IXboxModules : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ IXboxModule **Module) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxModulesVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxModules * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxModules * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxModules * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxModules * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxModules * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxModules * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxModules * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxModules * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxModule **Module); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxModules * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxModules * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxModulesVtbl; + + interface IXboxModules + { + CONST_VTBL struct IXboxModulesVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxModules_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxModules_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxModules_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxModules_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxModules_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxModules_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxModules_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxModules_get_Item(This,Index,Module) \ + (This)->lpVtbl -> get_Item(This,Index,Module) + +#define IXboxModules_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxModules_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxModules_get_Item_Proxy( + IXboxModules * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxModule **Module); + + +void __RPC_STUB IXboxModules_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxModules_get_Count_Proxy( + IXboxModules * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxModules_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxModules_get__NewEnum_Proxy( + IXboxModules * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxModules_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxModules_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxExecutable_INTERFACE_DEFINED__ +#define __IXboxExecutable_INTERFACE_DEFINED__ + +/* interface IXboxExecutable */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxExecutable; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("4B103593-DB52-4e18-913D-B3B17824BD76") + IXboxExecutable : public IDispatch + { + public: + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetPEModuleName( + /* [retval][out] */ BSTR *ModuleName) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxExecutableVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxExecutable * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxExecutable * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxExecutable * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxExecutable * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxExecutable * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxExecutable * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxExecutable * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetPEModuleName )( + IXboxExecutable * This, + /* [retval][out] */ BSTR *ModuleName); + + END_INTERFACE + } IXboxExecutableVtbl; + + interface IXboxExecutable + { + CONST_VTBL struct IXboxExecutableVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxExecutable_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxExecutable_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxExecutable_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxExecutable_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxExecutable_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxExecutable_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxExecutable_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxExecutable_GetPEModuleName(This,ModuleName) \ + (This)->lpVtbl -> GetPEModuleName(This,ModuleName) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxExecutable_GetPEModuleName_Proxy( + IXboxExecutable * This, + /* [retval][out] */ BSTR *ModuleName); + + +void __RPC_STUB IXboxExecutable_GetPEModuleName_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxExecutable_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxSection_INTERFACE_DEFINED__ +#define __IXboxSection_INTERFACE_DEFINED__ + +/* interface IXboxSection */ +/* [helpstring][unique][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxSection; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("d6df8112-0326-4d29-a6b8-cfb0d89c358a") + IXboxSection : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_SectionInfo( + /* [retval][out] */ XBOX_SECTION_INFO *SectionInfo) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxSectionVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxSection * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxSection * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxSection * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxSection * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxSection * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxSection * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxSection * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_SectionInfo )( + IXboxSection * This, + /* [retval][out] */ XBOX_SECTION_INFO *SectionInfo); + + END_INTERFACE + } IXboxSectionVtbl; + + interface IXboxSection + { + CONST_VTBL struct IXboxSectionVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxSection_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxSection_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxSection_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxSection_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxSection_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxSection_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxSection_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxSection_get_SectionInfo(This,SectionInfo) \ + (This)->lpVtbl -> get_SectionInfo(This,SectionInfo) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxSection_get_SectionInfo_Proxy( + IXboxSection * This, + /* [retval][out] */ XBOX_SECTION_INFO *SectionInfo); + + +void __RPC_STUB IXboxSection_get_SectionInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxSection_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxSections_INTERFACE_DEFINED__ +#define __IXboxSections_INTERFACE_DEFINED__ + +/* interface IXboxSections */ +/* [helpstring][unique][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxSections; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("9762df66-9516-4531-a507-a11034056f5e") + IXboxSections : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ IXboxSection **Section) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxSectionsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxSections * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxSections * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxSections * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxSections * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxSections * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxSections * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxSections * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxSections * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxSection **Section); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxSections * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxSections * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxSectionsVtbl; + + interface IXboxSections + { + CONST_VTBL struct IXboxSectionsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxSections_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxSections_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxSections_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxSections_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxSections_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxSections_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxSections_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxSections_get_Item(This,Index,Section) \ + (This)->lpVtbl -> get_Item(This,Index,Section) + +#define IXboxSections_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxSections_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxSections_get_Item_Proxy( + IXboxSections * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxSection **Section); + + +void __RPC_STUB IXboxSections_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxSections_get_Count_Proxy( + IXboxSections * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxSections_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxSections_get__NewEnum_Proxy( + IXboxSections * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxSections_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxSections_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxThread_INTERFACE_DEFINED__ +#define __IXboxThread_INTERFACE_DEFINED__ + +/* interface IXboxThread */ +/* [helpstring][unique][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxThread; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("8f1e63f5-85ba-4b2d-ad9c-1fa6b750d57f") + IXboxThread : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ThreadId( + /* [retval][out] */ DWORD *ThreadId) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ThreadInfo( + /* [retval][out] */ XBOX_THREAD_INFO *ThreadInfo) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_StopEventInfo( + /* [retval][out] */ PXBOX_EVENT_INFO StopEventInfo) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_TopOfStack( + /* [retval][out] */ IXboxStackFrame **StackFrame) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Halt( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Continue( + /* [in] */ VARIANT_BOOL Exception) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Suspend( void) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE Resume( void) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_CurrentProcessor( + /* [retval][out] */ DWORD *Processor) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_LastError( + /* [retval][out] */ DWORD *LastError) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxThreadVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxThread * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxThread * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxThread * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxThread * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxThread * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxThread * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxThread * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ThreadId )( + IXboxThread * This, + /* [retval][out] */ DWORD *ThreadId); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ThreadInfo )( + IXboxThread * This, + /* [retval][out] */ XBOX_THREAD_INFO *ThreadInfo); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_StopEventInfo )( + IXboxThread * This, + /* [retval][out] */ PXBOX_EVENT_INFO StopEventInfo); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_TopOfStack )( + IXboxThread * This, + /* [retval][out] */ IXboxStackFrame **StackFrame); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Halt )( + IXboxThread * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Continue )( + IXboxThread * This, + /* [in] */ VARIANT_BOOL Exception); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Suspend )( + IXboxThread * This); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *Resume )( + IXboxThread * This); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_CurrentProcessor )( + IXboxThread * This, + /* [retval][out] */ DWORD *Processor); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_LastError )( + IXboxThread * This, + /* [retval][out] */ DWORD *LastError); + + END_INTERFACE + } IXboxThreadVtbl; + + interface IXboxThread + { + CONST_VTBL struct IXboxThreadVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxThread_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxThread_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxThread_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxThread_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxThread_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxThread_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxThread_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxThread_get_ThreadId(This,ThreadId) \ + (This)->lpVtbl -> get_ThreadId(This,ThreadId) + +#define IXboxThread_get_ThreadInfo(This,ThreadInfo) \ + (This)->lpVtbl -> get_ThreadInfo(This,ThreadInfo) + +#define IXboxThread_get_StopEventInfo(This,StopEventInfo) \ + (This)->lpVtbl -> get_StopEventInfo(This,StopEventInfo) + +#define IXboxThread_get_TopOfStack(This,StackFrame) \ + (This)->lpVtbl -> get_TopOfStack(This,StackFrame) + +#define IXboxThread_Halt(This) \ + (This)->lpVtbl -> Halt(This) + +#define IXboxThread_Continue(This,Exception) \ + (This)->lpVtbl -> Continue(This,Exception) + +#define IXboxThread_Suspend(This) \ + (This)->lpVtbl -> Suspend(This) + +#define IXboxThread_Resume(This) \ + (This)->lpVtbl -> Resume(This) + +#define IXboxThread_get_CurrentProcessor(This,Processor) \ + (This)->lpVtbl -> get_CurrentProcessor(This,Processor) + +#define IXboxThread_get_LastError(This,LastError) \ + (This)->lpVtbl -> get_LastError(This,LastError) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxThread_get_ThreadId_Proxy( + IXboxThread * This, + /* [retval][out] */ DWORD *ThreadId); + + +void __RPC_STUB IXboxThread_get_ThreadId_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxThread_get_ThreadInfo_Proxy( + IXboxThread * This, + /* [retval][out] */ XBOX_THREAD_INFO *ThreadInfo); + + +void __RPC_STUB IXboxThread_get_ThreadInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxThread_get_StopEventInfo_Proxy( + IXboxThread * This, + /* [retval][out] */ PXBOX_EVENT_INFO StopEventInfo); + + +void __RPC_STUB IXboxThread_get_StopEventInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxThread_get_TopOfStack_Proxy( + IXboxThread * This, + /* [retval][out] */ IXboxStackFrame **StackFrame); + + +void __RPC_STUB IXboxThread_get_TopOfStack_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxThread_Halt_Proxy( + IXboxThread * This); + + +void __RPC_STUB IXboxThread_Halt_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxThread_Continue_Proxy( + IXboxThread * This, + /* [in] */ VARIANT_BOOL Exception); + + +void __RPC_STUB IXboxThread_Continue_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxThread_Suspend_Proxy( + IXboxThread * This); + + +void __RPC_STUB IXboxThread_Suspend_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxThread_Resume_Proxy( + IXboxThread * This); + + +void __RPC_STUB IXboxThread_Resume_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxThread_get_CurrentProcessor_Proxy( + IXboxThread * This, + /* [retval][out] */ DWORD *Processor); + + +void __RPC_STUB IXboxThread_get_CurrentProcessor_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxThread_get_LastError_Proxy( + IXboxThread * This, + /* [retval][out] */ DWORD *LastError); + + +void __RPC_STUB IXboxThread_get_LastError_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxThread_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxThreads_INTERFACE_DEFINED__ +#define __IXboxThreads_INTERFACE_DEFINED__ + +/* interface IXboxThreads */ +/* [helpstring][unique][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxThreads; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("da7c0784-9a34-4a9e-a040-59ebcea92c1e") + IXboxThreads : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ IXboxThread **Thread) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxThreadsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxThreads * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxThreads * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxThreads * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxThreads * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxThreads * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxThreads * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxThreads * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxThreads * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxThread **Thread); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxThreads * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxThreads * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxThreadsVtbl; + + interface IXboxThreads + { + CONST_VTBL struct IXboxThreadsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxThreads_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxThreads_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxThreads_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxThreads_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxThreads_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxThreads_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxThreads_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxThreads_get_Item(This,Index,Thread) \ + (This)->lpVtbl -> get_Item(This,Index,Thread) + +#define IXboxThreads_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxThreads_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxThreads_get_Item_Proxy( + IXboxThreads * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxThread **Thread); + + +void __RPC_STUB IXboxThreads_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxThreads_get_Count_Proxy( + IXboxThreads * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxThreads_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxThreads_get__NewEnum_Proxy( + IXboxThreads * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxThreads_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxThreads_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_xdevkit_0279 */ +/* [local] */ + +namespace eXboxRegisters32{ +/* [v1_enum] */ +enum XboxRegisters32 + { msr = 0, + iar = msr + 1, + lr = iar + 1, + cr = lr + 1, + xer = cr + 1 + } ; +} +/* +typedef enum XboxRegisters32 _XboxRegisters32; + +*/ typedef eXboxRegisters32::XboxRegisters32 _XboxRegisters32; +namespace eXboxRegisters64{ +/* [v1_enum] */ +enum XboxRegisters64 + { ctr = 0, + r0 = ctr + 1, + r1 = r0 + 1, + r2 = r1 + 1, + r3 = r2 + 1, + r4 = r3 + 1, + r5 = r4 + 1, + r6 = r5 + 1, + r7 = r6 + 1, + r8 = r7 + 1, + r9 = r8 + 1, + r10 = r9 + 1, + r11 = r10 + 1, + r12 = r11 + 1, + r13 = r12 + 1, + r14 = r13 + 1, + r15 = r14 + 1, + r16 = r15 + 1, + r17 = r16 + 1, + r18 = r17 + 1, + r19 = r18 + 1, + r20 = r19 + 1, + r21 = r20 + 1, + r22 = r21 + 1, + r23 = r22 + 1, + r24 = r23 + 1, + r25 = r24 + 1, + r26 = r25 + 1, + r27 = r26 + 1, + r28 = r27 + 1, + r29 = r28 + 1, + r30 = r29 + 1, + r31 = r30 + 1 + } ; +} +/* +typedef enum XboxRegisters64 _XboxRegisters64; + +*/ typedef eXboxRegisters64::XboxRegisters64 _XboxRegisters64; +namespace eXboxRegistersDouble{ +/* [v1_enum] */ +enum XboxRegistersDouble + { fp0 = 0, + fp1 = fp0 + 1, + fp2 = fp1 + 1, + fp3 = fp2 + 1, + fp4 = fp3 + 1, + fp5 = fp4 + 1, + fp6 = fp5 + 1, + fp7 = fp6 + 1, + fp8 = fp7 + 1, + fp9 = fp8 + 1, + fp10 = fp9 + 1, + fp11 = fp10 + 1, + fp12 = fp11 + 1, + fp13 = fp12 + 1, + fp14 = fp13 + 1, + fp15 = fp14 + 1, + fp16 = fp15 + 1, + fp17 = fp16 + 1, + fp18 = fp17 + 1, + fp19 = fp18 + 1, + fp20 = fp19 + 1, + fp21 = fp20 + 1, + fp22 = fp21 + 1, + fp23 = fp22 + 1, + fp24 = fp23 + 1, + fp25 = fp24 + 1, + fp26 = fp25 + 1, + fp27 = fp26 + 1, + fp28 = fp27 + 1, + fp29 = fp28 + 1, + fp30 = fp29 + 1, + fp31 = fp30 + 1, + fpscr = fp31 + 1 + } ; +} +/* +typedef enum XboxRegistersDouble _XboxRegistersDouble; + +*/ typedef eXboxRegistersDouble::XboxRegistersDouble _XboxRegistersDouble; +namespace eXboxRegistersVector{ +/* [v1_enum] */ +enum XboxRegistersVector + { v0 = 0, + v1 = v0 + 1, + v2 = v1 + 1, + v3 = v2 + 1, + v4 = v3 + 1, + v5 = v4 + 1, + v6 = v5 + 1, + v7 = v6 + 1, + v8 = v7 + 1, + v9 = v8 + 1, + v10 = v9 + 1, + v11 = v10 + 1, + v12 = v11 + 1, + v13 = v12 + 1, + v14 = v13 + 1, + v15 = v14 + 1, + v16 = v15 + 1, + v17 = v16 + 1, + v18 = v17 + 1, + v19 = v18 + 1, + v20 = v19 + 1, + v21 = v20 + 1, + v22 = v21 + 1, + v23 = v22 + 1, + v24 = v23 + 1, + v25 = v24 + 1, + v26 = v25 + 1, + v27 = v26 + 1, + v28 = v27 + 1, + v29 = v28 + 1, + v30 = v29 + 1, + v31 = v30 + 1, + v32 = v31 + 1, + v33 = v32 + 1, + v34 = v33 + 1, + v35 = v34 + 1, + v36 = v35 + 1, + v37 = v36 + 1, + v38 = v37 + 1, + v39 = v38 + 1, + v40 = v39 + 1, + v41 = v40 + 1, + v42 = v41 + 1, + v43 = v42 + 1, + v44 = v43 + 1, + v45 = v44 + 1, + v46 = v45 + 1, + v47 = v46 + 1, + v48 = v47 + 1, + v49 = v48 + 1, + v50 = v49 + 1, + v51 = v50 + 1, + v52 = v51 + 1, + v53 = v52 + 1, + v54 = v53 + 1, + v55 = v54 + 1, + v56 = v55 + 1, + v57 = v56 + 1, + v58 = v57 + 1, + v59 = v58 + 1, + v60 = v59 + 1, + v61 = v60 + 1, + v62 = v61 + 1, + v63 = v62 + 1, + v64 = v63 + 1, + v65 = v64 + 1, + v66 = v65 + 1, + v67 = v66 + 1, + v68 = v67 + 1, + v69 = v68 + 1, + v70 = v69 + 1, + v71 = v70 + 1, + v72 = v71 + 1, + v73 = v72 + 1, + v74 = v73 + 1, + v75 = v74 + 1, + v76 = v75 + 1, + v77 = v76 + 1, + v78 = v77 + 1, + v79 = v78 + 1, + v80 = v79 + 1, + v81 = v80 + 1, + v82 = v81 + 1, + v83 = v82 + 1, + v84 = v83 + 1, + v85 = v84 + 1, + v86 = v85 + 1, + v87 = v86 + 1, + v88 = v87 + 1, + v89 = v88 + 1, + v90 = v89 + 1, + v91 = v90 + 1, + v92 = v91 + 1, + v93 = v92 + 1, + v94 = v93 + 1, + v95 = v94 + 1, + v96 = v95 + 1, + v97 = v96 + 1, + v98 = v97 + 1, + v99 = v98 + 1, + v100 = v99 + 1, + v101 = v100 + 1, + v102 = v101 + 1, + v103 = v102 + 1, + v104 = v103 + 1, + v105 = v104 + 1, + v106 = v105 + 1, + v107 = v106 + 1, + v108 = v107 + 1, + v109 = v108 + 1, + v110 = v109 + 1, + v111 = v110 + 1, + v112 = v111 + 1, + v113 = v112 + 1, + v114 = v113 + 1, + v115 = v114 + 1, + v116 = v115 + 1, + v117 = v116 + 1, + v118 = v117 + 1, + v119 = v118 + 1, + v120 = v119 + 1, + v121 = v120 + 1, + v122 = v121 + 1, + v123 = v122 + 1, + v124 = v123 + 1, + v125 = v124 + 1, + v126 = v125 + 1, + v127 = v126 + 1, + vscr = v127 + 1 + } ; +} +/* +typedef enum XboxRegistersVector _XboxRegistersVector; + +*/ typedef eXboxRegistersVector::XboxRegistersVector _XboxRegistersVector; + + +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0279_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0279_v0_0_s_ifspec; + +#ifndef __IXboxStackFrame_INTERFACE_DEFINED__ +#define __IXboxStackFrame_INTERFACE_DEFINED__ + +/* interface IXboxStackFrame */ +/* [helpstring][unique][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxStackFrame; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("eabf8976-1a2f-4aaa-bbbb-3ecab03b2ee9") + IXboxStackFrame : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_TopOfStack( + /* [retval][out] */ VARIANT_BOOL *TopOfStack) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Dirty( + /* [retval][out] */ VARIANT_BOOL *Dirty) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_NextStackFrame( + /* [retval][out] */ IXboxStackFrame **StackFrame) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetRegister32( + /* [in] */ _XboxRegisters32 Register, + /* [out] */ LONG *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetRegister32( + /* [in] */ _XboxRegisters32 Register, + /* [in] */ LONG Value) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetRegister64( + /* [in] */ _XboxRegisters64 Register, + /* [out] */ LONGLONG *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetRegister64( + /* [in] */ _XboxRegisters64 Register, + /* [in] */ LONGLONG Value) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetRegisterDouble( + /* [in] */ _XboxRegistersDouble Register, + /* [out] */ double *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetRegisterDouble( + /* [in] */ _XboxRegistersDouble Register, + /* [in] */ double Value) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE GetRegisterVector_cpp( + /* [in] */ _XboxRegistersVector Register, + /* [length_is][size_is][out] */ float *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid) = 0; + + virtual /* [hidden][id] */ HRESULT STDMETHODCALLTYPE SetRegisterVector_cpp( + /* [in] */ _XboxRegistersVector Register, + /* [length_is][size_is][in] */ float *Value) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetRegisterVector( + /* [in] */ _XboxRegistersVector Register, + SAFEARRAY * Value, + /* [retval][out] */ VARIANT_BOOL *IsValid) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetRegisterVector( + /* [in] */ _XboxRegistersVector Register, + SAFEARRAY * Value) = 0; + + virtual /* [id] */ HRESULT STDMETHODCALLTYPE FlushRegisterChanges( void) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_FunctionInfo( + /* [retval][out] */ XBOX_FUNCTION_INFO *FunctionInfo) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_StackPointer( + /* [retval][out] */ DWORD *StackPointer) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_ReturnAddress( + /* [retval][out] */ DWORD *ReturnAddress) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxStackFrameVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxStackFrame * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxStackFrame * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxStackFrame * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxStackFrame * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxStackFrame * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxStackFrame * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxStackFrame * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_TopOfStack )( + IXboxStackFrame * This, + /* [retval][out] */ VARIANT_BOOL *TopOfStack); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Dirty )( + IXboxStackFrame * This, + /* [retval][out] */ VARIANT_BOOL *Dirty); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_NextStackFrame )( + IXboxStackFrame * This, + /* [retval][out] */ IXboxStackFrame **StackFrame); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetRegister32 )( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters32 Register, + /* [out] */ LONG *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetRegister32 )( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters32 Register, + /* [in] */ LONG Value); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetRegister64 )( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters64 Register, + /* [out] */ LONGLONG *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetRegister64 )( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters64 Register, + /* [in] */ LONGLONG Value); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetRegisterDouble )( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersDouble Register, + /* [out] */ double *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetRegisterDouble )( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersDouble Register, + /* [in] */ double Value); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *GetRegisterVector_cpp )( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + /* [length_is][size_is][out] */ float *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + /* [hidden][id] */ HRESULT ( STDMETHODCALLTYPE *SetRegisterVector_cpp )( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + /* [length_is][size_is][in] */ float *Value); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *GetRegisterVector )( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + SAFEARRAY * Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *SetRegisterVector )( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + SAFEARRAY * Value); + + /* [id] */ HRESULT ( STDMETHODCALLTYPE *FlushRegisterChanges )( + IXboxStackFrame * This); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_FunctionInfo )( + IXboxStackFrame * This, + /* [retval][out] */ XBOX_FUNCTION_INFO *FunctionInfo); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_StackPointer )( + IXboxStackFrame * This, + /* [retval][out] */ DWORD *StackPointer); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_ReturnAddress )( + IXboxStackFrame * This, + /* [retval][out] */ DWORD *ReturnAddress); + + END_INTERFACE + } IXboxStackFrameVtbl; + + interface IXboxStackFrame + { + CONST_VTBL struct IXboxStackFrameVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxStackFrame_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxStackFrame_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxStackFrame_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxStackFrame_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxStackFrame_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxStackFrame_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxStackFrame_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxStackFrame_get_TopOfStack(This,TopOfStack) \ + (This)->lpVtbl -> get_TopOfStack(This,TopOfStack) + +#define IXboxStackFrame_get_Dirty(This,Dirty) \ + (This)->lpVtbl -> get_Dirty(This,Dirty) + +#define IXboxStackFrame_get_NextStackFrame(This,StackFrame) \ + (This)->lpVtbl -> get_NextStackFrame(This,StackFrame) + +#define IXboxStackFrame_GetRegister32(This,Register,Value,IsValid) \ + (This)->lpVtbl -> GetRegister32(This,Register,Value,IsValid) + +#define IXboxStackFrame_SetRegister32(This,Register,Value) \ + (This)->lpVtbl -> SetRegister32(This,Register,Value) + +#define IXboxStackFrame_GetRegister64(This,Register,Value,IsValid) \ + (This)->lpVtbl -> GetRegister64(This,Register,Value,IsValid) + +#define IXboxStackFrame_SetRegister64(This,Register,Value) \ + (This)->lpVtbl -> SetRegister64(This,Register,Value) + +#define IXboxStackFrame_GetRegisterDouble(This,Register,Value,IsValid) \ + (This)->lpVtbl -> GetRegisterDouble(This,Register,Value,IsValid) + +#define IXboxStackFrame_SetRegisterDouble(This,Register,Value) \ + (This)->lpVtbl -> SetRegisterDouble(This,Register,Value) + +#define IXboxStackFrame_GetRegisterVector_cpp(This,Register,Value,IsValid) \ + (This)->lpVtbl -> GetRegisterVector_cpp(This,Register,Value,IsValid) + +#define IXboxStackFrame_SetRegisterVector_cpp(This,Register,Value) \ + (This)->lpVtbl -> SetRegisterVector_cpp(This,Register,Value) + +#define IXboxStackFrame_GetRegisterVector(This,Register,Value,IsValid) \ + (This)->lpVtbl -> GetRegisterVector(This,Register,Value,IsValid) + +#define IXboxStackFrame_SetRegisterVector(This,Register,Value) \ + (This)->lpVtbl -> SetRegisterVector(This,Register,Value) + +#define IXboxStackFrame_FlushRegisterChanges(This) \ + (This)->lpVtbl -> FlushRegisterChanges(This) + +#define IXboxStackFrame_get_FunctionInfo(This,FunctionInfo) \ + (This)->lpVtbl -> get_FunctionInfo(This,FunctionInfo) + +#define IXboxStackFrame_get_StackPointer(This,StackPointer) \ + (This)->lpVtbl -> get_StackPointer(This,StackPointer) + +#define IXboxStackFrame_get_ReturnAddress(This,ReturnAddress) \ + (This)->lpVtbl -> get_ReturnAddress(This,ReturnAddress) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_get_TopOfStack_Proxy( + IXboxStackFrame * This, + /* [retval][out] */ VARIANT_BOOL *TopOfStack); + + +void __RPC_STUB IXboxStackFrame_get_TopOfStack_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_get_Dirty_Proxy( + IXboxStackFrame * This, + /* [retval][out] */ VARIANT_BOOL *Dirty); + + +void __RPC_STUB IXboxStackFrame_get_Dirty_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_get_NextStackFrame_Proxy( + IXboxStackFrame * This, + /* [retval][out] */ IXboxStackFrame **StackFrame); + + +void __RPC_STUB IXboxStackFrame_get_NextStackFrame_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_GetRegister32_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters32 Register, + /* [out] */ LONG *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + +void __RPC_STUB IXboxStackFrame_GetRegister32_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_SetRegister32_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters32 Register, + /* [in] */ LONG Value); + + +void __RPC_STUB IXboxStackFrame_SetRegister32_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_GetRegister64_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters64 Register, + /* [out] */ LONGLONG *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + +void __RPC_STUB IXboxStackFrame_GetRegister64_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_SetRegister64_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegisters64 Register, + /* [in] */ LONGLONG Value); + + +void __RPC_STUB IXboxStackFrame_SetRegister64_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_GetRegisterDouble_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersDouble Register, + /* [out] */ double *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + +void __RPC_STUB IXboxStackFrame_GetRegisterDouble_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_SetRegisterDouble_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersDouble Register, + /* [in] */ double Value); + + +void __RPC_STUB IXboxStackFrame_SetRegisterDouble_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_GetRegisterVector_cpp_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + /* [length_is][size_is][out] */ float *Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + +void __RPC_STUB IXboxStackFrame_GetRegisterVector_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [hidden][id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_SetRegisterVector_cpp_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + /* [length_is][size_is][in] */ float *Value); + + +void __RPC_STUB IXboxStackFrame_SetRegisterVector_cpp_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_GetRegisterVector_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + SAFEARRAY * Value, + /* [retval][out] */ VARIANT_BOOL *IsValid); + + +void __RPC_STUB IXboxStackFrame_GetRegisterVector_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_SetRegisterVector_Proxy( + IXboxStackFrame * This, + /* [in] */ _XboxRegistersVector Register, + SAFEARRAY * Value); + + +void __RPC_STUB IXboxStackFrame_SetRegisterVector_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_FlushRegisterChanges_Proxy( + IXboxStackFrame * This); + + +void __RPC_STUB IXboxStackFrame_FlushRegisterChanges_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_get_FunctionInfo_Proxy( + IXboxStackFrame * This, + /* [retval][out] */ XBOX_FUNCTION_INFO *FunctionInfo); + + +void __RPC_STUB IXboxStackFrame_get_FunctionInfo_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_get_StackPointer_Proxy( + IXboxStackFrame * This, + /* [retval][out] */ DWORD *StackPointer); + + +void __RPC_STUB IXboxStackFrame_get_StackPointer_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxStackFrame_get_ReturnAddress_Proxy( + IXboxStackFrame * This, + /* [retval][out] */ DWORD *ReturnAddress); + + +void __RPC_STUB IXboxStackFrame_get_ReturnAddress_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxStackFrame_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxMemoryRegions_INTERFACE_DEFINED__ +#define __IXboxMemoryRegions_INTERFACE_DEFINED__ + +/* interface IXboxMemoryRegions */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxMemoryRegions; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("7f8e857b-fd59-4b67-8156-faa3fd06d1e5") + IXboxMemoryRegions : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Item( + /* [in] */ LONG Index, + /* [retval][out] */ IXboxMemoryRegion **MemoryRegion) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Count( + /* [retval][out] */ LONG *Count) = 0; + + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get__NewEnum( + /* [retval][out] */ IEnumVARIANT **Enumerator) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxMemoryRegionsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxMemoryRegions * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxMemoryRegions * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxMemoryRegions * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxMemoryRegions * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxMemoryRegions * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxMemoryRegions * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxMemoryRegions * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Item )( + IXboxMemoryRegions * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxMemoryRegion **MemoryRegion); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Count )( + IXboxMemoryRegions * This, + /* [retval][out] */ LONG *Count); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get__NewEnum )( + IXboxMemoryRegions * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + END_INTERFACE + } IXboxMemoryRegionsVtbl; + + interface IXboxMemoryRegions + { + CONST_VTBL struct IXboxMemoryRegionsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxMemoryRegions_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxMemoryRegions_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxMemoryRegions_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxMemoryRegions_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxMemoryRegions_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxMemoryRegions_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxMemoryRegions_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxMemoryRegions_get_Item(This,Index,MemoryRegion) \ + (This)->lpVtbl -> get_Item(This,Index,MemoryRegion) + +#define IXboxMemoryRegions_get_Count(This,Count) \ + (This)->lpVtbl -> get_Count(This,Count) + +#define IXboxMemoryRegions_get__NewEnum(This,Enumerator) \ + (This)->lpVtbl -> get__NewEnum(This,Enumerator) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxMemoryRegions_get_Item_Proxy( + IXboxMemoryRegions * This, + /* [in] */ LONG Index, + /* [retval][out] */ IXboxMemoryRegion **MemoryRegion); + + +void __RPC_STUB IXboxMemoryRegions_get_Item_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxMemoryRegions_get_Count_Proxy( + IXboxMemoryRegions * This, + /* [retval][out] */ LONG *Count); + + +void __RPC_STUB IXboxMemoryRegions_get_Count_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxMemoryRegions_get__NewEnum_Proxy( + IXboxMemoryRegions * This, + /* [retval][out] */ IEnumVARIANT **Enumerator); + + +void __RPC_STUB IXboxMemoryRegions_get__NewEnum_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxMemoryRegions_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_xdevkit_0281 */ +/* [local] */ + +namespace eXboxMemoryRegionFlags{ +/* [v1_enum] */ +enum XboxMemoryRegionFlags + { NoAccess = 0x1, + ReadOnly = 0x2, + ReadWrite = 0x4, + WriteCopy = 0x8, + Execute = 0x10, + ExecuteRead = 0x20, + ExecuteReadWrite = 0x40, + ExecuteWriteCopy = 0x80, + Guard = 0x100, + NoCache = 0x200, + WriteCombine = 0x400, + UserReadOnly = 0x1000, + UserReadWrite = 0x2000 + } ; +} +/* +typedef enum XboxMemoryRegionFlags _XboxMemoryRegionFlags; + +*/ typedef int _XboxMemoryRegionFlags; + + +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0281_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0281_v0_0_s_ifspec; + +#ifndef __IXboxMemoryRegion_INTERFACE_DEFINED__ +#define __IXboxMemoryRegion_INTERFACE_DEFINED__ + +/* interface IXboxMemoryRegion */ +/* [helpstring][unique][nonextensible][oleautomation][dual][uuid][object] */ + + +EXTERN_C const IID IID_IXboxMemoryRegion; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("4f882a21-7f2a-4bea-a0a3-a3710a93deea") + IXboxMemoryRegion : public IDispatch + { + public: + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_BaseAddress( + /* [retval][out] */ LONG *BaseAddress) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_RegionSize( + /* [retval][out] */ LONG *RegionSize) = 0; + + virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_Flags( + /* [retval][out] */ _XboxMemoryRegionFlags *Flags) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxMemoryRegionVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxMemoryRegion * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxMemoryRegion * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxMemoryRegion * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxMemoryRegion * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxMemoryRegion * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxMemoryRegion * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxMemoryRegion * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_BaseAddress )( + IXboxMemoryRegion * This, + /* [retval][out] */ LONG *BaseAddress); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_RegionSize )( + IXboxMemoryRegion * This, + /* [retval][out] */ LONG *RegionSize); + + /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Flags )( + IXboxMemoryRegion * This, + /* [retval][out] */ _XboxMemoryRegionFlags *Flags); + + END_INTERFACE + } IXboxMemoryRegionVtbl; + + interface IXboxMemoryRegion + { + CONST_VTBL struct IXboxMemoryRegionVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxMemoryRegion_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxMemoryRegion_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxMemoryRegion_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxMemoryRegion_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxMemoryRegion_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxMemoryRegion_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxMemoryRegion_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxMemoryRegion_get_BaseAddress(This,BaseAddress) \ + (This)->lpVtbl -> get_BaseAddress(This,BaseAddress) + +#define IXboxMemoryRegion_get_RegionSize(This,RegionSize) \ + (This)->lpVtbl -> get_RegionSize(This,RegionSize) + +#define IXboxMemoryRegion_get_Flags(This,Flags) \ + (This)->lpVtbl -> get_Flags(This,Flags) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxMemoryRegion_get_BaseAddress_Proxy( + IXboxMemoryRegion * This, + /* [retval][out] */ LONG *BaseAddress); + + +void __RPC_STUB IXboxMemoryRegion_get_BaseAddress_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxMemoryRegion_get_RegionSize_Proxy( + IXboxMemoryRegion * This, + /* [retval][out] */ LONG *RegionSize); + + +void __RPC_STUB IXboxMemoryRegion_get_RegionSize_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +/* [id][propget] */ HRESULT STDMETHODCALLTYPE IXboxMemoryRegion_get_Flags_Proxy( + IXboxMemoryRegion * This, + /* [retval][out] */ _XboxMemoryRegionFlags *Flags); + + +void __RPC_STUB IXboxMemoryRegion_get_Flags_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxMemoryRegion_INTERFACE_DEFINED__ */ + + +#ifndef __IXboxEventInfo_INTERFACE_DEFINED__ +#define __IXboxEventInfo_INTERFACE_DEFINED__ + +/* interface IXboxEventInfo */ +/* [object][oleautomation][dual][uuid] */ + + +EXTERN_C const IID IID_IXboxEventInfo; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("85c9127a-11ed-47f2-9e87-a83058fc264a") + IXboxEventInfo : public IDispatch + { + public: + virtual /* [propget][id] */ HRESULT STDMETHODCALLTYPE get_Info( + /* [retval][out] */ PXBOX_EVENT_INFO EventInfo) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxEventInfoVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxEventInfo * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxEventInfo * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxEventInfo * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + IXboxEventInfo * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + IXboxEventInfo * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + IXboxEventInfo * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + IXboxEventInfo * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + /* [propget][id] */ HRESULT ( STDMETHODCALLTYPE *get_Info )( + IXboxEventInfo * This, + /* [retval][out] */ PXBOX_EVENT_INFO EventInfo); + + END_INTERFACE + } IXboxEventInfoVtbl; + + interface IXboxEventInfo + { + CONST_VTBL struct IXboxEventInfoVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxEventInfo_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxEventInfo_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxEventInfo_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxEventInfo_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define IXboxEventInfo_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define IXboxEventInfo_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define IXboxEventInfo_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + + +#define IXboxEventInfo_get_Info(This,EventInfo) \ + (This)->lpVtbl -> get_Info(This,EventInfo) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +/* [propget][id] */ HRESULT STDMETHODCALLTYPE IXboxEventInfo_get_Info_Proxy( + IXboxEventInfo * This, + /* [retval][out] */ PXBOX_EVENT_INFO EventInfo); + + +void __RPC_STUB IXboxEventInfo_get_Info_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxEventInfo_INTERFACE_DEFINED__ */ + + +/* interface __MIDL_itf_xdevkit_0283 */ +/* [local] */ + +#define DISPID_XBOX_EVENT ( 1 ) + +#define DISPID_XBOX_TEXT_EVENT ( 2 ) + + + +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0283_v0_0_c_ifspec; +extern RPC_IF_HANDLE __MIDL_itf_xdevkit_0283_v0_0_s_ifspec; + +#ifndef __IXboxEvents_INTERFACE_DEFINED__ +#define __IXboxEvents_INTERFACE_DEFINED__ + +/* interface IXboxEvents */ +/* [object][oleautomation][uuid] */ + + +EXTERN_C const IID IID_IXboxEvents; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e3c9d73f-9df0-4b57-8cee-05f9ca6823be") + IXboxEvents : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE OnStdNotify( + /* [in] */ _XboxDebugEventType EventCode, + /* [in] */ IXboxEventInfo *eventInfo) = 0; + + virtual HRESULT STDMETHODCALLTYPE OnTextNotify( + /* [in] */ BSTR Source, + /* [in] */ BSTR Notification) = 0; + + }; + +#else /* C style interface */ + + typedef struct IXboxEventsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + IXboxEvents * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + IXboxEvents * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + IXboxEvents * This); + + HRESULT ( STDMETHODCALLTYPE *OnStdNotify )( + IXboxEvents * This, + /* [in] */ _XboxDebugEventType EventCode, + /* [in] */ IXboxEventInfo *eventInfo); + + HRESULT ( STDMETHODCALLTYPE *OnTextNotify )( + IXboxEvents * This, + /* [in] */ BSTR Source, + /* [in] */ BSTR Notification); + + END_INTERFACE + } IXboxEventsVtbl; + + interface IXboxEvents + { + CONST_VTBL struct IXboxEventsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define IXboxEvents_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define IXboxEvents_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define IXboxEvents_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define IXboxEvents_OnStdNotify(This,EventCode,eventInfo) \ + (This)->lpVtbl -> OnStdNotify(This,EventCode,eventInfo) + +#define IXboxEvents_OnTextNotify(This,Source,Notification) \ + (This)->lpVtbl -> OnTextNotify(This,Source,Notification) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + +HRESULT STDMETHODCALLTYPE IXboxEvents_OnStdNotify_Proxy( + IXboxEvents * This, + /* [in] */ _XboxDebugEventType EventCode, + /* [in] */ IXboxEventInfo *eventInfo); + + +void __RPC_STUB IXboxEvents_OnStdNotify_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + +HRESULT STDMETHODCALLTYPE IXboxEvents_OnTextNotify_Proxy( + IXboxEvents * This, + /* [in] */ BSTR Source, + /* [in] */ BSTR Notification); + + +void __RPC_STUB IXboxEvents_OnTextNotify_Stub( + IRpcStubBuffer *This, + IRpcChannelBuffer *_pRpcChannelBuffer, + PRPC_MESSAGE _pRpcMessage, + DWORD *_pdwStubPhase); + + + +#endif /* __IXboxEvents_INTERFACE_DEFINED__ */ + + + +#ifndef __XDevkit_LIBRARY_DEFINED__ +#define __XDevkit_LIBRARY_DEFINED__ + +/* library XDevkit */ +/* [helpstring][version][uuid] */ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +EXTERN_C const IID LIBID_XDevkit; + +#ifndef __XboxEvents_DISPINTERFACE_DEFINED__ +#define __XboxEvents_DISPINTERFACE_DEFINED__ + +/* dispinterface XboxEvents */ +/* [uuid] */ + + +EXTERN_C const IID DIID_XboxEvents; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("420208df-c38c-4efb-9fc3-acd50350941e") + XboxEvents : public IDispatch + { + }; + +#else /* C style interface */ + + typedef struct XboxEventsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + XboxEvents * This, + /* [in] */ REFIID riid, + /* [iid_is][out] */ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + XboxEvents * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + XboxEvents * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + XboxEvents * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + XboxEvents * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + XboxEvents * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + XboxEvents * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + END_INTERFACE + } XboxEventsVtbl; + + interface XboxEvents + { + CONST_VTBL struct XboxEventsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define XboxEvents_QueryInterface(This,riid,ppvObject) \ + (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) + +#define XboxEvents_AddRef(This) \ + (This)->lpVtbl -> AddRef(This) + +#define XboxEvents_Release(This) \ + (This)->lpVtbl -> Release(This) + + +#define XboxEvents_GetTypeInfoCount(This,pctinfo) \ + (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) + +#define XboxEvents_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) + +#define XboxEvents_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) + +#define XboxEvents_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + +#endif /* __XboxEvents_DISPINTERFACE_DEFINED__ */ + + +EXTERN_C const CLSID CLSID_XboxConsole; + +#ifdef __cplusplus + +class DECLSPEC_UUID("3ed2b073-99a1-42db-80cc-295e9ffba18f") +XboxConsole; +#endif + +EXTERN_C const CLSID CLSID_XboxManager; + +#ifdef __cplusplus + +class DECLSPEC_UUID("a5eb45d8-f3b6-49b9-984a-0d313ab60342") +XboxManager; +#endif + +EXTERN_C const CLSID CLSID_XboxExecutableDatabase; + +#ifdef __cplusplus + +class DECLSPEC_UUID("3151B328-4A0D-4b83-950F-6861AB6B3ECD") +XboxExecutableDatabase; +#endif +#endif /* __XDevkit_LIBRARY_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +unsigned long __RPC_USER BSTR_UserSize( unsigned long *, unsigned long , BSTR * ); +unsigned char * __RPC_USER BSTR_UserMarshal( unsigned long *, unsigned char *, BSTR * ); +unsigned char * __RPC_USER BSTR_UserUnmarshal(unsigned long *, unsigned char *, BSTR * ); +void __RPC_USER BSTR_UserFree( unsigned long *, BSTR * ); + +unsigned long __RPC_USER LPSAFEARRAY_UserSize( unsigned long *, unsigned long , LPSAFEARRAY * ); +unsigned char * __RPC_USER LPSAFEARRAY_UserMarshal( unsigned long *, unsigned char *, LPSAFEARRAY * ); +unsigned char * __RPC_USER LPSAFEARRAY_UserUnmarshal(unsigned long *, unsigned char *, LPSAFEARRAY * ); +void __RPC_USER LPSAFEARRAY_UserFree( unsigned long *, LPSAFEARRAY * ); + +unsigned long __RPC_USER VARIANT_UserSize( unsigned long *, unsigned long , VARIANT * ); +unsigned char * __RPC_USER VARIANT_UserMarshal( unsigned long *, unsigned char *, VARIANT * ); +unsigned char * __RPC_USER VARIANT_UserUnmarshal(unsigned long *, unsigned char *, VARIANT * ); +void __RPC_USER VARIANT_UserFree( unsigned long *, VARIANT * ); + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/third_party/xbox_sdk/include/XDevkit.idl b/third_party/xbox_sdk/include/XDevkit.idl new file mode 100644 index 0000000..c531aa8 --- /dev/null +++ b/third_party/xbox_sdk/include/XDevkit.idl @@ -0,0 +1,1547 @@ +// XKDebug.idl : IDL source for XKDebug +// + +// This file will be processed by the MIDL tool to +// produce the type library (XKDebug.tlb) and marshalling code. + +import "oaidl.idl"; +import "ocidl.idl"; + +interface IXboxManager; +interface IXboxExecutableDatabase; +interface IXboxConsole; +interface IXboxConsoles; +interface IXboxUser; +interface IXboxUsers; +interface IXboxFile; +interface IXboxFiles; + +interface IXboxDebugTarget; +interface IXboxModule; +interface IXboxModules; +interface IXboxSection; +interface IXboxSections; +interface IXboxThread; +interface IXboxThreads; +interface IXboxMemoryRegions; +interface IXboxMemoryRegion; +interface IXboxStackFrame; +interface IXboxEvents; +interface IXboxExecutable; + +interface IXboxAutomation; + + +// +// Macros for generating HRESULTS. These should match those in xbdm.h +// + +cpp_quote("#define FACILITY_XDEVKIT 0x2da") +cpp_quote("#ifndef MAKE_HRESULT") +cpp_quote("#define MAKE_HRESULT(sev,fac,code) ((HRESULT)(((unsigned long)sev<<31)|((unsigned long)fac<<16)|((unsigned long)code)))") +cpp_quote("#endif") +cpp_quote("#define MAKE_E_XDEVKIT(code) MAKE_HRESULT(1, FACILITY_XDEVKIT, code)") +cpp_quote("#define MAKE_S_XDEVKIT(code) MAKE_HRESULT(0, FACILITY_XDEVKIT, code)") + +// +// Success codes +// + +cpp_quote("#define S_XDEVKIT_NOERR MAKE_S_XDEVKIT(0)") +cpp_quote("#define S_XDEVKIT_CONNECTED MAKE_S_XDEVKIT(1)") +cpp_quote("#define S_XDEVKIT_MULTIRESPONSE MAKE_S_XDEVKIT(2)") +cpp_quote("#define S_XDEVKIT_BINRESPONSE MAKE_S_XDEVKIT(3)") +cpp_quote("#define S_XDEVKIT_READYFORBIN MAKE_S_XDEVKIT(4)") +cpp_quote("#define S_XDEVKIT_DEDICATED MAKE_S_XDEVKIT(5)") +cpp_quote("#define S_XDEVKIT_PROFILERESTARTED MAKE_S_XDEVKIT(6)") +cpp_quote("#define S_XDEVKIT_FASTCAPENABLED MAKE_S_XDEVKIT(7)") +cpp_quote("#define S_XDEVKIT_CALLCAPENABLED MAKE_S_XDEVKIT(8)") + +// +// Errors (non-wire) +// + +cpp_quote("#define E_XDEVKIT_UNDEFINED MAKE_E_XDEVKIT(0)") +cpp_quote("#define E_XDEVKIT_MAXCONNECT MAKE_E_XDEVKIT(1)") +cpp_quote("#define E_XDEVKIT_NOSUCHFILE MAKE_E_XDEVKIT(2)") +cpp_quote("#define E_XDEVKIT_NOMODULE MAKE_E_XDEVKIT(3)") +cpp_quote("#define E_XDEVKIT_MEMUNMAPPED MAKE_E_XDEVKIT(4)") +cpp_quote("#define E_XDEVKIT_NOTHREAD MAKE_E_XDEVKIT(5)") +cpp_quote("#define E_XDEVKIT_CLOCKNOTSET MAKE_E_XDEVKIT(6)") +cpp_quote("#define E_XDEVKIT_INVALIDCMD MAKE_E_XDEVKIT(7)") +cpp_quote("#define E_XDEVKIT_NOTSTOPPED MAKE_E_XDEVKIT(8)") +cpp_quote("#define E_XDEVKIT_MUSTCOPY MAKE_E_XDEVKIT(9)") +cpp_quote("#define E_XDEVKIT_ALREADYEXISTS MAKE_E_XDEVKIT(10)") +cpp_quote("#define E_XDEVKIT_DIRNOTEMPTY MAKE_E_XDEVKIT(11)") +cpp_quote("#define E_XDEVKIT_BADFILENAME MAKE_E_XDEVKIT(12)") +cpp_quote("#define E_XDEVKIT_CANNOTCREATE MAKE_E_XDEVKIT(13)") +cpp_quote("#define E_XDEVKIT_CANNOTACCESS MAKE_E_XDEVKIT(14)") +cpp_quote("#define E_XDEVKIT_DEVICEFULL MAKE_E_XDEVKIT(15)") +cpp_quote("#define E_XDEVKIT_NOTDEBUGGABLE MAKE_E_XDEVKIT(16)") +cpp_quote("#define E_XDEVKIT_BADCOUNTTYPE MAKE_E_XDEVKIT(17)") +cpp_quote("#define E_XDEVKIT_COUNTUNAVAILABLE MAKE_E_XDEVKIT(18)") +cpp_quote("#define E_XDEVKIT_NOTLOCKED MAKE_E_XDEVKIT(20)") +cpp_quote("#define E_XDEVKIT_KEYXCHG MAKE_E_XDEVKIT(21)") +cpp_quote("#define E_XDEVKIT_MUSTBEDEDICATED MAKE_E_XDEVKIT(22)") +cpp_quote("#define E_XDEVKIT_INVALIDARG MAKE_E_XDEVKIT(23)") +cpp_quote("#define E_XDEVKIT_PROFILENOTSTARTED MAKE_E_XDEVKIT(24)") +cpp_quote("#define E_XDEVKIT_PROFILEALREADYSTARTED MAKE_E_XDEVKIT(25)") +cpp_quote("#define E_XDEVKIT_ALREADYSTOPPED MAKE_E_XDEVKIT(26)") +cpp_quote("#define E_XDEVKIT_FASTCAPNOTENABLED MAKE_E_XDEVKIT(27)") +cpp_quote("#define E_XDEVKIT_NOMEMORY MAKE_E_XDEVKIT(28)") +cpp_quote("#define E_XDEVKIT_TIMEOUT MAKE_E_XDEVKIT(29)") +cpp_quote("#define E_XDEVKIT_NOSUCHPATH MAKE_E_XDEVKIT(30)") +cpp_quote("#define E_XDEVKIT_INVALID_SCREEN_INPUT_FORMAT MAKE_E_XDEVKIT(31)") +cpp_quote("#define E_XDEVKIT_INVALID_SCREEN_OUTPUT_FORMAT MAKE_E_XDEVKIT(32)") +cpp_quote("#define E_XDEVKIT_CALLCAPNOTENABLED MAKE_E_XDEVKIT(33)") +cpp_quote("#define E_XDEVKIT_INVALIDCAPCFG MAKE_E_XDEVKIT(34)") +cpp_quote("#define E_XDEVKIT_CAPNOTENABLED MAKE_E_XDEVKIT(35)") +cpp_quote("#define E_XDEVKIT_TOOBIGJUMP MAKE_E_XDEVKIT(36)") +cpp_quote("#define E_XDEVKIT_OUTPUTBUFFERTOOSMALL MAKE_E_XDEVKIT(38)") +cpp_quote("#define E_XDEVKIT_PROFILEREBOOT MAKE_E_XDEVKIT(39)") +cpp_quote("#define E_XDEVKIT_MAXDURATIONEXCEEDED MAKE_E_XDEVKIT(41)") +cpp_quote("#define E_XDEVKIT_INVALIDSTATE MAKE_E_XDEVKIT(42)") +cpp_quote("#define E_XDEVKIT_MAXEXTENSIONS MAKE_E_XDEVKIT(43)") +cpp_quote("#define E_XDEVKIT_PMCSESSIONALREADYACTIVE MAKE_E_XDEVKIT(44)") +cpp_quote("#define E_XDEVKIT_PMCSESSIONNOTACTIVE MAKE_E_XDEVKIT(45)") +cpp_quote("#define E_XDEVKIT_LINE_TOO_LONG MAKE_E_XDEVKIT(46)") +cpp_quote("#define E_XDEVKIT_D3D_DEBUG_COMMAND_NOT_IMPLEMENTED MAKE_E_XDEVKIT(0x50)") +cpp_quote("#define E_XDEVKIT_D3D_INVALID_SURFACE MAKE_E_XDEVKIT(0x51)") + +// +// Errors (wire) +// + +cpp_quote("#define E_XDEVKIT_CANNOTCONNECT MAKE_E_XDEVKIT(0x100)") +cpp_quote("#define E_XDEVKIT_CONNECTIONLOST MAKE_E_XDEVKIT(0x101)") +cpp_quote("#define E_XDEVKIT_FILEERROR MAKE_E_XDEVKIT(0x103)") +cpp_quote("#define E_XDEVKIT_ENDOFLIST MAKE_E_XDEVKIT(0x104)") +cpp_quote("#define E_XDEVKIT_BUFFER_TOO_SMALL MAKE_E_XDEVKIT(0x105)") +cpp_quote("#define E_XDEVKIT_NOTXBEFILE MAKE_E_XDEVKIT(0x106)") +cpp_quote("#define E_XDEVKIT_MEMSETINCOMPLETE MAKE_E_XDEVKIT(0x107)") +cpp_quote("#define E_XDEVKIT_NOXBOXNAME MAKE_E_XDEVKIT(0x108)") +cpp_quote("#define E_XDEVKIT_NOERRORSTRING MAKE_E_XDEVKIT(0x109)") +cpp_quote("#define E_XDEVKIT_INVALIDSTATUS MAKE_E_XDEVKIT(0x10A)") +cpp_quote("#define E_XDEVKIT_TASK_PENDING MAKE_E_XDEVKIT(0x150)") + +// +// Errors (PC tools) +// + +cpp_quote("#define FACILITY_XEXECDB 0x2da") +cpp_quote("#define MAKE_E_XEXECDB(code) MAKE_HRESULT(1, FACILITY_XEXECDB, code)") +cpp_quote("#define MAKE_S_XEXECDB(code) MAKE_HRESULT(0, FACILITY_XEXECDB, code)") + +cpp_quote("#define E_XEXECDB_UNRECOGNIZED_FILE MAKE_E_XEXECDB(0x400)") +cpp_quote("#define E_XEXECDB_WRONG_VERSION MAKE_E_XEXECDB(0x401)") + +typedef struct XBOX_PROCESS_INFO +{ + DWORD ProcessId; + BSTR ProgramName; +} XBOX_PROCESS_INFO, *PXBOX_PROCESS_INFO; + +cpp_quote("namespace eXboxAccessFlags {") +[v1_enum] enum XboxAccessFlags +{ + Read = 1, + Write = 2, + Control = 4, + Configure = 8, + Manage = 16 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxAccessFlags _XboxAccessFlags; +cpp_quote("*/ typedef int _XboxAccessFlags;") + +typedef struct XBOX_USER { + BSTR UserName; + _XboxAccessFlags Access; +} XBOX_USER, *PXBOX_USER; + +cpp_quote("namespace eXboxModuleInfoFlags {") +[v1_enum] enum XboxModuleInfoFlags +{ + Main = 1, + Tls = 2, + Dll = 4 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxModuleInfoFlags _XboxModuleInfoFlags; +cpp_quote("*/ typedef int _XboxModuleInfoFlags;") + + +typedef struct XBOX_MODULE_INFO +{ + BSTR Name; + BSTR FullName; + DWORD BaseAddress; + DWORD Size; + DWORD TimeStamp; + DWORD CheckSum; + _XboxModuleInfoFlags Flags; +} XBOX_MODULE_INFO, *PXBOX_MODULE_INFO; + +cpp_quote("namespace eXboxSectionInfoFlags {") +[v1_enum] enum XboxSectionInfoFlags +{ + Loaded = 1, + Readable = 2, + Writeable = 4, + Executable = 8, + Uninitialized = 16 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxSectionInfoFlags _XboxSectionInfoFlags; +cpp_quote("*/ typedef int _XboxSectionInfoFlags;") + +typedef struct XBOX_SECTION_INFO +{ + BSTR Name; + DWORD BaseAddress; + DWORD Size; + DWORD Index; + _XboxSectionInfoFlags Flags; +} XBOX_SECTION_INFO, *PXBOX_SECTION_INFO; + +typedef struct XBOX_THREAD_INFO +{ + DWORD ThreadId; + DWORD SuspendCount; + DWORD Priority; + DWORD TlsBase; + DWORD StartAddress; + DWORD StackBase; + DWORD StackLimit; + DWORD StackSlackSpace; + VARIANT CreateTime; + BSTR Name; +} XBOX_THREAD_INFO, *PXBOX_THREAD_INFO; + +cpp_quote("namespace eXboxFunctionType {") +[v1_enum] enum XboxFunctionType +{ + NoPData = 0xFFFFFFFF, + SaveMillicode = 0, + NoHandler = 1, + RestoreMillicode = 2, + Handler = 3 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxFunctionType _XboxFunctionType; +cpp_quote("*/ typedef eXboxFunctionType::XboxFunctionType _XboxFunctionType;") + +typedef struct XBOX_FUNCTION_INFO +{ + _XboxFunctionType FunctionType; + DWORD BeginAddress; + DWORD PrologEndAddress; + DWORD FunctionEndAddress; +} XBOX_FUNCTION_INFO, *PXBOX_FUNCTION_INFO; + + +cpp_quote("namespace eXboxDebugEventType {") +[v1_enum] enum XboxDebugEventType +{ + NoEvent, + ExecutionBreak, + DebugString, + ExecStateChange, + SingleStep, + ModuleLoad, + ModuleUnload, + ThreadCreate, + ThreadDestroy, + Exception, + AssertionFailed, + AssertionFailedEx, + DataBreak, + RIP, + SectionLoad, + SectionUnload, + StackTrace, + FiberCreate, + FiberDestroy, + BugCheck, + PgoModuleStartup +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxDebugEventType _XboxDebugEventType; +cpp_quote("*/ typedef eXboxDebugEventType::XboxDebugEventType _XboxDebugEventType;") + +cpp_quote("namespace eXboxExecutionState {") +[v1_enum] enum XboxExecutionState +{ + Stopped, + Running, + Rebooting, + Pending, + RebootingTitle, + PendingTitle +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxExecutionState _XboxExecutionState; +cpp_quote("*/ typedef eXboxExecutionState::XboxExecutionState _XboxExecutionState;") + +cpp_quote("// Must match DMSTOP_ constants") +cpp_quote("namespace eXboxStopOnFlags {") +[v1_enum] enum XboxStopOnFlags +{ + OnThreadCreate = 0x01, + OnFirstChanceException = 0x02, + OnDebugString = 0x04, + OnStackTrace = 0x08, + OnModuleLoad = 0x10, + OnTitleLaunch = 0x20, + OnPgoModuleStartup = 0x40 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxStopOnFlags _XboxStopOnFlags; +cpp_quote("*/ typedef int _XboxStopOnFlags;") + +cpp_quote("namespace eXboxRebootFlags {") +[v1_enum] enum XboxRebootFlags +{ + Title = 0, + Wait = 1, + Cold = 2, + [helpstring("Deprecated, use Cold")] Warm = 4, + Stop = 8 +}; +cpp_quote("#pragma deprecated(Warm)") +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxRebootFlags _XboxRebootFlags; +cpp_quote("*/ typedef int _XboxRebootFlags;") + + +cpp_quote("namespace eXboxExceptionFlags {") +[v1_enum] enum XboxExceptionFlags +{ + Noncontinuable = 1, + FirstChance = 2 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxExceptionFlags _XboxExceptionFlags; +cpp_quote("*/ typedef int _XboxExceptionFlags;") + +typedef struct XBOX_EVENT_INFO +{ + _XboxDebugEventType Event; + VARIANT_BOOL IsThreadStopped; + IXboxThread *Thread; + IXboxModule *Module; + IXboxSection *Section; + _XboxExecutionState ExecState; + BSTR Message; + DWORD Code; + DWORD Address; + _XboxExceptionFlags Flags; + DWORD ParameterCount; + DWORD Parameters[15]; +} XBOX_EVENT_INFO, *PXBOX_EVENT_INFO; + +cpp_quote("namespace eXboxBreakpointType {") +[v1_enum] enum XboxBreakpointType +{ + NoBreakpoint = 0, + OnWrite, + OnRead, + OnExecuteHW, + OnExecute +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxBreakpointType _XboxBreakpointType; +cpp_quote("*/ typedef eXboxBreakpointType::XboxBreakpointType _XboxBreakpointType;") + +cpp_quote("namespace eXboxSelectConsoleFlags {") +[v1_enum] enum XboxSelectConsoleFlags +{ + NoPromptIfDefaultExists, + NoPromptIfOnlyOne, + FilterByAccess +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxSelectConsoleFlags _XboxSelectConsoleFlags; +cpp_quote("*/ typedef int _XboxSelectConsoleFlags;") + +cpp_quote("namespace eXboxDebugConnectFlags{") +[v1_enum] enum XboxDebugConnectFlags +{ + Force = 0x0001, + MonitorOnly = 0x0002 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxDebugConnectFlags _XboxDebugConnectFlags; +cpp_quote("*/ typedef int _XboxDebugConnectFlags;") + +cpp_quote("namespace eXboxDumpFlags{") +[v1_enum] enum XboxDumpFlags +{ + Normal = 0x0000, + WithDataSegs = 0x0001, + WithFullMemory = 0x0002, + WithHandleData = 0x0004, + FilterMemory = 0x0008, + ScanMemory = 0x0010, + WithUnloadedModules = 0x0020, + WithIndirectlyReferencedMemory = 0x0040, + FilterModulePaths = 0x0080, + WithProcessThreadData = 0x0100, + WithPrivateReadWriteMemory = 0x0200, +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxDumpFlags _XboxDumpFlags; +cpp_quote("*/ typedef int _XboxDumpFlags;") + +cpp_quote("namespace eXboxDumpMode{") +[v1_enum] enum XboxDumpMode +{ + Smart = 0x0000, + Enabled = 0x0001, + Disabled = 0x0002 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxDumpMode _XboxDumpMode; +cpp_quote("*/ typedef eXboxDumpMode::XboxDumpMode _XboxDumpMode;") + +cpp_quote("namespace eXboxEventDeferFlags {") +[v1_enum] enum XboxEventDeferFlags +{ + CanDeferExecutionBreak =0x0001, + CanDeferDebugString =0x0002, + CanDeferSingleStep =0x0004, + CanDeferAssertionFailed =0x0008, + CanDeferAssertionFailedEx =0x0010, + CanDeferDataBreak =0x0020, + CanDeferRIP =0x0040 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxEventDeferFlags _XboxEventDeferFlags; +cpp_quote("*/ typedef int _XboxEventDeferFlags;") + +cpp_quote("namespace eXboxDumpReportFlags {") +[v1_enum] enum XboxDumpReportFlags +{ + PromptToReport = 0, + AlwaysReport = 0x0001, + NeverReport = 0x0002, + ReportGroup = 0x000F, + LocalDestination = 0x0000, + RemoteDestination = 0x0010, + DestinationGroup = 0x000F, + FormatFullHeap = 0x0000, + FormatPartialHeap = 0x0100, + FormatNoHeap = 0x0200, + FormatRetail = 0x0400, + FormatGroup = 0x0F00 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxDumpReportFlags _XboxDumpReportFlags; +cpp_quote("*/ typedef int _XboxDumpReportFlags;") + +cpp_quote("namespace eXboxConsoleType {") +[v1_enum] enum XboxConsoleType +{ + DevelopmentKit = 0, + TestKit = 1, + ReviewerKit = 2 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxConsoleType _XboxConsoleType; +cpp_quote("*/ typedef eXboxConsoleType::XboxConsoleType _XboxConsoleType;") + +cpp_quote("namespace eXboxConsoleFeatures {") +[v1_enum] enum XboxConsoleFeatures +{ + Debugging = 1, //DMCF_DEBUGGING + SecondaryNIC = 2, //DMCF_SECONDARY_NIC + GB_RAM = 4 //DMCF_1GB_RAM +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxConsoleFeatures _XboxConsoleFeatures; +cpp_quote("*/ typedef int _XboxConsoleFeatures;") + +typedef struct XBOX_DUMP_SETTINGS +{ + _XboxDumpReportFlags Flags; + BSTR NetworkPath; +} XBOX_DUMP_SETTINGS, *PXBOX_DUMP_SETTINGS; + +[ + object, + uuid(c4c077e9-bf83-4657-ad8b-1e5abb9bb9a8), + dual, + oleautomation, + nonextensible, + helpstring("Add, remove, enumerate, open Xbox consoles and dump files") +] +interface IXboxManager: IDispatch +{ + + [propget, id(1)]HRESULT DefaultConsole( [out, retval] BSTR *DefaultXbox); + [propput, id(1)]HRESULT DefaultConsole( [in] BSTR DefaultXbox); + + [propget, id(2)]HRESULT Consoles( [out, retval] IXboxConsoles **Consoles); + [id(3)]HRESULT AddConsole( [in] BSTR Xbox); + [id(4)]HRESULT RemoveConsole( [in] BSTR Xbox); + + + [id(6)]HRESULT OpenConsole( [in] BSTR XboxName, [out, retval] IXboxConsole **Console); + [id(7)]HRESULT OpenDumpFile( [in] BSTR FileName, [in] BSTR ImageSearchPath, [out, retval] IXboxDebugTarget **DebugTarget); + + [id(8)] HRESULT SelectConsole( [in] LONG ParentWindow, [out] BSTR *SelectedXbox, [in] _XboxAccessFlags DesiredAccess, [in] _XboxSelectConsoleFlags Flags); + [id(9)] HRESULT RunAddConsoleWizard( [in] LONG ParentWindow, [in] VARIANT_BOOL Modal); + [id(10)] HRESULT OpenWindowsExplorer( [in] BSTR XboxName, [in] BSTR Path); + + [id(20)] HRESULT TranslateError( [in] HRESULT hr, [out, retval] BSTR *ErrorString); + [propget,id(21)] HRESULT SystemSymbolServerPath([out, retval] BSTR *SymbolServerPath); + + [id(22)] HRESULT SelectConsoleEx( [in] LONGLONG ParentWindow, [out] BSTR *SelectedXbox, [in] _XboxAccessFlags DesiredAccess, [in] _XboxSelectConsoleFlags Flags); + [id(23)] HRESULT RunAddConsoleWizardEx( [in] LONGLONG ParentWindow, [in] VARIANT_BOOL Modal); + +}; + +cpp_quote("namespace eXboxShareMode {") +[v1_enum] enum XboxShareMode +{ + ShareNone = 0, + ShareRead = 0x0001, // Same as WIN32 SHARE_READ + ShareWrite = 0x0002, // Same as WIN32 SHARE_WRITE + ShareDelete = 0x0004 // Same as WIN32 SHARE_DELETE +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxShareMode _XboxShareMode; +cpp_quote("*/ typedef int _XboxShareMode;") + +cpp_quote("namespace eXboxCreateDisposition {") +[v1_enum] enum XboxCreateDisposition +{ + CreateNew = 1, // Same as WIN32 CREATE_NEW + CreateAlways = 2, // Same as WIN32 CREATE_ALWAYS + OpenExisting = 3, // Same as WIN32 OPEN_EXISTING + OpenAlways = 4 // Same as WIN32 OPEN_ALWAYS +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxCreateDisposition _XboxCreateDisposition; +cpp_quote("*/ typedef eXboxCreateDisposition::XboxCreateDisposition _XboxCreateDisposition;") + +[ + object, + uuid(978B90D1-1F44-4adc-B992-12AF5DBE16E2), + dual, + oleautomation, + nonextensible, + helpstring("Information about an executable in an executable database.") +] +interface IXboxExecutableInfo : IDispatch +{ + // Persisted properties + [propget, id(1)] HRESULT SymbolGuid([out,retval] BSTR *Guid); + [propget, id(2)] HRESULT XboxExecutablePath([out,retval] BSTR *Path); + [propget, id(3)] HRESULT PortableExecutablePath([out,retval] BSTR *Path); + [propget, id(4)] HRESULT SymbolPath([out,retval] BSTR *Path); + [propget, id(5)] HRESULT PublicSymbolPath([out,retval] BSTR *Path); + [propget, id(6)] HRESULT ModuleName([out,retval] BSTR *Name); + [propget, id(7)] HRESULT TimeDateStamp([out,retval] DWORD *Time); + [propget, id(8)] HRESULT SizeOfImage([out,retval] DWORD *Size); + [propget, id(9)] HRESULT StoreRelativePath([out,retval] VARIANT_BOOL *RelativePath); + + // Runtime Properties + [propget, id(10)] HRESULT BasePath([out,retval] BSTR *Path); + [propput, id(10)] HRESULT BasePath([in] BSTR Path); + [propget, id(11)] HRESULT PropGetRelativePath([out,retval] VARIANT_BOOL *Relative); + [propput, id(11)] HRESULT PropGetRelativePath([in] VARIANT_BOOL Relative); +}; + +[ + object, + uuid(CB8E47BA-2673-48af-B0C5-FD5738FFCC6B), + dual, + oleautomation, + nonextensible, + helpstring("Search, edit executable database file.") +] +interface IXboxExecutableDatabase : IDispatch +{ + [propget, id(1)] HRESULT IsDirty([out,retval] VARIANT_BOOL *DirtyFlag); + [propget, id(2)] HRESULT CurrentFileName([out,retval] BSTR *Path); + + [id(100)] HRESULT LoadDatabase( + [in] BSTR DatabaseFile, + [in] VARIANT_BOOL ReadOnly, + [in] _XboxCreateDisposition CreateDisposition, + [in] _XboxShareMode ShareMode + ); + + [id(101)] HRESULT SaveDatabase( + [in] BSTR DatabaseFile, + [in] VARIANT_BOOL Remember + ); + + [id(102)] HRESULT CloseDatabase(); + + [id(103)] HRESULT ResetDatabase(); + + [id(120)] HRESULT AddExecutable( + [in] BSTR XboxExecutablePath, + [in] BSTR PortableExecutablePath, + [in] BSTR SymbolPath, + [in] BSTR PublicSymbolPath, + [in] VARIANT_BOOL ExplictFilesOnly, + [in] VARIANT_BOOL StoreRelativePath + ); + + [id(121)] HRESULT RemoveExecutable([in] BSTR Guid); + + [id(122)] HRESULT FindExecutableByGuid( + [in] BSTR Guid, + [out] IXboxExecutableInfo **Info, + [out,retval] VARIANT_BOOL *Found + ); + + [id(123)] HRESULT FindExecutableForSymServ( + [in] BSTR ModuleName, + [in] DWORD TimeDateStamp, + [in] DWORD SizeOfImage, + [out] IXboxExecutableInfo **Info, + [out,retval] VARIANT_BOOL *Found + ); + +}; + +[ + object, + uuid(75dd80a9-5a33-42d4-8a39-ab07c9b17cc3), + dual, + oleautomation, + nonextensible, + helpstring("Xbox Console") +] +interface IXboxConsole: IDispatch +{ + // + // Console Properties + // + + [propget, id(DISPID_VALUE)] HRESULT Name( [out,retval] BSTR *XboxName); + [propput, id(DISPID_VALUE)] HRESULT Name( [in] BSTR XboxName); + [propget, id(1)] HRESULT IPAddress( [out,retval] DWORD *IPAddress); + [propget, id(2)] HRESULT IPAddressTitle( [out,retval] DWORD *IPAddress); + [propget, id(3)] HRESULT SystemTime( [out,retval] VARIANT *Date); + [propput, id(3)] HRESULT SystemTime( [in] VARIANT Date); + + // + // Connection Properties + // + + [propget, id(20)] HRESULT Shared( [out,retval] VARIANT_BOOL *Shared); + [propput, id(20)] HRESULT Shared( [in] VARIANT_BOOL Shared); + [propget, id(21)] HRESULT ConnectTimeout( [out,retval] DWORD *Timeout); + [propput, id(21)] HRESULT ConnectTimeout( [in] DWORD Timeout); + [propget, id(22)] HRESULT ConversationTimeout( [out,retval] DWORD *Timeout); + [propput, id(22)] HRESULT ConversationTimeout( [in] DWORD Timeout); + [id(30)] HRESULT FindConsole( [in] DWORD Retries, [in] DWORD RetryDelay); + + // + // Get other interfaces. + // + [propget, id(50)] HRESULT XboxManager([out, retval] IXboxManager **XboxManager); + [propget, id(51)] HRESULT DebugTarget([out, retval] IXboxDebugTarget **DebugTarget); + + // + // Manipulate running process + // + + [id(100)] HRESULT Reboot([in] BSTR Name, [in] BSTR MediaDirectory, [in] BSTR CmdLine, [in] _XboxRebootFlags Flags); + [id(101)] HRESULT SetDefaultTitle([in] BSTR TitleName, [in] BSTR MediaDirectory, [in] DWORD Flags); + [propget, id(102)] HRESULT RunningProcessInfo( [out, retval] PXBOX_PROCESS_INFO ProcessInfo); + + // + // Support for Custom Command Handlers + // + + [id(110)] HRESULT OpenConnection( [in] BSTR Handler, [out,retval] DWORD *Connection); + [id(111)] HRESULT CloseConnection([in] DWORD Connection); + [id(112)] HRESULT SendTextCommand([in] DWORD Connection, [in] BSTR Command, [out] BSTR *Response); + + // For binary data in commands + + [id(113)] HRESULT ReceiveSocketLine([in] DWORD Connection, [out] BSTR *Line); + [id(114)] HRESULT ReceiveStatusResponse([in] DWORD Connection, [out] BSTR *Line, [out,retval] HRESULT* status); + [id(115)] HRESULT SendBinary([in] DWORD Connection, [in] SAFEARRAY(BYTE) Data, [in] DWORD Count); + [id(116)] HRESULT ReceiveBinary([in] DWORD Connection, [in,out] SAFEARRAY(BYTE) Data, [in] DWORD Count, [out] DWORD *BytesReceived); + [id(117),hidden] HRESULT SendBinary_cpp([in] DWORD Connection, [in, size_is(Count)] BYTE *Data, [in] DWORD Count); + [id(118),hidden] HRESULT ReceiveBinary_cpp([in] DWORD Connection, [in, size_is(Count)] BYTE *Data, [in] DWORD Count, [out] DWORD *BytesReceived); + + // + // Drive information + // + + [propget, id(120)] HRESULT Drives( [out, retval] BSTR *Drives); + [id(121)] HRESULT GetDiskFreeSpace( + [in] WCHAR Drive, + [out] ULONGLONG *FreeBytesAvailableToCaller, + [out] ULONGLONG *TotalNumberOfBytes, + [out] ULONGLONG *TotalNumberOfFreeBytes + ); + + // + // Directory Access + // + + [id(125)] HRESULT MakeDirectory( [in] BSTR Directory); + [id(126)] HRESULT RemoveDirectory( [in] BSTR Directory); + [id(127)] HRESULT DirectoryFiles( [in] BSTR Directory, [out,retval] IXboxFiles **Files); + + + // + // File data access + // + + [id(130)] HRESULT SendFile( [in] BSTR LocalName, [in] BSTR RemoteName); + [id(131)] HRESULT ReceiveFile( [in] BSTR LocalName, [in] BSTR RemoteName); + [id(132)] HRESULT ReadFileBytes( + [in] BSTR FileName, + [in] DWORD FileOffset, + [in] DWORD Count, + [in, out] SAFEARRAY(BYTE) Data, + [out] DWORD *BytesRead + ); + + [id(133)] HRESULT WriteFileBytes( + [in] BSTR FileName, + [in] DWORD FileOffset, + [in] DWORD Count, + [in] SAFEARRAY(BYTE) Data, + [out] DWORD *BytesWritten + ); + + [id(134),hidden] HRESULT ReadFileBytes_cpp( + [in] BSTR FileName, + [in] DWORD FileOffset, + [in] DWORD Count, + [out, size_is(Count), length_is(*BytesRead)] BYTE *Data, + [out] DWORD *BytesRead + ); + + [id(135),hidden] HRESULT WriteFileBytes_cpp( + [in] BSTR FileName, + [in] DWORD FileOffset, + [in] DWORD Count, + [in, size_is(Count)] BYTE *Data, + [out] DWORD *BytesWritten + ); + + [id(136)] HRESULT SetFileSize( + [in] BSTR FileName, + [in] DWORD FileOffset, + [in] _XboxCreateDisposition CreateDisposition + ); + + // + // File Attributes + // + + [id(140)] HRESULT GetFileObject([in] BSTR FileName, [out, retval] IXboxFile **FileObject); + [id(141)] HRESULT RenameFile( [in] BSTR OldName, [in] BSTR NewName); + [id(142)] HRESULT DeleteFile( [in] BSTR FileName); + + // + // D3D Info + // + + [id(150)] HRESULT ScreenShot(BSTR FileName); + + // + // Debug Settings + // + + [propget, id(160)] HRESULT DumpMode( [out, retval] _XboxDumpMode* DumpMode); + [propput, id(160)] HRESULT DumpMode( [in] _XboxDumpMode DumpMode); + [id(161)] HRESULT GetDumpSettings( [out] PXBOX_DUMP_SETTINGS DumpMode); + [id(162)] HRESULT SetDumpSettings( [in] PXBOX_DUMP_SETTINGS DumpMode); + [propget, id(163)] HRESULT EventDeferFlags( [out,retval] _XboxEventDeferFlags *EventDeferFlags); + [propput, id(163)] HRESULT EventDeferFlags( [in] _XboxEventDeferFlags EventDeferFlags); + + // + // Console type + // + + [propget, id(170)] HRESULT ConsoleType( [out,retval] _XboxConsoleType *ConsoleType); + + + // NYI + // HRESULT GetSurface(TBD); + // HRESULT GetGammaTable(TBD); + // HRESULT GetPalette(TBD); + // HRESULT GetD3DState(TBD); + + // + // Security Methods + // + // [id(160)] HRESULT RunSecurityDialog( [in] LONG ParentWindow ); + // [propget, id(161)] HRESULT SecurityEnabled( [out, retval] VARIANT_BOOL *Enabled); + // [propput, id(162)] HRESULT SecurityEnabled( [in] VARIANT_BOOL Enabled); + // [id(163)] HRESULT StartAdminMode( [in] BSTR Password ); + // [id(164)] HRESULT StopAdminMode(); + // [propput, id(159)] HRESULT AdminPassword( [in] BSTR Password); + // [id(165)] HRESULT SetUserAccess( [in] BSTR UserName, [in] _XboxAccessFlags Access); + // [id(166)] HRESULT GetUserAccess( [in] BSTR UserName, [in] _XboxAccessFlags *Access); + // [id(167)] HRESULT AddUser( [in] BSTR UserName, [in] _XboxAccessFlags Access); + // [id(168)] HRESULT RemoveUser( [in] BSTR UserName); + // [propget, id(169)] HRESULT Users( [out, retval] IXboxUsers **Users); + + // + // Configuration Values [REVIEW] do we want some enums defined, or rather specific methods. + // + + // [id(180)] HRESULT GetConfigurationValue( + // [in] DWORD Index, + // [in] DWORD Type, + // [out, size_is(ValueLength),length_is(ValueLength)] BYTE *Value, + // [in] DWORD ValueLength + // ); + + // [id(181)] HRESULT SetConfigurationValue( + // [in] DWORD Index, + // [in] DWORD Type, + // [in, size_is(ValueLength)] BYTE *Value, + // [in] DWORD ValueLength + // ); + + // + // File-event Methods + // + [id(182)] HRESULT StartFileEventCapture(); + [id(183)] HRESULT StopFileEventCapture(); + + // + // Get IXboxAutomation interface + // + + [propget, id(184)] HRESULT XboxAutomation([out, retval] IXboxAutomation **Automation); + + // + // Debugger Extensions + // + + [id(185)] HRESULT LoadDebuggerExtension( [in] BSTR ExtensionName, [out,retval] DWORD* ModuleHandle); + [id(186)] HRESULT UnloadDebuggerExtension( [in] DWORD ModuleHandle); + + + // + // Console Extensions + // + + [propget, id(190)] HRESULT ConsoleFeatures ( [out,retval] _XboxConsoleFeatures *ConsoleFeatures); + +}; + + +[ + object, + uuid(110980e4-f8d4-45f1-8a86-90d86fd4a879), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Console in Xenon Neighborhood") +] +interface IXboxConsoles : IDispatch +{ + [id(DISPID_VALUE), propget] HRESULT Item( [in] LONG Index, [out, retval] BSTR *ConsoleName); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); +}; + +[ + object, + uuid(b9dbc76d-8a06-4eeb-84bd-1ad42f0afe28), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("File") +] +interface IXboxFile : IDispatch +{ + [propget, id(DISPID_VALUE)] HRESULT Name([out, retval]BSTR *Name); + [propput, id(DISPID_VALUE)] HRESULT Name([in] BSTR Name); + [propget, id(1)] HRESULT CreationTime([out, retval]VARIANT *CreationTime); + [propput, id(1)] HRESULT CreationTime([in]VARIANT CreationTime); + [propget, id(2)] HRESULT ChangeTime([out, retval]VARIANT *ChangeTime); + [propput, id(2)] HRESULT ChangeTime([in]VARIANT ChangeTime); + [propget, id(3)] HRESULT Size([out, retval]ULONGLONG *Size); + [propput, id(3)] HRESULT Size([in]ULONGLONG Size); + [propget, id(4)] HRESULT IsReadOnly([out, retval]VARIANT_BOOL *ReadOnly); + [propput, id(4)] HRESULT IsReadOnly([in]VARIANT_BOOL ReadOnly); + [propget, id(5)] HRESULT IsDirectory([out, retval]VARIANT_BOOL *Directory); +}; + +[ + object, + uuid(dfcf3f84-5394-448d-bcac-e30af6c840e1), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Files in a Directory") +] +interface IXboxFiles : IDispatch +{ + [id(DISPID_VALUE), propget] HRESULT Item( [in] LONG Index, [out, retval] IXboxFile **File); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); + +}; + +[ + object, + uuid(6bb90673-5c3c-4b63-8d3c-479a5ede82c3), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Information about User's Access") +] +interface IXboxUser : IDispatch +{ + [propget, id(DISPID_VALUE)] HRESULT Name([out, retval]BSTR *UserName); + [propput, id(DISPID_VALUE)] HRESULT Name([in]BSTR UserName); + [propget, id(1)] HRESULT HasReadAccess( [out, retval] VARIANT_BOOL *ReadAccess); + [propput, id(1)] HRESULT HasReadAccess( [in] VARIANT_BOOL ReadAccess); + [propget, id(2)] HRESULT HasWriteAccess( [out, retval] VARIANT_BOOL *WriteAccess); + [propput, id(2)] HRESULT HasWriteAccess( [in] VARIANT_BOOL WriteAccess); + [propget, id(3)] HRESULT HasControlAccess( [out, retval] VARIANT_BOOL *ControlAccess); + [propput, id(3)] HRESULT HasControlAccess( [in] VARIANT_BOOL ControlAccess); + [propget, id(4)] HRESULT HasConfigureAccess( [out, retval] VARIANT_BOOL *ConfigureAccess); + [propput, id(4)] HRESULT HasConfigureAccess( [in] VARIANT_BOOL ConfigureAccess); + [propget, id(5)] HRESULT HasManageAccess( [out, retval] VARIANT_BOOL *ManageAccess); + [propput, id(5)] HRESULT HasManageAccess( [in] VARIANT_BOOL ManageAccess); +}; + +[ + object, + uuid(d5ee3179-7955-41b4-a507-bd78efc462c9), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Users with Access") +] +interface IXboxUsers : IDispatch +{ + [id(DISPID_VALUE), propget] HRESULT Item( [in] LONG Index, [out, retval] IXboxUser **User); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); +}; + +[ + object, + uuid(43ccafd7-4636-43aa-b468-b7f6edca6651), + dual, + oleautomation, + nonextensible, + helpstring("Information about a debug target") +] +interface IXboxDebugTarget: IDispatch +{ + [propget, id(DISPID_VALUE)] HRESULT Name( [out,retval] BSTR *Name); + [propget, id(1)] HRESULT IsDump( [out,retval] VARIANT_BOOL *IsDump); + + [propget, id(20)] HRESULT XboxManager([out,retval] IXboxManager **XboxManager); + [propget, id(21)] HRESULT Console([out,retval] IXboxConsole **Console); + + [id(50)] HRESULT ConnectAsDebugger( [in] BSTR DebuggerName, [in] _XboxDebugConnectFlags Flags); + [id(51)] HRESULT DisconnectAsDebugger(); + [id(52)] HRESULT IsDebuggerConnected([out] BSTR *DebuggerName, [out] BSTR *UserName, [out,retval]VARIANT_BOOL *Connected); + + [propget, id(100)] HRESULT Modules([out,retval] IXboxModules** Modules); + [propget,id(101)] HRESULT Threads([out,retval] IXboxThreads** Threads); + + [id(103)] HRESULT GetMemory( + [in] DWORD Address, + [in] DWORD BytesToRead, + [in,out] SAFEARRAY(BYTE) Data, + [out] DWORD *BytesRead + ); + + [id(104)] HRESULT SetMemory( + [in] DWORD Address, + [in] DWORD BytesToWrite, + [in] SAFEARRAY(BYTE) Data, + [out] DWORD *BytesWritten + ); + + [id(105), hidden] HRESULT GetMemory_cpp( + [in] DWORD Address, + [in] DWORD BytesToRead, + [out,size_is(BytesToRead),length_is(*BytesRead)] BYTE *Data, + [out] DWORD *BytesRead + ); + + [id(106), hidden] HRESULT SetMemory_cpp( + [in] DWORD Address, + [in] DWORD BytesToWrite, + [in, size_is(BytesToWrite)] BYTE *Data, + [out] DWORD *BytesWritten + ); + + [id(107)] HRESULT InvalidateMemoryCache( [in] VARIANT_BOOL ExecutablePages, [in]DWORD Address, [in] DWORD Size); + [propget, id(108)] HRESULT MemoryCacheEnabled( [out, retval] VARIANT_BOOL *Enabled); + [propput, id(108)] HRESULT MemoryCacheEnabled( [in] VARIANT_BOOL Enabled); + [propget, id(109)] HRESULT MemoryRegions([out, retval] IXboxMemoryRegions **MemoryRegions); + + [propget, id(110)] HRESULT RunningProcessInfo( [out,retval] PXBOX_PROCESS_INFO ProcessInfo); + + [id(115)] HRESULT StopOn( [in] _XboxStopOnFlags StopOn, [in] VARIANT_BOOL Stop); + [id(116)] HRESULT Stop( [out] VARIANT_BOOL* AlreadyStopped ); + [id(117)] HRESULT Go( [out] VARIANT_BOOL* NotStopped ); + + [id(130)] HRESULT SetBreakpoint([in] DWORD Address); + [id(131)] HRESULT RemoveBreakpoint([in] DWORD Address); + [id(132)] HRESULT RemoveAllBreakpoints(); + [id(133)] HRESULT SetInitialBreakpoint(); + [id(134)] HRESULT SetDataBreakpoint([in] DWORD Address, [in] _XboxBreakpointType Type, [in] DWORD Size); + [id(135)] HRESULT IsBreakpoint([in] DWORD Address, [out] _XboxBreakpointType *Type); + + [id(136)] HRESULT WriteDump( [in] BSTR Filename, [in] _XboxDumpFlags Type ); + + [id(140), hidden] HRESULT CopyEventInfo( [out] XBOX_EVENT_INFO *EventInfoDest, [in] XBOX_EVENT_INFO *EventInfoSource); + [id(150), hidden] HRESULT FreeEventInfo( [in,out] XBOX_EVENT_INFO *EventInfo); + + [id(160)] HRESULT PgoStartDataCollection (DWORD PgoModule); + [id(161)] HRESULT PgoStopDataCollection (DWORD PgoModule); + [id(162)] HRESULT PgoSaveSnapshot(BSTR Phase, VARIANT_BOOL Reset, DWORD PgoModule); + [id(163)] HRESULT PgoSetAllocScale(DWORD PgoModule, DWORD BufferAllocScale); +}; + +cpp_quote("namespace eXboxAutomationButtonFlags {") +[v1_enum] enum XboxAutomationButtonFlags +{ + DPadUp =0x0001, + DPadDown =0x0002, + DPadLeft =0x0004, + DPadRight =0x0008, + StartButton =0x0010, + BackButton =0x0020, + LeftThumbButton =0x0040, + RightThumbButton =0x0080, + LeftShoulderButton =0x0100, + RightShoulderButton =0x0200, + A_Button =0x1000, + B_Button =0x2000, + X_Button =0x4000, + Y_Button =0x8000, + Xbox360_Button =0x0400, + Bind_Button =0x0800 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxAutomationButtonFlags _XboxAutomationButtonFlags; +cpp_quote("*/ typedef int _XboxAutomationButtonFlags;") + +typedef struct XBOX_AUTOMATION_GAMEPAD +{ + _XboxAutomationButtonFlags Buttons; + DWORD LeftTrigger; + DWORD RightTrigger; + long LeftThumbX; + long LeftThumbY; + long RightThumbX; + long RightThumbY; +} XBOX_AUTOMATION_GAMEPAD, *PXBOX_AUTOMATION_GAMEPAD; + +[ + object, + uuid(D81F3E2E-8304-4024-8997-BB1C893516B0), + dual, + oleautomation, + nonextensible, + helpstring("Interface to control automation on a console") +] +interface IXboxAutomation: IDispatch +{ + [id(100)] HRESULT GetInputProcess( [in] DWORD UserIndex, [out] VARIANT_BOOL* SystemProcess); + [id(101)] HRESULT BindController( [in] DWORD UserIndex, [in] DWORD QueueLength); + [id(102)] HRESULT UnbindController([in] DWORD UserIndex); + [id(103)] HRESULT ConnectController([in] DWORD UserIndex); + [id(104)] HRESULT DisconnectController([in] DWORD UserIndex); + [id(105)] HRESULT SetGamepadState([in] DWORD UserIndex, [in] PXBOX_AUTOMATION_GAMEPAD Gamepad); + [id(106)] HRESULT QueueGamepadState_cpp( + [in] DWORD UserIndex, + [in, size_is(UserIndex)] PXBOX_AUTOMATION_GAMEPAD GamepadArray, + [in, size_is(UserIndex)] DWORD *TimedDurationArray, + [in, size_is(UserIndex)] DWORD *CountDurationArray, + [in] DWORD ItemCount, + [out] DWORD *ItemsAddedToQueue + ); + [id(107)] HRESULT QueueGamepadState( + [in] DWORD UserIndex, + [in] XBOX_AUTOMATION_GAMEPAD* Gamepad, + [in] DWORD TimedDuration, + [in] DWORD CountDuration, + [out, retval] VARIANT_BOOL *AddedToQueue + ); + [id(108)] HRESULT ClearGamepadQueue([in] DWORD UserIndex); + [id(109)] HRESULT QueryGamepadQueue([in] DWORD UserIndex, + [out] DWORD *QueueLength, + [out] DWORD *ItemsInQueue, + [out] DWORD *TimedDurationRemaining, + [out] DWORD *CountDurationRemaining + ); + [id(110)] HRESULT GetUserDefaultProfile([out] LONGLONG* Xuid); + [id(111)] HRESULT SetUserDefaultProfile([in] LONGLONG Xuid); +}; + +[ + object, + uuid(0eee2aa0-60f0-4c18-b4ed-e3933e659847), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Information about a module") +] +interface IXboxModule: IDispatch +{ + [propget, id(DISPID_VALUE)] HRESULT ModuleInfo([out,retval] XBOX_MODULE_INFO *ModuleInfo); + [propget, id(1)] HRESULT Sections([out,retval] IXboxSections** Sections); + [id(2)] HRESULT GetFunctionInfo( [in] DWORD Address, [out]XBOX_FUNCTION_INFO *FunctionInfo); + [propget, id(3)] HRESULT OriginalSize([out,retval] DWORD* OriginalSize); + [propget, id(4)] HRESULT Executable([out,retval] IXboxExecutable** Executable); + [id(5)] HRESULT GetEntryPointAddress([out,retval] DWORD* EntryPointAddress); +}; + +[ + object, + uuid(e4f0c350-d2da-426e-adec-3d01f60fc842), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Collection of Modules") +] +interface IXboxModules: IDispatch +{ + [id(DISPID_VALUE),propget] HRESULT Item( [in] LONG Index, [out, retval] IXboxModule **Module); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); +}; + +[ + object, + uuid(4B103593-DB52-4e18-913D-B3B17824BD76), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Information about an Xbox executable") +] +interface IXboxExecutable: IDispatch +{ + [id(1)]HRESULT GetPEModuleName( [out, retval] BSTR *ModuleName); +}; + +[ + object, + uuid(d6df8112-0326-4d29-a6b8-cfb0d89c358a), + dual, + oleautomation, + pointer_default(unique), + helpstring("Information about a section") +] +interface IXboxSection: IDispatch +{ + [propget, id(100)] HRESULT SectionInfo([out,retval] XBOX_SECTION_INFO *SectionInfo); +}; + +[ + object, + uuid(9762df66-9516-4531-a507-a11034056f5e), + dual, + oleautomation, + pointer_default(unique), + helpstring("Sections in a module") +] +interface IXboxSections : IDispatch +{ + [id(DISPID_VALUE), propget] HRESULT Item( [in] LONG Index, [out, retval] IXboxSection **Section); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); +}; + +[ + object, + uuid(8f1e63f5-85ba-4b2d-ad9c-1fa6b750d57f), + dual, + oleautomation, + pointer_default(unique), + helpstring("Information about a thread") +] +interface IXboxThread: IDispatch +{ + [propget, id(DISPID_VALUE)] HRESULT ThreadId([out, retval] DWORD *ThreadId); + [propget, id(100)] HRESULT ThreadInfo([out,retval] XBOX_THREAD_INFO *ThreadInfo); + [propget, id(101)] HRESULT StopEventInfo([out,retval] PXBOX_EVENT_INFO StopEventInfo); + [propget, id(102)] HRESULT TopOfStack([out,retval] IXboxStackFrame **StackFrame); + [id(103)] HRESULT Halt(); + [id(104)] HRESULT Continue([in] VARIANT_BOOL Exception); + [id(105)] HRESULT Suspend(); + [id(106)] HRESULT Resume(); + [propget, id(107)] HRESULT CurrentProcessor([out,retval] DWORD *Processor); + [propget, id(108)] HRESULT LastError([out,retval] DWORD *LastError); + + // Most likely will be added. + // [id(110)] HRESULT StepInstruction( [in] VARIANT_BOOL StepOver); + // [id(111)] HRESULT StepRange( [in] DWORD RangeStart, [in] DWORD RangeEnd, [in] VARIANT_BOOL StepOver); + // [id(112)] HRESULT StepOut(); + +}; + +[ + object, + uuid(da7c0784-9a34-4a9e-a040-59ebcea92c1e), + dual, + oleautomation, + pointer_default(unique), + helpstring("Threads in Process") +] +interface IXboxThreads : IDispatch +{ + [id(DISPID_VALUE), propget] HRESULT Item( [in] LONG Index, [out, retval] IXboxThread **Thread); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); +}; + +cpp_quote("namespace eXboxRegisters32{") +[v1_enum] enum XboxRegisters32 +{ + msr, iar, lr, cr, xer +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxRegisters32 _XboxRegisters32; +cpp_quote("*/ typedef eXboxRegisters32::XboxRegisters32 _XboxRegisters32;") + +cpp_quote("namespace eXboxRegisters64{") +[v1_enum] enum XboxRegisters64 +{ + ctr, + r0, r1, r2, r3, r4, r5, r6, r7, + r8, r9, r10, r11, r12, r13, r14, r15, + r16, r17, r18, r19, r20, r21, r22, r23, + r24, r25, r26, r27, r28, r29, r30, r31 +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxRegisters64 _XboxRegisters64; +cpp_quote("*/ typedef eXboxRegisters64::XboxRegisters64 _XboxRegisters64;") + +cpp_quote("namespace eXboxRegistersDouble{") +[v1_enum] enum XboxRegistersDouble +{ + fp0, fp1, fp2, fp3, fp4, fp5, fp6, fp7, + fp8, fp9, fp10, fp11, fp12, fp13, fp14, fp15, + fp16, fp17, fp18, fp19, fp20, fp21, fp22, fp23, + fp24, fp25, fp26, fp27, fp28, fp29, fp30, fp31, + fpscr +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxRegistersDouble _XboxRegistersDouble; +cpp_quote("*/ typedef eXboxRegistersDouble::XboxRegistersDouble _XboxRegistersDouble;") + +cpp_quote("namespace eXboxRegistersVector{") +[v1_enum] enum XboxRegistersVector +{ + v0, v1, v2, v3, v4, v5, v6, v7, + v8, v9, v10, v11, v12, v13, v14, v15, + v16, v17, v18, v19, v20, v21, v22, v23, + v24, v25, v26, v27, v28, v29, v30, v31, + v32, v33, v34, v35, v36, v37, v38, v39, + v40, v41, v42, v43, v44, v45, v46, v47, + v48, v49, v50, v51, v52, v53, v54, v55, + v56, v57, v58, v59, v60, v61, v62, v63, + v64, v65, v66, v67, v68, v69, v70, v71, + v72, v73, v74, v75, v76, v77, v78, v79, + v80, v81, v82, v83, v84, v85, v86, v87, + v88, v89, v90, v91, v92, v93, v94, v95, + v96, v97, v98, v99, v100, v101, v102, v103, + v104, v105, v106, v107, v108, v109, v110, v111, + v112, v113, v114, v115, v116, v117, v118, v119, + v120, v121, v122, v123, v124, v125, v126, v127, + vscr +}; +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxRegistersVector _XboxRegistersVector; +cpp_quote("*/ typedef eXboxRegistersVector::XboxRegistersVector _XboxRegistersVector;") + +[ + object, + uuid(eabf8976-1a2f-4aaa-bbbb-3ecab03b2ee9), + dual, + oleautomation, + pointer_default(unique), + helpstring("a stack frame on a thread") +] +interface IXboxStackFrame: IDispatch +{ + [propget, id(1)] HRESULT TopOfStack([out,retval] VARIANT_BOOL *TopOfStack); + [propget, id(2)] HRESULT Dirty([out,retval] VARIANT_BOOL *Dirty); + [propget, id(3)] HRESULT NextStackFrame([out,retval] IXboxStackFrame **StackFrame); + + // Registers are grouped by data type. + [id(100)] HRESULT GetRegister32( + [in] _XboxRegisters32 Register, + [out] LONG* Value, + [out, retval] VARIANT_BOOL *IsValid + ); + [id(101)] HRESULT SetRegister32( + [in] _XboxRegisters32 Register, + [in] LONG Value + ); + + [id(102)] HRESULT GetRegister64( + [in] _XboxRegisters64 Register, + [out] LONGLONG* Value, + [out, retval] VARIANT_BOOL *IsValid + ); + [id(103)] HRESULT SetRegister64( + [in] _XboxRegisters64 Register, + [in] LONGLONG Value + ); + [id(104)] HRESULT GetRegisterDouble( + [in] _XboxRegistersDouble Register, + [out] double* Value, + [out, retval] VARIANT_BOOL *IsValid + ); + [id(105)] HRESULT SetRegisterDouble( + [in] _XboxRegistersDouble Register, + [in] double Value + ); + [id(106),hidden] HRESULT GetRegisterVector_cpp( + [in] _XboxRegistersVector Register, + [out, size_is(4), length_is(4)] float* Value, + [out, retval] VARIANT_BOOL *IsValid + ); + [id(107),hidden] HRESULT SetRegisterVector_cpp( + [in] _XboxRegistersVector Register, + [in, size_is(4), length_is(4)] float *Value + ); + [id(108)] HRESULT GetRegisterVector( + [in] _XboxRegistersVector Register, + SAFEARRAY(float) Value, + [out, retval] VARIANT_BOOL *IsValid + ); + [id(109)] HRESULT SetRegisterVector( + [in] _XboxRegistersVector Register, + SAFEARRAY(float) Value + ); + + [id(110)] HRESULT FlushRegisterChanges(); + + [propget, id(111)] HRESULT FunctionInfo([out,retval]XBOX_FUNCTION_INFO *FunctionInfo); + [propget, id(112)] HRESULT StackPointer([out,retval]DWORD *StackPointer); + [propget, id(113)] HRESULT ReturnAddress([out,retval]DWORD *ReturnAddress); +}; + +[ + object, + uuid(7f8e857b-fd59-4b67-8156-faa3fd06d1e5), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Collection of memory regions") +] +interface IXboxMemoryRegions : IDispatch +{ + [id(DISPID_VALUE),propget] HRESULT Item( [in] LONG Index, [out, retval] IXboxMemoryRegion **MemoryRegion); + [id(1), propget] HRESULT Count([out, retval]LONG *Count); + [id(DISPID_NEWENUM), propget] HRESULT _NewEnum( [out, retval] IEnumVARIANT **Enumerator); +}; + +cpp_quote("namespace eXboxMemoryRegionFlags{") +[v1_enum] enum XboxMemoryRegionFlags +{ + NoAccess = 0x01, + ReadOnly = 0x02, + ReadWrite = 0x04, + WriteCopy = 0x08, + Execute = 0x10, + ExecuteRead = 0x20, + ExecuteReadWrite = 0x40, + ExecuteWriteCopy = 0x80, + Guard = 0x100, + NoCache = 0x200, + WriteCombine = 0x400, + UserReadOnly = 0x1000, + UserReadWrite = 0x2000 +}; + +cpp_quote("}") +cpp_quote("/*") +typedef enum XboxMemoryRegionFlags _XboxMemoryRegionFlags; +cpp_quote("*/ typedef int _XboxMemoryRegionFlags;") + +[ + object, + uuid(4f882a21-7f2a-4bea-a0a3-a3710a93deea), + dual, + oleautomation, + nonextensible, + pointer_default(unique), + helpstring("Memory Region Info") +] +interface IXboxMemoryRegion : IDispatch +{ + [propget, id(1)] HRESULT BaseAddress([out,retval] LONG *BaseAddress); + [propget, id(2)] HRESULT RegionSize([out,retval] LONG *RegionSize); + [propget, id(3)] HRESULT Flags([out,retval] _XboxMemoryRegionFlags *Flags); +}; + +[ + uuid(85c9127a-11ed-47f2-9e87-a83058fc264a), + dual, + oleautomation +] +interface IXboxEventInfo : IDispatch +{ + [id(DISPID_VALUE), propget] HRESULT Info( [out, retval] PXBOX_EVENT_INFO EventInfo); +} + +const DISPID DISPID_XBOX_EVENT = 1; +const DISPID DISPID_XBOX_TEXT_EVENT = 2; + +[ + uuid(420208df-c38c-4efb-9fc3-acd50350941e) +] +dispinterface XboxEvents +{ + properties: + methods: + [id(DISPID_XBOX_EVENT)] void OnStdNotify( [in] _XboxDebugEventType EventCode, [in]IXboxEventInfo *eventInfo); + [id(DISPID_XBOX_TEXT_EVENT)] void OnTextNotify( [in] BSTR Source, [in] BSTR Notification ); +}; + +[ + uuid(e3c9d73f-9df0-4b57-8cee-05f9ca6823be), + oleautomation +] +interface IXboxEvents : IUnknown +{ + HRESULT OnStdNotify( [in] _XboxDebugEventType EventCode, [in]IXboxEventInfo *eventInfo); + HRESULT OnTextNotify( [in] BSTR Source, [in] BSTR Notification ); +}; + +[ + uuid(d7a62fa2-524f-4f0d-8025-e72f9ff3eff6), + version(1.0), + helpstring("Xbox Development Kit API 2.0") +] +library XDevkit +{ + importlib("stdole2.tlb"); + + struct XBOX_PROCESS_INFO; + enum XboxAccessFlags; + struct XBOX_USER; + enum XboxModuleInfoFlags; + struct XBOX_MODULE_INFO; + enum XboxSectionInfoFlags; + struct XBOX_SECTION_INFO; + struct XBOX_THREAD_INFO; + enum XboxFunctionType; + struct XBOX_FUNCTION_INFO; + enum XboxDebugEventType; + enum XboxExecutionState; + enum XboxStopOnFlags; + enum XboxRebootFlags; + enum XboxExceptionFlags; + struct XBOX_EVENT_INFO; + enum XboxBreakpointType; + enum XboxSelectConsoleFlags; + enum XboxDebugConnectFlags; + enum XboxDumpFlags; + enum XboxDumpMode; + enum XboxEventDeferFlags; + enum XboxDumpReportFlags; + struct XBOX_DUMP_SETTINGS; + interface IXboxManager; + enum XboxCreateDisposition; + interface IXboxConsole; + interface IXboxConsoles; + interface IXboxFile; + interface IXboxFiles; + interface IXboxUser; + interface IXboxUsers; + interface IXboxDebugTarget; + interface IXboxModule; + interface IXboxModules; + interface IXboxSection; + interface IXboxSections; + interface IXboxThread; + interface IXboxThreads; + enum XboxRegisters32; + enum XboxRegisters64; + enum XboxRegistersDouble; + enum XboxRegistersVector; + interface IXboxStackFrame; + interface IXboxMemoryRegions; + enum XboxMemoryRegionFlags; + interface IXboxMemoryRegion; + interface IXboxEventInfo; + dispinterface XboxEvents; + interface IXboxEvents; + + [ + uuid(3ed2b073-99a1-42db-80cc-295e9ffba18f), + helpstring("Xbox Console Object") + ] + coclass XboxConsole + { + [default] interface IXboxConsole; + [default, source] interface XboxEvents; + }; + + [ + uuid(a5eb45d8-f3b6-49b9-984a-0d313ab60342), + helpstring("Xbox Manager Object") + ] + coclass XboxManager + { + [default] interface IXboxManager; + }; + + [ + uuid(3151B328-4A0D-4b83-950F-6861AB6B3ECD), + helpstring("Xbox Executable Database Object") + ] + coclass XboxExecutableDatabase + { + [default] interface IXboxExecutableDatabase; + }; + +}; diff --git a/third_party/xbox_sdk/include/XStudio.h b/third_party/xbox_sdk/include/XStudio.h new file mode 100644 index 0000000..ccd0235 --- /dev/null +++ b/third_party/xbox_sdk/include/XStudio.h @@ -0,0 +1,77 @@ +/*********************************************************************** +* * +* XStudio.h -- This module aggregates the APIs for Xbox 360 Studio * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +***********************************************************************/ + +#pragma once + +#ifndef XSTUDIO +#define XSTUDIO + +#ifdef __cplusplus +extern "C" { +#endif + + +// ----------------------------------------------------------------------------- +// Error codes +// ----------------------------------------------------------------------------- +#define FACILITY_XSTUDIO 0x310 + +#define S_XSTUDIO_SUCCESS __HRESULT_FROM_WIN32( ERROR_SUCCESS ) +#define S_XSTUDIO_STOPPED MAKE_HRESULT( SEVERITY_SUCCESS, FACILITY_XSTUDIO, 1 ) +#define S_XSTUDIO_NO_PLAYER_INDEX MAKE_HRESULT( SEVERITY_SUCCESS, FACILITY_XSTUDIO, 2 ) + +#define E_XSTUDIO_OUT_OF_MEMORY __HRESULT_FROM_WIN32( ERROR_OUTOFMEMORY ) +#define E_XSTUDIO_INVALID_ARG __HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER ) +#define E_XSTUDIO_INVALID_HANDLE __HRESULT_FROM_WIN32( ERROR_INVALID_HANDLE ) +#define E_XSTUDIO_INVALID_FUNCTION __HRESULT_FROM_WIN32( ERROR_INVALID_FUNCTION ) +#define E_XSTUDIO_INVALID_FLAGS __HRESULT_FROM_WIN32( ERROR_INVALID_FLAGS ) +#define E_XSTUDIO_INTERNAL E_FAIL +#define E_XSTUDIO_BUSY __HRESULT_FROM_WIN32( ERROR_BUSY ) +#define E_XSTUDIO_ACCESS_DENIED __HRESULT_FROM_WIN32( ERROR_ACCESS_DENIED ) +#define E_XSTUDIO_INVALID_DATA __HRESULT_FROM_WIN32( ERROR_INVALID_DATA ) +#define E_XSTUDIO_NO_CONNECTION __HRESULT_FROM_WIN32( ERROR_CONNECTION_UNAVAIL ) +#define E_XSTUDIO_FILE_ALREADY_EXISTS __HRESULT_FROM_WIN32( ERROR_ALREADY_EXISTS ) +#define E_XSTUDIO_FILE_NOT_FOUND __HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) +#define E_XSTUDIO_PATH_NOT_FOUND __HRESULT_FROM_WIN32( ERROR_PATH_NOT_FOUND ) +#define E_XSTUDIO_SHARING_VIOLATION __HRESULT_FROM_WIN32( ERROR_SHARING_VIOLATION ) +#define E_XSTUDIO_TOO_MANY_OPEN_FILES __HRESULT_FROM_WIN32( ERROR_TOO_MANY_OPEN_FILES ) +#define E_XSTUDIO_NO_MORE_ITEMS __HRESULT_FROM_WIN32( ERROR_NO_MORE_ITEMS ) +#define E_XSTUDIO_MORE_DATA __HRESULT_FROM_WIN32( ERROR_MORE_DATA ) +#define E_XSTUDIO_TIMEOUT __HRESULT_FROM_WIN32( ERROR_TIMEOUT ) +#define E_XSTUDIO_INVALID_OPERATION __HRESULT_FROM_WIN32( ERROR_INVALID_OPERATION ) +#define E_XSTUDIO_ALREADY_ASSIGNED __HRESULT_FROM_WIN32( ERROR_ALREADY_ASSIGNED ) +#define E_XSTUDIO_PROTOCOL_MISMATCH MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 2 ) +#define E_XSTUDIO_TITLE_TERMINATE MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 3 ) +#define E_XSTUDIO_NUI_NOT_INITIALIZED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 4 ) +#define E_XSTUDIO_HEADLESS_MODE MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 5 ) +#define E_XSTUDIO_NO_DATA_AVAILABLE MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 6 ) +#define E_XSTUDIO_FILE_CONVERSION_REQUIRED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 7 ) +#define E_XSTUDIO_INVALID_STREAM MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 8 ) +#define E_XSTUDIO_STREAM_NOT_MAPPED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 9 ) +#define E_XSTUDIO_STREAM_ALREADY_MAPPED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 10 ) +#define E_XSTUDIO_NO_STREAM_SPECIFIED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 13 ) +#define E_XSTUDIO_INVALID_TIMESTAMP MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 14 ) +#define E_XSTUDIO_SKELETON_DATA_REQUIRED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 15 ) +#define E_XSTUDIO_TRACKING_ID_NOT_FOUND MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 16 ) +#define E_XSTUDIO_INVALID_EVENT_INDEX MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 17 ) +#define E_XSTUDIO_NOT_SUSPENDED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 18 ) +#define E_XSTUDIO_RECORD_WHILE_SUSPENDED MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 19 ) +#define E_XSTUDIO_SUSPEND_WHILE_RECORDING MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 20 ) +#define E_XSTUDIO_SUSPEND_WITHOUT_PLAYING MAKE_HRESULT( SEVERITY_ERROR, FACILITY_XSTUDIO, 21 ) + + +#ifdef __cplusplus +} +#endif + +#include +#include + + +#endif //XSTUDIO + diff --git a/third_party/xbox_sdk/include/XStudioApi.h b/third_party/xbox_sdk/include/XStudioApi.h new file mode 100644 index 0000000..df71c32 --- /dev/null +++ b/third_party/xbox_sdk/include/XStudioApi.h @@ -0,0 +1,390 @@ +/*********************************************************************** +* * +* XStudioApi.h -- This module defines the APIs for Xbox 360 Studio * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +***********************************************************************/ + +#pragma once + +#ifndef XSTUDIO +#error "You must include xstudio.h rather than including xstudioapi.h directly" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define XSTINLINE __inline +#define XSTAPI WINAPI + +#ifndef _XBOX // + +// ----------------------------------------------------------------------------- +// Connection +// ----------------------------------------------------------------------------- + +typedef enum _XSTUDIO_CONNECTION_TYPE +{ + XSTUDIO_CONNECTION_TYPE_USB, + XSTUDIO_CONNECTION_TYPE_TCP, +} XSTUDIO_CONNECTION_TYPE; + +HRESULT +XSTAPI +XStudioConnect( + _In_z_ const char * sConsoleName, + _In_ XSTUDIO_CONNECTION_TYPE ConnectionType +); + +HRESULT +XSTAPI +XStudioDisconnect(); + +HRESULT +XSTAPI +XStudioGetConnectionStatus(); + +#endif // + +// ----------------------------------------------------------------------------- +// XStudio File +// ----------------------------------------------------------------------------- + +HRESULT +XSTAPI +XStudioCreateFile( + _In_z_ const char * sFilePath, + _In_ DWORD dwDesiredAccess, + _In_ DWORD dwCreationDisposition, + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _Out_ XSTUDIO_FILE_HANDLE * phFile +); + +HRESULT +XSTAPI +XStudioCloseFile( + _In_ XSTUDIO_FILE_HANDLE hFile +); + +HRESULT +XSTAPI +XStudioGetFileStreams( + _In_ XSTUDIO_FILE_HANDLE hFile, + _Out_ XSTUDIO_STREAM_FLAGS * pdwStreams +); + +// ----------------------------------------------------------------------------- +// Stream Mapping +// ----------------------------------------------------------------------------- + +HRESULT +XSTAPI +XStudioMapStreams( + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _In_ XSTUDIO_HANDLE hHandle +); + +HRESULT +XSTAPI +XStudioUnmapStreams( + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _In_ XSTUDIO_HANDLE hHandle +); + +// ----------------------------------------------------------------------------- +// Switch Producers +// ----------------------------------------------------------------------------- + +typedef enum XSTUDIO_PRODUCER +{ + XSTUDIO_PRODUCER_FILE, +} XSTUDIO_PRODUCER; + +HRESULT +XSTAPI +XStudioSwitchToProducers( + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _In_ XSTUDIO_PRODUCER producer +); + +// ----------------------------------------------------------------------------- +// Stream Callback +// ----------------------------------------------------------------------------- + +#define XSTUDIO_STREAM_CALLBACK_REGISTRATION_FLAG_CONSUMER 0x00000001 +#define XSTUDIO_STREAM_CALLBACK_REGISTRATION_FLAG_PRODUCER 0x00000002 + + +#define XSTUDIO_STREAM_CALLBACK_REGISTRATION_FLAG_PRODUCER_FILL_IN 0x00000005 + +#define XSTUDIO_STREAM_CALLBACK_REGISTRATION_FLAG_REALTIME 0x00000100 + + +typedef struct _XSTUDIO_STREAM_EVENT +{ + UINT cbSize; + + XSTUDIO_STREAM_ID StreamID; + UINT uEventIndex; + + UINT64 uEventMicroseconds; + + void* pvIndexBuffer; + UINT cbIndexBufferSize; + UINT cbIndexBufferUsed; + + void* pvDataBuffer; + UINT cbDataBufferSize; + UINT cbDataBufferUsed; +} XSTUDIO_STREAM_EVENT; + + +typedef enum _NUI_IMAGE_TYPE NUI_IMAGE_TYPE; + +typedef struct _XSTUDIO_NUICAM_IMAGE_INDEX_DATA +{ + NUI_IMAGE_TYPE ImageType; + USHORT Width; + USHORT Height; + DWORD FrameNumber; + DWORD64 NuiTimeStamp; + +} XSTUDIO_NUICAM_IMAGE_INDEX_DATA; + + +typedef struct _XSTUDIO_TITLE_INDEX_DATA +{ + UINT64 Reserved; + DWORD IndexData[4]; + +} XSTUDIO_TITLE_INDEX_DATA; + +#ifdef _XBOX // +#endif // + +#ifndef _XBOX // + +typedef HRESULT (CALLBACK * XSTUDIO_STREAM_CALLBACK)( + _Inout_ XSTUDIO_STREAM_EVENT* pStreamEvent, + _In_opt_ void* pvStreamCallbackContext ); + +HRESULT +XSTAPI +XStudioRegisterStreamCallback( + _In_ XSTUDIO_STREAM_CALLBACK pfnStreamCallback, + _In_ DWORD dwStreamCallbackRegistrationFlags, + _In_opt_ void* pvStreamCallbackContext, + _Out_ XSTUDIO_HANDLE* phStreamCallback +); + +HRESULT +XSTAPI +XStudioCloseHandle( + _In_ XSTUDIO_HANDLE Handle +); + +#endif // + +// ----------------------------------------------------------------------------- +// Notifications +// ----------------------------------------------------------------------------- + +typedef HRESULT (CALLBACK * XSTUDIO_NOTIFICATION_CALLBACK)( + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _In_ DWORD dwNotification, + _In_ void* pvContext, + _In_ LPARAM lparam); + +#ifndef _XBOX // + +HRESULT +XSTAPI +XStudioRegisterNotificationCallback( + _In_ XSTUDIO_NOTIFICATION_CALLBACK pfnNotificationCallback, + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _In_ DWORD dwNotificationsFlags, + _In_ DWORD dwFlags, + _In_ void* pvContext, + _Out_ XSTUDIO_HANDLE* phandle +); + + +#endif // + +// Called just before playback is started. No events will have been delivered at this point. +#define XSTUDIO_NOTIF_PLAYBACK_STARTING 0x00000001 +// Called just after playback is stopped. No more events will be delivered at this point. +#define XSTUDIO_NOTIF_PLAYBACK_STOPPED 0x00000002 + +// Called just before recording is started. No events will have been delivered at this point. +#define XSTUDIO_NOTIF_RECORDING_STARTING 0x00000004 +// Called just after recording is stopped. No more events will be delivered at this point. +#define XSTUDIO_NOTIF_RECORDING_STOPPED 0x00000008 + +// Called when playback is suspended / resumed +// Does not use stream flags argument +// For SUSPENDED, lparam is one of XSTUDIO_NOTIF_SUSPEND_... +#define XSTUDIO_NOTIF_SUSPENDED 0x00000010 +#define XSTUDIO_NOTIF_RESUMING 0x00000020 + +// Called after the last event in a loop iteration, +// but before the first event in the next loop iteration +#define XSTUDIO_NOTIF_LOOPING 0x00000040 + +// Switching to a diff producer. Sent before any event make it to the new producer. +// lparam is one of the XSTUDIO_PRODUCER_... values +#define XSTUDIO_NOTIF_SWITCHING_TO_PROD 0x00000080 + +// Switched to a diff producer. Sent after the switch to a producer is complete. +// lparam is one of the XSTUDIO_PRODUCER_... values +#define XSTUDIO_NOTIF_SWITCHED_TO_PROD 0x00000100 + + + +//-------------------------------- +// Suspend reasons +//-------------------------------- +#define XSTUDIO_NOTIF_SUSPEND_API 1 +#define XSTUDIO_NOTIF_SUSPEND_SUSPENDPOINT 2 +#define XSTUDIO_NOTIF_SUSPEND_SINGLESTEP 3 + +// ----------------------------------------------------------------------------- +// Monitoring / Live Preview +// ----------------------------------------------------------------------------- + +#ifndef _XBOX // + + +#endif // + +// ----------------------------------------------------------------------------- +// Record and Play Control +// ----------------------------------------------------------------------------- + +HRESULT +XSTAPI +XStudioStart( + _In_ XSTUDIO_STREAM_FLAGS dwStreams +); + +HRESULT +XSTAPI +XStudioStop( + _In_ XSTUDIO_STREAM_FLAGS dwStreams +); + +HRESULT +XSTAPI +XStudioStopEx( + _In_ XSTUDIO_STREAM_FLAGS dwStreams, + _In_ XSTUDIO_HANDLE handle +); + +// ----------------------------------------------------------------------------- +// Status Query +// ----------------------------------------------------------------------------- + + +HRESULT +XSTAPI +XStudioGetActiveStreams( + _Out_ XSTUDIO_STREAM_FLAGS * pdwStreams +); + +HRESULT +XSTAPI +XStudioGetErrorStreams( + _Out_ XSTUDIO_STREAM_FLAGS * pdwStreams +); + + +// ----------------------------------------------------------------------------- +// Title Data +// ----------------------------------------------------------------------------- + +#define XSTUDIO_TITLE_DATA_MAX_BUFFER_SIZE (32*1024) + +#ifdef _XBOX // + +HRESULT +XSTAPI +XStudioWriteTitleData( + _In_opt_ const XSTUDIO_TITLE_INDEX_DATA * pTitleIndexData, + _In_opt_bytecount_(dwTitleDataBufferSize) const void * pTitleDataBuffer, + _In_ DWORD dwTitleDataBufferSize +); + +HRESULT +XSTAPI +XStudioReadTitleData( + _In_ DWORD dwMillisecondsToWait, + _Out_opt_ XSTUDIO_TITLE_INDEX_DATA * pTitleIndexData, + _Out_opt_bytecap_(dwTitleDataBufferSize) void * pTitleDataBuffer, + _In_ DWORD dwTitleDataBufferSize, + _Out_ DWORD * pdwRequiredTitleDataBufferSize +); + +#endif // + +// ----------------------------------------------------------------------------- +// Input Mode +// ----------------------------------------------------------------------------- + +typedef enum _XSTUDIO_INPUT_MODE +{ + XSTUDIO_INPUT_MODE_DEFAULT, + XSTUDIO_INPUT_MODE_SIMULATED, + + XSTUDIO_INPUT_MODE_INVALID = 0xFFFFFFFF, + +} XSTUDIO_INPUT_MODE; + + +HRESULT XStudioSetInputMode( + XSTUDIO_STREAM_FLAGS streamFlags, + XSTUDIO_INPUT_MODE InputMode +); + +HRESULT XStudioGetInputMode( + XSTUDIO_STREAM_FLAGS streamFlags, + _Out_ XSTUDIO_INPUT_MODE * pInputModeOut +); + +// ----------------------------------------------------------------------------- +// Loop +// ----------------------------------------------------------------------------- + +HRESULT XStudioSetLoopCount( XSTUDIO_STREAM_FLAGS streamFlags, UINT loopCount ); +HRESULT XStudioGetLoopCount( XSTUDIO_STREAM_FLAGS streamFlags, _Out_ UINT * pLoopCount ); + + +// ----------------------------------------------------------------------------- +// Suspend / Resume +// ----------------------------------------------------------------------------- + +HRESULT XStudioSuspend( XSTUDIO_STREAM_FLAGS streamFlags ); +HRESULT XStudioResume( XSTUDIO_STREAM_FLAGS streamFlags ); + +#ifndef _XBOX // + +// ----------------------------------------------------------------------------- +// Suspend points / Single step +// ----------------------------------------------------------------------------- +HRESULT XStudioAddSuspendPoint( + _In_ XSTUDIO_STREAM_ID dwStreamID, + _In_ DWORD dwEventIndex, + _Out_ XSTUDIO_HANDLE* phandle +); + +HRESULT XStudioSingleStep( + _In_ XSTUDIO_STREAM_FLAGS dwStreams +); + +#endif // + +#ifdef __cplusplus +} +#endif + diff --git a/third_party/xbox_sdk/include/XStudioService.h b/third_party/xbox_sdk/include/XStudioService.h new file mode 100644 index 0000000..c40a577 --- /dev/null +++ b/third_party/xbox_sdk/include/XStudioService.h @@ -0,0 +1,98 @@ +/*************************************************************************** +* * +* XStudioService.h -- This module defines the APIs for Xbox 360 Studio * +* Services * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +***************************************************************************/ + +#pragma once + +#ifndef XSTUDIO +#error "You must include xstudio.h rather than including xstudioservice.h directly" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +// Set bitfield ordering to lsb->msb on PPC (default is msb->lsb) +#if defined(_M_PPCBE) +#pragma bitfield_order(push) +#pragma bitfield_order(lsb_to_msb) +#endif + + +// ----------------------------------------------------------------------------- +// Handle Types +// ----------------------------------------------------------------------------- + +typedef unsigned int XSTUDIO_HANDLE; + +typedef XSTUDIO_HANDLE XSTUDIO_FILE_HANDLE; + +// ----------------------------------------------------------------------------- +// Stream Types +// ----------------------------------------------------------------------------- + +typedef enum _XSTUDIO_STREAM_ID +{ + XSTUDIO_STREAM_ID_NUICAM_BASE = 0, + XSTUDIO_STREAM_ID_NUICAM_DEPTH = XSTUDIO_STREAM_ID_NUICAM_BASE + 0, // 0 + XSTUDIO_STREAM_ID_NUICAM_COLOR = XSTUDIO_STREAM_ID_NUICAM_BASE + 1, // 1 + + XSTUDIO_STREAM_ID_NUIAPI_BASE = 4, + XSTUDIO_STREAM_ID_NUIAPI_SKELETON = XSTUDIO_STREAM_ID_NUIAPI_BASE + 0, // 4 + XSTUDIO_STREAM_ID_NUIAPI_IDENTITY = XSTUDIO_STREAM_ID_NUIAPI_BASE + 2, // 6 + XSTUDIO_STREAM_ID_NUIAPI_PLAYER_INDEX = XSTUDIO_STREAM_ID_NUIAPI_BASE + 3, // 7 + + XSTUDIO_STREAM_ID_TITLE_BASE = 16, + XSTUDIO_STREAM_ID_TITLE_DATA = XSTUDIO_STREAM_ID_TITLE_BASE + 0, // 16 + + XSTUDIO_STREAM_ID_MISC_PRIVATE = 31, // 31 + + XSTUDIO_STREAM_ID_COUNT = 32, + + XSTUDIO_STREAM_ID_INVALID = 0xFFFFFFFF + +} XSTUDIO_STREAM_ID; + + +typedef DWORD XSTUDIO_STREAM_FLAGS, *PXSTUDIO_STREAM_FLAGS; + +#define XSTUDIO_STREAM_FLAG_NONE ( 0 ) +#define XSTUDIO_STREAM_FLAG_DEFAULT ( (XSTUDIO_STREAM_FLAGS)-1 ) + +#define XSTUDIO_STREAM_FLAG_NUICAM_DEPTH ( 1 << XSTUDIO_STREAM_ID_NUICAM_DEPTH ) +#define XSTUDIO_STREAM_FLAG_NUICAM_COLOR ( 1 << XSTUDIO_STREAM_ID_NUICAM_COLOR ) +#define XSTUDIO_STREAM_FLAG_NUICAM_ALL ( XSTUDIO_STREAM_FLAG_NUICAM_DEPTH | XSTUDIO_STREAM_FLAG_NUICAM_COLOR ) + +#define XSTUDIO_STREAM_FLAG_NUIAPI_SKELETON ( 1 << XSTUDIO_STREAM_ID_NUIAPI_SKELETON ) +#define XSTUDIO_STREAM_FLAG_NUIAPI_IDENTITY ( 1 << XSTUDIO_STREAM_ID_NUIAPI_IDENTITY ) +#define XSTUDIO_STREAM_FLAG_NUIAPI_PLAYER_INDEX ( 1 << XSTUDIO_STREAM_ID_NUIAPI_PLAYER_INDEX ) + +#define XSTUDIO_STREAM_FLAG_NUIAPI_ALL ( XSTUDIO_STREAM_FLAG_NUIAPI_SKELETON \ + | XSTUDIO_STREAM_FLAG_NUIAPI_IDENTITY \ + | XSTUDIO_STREAM_FLAG_NUIAPI_PLAYER_INDEX ) + + +#define XSTUDIO_STREAM_FLAG_TITLE_DATA ( 1 << XSTUDIO_STREAM_ID_TITLE_DATA ) +#define XSTUDIO_STREAM_FLAG_TITLE_ALL ( XSTUDIO_STREAM_FLAG_TITLE_DATA ) + + +#define XSTUDIO_STREAM_FLAG_ALL ( XSTUDIO_STREAM_FLAG_NUICAM_ALL \ + | XSTUDIO_STREAM_FLAG_NUIAPI_ALL \ + | XSTUDIO_STREAM_FLAG_TITLE_ALL ) + + + +#if defined(_M_PPCBE) +#pragma bitfield_order(pop) +#endif + +#ifdef __cplusplus +} +#endif + diff --git a/third_party/xbox_sdk/include/XedFile.h b/third_party/xbox_sdk/include/XedFile.h new file mode 100644 index 0000000..ee0527b --- /dev/null +++ b/third_party/xbox_sdk/include/XedFile.h @@ -0,0 +1,373 @@ +/************************************************************************** +* * +* XedFile.h -- This module defines the APIs for Xbox 360 Studio Files * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +**************************************************************************/ + +#pragma once + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define XEDAPI WINAPI + +typedef enum _NUI_IMAGE_TYPE NUI_IMAGE_TYPE; +typedef struct _NUI_SKELETON_FRAME NUI_SKELETON_FRAME; +typedef struct _NUI_IDENTITY_MESSAGE NUI_IDENTITY_MESSAGE; + + +#ifndef NUI_INITIALIZE_FLAG_USES_COLOR + #define NUI_INITIALIZE_FLAG_USES_COLOR 0x00000002 +#endif + +#ifndef NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR + #define NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR 0x00000040 +#endif + +typedef struct _XSTUDIO_TITLE_INDEX_DATA XSTUDIO_TITLE_INDEX_DATA; + + +typedef struct XED_CONTEXT XED_CONTEXT; + + +#define XED_EVENTINDEX_INVALID ((UINT)-1) +#define XED_FRAMENUMBER_INVALID ((UINT)-1) +#define XED_TIMESTAMP_INVALID ((UINT64)-1) + +#define XED_FLAG_CREATE_NEW CREATE_NEW +#define XED_FLAG_CREATE_ALWAYS CREATE_ALWAYS + + +HRESULT +XEDAPI +XedOpenFile( + _In_z_ const char * sFilePath, + DWORD flags, + _Deref_out_opt_ XED_CONTEXT ** ppContext + ); + + +HRESULT +XEDAPI +XedCreateFile( + _In_z_ const char * sFilePath, + _In_opt_ const XED_CONTEXT * pTemplate, + DWORD flags, + _Deref_out_opt_ XED_CONTEXT ** ppContext + ); + + + +HRESULT +XEDAPI +XedCloseFile( + XED_CONTEXT ** ppContext + ); + + +HRESULT +XedSetNuiDepthImageType( + XED_CONTEXT * pContext, + NUI_IMAGE_TYPE newImageType, + NUI_IMAGE_TYPE * pPreviousImageType +); + + +HRESULT +XEDAPI +XedSetNuiColorBufferType( + _In_ XED_CONTEXT * pContext, + NUI_IMAGE_TYPE newImageType, + _Out_opt_ NUI_IMAGE_TYPE * pPreviousImageType + ); + + +HRESULT +XEDAPI +XedSetFileNuiColorQuality( + _In_ XED_CONTEXT * pContext, + DWORD newColorQuality, + _Out_opt_ DWORD * pPreviousColorQuality + ); + + +UINT +XEDAPI +XedGetNuiDepthEventCount( + _In_ XED_CONTEXT * pContext + ); + + +UINT +XEDAPI +XedGetNuiColorEventCount( + _In_ XED_CONTEXT * pContext + ); + + +UINT +XEDAPI +XedGetNuiSkeletonEventCount( + _In_ XED_CONTEXT * pContext + ); + + +UINT +XEDAPI +XedGetNuiDepthEventIndexFromFrameNumber( + _In_ XED_CONTEXT * pContext, + UINT frameNumber + ); + + +UINT +XEDAPI +XedGetNuiColorEventIndexFromFrameNumber( + _In_ XED_CONTEXT * pContext, + UINT frameNumber + ); + + +UINT +XEDAPI +XedGetNuiSkeletonEventIndexFromFrameNumber( + _In_ XED_CONTEXT * pContext, + UINT frameNumber + ); + + +UINT +XEDAPI +XedGetNuiDepthEventIndexFromMicroseconds( + _In_ XED_CONTEXT * pContext, + UINT64 frameMicroseconds + ); + + +UINT +XEDAPI +XedGetNuiColorEventIndexFromMicroseconds( + _In_ XED_CONTEXT * pContext, + UINT64 frameMicroseconds + ); + + +UINT +XEDAPI +XedGetNuiSkeletonEventIndexFromMicroseconds( + _In_ XED_CONTEXT * pContext, + UINT64 frameMicroseconds + ); + + +HRESULT +XEDAPI +XedReadNuiDepthFrame( + _In_ XED_CONTEXT * pContext, + UINT eventIndex, + _Out_opt_ UINT * pFrameNumber, + _Out_opt_ UINT64 * pFrameMicroseconds, + _Out_opt_bytecap_(bufferSize) WORD * pBuffer, + UINT bufferSize, // in bytes + BOOL registerWithColor + ); + + +HRESULT +XEDAPI +XedReadNuiColorFrame( + _In_ XED_CONTEXT * pContext, + UINT eventIndex, + _Out_opt_ UINT * pFrameNumber, + _Out_opt_ UINT64 * pFrameMicroseconds, + _Out_opt_bytecap_(bufferSize) DWORD * pBuffer, + UINT bufferSize, // in bytes + BOOL registerWithDepth + ); + + +HRESULT +XEDAPI +XedReadNuiSkeletonFrame( + _In_ XED_CONTEXT * pContext, + UINT eventIndex, + _Out_opt_ UINT * pFrameNumber, + _Out_opt_ UINT64 * pFrameMicroseconds, + _Out_opt_bytecap_(skeletonFrameSize) NUI_SKELETON_FRAME * pSkeletonFrame, + UINT skeletonFrameSize + ); + + +HRESULT +XEDAPI +XedWriteNuiDepthFrame( + _In_ XED_CONTEXT * pContext, + UINT frameNumber, + UINT64 frameMicroseconds, + _In_bytecount_(bufferSize) const WORD * pBuffer, + UINT bufferSize // in bytes + ); + + +HRESULT +XEDAPI +XedWriteNuiColorFrame( + _In_ XED_CONTEXT * pContext, + UINT frameNumber, + UINT64 frameMicroseconds, + _In_bytecount_(bufferSize) const DWORD * pBuffer, + UINT bufferSize // in bytes + ); + + +HRESULT +XEDAPI +XedWriteNuiSkeletonFrame( + _In_ XED_CONTEXT * pContext, + UINT frameNumber, + UINT64 frameMicroseconds, + _In_bytecount_(skeletonFrameSize) const NUI_SKELETON_FRAME * pSkeletonFrame, + UINT skeletonFrameSize + ); + + +HRESULT +XEDAPI +XedCopyNuiDepthFrame( + _In_ XED_CONTEXT * pFromContext, + UINT eventIndex, + _In_ XED_CONTEXT * pToContext, + UINT frameNumber, + UINT64 frameMicroseconds + ); + + +HRESULT +XEDAPI +XedCopyNuiColorFrame( + _In_ XED_CONTEXT * pFromContext, + UINT eventIndex, + _In_ XED_CONTEXT * pToContext, + UINT frameNumber, + UINT64 frameMicroseconds + ); + + +HRESULT +XEDAPI +XedCopyNuiSkeletonFrame( + _In_ XED_CONTEXT * pFromContext, + UINT eventIndex, + _In_ XED_CONTEXT * pToContext, + UINT frameNumber, + UINT64 frameMicroseconds + ); + + +UINT +XEDAPI +XedGetTitleDataEventCount( + _In_ XED_CONTEXT * pContext + ); + + +UINT +XEDAPI +XedGetTitleDataEventIndexFromMicroseconds( + _In_ XED_CONTEXT * pContext, + UINT64 eventMicroseconds + ); + + +HRESULT +XEDAPI +XedReadTitleData( + _In_ XED_CONTEXT * pContext, + UINT eventIndex, + _Out_opt_ UINT64 * pEventMicroseconds, + _Out_opt_ XSTUDIO_TITLE_INDEX_DATA * pTitleIndexData, + _Out_opt_bytecap_(titleDataBufferSize) void * pTitleDataBuffer, + UINT titleDataBufferSize, + _Out_ UINT * pRequiredTitleDataBufferSize + ); + + +HRESULT +XEDAPI +XedWriteTitleData( + _In_ XED_CONTEXT * pContext, + UINT64 eventMicroseconds, + _In_opt_ const XSTUDIO_TITLE_INDEX_DATA * pTitleIndexData, + _In_bytecount_(titleDataBufferSize) const void * pTitleDataBuffer, + UINT titleDataBufferSize + ); + + +HRESULT +XEDAPI +XedCopyTitleData( + _In_ XED_CONTEXT * pFromContext, + UINT eventIndex, + _In_ XED_CONTEXT * pToContext, + UINT64 eventMicroseconds + ); + + + +UINT +XEDAPI +XedGetEventCount( + _In_ XED_CONTEXT * pContext, + XSTUDIO_STREAM_ID streamId +); + + +UINT +XEDAPI +XedGetEventIndexFromMicroseconds( + _In_ XED_CONTEXT * pContext, + XSTUDIO_STREAM_ID streamId, + UINT64 eventMicroseconds +); + + +HRESULT +XEDAPI +XedReadNuiIdentityMessage( + _In_ XED_CONTEXT * pContext, + UINT eventIndex, + _Out_opt_ UINT64* pFrameMicroseconds, + _Out_opt_bytecap_(identityMessageSize) NUI_IDENTITY_MESSAGE * pIdentityMessage, + UINT identityMessageSize +); + + +HRESULT +XEDAPI +XedWriteNuiIdentityMessage( + _In_ XED_CONTEXT * pContext, + UINT64 frameMicroseconds, + _In_bytecount_(identityMessageSize) const NUI_IDENTITY_MESSAGE * pIdentityMessage, + UINT identityMessageSize +); + + +HRESULT +XEDAPI +XedCopyNuiIdentityMessage( + _In_ XED_CONTEXT * pSrcContext, + UINT srcEventIndex, + _In_ XED_CONTEXT * pDstContext, + DWORD dwDstTrackingID, + UINT64 dstEventMicroseconds ); + + +#ifdef __cplusplus +} // extern "C" +#endif + diff --git a/third_party/xbox_sdk/include/audiodefs.h b/third_party/xbox_sdk/include/audiodefs.h new file mode 100644 index 0000000..ff995ec --- /dev/null +++ b/third_party/xbox_sdk/include/audiodefs.h @@ -0,0 +1,263 @@ +/*************************************************************************** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * + * File: audiodefs.h + * Content: Basic constants and data types for audio work. + * + * Remarks: This header file defines all of the audio format constants and + * structures required for XAudio2 and XACT work. Providing these + * in a single location avoids certain dependency problems in the + * legacy audio headers (mmreg.h, mmsystem.h, ksmedia.h). + * + * NOTE: Including the legacy headers after this one may cause a + * compilation error, because they define some of the same types + * defined here without preprocessor guards to avoid multiple + * definitions. If a source file needs one of the old headers, + * it must include it before including audiodefs.h. + * + ***************************************************************************/ + +#ifndef __AUDIODEFS_INCLUDED__ +#define __AUDIODEFS_INCLUDED__ + +#include // For WORD, DWORD, etc. + +#pragma pack(push, 1) // Pack structures to 1-byte boundaries + + +/************************************************************************** + * + * WAVEFORMATEX: Base structure for many audio formats. Format-specific + * extensions can be defined for particular formats by using a non-zero + * cbSize value and adding extra fields to the end of this structure. + * + ***************************************************************************/ + +#ifndef _WAVEFORMATEX_ + + #define _WAVEFORMATEX_ + typedef struct tWAVEFORMATEX + { + WORD wFormatTag; // Integer identifier of the format + WORD nChannels; // Number of audio channels + DWORD nSamplesPerSec; // Audio sample rate + DWORD nAvgBytesPerSec; // Bytes per second (possibly approximate) + WORD nBlockAlign; // Size in bytes of a sample block (all channels) + WORD wBitsPerSample; // Size in bits of a single per-channel sample + WORD cbSize; // Bytes of extra data appended to this struct + } WAVEFORMATEX; + +#endif + +// Defining pointer types outside of the #if block to make sure they are +// defined even if mmreg.h or mmsystem.h is #included before this file + +typedef WAVEFORMATEX *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX; +typedef const WAVEFORMATEX *PCWAVEFORMATEX, *LPCWAVEFORMATEX; + + +/************************************************************************** + * + * WAVEFORMATEXTENSIBLE: Extended version of WAVEFORMATEX that should be + * used as a basis for all new audio formats. The format tag is replaced + * with a GUID, allowing new formats to be defined without registering a + * format tag with Microsoft. There are also new fields that can be used + * to specify the spatial positions for each channel and the bit packing + * used for wide samples (e.g. 24-bit PCM samples in 32-bit containers). + * + ***************************************************************************/ + +#ifndef _WAVEFORMATEXTENSIBLE_ + + #define _WAVEFORMATEXTENSIBLE_ + typedef struct + { + WAVEFORMATEX Format; // Base WAVEFORMATEX data + union + { + WORD wValidBitsPerSample; // Valid bits in each sample container + WORD wSamplesPerBlock; // Samples per block of audio data; valid + // if wBitsPerSample=0 (but rarely used). + WORD wReserved; // Zero if neither case above applies. + } Samples; + DWORD dwChannelMask; // Positions of the audio channels + GUID SubFormat; // Format identifier GUID + } WAVEFORMATEXTENSIBLE; + +#endif + +typedef WAVEFORMATEXTENSIBLE *PWAVEFORMATEXTENSIBLE, *LPWAVEFORMATEXTENSIBLE; +typedef const WAVEFORMATEXTENSIBLE *PCWAVEFORMATEXTENSIBLE, *LPCWAVEFORMATEXTENSIBLE; + + + +/************************************************************************** + * + * Define the most common wave format tags used in WAVEFORMATEX formats. + * + ***************************************************************************/ + +#ifndef WAVE_FORMAT_PCM // Pulse Code Modulation + + // If WAVE_FORMAT_PCM is not defined, we need to define some legacy types + // for compatibility with the Windows mmreg.h / mmsystem.h header files. + + // Old general format structure (information common to all formats) + typedef struct waveformat_tag + { + WORD wFormatTag; + WORD nChannels; + DWORD nSamplesPerSec; + DWORD nAvgBytesPerSec; + WORD nBlockAlign; + } WAVEFORMAT, *PWAVEFORMAT, NEAR *NPWAVEFORMAT, FAR *LPWAVEFORMAT; + + // Specific format structure for PCM data + typedef struct pcmwaveformat_tag + { + WAVEFORMAT wf; + WORD wBitsPerSample; + } PCMWAVEFORMAT, *PPCMWAVEFORMAT, NEAR *NPPCMWAVEFORMAT, FAR *LPPCMWAVEFORMAT; + + #define WAVE_FORMAT_PCM 0x0001 + +#endif + +#ifndef WAVE_FORMAT_ADPCM // Microsoft Adaptive Differental PCM + + // Replicate the Microsoft ADPCM type definitions from mmreg.h. + + typedef struct adpcmcoef_tag + { + short iCoef1; + short iCoef2; + } ADPCMCOEFSET; + + #pragma warning(push) + #pragma warning(disable:4200) // Disable zero-sized array warnings + + typedef struct adpcmwaveformat_tag { + WAVEFORMATEX wfx; + WORD wSamplesPerBlock; + WORD wNumCoef; + ADPCMCOEFSET aCoef[]; // Always 7 coefficient pairs for MS ADPCM + } ADPCMWAVEFORMAT; + + #pragma warning(pop) + + #define WAVE_FORMAT_ADPCM 0x0002 + +#endif + +// Other frequently used format tags + +#ifndef WAVE_FORMAT_UNKNOWN + #define WAVE_FORMAT_UNKNOWN 0x0000 // Unknown or invalid format tag +#endif + +#ifndef WAVE_FORMAT_IEEE_FLOAT + #define WAVE_FORMAT_IEEE_FLOAT 0x0003 // 32-bit floating-point +#endif + +#ifndef WAVE_FORMAT_MPEGLAYER3 + #define WAVE_FORMAT_MPEGLAYER3 0x0055 // ISO/MPEG Layer3 +#endif + +#ifndef WAVE_FORMAT_DOLBY_AC3_SPDIF + #define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092 // Dolby Audio Codec 3 over S/PDIF +#endif + +#ifndef WAVE_FORMAT_WMAUDIO2 + #define WAVE_FORMAT_WMAUDIO2 0x0161 // Windows Media Audio +#endif + +#ifndef WAVE_FORMAT_WMAUDIO3 + #define WAVE_FORMAT_WMAUDIO3 0x0162 // Windows Media Audio Pro +#endif + +#ifndef WAVE_FORMAT_WMASPDIF + #define WAVE_FORMAT_WMASPDIF 0x0164 // Windows Media Audio over S/PDIF +#endif + +#ifndef WAVE_FORMAT_EXTENSIBLE + #define WAVE_FORMAT_EXTENSIBLE 0xFFFE // All WAVEFORMATEXTENSIBLE formats +#endif + + +/************************************************************************** + * + * Define the most common wave format GUIDs used in WAVEFORMATEXTENSIBLE + * formats. Note that including the Windows ksmedia.h header after this + * one will cause build problems; this cannot be avoided, since ksmedia.h + * defines these macros without preprocessor guards. + * + ***************************************************************************/ + +#ifdef __cplusplus // uuid() and __uuidof() are only available in C++ + + #ifndef KSDATAFORMAT_SUBTYPE_PCM + struct __declspec(uuid("00000001-0000-0010-8000-00aa00389b71")) KSDATAFORMAT_SUBTYPE_PCM_STRUCT; + #define KSDATAFORMAT_SUBTYPE_PCM __uuidof(KSDATAFORMAT_SUBTYPE_PCM_STRUCT) + #endif + + #ifndef KSDATAFORMAT_SUBTYPE_ADPCM + struct __declspec(uuid("00000002-0000-0010-8000-00aa00389b71")) KSDATAFORMAT_SUBTYPE_ADPCM_STRUCT; + #define KSDATAFORMAT_SUBTYPE_ADPCM __uuidof(KSDATAFORMAT_SUBTYPE_ADPCM_STRUCT) + #endif + + #ifndef KSDATAFORMAT_SUBTYPE_IEEE_FLOAT + struct __declspec(uuid("00000003-0000-0010-8000-00aa00389b71")) KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_STRUCT; + #define KSDATAFORMAT_SUBTYPE_IEEE_FLOAT __uuidof(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT_STRUCT) + #endif + +#endif + + +/************************************************************************** + * + * Speaker positions used in the WAVEFORMATEXTENSIBLE dwChannelMask field. + * + ***************************************************************************/ + +#ifndef SPEAKER_FRONT_LEFT + #define SPEAKER_FRONT_LEFT 0x00000001 + #define SPEAKER_FRONT_RIGHT 0x00000002 + #define SPEAKER_FRONT_CENTER 0x00000004 + #define SPEAKER_LOW_FREQUENCY 0x00000008 + #define SPEAKER_BACK_LEFT 0x00000010 + #define SPEAKER_BACK_RIGHT 0x00000020 + #define SPEAKER_FRONT_LEFT_OF_CENTER 0x00000040 + #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080 + #define SPEAKER_BACK_CENTER 0x00000100 + #define SPEAKER_SIDE_LEFT 0x00000200 + #define SPEAKER_SIDE_RIGHT 0x00000400 + #define SPEAKER_TOP_CENTER 0x00000800 + #define SPEAKER_TOP_FRONT_LEFT 0x00001000 + #define SPEAKER_TOP_FRONT_CENTER 0x00002000 + #define SPEAKER_TOP_FRONT_RIGHT 0x00004000 + #define SPEAKER_TOP_BACK_LEFT 0x00008000 + #define SPEAKER_TOP_BACK_CENTER 0x00010000 + #define SPEAKER_TOP_BACK_RIGHT 0x00020000 + #define SPEAKER_RESERVED 0x7FFC0000 + #define SPEAKER_ALL 0x80000000 + #define _SPEAKER_POSITIONS_ +#endif + +#ifndef SPEAKER_STEREO + #define SPEAKER_MONO (SPEAKER_FRONT_CENTER) + #define SPEAKER_STEREO (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT) + #define SPEAKER_2POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY) + #define SPEAKER_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_BACK_CENTER) + #define SPEAKER_QUAD (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT) + #define SPEAKER_4POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT) + #define SPEAKER_5POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT) + #define SPEAKER_7POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER) + #define SPEAKER_5POINT1_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT) + #define SPEAKER_7POINT1_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT) +#endif + + +#pragma pack(pop) + +#endif // #ifndef __AUDIODEFS_INCLUDED__ diff --git a/third_party/xbox_sdk/include/d3d9.h b/third_party/xbox_sdk/include/d3d9.h new file mode 100644 index 0000000..9c677b2 --- /dev/null +++ b/third_party/xbox_sdk/include/d3d9.h @@ -0,0 +1,5282 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: d3d9.h + * Content: Xbox 360 Direct3D include file + * + ****************************************************************************/ + +#ifndef _D3D9_H_ +#define _D3D9_H_ + +#if defined(_XBOX) + #include "xbox.h" +#elif defined(_X86_) + #include +#endif + +#include + +#pragma warning( push ) + +// Disable unreferenced parameter, nameless struct/union, zero-sized +// array, structure padded due to __declspec(align()) and conditional +// expression is constant warnings for this header. + +#pragma warning( disable : 4100 4201 4200 4324 4127 ) + +#define DIRECT3D_VERSION 0x0900 +#define D3D_SDK_VERSION 0 + +/**************************************************************************** + * + * D3DCOMPILE_USEVOIDS + * + * On Xbox 360, all D3D APIs (except Create* calls and some other exceptions) + * always return S_OK. D3D parameter checking is only done (on debug builds) + * via assertions, so the API functions could really be declared 'void' + * and have no return value, resulting in better clarity and potentially + * slightly better performance. But the PC version of DirectX returns + * HRESULT values for all APIs, so for compatibility we declare them the + * same way, by default. + * + * If you prefer to have the D3D APIs declared as void when there is no + * return value other than S_OK, simply #define D3DCOMPILE_USEVOIDS before + * including d3d9.h. + * + * Note that Create* APIs do memory allocations and so can return either + * S_OK or E_OUTOFMEMORY. + * + ****************************************************************************/ + +#ifdef D3DCOMPILE_USEVOIDS + #define D3DVOID void + #define D3DVOIDRETURN return +#else + #define D3DVOID HRESULT + #define D3DVOIDRETURN return S_OK +#endif + +#define D3DINLINE static __forceinline +#define D3DMINLINE __forceinline + +#define D3DFASTCALL __fastcall +#define DECLSPEC_SELECTANY __declspec(selectany) + +#if defined(_XBOX) && !defined(_NORESTRICT_) && !defined(_PREFAST_) + #define D3DRESTRICT __restrict +#else + #define D3DRESTRICT +#endif + +#if defined(_XBOX) + // The Xbox 360 compiler supports the '__IsIntConst' intrinsic which + // always evaluates to a value of 1 if the argument is constant and + // 0 if it's not. + #define D3DISINTCONST(x) __IsIntConst((int) (x)) +#else + // The x86 compiler doesn't support the '__IsIntConst' intrinsic so + // always assume that the argument is not constant in order to avoid + // code bloat. + #define D3DISINTCONST(x) FALSE +#endif + +// The D3D PixBeginNamedEvent/PixEndNamedEvent/PixSetMarker device methods +// (which are not to be confused with the PIXBeginNamedEvent/PIXEndNamedEvent/ +// PIXSetMarker APIs which do not need a D3D device) should compile to nothing +// on retail builds. +// +// In contrast to the pix.h's USE_PIX define, this functionality should be +// available on x86 builds when using debug libraries. +#if (defined(_DEBUG) || DBG || (defined(PROFILE) && !defined(FASTCAP)) || defined(PROFILE_BUILD)) + #define USE_D3D_PIX_METHODS +#endif + +#include +#ifdef _XBOX +#include +#endif + +// Xbox 360 Direct3D internal native types. + +typedef struct Direct3D Direct3D; +typedef struct D3DDevice D3DDevice; +typedef struct D3DStateBlock D3DStateBlock; +typedef struct D3DVertexDeclaration D3DVertexDeclaration; +typedef struct D3DVertexShader D3DVertexShader; +typedef struct D3DPixelShader D3DPixelShader; +typedef struct D3DResource D3DResource; +typedef struct D3DBaseTexture D3DBaseTexture; +typedef struct D3DTexture D3DTexture; +typedef struct D3DVolumeTexture D3DVolumeTexture; +typedef struct D3DCubeTexture D3DCubeTexture; +typedef struct D3DArrayTexture D3DArrayTexture; +typedef struct D3DLineTexture D3DLineTexture; +typedef struct D3DVertexBuffer D3DVertexBuffer; +typedef struct D3DIndexBuffer D3DIndexBuffer; +typedef struct D3DSurface D3DSurface; +typedef struct D3DVolume D3DVolume; +typedef struct D3DQuery D3DQuery; +typedef struct D3DPerfCounters D3DPerfCounters; +typedef struct D3DPerfCounterBatch D3DPerfCounterBatch; +typedef struct D3DConstantBuffer D3DConstantBuffer; +typedef struct D3DCommandBuffer D3DCommandBuffer; +typedef struct D3DAsyncCommandBufferCall D3DAsyncCommandBufferCall; +typedef struct D3DOcclusionQueryBatch D3DOcclusionQueryBatch; + +// Compatibility typedefs. + +#define IDirect3D9 Direct3D +#define IDirect3DDevice9 D3DDevice +#define IDirect3DStateBlock9 D3DStateBlock +#define IDirect3DVertexDeclaration9 D3DVertexDeclaration +#define IDirect3DVertexShader9 D3DVertexShader +#define IDirect3DPixelShader9 D3DPixelShader +#define IDirect3DResource9 D3DResource +#define IDirect3DBaseTexture9 D3DBaseTexture +#define IDirect3DTexture9 D3DTexture +#define IDirect3DVolumeTexture9 D3DVolumeTexture +#define IDirect3DCubeTexture9 D3DCubeTexture +#define IDirect3DArrayTexture9 D3DArrayTexture +#define IDirect3DLineTexture9 D3DLineTexture +#define IDirect3DVertexBuffer9 D3DVertexBuffer +#define IDirect3DIndexBuffer9 D3DIndexBuffer +#define IDirect3DSurface9 D3DSurface +#define IDirect3DVolume9 D3DVolume +#define IDirect3DQuery9 D3DQuery +#define IDirect3DPerfCounter9 D3DPerfCounters // keep both version here for backward compatibility +#define IDirect3DPerfCounters9 D3DPerfCounters +#define IDirect3DPerfCounterBatch9 D3DPerfCounterBatch +#define IDirect3DConstantBuffer9 D3DConstantBuffer +#define IDirect3DCommandBuffer9 D3DCommandBuffer +#define IDirect3DAsyncCommandBufferCall9 D3DAsyncCommandBufferCall +#define IDirect3DOcclusionQueryBatch9 D3DOcclusionQueryBatch + +// Pointer typedefs. + +typedef struct Direct3D *LPDIRECT3D9, *PDIRECT3D9; +typedef struct D3DDevice *LPDIRECT3DDEVICE9, *PDIRECT3DDEVICE9; +typedef struct D3DStateBlock *LPDIRECT3DSTATEBLOCK9, *PDIRECT3DSTATEBLOCK9; +typedef struct D3DVertexDeclaration *LPDIRECT3DVERTEXDECLARATION9, *PDIRECT3DVERTEXDECLARATION9; +typedef struct D3DVertexShader *LPDIRECT3DVERTEXSHADER9, *PDIRECT3DVERTEXSHADER9; +typedef struct D3DPixelShader *LPDIRECT3DPIXELSHADER9, *PDIRECT3DPIXELSHADER9; +typedef struct D3DResource *LPDIRECT3DRESOURCE9, *PDIRECT3DRESOURCE9; +typedef struct D3DBaseTexture *LPDIRECT3DBASETEXTURE9, *PDIRECT3DBASETEXTURE9; +typedef struct D3DTexture *LPDIRECT3DTEXTURE9, *PDIRECT3DTEXTURE9; +typedef struct D3DVolumeTexture *LPDIRECT3DVOLUMETEXTURE9, *PDIRECT3DVOLUMETEXTURE9; +typedef struct D3DCubeTexture *LPDIRECT3DCUBETEXTURE9, *PDIRECT3DCUBETEXTURE9; +typedef struct D3DArrayTexture *LPDIRECT3DARRAYTEXTURE9, *PDIRECT3DARRAYTEXTURE9; +typedef struct D3DLineTexture *LPDIRECT3DLINETEXTURE9, *PDIRECT3DLINETEXTURE9; +typedef struct D3DVertexBuffer *LPDIRECT3DVERTEXBUFFER9, *PDIRECT3DVERTEXBUFFER9; +typedef struct D3DIndexBuffer *LPDIRECT3DINDEXBUFFER9, *PDIRECT3DINDEXBUFFER9; +typedef struct D3DSurface *LPDIRECT3DSURFACE9, *PDIRECT3DSURFACE9; +typedef struct D3DVolume *LPDIRECT3DVOLUME9, *PDIRECT3DVOLUME9; +typedef struct D3DQuery *LPDIRECT3DQUERY9, *PDIRECT3DQUERY9; +typedef struct D3DPerfCounters *LPDIRECT3DPERFCOUNTERS9, *PDIRECT3DPERFCOUNTERS9; +typedef struct D3DPerfCounterBatch *LPDIRECT3DPERFCOUNTERBATCH9, *PDIRECT3DPERFCOUNTERBATCH9; +typedef struct D3DConstantBuffer *LPDIRECT3DCONSTANTBUFFER9, *PDIRECT3DCONSTANTBUFFER9; +typedef struct D3DCommandBuffer *LPDIRECT3DCOMMANDBUFFER9, *PDIRECT3DCOMMANDBUFFER9; +typedef struct D3DAsyncCommandBufferCall *LPDIRECT3DASYNCCOMMANDBUFFERCALL9, *PDIRECT3DASYNCCOMMANDBUFFERCALL9; +typedef struct D3DOcclusionQueryBatch *LPDIRECT3DOCCLUSIONQUERYBATCH9, *PDIRECT3DOCCLUSIONQUERYBATCH9; + +typedef struct _D3DSURFACES { + D3DSurface* pDepthStencilSurface; + D3DSurface* pRenderTarget[4]; +} D3DSURFACES; + +// IDirect3DSwapChain9 is not supported on Xbox 360 + +#include "d3d9types.h" +#include "d3d9caps.h" +#include "d3d9xps.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/**************************************************************************** + * + * D3DVECTOR4 member accessors. When _VECTOR4_STRICT_MEMBER_ACCESS_ is + * defined, individual vector components are not accessible as simple fields. + * + ****************************************************************************/ + +D3DINLINE float D3DVECTOR4_GetX (__in D3DVECTOR4 *pVector) +{ + return *(float*)pVector; +} + +D3DINLINE float D3DVECTOR4_GetY (__in D3DVECTOR4 *pVector) +{ + return *((float*)pVector+1); +} + +D3DINLINE float D3DVECTOR4_GetZ (__in D3DVECTOR4 *pVector) +{ + return *((float*)pVector+2); +} + +D3DINLINE float D3DVECTOR4_GetW (__in D3DVECTOR4 *pVector) +{ + return *((float*)pVector+3); +} + +D3DINLINE void D3DVECTOR4_SetX (__out D3DVECTOR4 *pVector, float Value) +{ + *(float*)pVector = Value; +} + +D3DINLINE void D3DVECTOR4_SetY (__out D3DVECTOR4 *pVector, float Value) +{ + *((float*)pVector+1) = Value; +} + +D3DINLINE void D3DVECTOR4_SetZ (__out D3DVECTOR4 *pVector, float Value) +{ + *((float*)pVector+2) = Value; +} + +D3DINLINE void D3DVECTOR4_SetW (__out D3DVECTOR4 *pVector, float Value) +{ + *((float*)pVector+3) = Value; +} + +/****************************************************************************/ + +D3DINLINE __out Direct3D* WINAPI Direct3DCreate9(UINT SDKVersion) { return (Direct3D*) 1; } + +void WINAPI Direct3DReclaimGrowableMemory(__in_bcount(Size) void* pStart, DWORD Size); + +/**************************************************************************** + * + * Parameter for Direct3D Enum and GetCaps9 functions to get the info for + * the current mode only. + * + ****************************************************************************/ + +#define D3DCURRENT_DISPLAY_MODE 0x00EFFFFFL + +/**************************************************************************** + * + * Flags for Direct3D::CreateDevice's BehaviorFlags + * + ****************************************************************************/ + +#define D3DCREATE_PUREDEVICE 0x00000000L // Ignored on Xbox 360 +#define D3DCREATE_FPU_PRESERVE 0x00000000L // Ignored on Xbox 360 +#define D3DCREATE_HARDWARE_VERTEXPROCESSING 0x00000000L // Ignored on Xbox 360 +#define D3DCREATE_BUFFER_2_FRAMES 0x00000001L // Xbox 360 extension +#define D3DCREATE_CLIPPER_MODE_1 0x00000002L // Xbox 360 extension +#define D3DCREATE_ASYNCHRONOUS_SWAPS 0x00000004L // Xbox 360 extension +#define D3DCREATE_NO_SHADER_PATCHING 0x00000008L // Xbox 360 extension +#define D3DCREATE_CREATE_THREAD_ON_0 0x01000000L // Xbox 360 extension +#define D3DCREATE_CREATE_THREAD_ON_1 0x02000000L // Xbox 360 extension +#define D3DCREATE_CREATE_THREAD_ON_2 0x04000000L // Xbox 360 extension +#define D3DCREATE_CREATE_THREAD_ON_3 0x08000000L // Xbox 360 extension +#define D3DCREATE_CREATE_THREAD_ON_4 0x10000000L // Xbox 360 extension +#define D3DCREATE_CREATE_THREAD_ON_5 0x20000000L // Xbox 360 extension +#define D3DCREATE_CREATE_NO_THREADS 0x00000100L // Xbox 360 extension + +// The following flags are not supported on Xbox 360: +// +// D3DCREATE_MULTITHREADED +// D3DCREATE_SOFTWARE_VERTEXPROCESSING +// D3DCREATE_MIXED_VERTEXPROCESSING +// D3DCREATE_DISABLE_DRIVER_MANAGEMENT +// D3DCREATE_ADAPTERGROUP_DEVICE + +/**************************************************************************** + * + * Parameter for Direct3D::CreateDevice's Adapter + * + ****************************************************************************/ + +#define D3DADAPTER_DEFAULT 0 + +/**************************************************************************** + * + * Flags for Direct3D::EnumAdapters + * + ****************************************************************************/ + +#define D3DENUM_NO_WHQL_LEVEL 0x00000002L + +/**************************************************************************** + * + * Maximum number of back-buffers supported in DX9 + * + ****************************************************************************/ + +#define D3DPRESENT_BACK_BUFFERS_MAX 2L + +/**************************************************************************** + * + * Flags for IDirect3DDevice9::SetGammaRamp + * + ****************************************************************************/ + +#define D3DSGR_NO_CALIBRATION 0x00000000L +#define D3DSGR_IMMEDIATE 0x00000002L + +/* + * DirectDraw error codes + */ + +#define _FACD3D 0x876 +#define MAKE_D3DHRESULT( code ) MAKE_HRESULT( 1, _FACD3D, code ) +#define MAKE_D3DSTATUS( code ) MAKE_HRESULT( 0, _FACD3D, code ) + +/* + * Direct3D Errors + */ + +#define D3D_OK S_OK + +#define D3DERR_WRONGTEXTUREFORMAT MAKE_D3DHRESULT(2072) +#define D3DERR_UNSUPPORTEDCOLOROPERATION MAKE_D3DHRESULT(2073) +#define D3DERR_UNSUPPORTEDCOLORARG MAKE_D3DHRESULT(2074) +#define D3DERR_UNSUPPORTEDALPHAOPERATION MAKE_D3DHRESULT(2075) +#define D3DERR_UNSUPPORTEDALPHAARG MAKE_D3DHRESULT(2076) +#define D3DERR_TOOMANYOPERATIONS MAKE_D3DHRESULT(2077) +#define D3DERR_CONFLICTINGTEXTUREFILTER MAKE_D3DHRESULT(2078) +#define D3DERR_UNSUPPORTEDFACTORVALUE MAKE_D3DHRESULT(2079) +#define D3DERR_CONFLICTINGRENDERSTATE MAKE_D3DHRESULT(2081) +#define D3DERR_UNSUPPORTEDTEXTUREFILTER MAKE_D3DHRESULT(2082) +#define D3DERR_DRIVERINTERNALERROR MAKE_D3DHRESULT(2087) + +#define D3DERR_NOTFOUND MAKE_D3DHRESULT(2150) +#define D3DERR_MOREDATA MAKE_D3DHRESULT(2151) +#define D3DERR_DEVICELOST MAKE_D3DHRESULT(2152) +#define D3DERR_DEVICENOTRESET MAKE_D3DHRESULT(2153) +#define D3DERR_NOTAVAILABLE MAKE_D3DHRESULT(2154) +#define D3DERR_OUTOFVIDEOMEMORY MAKE_D3DHRESULT(380) +#define D3DERR_INVALIDDEVICE MAKE_D3DHRESULT(2155) +#define D3DERR_INVALIDCALL MAKE_D3DHRESULT(2156) +#define D3DOK_NOAUTOGEN MAKE_D3DSTATUS(2159) + +/**************************************************************************** + * + * __declspec(selectany) has the lovely attribute that it allows the linker + * to remove duplicate instantiations of global declarations, and to remove + * the instantiation entirely if unreferenced. + * + ****************************************************************************/ + +#define D3DCONST extern CONST DECLSPEC_SELECTANY + +/**************************************************************************** + * + * Private internal data - Please don't access these directly, as they're + * subject to change. + * + ****************************************************************************/ + +D3DCONST UINT D3DPRIMITIVEVERTEXCOUNT[][2] = +{ + {0, 0}, // Illegal = 0 + {1, 0}, // D3DPT_POINTLIST = 1, + {2, 0}, // D3DPT_LINELIST = 2, + {1, 1}, // D3DPT_LINESTRIP = 3, + {3, 0}, // D3DPT_TRIANGLELIST = 4, + {1, 2}, // D3DPT_TRIANGLEFAN = 5, + {1, 2}, // D3DPT_TRIANGLESTRIP = 6, + {0, 0}, // Illegal = 7 + {3, 0}, // D3DPT_RECTLIST = 8 + {0, 0}, // Illegal = 9 + {0, 0}, // Illegal = 10 + {0, 0}, // Illegal = 11 + {0, 0}, // Illegal = 12 + {4, 0}, // D3DPT_QUADLIST = 13, +}; + +// Macro for converting from primitive count to number of vertices. When +// 'PrimitiveType' is specified as a constant, the table lookups are done +// at compile time. +// +#define D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount) \ + ((PrimitiveCount) * D3DPRIMITIVEVERTEXCOUNT[PrimitiveType][0] \ + + D3DPRIMITIVEVERTEXCOUNT[PrimitiveType][1]) + +// Macro for converting from vertex count to number of primitives. When +// 'PrimitiveType' is specified as a constant, the table lookups are done +// at compile time. +// +#define D3DPRIMCOUNT(PrimitiveType, VertexCount) \ + (((VertexCount) - D3DPRIMITIVEVERTEXCOUNT[PrimitiveType][1]) \ + / D3DPRIMITIVEVERTEXCOUNT[PrimitiveType][0]) + +// The equivalent table for tessellated primitives +D3DCONST UINT D3DTESSPRIMITIVEVERTEXCOUNT[][2] = +{ + {0, 0}, // Illegal = 0 + {0, 0}, // Illegal = 1, + {2, 0}, // D3DTPT_LINELIST = 2, + {1, 1}, // D3DTPT_LINESTRIP = 3, + {3, 0}, // D3DTPT_TRIANGLELIST = 4, + {1, 2}, // D3DTPT_TRIANGLEFAN = 5, + {1, 2}, // D3DTPT_TRIANGLESTRIP = 6, + {0, 0}, // Illegal = 7 + {0, 0}, // Illegal = 8 + {0, 0}, // Illegal = 9 + {0, 0}, // Illegal = 10 + {0, 0}, // Illegal = 11 + {0, 0}, // Illegal = 12 + {4, 0}, // D3DTPT_QUADLIST = 13, + {0, 0}, // Illegal = 14 + {0, 0}, // Illegal = 15 + {1, 0}, // D3DTPT_LINEPATCH = 16, + {1, 0}, // D3DTPT_TRIPATCH = 17, + {1, 0}, // D3DTPT_RECTPATCH = 18, +}; + +// Macro for converting from primitive count to number of vertices. When +// 'PrimitiveType' is specified as a constant, the table lookups are done +// at compile time. +// +#define D3DTESSVERTEXCOUNT(PrimitiveType, PrimitiveCount) \ + ((PrimitiveCount) * D3DTESSPRIMITIVEVERTEXCOUNT[PrimitiveType][0] + \ + + D3DTESSPRIMITIVEVERTEXCOUNT[PrimitiveType][1]) + +// Macro for converting from vertex count to number of primitives. When +// 'PrimitiveType' is specified as a constant, the table lookups are done +// at compile time. +// +#define D3DTESSPRIMCOUNT(PrimitiveType, VertexCount) \ + (((VertexCount) - D3DTESSPRIMITIVEVERTEXCOUNT[PrimitiveType][1]) \ + / D3DTESSPRIMITIVEVERTEXCOUNT[PrimitiveType][0]) + +// 'Extern' declaration that is both C and C++ friendly. +// +#ifdef __cplusplus + #define D3DEXTERN extern "C" +#else + #define D3DEXTERN extern +#endif + +/**************************************************************************** + * + * Definitions for Win64 compatibility + * + ****************************************************************************/ + +#if defined(_PREFAST_) + + #define D3DASSERT(cond, msg) __assume(cond) + +#elif defined(_DEBUG) + + VOID D3DRIP(__in_z CONST CHAR* Format, ...); + + #define D3DASSERT(cond, msg) { if (!(cond)) D3DRIP("Assertion failure: %s\n%s", #cond, (msg)); } + +#else + + #define D3DASSERT(cond, msg) __noop() + +#endif + + +#if defined(_XBOX) + + D3DINLINE BOOL D3DInitializeHeap() { return TRUE; } + + #define D3D__AllocAttributes ( \ + MAKE_XALLOC_ATTRIBUTES(0, 0, 0, 0, \ + eXALLOCAllocatorId_D3DAlloc, \ + XALLOC_ALIGNMENT_16, \ + XALLOC_MEMPROTECT_READWRITE, \ + 0, XALLOC_MEMTYPE_HEAP)) + + D3DINLINE void* D3DAlloc (DWORD size) { return XMemAlloc(size, D3D__AllocAttributes); } + D3DINLINE void D3DFree (void* ptr) { XMemFree(ptr, D3D__AllocAttributes); } + D3DINLINE DWORD D3DMemSize(__in void* ptr) { return XMemSize(ptr, D3D__AllocAttributes); } + + D3DINLINE void* D3DPhysicalAlloc(DWORD size, DWORD protect) { return XPhysicalAlloc(size, MAXULONG_PTR, 4096, protect); } + D3DINLINE void D3DPhysicalFree (void* ptr) { XPhysicalFree(ptr); } + + D3DINLINE DWORD D3DPtrToDWORD(void const* ptr) { return (DWORD) (UINT_PTR) ptr; } + D3DINLINE void* D3DDWORDToPtr(DWORD dw) { return (void*) (UINT_PTR) dw; } + +#elif defined(_X86_) + + D3DINLINE BOOL D3DInitializeHeap() { return TRUE; } + + D3DINLINE void* D3DAlloc (DWORD size) { return _aligned_malloc( size, 16 ); } + D3DINLINE void D3DFree (void* ptr) { _aligned_free(ptr); } + DWORD D3DMemSize(__in void* ptr); + + D3DINLINE void* D3DPhysicalAlloc(DWORD size, DWORD protect) { return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); } + D3DINLINE void D3DPhysicalFree (void* ptr) { VirtualFree(ptr, 0, MEM_RELEASE); } + + D3DINLINE DWORD D3DPtrToDWORD(void const* ptr) { return (DWORD) (UINT_PTR) ptr; } + D3DINLINE void* D3DDWORDToPtr(DWORD dw) { return (void*) (UINT_PTR) dw; } + +#else // defined(_AMD64_) + + D3DEXTERN BOOL D3DInitializeHeap(); + + D3DEXTERN void* D3D__Heap32Base; + D3DEXTERN DWORD D3D__Heap32Top; + + D3DEXTERN void* D3DAlloc (DWORD size); + D3DEXTERN void D3DFree (void* ptr); + D3DEXTERN DWORD D3DMemSize(__in void* ptr); + + D3DEXTERN void* D3DPhysicalAlloc(DWORD size, DWORD protect); + D3DEXTERN void D3DPhysicalFree (void* ptr); + + D3DINLINE + DWORD D3DPtrToDWORD(void const* ptr) + { + if (ptr == NULL) + { + return 0; + } + + D3DASSERT(D3D__Heap32Base != NULL, + "D3DPtrToDWORD was called, but D3D's 32-bit heap is not yet initialized.\n" + "You should call D3DInitializeHeap first."); + + D3DASSERT((BYTE*)ptr >= (BYTE*)D3D__Heap32Base && (BYTE*)ptr <= (BYTE*)D3D__Heap32Base + D3D__Heap32Top, + "D3DPtrToDWORD was called with a pointer that wasn't allocated\n" + "with D3DAlloc or D3DPhysicalAlloc."); + + return (DWORD)((BYTE*)ptr - (BYTE*)D3D__Heap32Base); + } + + D3DINLINE + void* D3DDWORDToPtr(DWORD dw) + { + if (dw == 0) + { + return NULL; + } + + D3DASSERT(dw <= D3D__Heap32Top, + "D3DDWORDToPtr was called with a value that's outside of the heap.\n" + "Either this value wasn't obtained with D3DPtrToDWORD,\n" + "or the data it referenced has been freed."); + + return (BYTE*)D3D__Heap32Base + dw; + } + +#endif // _AMD64_ + +/**************************************************************************** + * + * Definitions for public fields in Xbox 360's D3D objects + * + ****************************************************************************/ + +// Structure for maintaining D3D's shadow of all GPU constants. +// +typedef struct _D3DConstants +{ + union { + GPUFETCH_CONSTANT Fetch[GPU_FETCH_CONSTANTS]; + struct { + GPUTEXTURE_FETCH_CONSTANT TextureFetch[GPU_D3D_TEXTURE_FETCH_CONSTANT_COUNT]; + GPUVERTEX_FETCH_CONSTANT VertexFetch[3*GPU_D3D_VERTEX_FETCH_CONSTANT_COUNT]; + }; + }; + union { + D3DVECTOR4 Alu[GPU_ALU_CONSTANTS]; + struct { + D3DVECTOR4 VertexShaderF[GPU_D3D_VERTEX_CONSTANTF_COUNT]; + D3DVECTOR4 PixelShaderF[GPU_D3D_PIXEL_CONSTANTF_COUNT]; + }; + }; + union { + DWORD Flow[GPU_FLOW_CONSTANTS]; + struct { + DWORD VertexShaderB[GPU_D3D_VERTEX_CONSTANTB_COUNT/32]; + DWORD PixelShaderB[GPU_D3D_PIXEL_CONSTANTB_COUNT/32]; + DWORD VertexShaderI[GPU_D3D_VERTEX_CONSTANTI_COUNT]; + DWORD PixelShaderI[GPU_D3D_PIXEL_CONSTANTI_COUNT]; + }; + }; +} D3DConstants; + +// Function prototypes +// +typedef void (WINAPI *D3DSETRENDERSTATECALL)(__in D3DDevice* pDevice, DWORD Value); +typedef void (WINAPI *D3DSETSAMPLERSTATECALL)(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); + +typedef DWORD (WINAPI *D3DGETRENDERSTATECALL)(__in D3DDevice* pDevice); +typedef DWORD (WINAPI *D3DGETSAMPLERSTATECALL)(__in D3DDevice* pDevice, DWORD Sampler); + +void WINAPI D3DTagCollection_SetVertexShaderConstantFTag_ParameterCheck(DWORD StartConstant, DWORD ConstantCount); +void WINAPI D3DTagCollection_SetPixelShaderConstantFTag_ParameterCheck(DWORD StartConstant, DWORD ConstantCount); + +// Helpers for decoding ownership of GPU registers +// +D3DINLINE DWORD D3DTag_Index(D3DTAG Tag) +{ + return D3DTAG_INDEX(Tag); +} +D3DINLINE DWORD D3DTag_Count(D3DTAG Tag) +{ + return D3DTAG_COUNT(Tag); +} +D3DINLINE UINT64 D3DTag_SubsetMask(D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) +{ + return D3DTAG_MASKENCODE(D3DTAG_START(Tag) + StartIndex, D3DTAG_START(Tag) + EndIndex); +} +D3DINLINE UINT64 D3DTag_Mask(D3DTAG Tag) +{ + return D3DTag_SubsetMask(Tag, 0, D3DTAG_COUNT(Tag) - 1); +} +D3DINLINE UINT64 D3DTag_ShaderConstantMask(DWORD StartConstant, DWORD ConstantCount) +{ + // D3DTAG_PIXELSHADERCONSTANTS vs D3DTAG_VERTEXSHADERCONSTANTS doesn't matter here + return D3DTag_SubsetMask(D3DTAG_VERTEXSHADERCONSTANTS, StartConstant / 4, (StartConstant + ConstantCount - 1) / 4); +} +D3DINLINE UINT64 D3DTag_SamplerMask(DWORD Sampler) +{ + return D3DTag_SubsetMask(D3DTAG_TEXTUREFETCHCONSTANTS, Sampler, Sampler); +} + +// Structure representing every context register on the GPU +typedef struct _D3DTAGCOLLECTION +{ + UINT64 m_Mask[5]; + +} D3DTAGCOLLECTION; + +D3DINLINE void D3DTagCollection_Set(__in D3DTAGCOLLECTION* pCollection, DWORD Index, UINT64 Mask) +{ + pCollection->m_Mask[Index] |= Mask; +} +D3DINLINE void D3DTagCollection_SetAll(__in D3DTAGCOLLECTION* pCollection) +{ + pCollection->m_Mask[0] = ~((UINT64) 0); + pCollection->m_Mask[1] = ~((UINT64) 0); + pCollection->m_Mask[2] = ~((UINT64) 0); + pCollection->m_Mask[3] = ~((UINT64) 0); + pCollection->m_Mask[4] = ~((UINT64) 0); +} +D3DINLINE void D3DTagCollection_Clear(__in D3DTAGCOLLECTION* pCollection, DWORD Index, UINT64 Mask) +{ + pCollection->m_Mask[Index] &= ~Mask; +} +D3DINLINE BOOL D3DTagCollection_TestAny(__in D3DTAGCOLLECTION* pCollection, DWORD Index, UINT64 Mask) +{ + return (pCollection->m_Mask[Index] & Mask) != 0; +} +D3DINLINE BOOL D3DTagCollection_TestAll(__in D3DTAGCOLLECTION* pCollection, DWORD Index, UINT64 Mask) +{ + return (pCollection->m_Mask[Index] & Mask) == Mask; +} + +D3DINLINE void D3DTagCollection_SetTag(__in D3DTAGCOLLECTION* pCollection, D3DTAG Tag) +{ + D3DTagCollection_Set(pCollection, D3DTag_Index(Tag), D3DTag_Mask(Tag)); +} +D3DINLINE void D3DTagCollection_SetVertexShaderConstantFTag(__in D3DTAGCOLLECTION* pCollection, DWORD StartConstant, DWORD ConstantCount) +{ +#if defined(_DEBUG) + D3DTagCollection_SetVertexShaderConstantFTag_ParameterCheck(StartConstant, ConstantCount); +#endif + + D3DTagCollection_Set(pCollection, D3DTag_Index(D3DTAG_VERTEXSHADERCONSTANTS), D3DTag_ShaderConstantMask(StartConstant, ConstantCount)); +} +D3DINLINE void D3DTagCollection_SetPixelShaderConstantFTag(__in D3DTAGCOLLECTION* pCollection, DWORD StartConstant, DWORD ConstantCount) +{ +#if defined(_DEBUG) + D3DTagCollection_SetPixelShaderConstantFTag_ParameterCheck(StartConstant, ConstantCount); +#endif + + D3DTagCollection_Set(pCollection, D3DTag_Index(D3DTAG_PIXELSHADERCONSTANTS), D3DTag_ShaderConstantMask(StartConstant, ConstantCount)); +} + +/**************************************************************************** + * + * Publicly accessible globals - Feel free to modify the values. + * + ****************************************************************************/ + +// Set D3D__NullHardware to TRUE to enable infinitely fast hardware (so fast +// you can't even see the results). This is useful for determining how CPU- +// bound your program is. +// +D3DEXTERN BOOL D3D__NullHardware; + +// Set D3D__SingleStepper to TRUE on debug versions of D3D to cause D3D to +// do an implicit BlockUntilIdle after every D3D draw call. This is useful +// for tracking weird hardware crashes and hangs down to the problem draw call. +// +D3DEXTERN BOOL D3D__SingleStepper; + +// Set D3D__BreakOnDeprecation to TRUE on debug versions of D3D to cause D3D +// to break into the debugger when warning about deprecated D3D functionality. +// +D3DEXTERN BOOL D3D__BreakOnDeprecation; + +#if defined(_DEBUG) + +// Set D3D__DisableConstantOverwriteCheck to disable the shader constant +// overwrite checks. These checks are only performed for debug builds.) This is +// useful when D3D is warning you about constants being overwritten, but you +// know that it's OK. (Perhaps you know that for some draw calls the shader +// doesn't actually use the constants that were overwritten.) +// +D3DEXTERN BOOL D3D__DisableConstantOverwriteCheck; + +// Set D3D__DisableAllChecks to disable all errors, warnings, notifications +// and assertions thrown in D3D APIs. This is only performed for debug builds. +// This is useful when D3D is complaining about something, but you know that +// it's OK in your particular case. You should reset this immediately to FALSE +// after calling the APIs that would complain. +// +// Note that updates to this global affect all threads, and are not thread-safe +// unless you make it thread-safe. +// +// Note that, if D3D would normally crash or misbehave in any way if you +// continue execution after a failure breakpoint, it will now crash or +// misbehave identically. There is no alternative failure recovery. +// +// If you encounter the need to use this toggle, please report the +// circumstances to gameds@microsoft.com. +// +D3DEXTERN BOOL D3D__DisableAllChecks; + +// Set D3D__DisableBreakOnError to disable breaking into the debugger in D3D +// APIs. This is only performed for debug builds. This is useful when D3D is +// breaking into the debugger, but you know that it's OK in your particular +// case. D3D will still report the error as a warning. You should reset this +// immediately to FALSE after calling the APIs that would break. +// +// Note that updates to this global affect all threads, and are not thread-safe +// unless you make it thread-safe. +// +// Note that, if D3D would normally crash or misbehave in any way if you +// continue execution after a failure breakpoint, it will now crash or +// misbehave identically. There is no alternative failure recovery. +// +// If you encounter the need to use this toggle, please report the +// circumstances to gameds@microsoft.com. +// +D3DEXTERN BOOL D3D__DisableBreakOnError; + +#endif + +/**************************************************************************** + * + * Miscellaneous public defines + * + ****************************************************************************/ + +// Types of our various callback functions. +// +typedef void (WINAPI *D3DCALLBACK)(DWORD Context); +typedef void (WINAPI *D3DVBLANKCALLBACK)(__in D3DVBLANKDATA *pData); +typedef void (WINAPI *D3DSWAPCALLBACK)(__in D3DSWAPDATA *pData); +typedef void (WINAPI *D3DHANGCALLBACK)(__in_z CONST char* pDescription); +typedef void (WINAPI *D3DBLOCKCALLBACK)(DWORD Flags, D3DBLOCKTYPE BlockType, float ClockTime, DWORD ThreadTime); +typedef void* (WINAPI *D3DALLOCATECALLBACK)(DWORD Context, DWORD Flags, __inout DWORD* pSize, DWORD Alignment); +typedef void (WINAPI *D3DFREECALLBACK)(DWORD Context); +typedef void (WINAPI *D3DQUERYCALLBACK)(DWORD Context, __out DWORD* pUsed, __out DWORD* pRemaining); +typedef void (WINAPI *D3DTEXTURETRACKERERRORCALLBACK)(BOOL bIsGuiInitiatedCapture, __in_z CONST char* pDescription); + +/* + * D3DQuery, IDirect3DQuery9 interface + * + * There are no public fields + */ + +#ifdef __cplusplus + +struct D3DQuery +{ + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + D3DVOID WINAPI GetDevice(__deref_out D3DDevice **ppDevice); + D3DQUERYTYPE WINAPI GetType(); + DWORD WINAPI GetDataSize(); + D3DVOID WINAPI Issue(DWORD IssueFlags); + HRESULT WINAPI GetData(__out_bcount(Size) void* pData, DWORD Size, DWORD GetDataFlags); +}; + +#endif __cplusplus + + +/* + * D3DPerfCounters, IDirect3DPerfCounters9 interface + * + */ + +#ifdef __cplusplus + +struct D3DPerfCounters +{ + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + D3DVOID WINAPI GetDevice(__deref_out D3DDevice **ppDevice); + BOOL WINAPI IsBusy(); + void WINAPI BlockUntilNotBusy(); + UINT WINAPI GetNumPasses(); + HRESULT WINAPI GetValues(__out D3DPERFCOUNTER_VALUES* pValues, UINT InstanceIndex, __out_opt DWORD* pMask); +}; + +#endif __cplusplus + + + +/* + * D3DStateBlock, IDirect3DStateBlock9 interface + * + * There are no public fields + */ + +#ifdef __cplusplus + +struct D3DStateBlock +{ + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + D3DVOID WINAPI GetDevice(__deref_out D3DDevice **ppDevice); + D3DVOID WINAPI Capture(); + D3DVOID WINAPI Apply(); +}; + +#endif __cplusplus + +/* + * D3DResource, IDirect3DResource9 interface + * + * The root structure of all D3D 'resources' such as textures and vertex buffers. + */ + +#define D3DCOMMON_TYPE_MASK 0x0000000F +#define D3DCOMMON_TYPE_SHIFT 0 +#define D3DCOMMON_TYPE_VERTEXBUFFER (D3DRTYPE_VERTEXBUFFER << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_INDEXBUFFER (D3DRTYPE_INDEXBUFFER << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_TEXTURE (D3DRTYPE_TEXTURE << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_SURFACE (D3DRTYPE_SURFACE << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_VERTEXDECLARATION (D3DRTYPE_VERTEXDECLARATION << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_VERTEXSHADER (D3DRTYPE_VERTEXSHADER << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_PIXELSHADER (D3DRTYPE_PIXELSHADER << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_CONSTANTBUFFER (D3DRTYPE_CONSTANTBUFFER << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_COMMANDBUFFER (D3DRTYPE_COMMANDBUFFER << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_ASYNCCOMMANDBUFFERCALL (D3DRTYPE_ASYNCCOMMANDBUFFERCALL << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_PERFCOUNTERBATCH (D3DRTYPE_PERFCOUNTERBATCH << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_OCCLUSIONQUERYBATCH (D3DRTYPE_OCCLUSIONQUERYBATCH << D3DCOMMON_TYPE_SHIFT) +#define D3DCOMMON_TYPE_RESERVED (0xf << D3DCOMMON_TYPE_SHIFT) + +#define D3DCOMMON_LOCKID_MASK 0x000000F0 +#define D3DCOMMON_LOCKID_SHIFT 4 + +#define D3DCOMMON_LOCKCOUNT_MASK 0x00000F00 +#define D3DCOMMON_LOCKCOUNT_SHIFT 8 + +#if defined(_DEBUG) + +// The following is used by D3D only on debug builds and is used to keep +// count of internal reference counts for debug purposes +// +#define D3DCOMMON_DEBUG_INTREFCOUNT_MASK 0x0001F000 +#define D3DCOMMON_DEBUG_INTREFCOUNT_SHIFT 12 + +// The following is used by D3D only on debug builds and is set when a +// resource is referenced by a command buffer +// +#define D3DCOMMON_DEBUG_COMMMANDBUFFER_USED 0x00020000 + +// The following is used by D3D only on debug builds and is set when a +// resource is involved in one or more pending asynchronous operations. +// +#define D3DCOMMON_DEBUG_ASYNCLOCK 0x00040000 + +// The following is used by D3D only on debug builds to prevent +// multiple simultaneous asynchronous locks, which are not allowed. +// +#define D3DCOMMON_DEBUG_ASYNCLOCK_LOCKED 0x00080000 + +#endif + +// Internal flag to indicate that this resource was created by Direct3D. +// +#define D3DCOMMON_D3DCREATED 0x00100000 + +// When accessing this resource via the CPU, the CPU uses a cached memory +// view. D3D ensures coherency with the GPU by flushing the modified +// range at Unlock time. +// +#define D3DCOMMON_CPU_CACHED_MEMORY 0x00200000 + +// Update the fence for this resource when a command buffer using this resource +// is run. +// +#define D3DCOMMON_RUNCOMMANDBUFFER_TIMESTAMP 0x00400000 + +#if defined(_DEBUG) + +// The following is used by D3D only on debug builds and is a count +// of pending asynchronous locks, for debug purposes +// +#define D3DCOMMON_DEBUG_ASYNCLOCK_PENDING_MASK 0x1F800000 +#define D3DCOMMON_DEBUG_ASYNCLOCK_PENDING_INC 0x00800000 + +#endif + +// The rest of the bits may be used by derived classes. +// +#define D3DCOMMON_UNUSED_MASK 0xE0000000 +#define D3DCOMMON_UNUSED_SHIFT 29 + +// Initialize the 'BaseFlush' and 'MipFlush' fields to this value. +// +#define D3DFLUSH_INITIAL_VALUE 0xffff0000 + +struct D3DResource +{ + +#ifdef __cplusplus + + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + D3DVOID WINAPI GetDevice(__deref_out D3DDevice **ppDevice); + D3DRESOURCETYPE WINAPI GetType(); + BOOL WINAPI IsBusy(); + BOOL WINAPI IsSet(__in D3DDevice *pDevice); + void WINAPI BlockUntilNotBusy(); + void WINAPI SetIdentifier(DWORD Identifier); + DWORD WINAPI GetIdentifier(); + + // The following methods are not supported on Xbox 360: + // + // SetPrivateData + // GetPrivateData + // FreePrivateData + // SetPriority + // GetPriority + // PreLoad + +#endif __cplusplus + + // All resources need these fields. Inherit them in C++. + + DWORD Common; // Flags common to all resources + DWORD ReferenceCount; // External reference count + DWORD Fence; // This is the fence number of the last ring buffer + // reference to this resource. (This field was + // known as 'Lock' on the original Xbox.) + // Initialize it to zero. + DWORD ReadFence; // This is used to determine when it's safe for the + // CPU to read a resource that was written to + // by the GPU. Initialize it to zero. + DWORD Identifier; // Game-supplied data that identifies the resource + DWORD BaseFlush; // Encodes the memory range to be flushed by D3D + // via 'dcbf' at 'Unlock' time. Initialize it + // to D3DFLUSH_INITIAL_VALUE. +}; + +/* + * D3DBaseTexture interface + * + * The root structure of all D3D textures. Inherits all of the methods + * from D3DResource. + */ + +#define D3DTEXTURE_ALIGNMENT 4096 + +struct D3DBaseTexture + #ifdef __cplusplus + : public D3DResource + #endif +{ + +#ifdef __cplusplus + DWORD WINAPI GetLevelCount(); + D3DVOID WINAPI GetTailDesc(__out D3DMIPTAIL_DESC *pDesc); + D3DVOID WINAPI LockTail(UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI AsyncLockTail(D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI UnlockTail(UINT ArrayIndex); +#endif + + // The following methods are not supported on Xbox 360: + // + // SetLOD + // GetLOD + // SetAutoGenFilterType + // GetAutoGenFilterType + // GenerateMipSubLevels + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + DWORD MipFlush; // Encodes the mip's memory range to be flushed by D3D + // via 'dcbf' at 'Unlock' time. Initialize it + // to D3DFLUSH_INITIAL_VALUE. + GPUTEXTURE_FETCH_CONSTANT Format; + // The hardware's description of the texture +}; + + +/* + * D3DTexture, IDirect3DTexture9 interface + * + * A normal texture. Inherits from D3DBaseTexture + */ + +struct D3DTexture + #ifdef __cplusplus + : public D3DBaseTexture + #endif +{ + +#ifdef __cplusplus + D3DVOID WINAPI GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc); + HRESULT WINAPI GetSurfaceLevel(UINT Level, __deref_out D3DSurface **ppSurfaceLevel); + D3DVOID WINAPI LockRect(UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI AsyncLockRect(D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI UnlockRect(UINT Level); + D3DVOID WINAPI LockTail(__out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI AsyncLockTail(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI UnlockTail(); + + // The following methods are not supported on Xbox 360: + // + // AddDirtyRect + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DBaseTexture + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; + DWORD MipFlush; + GPUTEXTURE_FETCH_CONSTANT Format; +#endif + +}; + + +/* + * D3DVolumeTexture, IDirect3DVolumeTexture9 interface + * + * A volume texture. Inherits from D3DBaseTexture + */ + +struct D3DVolumeTexture + #ifdef __cplusplus + : public D3DBaseTexture + #endif +{ + +#ifdef __cplusplus + + D3DVOID WINAPI GetLevelDesc(UINT Level, __out D3DVOLUME_DESC *pDesc); + HRESULT WINAPI GetVolumeLevel(UINT Level, __deref_out D3DVolume **ppVolumeLevel); + D3DVOID WINAPI LockBox(UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); + D3DVOID WINAPI AsyncLockBox(D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); + D3DVOID WINAPI UnlockBox(UINT Level); + D3DVOID WINAPI LockTail(__out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI AsyncLockTail(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI UnlockTail(); + + // The following methods are not supported on Xbox 360: + // + // AddDirtyBox + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DBaseTexture + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; + DWORD MipFlush; + GPUTEXTURE_FETCH_CONSTANT Format; +#endif + +}; + + +/* + * D3DCubeTexture, IDirect3DCubeTexture9 interface + * + * A cube texture. Inherits from D3DBaseTexture + */ + +struct D3DCubeTexture + #ifdef __cplusplus + : public D3DBaseTexture + #endif +{ + +#ifdef __cplusplus + D3DVOID WINAPI GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc); + HRESULT WINAPI GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, __deref_out D3DSurface **ppCubeMapSurface); + D3DVOID WINAPI LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI AsyncLockRect(D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level); + D3DVOID WINAPI LockTail(D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI AsyncLockTail(D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI UnlockTail(D3DCUBEMAP_FACES FaceType); + + // The following methods are not supported on Xbox 360: + // + // AddDirtyRect + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DBaseTexture + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; + DWORD MipFlush; + GPUTEXTURE_FETCH_CONSTANT Format; +#endif + +}; + + +/* + * D3DArrayTexture, IDirect3DArrayTexture9 interface + * + * An array texture. Inherits from D3DBaseTexture + */ + +struct D3DArrayTexture + #ifdef __cplusplus + : public D3DBaseTexture + #endif +{ + +#ifdef __cplusplus + DWORD WINAPI GetArraySize(); + D3DVOID WINAPI GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc); + HRESULT WINAPI GetArraySurface(UINT ArrayIndex, UINT Level, __deref_out D3DSurface **ppArraySurface); + D3DVOID WINAPI LockRect(UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI AsyncLockRect(D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI UnlockRect(UINT ArrayIndex, UINT Level); + D3DVOID WINAPI LockTail(UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI AsyncLockTail(D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI UnlockTail(UINT ArrayIndex); + + // The following methods are not supported on Xbox 360: + // + // AddDirtyRect + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DBaseTexture + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; + DWORD MipFlush; + GPUTEXTURE_FETCH_CONSTANT Format; +#endif + +}; + +/* +* D3DLineTexture, IDirect3DLineTexture9 interface +* +* A 1D texture. Inherits from D3DBaseTexture +*/ + +struct D3DLineTexture +#ifdef __cplusplus + : public D3DBaseTexture +#endif +{ + +#ifdef __cplusplus + D3DVOID WINAPI GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc); + HRESULT WINAPI GetSurfaceLevel(UINT Level, __deref_out D3DSurface **ppSurfaceLevel); + D3DVOID WINAPI LockRect(UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI AsyncLockRect(D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI UnlockRect(UINT Level); + D3DVOID WINAPI LockTail(__out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI AsyncLockTail(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); + D3DVOID WINAPI UnlockTail(); + + // The following methods are not supported on Xbox 360: + // + // AddDirtyRect + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DBaseTexture + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; + DWORD MipFlush; + GPUTEXTURE_FETCH_CONSTANT Format; +#endif + +}; + +/* + * D3DVertexBuffer, IDirect3DVertexBuffer9 interface + * + * A vertex buffer. + * + * The data for the vertex buffer must be aligned on a D3DVERTEXBUFFER_ALIGNMENT + * byte multiple. + */ + +#define D3DVERTEXBUFFER_ALIGNMENT 4 + +struct D3DVertexBuffer + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI Lock(UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags); + D3DVOID WINAPI AsyncLock(D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags); + D3DVOID WINAPI Unlock(); + D3DVOID WINAPI GetDesc(__out D3DVERTEXBUFFER_DESC *pDesc); + +#endif __cplusplus + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + GPUVERTEX_FETCH_CONSTANT Format; +}; + + +/* + * D3DIndexBuffer, IDirect3DIndexBuffer9 interface + * + * An index buffer. + * + * The data for the vertex buffer must be aligned on a D3DINDEXBUFFER_ALIGNMENT + * byte multiple. + */ + +#define D3DINDEXBUFFER_ALIGNMENT 4 + +// If set in the 'Common' field, this bit indicates that the indices are +// 32-bit values instead of 16-bit: +// +#define D3DINDEXBUFFER_INDEX32 0x80000000 + +// This bitfield in 'Common' indicates the GPUENDIAN endianness to be used when +// the GPU reads the index buffer: +// +#define D3DINDEXBUFFER_ENDIAN_MASK 0X60000000 +#define D3DINDEXBUFFER_ENDIAN_SHIFT 29 + +struct D3DIndexBuffer + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI Lock(UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags); + D3DVOID WINAPI AsyncLock(D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags); + D3DVOID WINAPI Unlock(); + D3DVOID WINAPI GetDesc(__out D3DINDEXBUFFER_DESC *pDesc); + +#endif __cplusplus + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + DWORD Address; + DWORD Size; +}; + + +/* + * D3DSurface, IDirect3DSurface9 interface + * + */ + +#define D3DSURFACE_ALIGNMENT 4096 + +// This internal flag indicates whether D3D allocated the EDRAM memory, +// or whether it was specified by the game via D3DSURFACE_PARAMETERS. + +#define D3DCOMMON_SURFACE_D3D_EDRAM_ALLOCATED 0x80000000 + +// This internal flag indicates that this resource is a surface that +// was derived from a texture (via something like GetSurfaceLevel). +// As such, it doesn't own the memory to which it's pointing, and +// it can't be set as a render target. +// +#define D3DCOMMON_SURFACE_FROM_TEXTURE 0x40000000 + +struct D3DSurface + #if defined(__cplusplus) + : public D3DResource + #endif +{ +#ifdef __cplusplus + + HRESULT WINAPI GetContainer(REFIID UnusedRiid, __deref_out void **ppContainer); + D3DVOID WINAPI GetDesc(__out D3DSURFACE_DESC *pDesc); + + D3DVOID WINAPI LockRect(__out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI AsyncLockRect(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); + D3DVOID WINAPI UnlockRect(); + + // The following methods are not supported on Xbox 360: + // + // GetDC + // ReleaseDC + +#endif __cplusplus + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + union { + + struct { + + // The following fields are valid only if D3DCOMMON_SURFACEFROMTEXTURE + // is not set: + + GPU_SURFACEINFO SurfaceInfo; + union { + GPU_DEPTHINFO DepthInfo; + GPU_COLORINFO ColorInfo; + }; + GPU_HICONTROL HiControl; + struct { + DWORD Width : 14; + DWORD Height : 15; + DWORD : 3; + }; + D3DFORMAT Format; + DWORD Size; + }; + struct { + + // The following fields are valid only if D3DCOMMON_SURFACEFROMTEXTURE + // is set: + + D3DBaseTexture *Parent; + struct { + DWORD MipLevel : 4; + DWORD ArrayIndex : 6; + DWORD : 22; + }; + }; + }; +}; + +/* + * D3DVolume, IDirect3DVolume9 interface + */ + +#define D3DVOLUME_ALIGNMENT 4096 + +struct D3DVolume + #if defined(__cplusplus) + : public D3DResource + #endif +{ +#ifdef __cplusplus + + HRESULT WINAPI GetContainer(REFIID UnusedRiid, __deref_out void **ppContainer); + D3DVOID WINAPI GetDesc(__out D3DVOLUME_DESC *pDesc); + D3DVOID WINAPI LockBox(__out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); + D3DVOID WINAPI AsyncLockBox(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); + D3DVOID WINAPI UnlockBox(); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + D3DBaseTexture *Parent; + struct { + DWORD MipLevel : 4; + DWORD ArrayIndex : 6; + DWORD : 22; + }; +}; + +/* + * D3DVertexDeclaration, IDirect3DVertexDeclaration9 interface + * + * D3D keeps private internal fields in addition to the public fields for + * this structure. + */ + +struct D3DVertexDeclaration + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI GetDeclaration(__out_ecount_part(*pNumElements, *pNumElements) D3DVERTEXELEMENT9 *pDecl, __inout UINT *pNumElements); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif +}; + +/* + * D3DVertexShader, IDirect3DVertexShader9 interface + * + * D3D keeps private internal fields in addition to the public fields for + * this structure. + */ + +#define VERTEXSHADER_ALIGNMENT 32 + +struct D3DVertexShader + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI GetFunction(__out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData); + D3DVOID WINAPI Bind(DWORD Flags, __in D3DVertexDeclaration* pVertexDeclaration, __in CONST DWORD* pStreamStrides, __in_opt D3DPixelShader* pPixelShader); + BOOL WINAPI IsBound(); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif +}; + +/* + * D3DPixelShader, IDirect3DPixelShader9 interface + * + * D3D keeps private internal fields in addition to the public fields for + * this structure. + */ + +#define PIXELSHADER_ALIGNMENT 32 + +struct D3DPixelShader + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI GetFunction(__out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif +}; + +/* + * D3DConstantBuffer, IDirect3DConstantBuffer9 interface + */ + +#define D3DCONSTANTBUFFER_ALIGNMENT 16 + +struct D3DConstantBuffer + #if defined(__cplusplus) + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI Lock(__deref_out D3DVECTOR4** ppData, DWORD Flags); + D3DVOID WINAPI AsyncLock(D3DASYNCBLOCK AsyncBlock, __deref_out D3DVECTOR4** ppData, DWORD Flags); + D3DVOID WINAPI Unlock(); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + DWORD Address; + DWORD Size; +}; + +/* + * D3DCommandBuffer, IDirect3DCommandBuffer9 interface + */ + +#define D3DCOMMANDBUFFER_ALIGNMENT 32 + +struct D3DCommandBuffer + #if defined(__cplusplus) + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI GetResources(DWORD Flags, __out_ecount_opt(*pBufferSize) D3DResource** ppResourceList, __inout DWORD* pBufferSize); + HRESULT WINAPI CreateClone(DWORD Flags, __deref_out D3DCommandBuffer** ppCommandBuffer); + D3DVOID WINAPI GetClone(DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize); + D3DVOID WINAPI BeginFixupCreation(); + HRESULT WINAPI EndFixupCreation(); + HRESULT WINAPI Deconstruct(DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize, __out_bcount_opt(*pInitializationSize) void* pInitializationPart, __inout DWORD* pInitializationSize); + D3DVOID WINAPI BeginReconstruction(DWORD Flags, __in void* pPhysicalPart, __in void* pInitializationPart); + D3DVOID WINAPI EndReconstruction(); + D3DVOID WINAPI BeginDynamicFixups(); + D3DVOID WINAPI EndDynamicFixups(); + DWORD WINAPI CreateSurfacesFixup(DWORD Flags, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateClipRectFixup(DWORD Flags, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateViewportFixup(DWORD Flags, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateVertexShaderConstantFFixup(DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreatePixelShaderConstantFFixup(DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateVertexShaderFixup(DWORD Flags, __in D3DVertexShader* pVertexShader, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreatePixelShaderFixup(DWORD Flags, __in D3DPixelShader* pPixelShader, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateTextureFixup(DWORD Flags, __in D3DBaseTexture* pTexture, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateIndexBufferFixup(DWORD Flags, __in D3DIndexBuffer* pIndexBuffer, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateVertexBufferFixup(DWORD Flags, __in D3DVertexBuffer* pVertexBuffer, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateConstantBufferFixup(DWORD Flags, __in D3DConstantBuffer* pConstantBuffer, DWORD StartMarker, DWORD StopMarker); + DWORD WINAPI CreateCommandBufferFixup(DWORD Flags, __in D3DCommandBuffer* pCommandBuffer, DWORD StartMarker, DWORD StopMarker); + D3DVOID WINAPI SetSurfaces(DWORD FixupHandle, __in CONST D3DSURFACES* pSurfaces); + D3DVOID WINAPI SetClipRect(DWORD FixupHandle, __in CONST RECT* pRect); + D3DVOID WINAPI SetViewport(DWORD FixupHandle, __in CONST D3DVIEWPORT9* pViewport); + D3DVOID WINAPI SetVertexShaderConstantF(DWORD FixupHandle, __in CONST float* pConstantData); + D3DVOID WINAPI SetPixelShaderConstantF(DWORD FixupHandle, __in CONST float* pConstantData); + D3DVOID WINAPI SetVertexShader(DWORD FixupHandle, __in D3DVertexShader* pVertexShader); + D3DVOID WINAPI SetPixelShader(DWORD FixupHandle, __in D3DPixelShader* pPixelShader); + D3DVOID WINAPI SetTexture(DWORD FixupHandle, __in D3DBaseTexture* pTexture); + D3DVOID WINAPI SetIndexBuffer(DWORD FixupHandle, __in D3DIndexBuffer* pIndexBuffer); + D3DVOID WINAPI SetVertexBuffer(DWORD FixupHandle, __in D3DVertexBuffer* pVertexBuffer); + D3DVOID WINAPI SetConstantBuffer(DWORD FixupHandle, __in D3DConstantBuffer* pConstantBuffer); + D3DVOID WINAPI SetCommandBuffer(DWORD FixupHandle, __in D3DCommandBuffer* pCommandBuffer); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + // Flags indicating which registers are inherited from the GPU's current + // state when the command buffer is run. Inheritance is used to pass + // run-time parameters such as shader constants to the command buffer. + // + D3DTAGCOLLECTION m_Inherited; + + // Flags indicating which registers are to be persisted after the + // command buffer is run. + // + D3DTAGCOLLECTION m_Persisted; +}; + +/* + * D3DAsyncCommandBufferCall, IDirect3DAsyncCommandBufferCall9 interface + */ + +struct D3DAsyncCommandBufferCall + #if defined(__cplusplus) + : public D3DResource + #endif +{ +#ifdef __cplusplus + + D3DVOID WINAPI FixupAndSignal(__in_opt D3DCommandBuffer* pUserCommandBuffer, DWORD PredicationSelect, DWORD Flags); + D3DVOID WINAPI FixupAndSignalEx(__in_ecount_opt(CommandBufferCount) D3DCommandBuffer** ppUserCommandBuffers, __in_ecount_opt(CommandBufferCount) DWORD* pPredicationSelects, DWORD CommandBufferCount, DWORD Flags); + HRESULT WINAPI Reset(__in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags); + +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + // Flags indicating which registers are inherited from the GPU's current + // state when the async command buffer call is run. Inheritance is used to pass + // run-time parameters such as shader constants to the command buffer. + // + D3DTAGCOLLECTION m_Inherited; + + // Flags indicating which registers are to be persisted after the + // async command buffer call is run. + // + D3DTAGCOLLECTION m_Persisted; +}; + +/* + * D3DPerfCounterBatch, IDirect3DPerfCounterBatch9 interface + * + */ + +struct D3DPerfCounterBatch + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + void WINAPI Reset(); + UINT WINAPI Issue(DWORD PerfCounterIndex, DWORD Flags); + UINT WINAPI GetNumSlotsUsed(); + D3DVOID WINAPI Lock(__deref_out void **ppData); + D3DVOID WINAPI Unlock(); + UINT WINAPI GetValue32(DWORD Slot); + UINT64 WINAPI GetValue64(DWORD Slot); +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + // D3DPERFCOUNTERBATCH_* Flags indicating the creation type + + DWORD m_Flags; + + // Number of slots, each slot correspond to one Issue() + + DWORD m_NumSlots; + + // Number of passes in each slot + + DWORD m_NumPasses; + + // Size in bytes of each slot + + DWORD m_SlotSize; + + // Slots used + + UINT m_SlotsUsed; + + // Base address of physical memory for GPU write back, write-combined + + BYTE* m_pBase; + + // Cached read only address + + BYTE* m_pCachedReadOnlyBase; +}; + +/* + * D3DOcclusionQueryBatch, IDirect3DOcclusionQueryBatch9 interface + * + */ + +struct D3DOcclusionQueryBatch + #ifdef __cplusplus + : public D3DResource + #endif +{ +#ifdef __cplusplus + void WINAPI Reset(); + UINT WINAPI Issue(); + UINT WINAPI GetNumSlotsUsed(); + D3DVOID WINAPI Lock(__deref_out void **ppData); + D3DVOID WINAPI Unlock(); + void WINAPI GetOcclusionStats(DWORD Slot, __out D3DOCCLUSIONSTATS* pOcclusionStats); + UINT WINAPI GetPixelCount(DWORD Slot); +#endif + +#ifndef __cplusplus + // Manually inherit these from D3DResource + DWORD Common; + DWORD ReferenceCount; + DWORD Fence; + DWORD ReadFence; + DWORD Identifier; + DWORD BaseFlush; +#endif + + // Number of slots, each slot correspond to one Issue() + + DWORD m_NumSlots; + + // Number of tiles in each slot + + DWORD m_NumTiles; + + // Size in bytes of each slot + + DWORD m_SlotSize; + + // Slots used + + UINT m_SlotsUsed; + + // Base address of physical memory for GPU write back, write-combined + + BYTE* m_pBase; + + // Cached read only address + + BYTE* m_pCachedReadOnlyBase; +}; + +/* + * Direct3D, IDirect3D9 interface + * + */ + +#ifdef __cplusplus + +struct Direct3D +{ + + static ULONG WINAPI AddRef(); + static ULONG WINAPI Release(); + + static UINT WINAPI GetAdapterCount(); + static HRESULT WINAPI GetAdapterIdentifier(UINT Adapter, DWORD Flags, __out D3DADAPTER_IDENTIFIER9 *pIdentifier); + static HRESULT WINAPI CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed); + static HRESULT WINAPI CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat); + static HRESULT WINAPI CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, __out_opt DWORD* pQualityLevels); + static HRESULT WINAPI CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat); + static HRESULT WINAPI CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat); + static HRESULT WINAPI GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,__out D3DCAPS9 *pCaps); + static HRESULT WINAPI CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, __in_opt void *hUnusedFocusWindow, DWORD BehaviorFlags, __in_opt D3DPRESENT_PARAMETERS *pPresentationParameters, __deref_out D3DDevice **ppReturnedDeviceInterface); + + // The following APIs are all Xbox 360 extensions: + + static void WINAPI QueryGpuVersion(__out D3DGPUVERSION* pGpuVersion); + + // The following methods are not supported on Xbox 360: + // + // RegisterSoftwareDevice + // GetAdapterMonitor +}; + +#endif __cplusplus + +/* + * D3DDevice, IDirect3DDevice9 interface + */ + +struct D3DDevice +{ +#ifdef __cplusplus + + // Standard D3D APIs: + + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + D3DVOID WINAPI GetDirect3D(__deref_out Direct3D **ppD3D9); + D3DVOID WINAPI GetDeviceCaps(__out D3DCAPS9 *pCaps); + D3DVOID WINAPI GetDisplayMode(UINT UnusedSwapChain, __out D3DDISPLAYMODE *pMode); + D3DVOID WINAPI GetCreationParameters(__out D3DDEVICE_CREATION_PARAMETERS *pParameters); + HRESULT WINAPI Reset(__in D3DPRESENT_PARAMETERS *pPresentationParameters); + D3DVOID WINAPI Present(__in_opt CONST RECT *pUnusedSourceRect, __in_opt CONST RECT *pUnusedDestRect, __in_opt void *hUnusedDestWindowOverride, __in_opt void *pUnusedDirtyRegion); + D3DVOID WINAPI GetRasterStatus(UINT iUnusedSwapChain, __out D3DRASTER_STATUS *pRasterStatus); + void WINAPI SetGammaRamp(UINT iUnusedSwapChain, DWORD UnusedFlags, __in CONST D3DGAMMARAMP *pRamp); + void WINAPI GetGammaRamp(UINT iUnusedSwapChain, __out D3DGAMMARAMP *pRamp); + void WINAPI SetPWLGamma(DWORD Flags, __in CONST D3DPWLGAMMA *pRamp); + void WINAPI GetPWLGamma(__out D3DPWLGAMMA *pRamp); + HRESULT WINAPI CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DTexture **ppTexture, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DVolumeTexture **ppVolumeTexture, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DCubeTexture **ppCubeTexture, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateArrayTexture(UINT Width, UINT Height, UINT ArraySize, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DArrayTexture **ppArrayTexture, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateLineTexture(UINT Width, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DLineTexture **ppTexture, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateVertexBuffer(UINT Length, DWORD Usage, DWORD UnusedFVF, D3DPOOL UnusedPool, __deref_out D3DVertexBuffer **ppVertexBuffer, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DIndexBuffer **ppIndexBuffer, __in_opt HANDLE* pUnusedSharedHandle); + HRESULT WINAPI CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD UnusedMultisampleQuality, BOOL UnusedLockable, __deref_out D3DSurface **ppSurface, __in_opt CONST D3DSURFACE_PARAMETERS* pParameters); + HRESULT WINAPI CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD UnusedMultisampleQuality, BOOL UnusedDiscard, __deref_out D3DSurface **ppSurface, __in_opt CONST D3DSURFACE_PARAMETERS* pParameters); + D3DVOID WINAPI SetRenderTarget(DWORD RenderTargetIndex, __in_opt D3DSurface *pRenderTarget); + HRESULT WINAPI GetRenderTarget(DWORD RenderTargetIndex, __deref_out D3DSurface **ppRenderTarget); + D3DVOID WINAPI SetDepthStencilSurface(__in_opt D3DSurface *pZStencilSurface); + HRESULT WINAPI GetDepthStencilSurface(__deref_out D3DSurface **ppZStencilSurface); + HRESULT WINAPI GetBackBuffer(UINT UnusedSwapChain, UINT iUnusedBackBuffer, UINT UnusedType, __deref_out D3DSurface **ppBackBuffer); + HRESULT WINAPI GetFrontBuffer(__deref_out D3DTexture **ppFrontBuffer); + D3DVOID WINAPI BeginScene(); + D3DVOID WINAPI EndScene(); + D3DVOID WINAPI Clear(DWORD Count, __in_opt CONST D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil); + D3DVOID WINAPI ClearF(DWORD Flags, __in_opt CONST D3DRECT *pRect, __in_opt CONST D3DVECTOR4* pColor, float Z, DWORD Stencil); + D3DVOID WINAPI SetViewport(__in CONST D3DVIEWPORT9 *pViewport); + D3DVOID WINAPI GetViewport(__out D3DVIEWPORT9 *pViewport); + D3DVOID WINAPI SetRenderState(D3DRENDERSTATETYPE State, DWORD Value); + D3DVOID WINAPI SetRenderState_Inline(D3DRENDERSTATETYPE State, DWORD Value); + D3DVOID WINAPI GetRenderState(D3DRENDERSTATETYPE State, __out DWORD *pValue); + HRESULT WINAPI CreateStateBlock(D3DSTATEBLOCKTYPE Type, __deref_out D3DStateBlock** ppSB); + D3DVOID WINAPI GetTexture(DWORD Sampler, __deref_out D3DBaseTexture **ppTexture); + D3DVOID WINAPI SetTexture(DWORD Sampler, __in_opt D3DBaseTexture *pTexture); + D3DVOID WINAPI GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, __out DWORD* pValue); + D3DVOID WINAPI SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value); + D3DVOID WINAPI SetSamplerState_Inline(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value); + D3DVOID WINAPI SetSamplerAddressStates(DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW); + D3DVOID WINAPI SetSamplerBorderStates(DWORD Sampler, DWORD BorderColor, DWORD WhiteBorderColorW, DWORD PointBorderEnable); + D3DVOID WINAPI SetSamplerSeparateZFilterStates(DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MinFilterZ, DWORD MagFilterZ, DWORD MaxAnisotropy); + D3DVOID WINAPI SetSamplerFilterStates(DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MaxAnisotropy); + D3DVOID WINAPI DrawVertices(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT VertexCount); + D3DVOID WINAPI DrawIndexedVertices(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT IndexCount); + D3DVOID WINAPI DrawVerticesUP(D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride); + D3DVOID WINAPI DrawIndexedVerticesUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT IndexCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride); + D3DVOID WINAPI DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount); + D3DVOID WINAPI DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT UnusedMinIndex, UINT UnusedNumIndices, UINT StartIndex, UINT PrimitiveCount); + D3DVOID WINAPI DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride); + D3DVOID WINAPI DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT PrimitiveCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride); + D3DVOID WINAPI SetFVF(DWORD FVF); + D3DVOID WINAPI GetFVF(__out DWORD* pFVF); + HRESULT WINAPI CreateVertexShader(__in CONST DWORD *pFunction, __deref_out D3DVertexShader** ppShader); + D3DVOID WINAPI SetVertexShader(__in_opt D3DVertexShader *pShader); + D3DVOID WINAPI GetVertexShader(__deref_out D3DVertexShader **ppShader); + D3DVOID WINAPI SetVertexShaderConstantB(UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount); + D3DVOID WINAPI SetVertexShaderConstantF(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount); + D3DVOID WINAPI SetVertexShaderConstantI(UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount); + D3DVOID WINAPI GetVertexShaderConstantB(UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount); + D3DVOID WINAPI GetVertexShaderConstantF(UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount); + D3DVOID WINAPI GetVertexShaderConstantI(UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount); + D3DVOID WINAPI SetVertexShaderConstantF_NotInline(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount); + D3DVOID WINAPI SetStreamSource(UINT StreamNumber, __in_opt D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride); + D3DVOID WINAPI GetStreamSource(UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride); + D3DVOID WINAPI SetIndices(__in_opt D3DIndexBuffer *pIndexData); + D3DVOID WINAPI GetIndices(__deref_out D3DIndexBuffer **ppIndexData); + HRESULT WINAPI CreatePixelShader(__in CONST DWORD *pFunction, __deref_out D3DPixelShader** ppShader); + D3DVOID WINAPI SetPixelShader(__in_opt D3DPixelShader* pShader); + D3DVOID WINAPI GetPixelShader(__deref_out D3DPixelShader** ppShader); + D3DVOID WINAPI SetPixelShaderConstantB(UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount); + D3DVOID WINAPI SetPixelShaderConstantF(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount); + D3DVOID WINAPI SetPixelShaderConstantI(UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount); + D3DVOID WINAPI GetPixelShaderConstantB(UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount); + D3DVOID WINAPI GetPixelShaderConstantF(UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount); + D3DVOID WINAPI GetPixelShaderConstantI(UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount); + D3DVOID WINAPI SetPixelShaderConstantF_NotInline(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount); + HRESULT WINAPI CreateVertexDeclaration(__in CONST D3DVERTEXELEMENT9* pVertexElements, __deref_out D3DVertexDeclaration **ppVertexDeclaration); + D3DVOID WINAPI SetVertexDeclaration(__in_opt D3DVertexDeclaration *pDecl); + D3DVOID WINAPI GetVertexDeclaration(__deref_out D3DVertexDeclaration **ppDecl); + D3DVOID WINAPI SetScissorRect(__in CONST RECT* pRect); + D3DVOID WINAPI GetScissorRect(__out RECT* pRect); + D3DVOID WINAPI SetClipPlane(DWORD Index, __in_ecount(4) CONST float* pPlane); + D3DVOID WINAPI GetClipPlane(DWORD Index, __out_ecount(4) float* pPlane); + HRESULT WINAPI CreateQuery(D3DQUERYTYPE Type, __deref_out D3DQuery** ppQuery); + + // The following APIs are all Xbox 360 extensions: + + HRESULT WINAPI CreateQueryTiled(D3DQUERYTYPE Type, DWORD TileCount, __deref_out D3DQuery** ppQuery); + D3DVOID WINAPI Resolve(DWORD Flags, __in_opt CONST D3DRECT *pSourceRect, __in D3DBaseTexture *pDestTexture, __in_opt CONST D3DPOINT *pDestPoint, UINT DestLevel, UINT DestSliceOrFace, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters); + D3DVOID WINAPI AcquireThreadOwnership(); + D3DVOID WINAPI ReleaseThreadOwnership(); + D3DVOID WINAPI SetThreadOwnership(DWORD ThreadID); + DWORD WINAPI QueryThreadOwnership(); + BOOL WINAPI IsBusy(); + D3DVOID WINAPI BlockUntilIdle(); + D3DVOID WINAPI InsertCallback(D3DCALLBACKTYPE Type, __in_opt D3DCALLBACK pCallback, DWORD Context); + D3DVOID WINAPI SetVerticalBlankCallback(__in_opt D3DVBLANKCALLBACK pCallback); + D3DVOID WINAPI SetSwapCallback(__in D3DSWAPCALLBACK pCallback); + D3DVOID WINAPI SynchronizeToPresentationInterval(); + D3DVOID WINAPI Swap(__in D3DBaseTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters); + D3DVOID WINAPI RenderSystemUI(); + D3DVOID WINAPI QueryBufferSpace(__out DWORD* pUsed, __out DWORD* pRemaining); + D3DVOID WINAPI SetPredication(DWORD PredicationMask); + D3DVOID WINAPI SetPatchablePredication(DWORD PredicationMask, DWORD Identifier); + D3DVOID WINAPI BeginTiling(DWORD Flags, DWORD Count, __in_ecount(Count) CONST D3DRECT* pTileRects, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil); + HRESULT WINAPI EndTiling(DWORD ResolveFlags, __in_opt CONST D3DRECT* pResolveRects, __in_opt D3DBaseTexture* pDestTexture, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters); + D3DVOID WINAPI BeginZPass(DWORD Flags); + HRESULT WINAPI EndZPass(); + HRESULT WINAPI InvokeRenderPass(); + D3DVOID WINAPI BeginExport(DWORD Index, __in D3DResource* pResource, DWORD Flags); + D3DVOID WINAPI EndExport(DWORD Index, __in D3DResource* pResource, DWORD Flags); + D3DVOID WINAPI DrawTessellatedPrimitive(D3DTESSPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount); + D3DVOID WINAPI DrawIndexedTessellatedPrimitive(D3DTESSPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT PrimitiveCount); + HRESULT WINAPI SetRingBufferParameters(__in_opt CONST D3DRING_BUFFER_PARAMETERS *pParameters); + D3DVOID WINAPI XpsBegin(DWORD Flags); + HRESULT WINAPI XpsEnd(); + D3DVOID WINAPI XpsSetCallback(__in D3DXpsCallback pCallback, __in_opt void* pContext, DWORD Flags); + D3DVOID WINAPI XpsSubmit(DWORD InstanceCount, __in_bcount(Size) CONST void* pData, DWORD Size); + D3DVOID WINAPI XpsSetPredication(DWORD Predication); + D3DVOID WINAPI XpsSetPredicationFromVisibility(HANDLE VisibilityHandle); + D3DVOID WINAPI XpsSetPredicationFromQuery(__in_opt IDirect3DQuery9* pQuery); + HRESULT WINAPI BeginVertices(D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, UINT VertexStreamZeroStride, __deref_out_bcount(VertexCount*VertexStreamZeroStride) void**ppVertexData); + D3DVOID WINAPI EndVertices(); + HRESULT WINAPI BeginIndexedVertices(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT NumVertices, UINT IndexCount, D3DFORMAT IndexDataFormat, UINT VertexStreamZeroStride, __deref_out void** ppIndexData, __deref_out_bcount(NumVertices*VertexStreamZeroStride) void** ppVertexData); + D3DVOID WINAPI EndIndexedVertices(); + DWORD WINAPI InsertFence(); + D3DVOID WINAPI BlockOnFence(DWORD Fence); + BOOL WINAPI IsFencePending(DWORD Fence); + D3DVOID WINAPI SetBlendState(DWORD RenderTargetIndex, D3DBLENDSTATE BlendState); + D3DVOID WINAPI GetBlendState(DWORD RenderTargetIndex, __out D3DBLENDSTATE* pBlendState); + D3DVOID WINAPI SetVertexFetchConstant(UINT VertexFetchRegister, __in D3DVertexBuffer* pVertexBuffer, UINT Offset); + D3DVOID WINAPI SetTextureFetchConstant(UINT TextureFetchRegister, __in D3DBaseTexture* pTexture); + float WINAPI GetCounter(D3DCOUNTER CounterID); + D3DVOID WINAPI SetSafeLevel(DWORD Flags, DWORD Level); + D3DVOID WINAPI GetSafeLevel(DWORD* pFlags, __out DWORD* pLevel); + D3DVOID WINAPI SetHangCallback(D3DHANGCALLBACK pCallback); + D3DVOID WINAPI BeginConditionalSurvey(DWORD Identifier, DWORD Flags); + D3DVOID WINAPI EndConditionalSurvey(DWORD Flags); + D3DVOID WINAPI BeginConditionalRendering(DWORD Identifier); + D3DVOID WINAPI EndConditionalRendering(); + HRESULT WINAPI PersistDisplay(__in D3DTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters); + HRESULT WINAPI GetPersistedTexture(__deref_out D3DTexture** pFrontBuffer); + D3DVOID WINAPI Suspend(); + D3DVOID WINAPI Resume(); + HRESULT WINAPI CreatePerfCounters(__deref_out D3DPerfCounters** ppCounters, UINT NumInstances); + D3DVOID WINAPI EnablePerfCounters(BOOL Enable); + D3DVOID WINAPI SetPerfCounterEvents(__in CONST D3DPERFCOUNTER_EVENTS* pEvents, DWORD Flags); + D3DVOID WINAPI QueryPerfCounters(__in D3DPerfCounters* pCounters, DWORD Flags); + DWORD WINAPI GetNumPasses(); + D3DVOID WINAPI SetShaderInstructionAllocation(DWORD Flags, DWORD VertexShaderBase, DWORD PixelShaderBase); + D3DVOID WINAPI SetShaderGPRAllocation(DWORD Flags, DWORD VertexShaderCount, DWORD PixelShaderCount); + D3DVOID WINAPI GetShaderGPRAllocation(__out DWORD* pFlags, __out DWORD* pVertexShaderCount, __out DWORD* pPixelShaderCount); + D3DVOID WINAPI SetScreenExtentQueryMode(D3DSCREENEXTENTQUERYMODE Mode); + D3DVOID WINAPI GetScreenExtentQueryMode(__out D3DSCREENEXTENTQUERYMODE* pMode); + D3DVOID WINAPI BeginPixelShaderConstantF1(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount); + D3DVOID WINAPI EndPixelShaderConstantF1(); + D3DVOID WINAPI BeginVertexShaderConstantF1(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount); + D3DVOID WINAPI EndVertexShaderConstantF1(); + HRESULT WINAPI BeginPixelShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, UINT Vector4fCount); + D3DVOID WINAPI EndPixelShaderConstantF4(); + HRESULT WINAPI BeginVertexShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, UINT Vector4fCount); + D3DVOID WINAPI EndVertexShaderConstantF4(); + DWORD WINAPI GetCurrentFence(); + D3DVOID WINAPI InvalidateGpuCache(__in_bcount(Size) void* pBaseAddress, DWORD Size, DWORD Flags); + D3DVOID WINAPI InvalidateResourceGpuCache(__in D3DResource* pResource, DWORD Flags); + D3DVOID WINAPI FlushHiZStencil(D3DFHZS_FLUSHTYPE FlushType); + D3DVOID WINAPI UnsetAll(); + DWORD WINAPI GetDeviceState(); + D3DVOID WINAPI SetBlockCallback(DWORD Flags, __in_opt D3DBLOCKCALLBACK pCallback); + D3DVOID WINAPI SetSurfaces(__in CONST D3DSURFACES* pSurfaces, DWORD Flags); + HRESULT WINAPI CreateConstantBuffer(UINT VectorCount, DWORD Usage, __deref_out D3DConstantBuffer **ppConstantBuffer); + HRESULT WINAPI CreateCommandBuffer(UINT Size, DWORD Flags, __deref_out D3DCommandBuffer **ppCommandBuffer); + HRESULT WINAPI CreateGrowableCommandBuffer(DWORD Flags, __in D3DALLOCATECALLBACK pAllocateCallback, __in D3DFREECALLBACK pFreeCallback, __in D3DQUERYCALLBACK pQueryCallback, DWORD CallbackContext, DWORD SegmentSize, __deref_out D3DCommandBuffer** ppCommandBuffer); + D3DVOID WINAPI BeginCommandBuffer(__in D3DCommandBuffer* pCommandBuffer, DWORD Flags, __in_opt CONST D3DTAGCOLLECTION* pInheritTags, __in_opt CONST D3DTAGCOLLECTION* pPersistTags, __in_opt CONST D3DRECT* pTilingRects, DWORD TileCount); + HRESULT WINAPI EndCommandBuffer(); + D3DVOID WINAPI RunCommandBuffer(__in D3DCommandBuffer* pCommandBuffer, DWORD PredicationSelect); + HRESULT WINAPI InsertAsyncCommandBufferCall(__in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, DWORD PredicationSelect, DWORD Flags); + D3DVOID WINAPI SetCommandBufferPredication(DWORD TilePredication, DWORD RunPredication); + DWORD WINAPI InsertMarker(); + D3DVOID WINAPI Nop(DWORD Count); + D3DVOID WINAPI QuerySwapStatus(__out D3DSWAP_STATUS* pSwapStatus); + DWORD WINAPI PixBeginNamedEvent(DWORD Color, __in_z CONST char *szName, ...); + DWORD WINAPI PixEndNamedEvent(); + void WINAPI PixSetMarker(DWORD Color, __in_z CONST char *szName, ...); + void WINAPI PixIgnoreTexture(__in D3DBaseTexture* pTexture); + void WINAPI PixStopIgnoringTexture(__in D3DBaseTexture* pTexture); + void WINAPI PixIgnoreMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size); + void WINAPI PixStopIgnoringMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size); + HRESULT WINAPI PixSetTextureName(__in D3DBaseTexture* pTexture, __in_z const char* pName); + void WINAPI PixReportNewTexture(__in D3DBaseTexture* pTexture); + void WINAPI PixReportDeletedTexture(__in D3DBaseTexture* pTexture, BOOL BaseDeleted, BOOL MipDeleted); + void WINAPI PixReportMovedMemoryRange(__in_bcount(Size) const void* pDestinationAddress, __in_bcount(Size) const void* pSourceAddress, DWORD Size); + void WINAPI PixReportFreedMemoryRange(__in_bcount(Size) const void* pAddress, DWORD Size); + D3DVOID WINAPI SetViewportF(__in CONST D3DVIEWPORTF9* pViewportF); + D3DVOID WINAPI GetViewportF(__out D3DVIEWPORTF9* pViewportF); + HANDLE WINAPI BeginVisibilitySurvey(DWORD Flags); + D3DVOID WINAPI EndVisibilitySurvey(HANDLE VisibilityHandle); + D3DVOID WINAPI SetSwapMode(BOOL Asynchronous); + D3DASYNCBLOCK WINAPI InsertBlockOnAsyncResources(DWORD WriteCount, __in_ecount_opt(WriteCount) D3DResource* CONST* pWriteResourceList, DWORD ReadCount, __in_ecount_opt(ReadCount) D3DResource* CONST* pReadResourceList, DWORD Flags); + D3DVOID WINAPI SignalAsyncResources(D3DASYNCBLOCK AsyncBlock); + HRESULT WINAPI CreateAsyncCommandBufferCall(__in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags, D3DAsyncCommandBufferCall** ppAsyncCall); + HRESULT WINAPI CreatePerfCounterBatch(UINT NumSlots, UINT NumTiles, DWORD Flags, __deref_out D3DPerfCounterBatch** ppBatch); + HRESULT WINAPI CreateOcclusionQueryBatch(UINT NumSlots, UINT NumTiles, __deref_out D3DOcclusionQueryBatch** ppBatch); + + // The following methods are not supported on Xbox 360: + // + // TestCooperativeLevel + // GetAvailableTextureMemory + // EvictManagedResources + // SetCursorProperties + // SetCursorPosition + // ShowCursor + // CreateAdditionalSwapChain + // GetSwapChain + // GetNumberOfSwapChains + // SetDialogBoxMode + // UpdateSurface + // UpdateTexture + // GetRenderTargetData + // GetFrontBufferData + // StretchRect + // ColorFill + // CreateOffscreenPlainSurface + // ValidateDevice + // SetPaletteEntries + // GetPaletteEntries + // SetCurrentTexturePalette + // GetCurrentTexturePalette + // SetSoftwareVertexProcessing + // GetSoftwareVertexProcessing + // ProcessVertices + // BeginStateBlock + // EndStateBlock + // SetClipStatus + // GetClipStatus + + // Unbuffered 'Gpu' APIs: + // + // Most Xbox 360 D3D APIs defer the sending of modified state to the GPU + // until a Draw API is called. The following APIs are different in that + // they are unbuffered and so immediately send modified state to the GPU + // when the API is called. + + void WINAPI GpuOwn(D3DTAG Tag); + void WINAPI GpuOwnSubset(D3DTAG Tag, DWORD StartIndex, DWORD EndIndex); + void WINAPI GpuOwnVertexShaderConstantF(DWORD StartRegister, DWORD Vector4fCount); + void WINAPI GpuOwnPixelShaderConstantF(DWORD StartRegister, DWORD Vector4fCount); + void WINAPI GpuOwnShaders(); + void WINAPI GpuDisown(D3DTAG Tag); + void WINAPI GpuDisownSubset(D3DTAG Tag, DWORD StartIndex, DWORD EndIndex); + void WINAPI GpuDisownVertexShaderConstantF(DWORD StartRegister, DWORD Vector4fCount); + void WINAPI GpuDisownPixelShaderConstantF(DWORD StartRegister, DWORD Vector4fCount); + void WINAPI GpuDisownShaders(); + void WINAPI GpuDisownAll(); + void WINAPI GpuLoadPixelShaderConstantF4(UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors); + void WINAPI GpuLoadVertexShaderConstantF4(UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors); + void WINAPI GpuLoadPixelShaderConstantF4Pointer(UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount); + void WINAPI GpuLoadVertexShaderConstantF4Pointer(UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount); + HRESULT WINAPI GpuBeginVertexShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, DWORD Vector4fCount); + void WINAPI GpuEndVertexShaderConstantF4(); + HRESULT WINAPI GpuBeginPixelShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, DWORD Vector4fCount); + void WINAPI GpuEndPixelShaderConstantF4(); + void WINAPI GpuLoadShaders(__in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants); + void WINAPI GpuLoadShadersFast(__in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants, DWORD Flags); + void WINAPI GpuSetVertexFetchConstant(DWORD VertexFetchRegister, __in_opt D3DVertexBuffer* pVertexBuffer0, DWORD OffsetInBytes0, __in_opt D3DVertexBuffer* pVertexBuffer1, DWORD OffsetInBytes1, __in_opt D3DVertexBuffer* pVertexBuffer2, DWORD OffsetInBytes2); + void WINAPI GpuSetTextureFetchConstant(DWORD TextureFetchRegister, __in D3DBaseTexture* pTexture); + void WINAPI GpuSetColorMask(__in const GPU_COLORMASK* pColorMask); + void WINAPI GpuSetBlendFactor(__in const D3DCOLORVALUE* pColor); + void WINAPI GpuSetAlphaRef(float Ref); + void WINAPI GpuSetBlendControl(DWORD RenderTargetIndex, __in const GPU_BLENDCONTROL* pBlendControl); + void WINAPI GpuSetColorControl(__in const GPU_COLORCONTROL* pColorControl); + +#endif __cplusplus + + // Tracks all GPU registers that are pending to be set at the next Draw + // calls. These are essentially 'Lazy' flags for all GPU context state. + // Only registers that are not 'owned' by the 'Gpu' APIs can be pending. + // + D3DTAGCOLLECTION m_Pending; + + // To support the automatic Z prepass, some register writes have to + // be predicated. The following mask is used internally by D3D to catch + // updates to those registers, which all come from m_Pending.m_Mask[2]: + // + UINT64 m_Predicated_PendingMask2; + + // 'm_pRing' points one dword BEFORE the location in the ring-buffer + // or command buffer where the next GPU command will be added. It's one + // dword before so that we can use 'storewordupdate(dword, 4, pCommand)'/ + // 'storefloatupdate(float, 4, pCommand)' for most of our buffer writes, + // which is a nifty PPC trick that does a store and auto-increment in one + // instruction. The only caveat is that it's a pre-increment... + // + // (The 'storewordupdate/storefloatupdate' trick has the other nice + // attribute in that it forces the compiler to strongly order all writes + // to the ring-buffer, which is important since all writes to write-combined + // have to be perfectly consecutive in order to write-combine.) + // + PRING m_pRing; + + // 'm_pRingLimit' points to the end of the current secondary ring buffer + // segment. + // + PRING m_pRingLimit; + + // If 'm_pRing' is less than 'm_pRingGuarantee', it's guaranteed that + // there are at least 32 dwords of room in the segment. + // + PRING m_pRingGuarantee; + + // Reference count on the current device. + // + DWORD m_ReferenceCount; + + // Table of function pointers to specific state APIs. + // + D3DSETRENDERSTATECALL m_SetRenderStateCall[D3DRS_MAX/4]; + D3DSETSAMPLERSTATECALL m_SetSamplerStateCall[D3DSAMP_MAX/4]; + D3DGETRENDERSTATECALL m_GetRenderStateCall[D3DRS_MAX/4]; + D3DGETSAMPLERSTATECALL m_GetSamplerStateCall[D3DSAMP_MAX/4]; + + // Shadow of all GPU constants. Ensure that the beginning of the ALU + // constant array is 128-byte aligned. + // + __declspec(align(128)) D3DConstants m_Constants; + + // Shadow of all GPU render states. If updating a value in the shadow + // directly, be sure to also set the appropriate flag in 'm_Pending' + // so that the GPU's version of the state gets updated. + // + float m_ClipPlanes[D3DMAXUSERCLIPPLANES][4]; + + GPU_DESTINATIONPACKET m_DestinationPacket; + GPU_WINDOWPACKET m_WindowPacket; // Special, never set via 'm_Pending' + GPU_VALUESPACKET m_ValuesPacket; + GPU_PROGRAMPACKET m_ProgramPacket; + GPU_CONTROLPACKET m_ControlPacket; + GPU_TESSELLATORPACKET m_TessellatorPacket; + GPU_MISCPACKET m_MiscPacket; + GPU_POINTPACKET m_PointPacket; + + // Shadow sampler states for GetSamplerState + // + BYTE m_MaxAnisotropy[D3DSAMP_MAXSAMPLERS]; + BYTE m_ZFilter[D3DSAMP_MAXSAMPLERS]; +}; + +/* + * C exported method definitions for the class methods defined above and the C++ + * thunks that defer to them. + */ + +/* Direct3D */ + +D3DINLINE ULONG WINAPI Direct3D_AddRef() { return 1; } +D3DINLINE ULONG WINAPI Direct3D_Release() { return 1; } +D3DINLINE UINT WINAPI Direct3D_GetAdapterCount() { return 1; } +HRESULT WINAPI Direct3D_GetAdapterIdentifier(UINT Adapter, DWORD Flags, __out D3DADAPTER_IDENTIFIER9 *pIdentifier); +HRESULT WINAPI Direct3D_CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed); +HRESULT WINAPI Direct3D_CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat); +HRESULT WINAPI Direct3D_CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, __out_opt DWORD* pQualityLevels); +HRESULT WINAPI Direct3D_CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat); +HRESULT WINAPI Direct3D_CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat); +HRESULT WINAPI Direct3D_GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,__out D3DCAPS9 *pCaps); +HRESULT WINAPI Direct3D_CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, __in_opt void *hUnusedFocusWindow, DWORD BehaviorFlags, __in_opt D3DPRESENT_PARAMETERS *pPresentationParameters, __deref_out D3DDevice **ppReturnedDeviceInterface); +void WINAPI Direct3D_QueryGpuVersion(__out D3DGPUVERSION* pGpuVersion); + + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3D9_AddRef(__in Direct3D *pThis) { return Direct3D_AddRef(); } +D3DINLINE ULONG WINAPI IDirect3D9_Release(__in Direct3D *pThis) { return Direct3D_Release(); } +D3DINLINE UINT WINAPI IDirect3D9_GetAdapterCount(__in Direct3D *pThis) { return Direct3D_GetAdapterCount(); } +D3DINLINE HRESULT WINAPI IDirect3D9_GetAdapterIdentifier(__in Direct3D *pThis, UINT Adapter, DWORD Flags, __out D3DADAPTER_IDENTIFIER9 *pIdentifier) { return Direct3D_GetAdapterIdentifier(Adapter, Flags, pIdentifier); } +D3DINLINE HRESULT WINAPI IDirect3D9_CheckDeviceType(__in Direct3D *pThis, UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed) { return Direct3D_CheckDeviceType(Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed); } +D3DINLINE HRESULT WINAPI IDirect3D9_CheckDeviceFormat(__in Direct3D *pThis, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) { return Direct3D_CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); } +D3DINLINE HRESULT WINAPI IDirect3D9_CheckDeviceMultiSampleType(__in Direct3D *pThis, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, __out_opt DWORD* pQualityLevels) { return Direct3D_CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels); } +D3DINLINE HRESULT WINAPI IDirect3D9_CheckDepthStencilMatch(__in Direct3D *pThis, UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) { return Direct3D_CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); } +D3DINLINE HRESULT WINAPI IDirect3D9_CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) { return Direct3D_CheckDeviceFormatConversion(Adapter, DeviceType, SourceFormat, TargetFormat); } +D3DINLINE HRESULT WINAPI IDirect3D9_GetDeviceCaps(__in Direct3D *pThis, UINT Adapter,D3DDEVTYPE DeviceType,__out D3DCAPS9 *pCaps) { return Direct3D_GetDeviceCaps(Adapter, DeviceType, pCaps); } +D3DINLINE HRESULT WINAPI IDirect3D9_CreateDevice(__in Direct3D *pThis, UINT Adapter, D3DDEVTYPE DeviceType, __in_opt void *hUnusedFocusWindow, DWORD BehaviorFlags, __in_opt D3DPRESENT_PARAMETERS *pPresentationParameters, __deref_out D3DDevice **ppReturnedDeviceInterface) { return Direct3D_CreateDevice(Adapter, DeviceType, hUnusedFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); } +D3DINLINE void WINAPI IDirect3D9_QueryGpuVersion(__in Direct3D *pThis, __out D3DGPUVERSION* pGpuVersion) { Direct3D_QueryGpuVersion(pGpuVersion); } + +#ifdef __cplusplus + +D3DMINLINE ULONG WINAPI Direct3D::AddRef() { return Direct3D_AddRef(); } +D3DMINLINE ULONG WINAPI Direct3D::Release() { return Direct3D_Release(); } +D3DMINLINE UINT WINAPI Direct3D::GetAdapterCount() { return Direct3D_GetAdapterCount(); } +D3DMINLINE HRESULT WINAPI Direct3D::GetAdapterIdentifier(UINT Adapter, DWORD Flags, __out D3DADAPTER_IDENTIFIER9 *pIdentifier) { return Direct3D_GetAdapterIdentifier(Adapter, Flags, pIdentifier); } +D3DMINLINE HRESULT WINAPI Direct3D::CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed) { return Direct3D_CheckDeviceType(Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed); } +D3DMINLINE HRESULT WINAPI Direct3D::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) { return Direct3D_CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); } +D3DMINLINE HRESULT WINAPI Direct3D::CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, __out_opt DWORD* pQualityLevels) { return Direct3D_CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels); } +D3DMINLINE HRESULT WINAPI Direct3D::CheckDepthStencilMatch(UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) { return Direct3D_CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); } +D3DMINLINE HRESULT WINAPI Direct3D::CheckDeviceFormatConversion(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) { return Direct3D_CheckDeviceFormatConversion(Adapter, DeviceType, SourceFormat, TargetFormat); } +D3DMINLINE HRESULT WINAPI Direct3D::GetDeviceCaps(UINT Adapter,D3DDEVTYPE DeviceType,__out D3DCAPS9 *pCaps) { return Direct3D_GetDeviceCaps(Adapter, DeviceType, pCaps); } +D3DMINLINE HRESULT WINAPI Direct3D::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, __in_opt void *hUnusedFocusWindow, DWORD BehaviorFlags, __in_opt D3DPRESENT_PARAMETERS *pPresentationParameters, __deref_out D3DDevice **ppReturnedDeviceInterface) { return Direct3D_CreateDevice(Adapter, DeviceType, hUnusedFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); } +D3DMINLINE void WINAPI Direct3D::QueryGpuVersion(__out D3DGPUVERSION* pGpuVersion) { Direct3D_QueryGpuVersion(pGpuVersion); } + +#endif __cplusplus + +/**************************************************************************** + * + * D3DDevice_* + * + * Private internal interfaces - Please don't access these directly, as they're + * subject to change. + * + ****************************************************************************/ + +__out D3DVertexShader* WINAPI D3DDevice_CreateVertexShader(__in CONST DWORD *pFunction); +__out D3DPixelShader* WINAPI D3DDevice_CreatePixelShader(__in CONST DWORD *pFunction); +__out D3DBaseTexture* WINAPI D3DDevice_CreateTexture(DWORD Width, DWORD Height, DWORD Depth, DWORD Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, D3DRESOURCETYPE D3DType); +__out D3DSurface* WINAPI D3DDevice_CreateSurface(DWORD Width, DWORD Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, CONST D3DSURFACE_PARAMETERS* pParameters); +__out D3DVertexBuffer* WINAPI D3DDevice_CreateVertexBuffer(UINT Length, DWORD Usage, D3DPOOL UnusedPool); +__out D3DIndexBuffer* WINAPI D3DDevice_CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool); +__out D3DVertexDeclaration* WINAPI D3DDevice_CreateVertexDeclaration(__in CONST D3DVERTEXELEMENT9* pVertexElements); +__out D3DConstantBuffer* WINAPI D3DDevice_CreateConstantBuffer(UINT VectorCount, DWORD Usage); +__out D3DCommandBuffer* WINAPI D3DDevice_CreateCommandBuffer(UINT Size, DWORD Flags); +__out D3DCommandBuffer* WINAPI D3DDevice_CreateGrowableCommandBuffer(DWORD Flags, __in D3DALLOCATECALLBACK pAllocateCallback, __in D3DFREECALLBACK pFreeCallback, __in D3DQUERYCALLBACK pQueryCallback, DWORD CallbackContext, DWORD SegmentSize); +__out D3DQuery* WINAPI D3DDevice_CreateQuery(__in D3DDevice *pDevice, D3DQUERYTYPE Type); +__out D3DQuery* WINAPI D3DDevice_CreateQueryTiled(__in D3DDevice *pDevice, D3DQUERYTYPE Type, DWORD TileCount); +__out D3DVertexDeclaration* WINAPI D3DDevice_GetVertexDeclaration(__in D3DDevice *pDevice); +__out D3DSurface* WINAPI D3DDevice_GetRenderTarget(__in D3DDevice *pDevice, DWORD RenderTargetIndex); +__out D3DSurface* WINAPI D3DDevice_GetDepthStencilSurface(__in D3DDevice *pDevice); +__out D3DSurface* WINAPI D3DDevice_GetBackBuffer(__in D3DDevice *pDevice); +__out D3DTexture* WINAPI D3DDevice_GetFrontBuffer(__in D3DDevice *pDevice); +__out D3DBaseTexture* WINAPI D3DDevice_GetTexture(__in D3DDevice *pDevice, DWORD Sampler); +__out D3DVertexBuffer* WINAPI D3DDevice_GetStreamSource(__in D3DDevice *pDevice, UINT StreamNumber, __out UINT *pOffsetInBytes, __out UINT *pStride); +__out D3DIndexBuffer* WINAPI D3DDevice_GetIndices(__in D3DDevice *pDevice); +__out D3DStateBlock* WINAPI D3DDevice_CreateStateBlock(__in D3DDevice* pDevice, D3DSTATEBLOCKTYPE Type); +__out D3DPerfCounters* WINAPI D3DDevice_CreatePerfCounters(__in D3DDevice *pDevice, UINT NumInstances); +__out D3DPerfCounterBatch* WINAPI D3DDevice_CreatePerfCounterBatch(__in D3DDevice* pDevice, UINT NumSlots, UINT NumTiles, DWORD Flags); +__out D3DOcclusionQueryBatch* WINAPI D3DDevice_CreateOcclusionQueryBatch(__in D3DDevice* pDevice, UINT NumSlots, UINT NumTiles); + +ULONG WINAPI D3DDevice_AddRef(__in D3DDevice *pDevice); +ULONG WINAPI D3DDevice_Release(__in D3DDevice *pDevice); +void WINAPI D3DDevice_GetDirect3D(__in D3DDevice *pDevice, __deref_out Direct3D **ppD3D9); +void WINAPI D3DDevice_GetDeviceCaps(__in D3DDevice *pDevice, __out D3DCAPS9 *pCaps); +void WINAPI D3DDevice_GetDisplayMode(__in D3DDevice *pDevice, UINT UnusedSwapChain, __out D3DDISPLAYMODE *pMode); +void WINAPI D3DDevice_GetCreationParameters(__in D3DDevice *pDevice, __out D3DDEVICE_CREATION_PARAMETERS *pParameters); +HRESULT WINAPI D3DDevice_Reset(__in D3DDevice *pDevice, __in D3DPRESENT_PARAMETERS *pPresentationParameters); +void WINAPI D3DDevice_GetRasterStatus(__in D3DDevice *pDevice, __out D3DRASTER_STATUS *pRasterStatus); +void WINAPI D3DDevice_SetGammaRamp(__in D3DDevice *pDevice, DWORD UnusedFlags, __in CONST D3DGAMMARAMP *pRamp); +void WINAPI D3DDevice_GetGammaRamp(__in D3DDevice *pDevice, __out D3DGAMMARAMP *pRamp); +void WINAPI D3DDevice_SetPWLGamma(__in D3DDevice *pDevice, DWORD Flags, __in CONST D3DPWLGAMMA *pRamp); +void WINAPI D3DDevice_GetPWLGamma(__in D3DDevice *pDevice, __out D3DPWLGAMMA *pRamp); +void WINAPI D3DDevice_SetRenderTarget(__in D3DDevice *pDevice, DWORD RenderTargetIndex, __in_opt D3DSurface *pRenderTarget); +void WINAPI D3DDevice_SetRenderTarget_External(__in D3DDevice *pDevice, DWORD RenderTargetIndex, __in_opt D3DSurface *pRenderTarget); +void WINAPI D3DDevice_SetDepthStencilSurface(__in D3DDevice *pDevice, __in_opt D3DSurface *pZStencilSurface); +D3DINLINE void WINAPI D3DDevice_BeginScene(__in D3DDevice *pDevice) { } +D3DINLINE void WINAPI D3DDevice_EndScene(__in D3DDevice *pDevice) { } +void WINAPI D3DDevice_Clear(__in D3DDevice *pDevice, DWORD Count, __in_opt CONST D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil, BOOL EDRAMClear); +void WINAPI D3DDevice_ClearF(__in D3DDevice *pDevice, DWORD Flags, __in_opt CONST D3DRECT *pRect, __in_opt CONST D3DVECTOR4* pColor, float Z, DWORD Stencil); +void WINAPI D3DDevice_SetViewport(__in D3DDevice *pDevice, __in CONST D3DVIEWPORT9 *pViewport); +void WINAPI D3DDevice_GetViewport(__in D3DDevice *pDevice, __out D3DVIEWPORT9 *pViewport); +void WINAPI D3DDevice_SetRenderState_ParameterCheck(__in D3DDevice *pDevice, D3DRENDERSTATETYPE State, DWORD Value); +void WINAPI D3DDevice_GetRenderState_ParameterCheck(__in D3DDevice *pDevice, D3DRENDERSTATETYPE State); +void WINAPI D3DDevice_SetSamplerState_ParameterCheck(__in D3DDevice *pDevice, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value); +void WINAPI D3DDevice_GetSamplerState_ParameterCheck(__in D3DDevice *pDevice, DWORD Sampler, D3DSAMPLERSTATETYPE Type); +void WINAPI D3DDevice_SetTexture(__in D3DDevice *pDevice, DWORD Sampler, __in_opt D3DBaseTexture *pTexture, UINT64 PendingMask3); +void WINAPI D3DDevice_DrawVertices(__in D3DDevice *pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT VertexCount); +void WINAPI D3DDevice_DrawIndexedVertices(__in D3DDevice *pDevice, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT IndexCount); +void WINAPI D3DDevice_DrawVerticesUP(__in D3DDevice *pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride); +void WINAPI D3DDevice_DrawIndexedVerticesUP(__in D3DDevice *pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT IndexCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride); +void WINAPI D3DDevice_SetVertexDeclaration(__in D3DDevice* pDevice, __in_opt D3DVertexDeclaration *pDecl); +void WINAPI D3DDevice_SetScissorRect(__in D3DDevice* pDevice, __in CONST RECT* pRect); +void WINAPI D3DDevice_GetScissorRect(__in D3DDevice* pDevice, __out RECT* pRect); +void WINAPI D3DDevice_SetFVF(__in D3DDevice *pDevice, DWORD FVF); +DWORD WINAPI D3DDevice_GetFVF(__in D3DDevice *pDevice); +void WINAPI D3DDevice_SetVertexShader(__in D3DDevice *pDevice, __in_opt D3DVertexShader *pShader); +void WINAPI D3DDevice_GetVertexShader(__in D3DDevice *pDevice, __deref_out D3DVertexShader **ppShader); +void WINAPI D3DDevice_SetVertexShaderConstantB(__in D3DDevice *pDevice, UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount); +void WINAPI D3DDevice_SetVertexShaderConstantFN(__in D3DDevice *pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount, UINT64 PendingMask0); +void WINAPI D3DDevice_SetVertexShaderConstantI(__in D3DDevice *pDevice, UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount); +void WINAPI D3DDevice_GetVertexShaderConstantB(__in D3DDevice *pDevice, UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount); +void WINAPI D3DDevice_GetVertexShaderConstantF(__in D3DDevice *pDevice, UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount); +void WINAPI D3DDevice_GetVertexShaderConstantI(__in D3DDevice *pDevice, UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount); +void WINAPI D3DDevice_SetVertexShaderConstantF_ParameterCheck(__in D3DDevice* pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount); +void WINAPI D3DDevice_SetStreamSource(__in D3DDevice *pDevice, UINT StreamNumber, __in_opt D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride, UINT64 PendingMask3); +void WINAPI D3DDevice_SetIndices(__in D3DDevice *pDevice, __in_opt D3DIndexBuffer *pIndexData); +void WINAPI D3DDevice_SetPixelShader(__in D3DDevice *pDevice, __in_opt D3DPixelShader* pShader); +void WINAPI D3DDevice_GetPixelShader(__in D3DDevice *pDevice, __deref_out D3DPixelShader** ppShader); +void WINAPI D3DDevice_SetPixelShaderConstantB(__in D3DDevice *pDevice, UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount); +void WINAPI D3DDevice_SetPixelShaderConstantFN(__in D3DDevice *pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount, UINT64 PendingMask1); +void WINAPI D3DDevice_SetPixelShaderConstantI(__in D3DDevice *pDevice, UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount); +void WINAPI D3DDevice_GetPixelShaderConstantB(__in D3DDevice *pDevice, UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount); +void WINAPI D3DDevice_GetPixelShaderConstantF(__in D3DDevice *pDevice, UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount); +void WINAPI D3DDevice_GetPixelShaderConstantI(__in D3DDevice *pDevice, UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount); +void WINAPI D3DDevice_SetPixelShaderConstantF_ParameterCheck(__in D3DDevice* pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount); +void WINAPI D3DDevice_SetClipPlane(__in D3DDevice *pDevice, DWORD Index, __in_ecount(4) CONST float* pPlane); +void WINAPI D3DDevice_GetClipPlane(__in D3DDevice *pDevice, DWORD Index, __out_ecount(4) float* pPlane); + +void WINAPI D3DDevice_Resolve(__in D3DDevice* pDevice, DWORD Flags, __in_opt CONST D3DRECT *pSourceRect, __in D3DBaseTexture *pDestTexture, __in_opt CONST D3DPOINT *pDestPoint, UINT DestLevel, UINT DestSliceOrFace, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters); +void WINAPI D3DDevice_AcquireThreadOwnership(__in D3DDevice* pDevice); +void WINAPI D3DDevice_ReleaseThreadOwnership(__in D3DDevice* pDevice); +void WINAPI D3DDevice_SetThreadOwnership(__in D3DDevice* pDevice, DWORD ThreadID); +DWORD WINAPI D3DDevice_QueryThreadOwnership(__in D3DDevice* pDevice); +void WINAPI D3DDevice_Present(__in D3DDevice *pDevice); +BOOL WINAPI D3DDevice_IsBusy(__in D3DDevice *pDevice); +void WINAPI D3DDevice_BlockUntilIdle(__in D3DDevice *pDevice); +void WINAPI D3DDevice_InsertCallback(__in D3DDevice *pDevice, D3DCALLBACKTYPE Type, __in_opt D3DCALLBACK pCallback, DWORD Context); +void WINAPI D3DDevice_SetVerticalBlankCallback(__in D3DDevice *pDevice, __in_opt D3DVBLANKCALLBACK pCallback); +void WINAPI D3DDevice_SetSwapCallback(__in D3DDevice *pDevice, __in D3DSWAPCALLBACK pCallback); +void WINAPI D3DDevice_SynchronizeToPresentationInterval(__in D3DDevice *pDevice); +void WINAPI D3DDevice_Swap(__in D3DDevice *pDevice, __in D3DBaseTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters); +void WINAPI D3DDevice_RenderSystemUI(__in D3DDevice *pDevice); +void WINAPI D3DDevice_QueryBufferSpace(__in D3DDevice* pDevice, __out DWORD* pUsed, __out DWORD* pRemaining); +void WINAPI D3DDevice_SetPredication(__in D3DDevice* pDevice, DWORD PredicationMask); +void WINAPI D3DDevice_SetPatchablePredication(__in D3DDevice* pDevice, DWORD PredicationMask, DWORD Identifier); +void WINAPI D3DDevice_BeginTiling(__in D3DDevice* pDevice, DWORD Flags, DWORD Count, __in_ecount(Count) CONST D3DRECT* pTileRects, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil); +HRESULT WINAPI D3DDevice_EndTiling(__in D3DDevice* pDevice, DWORD ResolveFlags, __in_opt CONST D3DRECT* pResolveRects, __in_opt D3DBaseTexture* pDestTexture, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters); +void WINAPI D3DDevice_BeginZPass(__in D3DDevice* pDevice, DWORD Flags); +HRESULT WINAPI D3DDevice_EndZPass(__in D3DDevice* pDevice); +HRESULT WINAPI D3DDevice_InvokeRenderPass(__in D3DDevice* pDevice); +void WINAPI D3DDevice_BeginExport(__in D3DDevice* pDevice, DWORD Index, __in D3DResource* pResource, DWORD Flags); +void WINAPI D3DDevice_EndExport(__in D3DDevice* pDevice, DWORD Index, __in D3DResource* pResource, DWORD Flags); +void WINAPI D3DDevice_DrawTessellatedVertices(__in D3DDevice *pDevice, D3DTESSPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT VertexCount); +void WINAPI D3DDevice_DrawIndexedTessellatedVertices(__in D3DDevice *pDevice, D3DTESSPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT IndexCount); +HRESULT WINAPI D3DDevice_SetRingBufferParameters(__in D3DDevice* pDevice, __in_opt CONST D3DRING_BUFFER_PARAMETERS *pParameters); +void WINAPI D3DDevice_XpsBegin(__in D3DDevice* pDevice, DWORD Flags); +HRESULT WINAPI D3DDevice_XpsEnd(__in D3DDevice* pDevice); +void WINAPI D3DDevice_XpsSetCallback(__in D3DDevice* pDevice, __in D3DXpsCallback pCallback, __in_opt void* pContext, DWORD Flags); +void WINAPI D3DDevice_XpsSubmit(__in D3DDevice* pDevice, DWORD InstanceCount, __in_bcount(Size) CONST void* pData, DWORD Size); +void WINAPI D3DDevice_XpsSetPredication(__in D3DDevice* pDevice, DWORD Predication); +void WINAPI D3DDevice_XpsSetPredicationFromVisibility(__in D3DDevice* pDevice, HANDLE VisibilityHandle); +void WINAPI D3DDevice_XpsSetPredicationFromQuery(__in D3DDevice* pDevice, __in_opt IDirect3DQuery9* pQuery); +__out_bcount(VertexCount*VertexStreamZeroStride) void* WINAPI D3DDevice_BeginVertices(__in D3DDevice *pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, UINT VertexStreamZeroStride); +void WINAPI D3DDevice_EndVertices(__in D3DDevice *pDevice); +HRESULT WINAPI D3DDevice_BeginIndexedVertices(__in D3DDevice *pDevice, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT NumVertices, UINT IndexCount, D3DFORMAT IndexDataFormat, UINT VertexStreamZeroStride, __deref_out void** ppIndexData, __deref_out_bcount(NumVertices*VertexStreamZeroStride) void** ppVertexData); +void WINAPI D3DDevice_EndIndexedVertices(__in D3DDevice *pDevice); +DWORD WINAPI D3DDevice_InsertFence(__in D3DDevice* pDevice); +void WINAPI D3DDevice_BlockOnFence(DWORD Fence); +BOOL WINAPI D3DDevice_IsFencePending(DWORD Fence); +void WINAPI D3DDevice_SetBlendState(__in D3DDevice* pDevice, DWORD RenderTargetIndex, D3DBLENDSTATE BlendState); +void WINAPI D3DDevice_GetBlendState(__in D3DDevice* pDevice, DWORD RenderTargetIndex, __out D3DBLENDSTATE* pBlendState); +void WINAPI D3DDevice_SetVertexFetchConstant(__in D3DDevice* pDevice, UINT VertexFetchRegister, __in D3DVertexBuffer* pVertexBuffer, UINT Offset); +void WINAPI D3DDevice_SetTextureFetchConstant(__in D3DDevice* pDevice, UINT TextureFetchRegister, __in D3DBaseTexture* pTexture); +float WINAPI D3DDevice_GetCounter(__in D3DDevice* pDevice, D3DCOUNTER CounterID); +void WINAPI D3DDevice_SetSafeLevel(__in D3DDevice* pDevice, DWORD Flags, DWORD Level); +void WINAPI D3DDevice_GetSafeLevel(__in D3DDevice* pDevice, DWORD* pFlags, __out DWORD* pLevel); +void WINAPI D3DDevice_SetHangCallback(__in D3DDevice* pDevice, D3DHANGCALLBACK pCallback); +void WINAPI D3DDevice_BeginConditionalSurvey(__in D3DDevice* pDevice, DWORD Identifier, DWORD Flags); +void WINAPI D3DDevice_EndConditionalSurvey(__in D3DDevice* pDevice, DWORD Flags); +void WINAPI D3DDevice_BeginConditionalRendering(__in D3DDevice* pDevice, DWORD Identifier); +void WINAPI D3DDevice_EndConditionalRendering(__in D3DDevice* pDevice); +HRESULT WINAPI D3DDevice_PersistDisplay(__in D3DDevice* pDevice, __in D3DTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters); +HRESULT WINAPI D3DDevice_GetPersistedTexture(__in D3DDevice* pDevice, __deref_out D3DTexture** pFrontBuffer); +void WINAPI D3DDevice_Suspend(__in D3DDevice* pDevice); +void WINAPI D3DDevice_Resume(__in D3DDevice* pDevice); +void WINAPI D3DDevice_EnablePerfCounters(__in D3DDevice* pDevice, BOOL Enable); +void WINAPI D3DDevice_SetPerfCounterEvents(__in D3DDevice* pDevice, __in CONST D3DPERFCOUNTER_EVENTS* pEvents, DWORD Flags); +void WINAPI D3DDevice_QueryPerfCounters(__in D3DDevice* pDevice, __in D3DPerfCounters* pCounters, DWORD Flags); +DWORD WINAPI D3DDevice_GetNumPasses(__in D3DDevice* pDevice); +void WINAPI D3DDevice_SetShaderInstructionAllocation(__in D3DDevice* pDevice, DWORD Flags, DWORD VertexShaderBase, DWORD PixelShaderBase); +void WINAPI D3DDevice_SetShaderGPRAllocation(__in D3DDevice* pDevice, DWORD Flags, DWORD VertexShaderCount, DWORD PixelShaderCount); +void WINAPI D3DDevice_GetShaderGPRAllocation(__in D3DDevice* pDevice, __out DWORD* pFlags, __out DWORD* pVertexShaderCount, __out DWORD* pPixelShaderCount); +void WINAPI D3DDevice_SetScreenExtentQueryMode(__in D3DDevice* pDevice, D3DSCREENEXTENTQUERYMODE Mode); +void WINAPI D3DDevice_GetScreenExtentQueryMode(__in D3DDevice* pDevice, __out D3DSCREENEXTENTQUERYMODE* pMode); +void WINAPI D3DDevice_BeginShaderConstantF1_ParameterCheck(__in D3DDevice *pDevice, BOOL PixelShader, UINT StartRegister, DWORD Vector4fCount); +void WINAPI D3DDevice_EndShaderConstantF1_ParameterCheck(__in D3DDevice *pDevice); +HRESULT WINAPI D3DDevice_BeginShaderConstantF4(__in D3DDevice *pDevice, BOOL PixelShader, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, DWORD Vector4fCount); +void WINAPI D3DDevice_EndShaderConstantF4_ParameterCheck(__in D3DDevice *pDevice); +DWORD WINAPI D3DDevice_GetCurrentFence(); +void WINAPI D3DDevice_InvalidateGpuCache(__in D3DDevice* pDevice, __in_bcount(Size) void* pBaseAddress, DWORD Size, DWORD Flags); +void WINAPI D3DDevice_InvalidateResourceGpuCache(__in D3DDevice* pDevice, __in D3DResource* pResource, DWORD Flags); +void WINAPI D3DDevice_FlushHiZStencil(__in D3DDevice* pDevice, D3DFHZS_FLUSHTYPE FlushType); +void WINAPI D3DDevice_UnsetAll(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetDeviceState(__in D3DDevice* pDevice); +void WINAPI D3DDevice_SetBlockCallback(__in D3DDevice* pDevice, DWORD Flags, __in_opt D3DBLOCKCALLBACK pCallback); +void WINAPI D3DDevice_SetSurfaces(__in D3DDevice* pDevice, __in CONST D3DSURFACES* pSurfaces, DWORD Flags); +void WINAPI D3DDevice_BeginCommandBuffer(__in D3DDevice* pDevice, __in D3DCommandBuffer* pCommandBuffer, DWORD Flags, __in_opt CONST D3DTAGCOLLECTION* pInheritTags, __in_opt CONST D3DTAGCOLLECTION* pPersistTags, __in_opt CONST D3DRECT* pTilingRects, DWORD TileCount); +HRESULT WINAPI D3DDevice_EndCommandBuffer(__in D3DDevice* pDevice); +void WINAPI D3DDevice_RunCommandBuffer(__in D3DDevice* pDevice, __in D3DCommandBuffer* pD3dCommandBuffer, DWORD PredicationSelect); +HRESULT WINAPI D3DDevice_InsertAsyncCommandBufferCall(__in D3DDevice* pDevice, __in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, DWORD PredicationSelect, DWORD Flags); +void WINAPI D3DDevice_SetCommandBufferPredication(__in D3DDevice* pDevice, DWORD TilePredication, DWORD RunPredication); +DWORD WINAPI D3DDevice_InsertMarker(__in D3DDevice* pDevice); +void WINAPI D3DDevice_Nop(__in D3DDevice* pDevice, DWORD Count); +void WINAPI D3DDevice_QuerySwapStatus(__in D3DDevice* pDevice, __out D3DSWAP_STATUS* pSwapStatus); +DWORD WINAPI D3DDevice_PixBeginNamedEvent(__in D3DDevice *pDevice, DWORD Color, __in_z CONST char *szName, va_list Arglist); +DWORD WINAPI D3DDevice_PixEndNamedEvent(__in D3DDevice *pDevice); +void WINAPI D3DDevice_PixSetMarker(__in D3DDevice *pDevice, DWORD Color, __in_z CONST char *szName, va_list Arglist); +void WINAPI D3DDevice_PixIgnoreTexture(__in D3DDevice* pDevice, __in D3DBaseTexture* pTexture); +void WINAPI D3DDevice_PixStopIgnoringTexture(__in D3DDevice* pDevice, __in D3DBaseTexture* pTexture); +void WINAPI D3DDevice_PixIgnoreMemoryRange(__in D3DDevice* pDevice, __in_bcount(Size) const void* pBaseAddress, DWORD Size); +void WINAPI D3DDevice_PixStopIgnoringMemoryRange(__in D3DDevice* pDevice, __in_bcount(Size) const void* pBaseAddress, DWORD Size); +HRESULT WINAPI D3DDevice_PixSetTextureName(__in D3DDevice* pDevice, __in D3DBaseTexture* pTexture, __in_z const char* pName); +void WINAPI D3DDevice_PixReportNewTexture(__in D3DDevice* pDevice, __in D3DBaseTexture* pTexture); +void WINAPI D3DDevice_PixReportDeletedTexture(__in D3DDevice* pDevice, __in D3DBaseTexture* pTexture, BOOL BaseDeleted, BOOL MipDeleted); +void WINAPI D3DDevice_PixReportMovedMemoryRange(__in D3DDevice* pDevice, __in_bcount(Size) const void* pDestinationAddress, __in_bcount(Size) const void* pSourceAddress, DWORD Size); +void WINAPI D3DDevice_PixReportFreedMemoryRange(__in D3DDevice* pDevice, __in_bcount(Size) const void* pAddress, DWORD Size); + +void WINAPI D3DDevice_SetViewportF(__in D3DDevice *pDevice, __in CONST D3DVIEWPORTF9* pViewportF); +void WINAPI D3DDevice_GetViewportF(__in D3DDevice *pDevice, __out D3DVIEWPORTF9* pViewportF); +HANDLE WINAPI D3DDevice_BeginVisibilitySurvey(__in D3DDevice* pDevice, DWORD Flags); +void WINAPI D3DDevice_EndVisibilitySurvey(__in D3DDevice* pDevice, HANDLE VisibilityHandle); +void WINAPI D3DDevice_SetSwapMode(__in D3DDevice* pDevice, BOOL Asynchronous); +D3DASYNCBLOCK WINAPI D3DDevice_InsertBlockOnAsyncResources(__in D3DDevice* pDevice, DWORD WriteCount, __in_ecount_opt(WriteCount) D3DResource* CONST* pWriteResourceList, DWORD ReadCount, __in_ecount_opt(ReadCount) D3DResource* CONST* pReadResourceList, DWORD Flags); +void WINAPI D3DDevice_SignalAsyncResources(__in D3DDevice* pDevice, D3DASYNCBLOCK AsyncBlock); +D3DAsyncCommandBufferCall* WINAPI D3DDevice_CreateAsyncCommandBufferCall(__in D3DDevice* pDevice, __in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags); + +void WINAPI D3DDevice_SetRenderState_CullMode(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_FillMode(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_AlphaTestEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_AlphaBlendEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_BlendOp(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_SrcBlend(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_DestBlend(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_BlendOpAlpha(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_SrcBlendAlpha(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_DestBlendAlpha(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_SeparateAlphaBlendEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_AlphaRef(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_AlphaFunc(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_BlendFactor(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ZEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ZWriteEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ZFunc(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_TwoSidedStencilMode(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilFunc(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilFail(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilZFail(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilPass(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilFunc(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilFail(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilZFail(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilPass(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilRef(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilMask(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_StencilWriteMask(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilRef(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilMask(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_CCWStencilWriteMask(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ClipPlaneEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ScissorTestEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_SlopeScaleDepthBias(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_DepthBias(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_MultiSampleAntiAlias(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_MultiSampleMask(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ColorWriteEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ColorWriteEnable1(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ColorWriteEnable2(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ColorWriteEnable3(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_PointSpriteEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_PointSize(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_PointSizeMin(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_PointSizeMax(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_Wrap0(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap1(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap2(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap3(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap4(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap5(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap6(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap7(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap8(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap9(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap10(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap11(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap12(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap13(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap14(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Wrap15(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_ViewportEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HighPrecisionBlendEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HighPrecisionBlendEnable1(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HighPrecisionBlendEnable2(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HighPrecisionBlendEnable3(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_MinTessellationLevel(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_MaxTessellationLevel(__in D3DDevice* pDevice, DWORD FloatAsDword); +void WINAPI D3DDevice_SetRenderState_TessellationMode(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HalfPixelOffset(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_PrimitiveResetEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_PrimitiveResetIndex(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_AlphaToMaskEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_AlphaToMaskOffsets(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_GuardBand_X(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_GuardBand_Y(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_DiscardBand_X(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_DiscardBand_Y(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HiStencilEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HiStencilWriteEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HiStencilFunc(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HiStencilRef(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_PresentInterval(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_PresentImmediateThreshold(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HiZEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_HiZWriteEnable(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_LastPixel(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_LineWidth(__in D3DDevice* pDevice, DWORD Value); +void WINAPI D3DDevice_SetRenderState_Buffer2Frames(__in D3DDevice* pDevice, DWORD Value); + +DWORD WINAPI D3DDevice_GetRenderState_CullMode(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_FillMode(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_AlphaTestEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_AlphaBlendEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_BlendOp(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_SrcBlend(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_DestBlend(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_BlendOpAlpha(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_SrcBlendAlpha(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_DestBlendAlpha(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_SeparateAlphaBlendEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_AlphaRef(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_AlphaFunc(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_BlendFactor(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ZEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ZWriteEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ZFunc(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_TwoSidedStencilMode(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilFunc(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilFail(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilZFail(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilPass(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilFunc(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilFail(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilZFail(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilPass(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilRef(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilMask(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_StencilWriteMask(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilRef(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilMask(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_CCWStencilWriteMask(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ClipPlaneEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ScissorTestEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_SlopeScaleDepthBias(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_DepthBias(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_MultiSampleAntiAlias(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_MultiSampleMask(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ColorWriteEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ColorWriteEnable1(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ColorWriteEnable2(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ColorWriteEnable3(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PointSpriteEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PointSize(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PointSizeMin(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PointSizeMax(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap0(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap1(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap2(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap3(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap4(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap5(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap6(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap7(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap8(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap9(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap10(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap11(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap12(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap13(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap14(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Wrap15(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_ViewportEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HighPrecisionBlendEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HighPrecisionBlendEnable1(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HighPrecisionBlendEnable2(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HighPrecisionBlendEnable3(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_MinTessellationLevel(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_MaxTessellationLevel(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_TessellationMode(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HalfPixelOffset(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PrimitiveResetEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PrimitiveResetIndex(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_AlphaToMaskEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_AlphaToMaskOffsets(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_GuardBand_X(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_GuardBand_Y(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_DiscardBand_X(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_DiscardBand_Y(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HiStencilEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HiStencilWriteEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HiStencilFunc(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HiStencilRef(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PresentInterval(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_PresentImmediateThreshold(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HiZEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_HiZWriteEnable(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_LastPixel(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_LineWidth(__in D3DDevice* pDevice); +DWORD WINAPI D3DDevice_GetRenderState_Buffer2Frames(__in D3DDevice* pDevice); + +void WINAPI D3DDevice_SetSamplerState_MinFilter(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_MinFilterZ(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_MagFilter(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_MagFilterZ(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_MipFilter(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_SeparateZFilterEnable(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_MaxAnisotropy(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_AnisotropyBias(__in D3DDevice* pDevice, DWORD Sampler, DWORD FloatAsDword); +void WINAPI D3DDevice_SetSamplerState_MipMapLodBias(__in D3DDevice* pDevice, DWORD Sampler, DWORD FloatAsDword); +void WINAPI D3DDevice_SetSamplerState_MaxMipLevel(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_MinMipLevel(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_BorderColor(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_AddressU(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_AddressV(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_AddressW(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_TrilinearThreshold(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_HGradientExpBias(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_VGradientExpBias(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_WhiteBorderColorW(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); +void WINAPI D3DDevice_SetSamplerState_PointBorderEnable(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value); + +DWORD WINAPI D3DDevice_GetSamplerState_MinFilter(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MinFilterZ(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MagFilter(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MagFilterZ(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MipFilter(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_SeparateZFilterEnable(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MaxAnisotropy(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_AnisotropyBias(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MipMapLodBias(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MaxMipLevel(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_MinMipLevel(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_BorderColor(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_AddressU(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_AddressV(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_AddressW(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_TrilinearThreshold(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_HGradientExpBias(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_VGradientExpBias(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_WhiteBorderColorW(__in D3DDevice* pDevice, DWORD Sampler); +DWORD WINAPI D3DDevice_GetSamplerState_PointBorderEnable(__in D3DDevice* pDevice, DWORD Sampler); + +__out D3DVECTOR4* WINAPI D3DDevice_GpuBeginShaderConstantF4(__in D3DDevice* pDevice, BOOL PixelShader, UINT StartRegister, DWORD Vector4fCount); + +void WINAPI D3DDevice_GpuOwn_ParameterCheck(__in D3DDevice *pDevice, DWORD Index, UINT64 Mask); +void WINAPI D3DDevice_GpuDisown_ParameterCheck(__in D3DDevice *pDevice, DWORD Index, UINT64 Mask); +void WINAPI D3DDevice_GpuDisownAll(__in D3DDevice *pDevice); +void WINAPI D3DDevice_GpuEndShaderConstantF4_ParameterCheck(__in D3DDevice* pDevice); +void WINAPI D3DDevice_GpuLoadShaderConstantF4(__in D3DDevice* pDevice, BOOL PixelShader, UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors); +void WINAPI D3DDevice_GpuLoadShaderConstantF4Pointer(__in D3DDevice* pDevice, BOOL PixelShader, UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount); +void WINAPI D3DDevice_GpuLoadShadersFast(__in D3DDevice* pDevice, __in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants, DWORD Flags); +void WINAPI D3DDevice_GpuSetVertexFetchConstant(__in D3DDevice* pDevice, DWORD VertexFetchRegister, __in_opt D3DVertexBuffer* pVertexBuffer0, DWORD OffsetInBytes0, __in_opt D3DVertexBuffer* pVertexBuffer1, DWORD OffsetInBytes1, __in_opt D3DVertexBuffer* pVertexBuffer2, DWORD OffsetInBytes2); +void WINAPI D3DDevice_GpuSetTextureFetchConstant(__in D3DDevice* pDevice, DWORD TextureFetchRegister, __in D3DBaseTexture* pTexture); +void WINAPI D3DDevice_GpuSetColorMask(__in D3DDevice* pDevice, DWORD ColorMask); +void WINAPI D3DDevice_GpuSetBlendFactor(__in D3DDevice* pDevice, float r, float g, float b, float a); +void WINAPI D3DDevice_GpuSetAlphaRef(__in D3DDevice* pDevice, float Ref); +void WINAPI D3DDevice_GpuSetBlendControl(__in D3DDevice* pDevice, DWORD RenderTargetIndex, DWORD BlendControl); +void WINAPI D3DDevice_GpuSetColorControl(__in D3DDevice* pDevice, DWORD ColorControl); + +D3DINLINE void WINAPI D3DDevice_GpuLoadShaders(__in D3DDevice* pDevice, __in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants) +{ + D3DDevice_GpuLoadShadersFast(pDevice, pVertexShader, pPixelShader, pFlowConstants, 0); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_AddressU_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].ClampX = (GPUCLAMP)Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_AddressV_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].ClampY = (GPUCLAMP)Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_AddressW_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].ClampZ = (GPUCLAMP)Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_MipFilter_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].MipFilter = Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_BorderColor_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].BorderColor = (Value == 0) ? GPUBORDERCOLOR_ABGR_BLACK : GPUBORDERCOLOR_ABGR_WHITE; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_TrilinearThreshold_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].TriClamp = (GPUTRICLAMP)Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_HGradientExpBias_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].GradExpAdjustH = (INT) Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_VGradientExpBias_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].GradExpAdjustV = (INT) Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_WhiteBorderColorW_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].ForceBCWToMax = Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerState_PointBorderEnable_Inline(__in D3DDevice* pDevice, DWORD Sampler, DWORD Value) +{ + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].ClampPolicy = (GPUCLAMPPOLICY)!Value; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetStreamSource_Inline(__in D3DDevice* pDevice, UINT StreamNumber, __in_opt D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride) +{ + // The GPU has 96 vertex fetch constants and the hardware requires that they + // be set in groups of 3. This API has no notion of that requirement, so + // we defer actually setting the fetch constants to the hardware until + // the next 'Draw' time. What we do here is calculate the mask which will + // be ORed into D3DDevice::m_Pending[2] to indicate that the corresponding + // fetch constant needs to be set. + // + // When this API is called with a constant value for 'StreamNumber', all of + // this mask calculation code collapses to a single 'li' instruction. When + // passed a variable, we have to do more run-time work which includes + // dividing by 3 (which we approximate with a fixed-point multiply since + // that's faster). + DWORD vertexFetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(StreamNumber); + DWORD fetchConstant = (vertexFetchConstant * (65536/3 + 1)) >> 16; + UINT64 pendingMask3 = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + fetchConstant, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + fetchConstant); + + D3DDevice_SetStreamSource(pDevice, StreamNumber, pStreamData, OffsetInBytes, Stride, pendingMask3); +} + +D3DINLINE void WINAPI D3DDevice_SetTexture_Inline(__in D3DDevice* pDevice, DWORD Sampler, __in_opt D3DBaseTexture *pTexture) +{ + // As with D3DDevice_SetStreamSource_Inline above, we precompute the + // pending mask here to get a win when passed in a constant 'Sampler' + // value. The win here isn't as great, but we do avoid a shift-by- + // variable when given a constant which is a win because all such + // operations are handled in microcode by the CPU. + DWORD fetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + UINT64 pendingMask3 = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + fetchConstant, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + fetchConstant); + + D3DDevice_SetTexture(pDevice, Sampler, pTexture, pendingMask3); +} + +// When SetRenderState or SetSamplerState are called with a non-constant +// state type we indirect through a function-table which hangs off the device. +// +// In order to save a shift instruction we've pre-scaled the constants +// by 4 (the stride of the table) and do an ugly bit of casting. + +D3DINLINE void D3DDevice_SetRenderState(__in D3DDevice* pDevice, D3DRENDERSTATETYPE State, DWORD Value) +{ + #if defined(_DEBUG) + D3DDevice_SetRenderState_ParameterCheck(pDevice, State, Value); + #endif + + // Note that D3DISINTCONST() always evaluates to a constant: + + if (!D3DISINTCONST(State)) + { + // When 'State' is passed in using a non-constant we avoid horrendous + // code bloat by calling through the jump table: + + // Setting the state uses a function pointer table that assumes + // the pointers are 4 bytes in size. The pointer arithemetic for + // State*(sizeof(ULONG_PTR)/sizeof(DWORD)) uses platform specific + // ULONG_PTR type, which is the size of pointer, that when compiled + // is either compiled away (when sizeof(ULONG_PTR)/sizeof(DWORD) == 1) + // or becomes the specific multiple of the byte size for a pointer + // on the specific platform to ensure proper incrementation of the + // SetState pointer. + + (*(D3DSETRENDERSTATECALL*)(((BYTE*) &pDevice->m_SetRenderStateCall[0] + State*(sizeof(ULONG_PTR)/sizeof(DWORD)))))(pDevice, Value); + } + else + { + // When 'State' is passed in using a constant the optimizer can + // eliminate this entire switch statement: + + switch (State) + { + case D3DRS_ZENABLE: D3DDevice_SetRenderState_ZEnable(pDevice, Value); break; + case D3DRS_ZFUNC: D3DDevice_SetRenderState_ZFunc(pDevice, Value); break; + case D3DRS_ZWRITEENABLE: D3DDevice_SetRenderState_ZWriteEnable(pDevice, Value); break; + case D3DRS_FILLMODE: D3DDevice_SetRenderState_FillMode(pDevice, Value); break; + case D3DRS_CULLMODE: D3DDevice_SetRenderState_CullMode(pDevice, Value); break; + case D3DRS_ALPHABLENDENABLE: D3DDevice_SetRenderState_AlphaBlendEnable(pDevice, Value); break; + case D3DRS_SEPARATEALPHABLENDENABLE: D3DDevice_SetRenderState_SeparateAlphaBlendEnable(pDevice, Value); break; + case D3DRS_BLENDFACTOR: D3DDevice_SetRenderState_BlendFactor(pDevice, Value); break; + case D3DRS_SRCBLEND: D3DDevice_SetRenderState_SrcBlend(pDevice, Value); break; + case D3DRS_DESTBLEND: D3DDevice_SetRenderState_DestBlend(pDevice, Value); break; + case D3DRS_BLENDOP: D3DDevice_SetRenderState_BlendOp(pDevice, Value); break; + case D3DRS_SRCBLENDALPHA: D3DDevice_SetRenderState_SrcBlendAlpha(pDevice, Value); break; + case D3DRS_DESTBLENDALPHA: D3DDevice_SetRenderState_DestBlendAlpha(pDevice, Value); break; + case D3DRS_BLENDOPALPHA: D3DDevice_SetRenderState_BlendOpAlpha(pDevice, Value); break; + case D3DRS_ALPHATESTENABLE: D3DDevice_SetRenderState_AlphaTestEnable(pDevice, Value); break; + case D3DRS_ALPHAREF: D3DDevice_SetRenderState_AlphaRef(pDevice, Value); break; + case D3DRS_ALPHAFUNC: D3DDevice_SetRenderState_AlphaFunc(pDevice, Value); break; + case D3DRS_STENCILENABLE: D3DDevice_SetRenderState_StencilEnable(pDevice, Value); break; + case D3DRS_TWOSIDEDSTENCILMODE: D3DDevice_SetRenderState_TwoSidedStencilMode(pDevice, Value); break; + case D3DRS_STENCILFAIL: D3DDevice_SetRenderState_StencilFail(pDevice, Value); break; + case D3DRS_STENCILZFAIL: D3DDevice_SetRenderState_StencilZFail(pDevice, Value); break; + case D3DRS_STENCILPASS: D3DDevice_SetRenderState_StencilPass(pDevice, Value); break; + case D3DRS_STENCILFUNC: D3DDevice_SetRenderState_StencilFunc(pDevice, Value); break; + case D3DRS_STENCILREF: D3DDevice_SetRenderState_StencilRef(pDevice, Value); break; + case D3DRS_STENCILMASK: D3DDevice_SetRenderState_StencilMask(pDevice, Value); break; + case D3DRS_STENCILWRITEMASK: D3DDevice_SetRenderState_StencilWriteMask(pDevice, Value); break; + case D3DRS_CCW_STENCILFAIL: D3DDevice_SetRenderState_CCWStencilFail(pDevice, Value); break; + case D3DRS_CCW_STENCILZFAIL: D3DDevice_SetRenderState_CCWStencilZFail(pDevice, Value); break; + case D3DRS_CCW_STENCILPASS: D3DDevice_SetRenderState_CCWStencilPass(pDevice, Value); break; + case D3DRS_CCW_STENCILFUNC: D3DDevice_SetRenderState_CCWStencilFunc(pDevice, Value); break; + case D3DRS_CCW_STENCILREF: D3DDevice_SetRenderState_CCWStencilRef(pDevice, Value); break; + case D3DRS_CCW_STENCILMASK: D3DDevice_SetRenderState_CCWStencilMask(pDevice, Value); break; + case D3DRS_CCW_STENCILWRITEMASK: D3DDevice_SetRenderState_CCWStencilWriteMask(pDevice, Value); break; + case D3DRS_CLIPPLANEENABLE: D3DDevice_SetRenderState_ClipPlaneEnable(pDevice, Value); break; + case D3DRS_POINTSIZE: D3DDevice_SetRenderState_PointSize(pDevice, Value); break; + case D3DRS_POINTSIZE_MIN: D3DDevice_SetRenderState_PointSizeMin(pDevice, Value); break; + case D3DRS_POINTSPRITEENABLE: D3DDevice_SetRenderState_PointSpriteEnable(pDevice, Value); break; + case D3DRS_POINTSIZE_MAX: D3DDevice_SetRenderState_PointSizeMax(pDevice, Value); break; + case D3DRS_MULTISAMPLEANTIALIAS: D3DDevice_SetRenderState_MultiSampleAntiAlias(pDevice, Value); break; + case D3DRS_MULTISAMPLEMASK: D3DDevice_SetRenderState_MultiSampleMask(pDevice, Value); break; + case D3DRS_SCISSORTESTENABLE: D3DDevice_SetRenderState_ScissorTestEnable(pDevice, Value); break; + case D3DRS_SLOPESCALEDEPTHBIAS: D3DDevice_SetRenderState_SlopeScaleDepthBias(pDevice, Value); break; + case D3DRS_DEPTHBIAS: D3DDevice_SetRenderState_DepthBias(pDevice, Value); break; + case D3DRS_COLORWRITEENABLE: D3DDevice_SetRenderState_ColorWriteEnable(pDevice, Value); break; + case D3DRS_COLORWRITEENABLE1: D3DDevice_SetRenderState_ColorWriteEnable1(pDevice, Value); break; + case D3DRS_COLORWRITEENABLE2: D3DDevice_SetRenderState_ColorWriteEnable2(pDevice, Value); break; + case D3DRS_COLORWRITEENABLE3: D3DDevice_SetRenderState_ColorWriteEnable3(pDevice, Value); break; + case D3DRS_TESSELLATIONMODE: D3DDevice_SetRenderState_TessellationMode(pDevice, Value); break; + case D3DRS_MINTESSELLATIONLEVEL: D3DDevice_SetRenderState_MinTessellationLevel(pDevice, Value); break; + case D3DRS_MAXTESSELLATIONLEVEL: D3DDevice_SetRenderState_MaxTessellationLevel(pDevice, Value); break; + case D3DRS_WRAP0: D3DDevice_SetRenderState_Wrap0(pDevice, Value); break; + case D3DRS_WRAP1: D3DDevice_SetRenderState_Wrap1(pDevice, Value); break; + case D3DRS_WRAP2: D3DDevice_SetRenderState_Wrap2(pDevice, Value); break; + case D3DRS_WRAP3: D3DDevice_SetRenderState_Wrap3(pDevice, Value); break; + case D3DRS_WRAP4: D3DDevice_SetRenderState_Wrap4(pDevice, Value); break; + case D3DRS_WRAP5: D3DDevice_SetRenderState_Wrap5(pDevice, Value); break; + case D3DRS_WRAP6: D3DDevice_SetRenderState_Wrap6(pDevice, Value); break; + case D3DRS_WRAP7: D3DDevice_SetRenderState_Wrap7(pDevice, Value); break; + case D3DRS_WRAP8: D3DDevice_SetRenderState_Wrap8(pDevice, Value); break; + case D3DRS_WRAP9: D3DDevice_SetRenderState_Wrap9(pDevice, Value); break; + case D3DRS_WRAP10: D3DDevice_SetRenderState_Wrap10(pDevice, Value); break; + case D3DRS_WRAP11: D3DDevice_SetRenderState_Wrap11(pDevice, Value); break; + case D3DRS_WRAP12: D3DDevice_SetRenderState_Wrap12(pDevice, Value); break; + case D3DRS_WRAP13: D3DDevice_SetRenderState_Wrap13(pDevice, Value); break; + case D3DRS_WRAP14: D3DDevice_SetRenderState_Wrap14(pDevice, Value); break; + case D3DRS_WRAP15: D3DDevice_SetRenderState_Wrap15(pDevice, Value); break; + case D3DRS_VIEWPORTENABLE: D3DDevice_SetRenderState_ViewportEnable(pDevice, Value); break; + case D3DRS_HIGHPRECISIONBLENDENABLE: D3DDevice_SetRenderState_HighPrecisionBlendEnable(pDevice, Value); break; + case D3DRS_HIGHPRECISIONBLENDENABLE1: D3DDevice_SetRenderState_HighPrecisionBlendEnable1(pDevice, Value); break; + case D3DRS_HIGHPRECISIONBLENDENABLE2: D3DDevice_SetRenderState_HighPrecisionBlendEnable2(pDevice, Value); break; + case D3DRS_HIGHPRECISIONBLENDENABLE3: D3DDevice_SetRenderState_HighPrecisionBlendEnable3(pDevice, Value); break; + case D3DRS_HALFPIXELOFFSET: D3DDevice_SetRenderState_HalfPixelOffset(pDevice, Value); break; + case D3DRS_PRIMITIVERESETENABLE: D3DDevice_SetRenderState_PrimitiveResetEnable(pDevice, Value); break; + case D3DRS_PRIMITIVERESETINDEX: D3DDevice_SetRenderState_PrimitiveResetIndex(pDevice, Value); break; + case D3DRS_ALPHATOMASKENABLE: D3DDevice_SetRenderState_AlphaToMaskEnable(pDevice, Value); break; + case D3DRS_ALPHATOMASKOFFSETS: D3DDevice_SetRenderState_AlphaToMaskOffsets(pDevice, Value); break; + case D3DRS_GUARDBAND_X: D3DDevice_SetRenderState_GuardBand_X(pDevice, Value); break; + case D3DRS_GUARDBAND_Y: D3DDevice_SetRenderState_GuardBand_Y(pDevice, Value); break; + case D3DRS_DISCARDBAND_X: D3DDevice_SetRenderState_DiscardBand_X(pDevice, Value); break; + case D3DRS_DISCARDBAND_Y: D3DDevice_SetRenderState_DiscardBand_Y(pDevice, Value); break; + case D3DRS_HISTENCILENABLE: D3DDevice_SetRenderState_HiStencilEnable(pDevice, Value); break; + case D3DRS_HISTENCILWRITEENABLE: D3DDevice_SetRenderState_HiStencilWriteEnable(pDevice, Value); break; + case D3DRS_HISTENCILFUNC: D3DDevice_SetRenderState_HiStencilFunc(pDevice, Value); break; + case D3DRS_HISTENCILREF: D3DDevice_SetRenderState_HiStencilRef(pDevice, Value); break; + case D3DRS_PRESENTINTERVAL: D3DDevice_SetRenderState_PresentInterval(pDevice, Value); break; + case D3DRS_PRESENTIMMEDIATETHRESHOLD: D3DDevice_SetRenderState_PresentImmediateThreshold(pDevice, Value); break; + case D3DRS_HIZENABLE: D3DDevice_SetRenderState_HiZEnable(pDevice, Value); break; + case D3DRS_HIZWRITEENABLE: D3DDevice_SetRenderState_HiZWriteEnable(pDevice, Value); break; + case D3DRS_LASTPIXEL: D3DDevice_SetRenderState_LastPixel(pDevice, Value); break; + case D3DRS_LINEWIDTH: D3DDevice_SetRenderState_LineWidth(pDevice, Value); break; + case D3DRS_BUFFER2FRAMES: D3DDevice_SetRenderState_Buffer2Frames(pDevice, Value); break; + + #if defined(_DEBUG) + default: __debugbreak(); + #endif + } + } +} +D3DINLINE void D3DDevice_GetRenderState(__in D3DDevice* pDevice, D3DRENDERSTATETYPE State, __out DWORD* pValue) +{ + #if defined(_DEBUG) + D3DDevice_GetRenderState_ParameterCheck(pDevice, State); + #endif + + if (!D3DISINTCONST(State)) + { + // Getting the state uses a function pointer table that assumes + // the pointers are 4 bytes in size. The pointer arithemetic for + // State*(sizeof(ULONG_PTR)/sizeof(DWORD)) uses platform specific + // ULONG_PTR type, which is the size of pointer, that when compiled + // is either compiled away (when sizeof(ULONG_PTR)/sizeof(DWORD) == 1) + // or becomes the specific multiple of the byte size for a pointer + // on the specific platform to ensure proper incrementation of the + // GetState pointer. + + *pValue = (*(D3DGETRENDERSTATECALL*)(((BYTE*) &pDevice->m_GetRenderStateCall[0] + State*(sizeof(ULONG_PTR)/sizeof(DWORD)))))(pDevice); + } + else + { + switch (State) + { + case D3DRS_ZENABLE: *pValue = D3DDevice_GetRenderState_ZEnable(pDevice); break; + case D3DRS_ZFUNC: *pValue = D3DDevice_GetRenderState_ZFunc(pDevice); break; + case D3DRS_ZWRITEENABLE: *pValue = D3DDevice_GetRenderState_ZWriteEnable(pDevice); break; + case D3DRS_FILLMODE: *pValue = D3DDevice_GetRenderState_FillMode(pDevice); break; + case D3DRS_CULLMODE: *pValue = D3DDevice_GetRenderState_CullMode(pDevice); break; + case D3DRS_ALPHABLENDENABLE: *pValue = D3DDevice_GetRenderState_AlphaBlendEnable(pDevice); break; + case D3DRS_SEPARATEALPHABLENDENABLE: *pValue = D3DDevice_GetRenderState_SeparateAlphaBlendEnable(pDevice); break; + case D3DRS_BLENDFACTOR: *pValue = D3DDevice_GetRenderState_BlendFactor(pDevice); break; + case D3DRS_SRCBLEND: *pValue = D3DDevice_GetRenderState_SrcBlend(pDevice); break; + case D3DRS_DESTBLEND: *pValue = D3DDevice_GetRenderState_DestBlend(pDevice); break; + case D3DRS_BLENDOP: *pValue = D3DDevice_GetRenderState_BlendOp(pDevice); break; + case D3DRS_SRCBLENDALPHA: *pValue = D3DDevice_GetRenderState_SrcBlendAlpha(pDevice); break; + case D3DRS_DESTBLENDALPHA: *pValue = D3DDevice_GetRenderState_DestBlendAlpha(pDevice); break; + case D3DRS_BLENDOPALPHA: *pValue = D3DDevice_GetRenderState_BlendOpAlpha(pDevice); break; + case D3DRS_ALPHATESTENABLE: *pValue = D3DDevice_GetRenderState_AlphaTestEnable(pDevice); break; + case D3DRS_ALPHAREF: *pValue = D3DDevice_GetRenderState_AlphaRef(pDevice); break; + case D3DRS_ALPHAFUNC: *pValue = D3DDevice_GetRenderState_AlphaFunc(pDevice); break; + case D3DRS_STENCILENABLE: *pValue = D3DDevice_GetRenderState_StencilEnable(pDevice); break; + case D3DRS_TWOSIDEDSTENCILMODE: *pValue = D3DDevice_GetRenderState_TwoSidedStencilMode(pDevice); break; + case D3DRS_STENCILFAIL: *pValue = D3DDevice_GetRenderState_StencilFail(pDevice); break; + case D3DRS_STENCILZFAIL: *pValue = D3DDevice_GetRenderState_StencilZFail(pDevice); break; + case D3DRS_STENCILPASS: *pValue = D3DDevice_GetRenderState_StencilPass(pDevice); break; + case D3DRS_STENCILFUNC: *pValue = D3DDevice_GetRenderState_StencilFunc(pDevice); break; + case D3DRS_STENCILREF: *pValue = D3DDevice_GetRenderState_StencilRef(pDevice); break; + case D3DRS_STENCILMASK: *pValue = D3DDevice_GetRenderState_StencilMask(pDevice); break; + case D3DRS_STENCILWRITEMASK: *pValue = D3DDevice_GetRenderState_StencilWriteMask(pDevice); break; + case D3DRS_CCW_STENCILFAIL: *pValue = D3DDevice_GetRenderState_CCWStencilFail(pDevice); break; + case D3DRS_CCW_STENCILZFAIL: *pValue = D3DDevice_GetRenderState_CCWStencilZFail(pDevice); break; + case D3DRS_CCW_STENCILPASS: *pValue = D3DDevice_GetRenderState_CCWStencilPass(pDevice); break; + case D3DRS_CCW_STENCILFUNC: *pValue = D3DDevice_GetRenderState_CCWStencilFunc(pDevice); break; + case D3DRS_CCW_STENCILREF: *pValue = D3DDevice_GetRenderState_CCWStencilRef(pDevice); break; + case D3DRS_CCW_STENCILMASK: *pValue = D3DDevice_GetRenderState_CCWStencilMask(pDevice); break; + case D3DRS_CCW_STENCILWRITEMASK: *pValue = D3DDevice_GetRenderState_CCWStencilWriteMask(pDevice); break; + case D3DRS_CLIPPLANEENABLE: *pValue = D3DDevice_GetRenderState_ClipPlaneEnable(pDevice); break; + case D3DRS_POINTSIZE: *pValue = D3DDevice_GetRenderState_PointSize(pDevice); break; + case D3DRS_POINTSIZE_MIN: *pValue = D3DDevice_GetRenderState_PointSizeMin(pDevice); break; + case D3DRS_POINTSPRITEENABLE: *pValue = D3DDevice_GetRenderState_PointSpriteEnable(pDevice); break; + case D3DRS_POINTSIZE_MAX: *pValue = D3DDevice_GetRenderState_PointSizeMax(pDevice); break; + case D3DRS_MULTISAMPLEANTIALIAS: *pValue = D3DDevice_GetRenderState_MultiSampleAntiAlias(pDevice); break; + case D3DRS_MULTISAMPLEMASK: *pValue = D3DDevice_GetRenderState_MultiSampleMask(pDevice); break; + case D3DRS_SCISSORTESTENABLE: *pValue = D3DDevice_GetRenderState_ScissorTestEnable(pDevice); break; + case D3DRS_SLOPESCALEDEPTHBIAS: *pValue = D3DDevice_GetRenderState_SlopeScaleDepthBias(pDevice); break; + case D3DRS_DEPTHBIAS: *pValue = D3DDevice_GetRenderState_DepthBias(pDevice); break; + case D3DRS_COLORWRITEENABLE: *pValue = D3DDevice_GetRenderState_ColorWriteEnable(pDevice); break; + case D3DRS_COLORWRITEENABLE1: *pValue = D3DDevice_GetRenderState_ColorWriteEnable1(pDevice); break; + case D3DRS_COLORWRITEENABLE2: *pValue = D3DDevice_GetRenderState_ColorWriteEnable2(pDevice); break; + case D3DRS_COLORWRITEENABLE3: *pValue = D3DDevice_GetRenderState_ColorWriteEnable3(pDevice); break; + case D3DRS_TESSELLATIONMODE: *pValue = D3DDevice_GetRenderState_TessellationMode(pDevice); break; + case D3DRS_MINTESSELLATIONLEVEL: *pValue = D3DDevice_GetRenderState_MinTessellationLevel(pDevice); break; + case D3DRS_MAXTESSELLATIONLEVEL: *pValue = D3DDevice_GetRenderState_MaxTessellationLevel(pDevice); break; + case D3DRS_WRAP0: *pValue = D3DDevice_GetRenderState_Wrap0(pDevice); break; + case D3DRS_WRAP1: *pValue = D3DDevice_GetRenderState_Wrap1(pDevice); break; + case D3DRS_WRAP2: *pValue = D3DDevice_GetRenderState_Wrap2(pDevice); break; + case D3DRS_WRAP3: *pValue = D3DDevice_GetRenderState_Wrap3(pDevice); break; + case D3DRS_WRAP4: *pValue = D3DDevice_GetRenderState_Wrap4(pDevice); break; + case D3DRS_WRAP5: *pValue = D3DDevice_GetRenderState_Wrap5(pDevice); break; + case D3DRS_WRAP6: *pValue = D3DDevice_GetRenderState_Wrap6(pDevice); break; + case D3DRS_WRAP7: *pValue = D3DDevice_GetRenderState_Wrap7(pDevice); break; + case D3DRS_WRAP8: *pValue = D3DDevice_GetRenderState_Wrap8(pDevice); break; + case D3DRS_WRAP9: *pValue = D3DDevice_GetRenderState_Wrap9(pDevice); break; + case D3DRS_WRAP10: *pValue = D3DDevice_GetRenderState_Wrap10(pDevice); break; + case D3DRS_WRAP11: *pValue = D3DDevice_GetRenderState_Wrap11(pDevice); break; + case D3DRS_WRAP12: *pValue = D3DDevice_GetRenderState_Wrap12(pDevice); break; + case D3DRS_WRAP13: *pValue = D3DDevice_GetRenderState_Wrap13(pDevice); break; + case D3DRS_WRAP14: *pValue = D3DDevice_GetRenderState_Wrap14(pDevice); break; + case D3DRS_WRAP15: *pValue = D3DDevice_GetRenderState_Wrap15(pDevice); break; + case D3DRS_VIEWPORTENABLE: *pValue = D3DDevice_GetRenderState_ViewportEnable(pDevice); break; + case D3DRS_HIGHPRECISIONBLENDENABLE: *pValue = D3DDevice_GetRenderState_HighPrecisionBlendEnable(pDevice); break; + case D3DRS_HIGHPRECISIONBLENDENABLE1: *pValue = D3DDevice_GetRenderState_HighPrecisionBlendEnable1(pDevice); break; + case D3DRS_HIGHPRECISIONBLENDENABLE2: *pValue = D3DDevice_GetRenderState_HighPrecisionBlendEnable2(pDevice); break; + case D3DRS_HIGHPRECISIONBLENDENABLE3: *pValue = D3DDevice_GetRenderState_HighPrecisionBlendEnable3(pDevice); break; + case D3DRS_HALFPIXELOFFSET: *pValue = D3DDevice_GetRenderState_HalfPixelOffset(pDevice); break; + case D3DRS_PRIMITIVERESETENABLE: *pValue = D3DDevice_GetRenderState_PrimitiveResetEnable(pDevice); break; + case D3DRS_PRIMITIVERESETINDEX: *pValue = D3DDevice_GetRenderState_PrimitiveResetIndex(pDevice); break; + case D3DRS_ALPHATOMASKENABLE: *pValue = D3DDevice_GetRenderState_AlphaToMaskEnable(pDevice); break; + case D3DRS_ALPHATOMASKOFFSETS: *pValue = D3DDevice_GetRenderState_AlphaToMaskOffsets(pDevice); break; + case D3DRS_GUARDBAND_X: *pValue = D3DDevice_GetRenderState_GuardBand_X(pDevice); break; + case D3DRS_GUARDBAND_Y: *pValue = D3DDevice_GetRenderState_GuardBand_Y(pDevice); break; + case D3DRS_DISCARDBAND_X: *pValue = D3DDevice_GetRenderState_DiscardBand_X(pDevice); break; + case D3DRS_DISCARDBAND_Y: *pValue = D3DDevice_GetRenderState_DiscardBand_Y(pDevice); break; + case D3DRS_HISTENCILENABLE: *pValue = D3DDevice_GetRenderState_HiStencilEnable(pDevice); break; + case D3DRS_HISTENCILWRITEENABLE: *pValue = D3DDevice_GetRenderState_HiStencilWriteEnable(pDevice); break; + case D3DRS_HISTENCILFUNC: *pValue = D3DDevice_GetRenderState_HiStencilFunc(pDevice); break; + case D3DRS_HISTENCILREF: *pValue = D3DDevice_GetRenderState_HiStencilRef(pDevice); break; + case D3DRS_PRESENTINTERVAL: *pValue = D3DDevice_GetRenderState_PresentInterval(pDevice); break; + case D3DRS_PRESENTIMMEDIATETHRESHOLD: *pValue = D3DDevice_GetRenderState_PresentImmediateThreshold(pDevice); break; + case D3DRS_HIZENABLE: *pValue = D3DDevice_GetRenderState_HiZEnable(pDevice); break; + case D3DRS_HIZWRITEENABLE: *pValue = D3DDevice_GetRenderState_HiZWriteEnable(pDevice); break; + case D3DRS_LASTPIXEL: *pValue = D3DDevice_GetRenderState_LastPixel(pDevice); break; + case D3DRS_LINEWIDTH: *pValue = D3DDevice_GetRenderState_LineWidth(pDevice); break; + case D3DRS_BUFFER2FRAMES: *pValue = D3DDevice_GetRenderState_Buffer2Frames(pDevice); break; + + #if defined(_DEBUG) + default: __debugbreak(); + #endif + } + } +} + +D3DINLINE void D3DDevice_SetSamplerState(__in D3DDevice* pDevice, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) +{ + #if defined(_DEBUG) + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, Type, Value); + #endif + + // Note that D3DISINTCONST() always evaluates to a constant: + + if (!D3DISINTCONST(Type)) + { + // When 'Type' is passed in using a non-constant we avoid horrendous + // code bloat by calling through the jump table: + + // Setting the state uses a function pointer table that assumes + // the pointers are 4 bytes in size. The pointer arithemetic for + // Type*(sizeof(ULONG_PTR)/sizeof(DWORD)) uses platform specific + // ULONG_PTR type, which is the size of pointer, that when compiled + // is either compiled away (when sizeof(ULONG_PTR)/sizeof(DWORD) == 1) + // or becomes the specific multiple of the byte size for a pointer + // on the specific platform to ensure proper incrementation of the + // SetState pointer. + + (*(D3DSETSAMPLERSTATECALL*)(((BYTE*) &pDevice->m_SetSamplerStateCall[0] + Type*(sizeof(ULONG_PTR)/sizeof(DWORD)))))(pDevice, Sampler, Value); + } + else + { + // When 'Type' is passed in using a constant the optimizer can + // eliminate this entire switch statement: + + switch (Type) + { + case D3DSAMP_ADDRESSU: D3DDevice_SetSamplerState_AddressU_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_ADDRESSV: D3DDevice_SetSamplerState_AddressV_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_ADDRESSW: D3DDevice_SetSamplerState_AddressW_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_BORDERCOLOR: D3DDevice_SetSamplerState_BorderColor_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_MAGFILTER: D3DDevice_SetSamplerState_MagFilter(pDevice, Sampler, Value); break; + case D3DSAMP_MINFILTER: D3DDevice_SetSamplerState_MinFilter(pDevice, Sampler, Value); break; + case D3DSAMP_MIPFILTER: D3DDevice_SetSamplerState_MipFilter_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_MIPMAPLODBIAS: D3DDevice_SetSamplerState_MipMapLodBias(pDevice, Sampler, Value); break; + case D3DSAMP_MAXMIPLEVEL: D3DDevice_SetSamplerState_MaxMipLevel(pDevice, Sampler, Value); break; + case D3DSAMP_MAXANISOTROPY: D3DDevice_SetSamplerState_MaxAnisotropy(pDevice, Sampler, Value); break; + case D3DSAMP_MAGFILTERZ: D3DDevice_SetSamplerState_MagFilterZ(pDevice, Sampler, Value); break; + case D3DSAMP_MINFILTERZ: D3DDevice_SetSamplerState_MinFilterZ(pDevice, Sampler, Value); break; + case D3DSAMP_SEPARATEZFILTERENABLE: D3DDevice_SetSamplerState_SeparateZFilterEnable(pDevice, Sampler, Value); break; + case D3DSAMP_MINMIPLEVEL: D3DDevice_SetSamplerState_MinMipLevel(pDevice, Sampler, Value); break; + case D3DSAMP_TRILINEARTHRESHOLD: D3DDevice_SetSamplerState_TrilinearThreshold_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_ANISOTROPYBIAS: D3DDevice_SetSamplerState_AnisotropyBias(pDevice, Sampler, Value); break; + case D3DSAMP_HGRADIENTEXPBIAS: D3DDevice_SetSamplerState_HGradientExpBias_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_VGRADIENTEXPBIAS: D3DDevice_SetSamplerState_VGradientExpBias_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_WHITEBORDERCOLORW: D3DDevice_SetSamplerState_WhiteBorderColorW_Inline(pDevice, Sampler, Value); break; + case D3DSAMP_POINTBORDERENABLE: D3DDevice_SetSamplerState_PointBorderEnable_Inline(pDevice, Sampler, Value); break; + + #if defined(_DEBUG) + default: __debugbreak(); + #endif + } + } +} +D3DINLINE void D3DDevice_GetSamplerState(__in D3DDevice* pDevice, DWORD Sampler, D3DSAMPLERSTATETYPE Type, __out DWORD *pValue) +{ + #if defined(_DEBUG) + D3DDevice_GetSamplerState_ParameterCheck(pDevice, Sampler, Type); + #endif + + if (!D3DISINTCONST(Type)) + { + // Getting the state uses a function pointer table that assumes + // the pointers are 4 bytes in size. The pointer arithemetic for + // Type*(sizeof(ULONG_PTR)/sizeof(DWORD)) uses platform specific + // ULONG_PTR type, which is the size of pointer, that when compiled + // is either compiled away (when sizeof(ULONG_PTR)/sizeof(DWORD) == 1) + // or becomes the specific multiple of the byte size for a pointer + // on the specific platform to ensure proper incrementation of the + // GetState pointer. + + *pValue = (*(D3DGETSAMPLERSTATECALL*)(((BYTE*) &pDevice->m_GetSamplerStateCall[0] + Type*(sizeof(ULONG_PTR)/sizeof(DWORD)))))(pDevice, Sampler); + } + else + { + switch (Type) + { + case D3DSAMP_ADDRESSU: *pValue = D3DDevice_GetSamplerState_AddressU(pDevice, Sampler); break; + case D3DSAMP_ADDRESSV: *pValue = D3DDevice_GetSamplerState_AddressV(pDevice, Sampler); break; + case D3DSAMP_ADDRESSW: *pValue = D3DDevice_GetSamplerState_AddressW(pDevice, Sampler); break; + case D3DSAMP_BORDERCOLOR: *pValue = D3DDevice_GetSamplerState_BorderColor(pDevice, Sampler); break; + case D3DSAMP_MAGFILTER: *pValue = D3DDevice_GetSamplerState_MagFilter(pDevice, Sampler); break; + case D3DSAMP_MINFILTER: *pValue = D3DDevice_GetSamplerState_MinFilter(pDevice, Sampler); break; + case D3DSAMP_MIPFILTER: *pValue = D3DDevice_GetSamplerState_MipFilter(pDevice, Sampler); break; + case D3DSAMP_MIPMAPLODBIAS: *pValue = D3DDevice_GetSamplerState_MipMapLodBias(pDevice, Sampler); break; + case D3DSAMP_MAXMIPLEVEL: *pValue = D3DDevice_GetSamplerState_MaxMipLevel(pDevice, Sampler); break; + case D3DSAMP_MAXANISOTROPY: *pValue = D3DDevice_GetSamplerState_MaxAnisotropy(pDevice, Sampler); break; + case D3DSAMP_MAGFILTERZ: *pValue = D3DDevice_GetSamplerState_MagFilterZ(pDevice, Sampler); break; + case D3DSAMP_MINFILTERZ: *pValue = D3DDevice_GetSamplerState_MinFilterZ(pDevice, Sampler); break; + case D3DSAMP_SEPARATEZFILTERENABLE: *pValue = D3DDevice_GetSamplerState_SeparateZFilterEnable(pDevice, Sampler); break; + case D3DSAMP_MINMIPLEVEL: *pValue = D3DDevice_GetSamplerState_MinMipLevel(pDevice, Sampler); break; + case D3DSAMP_TRILINEARTHRESHOLD: *pValue = D3DDevice_GetSamplerState_TrilinearThreshold(pDevice, Sampler); break; + case D3DSAMP_ANISOTROPYBIAS: *pValue = D3DDevice_GetSamplerState_AnisotropyBias(pDevice, Sampler); break; + case D3DSAMP_HGRADIENTEXPBIAS: *pValue = D3DDevice_GetSamplerState_HGradientExpBias(pDevice, Sampler); break; + case D3DSAMP_VGRADIENTEXPBIAS: *pValue = D3DDevice_GetSamplerState_VGradientExpBias(pDevice, Sampler); break; + case D3DSAMP_WHITEBORDERCOLORW: *pValue = D3DDevice_GetSamplerState_WhiteBorderColorW(pDevice, Sampler); break; + case D3DSAMP_POINTBORDERENABLE: *pValue = D3DDevice_GetSamplerState_PointBorderEnable(pDevice, Sampler); break; + + #if defined(_DEBUG) + default: __debugbreak(); + #endif + } + } +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerAddressStates(__in D3DDevice* pDevice, DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW) +{ + #if defined(_DEBUG) + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_ADDRESSU, AddressU); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_ADDRESSV, AddressV); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_ADDRESSW, AddressW); + #endif + + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].ClampX = (GPUCLAMP)AddressU; + pDevice->m_Constants.TextureFetch[Sampler].ClampY = (GPUCLAMP)AddressV; + pDevice->m_Constants.TextureFetch[Sampler].ClampZ = (GPUCLAMP)AddressW; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerBorderStates(__in D3DDevice* pDevice, DWORD Sampler, DWORD BorderColor, DWORD WhiteBorderColorW, DWORD PointBorderEnable) +{ + #if defined(_DEBUG) + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_BORDERCOLOR, BorderColor); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_WHITEBORDERCOLORW, WhiteBorderColorW); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_POINTBORDERENABLE, PointBorderEnable); + #endif + + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].BorderColor = (BorderColor == 0) ? GPUBORDERCOLOR_ABGR_BLACK : GPUBORDERCOLOR_ABGR_WHITE; + pDevice->m_Constants.TextureFetch[Sampler].ForceBCWToMax = WhiteBorderColorW; + pDevice->m_Constants.TextureFetch[Sampler].ClampPolicy = (GPUCLAMPPOLICY)!PointBorderEnable; + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerSeparateZFilterStates(__in D3DDevice* pDevice, DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MinFilterZ, DWORD MagFilterZ, DWORD MaxAnisotropy) +{ + static CONST GPUANISOFILTER anisoFilterMap[] = + { + GPUANISOFILTER_DISABLED, // 0 + GPUANISOFILTER_DISABLED, // 1 + GPUANISOFILTER_MAX2TO1, // 2 + GPUANISOFILTER_MAX2TO1, // 3 + GPUANISOFILTER_MAX4TO1, // 4 + GPUANISOFILTER_MAX4TO1, // 5 + GPUANISOFILTER_MAX4TO1, // 6 + GPUANISOFILTER_MAX8TO1, // 7 + GPUANISOFILTER_MAX8TO1, // 8 + GPUANISOFILTER_MAX8TO1, // 9 + GPUANISOFILTER_MAX8TO1, // 10 + GPUANISOFILTER_MAX8TO1, // 11 + GPUANISOFILTER_MAX8TO1, // 12 + GPUANISOFILTER_MAX16TO1, // 13 + GPUANISOFILTER_MAX16TO1, // 14 + GPUANISOFILTER_MAX16TO1, // 15 + GPUANISOFILTER_MAX16TO1, // 16 + }; + + #if defined(_DEBUG) + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MINFILTER, MinFilter); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MAGFILTER, MagFilter); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MIPFILTER, MipFilter); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MINFILTERZ, MinFilterZ); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MAGFILTERZ, MagFilterZ); + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MAXANISOTROPY, MaxAnisotropy); + #endif + + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pDevice->m_Constants.TextureFetch[Sampler].MinFilter = (MinFilter == D3DTEXF_ANISOTROPIC) ? D3DTEXF_LINEAR : MinFilter; + pDevice->m_Constants.TextureFetch[Sampler].MagFilter = (MagFilter == D3DTEXF_ANISOTROPIC)? D3DTEXF_LINEAR : MagFilter; + pDevice->m_Constants.TextureFetch[Sampler].MipFilter = MipFilter; + pDevice->m_Constants.TextureFetch[Sampler].VolMinFilter = MinFilterZ; + pDevice->m_Constants.TextureFetch[Sampler].VolMagFilter = MagFilterZ; + pDevice->m_Constants.TextureFetch[Sampler].MinAnisoWalk = (DWORD)(MinFilter == D3DTEXF_ANISOTROPIC); + pDevice->m_Constants.TextureFetch[Sampler].MagAnisoWalk = (DWORD)(MagFilter == D3DTEXF_ANISOTROPIC); + pDevice->m_Constants.TextureFetch[Sampler].AnisoFilter = (MinFilter == D3DTEXF_ANISOTROPIC || MagFilter == D3DTEXF_ANISOTROPIC) ? anisoFilterMap[MaxAnisotropy] : GPUANISOFILTER_DISABLED; + + pDevice->m_MaxAnisotropy[Sampler] = (BYTE)MaxAnisotropy; + pDevice->m_ZFilter[Sampler] = (BYTE)(4 | (MinFilterZ << 1) | MagFilterZ); + + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_TEXTUREFETCHCONSTANTS), D3DTag_SamplerMask(Sampler)); +} + +D3DINLINE void WINAPI D3DDevice_SetSamplerFilterStates(__in D3DDevice* pDevice, DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MaxAnisotropy) +{ + DWORD minFilterZ = (MinFilter == D3DTEXF_ANISOTROPIC) ? D3DTEXF_LINEAR : MinFilter; + DWORD magFilterZ = (MagFilter == D3DTEXF_ANISOTROPIC) ? D3DTEXF_LINEAR : MagFilter; + BYTE oldZFilter = pDevice->m_ZFilter[Sampler]; + D3DDevice_SetSamplerSeparateZFilterStates(pDevice, Sampler, MinFilter, MagFilter, MipFilter, minFilterZ, magFilterZ, MaxAnisotropy); + pDevice->m_ZFilter[Sampler] = (BYTE)(oldZFilter & ~4); +} + +// Fast deferred shader constant setting + +D3DINLINE void D3DDevice_BeginVertexShaderConstantF1(__in D3DDevice* pDevice, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount) +{ + #if defined(_DEBUG) + D3DDevice_BeginShaderConstantF1_ParameterCheck(pDevice, FALSE, StartRegister, Vector4fCount); + #endif + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_VERTEXSHADERCONSTANTS), D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); + *ppConstantData = &pDevice->m_Constants.VertexShaderF[StartRegister]; +} +D3DINLINE void D3DDevice_BeginPixelShaderConstantF1(__in D3DDevice* pDevice, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount) +{ + #if defined(_DEBUG) + D3DDevice_BeginShaderConstantF1_ParameterCheck(pDevice, TRUE, StartRegister, Vector4fCount); + #endif + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_PIXELSHADERCONSTANTS), D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); + *ppConstantData = &pDevice->m_Constants.PixelShaderF[StartRegister]; +} +D3DINLINE void D3DDevice_EndShaderConstantF1(__in D3DDevice* pDevice) +{ + #if defined(_DEBUG) + D3DDevice_EndShaderConstantF1_ParameterCheck(pDevice); + #endif +} +D3DINLINE void D3DDevice_EndShaderConstantF4(__in D3DDevice* pDevice) +{ + #if defined(_DEBUG) + D3DDevice_EndShaderConstantF4_ParameterCheck(pDevice); + #endif +} + +// The following two inline routines are automatically called by the corresponding +// SetVertexShaderConstantF/SetPixelShaderConstantF APIs. + +D3DINLINE void D3DDevice_SetVertexShaderConstantF1(__in D3DDevice* pDevice, UINT StartRegister, __in_ecount(4) CONST float* D3DRESTRICT pConstantData) +{ +#if defined(_DEBUG) + D3DDevice_SetVertexShaderConstantF_ParameterCheck(pDevice, StartRegister, pConstantData, 1); +#endif + // Copy into D3D's shadow state. Note that by copying a dword at a + // time, we let the optimizer recognize and remove redundant copies. + // That wouldn't be true if we used a vector copy. For example, + // this lets the compiler optimize the following so that the temporary + // store to the stack is completely eliminated from a sequence such + // as the following: + // + // float vector[4] = { x, y, z, w }; + // pDevice->SetVertexShaderConstantF(Register, vector, 1); + + D3DVECTOR4_SetX(&pDevice->m_Constants.VertexShaderF[StartRegister], pConstantData[0]); + D3DVECTOR4_SetY(&pDevice->m_Constants.VertexShaderF[StartRegister], pConstantData[1]); + D3DVECTOR4_SetZ(&pDevice->m_Constants.VertexShaderF[StartRegister], pConstantData[2]); + D3DVECTOR4_SetW(&pDevice->m_Constants.VertexShaderF[StartRegister], pConstantData[3]); + + // Let D3D know that the constants were set: + + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_VERTEXSHADERCONSTANTS), D3DTag_ShaderConstantMask(StartRegister, 1)); +} +D3DINLINE void D3DDevice_SetPixelShaderConstantF1(D3DDevice* D3DRESTRICT pDevice, UINT StartRegister, __in_ecount(4) CONST float* D3DRESTRICT pConstantData) +{ +#if defined(_DEBUG) + D3DDevice_SetPixelShaderConstantF_ParameterCheck(pDevice, StartRegister, pConstantData, 1); +#endif + + D3DVECTOR4_SetX(&pDevice->m_Constants.PixelShaderF[StartRegister], pConstantData[0]); + D3DVECTOR4_SetY(&pDevice->m_Constants.PixelShaderF[StartRegister], pConstantData[1]); + D3DVECTOR4_SetZ(&pDevice->m_Constants.PixelShaderF[StartRegister], pConstantData[2]); + D3DVECTOR4_SetW(&pDevice->m_Constants.PixelShaderF[StartRegister], pConstantData[3]); + + D3DTagCollection_Set(&pDevice->m_Pending, D3DTag_Index(D3DTAG_PIXELSHADERCONSTANTS), D3DTag_ShaderConstantMask(StartRegister, 1)); +} + +// The following two inline routines are automatically called by the +// corresponding SetVertexShaderConstantF/SetPixelShaderConstantF routines. +// They special-case a count of "1" since that's typically the most frequent +// count specified, and inlining can reduce copies and avoid load-hit-store +// stalls. +// +// Note that all the conditionals here get compiled away by the optimizer. + +D3DINLINE void D3DDevice_SetVertexShaderConstantF(__in D3DDevice* pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) +{ + if (D3DISINTCONST(Vector4fCount)) + { + if (Vector4fCount == 1) + { + D3DDevice_SetVertexShaderConstantF1(pDevice, StartRegister, pConstantData); + } + else + { + D3DDevice_SetVertexShaderConstantFN(pDevice, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); + } + } + else + { + D3DDevice_SetVertexShaderConstantFN(pDevice, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); + } +} + +D3DINLINE void D3DDevice_SetPixelShaderConstantF(__in D3DDevice* pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) +{ + if (D3DISINTCONST(Vector4fCount)) + { + if (Vector4fCount == 1) + { + D3DDevice_SetPixelShaderConstantF1(pDevice, StartRegister, pConstantData); + } + else + { + D3DDevice_SetPixelShaderConstantFN(pDevice, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); + } + } + else + { + D3DDevice_SetPixelShaderConstantFN(pDevice, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); + } +} + +// Unbuffered Graphics support + +D3DINLINE void D3DDevice_GpuOwn(__in D3DDevice* pDevice, D3DTAG Tag) +{ + DWORD index = D3DTag_Index(Tag); + UINT64 mask = D3DTag_Mask(Tag); + + #if defined(_DEBUG) + D3DDevice_GpuOwn_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Clear(&pDevice->m_Pending, index, mask); + +} +D3DINLINE void D3DDevice_GpuOwnSubset(__in D3DDevice* pDevice, D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) +{ + DWORD index = D3DTag_Index(Tag); + UINT64 mask = D3DTag_SubsetMask(Tag, StartIndex, EndIndex); + + #if defined(_DEBUG) + D3DDevice_GpuOwn_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Clear(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuOwnVertexShaderConstantF(__in D3DDevice* pDevice, DWORD StartRegister, DWORD Vector4fCount) +{ + DWORD index = D3DTag_Index(D3DTAG_VERTEXSHADERCONSTANTS); + UINT64 mask = D3DTag_ShaderConstantMask(StartRegister, Vector4fCount); + + #if defined(_DEBUG) + D3DDevice_GpuOwn_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Clear(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuOwnPixelShaderConstantF(__in D3DDevice* pDevice, DWORD StartRegister, DWORD Vector4fCount) +{ + DWORD index = D3DTag_Index(D3DTAG_PIXELSHADERCONSTANTS); + UINT64 mask = D3DTag_ShaderConstantMask(StartRegister, Vector4fCount); + + #if defined(_DEBUG) + D3DDevice_GpuOwn_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Clear(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuOwnShaders(__in D3DDevice* pDevice) +{ + D3DDevice_GpuOwn(pDevice, D3DTAG_VERTEXSHADER); + D3DDevice_GpuOwn(pDevice, D3DTAG_PIXELSHADER); + D3DDevice_GpuOwn(pDevice, D3DTAG_PROGRAMCONTROL); + D3DDevice_GpuOwn(pDevice, D3DTAG_FLOWCONSTANTS); + D3DDevice_GpuOwn(pDevice, D3DTAG_CONTEXTMISC); + D3DDevice_GpuOwn(pDevice, D3DTAG_INTERPOLATORCONTROL); + D3DDevice_GpuOwn(pDevice, D3DTAG_EDRAMMODECONTROL); + + D3DDevice_SetVertexShader(pDevice, NULL); +} + +D3DINLINE void D3DDevice_GpuDisown(__in D3DDevice* pDevice, D3DTAG Tag) +{ + DWORD index = D3DTag_Index(Tag); + UINT64 mask = D3DTag_Mask(Tag); + #if defined(_DEBUG) + D3DDevice_GpuDisown_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Set(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuDisownSubset(__in D3DDevice* pDevice, D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) +{ + DWORD index = D3DTag_Index(Tag); + UINT64 mask = D3DTag_SubsetMask(Tag, StartIndex, EndIndex); + + #if defined(_DEBUG) + D3DDevice_GpuDisown_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Set(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuDisownVertexShaderConstantF(__in D3DDevice* pDevice, DWORD StartRegister, DWORD Vector4fCount) +{ + DWORD index = D3DTag_Index(D3DTAG_VERTEXSHADERCONSTANTS); + UINT64 mask = D3DTag_ShaderConstantMask(StartRegister, Vector4fCount); + + #if defined(_DEBUG) + D3DDevice_GpuDisown_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Set(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuDisownPixelShaderConstantF(__in D3DDevice* pDevice, DWORD StartRegister, DWORD Vector4fCount) +{ + DWORD index = D3DTag_Index(D3DTAG_PIXELSHADERCONSTANTS); + UINT64 mask = D3DTag_ShaderConstantMask(StartRegister, Vector4fCount); + + #if defined(_DEBUG) + D3DDevice_GpuDisown_ParameterCheck(pDevice, index, mask); + #endif + + D3DTagCollection_Set(&pDevice->m_Pending, index, mask); +} +D3DINLINE void D3DDevice_GpuDisownShaders(__in D3DDevice* pDevice) +{ + D3DDevice_GpuDisown(pDevice, D3DTAG_VERTEXSHADER); + D3DDevice_GpuDisown(pDevice, D3DTAG_PIXELSHADER); + D3DDevice_GpuDisown(pDevice, D3DTAG_PROGRAMCONTROL); + D3DDevice_GpuDisown(pDevice, D3DTAG_FLOWCONSTANTS); + D3DDevice_GpuDisown(pDevice, D3DTAG_CONTEXTMISC); + D3DDevice_GpuDisown(pDevice, D3DTAG_INTERPOLATORCONTROL); + D3DDevice_GpuDisown(pDevice, D3DTAG_EDRAMMODECONTROL); +} + +D3DINLINE void D3DDevice_GpuEndShaderConstantF4(__in D3DDevice* pDevice) +{ + #if defined(_DEBUG) + D3DDevice_GpuEndShaderConstantF4_ParameterCheck(pDevice); + #endif +} + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3DDevice9_AddRef(__in D3DDevice *pThis) { return D3DDevice_AddRef(pThis); } +D3DINLINE ULONG WINAPI IDirect3DDevice9_Release(__in D3DDevice *pThis) { return D3DDevice_Release(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetDirect3D(__in D3DDevice *pThis, __deref_out Direct3D **ppD3D9) { D3DDevice_GetDirect3D(pThis, ppD3D9); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetDeviceCaps(__in D3DDevice *pThis, __out D3DCAPS9 *pCaps) { D3DDevice_GetDeviceCaps(pThis, pCaps); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetDisplayMode(__in D3DDevice *pThis, UINT UnusedSwapChain, __out D3DDISPLAYMODE *pMode) { D3DDevice_GetDisplayMode(pThis, UnusedSwapChain, pMode); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetCreationParameters(__in D3DDevice *pThis, __out D3DDEVICE_CREATION_PARAMETERS *pParameters) { D3DDevice_GetCreationParameters(pThis, pParameters); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_Reset(__in D3DDevice *pThis, __in D3DPRESENT_PARAMETERS *pPresentationParameters) { return D3DDevice_Reset(pThis, pPresentationParameters); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Present(__in D3DDevice *pThis, __in_opt CONST RECT *pUnusedSourceRect, __in_opt CONST RECT *pUnusedDestRect, __in_opt void *hUnusedDestWindowOverride, __in_opt void *pUnusedDirtyRegion) { D3DDevice_Present(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetRasterStatus(__in D3DDevice *pThis, UINT iUnusedSwapChain, __out D3DRASTER_STATUS *pRasterStatus) { D3DDevice_GetRasterStatus(pThis, pRasterStatus); D3DVOIDRETURN; } +D3DINLINE void WINAPI IDirect3DDevice9_SetGammaRamp(__in D3DDevice *pThis, UINT iUnusedSwapChain, DWORD UnusedFlags, __in CONST D3DGAMMARAMP *pRamp) { D3DDevice_SetGammaRamp(pThis, UnusedFlags, pRamp); } +D3DINLINE void WINAPI IDirect3DDevice9_GetGammaRamp(__in D3DDevice *pThis, UINT iUnusedSwapChain, __out D3DGAMMARAMP *pRamp) { D3DDevice_GetGammaRamp(pThis, pRamp); } +D3DINLINE void WINAPI IDirect3DDevice9_SetPWLGamma(__in D3DDevice *pThis, DWORD Flags, __in CONST D3DPWLGAMMA *pRamp) { D3DDevice_SetPWLGamma(pThis, Flags, pRamp); } +D3DINLINE void WINAPI IDirect3DDevice9_GetPWLGamma(__in D3DDevice *pThis, __out D3DPWLGAMMA *pRamp) { D3DDevice_GetPWLGamma(pThis, pRamp); } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateTexture(__in D3DDevice *pThis, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DTexture **ppTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppTexture = (D3DTexture*) D3DDevice_CreateTexture(Width, Height, 1, Levels, Usage, Format, UnusedPool, D3DRTYPE_TEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateVolumeTexture(__in D3DDevice *pThis, UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DVolumeTexture **ppVolumeTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppVolumeTexture = (D3DVolumeTexture*) D3DDevice_CreateTexture(Width, Height, Depth, Levels, Usage, Format, UnusedPool, D3DRTYPE_VOLUMETEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateCubeTexture(__in D3DDevice *pThis, UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DCubeTexture **ppCubeTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppCubeTexture = (D3DCubeTexture*) D3DDevice_CreateTexture(EdgeLength, EdgeLength, 6, Levels, Usage, Format, UnusedPool, D3DRTYPE_CUBETEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateArrayTexture(__in D3DDevice *pThis, UINT Width, UINT Height, UINT ArraySize, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DArrayTexture **ppArrayTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppArrayTexture = (D3DArrayTexture*) D3DDevice_CreateTexture(Width, Height, ArraySize, Levels, Usage, Format, UnusedPool, D3DRTYPE_ARRAYTEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateLineTexture(__in D3DDevice *pThis, UINT Width, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DLineTexture **ppTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppTexture = (D3DLineTexture*) D3DDevice_CreateTexture(Width, 1, 1, Levels, Usage, Format, UnusedPool, D3DRTYPE_LINETEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateVertexBuffer(__in D3DDevice *pThis, UINT Length, DWORD Usage, DWORD UnusedFVF, D3DPOOL UnusedPool, __deref_out D3DVertexBuffer **ppVertexBuffer, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppVertexBuffer = D3DDevice_CreateVertexBuffer(Length, Usage, UnusedPool)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateIndexBuffer(__in D3DDevice *pThis, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DIndexBuffer **ppIndexBuffer, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppIndexBuffer = D3DDevice_CreateIndexBuffer(Length, Usage, Format, UnusedPool)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateVertexDeclaration(__in D3DDevice* pThis, __in CONST D3DVERTEXELEMENT9* pVertexElements, __deref_out D3DVertexDeclaration **ppVertexDeclaration) { return (*ppVertexDeclaration = D3DDevice_CreateVertexDeclaration(pVertexElements)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateRenderTarget(__in D3DDevice *pThis, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD UnusedMultisampleQuality, BOOL UnusedLockable, __deref_out D3DSurface **ppSurface, __in_opt CONST D3DSURFACE_PARAMETERS* pParameters) { return (*ppSurface = D3DDevice_CreateSurface(Width, Height, Format, MultiSample, pParameters)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateDepthStencilSurface(__in D3DDevice *pThis, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD UnusedMultisampleQuality, BOOL UnusedDiscard, __deref_out D3DSurface **ppSurface, __in_opt CONST D3DSURFACE_PARAMETERS* pParameters) { return (*ppSurface = D3DDevice_CreateSurface(Width, Height, Format, MultiSample, pParameters)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetRenderTarget(__in D3DDevice *pThis, DWORD RenderTargetIndex, __in_opt D3DSurface *pRenderTarget) { D3DDevice_SetRenderTarget_External(pThis, RenderTargetIndex, pRenderTarget); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GetRenderTarget(__in D3DDevice *pThis, DWORD RenderTargetIndex, __deref_out D3DSurface **ppRenderTarget) { return (*ppRenderTarget = D3DDevice_GetRenderTarget(pThis, RenderTargetIndex)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetDepthStencilSurface(__in D3DDevice *pThis, __in_opt D3DSurface *pZStencilSurface) { D3DDevice_SetDepthStencilSurface(pThis, pZStencilSurface); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GetDepthStencilSurface(__in D3DDevice *pThis, __deref_out D3DSurface **ppZStencilSurface) { return (*ppZStencilSurface = D3DDevice_GetDepthStencilSurface(pThis)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GetBackBuffer(__in D3DDevice *pThis, UINT UnusedSwapChain, UINT iUnusedBackBuffer, UINT UnusedType, __deref_out D3DSurface **ppBackBuffer) { return (*ppBackBuffer = D3DDevice_GetBackBuffer(pThis)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GetFrontBuffer(__in D3DDevice *pThis, __deref_out D3DTexture **ppFrontBuffer) { return (*ppFrontBuffer = D3DDevice_GetFrontBuffer(pThis)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginScene(__in D3DDevice *pThis) { D3DDevice_BeginScene(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndScene(__in D3DDevice *pThis) { D3DDevice_EndScene(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Clear(__in D3DDevice *pThis, DWORD Count, __in_opt CONST D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) { D3DDevice_Clear(pThis, Count, pRects, Flags, Color, Z, Stencil, FALSE); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_ClearF(__in D3DDevice *pThis, DWORD Flags, __in_opt CONST D3DRECT *pRect, __in_opt CONST D3DVECTOR4* pColor, float Z, DWORD Stencil) { D3DDevice_ClearF(pThis, Flags, pRect, pColor, Z, Stencil); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SynchronizeToPresentationInterval(__in D3DDevice *pThis) { D3DDevice_SynchronizeToPresentationInterval(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Swap(__in D3DDevice *pThis, __in D3DBaseTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters) { D3DDevice_Swap(pThis, pFrontBuffer, pParameters); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_RenderSystemUI(__in D3DDevice *pThis) { D3DDevice_RenderSystemUI(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_QueryBufferSpace(__in D3DDevice* pDevice, __out DWORD* pUsed, __out DWORD* pRemaining) { D3DDevice_QueryBufferSpace(pDevice, pUsed, pRemaining); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPredication(__in D3DDevice* pDevice, DWORD PredicationMask) { D3DDevice_SetPredication(pDevice, PredicationMask); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPatchablePredication(__in D3DDevice* pDevice, DWORD PredicationMask, DWORD Identifier) { D3DDevice_SetPatchablePredication(pDevice, PredicationMask, Identifier); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginTiling(__in D3DDevice* pDevice, DWORD Flags, DWORD Count, __in_ecount(Count) CONST D3DRECT* pTileRects, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil) { D3DDevice_BeginTiling(pDevice, Flags, Count, pTileRects, pClearColor, ClearZ, ClearStencil); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_EndTiling(__in D3DDevice* pDevice, DWORD ResolveFlags, __in_opt CONST D3DRECT* pResolveRects, __in_opt D3DBaseTexture* pDestTexture, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters) { return D3DDevice_EndTiling(pDevice, ResolveFlags, pResolveRects, pDestTexture, pClearColor, ClearZ, ClearStencil, pParameters); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginZPass(__in D3DDevice* pDevice, DWORD Flags) { D3DDevice_BeginZPass(pDevice, Flags); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_EndZPass(__in D3DDevice* pDevice) { return D3DDevice_EndZPass(pDevice); } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_InvokeRenderPass(__in D3DDevice* pDevice) { return D3DDevice_InvokeRenderPass(pDevice); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginExport(__in D3DDevice* pDevice, DWORD Index, __in D3DResource* pResource, DWORD Flags) { D3DDevice_BeginExport(pDevice, Index, pResource, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndExport(__in D3DDevice* pDevice, DWORD Index, __in D3DResource* pResource, DWORD Flags) { D3DDevice_EndExport(pDevice, Index, pResource, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetViewport(__in D3DDevice *pThis, __in CONST D3DVIEWPORT9 *pViewport) { D3DDevice_SetViewport(pThis, pViewport); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetViewport(__in D3DDevice *pThis, __out D3DVIEWPORT9 *pViewport) { D3DDevice_GetViewport(pThis, pViewport); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetRenderState(__in D3DDevice *pThis, D3DRENDERSTATETYPE State, DWORD Value) { D3DDevice_SetRenderState(pThis, State, Value); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetRenderState_Inline(__in D3DDevice *pThis, D3DRENDERSTATETYPE State, DWORD Value) { D3DDevice_SetRenderState(pThis, State, Value); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetRenderState(__in D3DDevice *pThis, D3DRENDERSTATETYPE State, __out DWORD *pValue) { D3DDevice_GetRenderState(pThis, State, pValue); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateStateBlock(__in D3DDevice *pThis, D3DSTATEBLOCKTYPE Type, __deref_out D3DStateBlock** ppSB) { return (*ppSB = D3DDevice_CreateStateBlock(pThis, Type)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetTexture(__in D3DDevice *pThis, DWORD Sampler, __deref_out D3DBaseTexture **ppTexture) { *ppTexture = D3DDevice_GetTexture(pThis, Sampler); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetTexture(__in D3DDevice *pThis, DWORD Sampler, __in_opt D3DBaseTexture *pTexture) { D3DDevice_SetTexture_Inline(pThis, Sampler, pTexture); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetSamplerState(__in D3DDevice *pThis, DWORD Sampler, D3DSAMPLERSTATETYPE Type, __out DWORD* pValue) { D3DDevice_GetSamplerState(pThis, Sampler, Type, pValue); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSamplerState(__in D3DDevice *pThis, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) { D3DDevice_SetSamplerState(pThis, Sampler, Type, Value); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSamplerState_Inline(__in D3DDevice *pThis, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) { D3DDevice_SetSamplerState(pThis, Sampler, Type, Value); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSamplerAddressStates(__in D3DDevice *pThis, DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW) { D3DDevice_SetSamplerAddressStates(pThis, Sampler, AddressU, AddressV, AddressW); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSamplerBorderStates(__in D3DDevice *pThis, DWORD Sampler, DWORD BorderColor, DWORD WhiteBorderColorW, DWORD PointBorderEnable) { D3DDevice_SetSamplerBorderStates(pThis, Sampler, BorderColor, WhiteBorderColorW, PointBorderEnable); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSamplerSeparateZFilterStates(__in D3DDevice *pThis, DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MinFilterZ, DWORD MagFilterZ, DWORD MaxAnisotropy) { D3DDevice_SetSamplerSeparateZFilterStates(pThis, Sampler, MinFilter, MagFilter, MipFilter, MinFilterZ, MagFilterZ, MaxAnisotropy); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSamplerFilterStates(__in D3DDevice *pThis, DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MaxAnisotropy) { D3DDevice_SetSamplerFilterStates(pThis, Sampler, MinFilter, MagFilter, MipFilter, MaxAnisotropy); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawVertices(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT VertexCount) { D3DDevice_DrawVertices(pThis, PrimitiveType, StartVertex, VertexCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawIndexedVertices(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT IndexCount) { D3DDevice_DrawIndexedVertices(pThis, PrimitiveType, BaseVertexIndex, StartIndex, IndexCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawVerticesUP(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawVerticesUP(pThis, PrimitiveType, VertexCount, pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawIndexedVerticesUP(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT IndexCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawIndexedVerticesUP(pThis, PrimitiveType, MinVertexIndex, NumVertices, IndexCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawPrimitive(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) { D3DDevice_DrawVertices(pThis, PrimitiveType, StartVertex, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawIndexedPrimitive(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT UnusedMinIndex, UINT UnusedNumIndices, UINT StartIndex, UINT PrimitiveCount) { D3DDevice_DrawIndexedVertices(pThis, PrimitiveType, BaseVertexIndex, StartIndex, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawPrimitiveUP(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawVerticesUP(pThis, PrimitiveType, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount), pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawIndexedPrimitiveUP(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT PrimitiveCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawIndexedVerticesUP(pThis, PrimitiveType, MinIndex, NumVertices, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount), pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexDeclaration(__in D3DDevice *pThis, __in_opt D3DVertexDeclaration *pDecl) { D3DDevice_SetVertexDeclaration(pThis, pDecl); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetVertexDeclaration(__in D3DDevice *pThis, __deref_out D3DVertexDeclaration **ppDecl) { *ppDecl = D3DDevice_GetVertexDeclaration(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetScissorRect(__in D3DDevice *pThis, __in CONST RECT* pRect) { D3DDevice_SetScissorRect(pThis, pRect); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetScissorRect(__in D3DDevice *pThis, __out RECT* pRect) { D3DDevice_GetScissorRect(pThis, pRect); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetFVF(__in D3DDevice *pThis, DWORD FVF) { D3DDevice_SetFVF(pThis, FVF); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetFVF(__in D3DDevice *pThis, __out DWORD* pFVF) { *pFVF = D3DDevice_GetFVF(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateVertexShader(__in D3DDevice *pThis, __in CONST DWORD *pFunction, __deref_out D3DVertexShader** ppShader) { return (*ppShader = D3DDevice_CreateVertexShader(pFunction)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexShader(__in D3DDevice *pThis, __in_opt D3DVertexShader *pShader) { D3DDevice_SetVertexShader(pThis, pShader); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetVertexShader(__in D3DDevice *pThis, __deref_out D3DVertexShader **ppShader) { D3DDevice_GetVertexShader(pThis, ppShader); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexShaderConstantB(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount) { D3DDevice_SetVertexShaderConstantB(pThis, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexShaderConstantF(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetVertexShaderConstantF(pThis, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexShaderConstantI(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount) { D3DDevice_SetVertexShaderConstantI(pThis, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetVertexShaderConstantB(__in D3DDevice *pThis, UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount) { D3DDevice_GetVertexShaderConstantB(pThis, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetVertexShaderConstantF(__in D3DDevice *pThis, UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount) { D3DDevice_GetVertexShaderConstantF(pThis, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetVertexShaderConstantI(__in D3DDevice *pThis, UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount) { D3DDevice_GetVertexShaderConstantI(pThis, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexShaderConstantF_NotInline(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetVertexShaderConstantFN(pThis, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetStreamSource(__in D3DDevice *pThis, UINT StreamNumber, __in_opt D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride) { D3DDevice_SetStreamSource_Inline(pThis, StreamNumber, pStreamData, OffsetInBytes, Stride); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetStreamSource(__in D3DDevice *pThis, UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride) { *ppStreamData = D3DDevice_GetStreamSource(pThis, StreamNumber, pOffsetInBytes, pStride); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetIndices(__in D3DDevice *pThis, __in_opt D3DIndexBuffer *pIndexData) { D3DDevice_SetIndices(pThis, pIndexData); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetIndices(__in D3DDevice *pThis, __deref_out D3DIndexBuffer **ppIndexData) { *ppIndexData = D3DDevice_GetIndices(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreatePixelShader(__in D3DDevice *pThis, __in CONST DWORD *pFunction, __deref_out D3DPixelShader** ppShader) { return (*ppShader = D3DDevice_CreatePixelShader(pFunction)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPixelShader(__in D3DDevice *pThis, __in_opt D3DPixelShader* pShader) { D3DDevice_SetPixelShader(pThis, pShader); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetPixelShader(__in D3DDevice *pThis, __deref_out D3DPixelShader** ppShader) { D3DDevice_GetPixelShader(pThis, ppShader); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPixelShaderConstantB(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount) { D3DDevice_SetPixelShaderConstantB(pThis, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPixelShaderConstantF(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetPixelShaderConstantF(pThis, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPixelShaderConstantI(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount) { D3DDevice_SetPixelShaderConstantI(pThis, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetPixelShaderConstantB(__in D3DDevice *pThis, UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount) { D3DDevice_GetPixelShaderConstantB(pThis, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetPixelShaderConstantF(__in D3DDevice *pThis, UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount) { D3DDevice_GetPixelShaderConstantF(pThis, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetPixelShaderConstantI(__in D3DDevice *pThis, UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount) { D3DDevice_GetPixelShaderConstantI(pThis, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPixelShaderConstantF_NotInline(__in D3DDevice *pThis, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetPixelShaderConstantFN(pThis, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetClipPlane(__in D3DDevice *pThis, DWORD Index, __in_ecount(4) CONST float* pPlane) { D3DDevice_SetClipPlane(pThis, Index, pPlane); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetClipPlane(__in D3DDevice *pThis, DWORD Index, __out_ecount(4) float* pPlane) { D3DDevice_GetClipPlane(pThis, Index, pPlane); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateQuery(__in D3DDevice *pThis, D3DQUERYTYPE Type, __deref_out D3DQuery** ppQuery) { if (ppQuery == NULL) { return ((Type == D3DQUERYTYPE_EVENT) || (Type == D3DQUERYTYPE_OCCLUSION)) ? S_OK : D3DERR_NOTAVAILABLE; } else { return (*ppQuery = D3DDevice_CreateQueryTiled(pThis, Type, 1)) != NULL ? S_OK : E_OUTOFMEMORY; } } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateQueryTiled(__in D3DDevice *pThis, D3DQUERYTYPE Type, DWORD TileCount, __deref_out D3DQuery** ppQuery) { if (ppQuery == NULL) { return ((Type == D3DQUERYTYPE_EVENT) || (Type == D3DQUERYTYPE_OCCLUSION)) ? S_OK : D3DERR_NOTAVAILABLE; } else { return (*ppQuery = D3DDevice_CreateQueryTiled(pThis, Type, TileCount)) != NULL ? S_OK : E_OUTOFMEMORY; } } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateConstantBuffer(UINT VectorCount, DWORD Usage, __deref_out D3DConstantBuffer **ppConstantBuffer) { return (*ppConstantBuffer = D3DDevice_CreateConstantBuffer(VectorCount, Usage)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateCommandBuffer(UINT Size, DWORD Flags, __deref_out D3DCommandBuffer **ppCommandBuffer) { return (*ppCommandBuffer = D3DDevice_CreateCommandBuffer(Size, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateGrowableCommandBuffer(DWORD Flags, __in D3DALLOCATECALLBACK pAllocateCallback, __in D3DFREECALLBACK pFreeCallback, __in D3DQUERYCALLBACK pQueryCallback, DWORD CallbackContext, DWORD SegmentSize, __deref_out D3DCommandBuffer** ppCommandBuffer) { return (*ppCommandBuffer = D3DDevice_CreateGrowableCommandBuffer(Flags, pAllocateCallback, pFreeCallback, pQueryCallback, CallbackContext, SegmentSize)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Resolve(__in D3DDevice* pThis, DWORD Flags, __in_opt CONST D3DRECT *pSourceRect, __in D3DBaseTexture *pDestTexture, __in_opt CONST D3DPOINT *pDestPoint, UINT DestLevel, UINT DestSliceOrFace, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters) { D3DDevice_Resolve(pThis, Flags, pSourceRect, pDestTexture, pDestPoint, DestLevel, DestSliceOrFace, pClearColor, ClearZ, ClearStencil, pParameters); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_AcquireThreadOwnership(__in D3DDevice* pThis) { D3DDevice_AcquireThreadOwnership(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_ReleaseThreadOwnership(__in D3DDevice* pThis) { D3DDevice_ReleaseThreadOwnership(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetThreadOwnership(__in D3DDevice* pThis, DWORD ThreadID) { D3DDevice_SetThreadOwnership(pThis, ThreadID); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DDevice9_QueryThreadOwnership(__in D3DDevice* pThis) { return D3DDevice_QueryThreadOwnership(pThis); } +D3DINLINE BOOL WINAPI IDirect3DDevice9_IsBusy(__in D3DDevice *pThis) { return D3DDevice_IsBusy(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BlockUntilIdle(__in D3DDevice *pThis) { D3DDevice_BlockUntilIdle(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_InsertCallback(__in D3DDevice *pThis, D3DCALLBACKTYPE Type, __in_opt D3DCALLBACK pCallback, DWORD Context) { D3DDevice_InsertCallback(pThis, Type, pCallback, Context); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVerticalBlankCallback(__in D3DDevice *pThis, __in_opt D3DVBLANKCALLBACK pCallback) { D3DDevice_SetVerticalBlankCallback(pThis, pCallback); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSwapCallback(__in D3DDevice *pThis, __in D3DSWAPCALLBACK pCallback) { D3DDevice_SetSwapCallback(pThis, pCallback); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawTessellatedPrimitive(__in D3DDevice *pThis, D3DTESSPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) { D3DDevice_DrawTessellatedVertices(pThis, PrimitiveType, StartVertex, D3DTESSVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_DrawIndexedTessellatedPrimitive(__in D3DDevice *pThis, D3DTESSPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT PrimitiveCount) { D3DDevice_DrawIndexedTessellatedVertices(pThis, PrimitiveType, BaseVertexIndex, StartIndex, D3DTESSVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_SetRingBufferParameters(__in D3DDevice *pThis, __in_opt CONST D3DRING_BUFFER_PARAMETERS *pParameters) { return D3DDevice_SetRingBufferParameters(pThis, pParameters); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_XpsBegin(__in D3DDevice* pThis, DWORD Flags) { D3DDevice_XpsBegin(pThis, Flags); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_XpsEnd(__in D3DDevice* pThis) { return D3DDevice_XpsEnd(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_XpsSetCallback(__in D3DDevice* pThis, __in D3DXpsCallback pCallback, __in_opt void* pContext, DWORD Flags) { D3DDevice_XpsSetCallback(pThis, pCallback, pContext, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_XpsSubmit(__in D3DDevice* pThis, DWORD InstanceCount, __in_bcount(Size) CONST void* pData, DWORD Size) { D3DDevice_XpsSubmit(pThis, InstanceCount, pData, Size); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_XpsSetPredication(__in D3DDevice* pThis, DWORD Predication) { D3DDevice_XpsSetPredication(pThis, Predication); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_XpsSetPredicationFromVisibility(__in D3DDevice* pThis, HANDLE VisibilityHandle) { D3DDevice_XpsSetPredicationFromVisibility(pThis, VisibilityHandle); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_XpsSetPredicationFromQuery(__in D3DDevice* pThis, __in_opt IDirect3DQuery9* pQuery) { D3DDevice_XpsSetPredicationFromQuery(pThis, pQuery); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_BeginVertices(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, UINT VertexStreamZeroStride, __deref_out_bcount(VertexCount*VertexStreamZeroStride) void**ppVertexData) { return (*ppVertexData = D3DDevice_BeginVertices(pThis, PrimitiveType, VertexCount, VertexStreamZeroStride)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndVertices(__in D3DDevice *pThis) { D3DDevice_EndVertices(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_BeginIndexedVertices(__in D3DDevice *pThis, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT NumVertices, UINT IndexCount, D3DFORMAT IndexDataFormat, UINT VertexStreamZeroStride, __deref_out void** ppIndexData, __deref_out_bcount(NumVertices*VertexStreamZeroStride) void** ppVertexData) { return D3DDevice_BeginIndexedVertices(pThis, PrimitiveType, BaseVertexIndex, NumVertices, IndexCount, IndexDataFormat, VertexStreamZeroStride, ppIndexData, ppVertexData); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndIndexedVertices(__in D3DDevice *pThis) { D3DDevice_EndIndexedVertices(pThis); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DDevice9_InsertFence(__in D3DDevice *pThis) { return D3DDevice_InsertFence(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BlockOnFence(__in D3DDevice *pThis, DWORD Fence) { D3DDevice_BlockOnFence(Fence); D3DVOIDRETURN; } +D3DINLINE BOOL WINAPI IDirect3DDevice9_IsFencePending(__in D3DDevice *pThis, DWORD Fence) { return D3DDevice_IsFencePending(Fence); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetBlendState(__in D3DDevice *pThis, DWORD RenderTargetIndex, D3DBLENDSTATE BlendState) { D3DDevice_SetBlendState(pThis, RenderTargetIndex, BlendState); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetBlendState(__in D3DDevice *pThis, DWORD RenderTargetIndex, __out D3DBLENDSTATE* pBlendState) { D3DDevice_GetBlendState(pThis, RenderTargetIndex, pBlendState); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetVertexFetchConstant(__in D3DDevice *pThis, UINT VertexFetchRegister, __in D3DVertexBuffer* pVertexBuffer, UINT Offset) { D3DDevice_SetVertexFetchConstant(pThis, VertexFetchRegister, pVertexBuffer, Offset); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetTextureFetchConstant(__in D3DDevice *pThis, UINT TextureFetchRegister, __in D3DBaseTexture* pTexture) { D3DDevice_SetTextureFetchConstant(pThis, TextureFetchRegister, pTexture); D3DVOIDRETURN; } +D3DINLINE float WINAPI IDirect3DDevice9_GetCounter(__in D3DDevice* pThis, D3DCOUNTER CounterID) { return D3DDevice_GetCounter(pThis, CounterID);} +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSafeLevel(__in D3DDevice* pThis, DWORD Flags, DWORD Level) { D3DDevice_SetSafeLevel(pThis, Flags, Level); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetSafeLevel(__in D3DDevice* pThis, DWORD* pFlags, __out DWORD* pLevel) { D3DDevice_GetSafeLevel(pThis, pFlags, pLevel); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetHangCallback(__in D3DDevice* pThis, D3DHANGCALLBACK pCallback) { D3DDevice_SetHangCallback(pThis, pCallback); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginConditionalSurvey(__in D3DDevice* pThis, DWORD Identifier, DWORD Flags) { D3DDevice_BeginConditionalSurvey(pThis, Identifier, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndConditionalSurvey(__in D3DDevice* pThis, DWORD Flags) {D3DDevice_EndConditionalSurvey(pThis, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginConditionalRendering(__in D3DDevice* pThis, DWORD Identifier) { D3DDevice_BeginConditionalRendering(pThis, Identifier); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndConditionalRendering(__in D3DDevice* pThis) { D3DDevice_EndConditionalRendering(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_PersistDisplay(__in D3DDevice* pThis, __in D3DTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters) { return D3DDevice_PersistDisplay(pThis, pFrontBuffer, pParameters); } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GetPersistedTexture(__in D3DDevice* pThis, __deref_out D3DTexture** pFrontBuffer) { return D3DDevice_GetPersistedTexture(pThis, pFrontBuffer); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Suspend(__in D3DDevice* pThis) { D3DDevice_Suspend(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Resume(__in D3DDevice* pThis) { D3DDevice_Resume(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreatePerfCounters(__in D3DDevice *pThis, __deref_out D3DPerfCounters** ppCounters, UINT NumInstances) { return (*ppCounters = D3DDevice_CreatePerfCounters(pThis, NumInstances)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EnablePerfCounters(__in D3DDevice* pThis, BOOL Enable) { D3DDevice_EnablePerfCounters(pThis, Enable); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetPerfCounterEvents(__in D3DDevice* pThis, __in CONST D3DPERFCOUNTER_EVENTS* pEvents, DWORD Flags) { D3DDevice_SetPerfCounterEvents(pThis, pEvents, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_QueryPerfCounters(__in D3DDevice* pThis, __in D3DPerfCounters* pCounters, DWORD Flags) { D3DDevice_QueryPerfCounters(pThis, pCounters, Flags); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DDevice9_GetNumPasses(__in D3DDevice* pThis) { return D3DDevice_GetNumPasses(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetShaderInstructionAllocation(__in D3DDevice* pThis, DWORD Flags, DWORD VertexShaderBase, DWORD PixelShaderBase) { D3DDevice_SetShaderInstructionAllocation(pThis, Flags, VertexShaderBase, PixelShaderBase); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetShaderGPRAllocation(__in D3DDevice* pThis, DWORD Flags, DWORD VertexShaderCount, DWORD PixelShaderCount) { D3DDevice_SetShaderGPRAllocation(pThis, Flags, VertexShaderCount, PixelShaderCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetShaderGPRAllocation(__in D3DDevice* pThis, __out DWORD* pFlags, __out DWORD* pVertexShaderCount, __out DWORD* pPixelShaderCount) { D3DDevice_GetShaderGPRAllocation(pThis, pFlags, pVertexShaderCount, pPixelShaderCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetScreenExtentQueryMode(__in D3DDevice* pThis, D3DSCREENEXTENTQUERYMODE Mode) { D3DDevice_SetScreenExtentQueryMode(pThis, Mode); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetScreenExtentQueryMode(__in D3DDevice* pThis, __out D3DSCREENEXTENTQUERYMODE* pMode) { D3DDevice_GetScreenExtentQueryMode(pThis, pMode); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginVertexShaderConstantF1(__in D3DDevice* pThis, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount) { D3DDevice_BeginVertexShaderConstantF1(pThis, StartRegister, ppConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndVertexShaderConstantF1(__in D3DDevice* pThis) { D3DDevice_EndShaderConstantF1(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginPixelShaderConstantF1(__in D3DDevice* pThis, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount) { D3DDevice_BeginPixelShaderConstantF1(pThis, StartRegister, ppConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndPixelShaderConstantF1(__in D3DDevice* pThis) { D3DDevice_EndShaderConstantF1(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_BeginVertexShaderConstantF4(__in D3DDevice* pThis, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, UINT Vector4fCount) { return D3DDevice_BeginShaderConstantF4(pThis, FALSE, StartRegister, ppCachedConstantData, ppWriteCombinedConstantData, Vector4fCount); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndVertexShaderConstantF4(__in D3DDevice* pThis) { D3DDevice_EndShaderConstantF4(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_BeginPixelShaderConstantF4(__in D3DDevice* pThis, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, UINT Vector4fCount) { return D3DDevice_BeginShaderConstantF4(pThis, TRUE, StartRegister, ppCachedConstantData, ppWriteCombinedConstantData, Vector4fCount); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndPixelShaderConstantF4(__in D3DDevice* pThis) { D3DDevice_EndShaderConstantF4(pThis); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DDevice9_GetCurrentFence(__in D3DDevice* pThis) { return D3DDevice_GetCurrentFence(); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_InvalidateGpuCache(__in D3DDevice* pThis, __in_bcount(Size) void* pBaseAddress, DWORD Size, DWORD Flags) { D3DDevice_InvalidateGpuCache(pThis, pBaseAddress, Size, Flags ); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_InvalidateResourceGpuCache(__in D3DDevice* pThis, __in D3DResource* pResource, DWORD Flags) { D3DDevice_InvalidateResourceGpuCache(pThis, pResource, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_FlushHiZStencil(__in D3DDevice* pThis, D3DFHZS_FLUSHTYPE FlushType) { D3DDevice_FlushHiZStencil(pThis, FlushType); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_UnsetAll(__in D3DDevice* pThis) { D3DDevice_UnsetAll(pThis); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DDevice9_GetDeviceState(__in D3DDevice* pThis) { return D3DDevice_GetDeviceState(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetBlockCallback(__in D3DDevice* pThis, DWORD Flags, __in_opt D3DBLOCKCALLBACK pCallback) { D3DDevice_SetBlockCallback(pThis, Flags, pCallback); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSurfaces(__in D3DDevice* pThis, __in CONST D3DSURFACES* pSurfaces, DWORD Flags) { D3DDevice_SetSurfaces(pThis, pSurfaces, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_BeginCommandBuffer(__in D3DDevice* pThis, __in D3DCommandBuffer* pCommandBuffer, DWORD Flags, __in_opt CONST D3DTAGCOLLECTION* pInheritTags, __in_opt CONST D3DTAGCOLLECTION* pPersistTags, __in_opt CONST D3DRECT* pTilingRects, DWORD TileCount) { D3DDevice_BeginCommandBuffer(pThis, pCommandBuffer, Flags, pInheritTags, pPersistTags, pTilingRects, TileCount); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_EndCommandBuffer(__in D3DDevice* pThis) { return D3DDevice_EndCommandBuffer(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_RunCommandBuffer(__in D3DDevice* pThis, __in D3DCommandBuffer* pCommandBuffer, DWORD PredicationSelect) { D3DDevice_RunCommandBuffer(pThis, pCommandBuffer, PredicationSelect); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_InsertAsyncCommandBufferCall(__in D3DDevice* pThis, __in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, DWORD PredicationSelect, DWORD Flags) { return D3DDevice_InsertAsyncCommandBufferCall(pThis, pAsyncCommandBufferCall, PredicationSelect, Flags ); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetCommandBufferPredication(__in D3DDevice* pThis, DWORD TilePredication, DWORD RunPredication) { D3DDevice_SetCommandBufferPredication(pThis, TilePredication, RunPredication); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DDevice9_InsertMarker(__in D3DDevice* pThis) { return D3DDevice_InsertMarker(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_Nop(__in D3DDevice* pThis, DWORD Count) { D3DDevice_Nop(pThis, Count); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_QuerySwapStatus(__in D3DDevice* pDevice, __out D3DSWAP_STATUS* pSwapStatus) { D3DDevice_QuerySwapStatus(pDevice, pSwapStatus); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetViewportF(__in D3DDevice* pDevice, __in CONST D3DVIEWPORTF9* pViewportF) { D3DDevice_SetViewportF(pDevice, pViewportF); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_GetViewportF(__in D3DDevice* pDevice, __out D3DVIEWPORTF9* pViewportF) { D3DDevice_GetViewportF(pDevice, pViewportF); D3DVOIDRETURN; } +D3DINLINE HANDLE WINAPI IDirect3DDevice9_BeginVisibilitySurvey(__in D3DDevice* pDevice, DWORD Flags) { return D3DDevice_BeginVisibilitySurvey(pDevice, Flags); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_EndVisibilitySurvey(__in D3DDevice* pDevice, HANDLE VisibilityHandle) { D3DDevice_EndVisibilitySurvey(pDevice, VisibilityHandle); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SetSwapMode(__in D3DDevice* pDevice, BOOL Asynchronous) { D3DDevice_SetSwapMode(pDevice, Asynchronous); D3DVOIDRETURN; } +D3DINLINE D3DASYNCBLOCK WINAPI IDirect3DDevice9_InsertBlockOnAsyncResources(__in D3DDevice* pDevice, DWORD WriteCount, __in_ecount_opt(WriteCount) D3DResource* CONST* pWriteResourceList, DWORD ReadCount, __in_ecount_opt(ReadCount) D3DResource* CONST* pReadResourceList, DWORD Flags) { return D3DDevice_InsertBlockOnAsyncResources(pDevice, WriteCount, pWriteResourceList, ReadCount, pReadResourceList, Flags); } +D3DINLINE D3DVOID WINAPI IDirect3DDevice9_SignalAsyncResources(__in D3DDevice* pDevice, D3DASYNCBLOCK AsyncBlock) { D3DDevice_SignalAsyncResources(pDevice, AsyncBlock); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateAsyncCommandBufferCall(__in D3DDevice* pThis, __in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags, D3DAsyncCommandBufferCall** ppAsyncCall ) { return (*ppAsyncCall = D3DDevice_CreateAsyncCommandBufferCall(pThis, pInheritTags, pPersistTags, NumSegments, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreatePerfCounterBatch(__in D3DDevice *pThis, UINT NumSlots, UINT NumTiles, DWORD Flags, __deref_out D3DPerfCounterBatch** ppBatch) { return (*ppBatch = D3DDevice_CreatePerfCounterBatch(pThis, NumSlots, NumTiles, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_CreateOcclusionQueryBatch(__in D3DDevice* pThis, UINT NumSlots, UINT NumTiles, __deref_out D3DOcclusionQueryBatch** ppBatch) { return (*ppBatch = D3DDevice_CreateOcclusionQueryBatch(pThis, NumSlots, NumTiles)) != NULL ? S_OK : E_OUTOFMEMORY; } + +D3DINLINE void WINAPI IDirect3DDevice9_GpuOwn(__in D3DDevice* pThis, D3DTAG Tag) { D3DDevice_GpuOwn(pThis, Tag); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuOwnSubset(__in D3DDevice* pThis, D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) { D3DDevice_GpuOwnSubset(pThis, Tag, StartIndex, EndIndex); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuOwnVertexShaderConstantF(__in D3DDevice* pThis, DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuOwnVertexShaderConstantF(pThis, StartRegister, Vector4fCount); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuOwnPixelShaderConstantF(__in D3DDevice* pThis, DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuOwnPixelShaderConstantF(pThis, StartRegister, Vector4fCount); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuOwnShaders(__in D3DDevice* pThis) { D3DDevice_GpuOwnShaders(pThis); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuDisown(__in D3DDevice* pThis, D3DTAG Tag) { D3DDevice_GpuDisown(pThis, Tag); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuDisownSubset(__in D3DDevice* pThis, D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) { D3DDevice_GpuDisownSubset(pThis, Tag, StartIndex, EndIndex); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuDisownVertexShaderConstantF(__in D3DDevice* pThis, DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuDisownVertexShaderConstantF(pThis, StartRegister, Vector4fCount); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuDisownPixelShaderConstantF(__in D3DDevice* pThis, DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuDisownPixelShaderConstantF(pThis, StartRegister, Vector4fCount); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuDisownShaders(__in D3DDevice* pThis) { D3DDevice_GpuDisownShaders(pThis); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuDisownAll(__in D3DDevice* pThis) { D3DDevice_GpuDisownAll(pThis); } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GpuBeginVertexShaderConstantF4(__in D3DDevice* pThis, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, DWORD Vector4fCount) { return (*ppConstantData = D3DDevice_GpuBeginShaderConstantF4(pThis, FALSE, StartRegister, Vector4fCount)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE void WINAPI IDirect3DDevice9_GpuEndVertexShaderConstantF4(__in D3DDevice* pThis) { D3DDevice_GpuEndShaderConstantF4(pThis); } +D3DINLINE HRESULT WINAPI IDirect3DDevice9_GpuBeginPixelShaderConstantF4(__in D3DDevice* pThis, UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, DWORD Vector4fCount) { return (*ppConstantData = D3DDevice_GpuBeginShaderConstantF4(pThis, TRUE, StartRegister, Vector4fCount)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE void WINAPI IDirect3DDevice9_GpuEndPixelShaderConstantF4(__in D3DDevice* pThis) { D3DDevice_GpuEndShaderConstantF4(pThis); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuLoadVertexShaderConstantF4(__in D3DDevice* pThis, UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors) { D3DDevice_GpuLoadShaderConstantF4(pThis, FALSE, StartRegister, Vector4fCount, pConstantBuffer, OffsetInVectors); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuLoadPixelShaderConstantF4(__in D3DDevice* pThis, UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors) { D3DDevice_GpuLoadShaderConstantF4(pThis, TRUE, StartRegister, Vector4fCount, pConstantBuffer, OffsetInVectors); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuLoadVertexShaderConstantF4Pointer(__in D3DDevice* pThis, UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount) { D3DDevice_GpuLoadShaderConstantF4Pointer(pThis, FALSE, StartRegister, pConstantData, Vector4fCount); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuLoadPixelShaderConstantF4Pointer(__in D3DDevice* pThis, UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount) { D3DDevice_GpuLoadShaderConstantF4Pointer(pThis, TRUE, StartRegister, pConstantData, Vector4fCount); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuLoadShaders(__in D3DDevice* pThis, __in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants) { D3DDevice_GpuLoadShaders(pThis, pVertexShader, pPixelShader, pFlowConstants); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuLoadShadersFast(__in D3DDevice* pThis, __in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants, DWORD Flags) { D3DDevice_GpuLoadShadersFast(pThis, pVertexShader, pPixelShader, pFlowConstants, Flags); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetVertexFetchConstant(__in D3DDevice* pThis, DWORD VertexFetchRegister, __in_opt D3DVertexBuffer* pVertexBuffer0, DWORD OffsetInBytes0, __in_opt D3DVertexBuffer* pVertexBuffer1, DWORD OffsetInBytes1, __in_opt D3DVertexBuffer* pVertexBuffer2, DWORD OffsetInBytes2) { D3DDevice_GpuSetVertexFetchConstant(pThis, VertexFetchRegister, pVertexBuffer0, OffsetInBytes0, pVertexBuffer1, OffsetInBytes1, pVertexBuffer2, OffsetInBytes2); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetTextureFetchConstant(__in D3DDevice* pThis, DWORD TextureFetchRegister, __in D3DBaseTexture* pTexture) { IDirect3DDevice9_GpuSetTextureFetchConstant(pThis, TextureFetchRegister, pTexture); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetColorMask(__in D3DDevice* pThis, __in const GPU_COLORMASK* pColorMask) { D3DDevice_GpuSetColorMask(pThis, pColorMask->dword); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetBlendFactor(__in D3DDevice* pThis, __in const D3DCOLORVALUE* pColor) { D3DDevice_GpuSetBlendFactor(pThis, pColor->r, pColor->g, pColor->b, pColor->a); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetAlphaRef(__in D3DDevice* pThis, float Ref) { D3DDevice_GpuSetAlphaRef(pThis, Ref); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetBlendControl(__in D3DDevice* pThis, DWORD RenderTargetIndex, __in const GPU_BLENDCONTROL* pBlendControl) { D3DDevice_GpuSetBlendControl(pThis, RenderTargetIndex, pBlendControl->dword); } +D3DINLINE void WINAPI IDirect3DDevice9_GpuSetColorControl(__in D3DDevice* pThis, __in const GPU_COLORCONTROL* pColorControl) { D3DDevice_GpuSetColorControl(pThis, pColorControl->dword); } + +// Make the PIX methods disappear on retail builds +// +D3DINLINE DWORD WINAPI IDirect3DDevice9_PixBeginNamedEvent(__in D3DDevice* pThis, DWORD Color, __in_z CONST char *szName, ...) +{ +#if defined(USE_D3D_PIX_METHODS) + va_list arglist; + va_start(arglist, szName); + return D3DDevice_PixBeginNamedEvent(pThis, Color, szName, arglist); +#else + return 0; +#endif +} + +D3DINLINE DWORD WINAPI IDirect3DDevice9_PixEndNamedEvent(__in D3DDevice* pThis) +{ +#if defined(USE_D3D_PIX_METHODS) + return D3DDevice_PixEndNamedEvent(pThis); +#else + return 0; +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixSetMarker(__in D3DDevice* pThis, DWORD Color, __in_z CONST char *szName, ...) +{ +#if defined(USE_D3D_PIX_METHODS) + va_list arglist; + va_start(arglist, szName); + D3DDevice_PixSetMarker(pThis, Color, szName, arglist); +#endif +} + +// Make the PIX Texture Tracking methods disappear on retail and x86 builds +// +D3DINLINE void WINAPI IDirect3DDevice9_PixIgnoreTexture(__in D3DDevice* pThis, __in D3DBaseTexture* pTexture) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixIgnoreTexture(pThis, pTexture); +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixStopIgnoringTexture(__in D3DDevice* pThis, __in D3DBaseTexture* pTexture) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixStopIgnoringTexture(pThis, pTexture); +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixIgnoreMemoryRange(__in D3DDevice* pThis, __in_bcount(Size) const void* pBaseAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixIgnoreMemoryRange(pThis, pBaseAddress, Size); +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixStopIgnoringMemoryRange(__in D3DDevice* pThis, __in_bcount(Size) const void* pBaseAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixStopIgnoringMemoryRange(pThis, pBaseAddress, Size); +#endif +} + +D3DINLINE HRESULT WINAPI IDirect3DDevice9_PixSetTextureName(__in D3DDevice* pThis, __in D3DBaseTexture* pTexture, __in_z const char* pName) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + return D3DDevice_PixSetTextureName(pThis, pTexture, pName); +#else + return S_OK; +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixReportNewTexture(__in D3DDevice* pThis, __in D3DBaseTexture* pTexture) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportNewTexture(pThis, pTexture); +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixReportDeletedTexture(__in D3DDevice* pThis, __in D3DBaseTexture* pTexture, BOOL BaseDeleted, BOOL MipDeleted) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportDeletedTexture(pThis, pTexture, BaseDeleted, MipDeleted); +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixReportMovedMemoryRange(__in D3DDevice* pThis, __in_bcount(Size) const void* pDestinationAddress, __in_bcount(Size) const void* pSourceAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportMovedMemoryRange(pThis, pDestinationAddress, pSourceAddress, Size); +#endif +} + +D3DINLINE void WINAPI IDirect3DDevice9_PixReportFreedMemoryRange(__in D3DDevice* pThis, __in_bcount(Size) const void* pAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportFreedMemoryRange(pThis, pAddress, Size); +#endif +} + +#ifdef __cplusplus + +D3DMINLINE ULONG WINAPI D3DDevice::AddRef() { return D3DDevice_AddRef(this); } +D3DMINLINE ULONG WINAPI D3DDevice::Release() { return D3DDevice_Release(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetDirect3D(__deref_out Direct3D **ppD3D9) { D3DDevice_GetDirect3D(this, ppD3D9); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetDeviceCaps(__out D3DCAPS9 *pCaps) { D3DDevice_GetDeviceCaps(this, pCaps); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetDisplayMode(UINT UnusedSwapChain, __out D3DDISPLAYMODE *pMode) { D3DDevice_GetDisplayMode(this, UnusedSwapChain, pMode); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetCreationParameters(__out D3DDEVICE_CREATION_PARAMETERS *pParameters) { D3DDevice_GetCreationParameters(this, pParameters); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::Reset(__in D3DPRESENT_PARAMETERS *pPresentationParameters) { return D3DDevice_Reset(this, pPresentationParameters); } +D3DMINLINE D3DVOID WINAPI D3DDevice::Present(__in_opt CONST RECT *pUnusedSourceRect, __in_opt CONST RECT *pUnusedDestRect, __in_opt void *hUnusedDestWindowOverride, __in_opt void *pUnusedDirtyRegion) { D3DDevice_Present(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetRasterStatus(UINT iUnusedSwapChain, __out D3DRASTER_STATUS *pRasterStatus) { D3DDevice_GetRasterStatus(this, pRasterStatus); D3DVOIDRETURN; } +D3DMINLINE void WINAPI D3DDevice::SetGammaRamp(UINT iUnusedSwapChain, DWORD UnusedFlags, __in CONST D3DGAMMARAMP *pRamp) { D3DDevice_SetGammaRamp(this, UnusedFlags, pRamp); } +D3DMINLINE void WINAPI D3DDevice::GetGammaRamp(UINT iUnusedSwapChain, __out D3DGAMMARAMP *pRamp) { D3DDevice_GetGammaRamp(this, pRamp); } +D3DMINLINE void WINAPI D3DDevice::SetPWLGamma(DWORD Flags, __in CONST D3DPWLGAMMA *pRamp) { D3DDevice_SetPWLGamma(this, Flags, pRamp); } +D3DMINLINE void WINAPI D3DDevice::GetPWLGamma(__out D3DPWLGAMMA *pRamp) { D3DDevice_GetPWLGamma(this, pRamp); } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateTexture(UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DTexture **ppTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppTexture = (D3DTexture*) D3DDevice_CreateTexture(Width, Height, 1, Levels, Usage, Format, UnusedPool, D3DRTYPE_TEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateVolumeTexture(UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DVolumeTexture **ppVolumeTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppVolumeTexture = (D3DVolumeTexture*) D3DDevice_CreateTexture(Width, Height, Depth, Levels, Usage, Format, UnusedPool, D3DRTYPE_VOLUMETEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateCubeTexture(UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DCubeTexture **ppCubeTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppCubeTexture = (D3DCubeTexture*) D3DDevice_CreateTexture(EdgeLength, EdgeLength, 6, Levels, Usage, Format, UnusedPool, D3DRTYPE_CUBETEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateArrayTexture(UINT Width, UINT Height, UINT ArraySize, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DArrayTexture **ppArrayTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppArrayTexture = (D3DArrayTexture*) D3DDevice_CreateTexture(Width, Height, ArraySize, Levels, Usage, Format, UnusedPool, D3DRTYPE_ARRAYTEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateLineTexture(UINT Width, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DLineTexture **ppTexture, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppTexture = (D3DLineTexture*) D3DDevice_CreateTexture(Width, 1, 1, Levels, Usage, Format, UnusedPool, D3DRTYPE_LINETEXTURE)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateVertexBuffer(UINT Length, DWORD Usage, DWORD UnusedFVF, D3DPOOL UnusedPool, __deref_out D3DVertexBuffer **ppVertexBuffer, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppVertexBuffer = D3DDevice_CreateVertexBuffer(Length, Usage, UnusedPool)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL UnusedPool, __deref_out D3DIndexBuffer **ppIndexBuffer, __in_opt HANDLE* pUnusedSharedHandle) { return (*ppIndexBuffer = D3DDevice_CreateIndexBuffer(Length, Usage, Format, UnusedPool)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateVertexDeclaration(__in CONST D3DVERTEXELEMENT9* pVertexElements, __deref_out D3DVertexDeclaration **ppVertexDeclaration) { return (*ppVertexDeclaration = D3DDevice_CreateVertexDeclaration(pVertexElements)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateRenderTarget(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD UnusedMultisampleQuality, BOOL UnusedLockable, __deref_out D3DSurface **ppSurface, __in_opt CONST D3DSURFACE_PARAMETERS* pParameters) { return (*ppSurface = D3DDevice_CreateSurface(Width, Height, Format, MultiSample, pParameters)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD UnusedMultisampleQuality, BOOL UnusedDiscard, __deref_out D3DSurface **ppSurface, __in_opt CONST D3DSURFACE_PARAMETERS* pParameters) { return (*ppSurface = D3DDevice_CreateSurface(Width, Height, Format, MultiSample, pParameters)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetRenderTarget(DWORD RenderTargetIndex, __in_opt D3DSurface *pRenderTarget) { D3DDevice_SetRenderTarget_External(this, RenderTargetIndex, pRenderTarget); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::GetRenderTarget(DWORD RenderTargetIndex, __deref_out D3DSurface **ppRenderTarget) { return (*ppRenderTarget = D3DDevice_GetRenderTarget(this, RenderTargetIndex)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetDepthStencilSurface(__in_opt D3DSurface *pZStencilSurface) { D3DDevice_SetDepthStencilSurface(this, pZStencilSurface); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::GetDepthStencilSurface(__deref_out D3DSurface **ppZStencilSurface) { return (*ppZStencilSurface = D3DDevice_GetDepthStencilSurface(this)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DMINLINE HRESULT WINAPI D3DDevice::GetBackBuffer(UINT UnusedSwapChain, UINT iUnusedBackBuffer, UINT UnusedType, __deref_out D3DSurface **ppBackBuffer) { return (*ppBackBuffer = D3DDevice_GetBackBuffer(this)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DMINLINE HRESULT WINAPI D3DDevice::GetFrontBuffer(__deref_out D3DTexture **ppFrontBuffer) { return (*ppFrontBuffer = D3DDevice_GetFrontBuffer(this)) != NULL ? S_OK : D3DERR_NOTFOUND; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginScene() { D3DDevice_BeginScene(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndScene() { D3DDevice_EndScene(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::Clear(DWORD Count, __in_opt CONST D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) { D3DDevice_Clear(this, Count, pRects, Flags, Color, Z, Stencil, FALSE); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::ClearF(DWORD Flags, __in_opt CONST D3DRECT *pRect, __in_opt CONST D3DVECTOR4* pColor, float Z, DWORD Stencil) { D3DDevice_ClearF(this, Flags, pRect, pColor, Z, Stencil); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SynchronizeToPresentationInterval() { D3DDevice_SynchronizeToPresentationInterval(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::Swap(__in D3DBaseTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters) { D3DDevice_Swap(this, pFrontBuffer, pParameters); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::RenderSystemUI() { D3DDevice_RenderSystemUI(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::QueryBufferSpace(__out DWORD* pUsed, __out DWORD* pRemaining) { D3DDevice_QueryBufferSpace(this, pUsed, pRemaining); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPredication(DWORD PredicationMask) { D3DDevice_SetPredication(this, PredicationMask); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPatchablePredication(DWORD PredicationMask, DWORD Identifier) { D3DDevice_SetPatchablePredication(this, PredicationMask, Identifier); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginTiling(DWORD Flags, DWORD Count, __in_ecount(Count) CONST D3DRECT* pTileRects, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil) { D3DDevice_BeginTiling(this, Flags, Count, pTileRects, pClearColor, ClearZ, ClearStencil); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::EndTiling(DWORD ResolveFlags, __in_opt CONST D3DRECT* pResolveRects, __in_opt D3DBaseTexture* pDestTexture, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters) { return D3DDevice_EndTiling(this, ResolveFlags, pResolveRects, pDestTexture, pClearColor, ClearZ, ClearStencil, pParameters); } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginZPass(DWORD Flags) { D3DDevice_BeginZPass(this, Flags); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::EndZPass() { return D3DDevice_EndZPass(this); } +D3DMINLINE HRESULT WINAPI D3DDevice::InvokeRenderPass() { return D3DDevice_InvokeRenderPass(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginExport(DWORD Index, __in D3DResource* pResource, DWORD Flags) { D3DDevice_BeginExport(this, Index, pResource, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndExport(DWORD Index, __in D3DResource* pResource, DWORD Flags) { D3DDevice_EndExport(this, Index, pResource, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetViewport(__in CONST D3DVIEWPORT9 *pViewport) { D3DDevice_SetViewport(this, pViewport); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetViewport(__out D3DVIEWPORT9 *pViewport) { D3DDevice_GetViewport(this, pViewport); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) { D3DDevice_SetRenderState(this, State, Value); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetRenderState_Inline(D3DRENDERSTATETYPE State, DWORD Value) { D3DDevice_SetRenderState(this, State, Value); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetRenderState(D3DRENDERSTATETYPE State, __out DWORD *pValue) { D3DDevice_GetRenderState(this, State, pValue); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateStateBlock(D3DSTATEBLOCKTYPE Type, __deref_out D3DStateBlock** ppSB) { return (*ppSB = D3DDevice_CreateStateBlock(this, Type)) != NULL ? S_OK : E_OUTOFMEMORY;} +D3DMINLINE D3DVOID WINAPI D3DDevice::GetTexture(DWORD Sampler, __deref_out D3DBaseTexture **ppTexture) { *ppTexture = D3DDevice_GetTexture(this, Sampler); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetTexture(DWORD Sampler, __in_opt D3DBaseTexture *pTexture) { D3DDevice_SetTexture_Inline(this, Sampler, pTexture); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, __out DWORD* pValue) { D3DDevice_GetSamplerState(this, Sampler, Type, pValue); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) { D3DDevice_SetSamplerState(this, Sampler, Type, Value); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSamplerState_Inline(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) { D3DDevice_SetSamplerState(this, Sampler, Type, Value); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSamplerAddressStates(DWORD Sampler, DWORD AddressU, DWORD AddressV, DWORD AddressW) { D3DDevice_SetSamplerAddressStates(this, Sampler, AddressU, AddressV, AddressW); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSamplerBorderStates(DWORD Sampler, DWORD BorderColor, DWORD WhiteBorderColorW, DWORD PointBorderEnable) { D3DDevice_SetSamplerBorderStates(this, Sampler, BorderColor, WhiteBorderColorW, PointBorderEnable); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSamplerSeparateZFilterStates(DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MinFilterZ, DWORD MagFilterZ, DWORD MaxAnisotropy) { D3DDevice_SetSamplerSeparateZFilterStates(this, Sampler, MinFilter, MagFilter, MipFilter, MinFilterZ, MagFilterZ, MaxAnisotropy); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSamplerFilterStates(DWORD Sampler, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MaxAnisotropy) { D3DDevice_SetSamplerFilterStates(this, Sampler, MinFilter, MagFilter, MipFilter, MaxAnisotropy); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawVertices(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT VertexCount) { D3DDevice_DrawVertices(this, PrimitiveType, StartVertex, VertexCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawIndexedVertices(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT IndexCount) { D3DDevice_DrawIndexedVertices(this, PrimitiveType, BaseVertexIndex, StartIndex, IndexCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawVerticesUP(D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawVerticesUP(this, PrimitiveType, VertexCount, pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawIndexedVerticesUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT IndexCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawIndexedVerticesUP(this, PrimitiveType, MinVertexIndex, NumVertices, IndexCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) { D3DDevice_DrawVertices(this, PrimitiveType, StartVertex, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT UnusedMinIndex, UINT UnusedNumIndices, UINT StartIndex, UINT PrimitiveCount) { D3DDevice_DrawIndexedVertices(this, PrimitiveType, BaseVertexIndex, StartIndex, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawVerticesUP(this, PrimitiveType, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount), pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT PrimitiveCount, __in CONST void *pIndexData, D3DFORMAT IndexDataFormat, __in CONST void *pVertexStreamZeroData, UINT VertexStreamZeroStride) { D3DDevice_DrawIndexedVerticesUP(this, PrimitiveType, MinIndex, NumVertices, D3DVERTEXCOUNT(PrimitiveType, PrimitiveCount), pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexDeclaration(__in_opt D3DVertexDeclaration *pDecl) { D3DDevice_SetVertexDeclaration(this, pDecl); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetVertexDeclaration(__deref_out D3DVertexDeclaration **ppDecl) { *ppDecl = D3DDevice_GetVertexDeclaration(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetScissorRect(__in CONST RECT* pRect) { D3DDevice_SetScissorRect(this, pRect); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetScissorRect(__out RECT* pRect) { D3DDevice_GetScissorRect(this, pRect); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetFVF(DWORD FVF) { D3DDevice_SetFVF(this, FVF); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetFVF(__out DWORD* pFVF) { *pFVF = D3DDevice_GetFVF(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateVertexShader(__in CONST DWORD *pFunction, __deref_out D3DVertexShader** ppShader) { return (*ppShader = D3DDevice_CreateVertexShader(pFunction)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexShader(__in_opt D3DVertexShader *pShader) { D3DDevice_SetVertexShader(this, pShader); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetVertexShader(__deref_out D3DVertexShader **ppShader) { D3DDevice_GetVertexShader(this, ppShader); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexShaderConstantF(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetVertexShaderConstantF(this, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetVertexShaderConstantF(UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount) { D3DDevice_GetVertexShaderConstantF(this, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexShaderConstantI(UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount) { D3DDevice_SetVertexShaderConstantI(this, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetVertexShaderConstantI(UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount) { D3DDevice_GetVertexShaderConstantI(this, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexShaderConstantB(UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount) { D3DDevice_SetVertexShaderConstantB(this, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetVertexShaderConstantB(UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount) { D3DDevice_GetVertexShaderConstantB(this, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexShaderConstantF_NotInline(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetVertexShaderConstantFN(this, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetStreamSource(UINT StreamNumber, __in_opt D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride) { D3DDevice_SetStreamSource_Inline(this, StreamNumber, pStreamData, OffsetInBytes, Stride); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetStreamSource(UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride) { *ppStreamData = D3DDevice_GetStreamSource(this, StreamNumber, pOffsetInBytes, pStride); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetIndices(__in_opt D3DIndexBuffer *pIndexData) { D3DDevice_SetIndices(this, pIndexData); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetIndices(__deref_out D3DIndexBuffer **ppIndexData) { *ppIndexData = D3DDevice_GetIndices(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreatePixelShader(__in CONST DWORD *pFunction, __deref_out D3DPixelShader** ppShader) { return (*ppShader = D3DDevice_CreatePixelShader(pFunction)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPixelShader(__in_opt D3DPixelShader* pShader) { D3DDevice_SetPixelShader(this, pShader); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetPixelShader(__deref_out D3DPixelShader** ppShader) { D3DDevice_GetPixelShader(this, ppShader); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPixelShaderConstantF(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetPixelShaderConstantF(this, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetPixelShaderConstantF(UINT StartRegister, __out_ecount(4*Vector4fCount) float *pConstantData, DWORD Vector4fCount) { D3DDevice_GetPixelShaderConstantF(this, StartRegister, pConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPixelShaderConstantI(UINT StartRegister, __in_ecount(4*Vector4iCount) CONST int *pConstantData, DWORD Vector4iCount) { D3DDevice_SetPixelShaderConstantI(this, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetPixelShaderConstantI(UINT StartRegister, __out_ecount(4*Vector4iCount) int *pConstantData, DWORD Vector4iCount) { D3DDevice_GetPixelShaderConstantI(this, StartRegister, pConstantData, Vector4iCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPixelShaderConstantB(UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount) { D3DDevice_SetPixelShaderConstantB(this, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetPixelShaderConstantB(UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount) { D3DDevice_GetPixelShaderConstantB(this, StartRegister, pConstantData, BoolCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPixelShaderConstantF_NotInline(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST float *pConstantData, DWORD Vector4fCount) { D3DDevice_SetPixelShaderConstantFN(this, StartRegister, pConstantData, Vector4fCount, D3DTag_ShaderConstantMask(StartRegister, Vector4fCount)); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetClipPlane(DWORD Index, __in_ecount(4) CONST float* pPlane) { D3DDevice_SetClipPlane(this, Index, pPlane); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetClipPlane(DWORD Index, __out_ecount(4) float* pPlane) { D3DDevice_GetClipPlane(this, Index, pPlane); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateQuery(D3DQUERYTYPE Type, __deref_out D3DQuery** ppQuery) { if (ppQuery == NULL) { return ((Type == D3DQUERYTYPE_EVENT) || (Type == D3DQUERYTYPE_OCCLUSION)) ? S_OK : D3DERR_NOTAVAILABLE; } else { return (*ppQuery = D3DDevice_CreateQueryTiled(this, Type, 1)) != NULL ? S_OK : E_OUTOFMEMORY; } } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateQueryTiled(D3DQUERYTYPE Type, DWORD TileCount, __deref_out D3DQuery** ppQuery) { if (ppQuery == NULL) { return ((Type == D3DQUERYTYPE_EVENT) || (Type == D3DQUERYTYPE_OCCLUSION)) ? S_OK : D3DERR_NOTAVAILABLE; } else { return (*ppQuery = D3DDevice_CreateQueryTiled(this, Type, TileCount)) != NULL ? S_OK : E_OUTOFMEMORY; } } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateConstantBuffer(UINT VectorCount, DWORD Usage, __deref_out D3DConstantBuffer **ppConstantBuffer) { return (*ppConstantBuffer = D3DDevice_CreateConstantBuffer(VectorCount, Usage)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateCommandBuffer(UINT Size, DWORD Flags, __deref_out D3DCommandBuffer **ppCommandBuffer) { return (*ppCommandBuffer = D3DDevice_CreateCommandBuffer(Size, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateGrowableCommandBuffer(DWORD Flags, __in D3DALLOCATECALLBACK pAllocateCallback, __in D3DFREECALLBACK pFreeCallback, __in D3DQUERYCALLBACK pQueryCallback, DWORD CallbackContext, DWORD SegmentSize, __deref_out D3DCommandBuffer** ppCommandBuffer) { return (*ppCommandBuffer = D3DDevice_CreateGrowableCommandBuffer(Flags, pAllocateCallback, pFreeCallback, pQueryCallback, CallbackContext, SegmentSize)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DDevice::Resolve(DWORD Flags, __in_opt CONST D3DRECT *pSourceRect, __in D3DBaseTexture *pDestTexture, __in_opt CONST D3DPOINT *pDestPoint, UINT DestLevel, UINT DestSliceOrFace, __in_opt CONST D3DVECTOR4* pClearColor, float ClearZ, DWORD ClearStencil, __in_opt CONST D3DRESOLVE_PARAMETERS* pParameters) { D3DDevice_Resolve(this, Flags, pSourceRect, pDestTexture, pDestPoint, DestLevel, DestSliceOrFace, pClearColor, ClearZ, ClearStencil, pParameters); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::AcquireThreadOwnership() { D3DDevice_AcquireThreadOwnership(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::ReleaseThreadOwnership() { D3DDevice_ReleaseThreadOwnership(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetThreadOwnership(DWORD ThreadID) { D3DDevice_SetThreadOwnership(this, ThreadID); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DDevice::QueryThreadOwnership() { return D3DDevice_QueryThreadOwnership(this); } +D3DMINLINE BOOL WINAPI D3DDevice::IsBusy() { return D3DDevice_IsBusy(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::BlockUntilIdle() { D3DDevice_BlockUntilIdle(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::InsertCallback(D3DCALLBACKTYPE Type, __in_opt D3DCALLBACK pCallback, DWORD Context) { D3DDevice_InsertCallback(this, Type, pCallback, Context); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVerticalBlankCallback(__in_opt D3DVBLANKCALLBACK pCallback) { D3DDevice_SetVerticalBlankCallback(this, pCallback); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSwapCallback(__in D3DSWAPCALLBACK pCallback) { D3DDevice_SetSwapCallback(this, pCallback); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawTessellatedPrimitive(D3DTESSPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) { D3DDevice_DrawTessellatedVertices(this, PrimitiveType, StartVertex, D3DTESSVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::DrawIndexedTessellatedPrimitive(D3DTESSPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT StartIndex, UINT PrimitiveCount) { D3DDevice_DrawIndexedTessellatedVertices(this, PrimitiveType, BaseVertexIndex, StartIndex, D3DTESSVERTEXCOUNT(PrimitiveType, PrimitiveCount)); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::SetRingBufferParameters(__in_opt CONST D3DRING_BUFFER_PARAMETERS *pParameters) { return D3DDevice_SetRingBufferParameters(this, pParameters); } +D3DMINLINE D3DVOID WINAPI D3DDevice::XpsBegin(DWORD Flags) { D3DDevice_XpsBegin(this, Flags); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::XpsEnd() { return D3DDevice_XpsEnd(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::XpsSetCallback(__in D3DXpsCallback pCallback, __in_opt void* pContext, DWORD Flags) { D3DDevice_XpsSetCallback(this, pCallback, pContext, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::XpsSubmit(DWORD InstanceCount, __in_bcount(Size) CONST void* pData, DWORD Size) { D3DDevice_XpsSubmit(this, InstanceCount, pData, Size); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::XpsSetPredication(DWORD Predication) { D3DDevice_XpsSetPredication(this, Predication); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::XpsSetPredicationFromVisibility(HANDLE VisibilityHandle) { D3DDevice_XpsSetPredicationFromVisibility(this, VisibilityHandle); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::XpsSetPredicationFromQuery(__in_opt IDirect3DQuery9* pQuery) { D3DDevice_XpsSetPredicationFromQuery(this, pQuery); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::BeginVertices(D3DPRIMITIVETYPE PrimitiveType, UINT VertexCount, UINT VertexStreamZeroStride, __deref_out_bcount(VertexCount*VertexStreamZeroStride) void**ppVertexData) { return (*ppVertexData = D3DDevice_BeginVertices(this, PrimitiveType, VertexCount, VertexStreamZeroStride)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndVertices() { D3DDevice_EndVertices(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::BeginIndexedVertices(D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT NumVertices, UINT IndexCount, D3DFORMAT IndexDataFormat, UINT VertexStreamZeroStride, __deref_out void** ppIndexData, __deref_out_bcount(NumVertices*VertexStreamZeroStride) void** ppVertexData) { return D3DDevice_BeginIndexedVertices(this, PrimitiveType, BaseVertexIndex, NumVertices, IndexCount, IndexDataFormat, VertexStreamZeroStride, ppIndexData, ppVertexData); } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndIndexedVertices() { D3DDevice_EndIndexedVertices(this); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DDevice::InsertFence() { return D3DDevice_InsertFence(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::BlockOnFence(DWORD Fence) { D3DDevice_BlockOnFence(Fence); D3DVOIDRETURN; } +D3DMINLINE BOOL WINAPI D3DDevice::IsFencePending(DWORD Fence) { return D3DDevice_IsFencePending(Fence); } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetBlendState(DWORD RenderTargetIndex, D3DBLENDSTATE BlendState) { D3DDevice_SetBlendState(this, RenderTargetIndex, BlendState); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetBlendState(DWORD RenderTargetIndex, __out D3DBLENDSTATE* pBlendState) { D3DDevice_GetBlendState(this, RenderTargetIndex, pBlendState); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetVertexFetchConstant(UINT VertexFetchRegister, __in D3DVertexBuffer* pVertexBuffer, UINT Offset) { D3DDevice_SetVertexFetchConstant(this, VertexFetchRegister, pVertexBuffer, Offset); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetTextureFetchConstant(UINT TextureFetchRegister, __in D3DBaseTexture* pTexture) { D3DDevice_SetTextureFetchConstant(this, TextureFetchRegister, pTexture); D3DVOIDRETURN; } +D3DMINLINE float WINAPI D3DDevice::GetCounter(D3DCOUNTER CounterID) { return D3DDevice_GetCounter(this, CounterID);} +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSafeLevel(DWORD Flags, DWORD Level) { D3DDevice_SetSafeLevel(this, Flags, Level); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetSafeLevel(DWORD* pFlags, __out DWORD* pLevel) { D3DDevice_GetSafeLevel(this, pFlags, pLevel); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetHangCallback(D3DHANGCALLBACK pCallback) { D3DDevice_SetHangCallback(this, pCallback); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginConditionalSurvey(DWORD Identifier, DWORD Flags) { D3DDevice_BeginConditionalSurvey(this, Identifier, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndConditionalSurvey(DWORD Flags) {D3DDevice_EndConditionalSurvey(this, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginConditionalRendering(DWORD Identifier) { D3DDevice_BeginConditionalRendering(this, Identifier); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndConditionalRendering() { D3DDevice_EndConditionalRendering(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::PersistDisplay(__in D3DTexture* pFrontBuffer, __in_opt CONST D3DVIDEO_SCALER_PARAMETERS* pParameters) { return D3DDevice_PersistDisplay(this, pFrontBuffer, pParameters); } +D3DMINLINE HRESULT WINAPI D3DDevice::GetPersistedTexture(__deref_out D3DTexture** pFrontBuffer) { return D3DDevice_GetPersistedTexture(this, pFrontBuffer); } +D3DMINLINE D3DVOID WINAPI D3DDevice::Suspend() { D3DDevice_Suspend(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::Resume() { D3DDevice_Resume(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreatePerfCounters(__deref_out D3DPerfCounters** ppCounters, UINT NumInstances) { return (*ppCounters = D3DDevice_CreatePerfCounters(this, NumInstances)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EnablePerfCounters(BOOL Enable) { D3DDevice_EnablePerfCounters(this, Enable); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetPerfCounterEvents(__in CONST D3DPERFCOUNTER_EVENTS* pEvents, DWORD Flags) { D3DDevice_SetPerfCounterEvents(this, pEvents, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::QueryPerfCounters(__in D3DPerfCounters* pCounters, DWORD Flags) { D3DDevice_QueryPerfCounters(this, pCounters, Flags); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DDevice::GetNumPasses() { return D3DDevice_GetNumPasses(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetShaderInstructionAllocation(DWORD Flags, DWORD VertexShaderBase, DWORD PixelShaderBase) { D3DDevice_SetShaderInstructionAllocation(this, Flags, VertexShaderBase, PixelShaderBase); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetShaderGPRAllocation(DWORD Flags, DWORD VertexShaderCount, DWORD PixelShaderCount) { D3DDevice_SetShaderGPRAllocation(this, Flags, VertexShaderCount, PixelShaderCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetShaderGPRAllocation(__out DWORD* pFlags, __out DWORD* pVertexShaderCount, __out DWORD* pPixelShaderCount) { D3DDevice_GetShaderGPRAllocation(this, pFlags, pVertexShaderCount, pPixelShaderCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetScreenExtentQueryMode(D3DSCREENEXTENTQUERYMODE Mode) { D3DDevice_SetScreenExtentQueryMode(this, Mode); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetScreenExtentQueryMode(__out D3DSCREENEXTENTQUERYMODE* pMode) { D3DDevice_GetScreenExtentQueryMode(this, pMode); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginVertexShaderConstantF1(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount) { D3DDevice_BeginVertexShaderConstantF1(this, StartRegister, ppConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndVertexShaderConstantF1() { D3DDevice_EndShaderConstantF1(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginPixelShaderConstantF1(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, UINT Vector4fCount) { D3DDevice_BeginPixelShaderConstantF1(this, StartRegister, ppConstantData, Vector4fCount); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndPixelShaderConstantF1() { D3DDevice_EndShaderConstantF1(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::BeginVertexShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, UINT Vector4fCount) { return D3DDevice_BeginShaderConstantF4(this, FALSE, StartRegister, ppCachedConstantData, ppWriteCombinedConstantData, Vector4fCount); } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndVertexShaderConstantF4() { D3DDevice_EndShaderConstantF4(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::BeginPixelShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppCachedConstantData, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppWriteCombinedConstantData, UINT Vector4fCount) { return D3DDevice_BeginShaderConstantF4(this, TRUE, StartRegister, ppCachedConstantData, ppWriteCombinedConstantData, Vector4fCount); } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndPixelShaderConstantF4() { D3DDevice_EndShaderConstantF4(this); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DDevice::GetCurrentFence() { return D3DDevice_GetCurrentFence(); } +D3DMINLINE D3DVOID WINAPI D3DDevice::InvalidateGpuCache(__in_bcount(Size) void* pBaseAddress, DWORD Size, DWORD Flags) { D3DDevice_InvalidateGpuCache(this, pBaseAddress, Size, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::InvalidateResourceGpuCache(__in D3DResource* pResource, DWORD Flags) { D3DDevice_InvalidateResourceGpuCache(this, pResource, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::FlushHiZStencil(D3DFHZS_FLUSHTYPE FlushType) { D3DDevice_FlushHiZStencil(this, FlushType); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::UnsetAll() { D3DDevice_UnsetAll(this); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DDevice::GetDeviceState() { return D3DDevice_GetDeviceState(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetBlockCallback(DWORD Flags, __in_opt D3DBLOCKCALLBACK pCallback) { D3DDevice_SetBlockCallback(this, Flags, pCallback); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSurfaces(__in CONST D3DSURFACES* pSurfaces, DWORD Flags) { D3DDevice_SetSurfaces(this, pSurfaces, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::BeginCommandBuffer(__in D3DCommandBuffer* pCommandBuffer, DWORD Flags, __in_opt CONST D3DTAGCOLLECTION* pInheritTags, __in_opt CONST D3DTAGCOLLECTION* pPersistTags, __in_opt CONST D3DRECT* pTilingRects, DWORD TileCount) { D3DDevice_BeginCommandBuffer(this, pCommandBuffer, Flags, pInheritTags, pPersistTags, pTilingRects, TileCount); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::EndCommandBuffer() { return D3DDevice_EndCommandBuffer(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::RunCommandBuffer(__in D3DCommandBuffer* pCommandBuffer, DWORD PredicationSelect) { D3DDevice_RunCommandBuffer(this, pCommandBuffer, PredicationSelect); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::InsertAsyncCommandBufferCall(__in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, DWORD PredicationSelect, DWORD Flags) { return D3DDevice_InsertAsyncCommandBufferCall(this, pAsyncCommandBufferCall, PredicationSelect, Flags); } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetCommandBufferPredication(DWORD TilePredication, DWORD RunPredication) { D3DDevice_SetCommandBufferPredication(this, TilePredication, RunPredication); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DDevice::InsertMarker() { return D3DDevice_InsertMarker(this); } +D3DMINLINE D3DVOID WINAPI D3DDevice::Nop(DWORD Count) { D3DDevice_Nop(this, Count); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::QuerySwapStatus(__out D3DSWAP_STATUS* pSwapStatus) { D3DDevice_QuerySwapStatus(this, pSwapStatus); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetViewportF(__in CONST D3DVIEWPORTF9* pViewportF) { D3DDevice_SetViewportF(this, pViewportF); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::GetViewportF(__out D3DVIEWPORTF9* pViewportF) { D3DDevice_GetViewportF(this, pViewportF); D3DVOIDRETURN; } +D3DMINLINE HANDLE WINAPI D3DDevice::BeginVisibilitySurvey(DWORD Flags) { return D3DDevice_BeginVisibilitySurvey(this, Flags); } +D3DMINLINE D3DVOID WINAPI D3DDevice::EndVisibilitySurvey(HANDLE VisibilityHandle) { D3DDevice_EndVisibilitySurvey(this, VisibilityHandle); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DDevice::SetSwapMode(BOOL Asynchronous) { D3DDevice_SetSwapMode(this, Asynchronous); D3DVOIDRETURN; } +D3DMINLINE D3DASYNCBLOCK WINAPI D3DDevice::InsertBlockOnAsyncResources(DWORD WriteCount, __in_ecount_opt(WriteCount) D3DResource* CONST* pWriteResourceList, DWORD ReadCount, __in_ecount_opt(ReadCount) D3DResource* CONST* pReadResourceList, DWORD Flags) { return D3DDevice_InsertBlockOnAsyncResources(this, WriteCount, pWriteResourceList, ReadCount, pReadResourceList, Flags); } +D3DMINLINE D3DVOID WINAPI D3DDevice::SignalAsyncResources(D3DASYNCBLOCK AsyncBlock) { D3DDevice_SignalAsyncResources(this, AsyncBlock); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateAsyncCommandBufferCall(D3DTAGCOLLECTION* pInheritTags, D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags, D3DAsyncCommandBufferCall** ppAsyncCall ) { return (*ppAsyncCall = D3DDevice_CreateAsyncCommandBufferCall(this, pInheritTags, pPersistTags, NumSegments, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreatePerfCounterBatch(UINT NumSlots, UINT NumTiles, DWORD Flags, __deref_out D3DPerfCounterBatch** ppBatch) { return (*ppBatch = D3DDevice_CreatePerfCounterBatch(this, NumSlots, NumTiles, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE HRESULT WINAPI D3DDevice::CreateOcclusionQueryBatch(UINT NumSlots, UINT NumTiles, __deref_out D3DOcclusionQueryBatch** ppBatch) { return (*ppBatch = D3DDevice_CreateOcclusionQueryBatch(this, NumSlots, NumTiles)) != NULL ? S_OK : E_OUTOFMEMORY; } + +D3DMINLINE void WINAPI D3DDevice::GpuOwn(D3DTAG Tag) { D3DDevice_GpuOwn(this, Tag); } +D3DMINLINE void WINAPI D3DDevice::GpuOwnSubset(D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) { D3DDevice_GpuOwnSubset(this, Tag, StartIndex, EndIndex); } +D3DMINLINE void WINAPI D3DDevice::GpuOwnVertexShaderConstantF(DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuOwnVertexShaderConstantF(this, StartRegister, Vector4fCount); } +D3DMINLINE void WINAPI D3DDevice::GpuOwnPixelShaderConstantF(DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuOwnPixelShaderConstantF(this, StartRegister, Vector4fCount); } +D3DMINLINE void WINAPI D3DDevice::GpuOwnShaders() { D3DDevice_GpuOwnShaders(this); } +D3DMINLINE void WINAPI D3DDevice::GpuDisown(D3DTAG Tag) { D3DDevice_GpuDisown(this, Tag); } +D3DMINLINE void WINAPI D3DDevice::GpuDisownSubset(D3DTAG Tag, DWORD StartIndex, DWORD EndIndex) { D3DDevice_GpuDisownSubset(this, Tag, StartIndex, EndIndex); } +D3DMINLINE void WINAPI D3DDevice::GpuDisownVertexShaderConstantF(DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuDisownVertexShaderConstantF(this, StartRegister, Vector4fCount); } +D3DMINLINE void WINAPI D3DDevice::GpuDisownPixelShaderConstantF(DWORD StartRegister, DWORD Vector4fCount) { D3DDevice_GpuDisownPixelShaderConstantF(this, StartRegister, Vector4fCount); } +D3DMINLINE void WINAPI D3DDevice::GpuDisownShaders() { D3DDevice_GpuDisownShaders(this); } +D3DMINLINE void WINAPI D3DDevice::GpuDisownAll() { D3DDevice_GpuDisownAll(this); } +D3DMINLINE HRESULT WINAPI D3DDevice::GpuBeginVertexShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, DWORD Vector4fCount) { return (*ppConstantData = D3DDevice_GpuBeginShaderConstantF4(this, FALSE, StartRegister, Vector4fCount)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE void WINAPI D3DDevice::GpuEndVertexShaderConstantF4() { D3DDevice_GpuEndShaderConstantF4(this); } +D3DMINLINE HRESULT WINAPI D3DDevice::GpuBeginPixelShaderConstantF4(UINT StartRegister, __deref_out_ecount(Vector4fCount) D3DVECTOR4** ppConstantData, DWORD Vector4fCount) { return (*ppConstantData = D3DDevice_GpuBeginShaderConstantF4(this, TRUE, StartRegister, Vector4fCount)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE void WINAPI D3DDevice::GpuEndPixelShaderConstantF4() { D3DDevice_GpuEndShaderConstantF4(this); } +D3DMINLINE void WINAPI D3DDevice::GpuLoadVertexShaderConstantF4(UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors) { D3DDevice_GpuLoadShaderConstantF4(this, FALSE, StartRegister, Vector4fCount, pConstantBuffer, OffsetInVectors); } +D3DMINLINE void WINAPI D3DDevice::GpuLoadPixelShaderConstantF4(UINT StartRegister, DWORD Vector4fCount, __in D3DConstantBuffer* pConstantBuffer, DWORD OffsetInVectors) { D3DDevice_GpuLoadShaderConstantF4(this, TRUE, StartRegister, Vector4fCount, pConstantBuffer, OffsetInVectors); } +D3DMINLINE void WINAPI D3DDevice::GpuLoadVertexShaderConstantF4Pointer(UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount) { D3DDevice_GpuLoadShaderConstantF4Pointer(this, FALSE, StartRegister, pConstantData, Vector4fCount); } +D3DMINLINE void WINAPI D3DDevice::GpuLoadPixelShaderConstantF4Pointer(UINT StartRegister, __in_bcount(4*sizeof(FLOAT)*Vector4fCount) CONST void* pConstantData, DWORD Vector4fCount) { D3DDevice_GpuLoadShaderConstantF4Pointer(this, TRUE, StartRegister, pConstantData, Vector4fCount); } +D3DMINLINE void WINAPI D3DDevice::GpuLoadShaders(__in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants) { D3DDevice_GpuLoadShaders(this, pVertexShader, pPixelShader, pFlowConstants); } +D3DMINLINE void WINAPI D3DDevice::GpuLoadShadersFast(__in D3DVertexShader* pVertexShader, __in_opt D3DPixelShader* pPixelShader, __in_opt CONST GPUFLOW_CONSTANTS* pFlowConstants, DWORD Flags) { D3DDevice_GpuLoadShadersFast(this, pVertexShader, pPixelShader, pFlowConstants, Flags); } +D3DMINLINE void WINAPI D3DDevice::GpuSetVertexFetchConstant(DWORD VertexFetchRegister, __in_opt D3DVertexBuffer* pVertexBuffer0, DWORD OffsetInBytes0, __in_opt D3DVertexBuffer* pVertexBuffer1, DWORD OffsetInBytes1, __in_opt D3DVertexBuffer* pVertexBuffer2, DWORD OffsetInBytes2) { D3DDevice_GpuSetVertexFetchConstant(this, VertexFetchRegister, pVertexBuffer0, OffsetInBytes0, pVertexBuffer1, OffsetInBytes1, pVertexBuffer2, OffsetInBytes2); } +D3DMINLINE void WINAPI D3DDevice::GpuSetTextureFetchConstant(DWORD TextureFetchRegister, __in D3DBaseTexture* pTexture) { D3DDevice_GpuSetTextureFetchConstant(this, TextureFetchRegister, pTexture); } +D3DMINLINE void WINAPI D3DDevice::GpuSetColorMask(__in const GPU_COLORMASK* pColorMask) { D3DDevice_GpuSetColorMask(this, pColorMask->dword); } +D3DMINLINE void WINAPI D3DDevice::GpuSetBlendFactor(__in const D3DCOLORVALUE* pColor) { D3DDevice_GpuSetBlendFactor(this, pColor->r, pColor->g, pColor->b, pColor->a); } +D3DMINLINE void WINAPI D3DDevice::GpuSetAlphaRef(float Ref) { D3DDevice_GpuSetAlphaRef(this, Ref); } +D3DMINLINE void WINAPI D3DDevice::GpuSetBlendControl(DWORD RenderTargetIndex, __in const GPU_BLENDCONTROL* pBlendControl) { D3DDevice_GpuSetBlendControl(this, RenderTargetIndex, pBlendControl->dword); } +D3DMINLINE void WINAPI D3DDevice::GpuSetColorControl(__in const GPU_COLORCONTROL* pColorControl) { D3DDevice_GpuSetColorControl(this, pColorControl->dword); } + +// Make the PIX methods disappear on retail builds +// +D3DMINLINE DWORD WINAPI D3DDevice::PixBeginNamedEvent(DWORD Color, __in_z CONST char *szName, ...) +{ +#if defined(USE_D3D_PIX_METHODS) + va_list arglist; + va_start(arglist, szName); + return D3DDevice_PixBeginNamedEvent(this, Color, szName, arglist); +#else + return 0; +#endif +} + +D3DMINLINE DWORD WINAPI D3DDevice::PixEndNamedEvent() +{ +#if defined(USE_D3D_PIX_METHODS) + return D3DDevice_PixEndNamedEvent(this); +#else + return 0; +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixSetMarker(DWORD Color, __in_z CONST char *szName, ...) +{ +#if defined(USE_D3D_PIX_METHODS) + va_list arglist; + va_start(arglist, szName); + D3DDevice_PixSetMarker(this, Color, szName, arglist); +#endif +} + +// Make the PIX Texture Tracking methods disappear on retail and x86 builds +// +D3DMINLINE void WINAPI D3DDevice::PixIgnoreTexture(__in D3DBaseTexture* pTexture) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixIgnoreTexture(this, pTexture); +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixStopIgnoringTexture(__in D3DBaseTexture* pTexture) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixStopIgnoringTexture(this, pTexture); +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixIgnoreMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixIgnoreMemoryRange(this, pBaseAddress, Size); +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixStopIgnoringMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixStopIgnoringMemoryRange(this, pBaseAddress, Size); +#endif +} + +D3DMINLINE HRESULT WINAPI D3DDevice::PixSetTextureName(__in D3DBaseTexture* pTexture, __in_z const char* pName) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + return D3DDevice_PixSetTextureName(this, pTexture, pName); +#else + return S_OK; +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixReportNewTexture(__in D3DBaseTexture* pTexture) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportNewTexture(this, pTexture); +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixReportDeletedTexture(__in D3DBaseTexture* pTexture, BOOL BaseDeleted, BOOL MipDeleted) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportDeletedTexture(this, pTexture, BaseDeleted, MipDeleted); +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixReportMovedMemoryRange(__in_bcount(Size) const void* pDestinationAddress, __in_bcount(Size) const void* pSourceAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportMovedMemoryRange(this, pDestinationAddress, pSourceAddress, Size); +#endif +} + +D3DMINLINE void WINAPI D3DDevice::PixReportFreedMemoryRange(__in_bcount(Size) const void* pAddress, DWORD Size) +{ +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + D3DDevice_PixReportFreedMemoryRange(this, pAddress, Size); +#endif +} + +#endif __cplusplus + +/* D3DPerfCounters */ + +ULONG WINAPI D3DPerfCounters_AddRef(__in D3DPerfCounters *pThis); +ULONG WINAPI D3DPerfCounters_Release(__in D3DPerfCounters *pThis); +void WINAPI D3DPerfCounters_GetDevice(__in D3DPerfCounters *pThis, __deref_out D3DDevice **ppDevice); +BOOL WINAPI D3DPerfCounters_IsBusy(__in D3DPerfCounters *pThis); +void WINAPI D3DPerfCounters_BlockUntilNotBusy(__in D3DPerfCounters *pThis); +UINT WINAPI D3DPerfCounters_GetNumPasses(__in D3DPerfCounters* pThis); +HRESULT WINAPI D3DPerfCounters_GetValues(__in D3DPerfCounters *pThis, __out D3DPERFCOUNTER_VALUES* pValues, UINT PassIndex, __out_opt DWORD* pPassType); + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3DPerfCounters9_AddRef(__in D3DPerfCounters *pThis) { return D3DPerfCounters_AddRef(pThis); } +D3DINLINE ULONG WINAPI IDirect3DPerfCounters9_Release(__in D3DPerfCounters *pThis) { return D3DPerfCounters_Release(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DPerfCounters9_GetDevice(__in D3DPerfCounters *pThis, __deref_out D3DDevice **ppDevice) { D3DPerfCounters_GetDevice(pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE BOOL WINAPI IDirect3DPerfCounters9_IsBusy(__in D3DPerfCounters *pThis) { return D3DPerfCounters_IsBusy(pThis); } +D3DINLINE void WINAPI IDirect3DPerfCounters9_BlockUntilNotBusy(__in D3DPerfCounters *pThis) { D3DPerfCounters_BlockUntilNotBusy(pThis); } +D3DINLINE UINT WINAPI IDirect3DPerfCounters9_GetNumPasses(__in D3DPerfCounters* pThis) { return D3DPerfCounters_GetNumPasses(pThis); } +D3DINLINE HRESULT WINAPI IDirect3DPerfCounters9_GetValues(__in D3DPerfCounters *pThis, __out D3DPERFCOUNTER_VALUES* pValues, UINT PassIndex, __out_opt DWORD* pPassType) { return D3DPerfCounters_GetValues(pThis, pValues, PassIndex, pPassType); } + +#ifdef __cplusplus + +D3DMINLINE ULONG WINAPI D3DPerfCounters::AddRef() { return D3DPerfCounters_AddRef(this); } +D3DMINLINE ULONG WINAPI D3DPerfCounters::Release() { return D3DPerfCounters_Release(this); } +D3DMINLINE D3DVOID WINAPI D3DPerfCounters::GetDevice(__deref_out D3DDevice **ppDevice) { D3DPerfCounters_GetDevice(this, ppDevice); D3DVOIDRETURN; } +D3DMINLINE BOOL WINAPI D3DPerfCounters::IsBusy() { return D3DPerfCounters_IsBusy(this); } +D3DMINLINE void WINAPI D3DPerfCounters::BlockUntilNotBusy() { D3DPerfCounters_BlockUntilNotBusy(this); } +D3DMINLINE UINT WINAPI D3DPerfCounters::GetNumPasses() {return D3DPerfCounters_GetNumPasses(this); } +D3DMINLINE HRESULT WINAPI D3DPerfCounters::GetValues(__out D3DPERFCOUNTER_VALUES* pValues, UINT InstanceIndex, __out DWORD* pMask) { return D3DPerfCounters_GetValues(this, pValues, InstanceIndex, pMask); } + +#endif + +/* D3DPerfCounterBatch */ + +void WINAPI D3DPerfCounterBatch_Reset(__in D3DPerfCounterBatch *pThis); +UINT WINAPI D3DPerfCounterBatch_Issue(__in D3DPerfCounterBatch *pThis, DWORD PerfCounterIndex, DWORD Flags); +__out void* WINAPI D3DPerfCounterBatch_Lock(__in D3DPerfCounterBatch *pThis); +void WINAPI D3DPerfCounterBatch_Unlock(__in D3DPerfCounterBatch *pThis); +void WINAPI D3DPerfCounterBatch_ValidateSlot(__in D3DPerfCounterBatch *pThis, DWORD Slot, DWORD Flags); + +D3DMINLINE UINT WINAPI D3DPerfCounterBatch_GetNumSlotsUsed(__in D3DPerfCounterBatch *pThis) +{ + return pThis->m_SlotsUsed; +} + +D3DMINLINE UINT WINAPI D3DPerfCounterBatch_GetValue32(__in D3DPerfCounterBatch *pThis, DWORD Slot) +{ + UINT sum = 0; + UINT passes = pThis->m_NumPasses; + UINT* pData = (UINT*)(pThis->m_pCachedReadOnlyBase + Slot * pThis->m_SlotSize); + +#if defined(_DEBUG) + D3DPerfCounterBatch_ValidateSlot(pThis, Slot, 0); +#endif + + for(; passes != 0; --passes, ++pData) + { + sum += *pData; + } + return sum; +} + +D3DMINLINE UINT64 WINAPI D3DPerfCounterBatch_GetValue64(__in D3DPerfCounterBatch *pThis, DWORD Slot) +{ + UINT64 sum = 0; + UINT passes = pThis->m_NumPasses; + UINT64* pData = (UINT64*)(pThis->m_pCachedReadOnlyBase + Slot * pThis->m_SlotSize); + +#if defined(_DEBUG) + D3DPerfCounterBatch_ValidateSlot(pThis, Slot, D3DPERFCOUNTERBATCH_64BIT); +#endif + + for(; passes != 0; --passes, ++pData) + { + sum += *pData; + } + return sum; +} + +// Compatibility wrappers. + +D3DINLINE void WINAPI IDirect3DPerfCounterBatch9_Reset(__in D3DPerfCounterBatch *pThis) { D3DPerfCounterBatch_Reset(pThis); } +D3DINLINE UINT WINAPI IDirect3DPerfCounterBatch9_Issue(__in D3DPerfCounterBatch *pThis, DWORD PerfCounterIndex, DWORD Flags) { return D3DPerfCounterBatch_Issue(pThis, PerfCounterIndex, Flags); } +D3DINLINE UINT WINAPI IDirect3DPerfCounterBatch9_GetNumSlotsUsed(__in D3DPerfCounterBatch* pThis) { return D3DPerfCounterBatch_GetNumSlotsUsed(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DPerfCounterBatch9_Lock(__in D3DPerfCounterBatch *pThis, __deref_out void** ppData) { *ppData = D3DPerfCounterBatch_Lock(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DPerfCounterBatch9_Unlock(__in D3DPerfCounterBatch *pThis) { D3DPerfCounterBatch_Unlock(pThis); D3DVOIDRETURN; } +D3DINLINE UINT WINAPI IDirect3DPerfCounterBatch9_GetValue32(__in D3DPerfCounterBatch *pThis, DWORD Slot) { return D3DPerfCounterBatch_GetValue32(pThis, Slot); } +D3DINLINE UINT64 WINAPI IDirect3DPerfCounterBatch9_GetValue64(__in D3DPerfCounterBatch *pThis, DWORD Slot) { return D3DPerfCounterBatch_GetValue64(pThis, Slot); } + +#ifdef __cplusplus + +D3DMINLINE void WINAPI D3DPerfCounterBatch::Reset() { D3DPerfCounterBatch_Reset(this); } +D3DMINLINE UINT WINAPI D3DPerfCounterBatch::Issue(DWORD PerfCounterIndex, DWORD Flags) { return D3DPerfCounterBatch_Issue(this, PerfCounterIndex, Flags); } +D3DMINLINE UINT WINAPI D3DPerfCounterBatch::GetNumSlotsUsed() { return D3DPerfCounterBatch_GetNumSlotsUsed(this); } +D3DMINLINE D3DVOID WINAPI D3DPerfCounterBatch::Lock(__deref_out void** ppData) { *ppData = D3DPerfCounterBatch_Lock(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DPerfCounterBatch::Unlock() { D3DPerfCounterBatch_Unlock(this); D3DVOIDRETURN; } +D3DMINLINE UINT WINAPI D3DPerfCounterBatch::GetValue32(DWORD Slot) { return D3DPerfCounterBatch_GetValue32(this, Slot); } +D3DMINLINE UINT64 WINAPI D3DPerfCounterBatch::GetValue64(DWORD Slot) { return D3DPerfCounterBatch_GetValue64(this, Slot); } + +#endif + +/* D3DOcclusionQueryBatch */ + +void WINAPI D3DOcclusionQueryBatch_Reset(__in D3DOcclusionQueryBatch *pThis); +UINT WINAPI D3DOcclusionQueryBatch_Issue(__in D3DOcclusionQueryBatch *pThis); +__out void* WINAPI D3DOcclusionQueryBatch_Lock(__in D3DOcclusionQueryBatch *pThis); +void WINAPI D3DOcclusionQueryBatch_Unlock(__in D3DOcclusionQueryBatch *pThis); +void WINAPI D3DOcclusionQueryBatch_ValidateSlot(__in D3DOcclusionQueryBatch *pThis, DWORD Slot); + +D3DMINLINE UINT WINAPI D3DOcclusionQueryBatch_GetNumSlotsUsed(__in D3DOcclusionQueryBatch *pThis) +{ + return pThis->m_SlotsUsed; +} + +D3DMINLINE void WINAPI D3DOcclusionQueryBatch_GetOcclusionStats(__in D3DOcclusionQueryBatch *pThis, DWORD Slot, __out D3DOCCLUSIONSTATS* pOcclusionStats) +{ + UINT passes = pThis->m_NumTiles; + GPU_SAMPLECOUNT* pData = (GPU_SAMPLECOUNT*)(pThis->m_pCachedReadOnlyBase + Slot * pThis->m_SlotSize); + +#if defined(_DEBUG) + D3DOcclusionQueryBatch_ValidateSlot(pThis, Slot); +#endif + + memset(pOcclusionStats, 0, sizeof(D3DOCCLUSIONSTATS)); + + for(; passes != 0; --passes, ++pData) + { + pOcclusionStats->Total += _byteswap_ulong(pData->Total[0]) + _byteswap_ulong(pData->Total[1]); + pOcclusionStats->ZPass += _byteswap_ulong(pData->ZPass[0]) + _byteswap_ulong(pData->ZPass[1]); + pOcclusionStats->ZFail += _byteswap_ulong(pData->ZFail[0]) + _byteswap_ulong(pData->ZFail[1]); + pOcclusionStats->StencilFail += _byteswap_ulong(pData->StencilFail[0]) + _byteswap_ulong(pData->StencilFail[1]); + } +} + +D3DMINLINE UINT WINAPI D3DOcclusionQueryBatch_GetPixelCount(__in D3DOcclusionQueryBatch *pThis, DWORD Slot) +{ + UINT passes = pThis->m_NumTiles; + UINT pixelCount = 0; + GPU_SAMPLECOUNT* pData = (GPU_SAMPLECOUNT*)(pThis->m_pCachedReadOnlyBase + Slot * pThis->m_SlotSize); + +#if defined(_DEBUG) + D3DOcclusionQueryBatch_ValidateSlot(pThis, Slot); +#endif + + for(; passes != 0; --passes, ++pData) + { + pixelCount += _byteswap_ulong(pData->ZPass[0]) + _byteswap_ulong(pData->ZPass[1]); + } + return pixelCount; +} + +// Compatibility wrappers. + +D3DINLINE void WINAPI IDirect3DOcclusionQueryBatch9_Reset(__in D3DOcclusionQueryBatch *pThis) { D3DOcclusionQueryBatch_Reset(pThis); } +D3DINLINE UINT WINAPI IDirect3DOcclusionQueryBatch9_Issue(__in D3DOcclusionQueryBatch *pThis) { return D3DOcclusionQueryBatch_Issue(pThis); } +D3DINLINE UINT WINAPI IDirect3DOcclusionQueryBatch9_GetNumSlotsUsed(__in D3DOcclusionQueryBatch *pThis) { D3DOcclusionQueryBatch_GetNumSlotsUsed(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DOcclusionQueryBatch9_Lock(__in D3DOcclusionQueryBatch *pThis, __deref_out void** ppData) { *ppData = D3DOcclusionQueryBatch_Lock(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DOcclusionQueryBatch9_Unlock(__in D3DOcclusionQueryBatch *pThis) { D3DOcclusionQueryBatch_Unlock(pThis); D3DVOIDRETURN; } +D3DINLINE void WINAPI IDirect3DOcclusionQueryBatch9_GetOcclusionStats(__in D3DOcclusionQueryBatch* pThis, DWORD Slot, __out D3DOCCLUSIONSTATS* pOcclusionStats) { D3DOcclusionQueryBatch_GetOcclusionStats(pThis, Slot, pOcclusionStats); } +D3DINLINE UINT WINAPI IDirect3DOcclusionQueryBatch9_GetPixelCount(__in D3DOcclusionQueryBatch* pThis, DWORD Slot) { return D3DOcclusionQueryBatch_GetPixelCount(pThis, Slot); } + +#ifdef __cplusplus + +D3DMINLINE void WINAPI D3DOcclusionQueryBatch::Reset() { D3DOcclusionQueryBatch_Reset(this); } +D3DMINLINE UINT WINAPI D3DOcclusionQueryBatch::Issue() { return D3DOcclusionQueryBatch_Issue(this); } +D3DMINLINE UINT WINAPI D3DOcclusionQueryBatch::GetNumSlotsUsed() { return D3DOcclusionQueryBatch_GetNumSlotsUsed(this); } +D3DMINLINE D3DVOID WINAPI D3DOcclusionQueryBatch::Lock(__deref_out void** ppData) { *ppData = D3DOcclusionQueryBatch_Lock(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DOcclusionQueryBatch::Unlock() { D3DOcclusionQueryBatch_Unlock(this); D3DVOIDRETURN; } +D3DMINLINE void WINAPI D3DOcclusionQueryBatch::GetOcclusionStats(DWORD Slot, __out D3DOCCLUSIONSTATS* pOcclusionStats) { D3DOcclusionQueryBatch_GetOcclusionStats(this, Slot, pOcclusionStats); } +D3DMINLINE UINT WINAPI D3DOcclusionQueryBatch::GetPixelCount(DWORD Slot) { return D3DOcclusionQueryBatch_GetPixelCount(this, Slot); } + +#endif + +/* D3DQuery */ + +ULONG WINAPI D3DQuery_AddRef(__in D3DQuery *pThis); +ULONG WINAPI D3DQuery_Release(__in D3DQuery *pThis); +void WINAPI D3DQuery_GetDevice(__in D3DQuery *pThis, __deref_out D3DDevice **ppDevice); +D3DQUERYTYPE WINAPI D3DQuery_GetType(__in D3DQuery *pThis); +DWORD WINAPI D3DQuery_GetDataSize(__in D3DQuery *pThis); +void WINAPI D3DQuery_Issue(__in D3DQuery *pThis, DWORD IssueFlags); +HRESULT WINAPI D3DQuery_GetData(__in D3DQuery *pThis, __out_bcount(Size) void* pData, DWORD Size, DWORD GetDataFlags); + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3DQuery9_AddRef(__in D3DQuery *pThis) { return D3DQuery_AddRef(pThis); } +D3DINLINE ULONG WINAPI IDirect3DQuery9_Release(__in D3DQuery *pThis) { return D3DQuery_Release(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DQuery9_GetDevice(__in D3DQuery *pThis, __deref_out D3DDevice **ppDevice) { D3DQuery_GetDevice(pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DQUERYTYPE WINAPI IDirect3DQuery9_GetType(__in D3DQuery *pThis) { return D3DQuery_GetType(pThis); } +D3DINLINE DWORD WINAPI IDirect3DQuery9_GetDataSize(__in D3DQuery *pThis) { return D3DQuery_GetDataSize(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DQuery9_Issue(__in D3DQuery *pThis, DWORD IssueFlags) { D3DQuery_Issue(pThis, IssueFlags); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DQuery9_GetData(__in D3DQuery *pThis, __out_bcount(Size) void* pData, DWORD Size, DWORD GetDataFlags) { return D3DQuery_GetData(pThis, pData, Size, GetDataFlags); } + + +#ifdef __cplusplus + +D3DMINLINE ULONG WINAPI D3DQuery::AddRef() { return D3DQuery_AddRef(this); } +D3DMINLINE ULONG WINAPI D3DQuery::Release() { return D3DQuery_Release(this); } +D3DMINLINE D3DVOID WINAPI D3DQuery::GetDevice(__deref_out D3DDevice **ppDevice) { D3DQuery_GetDevice(this, ppDevice); D3DVOIDRETURN; } +D3DMINLINE D3DQUERYTYPE WINAPI D3DQuery::GetType() { return D3DQuery_GetType(this); } +D3DMINLINE DWORD WINAPI D3DQuery::GetDataSize() { return D3DQuery_GetDataSize(this); } +D3DMINLINE D3DVOID WINAPI D3DQuery::Issue(DWORD IssueFlags) { D3DQuery_Issue(this, IssueFlags); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DQuery::GetData(__out_bcount(Size) void* pData, DWORD Size, DWORD GetDataFlags) { return D3DQuery_GetData(this, pData, Size, GetDataFlags); } + +#endif + +/* D3DStateBlock */ + +ULONG WINAPI D3DStateBlock_AddRef(__in D3DStateBlock *pThis); +ULONG WINAPI D3DStateBlock_Release(__in D3DStateBlock *pThis); +void WINAPI D3DStateBlock_GetDevice(__in D3DStateBlock *pThis, __deref_out D3DDevice **ppDevice); +void WINAPI D3DStateBlock_Capture(__in D3DStateBlock *pThis); +void WINAPI D3DStateBlock_Apply(__in D3DStateBlock *pThis); + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3DStateBlock9_AddRef(__in D3DStateBlock *pThis) { return D3DStateBlock_AddRef(pThis); } +D3DINLINE ULONG WINAPI IDirect3DStateBlock9_Release(__in D3DStateBlock *pThis) { return D3DStateBlock_Release(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DStateBlock9_GetDevice(__in D3DStateBlock *pThis, __deref_out D3DDevice **ppDevice) { D3DStateBlock_GetDevice(pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DStateBlock9_Capture(__in D3DStateBlock *pThis) { D3DStateBlock_Capture(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DStateBlock9_Apply(__in D3DStateBlock *pThis) { D3DStateBlock_Apply(pThis); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE ULONG WINAPI D3DStateBlock::AddRef() { return D3DStateBlock_AddRef(this); } +D3DMINLINE ULONG WINAPI D3DStateBlock::Release() { return D3DStateBlock_Release(this); } +D3DMINLINE D3DVOID WINAPI D3DStateBlock::GetDevice(__deref_out D3DDevice **ppDevice) { D3DStateBlock_GetDevice(this, ppDevice); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DStateBlock::Capture() { D3DStateBlock_Capture(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DStateBlock::Apply() { D3DStateBlock_Apply(this); D3DVOIDRETURN; } + +#endif + +/* D3DResource */ + +ULONG WINAPI D3DResource_AddRef(__in D3DResource *pThis); +ULONG WINAPI D3DResource_Release(__in D3DResource *pThis); +void WINAPI D3DResource_GetDevice(__in D3DResource *pThis, __deref_out D3DDevice **ppDevice); +D3DRESOURCETYPE WINAPI D3DResource_GetType(__in D3DResource *pThis); +BOOL WINAPI D3DResource_IsBusy(__in D3DResource *pThis); +BOOL WINAPI D3DResource_IsSet(__in D3DResource *pThis, __in D3DDevice *pDevice); +void WINAPI D3DResource_BlockUntilNotBusy(__in D3DResource *pThis); + +D3DINLINE void WINAPI D3DResource_SetIdentifier(__in D3DResource *pThis, DWORD Identifier) { pThis->Identifier = Identifier; } +D3DINLINE DWORD WINAPI D3DResource_GetIdentifier(__in D3DResource *pThis) { return pThis->Identifier; } + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3DResource9_AddRef(__in D3DResource *pThis) { return D3DResource_AddRef(pThis); } +D3DINLINE ULONG WINAPI IDirect3DResource9_Release(__in D3DResource *pThis) { return D3DResource_Release(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DResource9_GetDevice(__in D3DResource *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice(pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DResource9_GetType(__in D3DResource *pThis) { return D3DResource_GetType(pThis); } +D3DINLINE BOOL WINAPI IDirect3DResource9_IsBusy(__in D3DResource *pThis) { return D3DResource_IsBusy(pThis); } +D3DINLINE BOOL WINAPI IDirect3DResource9_IsSet(__in D3DResource *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet(pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DResource9_BlockUntilNotBusy(__in D3DResource *pThis) { D3DResource_BlockUntilNotBusy(pThis); } +D3DINLINE void WINAPI IDirect3DResource9_SetIdentifier(__in D3DResource *pThis, DWORD Identifier) { D3DResource_SetIdentifier(pThis, Identifier); } +D3DINLINE DWORD WINAPI IDirect3DResource9_GetIdentifier(__in D3DResource *pThis) { return D3DResource_GetIdentifier(pThis); } + +#ifdef __cplusplus + +D3DMINLINE ULONG WINAPI D3DResource::AddRef() { return D3DResource_AddRef(this); } +D3DMINLINE ULONG WINAPI D3DResource::Release() { return D3DResource_Release(this); } +D3DMINLINE D3DVOID WINAPI D3DResource::GetDevice(__deref_out D3DDevice **ppDevice) { D3DResource_GetDevice(this, ppDevice); D3DVOIDRETURN; } +D3DMINLINE D3DRESOURCETYPE WINAPI D3DResource::GetType() { return D3DResource_GetType(this); } +D3DMINLINE BOOL WINAPI D3DResource::IsBusy() { return D3DResource_IsBusy(this); } +D3DMINLINE BOOL WINAPI D3DResource::IsSet(__in D3DDevice *pDevice) { return D3DResource_IsSet(this, pDevice); } +D3DMINLINE void WINAPI D3DResource::BlockUntilNotBusy() { D3DResource_BlockUntilNotBusy(this); } +D3DMINLINE void WINAPI D3DResource::SetIdentifier(DWORD Identifier) { D3DResource_SetIdentifier(this, Identifier); } +D3DMINLINE DWORD WINAPI D3DResource::GetIdentifier() { return D3DResource_GetIdentifier(this); } + +#endif __cplusplus + +/* D3DBaseTexture */ + +D3DINLINE ULONG WINAPI D3DBaseTexture_AddRef(__in D3DBaseTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DBaseTexture_Release(__in D3DBaseTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DBaseTexture_GetDevice(__in D3DBaseTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DBaseTexture_GetType(__in D3DBaseTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DBaseTexture_IsBusy(__in D3DBaseTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DBaseTexture_IsSet(__in D3DBaseTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DBaseTexture_BlockUntilNotBusy(__in D3DBaseTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +DWORD WINAPI D3DBaseTexture_GetLevelCount(__in D3DBaseTexture *pThis); +void WINAPI D3DBaseTexture_GetTailDesc(__in D3DBaseTexture *pThis, __out D3DMIPTAIL_DESC *pDesc); +void WINAPI D3DBaseTexture_LockTail(__in D3DBaseTexture *pThis, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); +void WINAPI D3DBaseTexture_AsyncLockTail(__in D3DBaseTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags); +void WINAPI D3DBaseTexture_UnlockTail(__in D3DBaseTexture *pThis, UINT ArrayIndex); + +// Compatibility wrappers. + +D3DINLINE ULONG WINAPI IDirect3DBaseTexture9_AddRef(__in D3DBaseTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DBaseTexture9_Release(__in D3DBaseTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DBaseTexture9_GetDevice(__in D3DBaseTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DBaseTexture9_GetType(__in D3DBaseTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DBaseTexture9_IsBusy(__in D3DBaseTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DBaseTexture9_IsSet(__in D3DBaseTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DBaseTexture9_BlockUntilNotBusy(__in D3DBaseTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DBaseTexture9_GetLevelCount(__in D3DBaseTexture *pThis) { return D3DBaseTexture_GetLevelCount(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DBaseTexture9_GetTailDesc(__in D3DBaseTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DBaseTexture9_LockTail(__in D3DBaseTexture *pThis, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail(pThis, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DBaseTexture9_AsyncLockTail(__in D3DBaseTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail(pThis, AsyncBlock, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DBaseTexture9_UnlockTail(__in D3DBaseTexture *pThis, UINT ArrayIndex) { D3DBaseTexture_UnlockTail(pThis, ArrayIndex); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE DWORD WINAPI D3DBaseTexture::GetLevelCount() { return D3DBaseTexture_GetLevelCount(this); } +D3DMINLINE D3DVOID WINAPI D3DBaseTexture::GetTailDesc(__out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc(this, pDesc); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DBaseTexture::LockTail(UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail(this, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DBaseTexture::AsyncLockTail(D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail(this, AsyncBlock, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DBaseTexture::UnlockTail(UINT ArrayIndex) { D3DBaseTexture_UnlockTail(this, ArrayIndex); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DTexture */ + +D3DINLINE ULONG WINAPI D3DTexture_AddRef(__in D3DTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DTexture_Release(__in D3DTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DTexture_GetDevice(__in D3DTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DTexture_GetType(__in D3DTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DTexture_IsBusy(__in D3DTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DTexture_IsSet(__in D3DTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DTexture_BlockUntilNotBusy(__in D3DTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI D3DTexture_GetLevelCount(__in D3DTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE void WINAPI D3DTexture_GetTailDesc(__in D3DTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc((D3DBaseTexture *)pThis, pDesc); } +D3DINLINE void WINAPI D3DTexture_LockTail(__in D3DTexture *pThis, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail((D3DBaseTexture *)pThis, D3DCUBEMAP_FACE_POSITIVE_X, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DTexture_AsyncLockTail(__in D3DTexture *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail((D3DBaseTexture *)pThis, AsyncBlock, D3DCUBEMAP_FACE_POSITIVE_X, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DTexture_UnlockTail(__in D3DTexture *pThis) { D3DBaseTexture_UnlockTail((D3DBaseTexture *)pThis, D3DCUBEMAP_FACE_POSITIVE_X); } + +void WINAPI D3DTexture_GetLevelDesc(__in D3DTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc); +__out D3DSurface* WINAPI D3DTexture_GetSurfaceLevel(__in D3DTexture *pThis, UINT Level); +void WINAPI D3DTexture_LockRect(__in D3DTexture *pThis, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DTexture_AsyncLockRect(__in D3DTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DTexture_UnlockRect(__in D3DTexture *pThis, UINT Level); + +// Compatibilty wrappers. + +D3DINLINE ULONG WINAPI IDirect3DTexture9_AddRef(__in D3DTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DTexture9_Release(__in D3DTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_GetDevice(__in D3DTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DTexture9_GetType(__in D3DTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DTexture9_IsBusy(__in D3DTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DTexture9_IsSet(__in D3DTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DTexture9_BlockUntilNotBusy(__in D3DTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DTexture9_GetLevelCount(__in D3DTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_GetLevelDesc(__in D3DTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DTexture_GetLevelDesc(pThis, Level, pDesc); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DTexture9_GetSurfaceLevel(__in D3DTexture *pThis, UINT Level, __deref_out D3DSurface **ppSurfaceLevel) { return (*ppSurfaceLevel = D3DTexture_GetSurfaceLevel(pThis, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_LockRect(__in D3DTexture *pThis, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DTexture_LockRect(pThis, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_AsyncLockRect(__in D3DTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DTexture_AsyncLockRect(pThis, AsyncBlock, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_UnlockRect(__in D3DTexture *pThis, UINT Level) { D3DTexture_UnlockRect(pThis, Level); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_GetTailDesc(__in D3DTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DTexture_GetTailDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_LockTail(__in D3DTexture *pThis, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DTexture_LockTail(pThis, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_AsyncLockTail(__in D3DTexture *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DTexture_AsyncLockTail(pThis, AsyncBlock, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DTexture9_UnlockTail(__in D3DTexture *pThis) { D3DTexture_UnlockTail(pThis); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DTexture::GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DTexture_GetLevelDesc(this, Level, pDesc); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DTexture::GetSurfaceLevel(UINT Level, __deref_out D3DSurface **ppSurfaceLevel) { return (*ppSurfaceLevel = D3DTexture_GetSurfaceLevel(this, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DTexture::LockRect(UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DTexture_LockRect(this, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DTexture::AsyncLockRect(D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DTexture_AsyncLockRect(this, AsyncBlock, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DTexture::UnlockRect(UINT Level) { D3DTexture_UnlockRect(this, Level); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DTexture::LockTail(__out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DTexture_LockTail(this, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DTexture::AsyncLockTail(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DTexture_AsyncLockTail(this, AsyncBlock, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DTexture::UnlockTail() { D3DTexture_UnlockTail(this); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DVolumeTexture */ + +D3DINLINE ULONG WINAPI D3DVolumeTexture_AddRef(__in D3DVolumeTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DVolumeTexture_Release(__in D3DVolumeTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DVolumeTexture_GetDevice(__in D3DVolumeTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DVolumeTexture_GetType(__in D3DVolumeTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVolumeTexture_IsBusy(__in D3DVolumeTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVolumeTexture_IsSet(__in D3DVolumeTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DVolumeTexture_BlockUntilNotBusy(__in D3DVolumeTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI D3DVolumeTexture_GetLevelCount(__in D3DVolumeTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE void WINAPI D3DVolumeTexture_GetTailDesc(__in D3DVolumeTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc((D3DBaseTexture *)pThis, pDesc); } +D3DINLINE void WINAPI D3DVolumeTexture_LockTail(__in D3DVolumeTexture *pThis, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail((D3DBaseTexture *)pThis, D3DCUBEMAP_FACE_POSITIVE_X, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DVolumeTexture_AsyncLockTail(__in D3DVolumeTexture *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail((D3DBaseTexture *)pThis, AsyncBlock, D3DCUBEMAP_FACE_POSITIVE_X, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DVolumeTexture_UnlockTail(__in D3DVolumeTexture *pThis) { D3DBaseTexture_UnlockTail((D3DBaseTexture *)pThis, D3DCUBEMAP_FACE_POSITIVE_X); } + +void WINAPI D3DVolumeTexture_GetLevelDesc(__in D3DVolumeTexture *pThis, UINT Level, __out D3DVOLUME_DESC *pDesc); +__out D3DVolume* WINAPI D3DVolumeTexture_GetVolumeLevel(__in D3DVolumeTexture *pThis, UINT Level); +void WINAPI D3DVolumeTexture_LockBox(__in D3DVolumeTexture *pThis, UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); +void WINAPI D3DVolumeTexture_AsyncLockBox(__in D3DVolumeTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); +void WINAPI D3DVolumeTexture_UnlockBox(__in D3DVolumeTexture *pThis, UINT Level); + +// Compatibilty wrappers. + +D3DINLINE ULONG WINAPI IDirect3DVolumeTexture9_AddRef(__in D3DVolumeTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DVolumeTexture9_Release(__in D3DVolumeTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_GetDevice(__in D3DVolumeTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9_GetType(__in D3DVolumeTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVolumeTexture9_IsBusy(__in D3DVolumeTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVolumeTexture9_IsSet(__in D3DVolumeTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DVolumeTexture9_BlockUntilNotBusy(__in D3DVolumeTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DVolumeTexture9_GetLevelCount(__in D3DVolumeTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_GetLevelDesc(__in D3DVolumeTexture *pThis, UINT Level, __out D3DVOLUME_DESC *pDesc) { D3DVolumeTexture_GetLevelDesc(pThis, Level, pDesc); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DVolumeTexture9_GetVolumeLevel(__in D3DVolumeTexture *pThis, UINT Level, __deref_out D3DVolume **ppVolumeLevel) { return (*ppVolumeLevel = D3DVolumeTexture_GetVolumeLevel(pThis, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_LockBox(__in D3DVolumeTexture *pThis, UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolumeTexture_LockBox(pThis, Level, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_AsyncLockBox(__in D3DVolumeTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolumeTexture_AsyncLockBox(pThis, AsyncBlock, Level, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_UnlockBox(__in D3DVolumeTexture *pThis, UINT Level) { D3DVolumeTexture_UnlockBox(pThis, Level); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_GetTailDesc(__in D3DVolumeTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DVolumeTexture_GetTailDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_LockTail(__in D3DVolumeTexture *pThis, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DVolumeTexture_LockTail(pThis, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_AsyncLockTail(__in D3DVolumeTexture *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DVolumeTexture_AsyncLockTail(pThis, AsyncBlock, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolumeTexture9_UnlockTail(__in D3DVolumeTexture *pThis) { D3DVolumeTexture_UnlockTail(pThis); D3DVOIDRETURN; } + + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::GetLevelDesc(UINT Level, __out D3DVOLUME_DESC *pDesc) { D3DVolumeTexture_GetLevelDesc(this, Level, pDesc); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DVolumeTexture::GetVolumeLevel(UINT Level, __deref_out D3DVolume **ppVolumeLevel) { return (*ppVolumeLevel = D3DVolumeTexture_GetVolumeLevel(this, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::LockBox(UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolumeTexture_LockBox(this, Level, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::AsyncLockBox(D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolumeTexture_AsyncLockBox(this, AsyncBlock, Level, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::UnlockBox(UINT Level) { D3DVolumeTexture_UnlockBox(this, Level); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::LockTail(__out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DVolumeTexture_LockTail(this, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::AsyncLockTail(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DVolumeTexture_AsyncLockTail(this, AsyncBlock, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolumeTexture::UnlockTail() { D3DVolumeTexture_UnlockTail(this); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DCubeTexture */ + +D3DINLINE ULONG WINAPI D3DCubeTexture_AddRef(__in D3DCubeTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DCubeTexture_Release(__in D3DCubeTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DCubeTexture_GetDevice(__in D3DCubeTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DCubeTexture_GetType(__in D3DCubeTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DCubeTexture_IsBusy(__in D3DCubeTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DCubeTexture_IsSet(__in D3DCubeTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DCubeTexture_BlockUntilNotBusy(__in D3DCubeTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI D3DCubeTexture_GetLevelCount(__in D3DCubeTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE void WINAPI D3DCubeTexture_GetTailDesc(__in D3DCubeTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc((D3DBaseTexture *)pThis, pDesc); } +D3DINLINE void WINAPI D3DCubeTexture_LockTail(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail((D3DBaseTexture *)pThis, FaceType, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DCubeTexture_AsyncLockTail(__in D3DCubeTexture *pThis, D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail((D3DBaseTexture *)pThis, AsyncBlock, FaceType, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DCubeTexture_UnlockTail(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType) { D3DBaseTexture_UnlockTail((D3DBaseTexture *)pThis, FaceType); } + +void WINAPI D3DCubeTexture_GetLevelDesc(__in D3DCubeTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc); +__out D3DSurface* WINAPI D3DCubeTexture_GetCubeMapSurface(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, UINT Level); +void WINAPI D3DCubeTexture_LockRect(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DCubeTexture_AsyncLockRect(__in D3DCubeTexture *pThis, D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DCubeTexture_UnlockRect(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, UINT Level); + +D3DINLINE ULONG WINAPI IDirect3DCubeTexture9_AddRef(__in D3DCubeTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DCubeTexture9_Release(__in D3DCubeTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_GetDevice(__in D3DCubeTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9_GetType(__in D3DCubeTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DCubeTexture9_IsBusy(__in D3DCubeTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DCubeTexture9_IsSet(__in D3DCubeTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DCubeTexture9_BlockUntilNotBusy(__in D3DCubeTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DCubeTexture9_GetLevelCount(__in D3DCubeTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_GetLevelDesc(__in D3DCubeTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DCubeTexture_GetLevelDesc(pThis, Level, pDesc); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DCubeTexture9_GetCubeMapSurface(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, UINT Level, __deref_out D3DSurface **ppCubeMapSurface) { return (*ppCubeMapSurface = D3DCubeTexture_GetCubeMapSurface(pThis, FaceType, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_LockRect(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DCubeTexture_LockRect(pThis, FaceType, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_AsyncLockRect(__in D3DCubeTexture *pThis, D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DCubeTexture_AsyncLockRect(pThis, AsyncBlock, FaceType, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_UnlockRect(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, UINT Level) { D3DCubeTexture_UnlockRect(pThis, FaceType, Level); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_GetTailDesc(__in D3DCubeTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DCubeTexture_GetTailDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_LockTail(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DCubeTexture_LockTail(pThis, FaceType, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_AsyncLockTail(__in D3DCubeTexture *pThis, D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DCubeTexture_AsyncLockTail(pThis, AsyncBlock, FaceType, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCubeTexture9_UnlockTail(__in D3DCubeTexture *pThis, D3DCUBEMAP_FACES FaceType) { D3DCubeTexture_UnlockTail(pThis, FaceType); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DCubeTexture_GetLevelDesc(this, Level, pDesc); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DCubeTexture::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, UINT Level, __deref_out D3DSurface **ppCubeMapSurface) { return (*ppCubeMapSurface = D3DCubeTexture_GetCubeMapSurface(this, FaceType, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::LockRect(D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DCubeTexture_LockRect(this, FaceType, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::AsyncLockRect(D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DCubeTexture_AsyncLockRect(this, AsyncBlock, FaceType, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Level) { D3DCubeTexture_UnlockRect(this, FaceType, Level); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::LockTail(D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DCubeTexture_LockTail(this, FaceType, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::AsyncLockTail(D3DASYNCBLOCK AsyncBlock, D3DCUBEMAP_FACES FaceType, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DCubeTexture_AsyncLockTail(this, AsyncBlock, FaceType, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCubeTexture::UnlockTail(D3DCUBEMAP_FACES FaceType) { D3DCubeTexture_UnlockTail(this, FaceType); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DArrayTexture */ + +D3DINLINE ULONG WINAPI D3DArrayTexture_AddRef(__in D3DArrayTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DArrayTexture_Release(__in D3DArrayTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DArrayTexture_GetDevice(__in D3DArrayTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DArrayTexture_GetType(__in D3DArrayTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DArrayTexture_IsBusy(__in D3DArrayTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DArrayTexture_IsSet(__in D3DArrayTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DArrayTexture_BlockUntilNotBusy(__in D3DArrayTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI D3DArrayTexture_GetLevelCount(__in D3DArrayTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE void WINAPI D3DArrayTexture_GetTailDesc(__in D3DArrayTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc((D3DBaseTexture *)pThis, pDesc); } +D3DINLINE void WINAPI D3DArrayTexture_LockTail(__in D3DArrayTexture *pThis, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail((D3DBaseTexture *)pThis, ArrayIndex, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DArrayTexture_AsyncLockTail(__in D3DArrayTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail((D3DBaseTexture *)pThis, AsyncBlock, ArrayIndex, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DArrayTexture_UnlockTail(__in D3DArrayTexture *pThis, UINT ArrayIndex) { D3DBaseTexture_UnlockTail((D3DBaseTexture *)pThis, ArrayIndex); } + +DWORD WINAPI D3DArrayTexture_GetArraySize(__in D3DArrayTexture *pThis); +void WINAPI D3DArrayTexture_GetLevelDesc(__in D3DArrayTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc); +__out D3DSurface* WINAPI D3DArrayTexture_GetArraySurface(__in D3DArrayTexture *pThis, UINT ArrayIndex, UINT Level); +void WINAPI D3DArrayTexture_LockRect(__in D3DArrayTexture *pThis, UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DArrayTexture_AsyncLockRect(__in D3DArrayTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DArrayTexture_UnlockRect(__in D3DArrayTexture *pThis, UINT ArrayIndex, UINT Level); + +D3DINLINE ULONG WINAPI IDirect3DArrayTexture9_AddRef(__in D3DArrayTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DArrayTexture9_Release(__in D3DArrayTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_GetDevice(__in D3DArrayTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DArrayTexture9_GetType(__in D3DArrayTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DArrayTexture9_IsBusy(__in D3DArrayTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DArrayTexture9_IsSet(__in D3DArrayTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DArrayTexture9_BlockUntilNotBusy(__in D3DArrayTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DArrayTexture9_GetLevelCount(__in D3DArrayTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DArrayTexture9_GetArraySize(__in D3DArrayTexture *pThis) { return D3DArrayTexture_GetArraySize(pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_GetLevelDesc(__in D3DArrayTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DArrayTexture_GetLevelDesc(pThis, Level, pDesc); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DArrayTexture9_GetArraySurface(__in D3DArrayTexture *pThis, UINT ArrayIndex, UINT Level, __deref_out D3DSurface **ppArraySurface) { return (*ppArraySurface = D3DArrayTexture_GetArraySurface(pThis, ArrayIndex, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_LockRect(__in D3DArrayTexture *pThis, UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DArrayTexture_LockRect(pThis, ArrayIndex, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_AsyncLockRect(__in D3DArrayTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DArrayTexture_AsyncLockRect(pThis, AsyncBlock, ArrayIndex, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_UnlockRect(__in D3DArrayTexture *pThis, UINT ArrayIndex, UINT Level) { D3DArrayTexture_UnlockRect(pThis, ArrayIndex, Level); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_GetTailDesc(__in D3DArrayTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DArrayTexture_GetTailDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_LockTail(__in D3DArrayTexture *pThis, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DArrayTexture_LockTail(pThis, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_AsyncLockTail(__in D3DArrayTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DArrayTexture_AsyncLockTail(pThis, AsyncBlock, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DArrayTexture9_UnlockTail(__in D3DArrayTexture *pThis, UINT ArrayIndex) { D3DArrayTexture_UnlockTail(pThis, ArrayIndex); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE DWORD WINAPI D3DArrayTexture::GetArraySize() { return D3DArrayTexture_GetArraySize(this); } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DArrayTexture_GetLevelDesc(this, Level, pDesc); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DArrayTexture::GetArraySurface(UINT ArrayIndex, UINT Level, __deref_out D3DSurface **ppArraySurface) { return (*ppArraySurface = D3DArrayTexture_GetArraySurface(this, ArrayIndex, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::LockRect(UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DArrayTexture_LockRect(this, ArrayIndex, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::AsyncLockRect(D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DArrayTexture_AsyncLockRect(this, AsyncBlock, ArrayIndex, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::UnlockRect(UINT ArrayIndex, UINT Level) { D3DArrayTexture_UnlockRect(this, ArrayIndex, Level); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::LockTail(UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DArrayTexture_LockTail(this, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::AsyncLockTail(D3DASYNCBLOCK AsyncBlock, UINT ArrayIndex, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DArrayTexture_AsyncLockTail(this, AsyncBlock, ArrayIndex, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DArrayTexture::UnlockTail(UINT ArrayIndex) { D3DArrayTexture_UnlockTail(this, ArrayIndex); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DLineTexture */ + +D3DINLINE ULONG WINAPI D3DLineTexture_AddRef(__in D3DLineTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DLineTexture_Release(__in D3DLineTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DLineTexture_GetDevice(__in D3DLineTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DLineTexture_GetType(__in D3DLineTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DLineTexture_IsBusy(__in D3DLineTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DLineTexture_IsSet(__in D3DLineTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DLineTexture_BlockUntilNotBusy(__in D3DLineTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI D3DLineTexture_GetLevelCount(__in D3DLineTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE void WINAPI D3DLineTexture_GetTailDesc(__in D3DLineTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DBaseTexture_GetTailDesc((D3DBaseTexture *)pThis, pDesc); } +D3DINLINE void WINAPI D3DLineTexture_LockTail(__in D3DLineTexture *pThis, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_LockTail((D3DBaseTexture *)pThis, D3DCUBEMAP_FACE_POSITIVE_X, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DLineTexture_AsyncLockTail(__in D3DLineTexture *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DBaseTexture_AsyncLockTail((D3DBaseTexture *)pThis, AsyncBlock, D3DCUBEMAP_FACE_POSITIVE_X, pLockedTail, Flags); } +D3DINLINE void WINAPI D3DLineTexture_UnlockTail(__in D3DLineTexture *pThis) { D3DBaseTexture_UnlockTail((D3DBaseTexture *)pThis, D3DCUBEMAP_FACE_POSITIVE_X); } + +void WINAPI D3DLineTexture_GetLevelDesc(__in D3DLineTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc); +__out D3DSurface* WINAPI D3DLineTexture_GetSurfaceLevel(__in D3DLineTexture *pThis, UINT Level); +void WINAPI D3DLineTexture_LockRect(__in D3DLineTexture *pThis, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DLineTexture_AsyncLockRect(__in D3DLineTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DLineTexture_UnlockRect(__in D3DLineTexture *pThis, UINT Level); + +// Compatibilty wrappers. + +D3DINLINE ULONG WINAPI IDirect3DLineTexture9_AddRef(__in D3DLineTexture *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DLineTexture9_Release(__in D3DLineTexture *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_GetDevice(__in D3DLineTexture *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DLineTexture9_GetType(__in D3DLineTexture *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DLineTexture9_IsBusy(__in D3DLineTexture *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DLineTexture9_IsSet(__in D3DLineTexture *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DLineTexture9_BlockUntilNotBusy(__in D3DLineTexture *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE DWORD WINAPI IDirect3DLineTexture9_GetLevelCount(__in D3DLineTexture *pThis) { return D3DBaseTexture_GetLevelCount((D3DBaseTexture *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_GetLevelDesc(__in D3DLineTexture *pThis, UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DLineTexture_GetLevelDesc(pThis, Level, pDesc); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DLineTexture9_GetSurfaceLevel(__in D3DLineTexture *pThis, UINT Level, __deref_out D3DSurface **ppSurfaceLevel) { return (*ppSurfaceLevel = D3DLineTexture_GetSurfaceLevel(pThis, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_LockRect(__in D3DLineTexture *pThis, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DLineTexture_LockRect(pThis, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_AsyncLockRect(__in D3DLineTexture *pThis, D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DLineTexture_AsyncLockRect(pThis, AsyncBlock, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_UnlockRect(__in D3DLineTexture *pThis, UINT Level) { D3DLineTexture_UnlockRect(pThis, Level); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_GetTailDesc(__in D3DLineTexture *pThis, __out D3DMIPTAIL_DESC *pDesc) { D3DLineTexture_GetTailDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_LockTail(__in D3DLineTexture *pThis, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DLineTexture_LockTail(pThis, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_AsyncLockTail(__in D3DLineTexture *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DLineTexture_AsyncLockTail(pThis, AsyncBlock, pLockedTail, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DLineTexture9_UnlockTail(__in D3DLineTexture *pThis) { D3DLineTexture_UnlockTail(pThis); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DLineTexture::GetLevelDesc(UINT Level, __out D3DSURFACE_DESC *pDesc) { D3DLineTexture_GetLevelDesc(this, Level, pDesc); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DLineTexture::GetSurfaceLevel(UINT Level, __deref_out D3DSurface **ppSurfaceLevel) { return (*ppSurfaceLevel = D3DLineTexture_GetSurfaceLevel(this, Level)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DLineTexture::LockRect(UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DLineTexture_LockRect(this, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DLineTexture::AsyncLockRect(D3DASYNCBLOCK AsyncBlock, UINT Level, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DLineTexture_AsyncLockRect(this, AsyncBlock, Level, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DLineTexture::UnlockRect(UINT Level) { D3DLineTexture_UnlockRect(this, Level); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DLineTexture::LockTail(__out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DLineTexture_LockTail(this, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DLineTexture::AsyncLockTail(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_TAIL *pLockedTail, DWORD Flags) { D3DLineTexture_AsyncLockTail(this, AsyncBlock, pLockedTail, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DLineTexture::UnlockTail() { D3DLineTexture_UnlockTail(this); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DVertexBuffer */ + +D3DINLINE ULONG WINAPI D3DVertexBuffer_AddRef(__in D3DVertexBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DVertexBuffer_Release(__in D3DVertexBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DVertexBuffer_GetDevice(__in D3DVertexBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DVertexBuffer_GetType(__in D3DVertexBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVertexBuffer_IsBusy(__in D3DVertexBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVertexBuffer_IsSet(__in D3DVertexBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DVertexBuffer_BlockUntilNotBusy(__in D3DVertexBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +__out void* WINAPI D3DVertexBuffer_Lock(__in D3DVertexBuffer *pThis, UINT OffsetToLock, UINT SizeToLock, DWORD Flags); +__out void* WINAPI D3DVertexBuffer_AsyncLock(__in D3DVertexBuffer *pThis, D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, DWORD Flags); +void WINAPI D3DVertexBuffer_GetDesc(__in D3DVertexBuffer *pThis, __out D3DVERTEXBUFFER_DESC *pDesc); +void WINAPI D3DVertexBuffer_Unlock(__in D3DVertexBuffer *pThis); + +D3DINLINE ULONG WINAPI IDirect3DVertexBuffer9_AddRef(__in D3DVertexBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DVertexBuffer9_Release(__in D3DVertexBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVertexBuffer9_GetDevice(__in D3DVertexBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9_GetType(__in D3DVertexBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVertexBuffer9_IsBusy(__in D3DVertexBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVertexBuffer9_IsSet(__in D3DVertexBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DVertexBuffer9_BlockUntilNotBusy(__in D3DVertexBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVertexBuffer9_Lock(__in D3DVertexBuffer *pThis, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = (BYTE*)D3DVertexBuffer_Lock(pThis, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVertexBuffer9_AsyncLock(__in D3DVertexBuffer *pThis, D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = (BYTE*)D3DVertexBuffer_AsyncLock(pThis, AsyncBlock, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVertexBuffer9_Unlock(__in D3DVertexBuffer *pThis) { D3DVertexBuffer_Unlock(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVertexBuffer9_GetDesc(__in D3DVertexBuffer *pThis, __out D3DVERTEXBUFFER_DESC *pDesc) { D3DVertexBuffer_GetDesc(pThis, pDesc); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DVertexBuffer::Lock(UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = (BYTE*)D3DVertexBuffer_Lock(this, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVertexBuffer::AsyncLock(D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = (BYTE*)D3DVertexBuffer_AsyncLock(this, AsyncBlock, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVertexBuffer::Unlock() { D3DVertexBuffer_Unlock(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVertexBuffer::GetDesc(__out D3DVERTEXBUFFER_DESC *pDesc) { D3DVertexBuffer_GetDesc(this, pDesc); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DIndexBuffer */ + +D3DINLINE ULONG WINAPI D3DIndexBuffer_AddRef(__in D3DIndexBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DIndexBuffer_Release(__in D3DIndexBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DIndexBuffer_GetDevice(__in D3DIndexBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DIndexBuffer_GetType(__in D3DIndexBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DIndexBuffer_IsBusy(__in D3DIndexBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DIndexBuffer_IsSet(__in D3DIndexBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DIndexBuffer_BlockUntilNotBusy(__in D3DIndexBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +__out void* WINAPI D3DIndexBuffer_Lock(__in D3DIndexBuffer *pThis, UINT OffsetToLock, UINT SizeToLock, DWORD Flags); +__out void* WINAPI D3DIndexBuffer_AsyncLock(__in D3DIndexBuffer *pThis, D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, DWORD Flags); +void WINAPI D3DIndexBuffer_Unlock(__in D3DIndexBuffer *pThis); +void WINAPI D3DIndexBuffer_GetDesc(__in D3DIndexBuffer *pThis, __out D3DINDEXBUFFER_DESC *pDesc); + +D3DINLINE ULONG WINAPI IDirect3DIndexBuffer9_AddRef(__in D3DIndexBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DIndexBuffer9_Release(__in D3DIndexBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DIndexBuffer9_GetDevice(__in D3DIndexBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9_GetType(__in D3DIndexBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DIndexBuffer9_IsBusy(__in D3DIndexBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DIndexBuffer9_IsSet(__in D3DIndexBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DIndexBuffer9_BlockUntilNotBusy(__in D3DIndexBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DIndexBuffer9_Lock(__in D3DIndexBuffer *pThis, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = D3DIndexBuffer_Lock(pThis, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DIndexBuffer9_AsyncLock(__in D3DIndexBuffer *pThis, D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = D3DIndexBuffer_AsyncLock(pThis, AsyncBlock, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DIndexBuffer9_Unlock(__in D3DIndexBuffer *pThis) { D3DIndexBuffer_Unlock(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DIndexBuffer9_GetDesc(__in D3DIndexBuffer *pThis, __out D3DINDEXBUFFER_DESC *pDesc) { D3DIndexBuffer_GetDesc(pThis, pDesc); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DIndexBuffer::Lock(UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = D3DIndexBuffer_Lock(this, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DIndexBuffer::AsyncLock(D3DASYNCBLOCK AsyncBlock, UINT OffsetToLock, UINT SizeToLock, __deref_out void **ppbData, DWORD Flags) { *ppbData = D3DIndexBuffer_AsyncLock(this, AsyncBlock, OffsetToLock, SizeToLock, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DIndexBuffer::Unlock() { D3DIndexBuffer_Unlock(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DIndexBuffer::GetDesc(__out D3DINDEXBUFFER_DESC *pDesc) { D3DIndexBuffer_GetDesc(this, pDesc); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DSurface */ + +D3DINLINE ULONG WINAPI D3DSurface_AddRef(__in D3DSurface *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DSurface_Release(__in D3DSurface *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DSurface_GetDevice(__in D3DSurface *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DSurface_GetType(__in D3DSurface *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DSurface_IsBusy(__in D3DSurface *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DSurface_IsSet(__in D3DSurface *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DSurface_BlockUntilNotBusy(__in D3DSurface *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +__out void* WINAPI D3DSurface_GetContainer(__in D3DSurface *pThis, REFIID UnusedRiid); +void WINAPI D3DSurface_GetDesc(__in D3DSurface *pThis, __out D3DSURFACE_DESC *pDesc); +void WINAPI D3DSurface_LockRect(__in D3DSurface *pThis, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DSurface_AsyncLockRect(__in D3DSurface *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags); +void WINAPI D3DSurface_UnlockRect(__in D3DSurface *pThis); + +D3DINLINE ULONG WINAPI IDirect3DSurface9_AddRef(__in D3DSurface *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DSurface9_Release(__in D3DSurface *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DSurface9_GetDevice(__in D3DSurface *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DSurface9_GetType(__in D3DSurface *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DSurface9_IsBusy(__in D3DSurface *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DSurface9_IsSet(__in D3DSurface *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DSurface9_BlockUntilNotBusy(__in D3DSurface *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } +D3DINLINE HRESULT WINAPI IDirect3DSurface9_GetContainer(__in D3DSurface *pThis, REFIID UnusedRiid, __deref_out void **ppContainer) { return (*ppContainer = D3DSurface_GetContainer(pThis, UnusedRiid)) != NULL ? S_OK : E_FAIL; } +D3DINLINE D3DVOID WINAPI IDirect3DSurface9_GetDesc(__in D3DSurface *pThis, __out D3DSURFACE_DESC *pDesc) { D3DSurface_GetDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DSurface9_LockRect(__in D3DSurface *pThis, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DSurface_LockRect(pThis, pLockedRect,pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DSurface9_AsyncLockRect(__in D3DSurface *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DSurface_AsyncLockRect(pThis, AsyncBlock, pLockedRect,pRect, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DSurface9_UnlockRect(__in D3DSurface *pThis) { D3DSurface_UnlockRect(pThis); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE HRESULT WINAPI D3DSurface::GetContainer(REFIID UnusedRiid, __deref_out void **ppContainer) { return (*ppContainer = D3DSurface_GetContainer(this, UnusedRiid)) != NULL ? S_OK : E_FAIL; } +D3DMINLINE D3DVOID WINAPI D3DSurface::GetDesc(__out D3DSURFACE_DESC *pDesc) { D3DSurface_GetDesc(this, pDesc); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DSurface::LockRect(__out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DSurface_LockRect(this, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DSurface::AsyncLockRect(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_RECT *pLockedRect, __in_opt CONST RECT *pRect, DWORD Flags) { D3DSurface_AsyncLockRect(this, AsyncBlock, pLockedRect, pRect, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DSurface::UnlockRect() { D3DSurface_UnlockRect(this); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DVolume */ + +D3DINLINE ULONG WINAPI D3DVolume_AddRef(__in D3DVolume *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DVolume_Release(__in D3DVolume *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DVolume_GetDevice(__in D3DVolume *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DVolume_GetType(__in D3DVolume *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVolume_IsBusy(__in D3DVolume *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVolume_IsSet(__in D3DVolume *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DVolume_BlockUntilNotBusy(__in D3DVolume *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +__out void* WINAPI D3DVolume_GetContainer(__in D3DVolume *pThis, REFIID UnusedRiid); +void WINAPI D3DVolume_GetDesc(__in D3DVolume *pThis, __out D3DVOLUME_DESC *pDesc); +void WINAPI D3DVolume_LockBox(__in D3DVolume *pThis, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); +void WINAPI D3DVolume_AsyncLockBox(__in D3DVolume *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags); +void WINAPI D3DVolume_UnlockBox(__in D3DVolume *pThis); + +D3DINLINE ULONG WINAPI IDirect3DVolume9_AddRef(__in D3DVolume *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DVolume9_Release(__in D3DVolume *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVolume9_GetDevice(__in D3DVolume *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DVolume9_GetType(__in D3DVolume *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVolume9_IsBusy(__in D3DVolume *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVolume9_IsSet(__in D3DVolume *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DVolume9_BlockUntilNotBusy(__in D3DVolume *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +D3DINLINE HRESULT WINAPI IDirect3DVolume9_GetContainer(__in D3DVolume *pThis, REFIID UnusedRiid, __deref_out void **ppContainer) { return (*ppContainer = D3DVolume_GetContainer(pThis, UnusedRiid)) != NULL ? S_OK : E_FAIL; } +D3DINLINE D3DVOID WINAPI IDirect3DVolume9_GetDesc(__in D3DVolume *pThis, __out D3DVOLUME_DESC *pDesc) { D3DVolume_GetDesc(pThis, pDesc); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolume9_LockBox(__in D3DVolume *pThis, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolume_LockBox(pThis, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolume9_AsyncLockBox(__in D3DVolume *pThis, D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolume_AsyncLockBox(pThis, AsyncBlock, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVolume9_UnlockBox(__in D3DVolume *pThis) { D3DVolume_UnlockBox(pThis); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE HRESULT WINAPI D3DVolume::GetContainer(REFIID UnusedRiid, __deref_out void **ppContainer) { return (*ppContainer = D3DVolume_GetContainer(this, UnusedRiid)) != NULL ? S_OK : E_FAIL; } +D3DMINLINE D3DVOID WINAPI D3DVolume::GetDesc(__out D3DVOLUME_DESC *pDesc) { D3DVolume_GetDesc(this, pDesc); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolume::LockBox(__out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolume_LockBox(this, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolume::AsyncLockBox(D3DASYNCBLOCK AsyncBlock, __out D3DLOCKED_BOX *pLockedVolume, __in_opt CONST D3DBOX *pBox, DWORD Flags) { D3DVolume_AsyncLockBox(this, AsyncBlock, pLockedVolume, pBox, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVolume::UnlockBox() { D3DVolume_UnlockBox(this); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DVertexDeclaration */ + +D3DINLINE ULONG WINAPI D3DVertexDeclaration_AddRef(__in D3DVertexDeclaration *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DVertexDeclaration_Release(__in D3DVertexDeclaration *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DVertexDeclaration_GetDevice(__in D3DVertexDeclaration *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DVertexDeclaration_GetType(__in D3DVertexDeclaration *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVertexDeclaration_IsBusy(__in D3DVertexDeclaration *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVertexDeclaration_IsSet(__in D3DVertexDeclaration *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DVertexDeclaration_BlockUntilNotBusy(__in D3DVertexDeclaration *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +void WINAPI D3DVertexDeclaration_GetDeclaration(__in D3DVertexDeclaration *pThis, __out_ecount_part(*pNumElements, *pNumElements) D3DVERTEXELEMENT9 *pDecl, __inout UINT *pNumElements); + +D3DINLINE ULONG WINAPI IDirect3DVertexDeclaration9_AddRef(__in D3DVertexDeclaration *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DVertexDeclaration9_Release(__in D3DVertexDeclaration *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVertexDeclaration9_GetDevice(__in D3DVertexDeclaration *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DVertexDeclaration9_GetType(__in D3DVertexDeclaration *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVertexDeclaration9_IsBusy(__in D3DVertexDeclaration *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVertexDeclaration9_IsSet(__in D3DVertexDeclaration *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DVertexDeclaration9_BlockUntilNotBusy(__in D3DVertexDeclaration *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +D3DINLINE D3DVOID WINAPI IDirect3DVertexDeclaration9_GetDeclaration(__in D3DVertexDeclaration *pThis, __out_ecount_part(*pNumElements, *pNumElements) D3DVERTEXELEMENT9 *pDecl, __inout UINT *pNumElements) { D3DVertexDeclaration_GetDeclaration(pThis, pDecl, pNumElements); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DVertexDeclaration::GetDeclaration(__out_ecount_part(*pNumElements, *pNumElements) D3DVERTEXELEMENT9 *pDecl, __inout UINT *pNumElements) { D3DVertexDeclaration_GetDeclaration(this, pDecl, pNumElements); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DVertexShader */ + +D3DINLINE ULONG WINAPI D3DVertexShader_AddRef(__in D3DVertexShader *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DVertexShader_Release(__in D3DVertexShader *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DVertexShader_GetDevice(__in D3DVertexShader *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DVertexShader_GetType(__in D3DVertexShader *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVertexShader_IsBusy(__in D3DVertexShader *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DVertexShader_IsSet(__in D3DVertexShader *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DVertexShader_BlockUntilNotBusy(__in D3DVertexShader *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +void WINAPI D3DVertexShader_GetFunction(__in D3DVertexShader *pThis, __out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData); +void WINAPI D3DVertexShader_Bind(__in D3DVertexShader *pThis, DWORD Flags, __in D3DVertexDeclaration* pVertexDeclaration, __in CONST DWORD* pStreamStrides, __in_opt D3DPixelShader* pPixelShader); +BOOL WINAPI D3DVertexShader_IsBound(__in D3DVertexShader *pThis); + +D3DINLINE ULONG WINAPI IDirect3DVertexShader9_AddRef(__in D3DVertexShader *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DVertexShader9_Release(__in D3DVertexShader *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DVertexShader9_GetDevice(__in D3DVertexShader *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DVertexShader9_GetType(__in D3DVertexShader *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVertexShader9_IsBusy(__in D3DVertexShader *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DVertexShader9_IsSet(__in D3DVertexShader *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DVertexShader9_BlockUntilNotBusy(__in D3DVertexShader *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +D3DINLINE D3DVOID WINAPI IDirect3DVertexShader9_GetFunction(__in D3DVertexShader *pThis, __out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData) { D3DVertexShader_GetFunction(pThis, pData, pSizeOfData); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DVertexShader9_Bind(__in D3DVertexShader *pThis, DWORD Flags, __in D3DVertexDeclaration* pVertexDeclaration, __in CONST DWORD* pStreamStrides, __in_opt D3DPixelShader* pPixelShader) { D3DVertexShader_Bind(pThis, Flags, pVertexDeclaration, pStreamStrides, pPixelShader); D3DVOIDRETURN; } +D3DINLINE BOOL WINAPI IDirect3DVertexShader9_IsBound(__in D3DVertexShader *pThis) { return D3DVertexShader_IsBound(pThis); } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DVertexShader::GetFunction(__out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData) { D3DVertexShader_GetFunction(this, pData, pSizeOfData); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DVertexShader::Bind(DWORD Flags, __in D3DVertexDeclaration* pVertexDeclaration, __in CONST DWORD* pStreamStrides, __in_opt D3DPixelShader* pPixelShader) { D3DVertexShader_Bind(this, Flags, pVertexDeclaration, pStreamStrides, pPixelShader); D3DVOIDRETURN; } +D3DMINLINE BOOL WINAPI D3DVertexShader::IsBound() { return D3DVertexShader_IsBound(this); } + +#endif __cplusplus + +/* D3DPixelShader */ + +D3DINLINE ULONG WINAPI D3DPixelShader_AddRef(__in D3DPixelShader *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DPixelShader_Release(__in D3DPixelShader *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DPixelShader_GetDevice(__in D3DPixelShader *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DPixelShader_GetType(__in D3DPixelShader *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DPixelShader_IsBusy(__in D3DPixelShader *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DPixelShader_IsSet(__in D3DPixelShader *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DPixelShader_BlockUntilNotBusy(__in D3DPixelShader *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +ULONG WINAPI D3DPixelShader_AddRef(__in D3DPixelShader *pThis); +ULONG WINAPI D3DPixelShader_Release(__in D3DPixelShader *pThis); +void WINAPI D3DPixelShader_GetDevice(__in D3DPixelShader *pThis, __deref_out D3DDevice **ppDevice); +void WINAPI D3DPixelShader_GetFunction(__in D3DPixelShader *pThis, __out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData); +BOOL WINAPI D3DPixelShader_IsSet(__in D3DPixelShader *pThis, __in D3DDevice *pDevice); + +D3DINLINE ULONG WINAPI IDirect3DPixelShader9_AddRef(__in D3DPixelShader *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DPixelShader9_Release(__in D3DPixelShader *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DPixelShader9_GetDevice(__in D3DPixelShader *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DPixelShader9_GetType(__in D3DPixelShader *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DPixelShader9_IsBusy(__in D3DPixelShader *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DPixelShader9_IsSet(__in D3DPixelShader *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DPixelShader9_BlockUntilNotBusy(__in D3DPixelShader *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +D3DINLINE D3DVOID WINAPI IDirect3DPixelShader9_GetFunction(__in D3DPixelShader *pThis, __out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData) { D3DPixelShader_GetFunction(pThis, pData, pSizeOfData); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DPixelShader::GetFunction(__out_bcount_opt(*pSizeOfData) void *pData, __inout UINT* pSizeOfData) { D3DPixelShader_GetFunction(this, pData, pSizeOfData); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DConstantBuffer */ + +D3DINLINE ULONG WINAPI D3DConstantBuffer_AddRef(__in D3DConstantBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DConstantBuffer_Release(__in D3DConstantBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DConstantBuffer_GetDevice(__in D3DConstantBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DConstantBuffer_GetType(__in D3DConstantBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DConstantBuffer_IsBusy(__in D3DConstantBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DConstantBuffer_IsSet(__in D3DConstantBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DConstantBuffer_BlockUntilNotBusy(__in D3DConstantBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +__out D3DVECTOR4* WINAPI D3DConstantBuffer_Lock(__in D3DConstantBuffer *pThis, DWORD Flags); +__out D3DVECTOR4* WINAPI D3DConstantBuffer_AsyncLock(__in D3DConstantBuffer *pThis, D3DASYNCBLOCK AsyncBlock, DWORD Flags); +void WINAPI D3DConstantBuffer_Unlock(__in D3DConstantBuffer *pThis); + +D3DINLINE ULONG WINAPI IDirect3DConstantBuffer9_AddRef(__in D3DConstantBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DConstantBuffer9_Release(__in D3DConstantBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DConstantBuffer9_GetDevice(__in D3DConstantBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DConstantBuffer9_GetType(__in D3DConstantBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DConstantBuffer9_IsBusy(__in D3DConstantBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DConstantBuffer9_IsSet(__in D3DConstantBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DConstantBuffer9_BlockUntilNotBusy(__in D3DConstantBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +D3DINLINE D3DVOID WINAPI IDirect3DConstantBuffer9_Lock(__in D3DConstantBuffer *pThis, __deref_out D3DVECTOR4** ppData, DWORD Flags) { *ppData = D3DConstantBuffer_Lock(pThis, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DConstantBuffer9_AsyncLock(__in D3DConstantBuffer *pThis, D3DASYNCBLOCK AsyncBlock, __deref_out D3DVECTOR4** ppData, DWORD Flags) { *ppData = D3DConstantBuffer_AsyncLock(pThis, AsyncBlock, Flags); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DConstantBuffer9_Unlock(__in D3DConstantBuffer *pThis) { D3DConstantBuffer_Unlock(pThis); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DConstantBuffer::Lock(__deref_out D3DVECTOR4** ppData, DWORD Flags) { *ppData = D3DConstantBuffer_Lock(this, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DConstantBuffer::AsyncLock(D3DASYNCBLOCK AsyncBlock, __deref_out D3DVECTOR4** ppData, DWORD Flags) { *ppData = D3DConstantBuffer_AsyncLock(this, AsyncBlock, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DConstantBuffer::Unlock() { D3DConstantBuffer_Unlock(this); D3DVOIDRETURN; } + +#endif __cplusplus + +/* D3DCommandBuffer */ + +D3DINLINE ULONG WINAPI D3DCommandBuffer_AddRef(__in D3DCommandBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI D3DCommandBuffer_Release(__in D3DCommandBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE void WINAPI D3DCommandBuffer_GetDevice(__in D3DCommandBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); } +D3DINLINE D3DRESOURCETYPE WINAPI D3DCommandBuffer_GetType(__in D3DCommandBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DCommandBuffer_IsBusy(__in D3DCommandBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI D3DCommandBuffer_IsSet(__in D3DCommandBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI D3DCommandBuffer_BlockUntilNotBusy(__in D3DCommandBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +void WINAPI D3DCommandBuffer_GetResources(__in D3DCommandBuffer *pThis, DWORD Flags, __out_ecount_opt(*pBufferSize) D3DResource** ppResourceList, __inout DWORD* pBufferSize); +__out D3DCommandBuffer* WINAPI D3DCommandBuffer_CreateClone(__in D3DCommandBuffer *pThis, DWORD Flags); +void WINAPI D3DCommandBuffer_GetClone(__in D3DCommandBuffer *pThis, DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize); +void WINAPI D3DCommandBuffer_BeginFixupCreation(__in D3DCommandBuffer *pThis); +HRESULT WINAPI D3DCommandBuffer_EndFixupCreation(__in D3DCommandBuffer *pThis); +HRESULT WINAPI D3DCommandBuffer_Deconstruct(__in D3DCommandBuffer *pThis, DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize, __out_bcount_opt(*pInitializationSize) void* pInitializationPart, __inout DWORD* pInitializationSize); +void WINAPI D3DCommandBuffer_BeginReconstruction(__in D3DCommandBuffer *pThis, DWORD Flags, __in void* pPhysicalPart, __in void* pInitializationPart); +void WINAPI D3DCommandBuffer_EndReconstruction(__in D3DCommandBuffer *pThis); +void WINAPI D3DCommandBuffer_BeginDynamicFixups(__in D3DCommandBuffer *pThis); +void WINAPI D3DCommandBuffer_EndDynamicFixups(__in D3DCommandBuffer *pThis); +DWORD WINAPI D3DCommandBuffer_CreateSurfacesFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateClipRectFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateViewportFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateVertexShaderConstantFFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreatePixelShaderConstantFFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateVertexShaderFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DVertexShader* pVertexShader, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreatePixelShaderFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DPixelShader* pPixelShader, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateTextureFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DBaseTexture* pTexture, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateIndexBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DIndexBuffer* pIndexBuffer, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateVertexBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DVertexBuffer* pVertexBuffer, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateConstantBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DConstantBuffer* pConstantBuffer, DWORD StartMarker, DWORD StopMarker); +DWORD WINAPI D3DCommandBuffer_CreateCommandBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DCommandBuffer* pCommandBuffer, DWORD StartMarker, DWORD StopMarker); +void WINAPI D3DCommandBuffer_SetSurfaces(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST D3DSURFACES* pSurfaces); +void WINAPI D3DCommandBuffer_SetClipRect(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST RECT* pRect); +void WINAPI D3DCommandBuffer_SetViewport(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST D3DVIEWPORT9* pViewport); +void WINAPI D3DCommandBuffer_SetVertexShaderConstantF(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST float* pConstantData); +void WINAPI D3DCommandBuffer_SetPixelShaderConstantF(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST float* pConstantData); +void WINAPI D3DCommandBuffer_SetVertexShader(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DVertexShader* pVertexShader); +void WINAPI D3DCommandBuffer_SetPixelShader(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DPixelShader* pPixelShader); +void WINAPI D3DCommandBuffer_SetTexture(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DBaseTexture* pTexture); +void WINAPI D3DCommandBuffer_SetIndexBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DIndexBuffer* pIndexBuffer); +void WINAPI D3DCommandBuffer_SetVertexBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DVertexBuffer* pVertexBuffer); +void WINAPI D3DCommandBuffer_SetConstantBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DConstantBuffer* pConstantBuffer); +void WINAPI D3DCommandBuffer_SetCommandBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DCommandBuffer* pCommandBuffer); + +D3DINLINE ULONG WINAPI IDirect3DCommandBuffer9_AddRef(__in D3DCommandBuffer *pThis) { return D3DResource_AddRef((D3DResource *)pThis); } +D3DINLINE ULONG WINAPI IDirect3DCommandBuffer9_Release(__in D3DCommandBuffer *pThis) { return D3DResource_Release((D3DResource *)pThis); } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_GetDevice(__in D3DCommandBuffer *pThis, __deref_out D3DDevice **ppDevice) { D3DResource_GetDevice((D3DResource *)pThis, ppDevice); D3DVOIDRETURN; } +D3DINLINE D3DRESOURCETYPE WINAPI IDirect3DCommandBuffer9_GetType(__in D3DCommandBuffer *pThis) { return D3DResource_GetType((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DCommandBuffer9_IsBusy(__in D3DCommandBuffer *pThis) { return D3DResource_IsBusy((D3DResource *)pThis); } +D3DINLINE BOOL WINAPI IDirect3DCommandBuffer9_IsSet(__in D3DCommandBuffer *pThis, __in D3DDevice *pDevice) { return D3DResource_IsSet((D3DResource *)pThis, pDevice); } +D3DINLINE void WINAPI IDirect3DCommandBuffer9_BlockUntilNotBusy(__in D3DCommandBuffer *pThis) { D3DResource_BlockUntilNotBusy((D3DResource *)pThis); } + +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_GetResources(__in D3DCommandBuffer *pThis, DWORD Flags, __out_ecount_opt(*pBufferSize) D3DResource** ppResourceList, __inout DWORD* pBufferSize) { D3DCommandBuffer_GetResources(pThis, Flags, ppResourceList, pBufferSize); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DCommandBuffer9_CreateClone(__in D3DCommandBuffer *pThis, DWORD Flags, __deref_out D3DCommandBuffer** ppCommandBuffer) { return (*ppCommandBuffer = D3DCommandBuffer_CreateClone(pThis, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_GetClone(__in D3DCommandBuffer *pThis, DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize) { D3DCommandBuffer_GetClone(pThis, Flags, pHeaderPart, pHeaderSize, pPhysicalPart, pPhysicalSize); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_BeginFixupCreation(__in D3DCommandBuffer *pThis) { D3DCommandBuffer_BeginFixupCreation(pThis); D3DVOIDRETURN; } +D3DINLINE HRESULT WINAPI IDirect3DCommandBuffer9_EndFixupCreation(__in D3DCommandBuffer *pThis) { return D3DCommandBuffer_EndFixupCreation(pThis); } +D3DINLINE HRESULT WINAPI IDirect3DCommandBuffer9_Deconstruct(__in D3DCommandBuffer *pThis, DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize, __out_bcount_opt(*pInitializationSize) void* pInitializationPart, __inout DWORD* pInitializationSize) { return D3DCommandBuffer_Deconstruct(pThis, Flags, pHeaderPart, pHeaderSize, pPhysicalPart, pPhysicalSize, pInitializationPart, pInitializationSize); } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_BeginReconstruction(__in D3DCommandBuffer *pThis, DWORD Flags, __in void* pPhysicalPart, __in void* pInitializationPart) { D3DCommandBuffer_BeginReconstruction(pThis, Flags, pPhysicalPart, pInitializationPart); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_EndReconstruction(__in D3DCommandBuffer *pThis) { D3DCommandBuffer_EndReconstruction(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_BeginDynamicFixups(__in D3DCommandBuffer *pThis) { D3DCommandBuffer_BeginDynamicFixups(pThis); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_EndDynamicFixups(__in D3DCommandBuffer *pThis) { D3DCommandBuffer_EndDynamicFixups(pThis); D3DVOIDRETURN; } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateSurfacesFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateSurfacesFixup(pThis, Flags, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateClipRectFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateClipRectFixup(pThis, Flags, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateViewportFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateViewportFixup(pThis, Flags, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateVertexShaderConstantFFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateVertexShaderConstantFFixup(pThis, Flags, StartRegister, Vector4fCount, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreatePixelShaderConstantFFixup(__in D3DCommandBuffer *pThis, DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreatePixelShaderConstantFFixup(pThis, Flags, StartRegister, Vector4fCount, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateVertexShaderFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DVertexShader* pVertexShader, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateVertexShaderFixup(pThis, Flags, pVertexShader, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreatePixelShaderFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DPixelShader* pPixelShader, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreatePixelShaderFixup(pThis, Flags, pPixelShader, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateTextureFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DBaseTexture* pTexture, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateTextureFixup(pThis, Flags, pTexture, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateIndexBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DIndexBuffer* pIndexBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateIndexBufferFixup(pThis, Flags, pIndexBuffer, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateVertexBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DVertexBuffer* pVertexBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateVertexBufferFixup(pThis, Flags, pVertexBuffer, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateConstantBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DConstantBuffer* pConstantBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateConstantBufferFixup(pThis, Flags, pConstantBuffer, StartMarker, StopMarker); } +D3DINLINE DWORD WINAPI IDirect3DCommandBuffer9_CreateCommandBufferFixup(__in D3DCommandBuffer *pThis, DWORD Flags, __in D3DCommandBuffer* pCommandBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateCommandBufferFixup(pThis, Flags, pCommandBuffer, StartMarker, StopMarker); } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetSurfaces(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST D3DSURFACES* pSurfaces) { D3DCommandBuffer_SetSurfaces(pThis, FixupHandle, pSurfaces); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetClipRect(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST RECT* pRect) { D3DCommandBuffer_SetClipRect(pThis, FixupHandle, pRect); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetViewport(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST D3DVIEWPORT9* pViewport) { D3DCommandBuffer_SetViewport(pThis, FixupHandle, pViewport); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetVertexShaderConstantF(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST float* pConstantData) { D3DCommandBuffer_SetVertexShaderConstantF(pThis, FixupHandle, pConstantData); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetPixelShaderConstantF(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in CONST float* pConstantData) { D3DCommandBuffer_SetPixelShaderConstantF(pThis, FixupHandle, pConstantData); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetVertexShader(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DVertexShader* pVertexShader) { D3DCommandBuffer_SetVertexShader(pThis, FixupHandle, pVertexShader); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetPixelShader(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DPixelShader* pPixelShader) { D3DCommandBuffer_SetPixelShader(pThis, FixupHandle, pPixelShader); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetTexture(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DBaseTexture* pTexture) { D3DCommandBuffer_SetTexture(pThis, FixupHandle, pTexture); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetIndexBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DIndexBuffer* pIndexBuffer) { D3DCommandBuffer_SetIndexBuffer(pThis, FixupHandle, pIndexBuffer); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetVertexBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DVertexBuffer* pVertexBuffer) { D3DCommandBuffer_SetVertexBuffer(pThis, FixupHandle, pVertexBuffer); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetConstantBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DConstantBuffer* pConstantBuffer) { D3DCommandBuffer_SetConstantBuffer(pThis, FixupHandle, pConstantBuffer); D3DVOIDRETURN; } +D3DINLINE D3DVOID WINAPI IDirect3DCommandBuffer9_SetCommandBuffer(__in D3DCommandBuffer *pThis, DWORD FixupHandle, __in D3DCommandBuffer* pCommandBuffer) { D3DCommandBuffer_SetCommandBuffer(pThis, FixupHandle, pCommandBuffer); D3DVOIDRETURN; } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::GetResources(DWORD Flags, __out_ecount_opt(*pBufferSize) D3DResource** ppResourceList, __inout DWORD* pBufferSize) { D3DCommandBuffer_GetResources(this, Flags, ppResourceList, pBufferSize); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DCommandBuffer::CreateClone(DWORD Flags, __deref_out D3DCommandBuffer** ppCommandBuffer) { return (*ppCommandBuffer = D3DCommandBuffer_CreateClone(this, Flags)) != NULL ? S_OK : E_OUTOFMEMORY; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::GetClone(DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize) { D3DCommandBuffer_GetClone(this, Flags, pHeaderPart, pHeaderSize, pPhysicalPart, pPhysicalSize); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::BeginFixupCreation() { D3DCommandBuffer_BeginFixupCreation(this); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DCommandBuffer::EndFixupCreation() { return D3DCommandBuffer_EndFixupCreation(this); } +D3DMINLINE HRESULT WINAPI D3DCommandBuffer::Deconstruct(DWORD Flags, __out_bcount_opt(*pHeaderSize) D3DCommandBuffer* pHeaderPart, __inout DWORD* pHeaderSize, __out_bcount_opt(*pPhysicalSize) void* pPhysicalPart, __inout DWORD* pPhysicalSize, __out_bcount_opt(*pInitializationSize) void* pInitializationPart, __inout DWORD* pInitializationSize) { return D3DCommandBuffer_Deconstruct(this, Flags, pHeaderPart, pHeaderSize, pPhysicalPart, pPhysicalSize, pInitializationPart, pInitializationSize); } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::BeginReconstruction(DWORD Flags, __in void* pPhysicalPart, __in void* pInitializationPart) { D3DCommandBuffer_BeginReconstruction(this, Flags, pPhysicalPart, pInitializationPart); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::EndReconstruction() { D3DCommandBuffer_EndReconstruction(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::BeginDynamicFixups() { D3DCommandBuffer_BeginDynamicFixups(this); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::EndDynamicFixups() { D3DCommandBuffer_EndDynamicFixups(this); D3DVOIDRETURN; } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateSurfacesFixup(DWORD Flags, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateSurfacesFixup(this, Flags, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateClipRectFixup(DWORD Flags, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateClipRectFixup(this, Flags, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateViewportFixup(DWORD Flags, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateViewportFixup(this, Flags, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateVertexShaderConstantFFixup(DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateVertexShaderConstantFFixup(this, Flags, StartRegister, Vector4fCount, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreatePixelShaderConstantFFixup(DWORD Flags, DWORD StartRegister, DWORD Vector4fCount, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreatePixelShaderConstantFFixup(this, Flags, StartRegister, Vector4fCount, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateVertexShaderFixup(DWORD Flags, __in D3DVertexShader* pVertexShader, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateVertexShaderFixup(this, Flags, pVertexShader, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreatePixelShaderFixup(DWORD Flags, __in D3DPixelShader* pPixelShader, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreatePixelShaderFixup(this, Flags, pPixelShader, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateTextureFixup(DWORD Flags, __in D3DBaseTexture* pTexture, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateTextureFixup(this, Flags, pTexture, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateIndexBufferFixup(DWORD Flags, __in D3DIndexBuffer* pIndexBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateIndexBufferFixup(this, Flags, pIndexBuffer, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateVertexBufferFixup(DWORD Flags, __in D3DVertexBuffer* pVertexBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateVertexBufferFixup(this, Flags, pVertexBuffer, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateConstantBufferFixup(DWORD Flags, __in D3DConstantBuffer* pConstantBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateConstantBufferFixup(this, Flags, pConstantBuffer, StartMarker, StopMarker); } +D3DMINLINE DWORD WINAPI D3DCommandBuffer::CreateCommandBufferFixup(DWORD Flags, __in D3DCommandBuffer* pCommandBuffer, DWORD StartMarker, DWORD StopMarker) { return D3DCommandBuffer_CreateCommandBufferFixup(this, Flags, pCommandBuffer, StartMarker, StopMarker); } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetSurfaces(DWORD FixupHandle, __in CONST D3DSURFACES* pSurfaces) { D3DCommandBuffer_SetSurfaces(this, FixupHandle, pSurfaces); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetClipRect(DWORD FixupHandle, __in CONST RECT* pRect) { D3DCommandBuffer_SetClipRect(this, FixupHandle, pRect); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetViewport(DWORD FixupHandle, __in CONST D3DVIEWPORT9* pViewport) { D3DCommandBuffer_SetViewport(this, FixupHandle, pViewport); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetVertexShaderConstantF(DWORD FixupHandle, __in CONST float* pConstantData) { D3DCommandBuffer_SetVertexShaderConstantF(this, FixupHandle, pConstantData); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetPixelShaderConstantF(DWORD FixupHandle, __in CONST float* pConstantData) { D3DCommandBuffer_SetPixelShaderConstantF(this, FixupHandle, pConstantData); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetVertexShader(DWORD FixupHandle, __in D3DVertexShader* pVertexShader) { D3DCommandBuffer_SetVertexShader(this, FixupHandle, pVertexShader); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetPixelShader(DWORD FixupHandle, __in D3DPixelShader* pPixelShader) { D3DCommandBuffer_SetPixelShader(this, FixupHandle, pPixelShader); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetTexture(DWORD FixupHandle, __in D3DBaseTexture* pTexture) { D3DCommandBuffer_SetTexture(this, FixupHandle, pTexture); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetIndexBuffer(DWORD FixupHandle, __in D3DIndexBuffer* pIndexBuffer) { D3DCommandBuffer_SetIndexBuffer(this, FixupHandle, pIndexBuffer); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetVertexBuffer(DWORD FixupHandle, __in D3DVertexBuffer* pVertexBuffer) { D3DCommandBuffer_SetVertexBuffer(this, FixupHandle, pVertexBuffer); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetConstantBuffer(DWORD FixupHandle, __in D3DConstantBuffer* pConstantBuffer) { D3DCommandBuffer_SetConstantBuffer(this, FixupHandle, pConstantBuffer); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DCommandBuffer::SetCommandBuffer(DWORD FixupHandle, __in D3DCommandBuffer* pCommandBuffer) { D3DCommandBuffer_SetCommandBuffer(this, FixupHandle, pCommandBuffer); D3DVOIDRETURN; } + +#endif __cplusplus + +void WINAPI D3DAsyncCommandBufferCall_FixupAndSignalEx(__in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, __in_ecount_opt(CommandBufferCount) D3DCommandBuffer** ppUserCommandBuffers, __in_ecount_opt(CommandBufferCount) DWORD* pPredicationSelects, DWORD CommandBufferCount, DWORD Flags); +D3DINLINE void WINAPI D3DAsyncCommandBufferCall_FixupAndSignal(__in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, D3DCommandBuffer* pUserCommandBuffer, DWORD PredicationSelect, DWORD Flags) { D3DAsyncCommandBufferCall_FixupAndSignalEx(pAsyncCommandBufferCall, &pUserCommandBuffer, &PredicationSelect, 1, Flags); } +HRESULT WINAPI D3DAsyncCommandBufferCall_Reset(__in D3DAsyncCommandBufferCall* pD3DCall, __in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags); + +D3DINLINE D3DVOID WINAPI IDirect3DAsyncCommandBufferCall9_FixupAndSignal(__in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, __in_opt D3DCommandBuffer* pUserCommandBuffer, DWORD PredicationSelect, DWORD Flags) { D3DAsyncCommandBufferCall_FixupAndSignalEx(pAsyncCommandBufferCall, &pUserCommandBuffer, &PredicationSelect, 1, Flags); } +D3DINLINE D3DVOID WINAPI IDirect3DAsyncCommandBufferCall9_FixupAndSignalEx(__in D3DAsyncCommandBufferCall* pAsyncCommandBufferCall, __in_ecount_opt(CommandBufferCount) D3DCommandBuffer** pUserCommandBuffers, __in_ecount_opt(CommandBufferCount) DWORD* PredicationSelects, DWORD CommandBufferCount, DWORD Flags) { D3DAsyncCommandBufferCall_FixupAndSignalEx(pAsyncCommandBufferCall, pUserCommandBuffers, PredicationSelects, CommandBufferCount, Flags); } +D3DINLINE HRESULT WINAPI IDirect3DAsyncCommandBufferCall9_Reset(__in D3DAsyncCommandBufferCall* pD3DCall, __in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags) { return D3DAsyncCommandBufferCall_Reset(pD3DCall, pInheritTags, pPersistTags, NumSegments, Flags); } + +#ifdef __cplusplus + +D3DMINLINE D3DVOID WINAPI D3DAsyncCommandBufferCall::FixupAndSignal(__in_opt D3DCommandBuffer* pUserCommandBuffer, DWORD PredicationSelect, DWORD Flags) { D3DAsyncCommandBufferCall_FixupAndSignalEx(this, &pUserCommandBuffer, &PredicationSelect, 1, Flags); D3DVOIDRETURN; } +D3DMINLINE D3DVOID WINAPI D3DAsyncCommandBufferCall::FixupAndSignalEx(__in_ecount_opt(CommandBufferCount) D3DCommandBuffer** ppUserCommandBuffers, __in_ecount_opt(CommandBufferCount) DWORD* pPredicationSelects, DWORD CommandBufferCount, DWORD Flags) { D3DAsyncCommandBufferCall_FixupAndSignalEx(this, ppUserCommandBuffers, pPredicationSelects, CommandBufferCount, Flags); D3DVOIDRETURN; } +D3DMINLINE HRESULT WINAPI D3DAsyncCommandBufferCall::Reset(__in_opt D3DTAGCOLLECTION* pInheritTags, __in_opt D3DTAGCOLLECTION* pPersistTags, DWORD NumSegments, DWORD Flags) { return D3DAsyncCommandBufferCall_Reset(this, pInheritTags, pPersistTags, NumSegments, Flags); } + +#endif __cplusplus + +#ifdef __cplusplus +}; +#endif + +/* PIX Utility Functions */ + +#ifdef __cplusplus +extern "C" { +#endif + +HRESULT WINAPI PIXCaptureTimingFrame(__in_z char *pFilename); +HRESULT WINAPI PIXCaptureGpuFrame(__in_z char *pFilename); + +#if defined(USE_D3D_PIX_METHODS) && defined(_XBOX) + +HRESULT WINAPI PIXEnableTextureTracking(DWORD TrackerThread, DWORD TrackerCommandBufferSize, __in_opt D3DTEXTURETRACKERERRORCALLBACK pCallback); +HRESULT WINAPI PIXDisableTextureTracking(); +HRESULT WINAPI PIXBeginTextureCapture(DWORD AutoSaveFrequency, DWORD ScreenCaptureFrequency, DWORD ChannelSoftCompareThreshold, __in_z const char* pFilename); +HRESULT WINAPI PIXEndTextureCapture(); + +HRESULT WINAPI PIXIgnoreTexture(__in D3DBaseTexture* pTexture); +HRESULT WINAPI PIXStopIgnoringTexture(__in D3DBaseTexture* pTexture); +HRESULT WINAPI PIXIgnoreMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size); +HRESULT WINAPI PIXStopIgnoringMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size); +HRESULT WINAPI PIXSetTextureName(__in D3DBaseTexture* pTexture, __in_z const char* pName); +HRESULT WINAPI PIXReportNewTexture(__in D3DBaseTexture* pTexture); +HRESULT WINAPI PIXReportDeletedTexture(__in D3DBaseTexture* pTexture, BOOL BaseDeleted, BOOL MipDeleted); +HRESULT WINAPI PIXReportMovedMemoryRange(__in_bcount(Size) const void* pDestinationAddress, __in_bcount(Size) const void* pSourceAddress, DWORD Size); +HRESULT WINAPI PIXReportFreedMemoryRange(__in_bcount(Size) const void* pAddress, DWORD Size); + +#else + +// Make PIX texture tracking methods disappear on retail and X86 builds + +D3DINLINE HRESULT WINAPI PIXEnableTextureTracking(DWORD TrackerThread, DWORD TrackerCommandBufferSize, __in_opt D3DTEXTURETRACKERERRORCALLBACK pCallback) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXDisableTextureTracking() { return S_OK; } +D3DINLINE HRESULT WINAPI PIXBeginTextureCapture(DWORD AutoSaveFrequency, DWORD ScreenCaptureFrequency, DWORD ChannelSoftCompareThreshold, __in_z const char* pFilename) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXEndTextureCapture() { return S_OK; } + +D3DINLINE HRESULT WINAPI PIXIgnoreTexture(__in D3DBaseTexture* pTexture) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXStopIgnoringTexture(__in D3DBaseTexture* pTexture) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXIgnoreMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXStopIgnoringMemoryRange(__in_bcount(Size) const void* pBaseAddress, DWORD Size) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXSetTextureName(__in D3DBaseTexture* pTexture, __in_z const char* pName) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXReportNewTexture(__in D3DBaseTexture* pTexture) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXReportDeletedTexture(__in D3DBaseTexture* pTexture, BOOL BaseDeleted, BOOL MipDeleted) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXReportMovedMemoryRange(__in_bcount(Size) const void* pDestinationAddress, __in_bcount(Size) const void* pSourceAddress, DWORD Size) { return S_OK; } +D3DINLINE HRESULT WINAPI PIXReportFreedMemoryRange(__in_bcount(Size) const void* pAddress, DWORD Size) { return S_OK; } + +#endif + +#ifdef __cplusplus +}; +#endif + +/**************************************************************************** + * + * Additional C++ definitions for Win64 compatibility + * + ****************************************************************************/ + +#ifdef __cplusplus + + template < typename T > + D3DINLINE + T* D3DNew() + { + void* const ptr = D3DAlloc(sizeof(T)); + return new(ptr) T; + } + + template < typename T > + D3DINLINE + void D3DDelete(T* ptr) + { + ptr->~T(); + D3DFree(ptr); + } + + template < typename T > + D3DINLINE + T* D3DNewArray(SIZE_T n) + { + void* const mem = ::D3DAlloc(sizeof(SIZE_T) + sizeof(void*) + 16 + sizeof(T) * n); + UINT_PTR const ptrAligned = (UINT_PTR(mem) + sizeof(SIZE_T) + sizeof(void*) + 15) & ~15; + + *(SIZE_T*)(ptrAligned - sizeof(SIZE_T)) = n; + *(void**)(ptrAligned - sizeof(SIZE_T) - sizeof(void*)) = mem; + + T* const ptr = (T*)ptrAligned; + + for (SIZE_T i = 0; i < n; ++i) + { + new(ptr + i) T; + } + + return ptr; + } + + template < typename T > + D3DINLINE + void D3DDeleteArray(T* ptr) + { + UINT_PTR const ptrAligned = UINT_PTR(ptr); + + SIZE_T const n = *(SIZE_T*)(ptrAligned - sizeof(SIZE_T)); + void* const mem = *(void**)(ptrAligned - sizeof(SIZE_T) - sizeof(void*)); + + for (SIZE_T i = 0; i < n; ++i) + { + ptr[i].~T(); + } + + ::D3DFree(mem); + } + + template < typename T > + __forceinline + T* D3DDWORDToPtr(DWORD dw) + { + return (T*) ::D3DDWORDToPtr(dw); + } + +#endif + +#pragma warning( pop ) + +#endif /* _D3D9_H_ */ diff --git a/third_party/xbox_sdk/include/d3d9caps.h b/third_party/xbox_sdk/include/d3d9caps.h new file mode 100644 index 0000000..a2e2874 --- /dev/null +++ b/third_party/xbox_sdk/include/d3d9caps.h @@ -0,0 +1,531 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: d3d9caps.h + * Content: Direct3D capabilities include file + * + ***************************************************************************/ + +#ifndef _d3d9CAPS_H +#define _d3d9CAPS_H + +#ifndef DIRECT3D_VERSION +#define DIRECT3D_VERSION 0x0900 +#endif //DIRECT3D_VERSION + +// include this file content only if compiling for DX9 interfaces +#if(DIRECT3D_VERSION >= 0x0900) + +#if defined(_X86_) || defined(_IA64) +#pragma pack(push, 4) +#endif + +/* + * Various handy maximums for Xbox 360 D3D + */ +// The maximum number of streams +#define D3DMAXSTREAMS 16 + +// The maximum number of float vertex shader constants +#define D3DMAXVERTEXSHADERCONSTANTSF GPU_D3D_VERTEX_CONSTANTF_COUNT + +// The maximum number of integer vertex shader constants +#define D3DMAXVERTEXSHADERCONSTANTSI GPU_D3D_VERTEX_CONSTANTI_COUNT + +// The maximum number of boolean vertex shader constants +#define D3DMAXVERTEXSHADERCONSTANTSB GPU_D3D_VERTEX_CONSTANTB_COUNT + +// The maximum number of float pixel shader constants +#define D3DMAXPIXELSHADERCONSTANTSF GPU_D3D_PIXEL_CONSTANTF_COUNT + +// The maximum number of integer pixel shader constants +#define D3DMAXPIXELSHADERCONSTANTSI GPU_D3D_PIXEL_CONSTANTI_COUNT + +// The maximum number of boolean pixel shader constants +#define D3DMAXPIXELSHADERCONSTANTSB GPU_D3D_PIXEL_CONSTANTB_COUNT + +// The maximum shader instructions (shared between pixel and vertex shader) +#define D3DMAXSHADERINSTRUCTIONS GPU_INSTRUCTIONS + +// The maximum number of simultaneous render targets +#define D3DMAXRENDERTARGETS 4 + +// The maximum number of user clipping planes +#define D3DMAXUSERCLIPPLANES 6 + +// The maximum dimension for textures and cubemaps +#define D3DMAXTEXTUREDIMENSION GPU_MAX_TEXTURE_DIMENSION + +// The maximum offset of a renderable surface offset (there's 10MB of EDRAM) +#define D3DMAXSURFACEOFFSET GPU_EDRAM_SIZE + +// The maximum number of samplers +#define D3DSAMP_MAXSAMPLERS GPU_D3D_TEXTURE_FETCH_CONSTANT_COUNT + +// The source rectangle for Resolve must be 8x8 pixel aligned +#define D3DRESOLVEALIGNMENT GPU_RESOLVE_ALIGNMENT + +// The maximum number of texture stages supported by the fixed function +// pipeline, if the fixed function pipeline were to be supported on Xbox 360 +// (which it's not) +#define D3DTSS_MAXSTAGES 8 + +/* + * Standard DirectX 9 structures + */ +typedef struct _D3DVSHADERCAPS2_0 +{ + DWORD Caps; + INT DynamicFlowControlDepth; + INT NumTemps; + INT StaticFlowControlDepth; +} D3DVSHADERCAPS2_0; + +#define D3DVS20CAPS_PREDICATION (1<<0) + +#define D3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH 24 +#define D3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH 0 +#define D3DVS20_MAX_NUMTEMPS 32 +#define D3DVS20_MIN_NUMTEMPS 12 +#define D3DVS20_MAX_STATICFLOWCONTROLDEPTH 4 +#define D3DVS20_MIN_STATICFLOWCONTROLDEPTH 1 + +typedef struct _D3DPSHADERCAPS2_0 +{ + DWORD Caps; + INT DynamicFlowControlDepth; + INT NumTemps; + INT StaticFlowControlDepth; + INT NumInstructionSlots; +} D3DPSHADERCAPS2_0; + +#define D3DPS20CAPS_ARBITRARYSWIZZLE (1<<0) +#define D3DPS20CAPS_GRADIENTINSTRUCTIONS (1<<1) +#define D3DPS20CAPS_PREDICATION (1<<2) +#define D3DPS20CAPS_NODEPENDENTREADLIMIT (1<<3) +#define D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT (1<<4) + +#define D3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH 24 +#define D3DPS20_MIN_DYNAMICFLOWCONTROLDEPTH 0 +#define D3DPS20_MAX_NUMTEMPS 32 +#define D3DPS20_MIN_NUMTEMPS 12 +#define D3DPS20_MAX_STATICFLOWCONTROLDEPTH 4 +#define D3DPS20_MIN_STATICFLOWCONTROLDEPTH 0 +#define D3DPS20_MAX_NUMINSTRUCTIONSLOTS 512 +#define D3DPS20_MIN_NUMINSTRUCTIONSLOTS 96 + +#define D3DMIN30SHADERINSTRUCTIONS 512 +#define D3DMAX30SHADERINSTRUCTIONS 32768 + +typedef struct _D3DCAPS9 +{ + /* Device Info */ + D3DDEVTYPE DeviceType; + UINT AdapterOrdinal; + + /* Caps from DX7 Draw */ + DWORD Caps; + DWORD Caps2; + DWORD Caps3; + DWORD PresentationIntervals; + + /* Cursor Caps */ + DWORD CursorCaps; + + /* 3D Device Caps */ + DWORD DevCaps; + + DWORD PrimitiveMiscCaps; + DWORD RasterCaps; + DWORD ZCmpCaps; + DWORD SrcBlendCaps; + DWORD DestBlendCaps; + DWORD AlphaCmpCaps; + DWORD ShadeCaps; + DWORD TextureCaps; + DWORD TextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DTexture9's + DWORD CubeTextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DCubeTexture9's + DWORD VolumeTextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DVolumeTexture9's + DWORD TextureAddressCaps; // D3DPTADDRESSCAPS for IDirect3DTexture9's + DWORD VolumeTextureAddressCaps; // D3DPTADDRESSCAPS for IDirect3DVolumeTexture9's + + DWORD LineCaps; // D3DLINECAPS + + DWORD MaxTextureWidth, MaxTextureHeight; + DWORD MaxVolumeExtent; + + DWORD MaxTextureRepeat; + DWORD MaxTextureAspectRatio; + DWORD MaxAnisotropy; + float MaxVertexW; + + float GuardBandLeft; + float GuardBandTop; + float GuardBandRight; + float GuardBandBottom; + + float ExtentsAdjust; + DWORD StencilCaps; + + DWORD FVFCaps; + DWORD TextureOpCaps; + DWORD MaxTextureBlendStages; + DWORD MaxSimultaneousTextures; + + DWORD VertexProcessingCaps; + DWORD MaxActiveLights; + DWORD MaxUserClipPlanes; + DWORD MaxVertexBlendMatrices; + DWORD MaxVertexBlendMatrixIndex; + + float MaxPointSize; + + DWORD MaxPrimitiveCount; // max number of primitives per DrawPrimitive call + DWORD MaxVertexIndex; + DWORD MaxStreams; + DWORD MaxStreamStride; // max stride for SetStreamSource + + DWORD VertexShaderVersion; + DWORD MaxVertexShaderConst; // number of vertex shader constant registers + + DWORD PixelShaderVersion; + float PixelShader1xMaxValue; // max value storable in registers of ps.1.x shaders + + // Here are the DX9 specific ones + DWORD DevCaps2; + + float MaxNpatchTessellationLevel; + DWORD Reserved5; + + UINT MasterAdapterOrdinal; // ordinal of master adaptor for adapter group + UINT AdapterOrdinalInGroup; // ordinal inside the adapter group + UINT NumberOfAdaptersInGroup; // number of adapters in this adapter group (only if master) + DWORD DeclTypes; // Data types, supported in vertex declarations + DWORD NumSimultaneousRTs; // Will be at least 1 + DWORD StretchRectFilterCaps; // Filter caps supported by StretchRect + D3DVSHADERCAPS2_0 VS20Caps; + D3DPSHADERCAPS2_0 PS20Caps; + DWORD VertexTextureFilterCaps; // D3DPTFILTERCAPS for IDirect3DTexture9's for texture, used in vertex shaders + DWORD MaxVShaderInstructionsExecuted; // maximum number of vertex shader instructions that can be executed + DWORD MaxPShaderInstructionsExecuted; // maximum number of pixel shader instructions that can be executed + DWORD MaxVertexShader30InstructionSlots; + DWORD MaxPixelShader30InstructionSlots; +} D3DCAPS9; + +// +// BIT DEFINES FOR D3DCAPS9 DWORD MEMBERS +// + +// +// Caps +// +#define D3DCAPS_READ_SCANLINE 0x00020000L + +// +// Caps2 +// +#define D3DCAPS2_FULLSCREENGAMMA 0x00020000L +#define D3DCAPS2_CANCALIBRATEGAMMA 0x00100000L +#define D3DCAPS2_RESERVED 0x02000000L +#define D3DCAPS2_CANMANAGERESOURCE 0x10000000L +#define D3DCAPS2_DYNAMICTEXTURES 0x20000000L +#define D3DCAPS2_CANAUTOGENMIPMAP 0x40000000L + +// +// Caps3 +// +#define D3DCAPS3_RESERVED 0x8000001fL + +// Indicates that the device can respect the ALPHABLENDENABLE render state +// when fullscreen while using the FLIP or DISCARD swap effect. +// COPY and COPYVSYNC swap effects work whether or not this flag is set. +#define D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD 0x00000020L + +// Indicates that the device can perform a gamma correction from +// a windowed back buffer containing linear content to the sRGB desktop. +#define D3DCAPS3_LINEAR_TO_SRGB_PRESENTATION 0x00000080L + +#define D3DCAPS3_COPY_TO_VIDMEM 0x00000100L /* Device can acclerate copies from sysmem to local vidmem */ +#define D3DCAPS3_COPY_TO_SYSTEMMEM 0x00000200L /* Device can acclerate copies from local vidmem to sysmem */ + + +// +// PresentationIntervals +// +#define D3DPRESENT_INTERVAL_DEFAULT 0x00000000L +#define D3DPRESENT_INTERVAL_ONE 0x00000001L +#define D3DPRESENT_INTERVAL_TWO 0x00000002L +#define D3DPRESENT_INTERVAL_THREE 0x00000004L +#define D3DPRESENT_INTERVAL_FOUR 0x00000008L +#define D3DPRESENT_INTERVAL_IMMEDIATE 0x80000000L + +// +// CursorCaps +// +// Driver supports HW color cursor in at least hi-res modes(height >=400) +#define D3DCURSORCAPS_COLOR 0x00000001L +// Driver supports HW cursor also in low-res modes(height < 400) +#define D3DCURSORCAPS_LOWRES 0x00000002L + +// +// DevCaps +// +#define D3DDEVCAPS_EXECUTESYSTEMMEMORY 0x00000010L /* Device can use execute buffers from system memory */ +#define D3DDEVCAPS_EXECUTEVIDEOMEMORY 0x00000020L /* Device can use execute buffers from video memory */ +#define D3DDEVCAPS_TLVERTEXSYSTEMMEMORY 0x00000040L /* Device can use TL buffers from system memory */ +#define D3DDEVCAPS_TLVERTEXVIDEOMEMORY 0x00000080L /* Device can use TL buffers from video memory */ +#define D3DDEVCAPS_TEXTURESYSTEMMEMORY 0x00000100L /* Device can texture from system memory */ +#define D3DDEVCAPS_TEXTUREVIDEOMEMORY 0x00000200L /* Device can texture from device memory */ +#define D3DDEVCAPS_DRAWPRIMTLVERTEX 0x00000400L /* Device can draw TLVERTEX primitives */ +#define D3DDEVCAPS_CANRENDERAFTERFLIP 0x00000800L /* Device can render without waiting for flip to complete */ +#define D3DDEVCAPS_TEXTURENONLOCALVIDMEM 0x00001000L /* Device can texture from nonlocal video memory */ +#define D3DDEVCAPS_DRAWPRIMITIVES2 0x00002000L /* Device can support DrawPrimitives2 */ +#define D3DDEVCAPS_SEPARATETEXTUREMEMORIES 0x00004000L /* Device is texturing from separate memory pools */ +#define D3DDEVCAPS_DRAWPRIMITIVES2EX 0x00008000L /* Device can support Extended DrawPrimitives2 i.e. DX7 compliant driver*/ +#define D3DDEVCAPS_HWTRANSFORMANDLIGHT 0x00010000L /* Device can support transformation and lighting in hardware and DRAWPRIMITIVES2EX must be also */ +#define D3DDEVCAPS_CANBLTSYSTONONLOCAL 0x00020000L /* Device supports a Tex Blt from system memory to non-local vidmem */ +#define D3DDEVCAPS_HWRASTERIZATION 0x00080000L /* Device has HW acceleration for rasterization */ +#define D3DDEVCAPS_PUREDEVICE 0x00100000L /* Device supports D3DCREATE_PUREDEVICE */ +#define D3DDEVCAPS_QUINTICRTPATCHES 0x00200000L /* Device supports quintic Beziers and BSplines */ +#define D3DDEVCAPS_RTPATCHES 0x00400000L /* Device supports Rect and Tri patches */ +#define D3DDEVCAPS_RTPATCHHANDLEZERO 0x00800000L /* Indicates that RT Patches may be drawn efficiently using handle 0 */ +#define D3DDEVCAPS_NPATCHES 0x01000000L /* Device supports N-Patches */ + +// +// PrimitiveMiscCaps +// +#define D3DPMISCCAPS_MASKZ 0x00000002L +#define D3DPMISCCAPS_CULLNONE 0x00000010L +#define D3DPMISCCAPS_CULLCW 0x00000020L +#define D3DPMISCCAPS_CULLCCW 0x00000040L +#define D3DPMISCCAPS_COLORWRITEENABLE 0x00000080L +#define D3DPMISCCAPS_CLIPPLANESCALEDPOINTS 0x00000100L /* Device correctly clips scaled points to clip planes */ +#define D3DPMISCCAPS_CLIPTLVERTS 0x00000200L /* device will clip post-transformed vertex primitives */ +#define D3DPMISCCAPS_TSSARGTEMP 0x00000400L /* device supports D3DTA_TEMP for temporary register */ +#define D3DPMISCCAPS_BLENDOP 0x00000800L /* device supports D3DRS_BLENDOP */ +#define D3DPMISCCAPS_NULLREFERENCE 0x00001000L /* Reference Device that doesnt render */ +#define D3DPMISCCAPS_INDEPENDENTWRITEMASKS 0x00004000L /* Device supports independent write masks for MET or MRT */ +#define D3DPMISCCAPS_PERSTAGECONSTANT 0x00008000L /* Device supports per-stage constants */ +#define D3DPMISCCAPS_FOGANDSPECULARALPHA 0x00010000L /* Device supports separate fog and specular alpha (many devices + use the specular alpha channel to store fog factor) */ +#define D3DPMISCCAPS_SEPARATEALPHABLEND 0x00020000L /* Device supports separate blend settings for the alpha channel */ +#define D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS 0x00040000L /* Device supports different bit depths for MRT */ +#define D3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING 0x00080000L /* Device supports post-pixel shader operations for MRT */ +#define D3DPMISCCAPS_FOGVERTEXCLAMPED 0x00100000L /* Device clamps fog blend factor per vertex */ + +// +// LineCaps +// +#define D3DLINECAPS_TEXTURE 0x00000001L +#define D3DLINECAPS_ZTEST 0x00000002L +#define D3DLINECAPS_BLEND 0x00000004L +#define D3DLINECAPS_ALPHACMP 0x00000008L +#define D3DLINECAPS_FOG 0x00000010L +#define D3DLINECAPS_ANTIALIAS 0x00000020L + +// +// RasterCaps +// +#define D3DPRASTERCAPS_DITHER 0x00000001L +#define D3DPRASTERCAPS_ZTEST 0x00000010L +#define D3DPRASTERCAPS_FOGVERTEX 0x00000080L +#define D3DPRASTERCAPS_FOGTABLE 0x00000100L +#define D3DPRASTERCAPS_MIPMAPLODBIAS 0x00002000L +#define D3DPRASTERCAPS_ZBUFFERLESSHSR 0x00008000L +#define D3DPRASTERCAPS_FOGRANGE 0x00010000L +#define D3DPRASTERCAPS_ANISOTROPY 0x00020000L +#define D3DPRASTERCAPS_WBUFFER 0x00040000L +#define D3DPRASTERCAPS_WFOG 0x00100000L +#define D3DPRASTERCAPS_ZFOG 0x00200000L +#define D3DPRASTERCAPS_COLORPERSPECTIVE 0x00400000L /* Device iterates colors perspective correct */ +#define D3DPRASTERCAPS_SCISSORTEST 0x01000000L +#define D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS 0x02000000L +#define D3DPRASTERCAPS_DEPTHBIAS 0x04000000L +#define D3DPRASTERCAPS_MULTISAMPLE_TOGGLE 0x08000000L + +// +// ZCmpCaps, AlphaCmpCaps +// +#define D3DPCMPCAPS_NEVER 0x00000001L +#define D3DPCMPCAPS_LESS 0x00000002L +#define D3DPCMPCAPS_EQUAL 0x00000004L +#define D3DPCMPCAPS_LESSEQUAL 0x00000008L +#define D3DPCMPCAPS_GREATER 0x00000010L +#define D3DPCMPCAPS_NOTEQUAL 0x00000020L +#define D3DPCMPCAPS_GREATEREQUAL 0x00000040L +#define D3DPCMPCAPS_ALWAYS 0x00000080L + +// +// SourceBlendCaps, DestBlendCaps +// +#define D3DPBLENDCAPS_ZERO 0x00000001L +#define D3DPBLENDCAPS_ONE 0x00000002L +#define D3DPBLENDCAPS_SRCCOLOR 0x00000004L +#define D3DPBLENDCAPS_INVSRCCOLOR 0x00000008L +#define D3DPBLENDCAPS_SRCALPHA 0x00000010L +#define D3DPBLENDCAPS_INVSRCALPHA 0x00000020L +#define D3DPBLENDCAPS_DESTALPHA 0x00000040L +#define D3DPBLENDCAPS_INVDESTALPHA 0x00000080L +#define D3DPBLENDCAPS_DESTCOLOR 0x00000100L +#define D3DPBLENDCAPS_INVDESTCOLOR 0x00000200L +#define D3DPBLENDCAPS_SRCALPHASAT 0x00000400L +#define D3DPBLENDCAPS_BOTHSRCALPHA 0x00000800L +#define D3DPBLENDCAPS_BOTHINVSRCALPHA 0x00001000L +#define D3DPBLENDCAPS_BLENDFACTOR 0x00002000L /* Supports both D3DBLEND_BLENDFACTOR and D3DBLEND_INVBLENDFACTOR */ + +// +// ShadeCaps +// +#define D3DPSHADECAPS_COLORGOURAUDRGB 0x00000008L +#define D3DPSHADECAPS_SPECULARGOURAUDRGB 0x00000200L +#define D3DPSHADECAPS_ALPHAGOURAUDBLEND 0x00004000L +#define D3DPSHADECAPS_FOGGOURAUD 0x00080000L + +// +// TextureCaps +// +#define D3DPTEXTURECAPS_PERSPECTIVE 0x00000001L /* Perspective-correct texturing is supported */ +#define D3DPTEXTURECAPS_POW2 0x00000002L /* Power-of-2 texture dimensions are required - applies to non-Cube/Volume textures only. */ +#define D3DPTEXTURECAPS_ALPHA 0x00000004L /* Alpha in texture pixels is supported */ +#define D3DPTEXTURECAPS_SQUAREONLY 0x00000020L /* Only square textures are supported */ +#define D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE 0x00000040L /* Texture indices are not scaled by the texture size prior to interpolation */ +#define D3DPTEXTURECAPS_ALPHAPALETTE 0x00000080L /* Device can draw alpha from texture palettes */ +// Device can use non-POW2 textures if: +// 1) D3DTEXTURE_ADDRESS is set to CLAMP for this texture's stage +// 2) D3DRS_WRAP(N) is zero for this texture's coordinates +// 3) mip mapping is not enabled (use magnification filter only) +#define D3DPTEXTURECAPS_NONPOW2CONDITIONAL 0x00000100L +#define D3DPTEXTURECAPS_PROJECTED 0x00000400L /* Device can do D3DTTFF_PROJECTED */ +#define D3DPTEXTURECAPS_CUBEMAP 0x00000800L /* Device can do cubemap textures */ +#define D3DPTEXTURECAPS_VOLUMEMAP 0x00002000L /* Device can do volume textures */ +#define D3DPTEXTURECAPS_MIPMAP 0x00004000L /* Device can do mipmapped textures */ +#define D3DPTEXTURECAPS_MIPVOLUMEMAP 0x00008000L /* Device can do mipmapped volume textures */ +#define D3DPTEXTURECAPS_MIPCUBEMAP 0x00010000L /* Device can do mipmapped cube maps */ +#define D3DPTEXTURECAPS_CUBEMAP_POW2 0x00020000L /* Device requires that cubemaps be power-of-2 dimension */ +#define D3DPTEXTURECAPS_VOLUMEMAP_POW2 0x00040000L /* Device requires that volume maps be power-of-2 dimension */ +#define D3DPTEXTURECAPS_NOPROJECTEDBUMPENV 0x00200000L /* Device does not support projected bump env lookup operation + in programmable and fixed function pixel shaders */ + +// +// TextureFilterCaps, StretchRectFilterCaps +// +#define D3DPTFILTERCAPS_MINFPOINT 0x00000100L /* Min Filter */ +#define D3DPTFILTERCAPS_MINFLINEAR 0x00000200L +#define D3DPTFILTERCAPS_MINFANISOTROPIC 0x00000400L +#define D3DPTFILTERCAPS_MINFPYRAMIDALQUAD 0x00000800L +#define D3DPTFILTERCAPS_MINFGAUSSIANQUAD 0x00001000L +#define D3DPTFILTERCAPS_MIPFPOINT 0x00010000L /* Mip Filter */ +#define D3DPTFILTERCAPS_MIPFLINEAR 0x00020000L +#define D3DPTFILTERCAPS_MAGFPOINT 0x01000000L /* Mag Filter */ +#define D3DPTFILTERCAPS_MAGFLINEAR 0x02000000L +#define D3DPTFILTERCAPS_MAGFANISOTROPIC 0x04000000L +#define D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD 0x08000000L +#define D3DPTFILTERCAPS_MAGFGAUSSIANQUAD 0x10000000L + +// +// TextureAddressCaps +// +#define D3DPTADDRESSCAPS_WRAP 0x00000001L +#define D3DPTADDRESSCAPS_MIRROR 0x00000002L +#define D3DPTADDRESSCAPS_CLAMP 0x00000004L +#define D3DPTADDRESSCAPS_BORDER 0x00000008L +#define D3DPTADDRESSCAPS_INDEPENDENTUV 0x00000010L +#define D3DPTADDRESSCAPS_MIRRORONCE 0x00000020L + +// +// StencilCaps +// +#define D3DSTENCILCAPS_KEEP 0x00000001L +#define D3DSTENCILCAPS_ZERO 0x00000002L +#define D3DSTENCILCAPS_REPLACE 0x00000004L +#define D3DSTENCILCAPS_INCRSAT 0x00000008L +#define D3DSTENCILCAPS_DECRSAT 0x00000010L +#define D3DSTENCILCAPS_INVERT 0x00000020L +#define D3DSTENCILCAPS_INCR 0x00000040L +#define D3DSTENCILCAPS_DECR 0x00000080L +#define D3DSTENCILCAPS_TWOSIDED 0x00000100L + +// +// TextureOpCaps +// +#define D3DTEXOPCAPS_DISABLE 0x00000001L +#define D3DTEXOPCAPS_SELECTARG1 0x00000002L +#define D3DTEXOPCAPS_SELECTARG2 0x00000004L +#define D3DTEXOPCAPS_MODULATE 0x00000008L +#define D3DTEXOPCAPS_MODULATE2X 0x00000010L +#define D3DTEXOPCAPS_MODULATE4X 0x00000020L +#define D3DTEXOPCAPS_ADD 0x00000040L +#define D3DTEXOPCAPS_ADDSIGNED 0x00000080L +#define D3DTEXOPCAPS_ADDSIGNED2X 0x00000100L +#define D3DTEXOPCAPS_SUBTRACT 0x00000200L +#define D3DTEXOPCAPS_ADDSMOOTH 0x00000400L +#define D3DTEXOPCAPS_BLENDDIFFUSEALPHA 0x00000800L +#define D3DTEXOPCAPS_BLENDTEXTUREALPHA 0x00001000L +#define D3DTEXOPCAPS_BLENDFACTORALPHA 0x00002000L +#define D3DTEXOPCAPS_BLENDTEXTUREALPHAPM 0x00004000L +#define D3DTEXOPCAPS_BLENDCURRENTALPHA 0x00008000L +#define D3DTEXOPCAPS_PREMODULATE 0x00010000L +#define D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR 0x00020000L +#define D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA 0x00040000L +#define D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR 0x00080000L +#define D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA 0x00100000L +#define D3DTEXOPCAPS_BUMPENVMAP 0x00200000L +#define D3DTEXOPCAPS_BUMPENVMAPLUMINANCE 0x00400000L +#define D3DTEXOPCAPS_DOTPRODUCT3 0x00800000L +#define D3DTEXOPCAPS_MULTIPLYADD 0x01000000L +#define D3DTEXOPCAPS_LERP 0x02000000L + +// +// FVFCaps +// +#define D3DFVFCAPS_TEXCOORDCOUNTMASK 0x0000ffffL /* mask for texture coordinate count field */ +#define D3DFVFCAPS_DONOTSTRIPELEMENTS 0x00080000L /* Device prefers that vertex elements not be stripped */ +#define D3DFVFCAPS_PSIZE 0x00100000L /* Device can receive point size */ + +// +// VertexProcessingCaps +// +#define D3DVTXPCAPS_TEXGEN 0x00000001L /* device can do texgen */ +#define D3DVTXPCAPS_MATERIALSOURCE7 0x00000002L /* device can do DX7-level colormaterialsource ops */ +#define D3DVTXPCAPS_DIRECTIONALLIGHTS 0x00000008L /* device can do directional lights */ +#define D3DVTXPCAPS_POSITIONALLIGHTS 0x00000010L /* device can do positional lights (includes point and spot) */ +#define D3DVTXPCAPS_LOCALVIEWER 0x00000020L /* device can do local viewer */ +#define D3DVTXPCAPS_TWEENING 0x00000040L /* device can do vertex tweening */ +#define D3DVTXPCAPS_TEXGEN_SPHEREMAP 0x00000100L /* device supports D3DTSS_TCI_SPHEREMAP */ +#define D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER 0x00000200L /* device does not support TexGen in non-local + viewer mode */ + +// +// DevCaps2 +// +#define D3DDEVCAPS2_STREAMOFFSET 0x00000001L /* Device supports offsets in streams. Must be set by DX9 drivers */ +#define D3DDEVCAPS2_DMAPNPATCH 0x00000002L /* Device supports displacement maps for N-Patches*/ +#define D3DDEVCAPS2_ADAPTIVETESSRTPATCH 0x00000004L /* Device supports adaptive tesselation of RT-patches*/ +#define D3DDEVCAPS2_ADAPTIVETESSNPATCH 0x00000008L /* Device supports adaptive tesselation of N-patches*/ +#define D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES 0x00000010L /* Device supports StretchRect calls with a texture as the source*/ +#define D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH 0x00000020L /* Device supports presampled displacement maps for N-Patches */ +#define D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET 0x00000040L /* Vertex elements in a vertex declaration can share the same stream offset */ + +// +// DeclTypes +// +#define D3DDTCAPS_UBYTE4 0x00000001L +#define D3DDTCAPS_UBYTE4N 0x00000002L +#define D3DDTCAPS_SHORT2N 0x00000004L +#define D3DDTCAPS_SHORT4N 0x00000008L +#define D3DDTCAPS_USHORT2N 0x00000010L +#define D3DDTCAPS_USHORT4N 0x00000020L +#define D3DDTCAPS_UDEC3 0x00000040L +#define D3DDTCAPS_DEC3N 0x00000080L +#define D3DDTCAPS_FLOAT16_2 0x00000100L +#define D3DDTCAPS_FLOAT16_4 0x00000200L + + +#if defined(_X86_) || defined(_IA64) +#pragma pack(pop) +#endif + +#endif /* (DIRECT3D_VERSION >= 0x0900) */ +#endif /* _d3d9CAPS_H_ */ + diff --git a/third_party/xbox_sdk/include/d3d9fftypes.h b/third_party/xbox_sdk/include/d3d9fftypes.h new file mode 100644 index 0000000..ee0d99e --- /dev/null +++ b/third_party/xbox_sdk/include/d3d9fftypes.h @@ -0,0 +1,239 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: d3d9fftypes.h + * Content: Legacy Direct3D types used by the unsupported fixed function + * pipeline + * + ***************************************************************************/ + +#ifndef _d3d9FFTYPES_H_ +#define _d3d9FFTYPES_H_ + +// Only define these items if explicitly asked for. +// (This is done to prevent the casual reintroduction +// of these types, when all the program wants is some +// other D3D fixed function data type. + +#ifdef D3DCOMPILE_DEFINE_POSITIONT_AND_XYZRHW + +#define D3DDECLUSAGE_POSITIONT ((D3DDECLUSAGE) 9) +#define D3DFVF_XYZRHW 0x004 + +#endif // D3DCOMPILE_DEFINE_POSITIONT_AND_XYZRHW + +typedef struct _D3DMATERIAL9 { + D3DCOLORVALUE Diffuse; /* Diffuse color RGBA */ + D3DCOLORVALUE Ambient; /* Ambient color RGB */ + D3DCOLORVALUE Specular; /* Specular 'shininess' */ + D3DCOLORVALUE Emissive; /* Emissive color RGB */ + float Power; /* Sharpness if specular highlight */ +} D3DMATERIAL9; + +typedef enum _D3DLIGHTTYPE { + D3DLIGHT_POINT = 1, + D3DLIGHT_SPOT = 2, + D3DLIGHT_DIRECTIONAL = 3, + D3DLIGHT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DLIGHTTYPE; + +typedef struct _D3DLIGHT9 { + D3DLIGHTTYPE Type; /* Type of light source */ + D3DCOLORVALUE Diffuse; /* Diffuse color of light */ + D3DCOLORVALUE Specular; /* Specular color of light */ + D3DCOLORVALUE Ambient; /* Ambient color of light */ + D3DVECTOR Position; /* Position in world space */ + D3DVECTOR Direction; /* Direction in world space */ + float Range; /* Cutoff range */ + float Falloff; /* Falloff */ + float Attenuation0; /* Constant attenuation */ + float Attenuation1; /* Linear attenuation */ + float Attenuation2; /* Quadratic attenuation */ + float Theta; /* Inner angle of spotlight cone */ + float Phi; /* Outer angle of spotlight cone */ +} D3DLIGHT9; + +typedef enum _D3DFOGMODE { + D3DFOG_NONE = 0, + D3DFOG_EXP = 1, + D3DFOG_EXP2 = 2, + D3DFOG_LINEAR = 3, + D3DFOG_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DFOGMODE; + +typedef enum _D3DTRANSFORMSTATETYPE { + D3DTS_WORLD = 0, + D3DTS_VIEW = 1, + D3DTS_PROJECTION = 2, + D3DTS_TEXTURE0 = 3, + D3DTS_TEXTURE1 = 4, + D3DTS_TEXTURE2 = 5, + D3DTS_TEXTURE3 = 6, + D3DTS_TEXTURE4 = 7, + D3DTS_TEXTURE5 = 8, + D3DTS_TEXTURE6 = 9, + D3DTS_TEXTURE7 = 10, + + D3DTS_MAX = 11, + D3DTS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTRANSFORMSTATETYPE; + +#define D3DTS_WORLDMATRIX(index) (D3DTS_WORLD) + +// Values for material source +typedef enum _D3DMATERIALCOLORSOURCE +{ + D3DMCS_MATERIAL = 0, // Color from material is used + D3DMCS_COLOR1 = 1, // Diffuse vertex color is used + D3DMCS_COLOR2 = 2, // Specular vertex color is used + D3DMCS_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum +} D3DMATERIALCOLORSOURCE; + +/* + * State enumerants for per-stage processing of fixed function pixel processing + * Two of these affect fixed function vertex processing as well: TEXTURETRANSFORMFLAGS and TEXCOORDINDEX. + */ +typedef enum _D3DTEXTURESTAGESTATETYPE +{ + D3DTSS_COLOROP = 1, /* D3DTEXTUREOP - per-stage blending controls for color channels */ + D3DTSS_COLORARG1 = 2, /* D3DTA_* (texture arg) */ + D3DTSS_COLORARG2 = 3, /* D3DTA_* (texture arg) */ + D3DTSS_ALPHAOP = 4, /* D3DTEXTUREOP - per-stage blending controls for alpha channel */ + D3DTSS_ALPHAARG1 = 5, /* D3DTA_* (texture arg) */ + D3DTSS_ALPHAARG2 = 6, /* D3DTA_* (texture arg) */ + D3DTSS_BUMPENVMAT00 = 7, /* float (bump mapping matrix) */ + D3DTSS_BUMPENVMAT01 = 8, /* float (bump mapping matrix) */ + D3DTSS_BUMPENVMAT10 = 9, /* float (bump mapping matrix) */ + D3DTSS_BUMPENVMAT11 = 10, /* float (bump mapping matrix) */ + D3DTSS_TEXCOORDINDEX = 11, /* identifies which set of texture coordinates index this texture */ + D3DTSS_BUMPENVLSCALE = 22, /* float scale for bump map luminance */ + D3DTSS_BUMPENVLOFFSET = 23, /* float offset for bump map luminance */ + D3DTSS_TEXTURETRANSFORMFLAGS = 24, /* D3DTEXTURETRANSFORMFLAGS controls texture transform */ + D3DTSS_COLORARG0 = 26, /* D3DTA_* third arg for triadic ops */ + D3DTSS_ALPHAARG0 = 27, /* D3DTA_* third arg for triadic ops */ + D3DTSS_RESULTARG = 28, /* D3DTA_* arg for result (CURRENT or TEMP) */ + D3DTSS_CONSTANT = 32, /* Per-stage constant D3DTA_CONSTANT */ + + D3DTSS_MAX = 33, /* Total number of texture stage states */ + + D3DTSS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTEXTURESTAGESTATETYPE; + +// Values, used with D3DTSS_TEXCOORDINDEX, to specify that the vertex data(position +// and normal in the camera space) should be taken as texture coordinates +// Low 16 bits are used to specify texture coordinate index, to take the WRAP mode from +// +#define D3DTSS_TCI_PASSTHRU 0x00000000 +#define D3DTSS_TCI_CAMERASPACENORMAL 0x00010000 +#define D3DTSS_TCI_CAMERASPACEPOSITION 0x00020000 +#define D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR 0x00030000 +#define D3DTSS_TCI_SPHEREMAP 0x00040000 + +/* + * Enumerations for COLOROP and ALPHAOP texture blending operations set in + * texture processing stage controls in D3DTSS. + */ +typedef enum _D3DTEXTUREOP +{ + // Control + D3DTOP_DISABLE = 1, // disables stage + D3DTOP_SELECTARG1 = 2, // the default + D3DTOP_SELECTARG2 = 3, + + // Modulate + D3DTOP_MODULATE = 4, // multiply args together + D3DTOP_MODULATE2X = 5, // multiply and 1 bit + D3DTOP_MODULATE4X = 6, // multiply and 2 bits + + // Add + D3DTOP_ADD = 7, // add arguments together + D3DTOP_ADDSIGNED = 8, // add with -0.5 bias + D3DTOP_ADDSIGNED2X = 9, // as above but left 1 bit + D3DTOP_SUBTRACT = 10, // Arg1 - Arg2, with no saturation + D3DTOP_ADDSMOOTH = 11, // add 2 args, subtract product + // Arg1 + Arg2 - Arg1*Arg2 + // = Arg1 + (1-Arg1)*Arg2 + + // Linear alpha blend: Arg1*(Alpha) + Arg2*(1-Alpha) + D3DTOP_BLENDDIFFUSEALPHA = 12, // iterated alpha + D3DTOP_BLENDTEXTUREALPHA = 13, // texture alpha + D3DTOP_BLENDFACTORALPHA = 14, // alpha from D3DRS_TEXTUREFACTOR + + // Linear alpha blend with pre-multiplied arg1 input: Arg1 + Arg2*(1-Alpha) + D3DTOP_BLENDTEXTUREALPHAPM = 15, // texture alpha + D3DTOP_BLENDCURRENTALPHA = 16, // by alpha of current color + + // Specular mapping + D3DTOP_PREMODULATE = 17, // modulate with next texture before use + D3DTOP_MODULATEALPHA_ADDCOLOR = 18, // Arg1.RGB + Arg1.A*Arg2.RGB + // COLOROP only + D3DTOP_MODULATECOLOR_ADDALPHA = 19, // Arg1.RGB*Arg2.RGB + Arg1.A + // COLOROP only + D3DTOP_MODULATEINVALPHA_ADDCOLOR = 20, // (1-Arg1.A)*Arg2.RGB + Arg1.RGB + // COLOROP only + D3DTOP_MODULATEINVCOLOR_ADDALPHA = 21, // (1-Arg1.RGB)*Arg2.RGB + Arg1.A + // COLOROP only + + // Bump mapping + D3DTOP_BUMPENVMAP = 22, // per pixel env map perturbation + D3DTOP_BUMPENVMAPLUMINANCE = 23, // with luminance channel + + // This can do either diffuse or specular bump mapping with correct input. + // Performs the function (Arg1.R*Arg2.R + Arg1.G*Arg2.G + Arg1.B*Arg2.B) + // where each component has been scaled and offset to make it signed. + // The result is replicated into all four (including alpha) channels. + // This is a valid COLOROP only. + D3DTOP_DOTPRODUCT3 = 24, + + // Triadic ops + D3DTOP_MULTIPLYADD = 25, // Arg0 + Arg1*Arg2 + D3DTOP_LERP = 26, // (Arg0)*Arg1 + (1-Arg0)*Arg2 + + D3DTOP_MAX = 27, /* Total number of texture operations */ + + D3DTOP_FORCE_DWORD = 0x7fffffff, +} D3DTEXTUREOP; + +/* + * Values for COLORARG0,1,2, ALPHAARG0,1,2, and RESULTARG texture blending + * operations set in texture processing stage controls in D3DRENDERSTATE. + */ +#define D3DTA_SELECTMASK 0x0000000f // mask for arg selector +#define D3DTA_DIFFUSE 0x00000000 // select diffuse color (read only) +#define D3DTA_CURRENT 0x00000001 // select stage destination register (read/write) +#define D3DTA_TEXTURE 0x00000002 // select texture color (read only) +#define D3DTA_TFACTOR 0x00000003 // select D3DRS_TEXTUREFACTOR (read only) +#define D3DTA_SPECULAR 0x00000004 // select specular color (read only) +#define D3DTA_TEMP 0x00000005 // select temporary register color (read/write) +#define D3DTA_CONSTANT 0x00000006 // select texture stage constant +#define D3DTA_COMPLEMENT 0x00000010 // take 1.0 - x (read modifier) +#define D3DTA_ALPHAREPLICATE 0x00000020 // replicate alpha to color components (read modifier) + +#define D3DTA_SELECTMAX 0x00000007 +#define D3DTA_MODIFIERMAX 0x00000040 + +// The D3DVERTEXBLENDFLAGS type is used with D3DRS_VERTEXBLEND state. +// +typedef enum _D3DVERTEXBLENDFLAGS +{ + D3DVBF_DISABLE = 0, // Disable vertex blending + D3DVBF_1WEIGHTS = 1, // 2 matrix blending + D3DVBF_2WEIGHTS = 2, // 3 matrix blending + D3DVBF_3WEIGHTS = 3, // 4 matrix blending + D3DVBF_TWEENING = 255, // blending using D3DRS_TWEENFACTOR + D3DVBF_0WEIGHTS = 256, // one matrix is used with weight 1.0 + D3DVBF_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum +} D3DVERTEXBLENDFLAGS; + +typedef enum _D3DTEXTURETRANSFORMFLAGS { + D3DTTFF_DISABLE = 0, // texture coordinates are passed directly + D3DTTFF_COUNT1 = 1, // rasterizer should expect 1-D texture coords + D3DTTFF_COUNT2 = 2, // rasterizer should expect 2-D texture coords + D3DTTFF_COUNT3 = 3, // rasterizer should expect 3-D texture coords + D3DTTFF_COUNT4 = 4, // rasterizer should expect 4-D texture coords + D3DTTFF_PROJECTED = 256, // texcoords to be divided by COUNTth element + D3DTTFF_FORCE_DWORD = 0x7fffffff, +} D3DTEXTURETRANSFORMFLAGS; + +#endif /* _d3d9FFTYPES(P)_H_ */ diff --git a/third_party/xbox_sdk/include/d3d9gpu.h b/third_party/xbox_sdk/include/d3d9gpu.h new file mode 100644 index 0000000..e595975 --- /dev/null +++ b/third_party/xbox_sdk/include/d3d9gpu.h @@ -0,0 +1,5604 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: d3d9gpu.h + * Content: Direct3D hardware register definitions include file + * + ****************************************************************************/ + +#ifndef _D3D9GPU_H_ +#define _D3D9GPU_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#pragma warning(push) + +// Disable nameless struct/union and zero-sized array warnings for this header. + +#pragma warning(disable:4201 4200) + +// The PPC back-end of the C compiler by default defines bitfields to be +// ordered from the MSB to the LSB, which is opposite the convention on +// the X86 platform. Use the 'bitfield_order' pragma to switch the +// ordering. Note that this does not affect endianness in any way. + +#if defined(_M_PPCBE) +#pragma bitfield_order(push) +#pragma bitfield_order(lsb_to_msb) +#endif + +// Total amount of EDRAM memory, in bytes: + +#define GPU_EDRAM_SIZE (10*1024*1024) + +// Total amount of system memory addressable by GPU, in bytes: + +#define GPU_MEMORY_SIZE (512*1024*1024) + +// The GPU's core clock is 500 MHz: + +#define GPU_CLOCK_SPEED (500*1000*1000) + +// AND with this value as part of the calculation to convert from a +// virtual memory pointer to a physical address that can be used by the GPU: + +#define GPU_ADDRESS_MASK (GPU_MEMORY_SIZE - 1) + +// The CPU's virtual addresses for 'physical memory' allocations are divided +// into three sections: +// +// 0xA0000000 - 0xBFFFFFF 64 KB Pages +// 0xC0000000 - 0xDFFFFFF 16 MB Pages (Address range also used for cached-read-only pages, see below) +// 0xE0000000 - 0xFFFFFFF 4 KB Pages + +#define GPU_CPU_VIRTUAL_ADDRESS_64KB_START ((DWORD) 0xA0000000) +#define GPU_CPU_VIRTUAL_ADDRESS_64KB_END ((DWORD) 0xBFFFFFFF) +#define GPU_CPU_VIRTUAL_ADDRESS_16MB_START ((DWORD) 0xC0000000) +#define GPU_CPU_VIRTUAL_ADDRESS_16MB_END ((DWORD) 0xDFFFFFFF) +#define GPU_CPU_VIRTUAL_ADDRESS_4KB_START ((DWORD) 0xDFFFF000) +#define GPU_CPU_VIRTUAL_ADDRESS_4KB_END ((DWORD) 0xFFFFFFFF) + +#define GPU_CPU_VIRTUAL_ADDRESS ((DWORD) 0xA0000000) + +// The 64KB and 4 KB physical memory pages can be accessed as +// cached, read-only memory by offseting their addresses from their +// native range to the corresponding 0xC0000000 to 0xDFFFFFFF range. +// 16 MB pages are always write-combined. They don't have a corresponding +// cached, read-only representation. + +#define GPU_CPU_CACHED_READONLY_VIRTUAL_ADDRESS ((DWORD) 0xC0000000) + +// There are sixteen 32-bit 'tail write-back' registers on the CPU. The +// GPU's command processor can write directly to these registers. They're +// beneficial over GPU write-backs to normal cacheable memory because they +// reduce the latency, which is particularly important for XPS: the CPU +// doesn't have to go all the way to memory to read a new write-back value. +// There is one register per 128 bytes at the following physical address +// range. The remainder of the range is unused. + +#define GPU_TAIL_WRITEBACKS 16 +#define GPU_TAIL_WRITEBACK_DELTA 128 + +#define GPU_TAIL_WRITEBACK_RANGE_VIRTUAL_ADDRESS ((DWORD) 0x7F000000) +#define GPU_TAIL_WRITEBACK_RANGE_PHYSICAL_ADDRESS ((DWORD) 0xC0000000) +#define GPU_TAIL_WRITEBACK_RANGE_SIZE 0x00100000 + +// There is a particular physical memory range where the GPU knows to request +// memory from the CPU's L2 instead of from physical memory. This is used +// solely by XPS. The L2 set has to be 'locked' and each cache-line in the +// set has to be pre-initialized using 'dcbz128' to a virtual address +// which corresponds to a consecutive subset of this physical memory range. +// (In other words, unless the cache is pre-populated, GPU requests from this +// memory range will be lost.) + +#define GPU_XPS_LOCKED_L2_RANGE_VIRTUAL_ADDRESS ((DWORD) 0x7F100000) +#define GPU_XPS_LOCKED_L2_RANGE_PHYSICAL_ADDRESS ((DWORD) 0xC0100000) +#define GPU_XPS_LOCKED_L2_RANGE_SIZE 0x07F00000 + +// Convert a CPU address into a GPU usable address. Only 'physical memory' +// (as allocated by XPhysicalAlloc or XMemAlloc(XALLOC_MEMTYPE_PHYSICAL)) can +// be converted in this way. + +static __forceinline DWORD GPU_CONVERT_CPU_TO_GPU_ADDRESS(CONST void* CpuAddress) +{ + return (((DWORD) (UINT_PTR) CpuAddress) & GPU_ADDRESS_MASK) + + (DWORD)(((((UINT_PTR) CpuAddress) >> 20) + 0x200) & 0x1000); +} + +// Convert a GPU address into a CPU usable address. The resulting address +// is usable only if the memory was originally allocated as 'physical +// memory' by XPhysicalAlloc or XMemAlloc(XALLOC_MEMTYPE_PHYSICAL). The +// memory will be accessed by the CPU using the memory-protection type (e.g., +// cached or write-combining) of the original XPhysicalAlloc or XMemAlloc +// allocation. + +static __forceinline void* GPU_CONVERT_GPU_TO_CPU_ADDRESS_64KB(DWORD GpuAddress) +{ + return (void*) (UINT_PTR) (GpuAddress + GPU_CPU_VIRTUAL_ADDRESS_64KB_START); +} + +static __forceinline void* GPU_CONVERT_GPU_TO_CPU_ADDRESS_16MB(DWORD GpuAddress) +{ + return (void*) (UINT_PTR) (GpuAddress + GPU_CPU_VIRTUAL_ADDRESS_16MB_START); +} + +static __forceinline void* GPU_CONVERT_GPU_TO_CPU_ADDRESS_4KB(DWORD GpuAddress) +{ + return (void*) (UINT_PTR) (GpuAddress + GPU_CPU_VIRTUAL_ADDRESS_4KB_START); +} + +// Convert a GPU address into a CPU usable address. All of memory can be +// accessed regardless of how the memory was originally allocated. The +// memory will be accessed by the CPU as cached and readonly. The hardware +// has no automatic cache coherency between write-combining and cached views +// so care must be taken to avoid stale data (e.g., if the CPU does a cached +// read of this memory, then modifies it using write-combining, then does a +// cached read again, the second read may get invalid stale cached data +// unless CPU cache control instructions are used). + +static __forceinline void* GPU_CONVERT_GPU_TO_CPU_CACHED_READONLY_ADDRESS(DWORD GpuAddress) +{ + return (void*) (UINT_PTR) (GpuAddress + GPU_CPU_CACHED_READONLY_VIRTUAL_ADDRESS); +} + +// Convert a CPU address into a CPU cached, readonly address. Only 'physical +// memory' (as allocated by XPhysicalAlloc or XMemAlloc(XALLOC_MEMTYPE_PHYSICAL)) +// can be converted in this way. + +static __forceinline void* GPU_CONVERT_CPU_TO_CPU_CACHED_READONLY_ADDRESS(CONST void* CpuAddress) +{ + return GPU_CONVERT_GPU_TO_CPU_CACHED_READONLY_ADDRESS(GPU_CONVERT_CPU_TO_GPU_ADDRESS(CpuAddress)); +} + +// Convert a CPU address pointing into the XPS locked L2 cache into a GPU +// physical address. + +static __forceinline DWORD GPU_CONVERT_XPS_CPU_TO_GPU_ADDRESS(CONST void* CpuAddress) +{ + return ((DWORD) (UINT_PTR) CpuAddress) + - GPU_XPS_LOCKED_L2_RANGE_VIRTUAL_ADDRESS + + GPU_XPS_LOCKED_L2_RANGE_PHYSICAL_ADDRESS; +} + +// Convert a GPU address pointing into the XPS locked L2 cache into a CPU +// virtual address. + +static __forceinline void* GPU_CONVERT_XPS_GPU_TO_CPU_ADDRESS(DWORD GpuAddress) +{ + return (void*) (UINT_PTR) (GpuAddress + - GPU_XPS_LOCKED_L2_RANGE_PHYSICAL_ADDRESS + + GPU_XPS_LOCKED_L2_RANGE_VIRTUAL_ADDRESS); +} + +// Total size of the shader program store, in instructions: + +#define GPU_INSTRUCTIONS 4096 + +// Total number of constants support by a single context: + +#define GPU_ALU_CONSTANTS 512 +#define GPU_BOOLEAN_CONSTANTS 256 +#define GPU_INTEGER_CONSTANTS 32 +#define GPU_FLOW_CONSTANTS (GPU_BOOLEAN_CONSTANTS/32 + GPU_INTEGER_CONSTANTS) // Actual register count +#define GPU_FETCH_CONSTANTS 32 +#define GPU_VERTEX_FETCH_CONSTANTS (3*GPU_FETCH_CONSTANTS) + +// How D3D divides up the constants: + +#define GPU_D3D_VERTEX_CONSTANTF_BASE 0 +#define GPU_D3D_VERTEX_CONSTANTF_COUNT 256 +#define GPU_D3D_VERTEX_CONSTANTI_BASE 0 +#define GPU_D3D_VERTEX_CONSTANTI_COUNT 16 +#define GPU_D3D_VERTEX_CONSTANTB_BASE 0 +#define GPU_D3D_VERTEX_CONSTANTB_COUNT 128 +#define GPU_D3D_VERTEX_FETCH_CONSTANT_BASE 26 +#define GPU_D3D_VERTEX_FETCH_CONSTANT_COUNT 6 // Good for 18 streams +#define GPU_D3D_VERTEX_TEXTURE_FETCH_CONSTANT_BASE 16 +#define GPU_D3D_VERTEX_TEXTURE_FETCH_CONSTANT_COUNT 10 + +#define GPU_D3D_PIXEL_CONSTANTF_BASE GPU_D3D_VERTEX_CONSTANTF_COUNT +#define GPU_D3D_PIXEL_CONSTANTF_COUNT 256 +#define GPU_D3D_PIXEL_CONSTANTI_BASE GPU_D3D_VERTEX_CONSTANTI_COUNT +#define GPU_D3D_PIXEL_CONSTANTI_COUNT 16 +#define GPU_D3D_PIXEL_CONSTANTB_BASE GPU_D3D_VERTEX_CONSTANTB_COUNT +#define GPU_D3D_PIXEL_CONSTANTB_COUNT 128 +#define GPU_D3D_PIXEL_TEXTURE_FETCH_CONSTANT_BASE 0 +#define GPU_D3D_PIXEL_TEXTURE_FETCH_CONSTANT_COUNT 26 + +// Total texture fetch constants tracked by D3D runtime +// for both vertex and pixel shaders: + +#define GPU_D3D_TEXTURE_FETCH_CONSTANT_BASE 0 +#define GPU_D3D_TEXTURE_FETCH_CONSTANT_COUNT 26 + +// Fetch constant allocation strategy: +// pixel shader samplers start at texture constant 0, and proceed upwards. +// vertex shader samplers start at texture constant 16 and proceed upwards. +// The constant D3DDMAPSAMPLER is set to 16. Typically vertex shaders will use +// textures D3DDMAPSAMPLER..D3DDMAPSAMPLER+3, while pixel shaders will use +// textures 0..15. But it's up to the shader authors to sort things out. + +// 0..15 : samplers 0..15 for pixel shaders +// 16..19 : samplers 0..3 for vertex shaders +// : also samplers 16..19 for pixel shaders +// 20..25 : samplers 20..25 for pixel shaders +// also samplers 4..9 for vertex shaders +// also vertex streams 18..35 +// 26..31 : Vertex stream fetch constants 0..17(31.High is stream 0, 31.Middle is stream 1, and so on.) + +#define GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(X) ((X) + GPU_D3D_PIXEL_TEXTURE_FETCH_CONSTANT_BASE) +#define GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(X) ((GPU_VERTEX_FETCH_CONSTANTS - 1) - (X)) + +// GPU Temporary register count (that can be used by our runtime) + +#define GPU_SHADER_TEMPORARY_REGISTER_COUNT 32 + +// GPU Temporary register count (that the hardware supports) + +#define GPU_SHADER_TEMPORARY_REGISTER_COUNT_PHYSICAL 64 + +// Vertex buffer maximum number of verts: + +#define GPU_MAX_VERTEX_BUFFER_DIMENSION 16777216 + +// 2D textures have a maximum dimension of 8K by 8K: + +#define GPU_MAX_TEXTURE_DIMENSION 8192 + +// 1D textures have a maximum dimension of 16M: + +#define GPU_MAX_1D_TEXTURE_DIMENSION 16777216 + +// Volume textures can have up to 1024 layers in the Z direction: + +#define GPU_MAX_TEXTURE_DEPTH 1024 + +// Textures have to have 4K alignment both for the base and mip levels: + +#define GPU_TEXTURE_ALIGNMENT 4096 + +// Textures have to have a pitch that is a multiple of 32 texels: + +#define GPU_TEXTURE_TEXEL_PITCH_ALIGNMENT 32 + +// Linear textures have to have a pitch that is a multiple of 256 bytes: + +#define GPU_LINEAR_TEXTURE_PITCH_BYTE_ALIGNMENT 256 + +// Texture tiles are 32x32x4 texels: + +#define GPU_TEXTURE_TILE_DIMENSION 32 + +#define GPU_TEXTURE_TILE_DEPTH_DIMENSION 4 + +// Resolve rectangles must always be 8x8 pixel aligned: + +#define GPU_RESOLVE_ALIGNMENT 8 + +// Maximum vertex fetch stride in dwords: + +#define GPU_MAX_VERTEX_STRIDE 255 + +// There's 16 interpolators for the pixel shader: + +#define GPU_INTERPOLATORS 16 + +// There is a pool of 128 sets of GPRs: + +#define GPU_GPRS 128 + +// There's 4 channels per interpolator: + +#define GPU_INTERPOLATOR_CHANNELS 4 + +// Size of the post-transform cache. VtxReuseDepth should always be +// set to this value: + +#define GPU_VERTEX_REUSE_DEPTH 14 + +// Distance from pixel center to outermost sample for multisampling. +// MaxSampleDist should always be set to the appropriate value: + +#define GPU_MAX_SAMPLE_DIST_1X 0 +#define GPU_MAX_SAMPLE_DIST_2X 4 +#define GPU_MAX_SAMPLE_DIST_4X 6 + +// Distance (in indices) which the vertex vector slot assignment leads the +// deallocation. DeallocDist should always be set to this value: + +#define GPU_DEALLOC_DIST 16 + +// EDRAM tiles are allocated in units of 80x16 pixels at 1X multisampling, +// 80x8 at 2X and 40x8 at 4X: + +#define GPU_EDRAM_TILE_WIDTH_1X 80 +#define GPU_EDRAM_TILE_HEIGHT_1X 16 + +#define GPU_EDRAM_TILE_WIDTH_2X 80 +#define GPU_EDRAM_TILE_HEIGHT_2X 8 + +#define GPU_EDRAM_TILE_WIDTH_4X 40 +#define GPU_EDRAM_TILE_HEIGHT_4X 8 + +// EDRAM tile size in fragments instead of pixels: + +#define GPU_EDRAM_TILE_WIDTH_IN_FRAGMENTS GPU_EDRAM_TILE_WIDTH_1X +#define GPU_EDRAM_TILE_HEIGHT_IN_FRAGMENTS GPU_EDRAM_TILE_HEIGHT_1X + +// An EDRAM tile size, in bytes. Note that 64-bit surfaces have an +// allocation granularity of twice this (10240 bytes) but can have a 5120 +// byte start alignment: + +#define GPU_EDRAM_TILE_SIZE 5120 + +// Total number of usable EDRAM tiles: + +#define GPU_EDRAM_TILES (GPU_EDRAM_SIZE / GPU_EDRAM_TILE_SIZE) + +// Hierarchical Z tiles are allocated in units of 32x16 at 1X multisampilng, +// 32x8 at 2X and 16x8 at 4X: + +#define GPU_HIERARCHICAL_Z_TILE_WIDTH_1X 32 +#define GPU_HIERARCHICAL_Z_TILE_HEIGHT_1X 16 + +#define GPU_HIERARCHICAL_Z_TILE_WIDTH_2X 32 +#define GPU_HIERARCHICAL_Z_TILE_HEIGHT_2X 8 + +#define GPU_HIERARCHICAL_Z_TILE_WIDTH_4X 16 +#define GPU_HIERARCHICAL_Z_TILE_HEIGHT_4X 8 + +// Hierarchical Z tile size in fragments instead of pixels: + +#define GPU_HIERARCHICAL_Z_TILE_WIDTH_IN_FRAGMENTS GPU_HIERARCHICAL_Z_TILE_WIDTH_1X +#define GPU_HIERARCHICAL_Z_TILE_HEIGHT_IN_FRAGMENTS GPU_HIERARCHICAL_Z_TILE_HEIGHT_1X + +// A hierarchical Z tile size, in fragments: + +#define GPU_HIERARCHICAL_Z_TILE_SIZE 512 + +// Total number of usable hierarchical Z tiles. This is enough for 1280x720x2X: + +#define GPU_HIERARCHICAL_Z_TILES 3600 + +// Resource address shift amounts for storage in header fields: + +#define GPU_VERTEXBUFFER_ADDRESS_SHIFT 2 +#define GPU_VERTEXBUFFER_SIZE_SHIFT 2 +#define GPU_TEXTURE_ADDRESS_SHIFT 12 + +// GPU callable command buffers require a 32 byte alignment: + +#define GPU_COMMAND_BUFFER_ALIGNMENT 32 + +// GPU callable indirect command buffers have a 1 MB DWORD maximum size: + +#define GPU_COMMAND_BUFFER_INDIRECT_MAX_SIZE (1 << 20) + +// Masks and shifts for GPU control flow exec instruction +// TypeAndSerialize field + +#define GPUEXEC_TYPE_SHIFT 0 +#define GPUEXEC_TYPE_MASK 1 // Set if Fetch instruction +#define GPUEXEC_SERIALIZE_SHIFT 1 +#define GPUEXEC_SERIALIZE_MASK 2 // Set if serialized + +// Maximum number of ALU/Fetch instructions in an Exec: + +#define GPUFLOW_MAX_EXEC_COUNT 6 + +// Size of the guard band: + +#define GPU_GUARDBAND 8192 + +// Helper for calculating guard band factors for a given number of pixels +// and a given scale. (Scale is 1/2 the height or width of the screen.): + +#define GPU_GUARDBANDFACTOR(GUARDBAND_PIXELS, SCALE) (1.0f + ((float) (GUARDBAND_PIXELS)) / ((float) (SCALE))) + +// Maximum size of a sprite: + +#define GPU_MAX_POINT_SIZE 256.0f + +//------------------------------------------------------------------------------ + +typedef enum +{ + GPUENDIAN_NONE = 0, + GPUENDIAN_8IN16 = 1, + GPUENDIAN_8IN32 = 2, + GPUENDIAN_16IN32 = 3, +} GPUENDIAN; + +typedef enum +{ + GPUENDIAN128_NONE = 0, + GPUENDIAN128_8IN16 = 1, + GPUENDIAN128_8IN32 = 2, + GPUENDIAN128_16IN32 = 3, + GPUENDIAN128_8IN64 = 4, + GPUENDIAN128_8IN128 = 5, +} GPUENDIAN128; + +typedef enum +{ + GPUCOLORARRAY_2D_COLOR = 0, + GPUCOLORARRAY_3D_SLICE_COLOR = 1, +} GPUCOLORARRAY; + +typedef enum +{ + GPUDEPTHARRAY_2D_ALT_DEPTH = 0, + GPUDEPTHARRAY_2D_DEPTH = 1, +} GPUDEPTHARRAY; + +typedef enum +{ + GPUCOLORFORMAT_8 = 2, + GPUCOLORFORMAT_1_5_5_5 = 3, + GPUCOLORFORMAT_5_6_5 = 4, + GPUCOLORFORMAT_6_5_5 = 5, + GPUCOLORFORMAT_8_8_8_8 = 6, + GPUCOLORFORMAT_2_10_10_10 = 7, + GPUCOLORFORMAT_8_A = 8, + GPUCOLORFORMAT_8_B = 9, + GPUCOLORFORMAT_8_8 = 10, + GPUCOLORFORMAT_8_8_8_8_A = 14, + GPUCOLORFORMAT_4_4_4_4 = 15, + GPUCOLORFORMAT_10_11_11 = 16, + GPUCOLORFORMAT_11_11_10 = 17, + GPUCOLORFORMAT_16 = 24, + GPUCOLORFORMAT_16_16 = 25, + GPUCOLORFORMAT_16_16_16_16 = 26, + GPUCOLORFORMAT_16_FLOAT = 30, + GPUCOLORFORMAT_16_16_FLOAT = 31, + GPUCOLORFORMAT_16_16_16_16_FLOAT = 32, + GPUCOLORFORMAT_32_FLOAT = 36, + GPUCOLORFORMAT_32_32_FLOAT = 37, + GPUCOLORFORMAT_32_32_32_32_FLOAT = 38, + GPUCOLORFORMAT_2_10_10_10_FLOAT = 62, // EDRAM render target only +} GPUCOLORFORMAT; + +typedef enum +{ + GPUTEXTUREFORMAT_1_REVERSE = 0, + GPUTEXTUREFORMAT_1 = 1, + GPUTEXTUREFORMAT_8 = 2, + GPUTEXTUREFORMAT_1_5_5_5 = 3, + GPUTEXTUREFORMAT_5_6_5 = 4, + GPUTEXTUREFORMAT_6_5_5 = 5, + GPUTEXTUREFORMAT_8_8_8_8 = 6, + GPUTEXTUREFORMAT_2_10_10_10 = 7, + GPUTEXTUREFORMAT_8_A = 8, + GPUTEXTUREFORMAT_8_B = 9, + GPUTEXTUREFORMAT_8_8 = 10, + GPUTEXTUREFORMAT_Cr_Y1_Cb_Y0_REP = 11, + GPUTEXTUREFORMAT_Y1_Cr_Y0_Cb_REP = 12, + GPUTEXTUREFORMAT_16_16_EDRAM = 13, // EDRAM render target only + GPUTEXTUREFORMAT_8_8_8_8_A = 14, + GPUTEXTUREFORMAT_4_4_4_4 = 15, + GPUTEXTUREFORMAT_10_11_11 = 16, + GPUTEXTUREFORMAT_11_11_10 = 17, + GPUTEXTUREFORMAT_DXT1 = 18, + GPUTEXTUREFORMAT_DXT2_3 = 19, + GPUTEXTUREFORMAT_DXT4_5 = 20, + GPUTEXTUREFORMAT_16_16_16_16_EDRAM = 21, // EDRAM render target only + GPUTEXTUREFORMAT_24_8 = 22, + GPUTEXTUREFORMAT_24_8_FLOAT = 23, + GPUTEXTUREFORMAT_16 = 24, + GPUTEXTUREFORMAT_16_16 = 25, + GPUTEXTUREFORMAT_16_16_16_16 = 26, + GPUTEXTUREFORMAT_16_EXPAND = 27, + GPUTEXTUREFORMAT_16_16_EXPAND = 28, + GPUTEXTUREFORMAT_16_16_16_16_EXPAND = 29, + GPUTEXTUREFORMAT_16_FLOAT = 30, + GPUTEXTUREFORMAT_16_16_FLOAT = 31, + GPUTEXTUREFORMAT_16_16_16_16_FLOAT = 32, + GPUTEXTUREFORMAT_32 = 33, + GPUTEXTUREFORMAT_32_32 = 34, + GPUTEXTUREFORMAT_32_32_32_32 = 35, + GPUTEXTUREFORMAT_32_FLOAT = 36, + GPUTEXTUREFORMAT_32_32_FLOAT = 37, + GPUTEXTUREFORMAT_32_32_32_32_FLOAT = 38, + GPUTEXTUREFORMAT_32_AS_8 = 39, + GPUTEXTUREFORMAT_32_AS_8_8 = 40, + GPUTEXTUREFORMAT_16_MPEG = 41, + GPUTEXTUREFORMAT_16_16_MPEG = 42, + GPUTEXTUREFORMAT_8_INTERLACED = 43, + GPUTEXTUREFORMAT_32_AS_8_INTERLACED = 44, + GPUTEXTUREFORMAT_32_AS_8_8_INTERLACED = 45, + GPUTEXTUREFORMAT_16_INTERLACED = 46, + GPUTEXTUREFORMAT_16_MPEG_INTERLACED = 47, + GPUTEXTUREFORMAT_16_16_MPEG_INTERLACED = 48, + GPUTEXTUREFORMAT_DXN = 49, + GPUTEXTUREFORMAT_8_8_8_8_AS_16_16_16_16 = 50, + GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16 = 51, + GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16 = 52, + GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16 = 53, + GPUTEXTUREFORMAT_2_10_10_10_AS_16_16_16_16 = 54, + GPUTEXTUREFORMAT_10_11_11_AS_16_16_16_16 = 55, + GPUTEXTUREFORMAT_11_11_10_AS_16_16_16_16 = 56, + GPUTEXTUREFORMAT_32_32_32_FLOAT = 57, + GPUTEXTUREFORMAT_DXT3A = 58, + GPUTEXTUREFORMAT_DXT5A = 59, + GPUTEXTUREFORMAT_CTX1 = 60, + GPUTEXTUREFORMAT_DXT3A_AS_1_1_1_1 = 61, + GPUTEXTUREFORMAT_8_8_8_8_GAMMA_EDRAM = 62, // EDRAM render target only + GPUTEXTUREFORMAT_2_10_10_10_FLOAT_EDRAM = 63, // EDRAM render target only +} GPUTEXTUREFORMAT; + +typedef enum +{ + GPUVERTEXFORMAT_8_8_8_8 = 6, + GPUVERTEXFORMAT_2_10_10_10 = 7, + GPUVERTEXFORMAT_10_11_11 = 16, + GPUVERTEXFORMAT_11_11_10 = 17, + GPUVERTEXFORMAT_16_16 = 25, + GPUVERTEXFORMAT_16_16_16_16 = 26, + GPUVERTEXFORMAT_16_16_FLOAT = 31, + GPUVERTEXFORMAT_16_16_16_16_FLOAT = 32, + GPUVERTEXFORMAT_32 = 33, + GPUVERTEXFORMAT_32_32 = 34, + GPUVERTEXFORMAT_32_32_32_32 = 35, + GPUVERTEXFORMAT_32_FLOAT = 36, + GPUVERTEXFORMAT_32_32_FLOAT = 37, + GPUVERTEXFORMAT_32_32_32_32_FLOAT = 38, + GPUVERTEXFORMAT_32_32_32_FLOAT = 57, +} GPUVERTEXFORMAT; + +typedef enum +{ + GPUEDRAMCOLORFORMAT_8_8_8_8 = 0, + GPUEDRAMCOLORFORMAT_8_8_8_8_GAMMA = 1, + GPUEDRAMCOLORFORMAT_2_10_10_10 = 2, + GPUEDRAMCOLORFORMAT_2_10_10_10_FLOAT = 3, + GPUEDRAMCOLORFORMAT_16_16 = 4, + GPUEDRAMCOLORFORMAT_16_16_16_16 = 5, + GPUEDRAMCOLORFORMAT_16_16_FLOAT = 6, + GPUEDRAMCOLORFORMAT_16_16_16_16_FLOAT = 7, + GPUEDRAMCOLORFORMAT_2_10_10_10_AS_10_10_10_10 = 10, + GPUEDRAMCOLORFORMAT_2_10_10_10_FLOAT_AS_16_16_16_16 = 12, + GPUEDRAMCOLORFORMAT_32_FLOAT = 14, + GPUEDRAMCOLORFORMAT_32_32_FLOAT = 15, +} GPUEDRAMCOLORFORMAT; + +typedef enum +{ + GPUEDRAMDEPTHFORMAT_24_8 = 0, + GPUEDRAMDEPTHFORMAT_24_8_FLOAT = 1, +} GPUEDRAMDEPTHFORMAT; + +typedef enum +{ + GPUSIGN_UNSIGNED = 0, + GPUSIGN_SIGNED = 1, + GPUSIGN_BIAS = 2, + GPUSIGN_GAMMA = 3, +} GPUSIGN; + +#define GPUSIGN_ALL_UNSIGNED (GPUSIGN_UNSIGNED | GPUSIGN_UNSIGNED<<2 | GPUSIGN_UNSIGNED<<4 | GPUSIGN_UNSIGNED<<6) +#define GPUSIGN_ALL_SIGNED (GPUSIGN_SIGNED | GPUSIGN_SIGNED<<2 | GPUSIGN_SIGNED<<4 | GPUSIGN_SIGNED<<6) + +typedef enum +{ + GPUSWIZZLE_X = 0, + GPUSWIZZLE_Y = 1, + GPUSWIZZLE_Z = 2, + GPUSWIZZLE_W = 3, + GPUSWIZZLE_0 = 4, + GPUSWIZZLE_1 = 5, + GPUSWIZZLE_KEEP = 7, // Fetch instructions only +} GPUSWIZZLE; + +#define GPUSWIZZLE_ARGB (GPUSWIZZLE_Z | GPUSWIZZLE_Y<<3 | GPUSWIZZLE_X<<6 | GPUSWIZZLE_W<<9) +#define GPUSWIZZLE_ORGB (GPUSWIZZLE_Z | GPUSWIZZLE_Y<<3 | GPUSWIZZLE_X<<6 | GPUSWIZZLE_1<<9) +#define GPUSWIZZLE_ABGR (GPUSWIZZLE_X | GPUSWIZZLE_Y<<3 | GPUSWIZZLE_Z<<6 | GPUSWIZZLE_W<<9) +#define GPUSWIZZLE_OBGR (GPUSWIZZLE_X | GPUSWIZZLE_Y<<3 | GPUSWIZZLE_Z<<6 | GPUSWIZZLE_1<<9) +#define GPUSWIZZLE_OOGR (GPUSWIZZLE_X | GPUSWIZZLE_Y<<3 | GPUSWIZZLE_1<<6 | GPUSWIZZLE_1<<9) +#define GPUSWIZZLE_OZGR (GPUSWIZZLE_X | GPUSWIZZLE_Y<<3 | GPUSWIZZLE_0<<6 | GPUSWIZZLE_1<<9) +#define GPUSWIZZLE_RZZZ (GPUSWIZZLE_0 | GPUSWIZZLE_0<<3 | GPUSWIZZLE_0<<6 | GPUSWIZZLE_X<<9) +#define GPUSWIZZLE_OOOR (GPUSWIZZLE_X | GPUSWIZZLE_1<<3 | GPUSWIZZLE_1<<6 | GPUSWIZZLE_1<<9) +#define GPUSWIZZLE_ORRR (GPUSWIZZLE_X | GPUSWIZZLE_X<<3 | GPUSWIZZLE_X<<6 | GPUSWIZZLE_1<<9) +#define GPUSWIZZLE_GRRR (GPUSWIZZLE_X | GPUSWIZZLE_X<<3 | GPUSWIZZLE_X<<6 | GPUSWIZZLE_Y<<9) +#define GPUSWIZZLE_RGBA (GPUSWIZZLE_W | GPUSWIZZLE_Z<<3 | GPUSWIZZLE_Y<<6 | GPUSWIZZLE_X<<9) + +typedef enum +{ + GPUNUMFORMAT_FRACTION = 0, + GPUNUMFORMAT_INTEGER = 1, +} GPUNUMFORMAT; + +typedef enum +{ + GPUCONSTANTTYPE_INVALID_TEXTURE = 0, + GPUCONSTANTTYPE_INVALID_VERTEX = 1, + GPUCONSTANTTYPE_TEXTURE = 2, + GPUCONSTANTTYPE_VERTEX = 3, +} GPUCONSTANTTYPE; + +typedef enum +{ + GPUCLAMP_WRAP = 0, + GPUCLAMP_MIRROR = 1, + GPUCLAMP_CLAMP_TO_LAST = 2, + GPUCLAMP_MIRROR_ONCE_TO_LAST = 3, + GPUCLAMP_CLAMP_HALFWAY = 4, + GPUCLAMP_MIRROR_ONCE_HALFWAY = 5, + GPUCLAMP_CLAMP_TO_BORDER = 6, + GPUCLAMP_MIRROR_TO_BORDER = 7, +} GPUCLAMP; + +typedef enum +{ + GPUDIMENSION_1D = 0, + GPUDIMENSION_2D = 1, + GPUDIMENSION_3D = 2, + GPUDIMENSION_CUBEMAP = 3, +} GPUDIMENSION; + +typedef enum +{ + GPUREQUESTSIZE_256BIT = 0, + GPUREQUESTSIZE_512BIT = 1, +} GPUREQUESTSIZE; + +typedef enum +{ + GPUCLAMPPOLICY_D3D = 0, + GPUCLAMPPOLICY_OGL = 1, +} GPUCLAMPPOLICY; + +typedef enum +{ + GPUMINMAGFILTER_POINT = 0, + GPUMINMAGFILTER_LINEAR = 1, + GPUMINMAGFILTER_KEEP = 3, // Texture fetch instructions only +} GPUMINMAGFILTER; + +typedef enum +{ + GPUMIPFILTER_POINT = 0, + GPUMIPFILTER_LINEAR = 1, + GPUMIPFILTER_BASEMAP = 2, + GPUMIPFILTER_KEEP = 3, // Texture fetch instructions only +} GPUMIPFILTER; + +typedef enum +{ + GPUANISOFILTER_DISABLED = 0, + GPUANISOFILTER_MAX1TO1 = 1, + GPUANISOFILTER_MAX2TO1 = 2, + GPUANISOFILTER_MAX4TO1 = 3, + GPUANISOFILTER_MAX8TO1 = 4, + GPUANISOFILTER_MAX16TO1 = 5 , + GPUANISOFILTER_KEEP = 7, // Texture fetch instructions only +} GPUANISOFILTER; + +typedef enum +{ + GPUBORDERCOLOR_ABGR_BLACK = 0, + GPUBORDERCOLOR_ABGR_WHITE = 1, + GPUBORDERCOLOR_ACBYCR_BLACK = 2, + GPUBORDERCOLOR_ACBCRY_BLACK = 3, +} GPUBORDERCOLOR; + +typedef enum +{ + GPUTRICLAMP_NORMAL = 0, + GPUTRICLAMP_ONE_SIXTH = 1, + GPUTRICLAMP_ONE_FOURTH = 2, + GPUTRICLAMP_THREE_EIGHTHS = 3, +} GPUTRICLAMP; + +typedef enum +{ + GPUADDRESSCLAMP_CLAMP_TO_LAST = 0, + GPUADDRESSCLAMP_CLAMP_TO_CONSTANT = 1, +} GPUADDRESSCLAMP; + +typedef enum +{ + GPUSURFACENUMBER_UREPEAT = 0, + GPUSURFACENUMBER_SREPEAT = 1, + GPUSURFACENUMBER_UINTEGER = 2, + GPUSURFACENUMBER_SINTEGER = 3, + GPUSURFACENUMBER_FLOAT = 7, +} GPUSURFACENUMBER; + +typedef enum +{ + SURFACESWAP_LOW_RED = 0, + SURFACESWAP_LOW_BLUE = 1, +} GPUSURFACESWAP; + +typedef enum +{ + GPUPRIMTYPE_NONE = 0, + GPUPRIMTYPE_POINTLIST = 1, + GPUPRIMTYPE_LINELIST = 2, + GPUPRIMTYPE_LINESTRIP = 3, + GPUPRIMTYPE_TRILIST = 4, + GPUPRIMTYPE_TRIFAN = 5, + GPUPRIMTYPE_TRISTRIP = 6, + GPUPRIMTYPE_TRI_WITH_WFLAGS = 7, + GPUPRIMTYPE_RECTLIST = 8, + GPUPRIMTYPE_LINELOOP = 12, + GPUPRIMTYPE_QUADLIST = 13, + GPUPRIMTYPE_QUADSTRIP = 14, + GPUPRIMTYPE_POLYGON = 15, + GPUPRIMTYPE_2D_COPY_RECT_LIST_V0 = 16, + GPUPRIMTYPE_2D_COPY_RECT_LIST_V1 = 17, + GPUPRIMTYPE_2D_COPY_RECT_LIST_V2 = 18, + GPUPRIMTYPE_2D_COPY_RECT_LIST_V3 = 19, + GPUPRIMTYPE_2D_FILL_RECT_LIST = 20, + GPUPRIMTYPE_2D_LINE_STRIP = 21, + GPUPRIMTYPE_2D_TRI_STRIP = 22, +} GPUPRIMTYPE; + +typedef enum +{ + GPUGROUPPRIMTYPE_3D_POINT = 0, + GPUGROUPPRIMTYPE_3D_LINE = 1, + GPUGROUPPRIMTYPE_3D_TRI = 2, + GPUGROUPPRIMTYPE_3D_RECT = 3, + GPUGROUPPRIMTYPE_3D_QUAD = 4, + GPUGROUPPRIMTYPE_2D_COPY_RECT_V0 = 5, + GPUGROUPPRIMTYPE_2D_COPY_RECT_V1 = 6, + GPUGROUPPRIMTYPE_2D_COPY_RECT_V2 = 7, + GPUGROUPPRIMTYPE_2D_COPY_RECT_V3 = 8, + GPUGROUPPRIMTYPE_2D_FILL_RECT = 9, + GPUGROUPPRIMTYPE_2D_LINE = 10, + GPUGROUPPRIMTYPE_2D_TRI = 11, + GPUGROUPPRIMTYPE_PRIM_INDEX_LINE = 12, + GPUGROUPPRIMTYPE_PRIM_INDEX_TRI = 13, + GPUGROUPPRIMTYPE_PRIM_INDEX_QUAD = 14, +} GPUGROUPPRIMTYPE; + +typedef enum +{ + GPUGROUPPRIMORDER_LIST = 0, + GPUGROUPPRIMORDER_STRIP = 1, + GPUGROUPPRIMORDER_FAN = 2, + GPUGROUPPRIMORDER_LOOP = 3, + GPUGROUPPRIMORDER_POLYGON = 4, +} GPUGROUPPRIMORDER; + +typedef enum +{ + GPUGROUPCONV_INDEX_16 = 0, + GPUGROUPCONV_INDEX_32 = 1, + GPUGROUPCONV_UINT_16 = 2, + GPUGROUPCONV_UINT_32 = 3, + GPUGROUPCONV_SINT_16 = 4, + GPUGROUPCONV_SINT_32 = 5, + GPUGROUPCONV_FLOAT_32 = 6, + GPUGROUPCONV_AUTO_PRIM = 7, + GPUGROUPCONV_FIX_1_23_TO_FLOAT = 8, +} GPUGROUPCONV; + +typedef enum +{ + GPUCMP_NEVER = 0, + GPUCMP_LESS = 1, + GPUCMP_EQUAL = 2, + GPUCMP_LESS_EQUAL = 3, + GPUCMP_GREATER = 4, + GPUCMP_NOT_EQUAL = 5, + GPUCMP_GREATER_EQUAL = 6, + GPUCMP_ALWAYS = 7, +} GPUCMPFUNC; + +typedef enum +{ + GPUSTENCILOP_KEEP = 0, + GPUSTENCILOP_ZERO = 1, + GPUSTENCILOP_REPLACE = 2, + GPUSTENCILOP_INCRSAT = 3, + GPUSTENCILOP_DECRSAT = 4, + GPUSTENCILOP_INVERT = 5, + GPUSTENCILOP_INCR = 6, + GPUSTENCILOP_DECR = 7, +} GPUSTENCILOP; + +typedef enum +{ + GPUBLEND_ZERO = 0, + GPUBLEND_ONE = 1, + GPUBLEND_SRCCOLOR = 4, + GPUBLEND_INVSRCCOLOR = 5, + GPUBLEND_SRCALPHA = 6, + GPUBLEND_INVSRCALPHA = 7, + GPUBLEND_DESTCOLOR = 8, + GPUBLEND_INVDESTCOLOR = 9, + GPUBLEND_DESTALPHA = 10, + GPUBLEND_INVDESTALPHA = 11, + GPUBLEND_BLENDFACTOR = 12, + GPUBLEND_INVBLENDFACTOR = 13, + GPUBLEND_CONSTANTALPHA = 14, + GPUBLEND_INVCONSTANTALPHA = 15, + GPUBLEND_SRCALPHASAT = 16, +} GPUBLEND; + +typedef enum +{ + GPUBLENDOP_ADD = 0, + GPUBLENDOP_SUBTRACT = 1, + GPUBLENDOP_MIN = 2, + GPUBLENDOP_MAX = 3, + GPUBLENDOP_REVSUBTRACT = 4, +} GPUBLENDOP; + +typedef enum +{ + GPUCULL_NONE_FRONTFACE_CCW = 0x0, + GPUCULL_FRONT_FRONTFACE_CCW = 0x1, + GPUCULL_BACK_FRONTFACE_CCW = 0x2, + GPUCULL_NONE_FRONTFACE_CW = 0x4, + GPUCULL_FRONT_FRONTFACE_CW = 0x5, + GPUCULL_BACK_FRONTFACE_CW = 0x6, +} GPUCULL; + +typedef enum +{ + GPUFILL_POINT = 0, + GPUFILL_WIREFRAME = 1, + GPUFILL_SOLID = 2, +} GPUFILLMODE; + +typedef enum +{ + GPUVERTEXSIGN_UNSIGNED = 0, + GPUVERTEXSIGN_SIGNED = 1 +} GPUVERTEXSIGN; + +typedef enum +{ + GPUVERTEXFETCHOP_FETCH_VERTEX = 0, +} GPUVERTEXFETCHOP; + +typedef enum +{ + GPUTEXTUREFETCHOP_FETCH_TEXTURE_MAP = 1, + GPUTEXTUREFETCHOP_GET_BORDER_COLOR_FRACTION = 16, + GPUTEXTUREFETCHOP_GET_COMPUTED_TEX_LOD = 17, + GPUTEXTUREFETCHOP_GET_GRADIENTS = 18, + GPUTEXTUREFETCHOP_GET_WEIGHTS = 19, + GPUTEXTUREFETCHOP_SET_TEX_LOD = 24, + GPUTEXTUREFETCHOP_SET_GRADIENTS_H = 25, + GPUTEXTUREFETCHOP_SET_GRADIENTS_V = 26, +} GPUTEXTUREFETCHOP; + +typedef enum +{ + GPUFLOWOP_NOP = 0, + GPUFLOWOP_EXEC = 1, + GPUFLOWOP_EXEC_END = 2, + GPUFLOWOP_COND_EXEC = 3, + GPUFLOWOP_COND_EXEC_END = 4, + GPUFLOWOP_COND_EXEC_PRED = 5, + GPUFLOWOP_COND_EXEC_PRED_END = 6, + GPUFLOWOP_LOOP_START = 7, + GPUFLOWOP_LOOP_END = 8, + GPUFLOWOP_COND_CALL = 9, + GPUFLOWOP_RETURN = 10, + GPUFLOWOP_COND_JUMP = 11, + GPUFLOWOP_ALLOC = 12, + GPUFLOWOP_COND_EXEC_PRED_CLEAN = 13, + GPUFLOWOP_COND_EXEC_PRED_CLEAN_END = 14, + GPUFLOWOP_VFETCH_END = 15, +} GPUFLOWOP; + +typedef enum +{ + GPUALUSCALAROP_ADD = 0, + GPUALUSCALAROP_ADDPREV = 1, + GPUALUSCALAROP_MUL = 2, + GPUALUSCALAROP_MULPREV = 3, + GPUALUSCALAROP_MULPREV2 = 4, + GPUALUSCALAROP_MAX = 5, + GPUALUSCALAROP_MIN = 6, + GPUALUSCALAROP_SEQ = 7, + GPUALUSCALAROP_SGT = 8, + GPUALUSCALAROP_SGE = 9, + GPUALUSCALAROP_SNE = 10, + GPUALUSCALAROP_FRC = 11, + GPUALUSCALAROP_TRUNC = 12, + GPUALUSCALAROP_FLOOR = 13, + GPUALUSCALAROP_EXP = 14, + GPUALUSCALAROP_LOGC = 15, + GPUALUSCALAROP_LOG = 16, + GPUALUSCALAROP_RCPC = 17, + GPUALUSCALAROP_RCPF = 18, + GPUALUSCALAROP_RCP = 19, + GPUALUSCALAROP_RSQC = 20, + GPUALUSCALAROP_RSQF = 21, + GPUALUSCALAROP_RSQ = 22, + GPUALUSCALAROP_MAXA = 23, + GPUALUSCALAROP_MAXAF = 24, + GPUALUSCALAROP_SUB = 25, + GPUALUSCALAROP_SUBPREV = 26, + GPUALUSCALAROP_SETPEQ = 27, + GPUALUSCALAROP_SETPNE = 28, + GPUALUSCALAROP_SETPGT = 29, + GPUALUSCALAROP_SETPGE = 30, + GPUALUSCALAROP_SETPINV = 31, + GPUALUSCALAROP_SETPPOP = 32, + GPUALUSCALAROP_SETPCLR = 33, + GPUALUSCALAROP_SETPRSTR = 34, + GPUALUSCALAROP_KILLEQ = 35, + GPUALUSCALAROP_KILLGT = 36, + GPUALUSCALAROP_KILLGE = 37, + GPUALUSCALAROP_KILLNE = 38, + GPUALUSCALAROP_KILLONE = 39, + GPUALUSCALAROP_SQRT = 40, + GPUALUSCALAROP_MULC0 = 42, + GPUALUSCALAROP_MULC1 = 43, + GPUALUSCALAROP_ADDC0 = 44, + GPUALUSCALAROP_ADDC1 = 45, + GPUALUSCALAROP_SUBC0 = 46, + GPUALUSCALAROP_SUBC1 = 47, + GPUALUSCALAROP_SIN = 48, + GPUALUSCALAROP_COS = 49, + GPUALUSCALAROP_RETAINPREV = 50 +} GPUALUSCALAROP; + +typedef enum +{ + GPUALUVECTOROP_ADD = 0, + GPUALUVECTOROP_MUL = 1, + GPUALUVECTOROP_MAX = 2, + GPUALUVECTOROP_MIN = 3, + GPUALUVECTOROP_SEQ = 4, + GPUALUVECTOROP_SGT = 5, + GPUALUVECTOROP_SGE = 6, + GPUALUVECTOROP_SNE = 7, + GPUALUVECTOROP_FRC = 8, + GPUALUVECTOROP_TRUNC = 9, + GPUALUVECTOROP_FLOOR = 10, + GPUALUVECTOROP_MAD = 11, + GPUALUVECTOROP_CNDEQ = 12, + GPUALUVECTOROP_CNDGE = 13, + GPUALUVECTOROP_CNDGT = 14, + GPUALUVECTOROP_DP4 = 15, + GPUALUVECTOROP_DP3 = 16, + GPUALUVECTOROP_DP2ADD = 17, + GPUALUVECTOROP_CUBE = 18, + GPUALUVECTOROP_MAX4 = 19, + GPUALUVECTOROP_SETPEQP = 20, + GPUALUVECTOROP_SETPNEP = 21, + GPUALUVECTOROP_SETPGTP = 22, + GPUALUVECTOROP_SETPGEP = 23, + GPUALUVECTOROP_KILLEQ = 24, + GPUALUVECTOROP_KILLGT = 25, + GPUALUVECTOROP_KILLGE = 26, + GPUALUVECTOROP_KILLNE = 27, + GPUALUVECTOROP_DST = 28, + GPUALUVECTOROP_MAXA = 29 +} GPUALUVECTOROP; + +typedef enum +{ + GPUALUSRCSELECT_C = 0, + GPUALUSRCSELECT_R = 1 +} GPUALUSRCSELECT; + +typedef enum +{ + GPUEXPORTREGISTER_PS_COLOR_0 = 0, + GPUEXPORTREGISTER_PS_COLOR_1 = 1, + GPUEXPORTREGISTER_PS_COLOR_2 = 2, + GPUEXPORTREGISTER_PS_COLOR_3 = 3, + + GPUEXPORTREGISTER_PS_EXPORT_ADDRESS = 32, + GPUEXPORTREGISTER_PS_EXPORT_DATA_0 = 33, + GPUEXPORTREGISTER_PS_EXPORT_DATA_1 = 34, + GPUEXPORTREGISTER_PS_EXPORT_DATA_2 = 35, + GPUEXPORTREGISTER_PS_EXPORT_DATA_3 = 36, + GPUEXPORTREGISTER_PS_EXPORT_DATA_4 = 37, + + GPUEXPORTREGISTER_PS_DEPTH = 61, +} GPUEXPORTREGISTER_PS; + +typedef enum +{ + GPUEXPORTREGISTER_VS_INTERPOLATOR_0 = 0, + GPUEXPORTREGISTER_VS_INTERPOLATOR_1 = 1, + GPUEXPORTREGISTER_VS_INTERPOLATOR_2 = 2, + GPUEXPORTREGISTER_VS_INTERPOLATOR_3 = 3, + GPUEXPORTREGISTER_VS_INTERPOLATOR_4 = 4, + GPUEXPORTREGISTER_VS_INTERPOLATOR_5 = 5, + GPUEXPORTREGISTER_VS_INTERPOLATOR_6 = 6, + GPUEXPORTREGISTER_VS_INTERPOLATOR_7 = 7, + GPUEXPORTREGISTER_VS_INTERPOLATOR_8 = 8, + GPUEXPORTREGISTER_VS_INTERPOLATOR_9 = 9, + GPUEXPORTREGISTER_VS_INTERPOLATOR_10 = 10, + GPUEXPORTREGISTER_VS_INTERPOLATOR_11 = 11, + GPUEXPORTREGISTER_VS_INTERPOLATOR_12 = 12, + GPUEXPORTREGISTER_VS_INTERPOLATOR_13 = 13, + GPUEXPORTREGISTER_VS_INTERPOLATOR_14 = 14, + GPUEXPORTREGISTER_VS_INTERPOLATOR_15 = 15, + + GPUEXPORTREGISTER_VS_EXPORT_ADDRESS = 32, + GPUEXPORTREGISTER_VS_EXPORT_DATA_0 = 33, + GPUEXPORTREGISTER_VS_EXPORT_DATA_1 = 34, + GPUEXPORTREGISTER_VS_EXPORT_DATA_2 = 35, + GPUEXPORTREGISTER_VS_EXPORT_DATA_3 = 36, + GPUEXPORTREGISTER_VS_EXPORT_DATA_4 = 37, + + GPUEXPORTREGISTER_VS_POSITION = 62, + GPUEXPORTREGISTER_VS_SPRITE_EDGE_KILL = 63, +} GPUEXPORTREGISTER_VS; + +typedef enum +{ + GPUCOMMANDOP_NOP = 0x10, + GPUCOMMANDOP_REG_RMW = 0x21, + GPUCOMMANDOP_DRAW = 0x22, + GPUCOMMANDOP_VIZ_QUERY = 0x23, + GPUCOMMANDOP_SET_STATE = 0x25, + GPUCOMMANDOP_WAIT_FOR_IDLE = 0x26, + GPUCOMMANDOP_LOAD_SHADER = 0x27, + GPUCOMMANDOP_LOAD_SHADER_IMMEDIATE = 0x2b, + GPUCOMMANDOP_SET_CONSTANT = 0x2d, + GPUCOMMANDOP_LOAD_ALU_CONSTANT = 0x2f, + GPUCOMMANDOP_DRAW_IMMEDIATE = 0x36, + GPUCOMMANDOP_MPEG_INDEX = 0x3a, + GPUCOMMANDOP_INVALIDATE_STATE = 0x3b, + GPUCOMMANDOP_WAIT_REG_MEM = 0x3c, + GPUCOMMANDOP_MEM_WRITE = 0x3d, + GPUCOMMANDOP_REG_TO_MEM = 0x3e, + GPUCOMMANDOP_INDIRECT_BUFFER = 0x3f, + GPUCOMMANDOP_COND_WRITE = 0x45, + GPUCOMMANDOP_EVENT_WRITE = 0x46, + GPUCOMMANDOP_ME_INIT = 0x48, + GPUCOMMANDOP_FIX_2_FLT_REG = 0x4d, + GPUCOMMANDOP_MEM_WRITE_COUNTER = 0x4f, + GPUCOMMANDOP_WAIT_REG_EQ = 0x52, + GPUCOMMANDOP_WAIT_REG_GTE = 0x53, + GPUCOMMANDOP_CPU_INTERRUPT = 0x54, + GPUCOMMANDOP_EVENT_WRITE_SHADER = 0x58, + GPUCOMMANDOP_EVENT_WRITE_CACHE_FLUSH = 0x59, + GPUCOMMANDOP_EVENT_WRITE_SCREEN_EXTENT = 0x5a, + GPUCOMMANDOP_EVENT_WRITE_ZPASS_DONE = 0x5b, + GPUCOMMANDOP_CONTEXT_UPDATE = 0x5e, +#ifdef XAM_BUILD + GPUCOMMANDOP_SET_BIN_MASK_LO = GPUCOMMANDOP_NOP, + GPUCOMMANDOP_SET_BIN_MASK_HI = GPUCOMMANDOP_NOP, + GPUCOMMANDOP_SET_BIN_SELECT_LO = GPUCOMMANDOP_NOP, + GPUCOMMANDOP_SET_BIN_SELECT_HI = GPUCOMMANDOP_NOP, +#else + GPUCOMMANDOP_SET_BIN_MASK_LO = 0x60, + GPUCOMMANDOP_SET_BIN_MASK_HI = 0x61, + GPUCOMMANDOP_SET_BIN_SELECT_LO = 0x62, + GPUCOMMANDOP_SET_BIN_SELECT_HI = 0x63, +#endif +} GPUCOMMANDOP; + +typedef enum +{ + GPULOADTYPE_VERTEX = 0, + GPULOADTYPE_PIXEL = 1, + GPULOADTYPE_SHARED = 2, +} GPULOADTYPE; + +typedef enum +{ + GPUHIZFUNC_LESS_EQUAL = 0, + GPUHIZFUNC_GREATER_EQUAL = 1, +} GPUHIZFUNC; + +typedef enum +{ + GPUHISTENCILFUNC_EQUAL = 0, + GPUHISTENCILFUNC_NOT_EQUAL = 1, +} GPUHISTENCILFUNC; + +typedef enum +{ + GPUEDRAMMODE_NOP = 0, + GPUEDRAMMODE_COLOR_DEPTH = 4, + GPUEDRAMMODE_DOUBLE_DEPTH = 5, + GPUEDRAMMODE_COPY = 6, +} GPUEDRAMMODE; + +typedef enum +{ + GPUCLIPPLANEMODE_CULL_CENTER_NO_BIAS = 0, + GPUCLIPPLANEMODE_CULL_CENTER_RADIUS_BIAS = 1, + GPUCLIPPLANEMODE_CULL_CENTER_RADIUS_BIAS_EXPAND = 2, + GPUCLIPPLANEMODE_ALWAYS_EXPAND = 3, +} GPUCLIPPLANEMODE; + +typedef enum +{ + GPUSAMPLECONTROL_CENTROIDS_ONLY = 0, + GPUSAMPLECONTROL_CENTERS_ONLY = 1, + GPUSAMPLECONTROL_CENTROIDS_AND_CENTERS = 2, +} GPUSAMPLECONTROL; + +typedef enum +{ + GPUPATHSELECT_VERTEX_REUSE = 0, + GPUPATHSELECT_TESS_ENABLE = 1, + GPUPATHSELECT_PASSTHRU = 2, +} GPUPATHSELECT; + +typedef enum +{ + GPUTESSMODE_DISCRETE = 0, + GPUTESSMODE_CONTINUOUS = 1, + GPUTESSMODE_ADAPTIVE = 2, +} GPUTESSMODE; + +typedef enum +{ + GPUPIXCENTER_ZERO = 0, + GPUPIXCENTER_HALF = 1, +} GPUPIXCENTER; + +typedef enum +{ + GPUROUNDMODE_TRUNCATE = 0, + GPUROUNDMODE_ROUND = 1, + GPUROUNDMODE_ROUND_TO_EVEN = 2, + GPUROUNDMODE_ROUND_TO_ODD = 3, +} GPUROUNDMODE; + +typedef enum +{ + GPUQUANTMODE_16TH = 0, + GPUQUANTMODE_8TH = 1, + GPUQUANTMODE_4TH = 2, + GPUQUANTMODE_HALF = 3, + GPUQUANTMODE_ONE = 4, +} GPUQUANTMODE; + +typedef enum +{ + GPUCOPYSRCSELECT_RENDER_TARGET_0 = 0, + GPUCOPYSRCSELECT_RENDER_TARGET_1 = 1, + GPUCOPYSRCSELECT_RENDER_TARGET_2 = 2, + GPUCOPYSRCSELECT_RENDER_TARGET_3 = 3, + GPUCOPYSRCSELECT_DEPTH_STENCIL = 4, +} GPUCOPYSRCSELECT; + +typedef enum +{ + GPUCOPYSAMPLESELECT_SAMPLE_0 = 0, + GPUCOPYSAMPLESELECT_SAMPLE_1 = 1, + GPUCOPYSAMPLESELECT_SAMPLE_2 = 2, + GPUCOPYSAMPLESELECT_SAMPLE_3 = 3, + GPUCOPYSAMPLESELECT_SAMPLES_0_1 = 4, + GPUCOPYSAMPLESELECT_SAMPLES_2_3 = 5, + GPUCOPYSAMPLESELECT_SAMPLES_0_1_2_3 = 6, +} GPUCOPYSAMPLESELECT; + +typedef enum +{ + GPUCOPYCOMMAND_RAW = 0, + GPUCOPYCOMMAND_CONVERT = 1, + GPUCOPYCOMMAND_1_1_1_1 = 2, + GPUCOPYCOMMAND_NULL = 3, +} GPUCOPYCOMMAND; + +typedef enum +{ + GPUVSEXPORTMODE_POSITION_ONLY = 0, + GPUVSEXPORTMODE_SPRITE = 2, + GPUVSEXPORTMODE_EDGE = 3, + GPUVSEXPORTMODE_KILL = 4, + GPUVSEXPORTMODE_SPRITE_KILL = 5, + GPUVSEXPORTMODE_EDGE_KILL = 6, + GPUVSEXPORTMODE_MULTIPASS = 7, +} GPUVSEXPORTMODE; + +typedef enum +{ + GPUSAMPLES_1X = 0, + GPUSAMPLES_2X = 1, + GPUSAMPLES_4X = 2, +} GPUSAMPLES; + +typedef enum +{ + GPUEXECINSTRUCTIONTYPE_ALU = 0, + GPUEXECINSTRUCTIONTYPE_FETCH = 1, +} GPUEXECINSTRUCTIONTYPE; + +typedef enum +{ + GPUEXECSERIALIZEMODE_UNSERIALIZED = 0, + GPUEXECSERIALIZEMODE_SERIALIZED = 1, +} GPUEXECSERIALIZEMODE; + +typedef enum +{ + GPUEXECFETCHCACHETYPE_TEXTURE = 0, + GPUEXECFETCHCACHETYPE_VERTEX = 1, +} GPUEXECFETCHCACHETYPE; + +typedef enum +{ + GPUALLOCBUFFERSELECT_POSITION = 1, + GPUALLOCBUFFERSELECT_INTERPOLATORS = 2, // for vertex shaders + GPUALLOCBUFFERSELECT_COLORS = 2, // for pixel shaders + GPUALLOCBUFFERSELECT_EXPORT = 3 +} GPUALLOCBUFFERSELECT; + +typedef enum +{ + GPUSCREENEXTENTS_ALLTILES = 0, + GPUSCREENEXTENTS_NONCULLED = 1, + GPUSCREENEXTENTS_PRIMEXTENTS = 2, +} GPUSCREENEXTENTS; + +typedef enum +{ + GPUINITIATOR_VS_DEALLOC = 0, + GPUINITIATOR_PS_DEALLOC = 1, + GPUINITIATOR_VS_DONE_WRITE_BACK = 2, + GPUINITIATOR_PS_DONE_WRITE_BACK = 3, + GPUINITIATOR_CACHE_FLUSH_WRITE_BACK = 4, + GPUINITIATOR_CONTEXT_DONE = 5, + GPUINITIATOR_CACHE_FLUSH = 6, + GPUINITIATOR_VIZQUERY_START = 7, + GPUINITIATOR_VIZQUERY_END = 8, + GPUINITIATOR_SC_WAIT_WC = 9, + GPUINITIATOR_MPASS_PS_CP_REFETCH = 10, + GPUINITIATOR_MPASS_PS_RST_START = 11, + GPUINITIATOR_MPASS_PS_INCR_START = 12, + GPUINITIATOR_RST_PIX_CNT = 13, + GPUINITIATOR_RST_VTX_CNT = 14, + GPUINITIATOR_TILE_FLUSH = 15, + GPUINITIATOR_CACHE_FLUSH_AND_INV_WRITE_BACK_EVENT = 20, + GPUINITIATOR_ZPASS_DONE = 21, + GPUINITIATOR_CACHE_FLUSH_AND_INV_EVENT = 22, + GPUINITIATOR_PERFCOUNTER_START = 23, + GPUINITIATOR_PERFCOUNTER_STOP = 24, + GPUINITIATOR_SCREEN_EXT_INIT = 25, + GPUINITIATOR_SCREEN_EXT_RPT = 26, + GPUINITIATOR_VS_FETCH_DONE_WRITE_BACK = 27, +} GPUINITIATOR; + +typedef enum +{ + GPUSYNCFUNCTION_NEVER = 0, + GPUSYNCFUNCTION_LESS = 1, + GPUSYNCFUNCTION_LEQUAL = 2, + GPUSYNCFUNCTION_EQUAL = 3, + GPUSYNCFUNCTION_NOTEQUAL = 4, + GPUSYNCFUNCTION_GEQUAL = 5, + GPUSYNCFUNCTION_GREATER = 6, + GPUSYNCFUNCTION_ALWAYS = 7, +} GPUSYNCFUNCTION; + +typedef enum +{ + GPUSYNCSPACE_REGISTER = 0, + GPUSYNCSPACE_MEMORY = 1, +} GPUSYNCSPACE; + +typedef enum +{ + GPUCONSTANTID_ALU = 0, + GPUCONSTANTID_FETCH = 1, + GPUCONSTANTID_BOOLEAN = 2, + GPUCONSTANTID_INTEGER = 3, + GPUCONSTANTID_REGISTER = 4, +} GPUCONSTANTID; + +typedef enum +{ + GPUINDEXSELECT_DMA = 0, + GPUINDEXSELECT_IMMEDIATE = 1, + GPUINDEXSELECT_AUTO = 2, +} GPUINDEXSELECT; + +typedef enum +{ + GPUINDEXTYPE_16BIT = 0, + GPUINDEXTYPE_32BIT = 1, +} GPUINDEXTYPE; + +typedef enum +{ + GPUDESTBASE7_CLIPPLANE_DISABLED = 0, + GPUDESTBASE7_CLIPPLANE_ENABLED = 0X1000, +} GPUDESTBASE7; + +//------------------------------------------------------------------------------ + +typedef struct +{ + DWORD Total[2]; // Odd/even pair, little-endian + DWORD ZFail[2]; // Odd/even pair, little-endian + DWORD ZPass[2]; // Odd/even pair, little-endian + DWORD StencilFail[2]; // Odd/even pair, little-endian +} GPU_SAMPLECOUNT; + +typedef struct +{ + WORD MinX; // In tile coordinates, multiply by 8 for pixel coordinates + WORD MaxX; // In tile coordinates, multiply by 8 for pixel coordinates + WORD MinY; // In tile coordinates, multiply by 8 for pixel coordinates + WORD MaxY; // In tile coordinates, multiply by 8 for pixel coordinates + WORD MinZ; // 11 MSBs of Z + WORD MaxZ; // 11 MSBs of Z +} GPU_SCREENEXTENT; + +//------------------------------------------------------------------------------ + +typedef union { + struct { + DWORD SurfacePitch : 14; + DWORD : 2; + DWORD MsaaSamples : 2; // GPUSAMPLES + DWORD HiZPitch : 14; + }; + DWORD dword; +} GPU_SURFACEINFO; + +typedef union { + struct { + DWORD ColorBase : 12; + DWORD : 4; + DWORD ColorFormat : 4; // GPUEDRAMCOLORFORMAT + DWORD ColorExpBias : 6; + DWORD : 6; + }; + DWORD dword; +} GPU_COLORINFO; + +typedef union { + struct { + DWORD DepthBase : 12; + DWORD : 4; + DWORD DepthFormat : 1; // GPUEDRAMDEPTHFORMAT + DWORD DisableHZClamp : 1; + DWORD : 14; + }; + DWORD dword; +} GPU_DEPTHINFO; + +typedef union { + struct { + int X : 15; + DWORD : 1; + int Y : 15; + DWORD : 1; + }; + DWORD dword; +} GPU_POINT; + +typedef union { + struct { + DWORD Write0 : 4; + DWORD Write1 : 4; + DWORD Write2 : 4; + DWORD Write3 : 4; + DWORD : 16; + }; + DWORD dword; +} GPU_COLORMASK; + +typedef union { + struct { + DWORD Ref : 8; + DWORD Mask : 8; + DWORD WriteMask : 8; + DWORD : 8; + }; + DWORD dword; +} GPU_STENCILREFMASK; + +typedef union { + struct { + DWORD VsMaxReg : 6; + DWORD : 2; + DWORD PsMaxReg : 6; + DWORD : 2; + DWORD VsResource : 1; + DWORD PsResource : 1; + DWORD ParamGen : 1; + DWORD GenIndexPix : 1; + DWORD VsExportCount : 4; + DWORD VsExportMode : 3; // GPUVSEXPORTMODE + DWORD PsExportZ : 1; + DWORD PsExportColorCount : 3; + DWORD GenIndexVtx : 1; + }; + DWORD dword; +} GPU_PROGRAMCONTROL; + +#define GPU_PROGRAMCONTROL_PS_MASK 0x780E3F00 +#define GPU_PROGRAMCONTROL_VS_MASK (~GPU_PROGRAMCONTROL_PS_MASK) + +typedef union { + struct { + DWORD InstPredOptimize : 1; + DWORD OutputScreenXY : 1; + DWORD SampleControl : 2; // GPUSAMPLECONTROL + DWORD : 4; + DWORD ParamGenPos : 8; + DWORD PerfCounterRef : 1; + DWORD YieldOptimize : 1; + DWORD TxCacheSelect : 1; + DWORD : 13; + }; + DWORD dword; +} GPU_CONTEXTMISC; + +#define GPU_CONTEXTMISC_PS_MASK 0x0000FFE +#define GPU_CONTEXTMISC_VS_MASK (~GPU_CONTEXTMISC_PS_MASK) + +typedef union { + struct { + DWORD ParamShade : 16; + DWORD SamplingPattern : 16; + }; + DWORD dword; +} GPU_INTERPOLATORCONTROL; + +typedef union { + struct { + DWORD Wrap0 : 4; + DWORD Wrap1 : 4; + DWORD Wrap2 : 4; + DWORD Wrap3 : 4; + DWORD Wrap4 : 4; + DWORD Wrap5 : 4; + DWORD Wrap6 : 4; + DWORD Wrap7 : 4; + }; + DWORD dword; +} GPU_WRAPPING1; + +typedef union { + struct { + DWORD Wrap8 : 4; + DWORD Wrap9 : 4; + DWORD Wrap10 : 4; + DWORD Wrap11 : 4; + DWORD Wrap12 : 4; + DWORD Wrap13 : 4; + DWORD Wrap14 : 4; + DWORD Wrap15 : 4; + }; + DWORD dword; +} GPU_WRAPPING0; + +typedef union { + struct { + DWORD StencilEnable : 1; + DWORD ZEnable : 1; + DWORD ZWriteEnable : 1; + DWORD : 1; + DWORD ZFunc : 3; // GPUCMPFUNC + DWORD BackFaceEnable : 1; + DWORD StencilFunc : 3; // GPUCMPFUNC + DWORD StencilFail : 3; // GPUSTENCILOP + DWORD StencilZPass : 3; // GPUSTENCILOP + DWORD StencilZFail : 3; // GPUSTENCILOP + DWORD StencilFuncBF : 3; // GPUCMPFUNC + DWORD StencilFailBF : 3; // GPUSTENCILOP + DWORD StencilZPassBF : 3; // GPUSTENCILOP + DWORD StencilZFailBF : 3; // GPUSTENCILOP + }; + DWORD dword; +} GPU_DEPTHCONTROL; + +typedef union { + struct { + DWORD ColorSrcBlend : 5; // GPUBLEND + DWORD ColorBlendOp : 3; // GPUBLENDOP + DWORD ColorDestBlend : 5; // GPUBLEND + DWORD : 3; + DWORD AlphaSrcBlend : 5; // GPUBLEND + DWORD AlphaBlendOp : 3; // GPUBLENDOP + DWORD AlphaDestBlend : 5; // GPUBLEND + DWORD : 3; + }; + DWORD dword; +} GPU_BLENDCONTROL; + +typedef union { + struct { + DWORD AlphaFunc : 3; // GPUCMPFUNC + DWORD AlphaTestEnable : 1; + DWORD AlphaToMaskEnable : 1; + DWORD : 19; + DWORD AlphaToMaskOffset0 : 2; + DWORD AlphaToMaskOffset1 : 2; + DWORD AlphaToMaskOffset2 : 2; + DWORD AlphaToMaskOffset3 : 2; + }; + DWORD dword; +} GPU_COLORCONTROL; + +typedef union { + struct { + DWORD HiZWriteEnable : 1; + DWORD HiZEnable : 1; + DWORD HiStencilWriteEnable : 1; + DWORD HiStencilEnable : 1; + DWORD HiZFunc : 1; // GPUHIZFUNC + DWORD HiStencilFunc : 1; // GPUHISTENCILFUNC + DWORD : 2; + DWORD HiStencilRef : 8; + DWORD : 1; + DWORD HiBaseAddr : 15; + }; + DWORD dword; +} GPU_HICONTROL; + +typedef union { + struct { + DWORD ClipPlaneEnable0 : 1; + DWORD ClipPlaneEnable1 : 1; + DWORD ClipPlaneEnable2 : 1; + DWORD ClipPlaneEnable3 : 1; + DWORD ClipPlaneEnable4 : 1; + DWORD ClipPlaneEnable5 : 1; + DWORD : 8; + DWORD ClipPlaneMode : 2; // GPUCLIPPLANEMODE + DWORD ClipDisable : 1; + DWORD ClipPlaneCullOnlyEnable : 1; + DWORD BoundaryEdgeFlagEnable : 1; + DWORD DxClipSpaceDef : 1; + DWORD DisableClipErrDetect : 1; + DWORD VtxKillOr : 1; + DWORD XyNanRetain : 1; + DWORD ZNanRetain : 1; + DWORD WNanRetain : 1; + DWORD : 7; + }; + DWORD dword; +} GPU_CLIPCONTROL; + +typedef union { + struct { + DWORD CullMode : 3; // GPUCULL + DWORD PolyMode : 2; // BOOL + DWORD PolyModeFrontPType : 3; // GPUFILLMODE + DWORD PolyModeBackPType : 3; // GPUFILLMODE + DWORD PolyOffsetFrontEnable : 1; + DWORD PolyOffsetBackEnable : 1; + DWORD PolyOffsetParaEnable : 1; + DWORD : 1; + DWORD MsaaEnable : 1; + DWORD VtxWindowOffsetEnable : 1; + DWORD : 2; + DWORD ProvokingVtxLast : 1; + DWORD PerspCorrDisable : 1; + DWORD MultiPrimIbEnable : 1; + DWORD : 1; + DWORD QuadOrderEnable : 1; + DWORD ScOneQuadPerClock : 1; + DWORD : 7; + }; + DWORD dword; +} GPU_MODECONTROL; + +typedef union { + struct { + DWORD VportXScaleEnable : 1; + DWORD VportXOffsetEnable : 1; + DWORD VportYScaleEnable : 1; + DWORD VportYOffsetEnable : 1; + DWORD VportZScaleEnable : 1; + DWORD VportZOffsetEnable : 1; + DWORD : 2; + DWORD VtxXyFmt : 1; + DWORD VtxZFmt : 1; + DWORD VtxW0Fmt : 1; + DWORD PerfCounterRef : 1; + DWORD : 20; + }; + DWORD dword; +} GPU_VTECONTROL; + +typedef union { + struct { + DWORD EdramMode : 3; // GPUEDRAMMODE + DWORD ColorDepthMacro : 1; + DWORD : 28; + }; + DWORD dword; +} GPU_EDRAMMODECONTROL; + +typedef union { + struct { + DWORD Height : 16; + DWORD Width : 16; + }; + DWORD dword; +} GPU_POINTSIZE; + +typedef union { + struct { + DWORD MinSize : 16; + DWORD MaxSize : 16; + }; + DWORD dword; +} GPU_POINTMINMAX; + +typedef union { + struct { + DWORD Width : 16; + DWORD : 16; + }; + DWORD dword; +} GPU_LINECONTROL; + +typedef union { + struct { + DWORD PathSelect : 2; // GPUPATHSELECT + DWORD : 30; + }; + DWORD dword; +} GPU_OUTPUTPATHCONTROL; + +typedef union { + struct { + DWORD TessMode : 2; // GPUTESSMODE + DWORD : 30; + }; + DWORD dword; +} GPU_HOSCONTROL; + +typedef union { + struct { + DWORD GroupPrimType : 4; // GPUGROUPPRIMTYPE + DWORD : 10; + DWORD GroupRetainOrder : 1; + DWORD GroupRetainQuads : 1; + DWORD GroupPrimOrder : 3; // GPUGROUPPRIMORDER + DWORD : 13; + }; + DWORD dword; +} GPU_GROUPPRIMTYPE; + +typedef union { + struct { + DWORD CompXEnable : 1; + DWORD CompYEnable : 1; + DWORD CompZEnable : 1; + DWORD CompWEnable : 1; + DWORD : 4; + DWORD Stride : 8; + DWORD Shift : 8; + DWORD : 8; + }; + DWORD dword; +} GPU_GROUPVECTCONTROL; + +typedef union { + struct { + DWORD XConv : 4; // GPUGROUPCONV + DWORD XOffset : 4; + DWORD YConv : 4; // GPUGROUPCONV + DWORD YOffset : 4; + DWORD ZConv : 4; // GPUGROUPCONV + DWORD ZOffset : 4; + DWORD WConv : 4; // GPUGROUPCONV + DWORD WOffset : 4; + }; + DWORD dword; +} GPU_GROUPVECTFMTCONTROL; + +typedef union { + struct { + DWORD MPassPixVecPerPass : 20; + DWORD : 11; + DWORD MPassPsEnable : 1; + }; + DWORD dword; +} GPU_MPASSPSCONTROL; + +typedef union { + struct { + DWORD VizQueryEnable : 1; + DWORD VizQueryId : 6; + DWORD KillPixPostHiZ : 1; + DWORD KillPixPostDetailMask : 1; + DWORD : 23; + }; + DWORD dword; +} GPU_VIZQUERY; + +typedef union { + struct { + DWORD Misc : 16; + DWORD : 16; + }; + DWORD dword; +} GPU_ENHANCE; + +typedef union { + struct { + DWORD BresControl : 8; + DWORD UseBresControl : 1; + DWORD ExpandLineWidth : 1; + DWORD LastPixel : 1; + DWORD : 21; + }; + DWORD dword; +} GPU_SCLINECONTROL; + +typedef union { + struct { + DWORD MsaaNumSamples : 3; + DWORD : 10; + DWORD MaxSampleDist : 4; + DWORD : 15; + }; + DWORD dword; +} GPU_AACONFIG; + +typedef union { + struct { + DWORD PixCenter : 1; // GPUPIXCENTER + DWORD RoundMode : 2; // GPUROUNDMODE + DWORD QuantMode : 3; // GPUQUANTMODE + DWORD : 26; + }; + DWORD dword; +} GPU_VTXCONTROL; + +typedef union { + struct { + DWORD Base : 9; + DWORD : 3; + DWORD Size : 9; + DWORD : 11; + }; + DWORD dword; +} GPU_CONST; + +typedef union { + struct { + DWORD DbProgOn : 1; + DWORD : 3; + DWORD DbProbBreak : 1; + DWORD : 3; + DWORD DbProbAddr : 11; + DWORD : 5; + DWORD DbProbCount : 8; + }; + DWORD dword; +} GPU_DEBUGMISC0; + +typedef union { + struct { + DWORD DbOnPix : 1; + DWORD DbOnVtx : 1; + DWORD : 6; + DWORD DbInstCount : 8; + DWORD DbBreakAddr : 11; + DWORD : 5; + }; + DWORD dword; +} GPU_DEBUGMISC1; + +typedef union { + struct { + DWORD VtxReuseDepth : 8; + DWORD : 24; + }; + DWORD dword; +} GPU_VERTEXREUSEBLOCKCONTROL; + +typedef union { + struct { + DWORD DeallocDist : 7; + DWORD : 25; + }; + DWORD dword; +} GPU_OUTDEALLOCCONTROL; + +typedef union { + struct { + DWORD CopySrcSelect : 3; // GPUCOPYSRCSELECT + DWORD : 1; + DWORD CopySampleSelect : 3; // GPUCOPYSAMPLESELECT + DWORD : 1; + DWORD ColorClearEnable : 1; + DWORD DepthClearEnable : 1; + DWORD : 10; + DWORD CopyCommand : 2; // GPUCOPYCOMMAND + DWORD : 10; + }; + DWORD dword; +} GPU_COPYCONTROL; + +typedef union { + struct { + DWORD CopyDestPitch : 14; + DWORD : 2; + DWORD CopyDestHeight : 14; + DWORD : 2; + }; + DWORD dword; +} GPU_COPYDESTPITCH; + +typedef union { + struct { + DWORD CopyDestEndian : 3; // GPUENDIAN128 + DWORD CopyDestArray : 1; // GPUCOLORARRAY + DWORD CopyDestSlice : 3; + DWORD CopyDestFormat : 6; // GPUCOLORFORMAT + DWORD CopyDestNumber : 3; // GPUSURFACENUMBER + DWORD CopyDestExpBias : 6; + DWORD : 2; + DWORD CopyDestSwap : 1; // GPUSURFACESWAP + DWORD : 7; + }; + DWORD dword; +} GPU_COPYDESTINFO; + +typedef union { + struct { + DWORD CopyFuncRed : 3; + DWORD : 1; + DWORD CopyFuncGreen : 3; + DWORD : 1; + DWORD CopyFuncBlue : 3; + DWORD : 1; + DWORD CopyFuncAlpha : 3; + DWORD : 17; + }; + DWORD dword; +} GPU_COPYFUNC; + +typedef union { + struct { + DWORD CopyRefRed : 8; + DWORD CopyRefGreen : 8; + DWORD CopyRefBlue : 8; + DWORD CopyRefAlpha : 8; + }; + DWORD dword; +} GPU_COPYREF; + +typedef union { + struct { + DWORD CopyMaskRed : 8; + DWORD CopyMaskGreen : 8; + DWORD CopyMaskBlue : 8; + DWORD CopyMaskAlpha : 8; + }; + DWORD dword; +} GPU_COPYMASK; + +typedef union { + struct { + DWORD ResetSampleCount : 1; + DWORD CopySampleCount : 1; + DWORD : 30; + }; + DWORD dword; +} GPU_SAMPLECOUNTCONTROL; + +typedef union { + struct { + DWORD BankActToActSClk : 6; + DWORD : 2; + DWORD DisableFragCombine : 1; + DWORD DisableReOrder : 1; + DWORD HzFudgeShift : 2; + DWORD ScreenExtMethod : 2; // GPUSCREENEXTENTS + DWORD : 18; + }; + DWORD dword; +} GPU_BCCONTROL; + +typedef union { + struct { + DWORD MatchingContexts : 8; + DWORD CopyDestBaseEnable : 1; + DWORD DestBase0Enable : 1; + DWORD DestBase1Enable : 1; + DWORD DestBase2Enable : 1; + DWORD DestBase3Enable : 1; + DWORD DestBase4Enable : 1; + DWORD DestBase5Enable : 1; + DWORD DestBase6Enable : 1; + DWORD DestBase7Enable : 1; + DWORD : 7; + DWORD VcActionEnable : 1; + DWORD TcActionEnable : 1; + DWORD PglbActionEnable : 1; + DWORD : 4; + DWORD Status : 1; + }; + DWORD dword; +} GPU_COHERSTATUS; + +typedef union { + struct { + DWORD WaitCrtcPFlip : 1; + DWORD WaitReCrtcVLine : 1; + DWORD WaitFeCrtcVLine : 1; + DWORD WaitCrtcVLine : 1; + DWORD : 4; + DWORD WaitCpDmaIdle : 1; + DWORD : 1; + DWORD WaitCmdFifo : 1; + DWORD WaitOvFlip : 1; + DWORD : 3; + DWORD WaitIdle : 1; + DWORD : 1; + DWORD WaitIdleClean : 1; + DWORD : 2; + DWORD CmdFifoEntries : 4; + DWORD : 8; + }; + DWORD dword; +} GPU_WAITUNTIL; + +typedef union { + struct { + DWORD Cpu0Ack : 1; + DWORD Cpu1Ack : 1; + DWORD Cpu2Ack : 1; + DWORD Cpu3Ack : 1; + DWORD Cpu4Ack : 1; + DWORD Cpu5Ack : 1; + DWORD : 26; + }; + DWORD dword; +} GPU_CPUINTERRUPTACK; + +typedef union { + struct { + DWORD Dynamic : 1; + DWORD : 3; + DWORD PixelSize : 7; + DWORD : 1; + DWORD VertexSize : 7; + DWORD : 13; + }; + DWORD dword; +} GPU_GPRMANAGEMENT; + +typedef union { + struct { + DWORD PixelBase : 16; + DWORD VertexBase : 16; + }; + DWORD dword; +} GPU_INSTSTOREMANAGEMENT; + +typedef union { + struct { + DWORD Flags ; // DWORD 0 must be 0x3FF + DWORD Reserved1 ; // DWORD 1 must be 0 + DWORD Reserved2 ; // DWORD 2 must be 0 + union { + struct { + DWORD Reserved3 ; // DWORD 3 must be 0 + DWORD Reserved4 ; // DWORD 4 must be 0x80 + DWORD Reserved5 ; // DWORD 5 must be 0x100 + DWORD Reserved6 ; // DWORD 6 must be 0x180 + DWORD Reserved7 ; // DWORD 7 must be 0x200 + DWORD Reserved8 ; // DWORD 8 must be 0x280 + DWORD Reserved9 ; // DWORD 9 must be 0x300 + DWORD Reserved10 ; // DWORD 10 must be 0x380 + }; + DWORD Reserved3To10[8] ; // DWORD 3-10 + }; + union { + struct { + DWORD PixelBase : 16; // DWORD 11 + DWORD VertexBase : 16; // DWORD 11 + }; + GPU_INSTSTOREMANAGEMENT InstructionStore ; + }; + DWORD MaxContext ; // DWORD 12 must be 7 + DWORD Reserved13 ; // DWORD 13 must be 0 + DWORD Reserved14 ; // DWORD 14 must be 0 + DWORD Reserved15 ; // DWORD 15 must be 0 + DWORD Reserved16 ; // DWORD 16 must be 0 + DWORD Reserved17 ; // DWORD 17 must be 0 + }; + DWORD dword[18]; +} GPU_MEINIT; + +//------------------------------------------------------------------------------ + +// Packet 0: + +typedef struct +{ + GPU_SURFACEINFO SurfaceInfo; // RB_SURFACE_INFO + GPU_COLORINFO Color0Info; // RB_COLOR0_INFO + GPU_DEPTHINFO DepthInfo; // RB_DEPTH_INFO + GPU_COLORINFO Color1Info; // RB_COLOR1_INFO + GPU_COLORINFO Color2Info; // RB_COLOR2_INFO + GPU_COLORINFO Color3Info; // RB_COLOR3_INFO + DWORD CoherDestBase0; // COHER_DEST_BASE_0 + DWORD CoherDestBase1; // COHER_DEST_BASE_1 + + DWORD CoherDestBase2; // COHER_DEST_BASE_2 + DWORD CoherDestBase3; // COHER_DEST_BASE_3 + DWORD CoherDestBase4; // COHER_DEST_BASE_4 + DWORD CoherDestBase5; // COHER_DEST_BASE_5 + DWORD CoherDestBase6; // COHER_DEST_BASE_6 + DWORD CoherDestBase7; // COHER_DEST_BASE_7 + GPU_POINT ScreenScissorTL; // PA_SC_SCREEN_SCISSOR_TL + GPU_POINT ScreenScissorBR; // PA_SC_SCREEN_SCISSOR_BR +} GPU_DESTINATIONPACKET; + +// Packet 1: + +typedef struct +{ + GPU_POINT WindowOffset; // PA_SC_WINDOW_OFFSET + GPU_POINT WindowScissorTL; // PA_SC_WINDOW_SCISSOR_TL + GPU_POINT WindowScissorBR; // PA_SC_WINDOW_SCISSOR_BR +} GPU_WINDOWPACKET; + +// Packet 2: + +typedef struct +{ + DWORD MaxVtxIndx; // VGT_MAX_VTX_INDX + DWORD MinVtxIndx; // VGT_MIN_VTX_INDX + DWORD IndxOffset; // VGT_INDX_OFFSET + DWORD MultiPrimIbResetIndx; // VGT_MULTI_PRIM_IB_RESET_INDX + GPU_COLORMASK ColorMask; // RB_COLOR_MASK + float BlendRed; // RB_BLEND_RED + float BlendGreen; // RB_BLEND_GREEN + float BlendBlue; // RB_BLEND_BLUE + + float BlendAlpha; // RB_BLEND_ALPHA + DWORD Unused[3]; + GPU_STENCILREFMASK StencilRefMaskBF; // RB_STENCILREFMASK_BF + GPU_STENCILREFMASK StencilRefMask; // RB_STENCILREFMASK + float AlphaRef; // RB_ALPHA_REF + float VportXScale; // PA_CL_VPORT_XSCALE + + float VportXOffset; // PA_CL_VPORT_XOFFSET + float VportYScale; // PA_CL_VPORT_YSCALE + float VportYOffset; // PA_CL_VPORT_YOFFSET + float VportZScale; // PA_CL_VPORT_ZSCALE + float VportZOffset; // PA_CL_VPORT_ZOFFSET +} GPU_VALUESPACKET; + +// Packet 3: + +typedef struct +{ + GPU_PROGRAMCONTROL ProgramControl; // SQ_PROGRAM_CNTL + GPU_CONTEXTMISC ContextMisc; // SQ_CONTEXT_MISC + GPU_INTERPOLATORCONTROL InterpolatorControl; // SQ_INTERPOLATOR_CNTL + GPU_WRAPPING0 Wrapping0; // SQ_WRAPPING_0 + GPU_WRAPPING1 Wrapping1; // SQ_WRAPPING_1 +} GPU_PROGRAMPACKET; + +// Packet 4: + +typedef struct +{ + GPU_DEPTHCONTROL DepthControl; // RB_DEPTHCONTROL + GPU_BLENDCONTROL BlendControl0; // RB_BLENDCONTROL0 + GPU_COLORCONTROL ColorControl; // RB_COLORCONTROL + GPU_HICONTROL HiControl; // RB_TILECONTROL + GPU_CLIPCONTROL ClipControl; // PA_CL_CLIP_CNTL + GPU_MODECONTROL ModeControl; // PA_SU_SC_MODE_CNTL + GPU_VTECONTROL VteControl; // PA_CL_VTE_CNTL + DWORD Unused; + + GPU_EDRAMMODECONTROL EdramModeControl; // RB_MODECONTROL + GPU_BLENDCONTROL BlendControl1; // RB_BLENDCONTROL1 + GPU_BLENDCONTROL BlendControl2; // RB_BLENDCONTROL2 + GPU_BLENDCONTROL BlendControl3; // RB_BLENDCONTROL3 +} GPU_CONTROLPACKET; + +// Packet 5: + +typedef struct +{ + GPU_POINTSIZE PointSize; // PA_SU_POINT_SIZE + GPU_POINTMINMAX PointMinMax; // PA_SU_POINT_MINMAX + GPU_LINECONTROL LineControl; // PA_SU_LINE_CNTL + DWORD Unused1; + GPU_OUTPUTPATHCONTROL OutputPathControl; // VGT_OUTPUT_PATH_CNTL + GPU_HOSCONTROL HosControl; // VGT_HOS_CNTL + float HosMaxTessLevel; // VGT_HOS_MAX_TESS_LEVEL + float HosMinTessLevel; // VGT_HOS_MIN_TESS_LEVEL + + DWORD HosReuseDepth; // VGT_HOS_REUSE_DEPTH + GPU_GROUPPRIMTYPE GroupPrimType; // VGT_GROUP_PRIM_TYPE + DWORD GroupFirstDecr; // VGT_GROUP_FIRST_DECR + DWORD GroupDecr; // VGT_GROUP_DECR + GPU_GROUPVECTCONTROL GroupVect0Control; // VGT_GROUP_VECT_0_CNTL + GPU_GROUPVECTCONTROL GroupVect1Control; // VGT_GROUP_VECT_1_CNTL + GPU_GROUPVECTFMTCONTROL GroupVect0FmtControl; // VGT_GROUP_VECT_0_FMT_CNTL + GPU_GROUPVECTFMTCONTROL GroupVect1FmtControl; // VGT_GROUP_VECT_1_FMT_CNTL + + DWORD Unused2[2]; + GPU_MPASSPSCONTROL MPassPsControl; // PA_SC_MPASS_PS_CNTL + GPU_VIZQUERY VizQuery; // PA_SC_VIZ_QUERY + GPU_ENHANCE Enhance; // VGT_ENHANCE +} GPU_TESSELLATORPACKET; + +// Packet 6: + +typedef struct +{ + GPU_SCLINECONTROL ScLineControl; // PA_SC_LINE_CNTL + GPU_AACONFIG AaConfig; // PA_SC_AA_CONFIG + GPU_VTXCONTROL VtxControl; // PA_SU_VTX_CNTL + float GbVertClipAdj; // PA_CL_GB_VERT_CLIP_ADJ + float GbVertDiscAdj; // PA_CL_GB_VERT_DISC_ADJ + float GbHorzClipAdj; // PA_CL_GB_HORZ_CLIP_ADJ + float GbHorzDiscAdj; // PA_CL_GB_HORZ_DISC_ADJ + GPU_CONST VsConst; // SQ_VS_CONST + + GPU_CONST PsConst; // SQ_PS_CONST + GPU_DEBUGMISC0 DebugMisc0; // SQ_DEBUG_MISC_0 + GPU_DEBUGMISC1 DebugMisc1; // SQ_DEBUG_MISC_1 + DWORD Unused1[5]; + + DWORD Unused2[2]; + DWORD AaMask; // PA_SC_AA_MASK + DWORD Unused3[3]; + GPU_VERTEXREUSEBLOCKCONTROL VertexReuseBlockControl;// VGT_VERTEX_REUSE_BLOCK_CNTL + GPU_OUTDEALLOCCONTROL OutDeallocControl; // VGT_OUT_DEALLOC_CNTL + + GPU_COPYCONTROL CopyControl; // RB_COPY_CONTROL + DWORD CopyDestBase; // RB_COPY_DEST_BASE + GPU_COPYDESTPITCH CopyDestPitch; // RB_COPY_DEST_PITCH + GPU_COPYDESTINFO CopyDestInfo; // RB_COPY_DEST_INFO + DWORD HiClear; // RB_TILE_CLEAR + DWORD DepthClear; // RB_DEPTH_CLEAR + DWORD ColorClear; // RB_COLOR_CLEAR + DWORD ColorClearLo; // RB_COLOR_CLEAR_LO + + GPU_COPYFUNC CopyFunc; // RB_COPY_FUNC + GPU_COPYREF CopyRef; // RB_COPY_REF + GPU_COPYMASK CopyMask; // RB_COPY_MASK + DWORD CopySurfaceSlice; // RB_COPY_SURFACE_SLICE + GPU_SAMPLECOUNTCONTROL SampleCountControl; // RB_SAMPLE_COUNT_CTL + DWORD SampleCountAddress; // RB_SAMPLE_COUNT_ADDR +} GPU_MISCPACKET; + +// Packet 7: + +typedef struct +{ + float PolyOffsetFrontScale; // PA_SU_POLY_OFFSET_FRONT_SCALE + float PolyOffsetFrontOffset; // PA_SU_POLY_OFFSET_FRONT_OFFSET + float PolyOffsetBackScale; // PA_SU_POLY_OFFSET_BACK_SCALE + float PolyOffsetBackOffset; // PA_SU_POLY_OFFSET_BACK_OFFSET + float PointXRad; // PA_CL_POINT_X_RAD + float PointYRad; // PA_CL_POINT_Y_RAD + float PointConstantSize; // PA_CL_POINT_SIZE + float PointCullRad; // PA_CL_POINT_CULL_RAD +} GPU_POINTPACKET; + +//------------------------------------------------------------------------------ + +// Number of packets: + +#define GPU_PACKET_COUNT 8 + +// Maximum size of every packet, in registers: + +#define GPU_PACKET_SIZE 0x80 + +// Actual size of each packet: + +#define GPU_DESTINATIONPACKET_SIZE (sizeof(GPU_DESTINATIONPACKET) / sizeof(DWORD)) +#define GPU_WINDOWPACKET_SIZE (sizeof(GPU_WINDOWPACKET) / sizeof(DWORD)) +#define GPU_VALUESPACKET_SIZE (sizeof(GPU_VALUESPACKET) / sizeof(DWORD)) +#define GPU_PROGRAMPACKET_SIZE (sizeof(GPU_PROGRAMPACKET) / sizeof(DWORD)) +#define GPU_CONTROLPACKET_SIZE (sizeof(GPU_CONTROLPACKET) / sizeof(DWORD)) +#define GPU_TESSELLATORPACKET_SIZE (sizeof(GPU_TESSELLATORPACKET) / sizeof(DWORD)) +#define GPU_MISCPACKET_SIZE (sizeof(GPU_MISCPACKET) / sizeof(DWORD)) +#define GPU_POINTPACKET_SIZE (sizeof(GPU_POINTPACKET) / sizeof(DWORD)) + +//------------------------------------------------------------------------------ + +typedef enum +{ + GPUREG_WAITUNTIL = 0x05C8, // GPU_WAITUNTIL + + GPUREG_COHERSIZEHOST = 0x0A2F, // DWORD + GPUREG_COHERBASEHOST, // DWORD + GPUREG_COHERSTATUSHOST, // GPU_COHERSTATUS + + GPUREG_CPUINTERRUPTACK = 0x045E, // GPU_CPUINTERRUPTACK + + GPUREG_CALLBACKADDRESS = 0x057C, // DWORD + + GPUREG_GPRMANAGEMENT = 0x0D00, // GPU_GPRMANAGEMENT + + GPUREG_INSTSTOREMANAGEMENT = 0x0D02, // GPU_INSTSTOREMANAGEMENT + + GPUREG_INVALIDATECONSTANTS = 0x0D04, // DWORD + + GPUREG_BCCONTROL = 0x0F01, // GPU_BCCONTROL + + // Packet 0: + + GPUREG_DESTINATIONPACKET = 0x2000, // GPU_DESTINATIONPACKET + GPUREG_PACKET0 = 0x2000, + + GPUREG_SURFACEINFO = 0x2000, // GPU_SURFACEINFO + GPUREG_COLOR0INFO, // GPU_COLORINFO + GPUREG_DEPTHINFO, // GPU_DEPTHINFO + GPUREG_COLOR1INFO, // GPU_COLORINFO + GPUREG_COLOR2INFO, // GPU_COLORINFO + GPUREG_COLOR3INFO, // GPU_COLORINFO + GPUREG_COHERDESTBASE0, // DWORD + GPUREG_COHERDESTBASE1, // DWORD + + GPUREG_COHERDESTBASE2, // DWORD + GPUREG_COHERDESTBASE3, // DWORD + GPUREG_COHERDESTBASE4, // DWORD + GPUREG_COHERDESTBASE5, // DWORD + GPUREG_COHERDESTBASE6, // DWORD + GPUREG_COHERDESTBASE7, // DWORD + GPUREG_SCREENSCISSORTL, // GPU_POINT + GPUREG_SCREENSCISSORBR, // GPU_POINT + + // Packet 1: + + GPUREG_WINDOWPACKET = 0x2080, // GPU_WINDOWPACKET + GPUREG_PACKET1 = 0x2080, + + GPUREG_WINDOWOFFSET = 0x2080, // GPU_POINT + GPUREG_WINDOWSCISSORTL, // GPU_POINT + GPUREG_WINDOWSCISSORBR, // GPU_POINT + + // Packet 2: + + GPUREG_VALUESPACKET = 0x2100, // GPU_VALUESPACKET + GPUREG_PACKET2 = 0x2100, + + GPUREG_MAXVTXINDX = 0x2100, // DWORD + GPUREG_MINVTXINDX, // DWORD + GPUREG_INDXOFFSET, // DWORD + GPUREG_MULTIPRIMIBRESETINDX, // DWORD + GPUREG_COLORMASK, // GPUREG_COLORMASK + GPUREG_BLENDRED, // float + GPUREG_BLENDGREEN, // float + GPUREG_BLENDBLUE, // float + + GPUREG_BLENDALPHA, // float + GPUREG_UNUSED0, + GPUREG_UNUSED1, + GPUREG_UNUSED2, + GPUREG_STENCILREFMASKBF, // GPU_STENCILREFMASK + GPUREG_STENCILREFMASK, // GPU_STENCILREFMASK + GPUREG_ALPHAREF, // float + GPUREG_VPORTXSCALE, // float + + GPUREG_VPORTXOFFSET, // float + GPUREG_VPORTYSCALE, // float + GPUREG_VPORTYOFFSET, // float + GPUREG_VPORTZSCALE, // float + GPUREG_VPORTZOFFSET, // float + + // Packet 3: + + GPUREG_PROGRAMPACKET = 0x2180, // GPU_PROGRAMPACKET + GPUREG_PACKET3 = 0x2180, + + GPUREG_PROGRAMCONTROL = 0x2180, // GPU_PROGRAMCONTROL + GPUREG_CONTEXTMISC, // GPU_CONTEXTMISC + GPUREG_INTERPOLATORCONTROL, // GPU_INTERPOLATORCONTROL + GPUREG_WRAPPING0, // GPU_WRAPPING0 + GPUREG_WRAPPING1, // GPU_WRAPPING1 + + // Packet 4: + + GPUREG_CONTROLPACKET = 0x2200, // GPU_CONTROLPACKET + GPUREG_PACKET4 = 0x2200, + + GPUREG_DEPTHCONTROL = 0x2200, // GPU_DEPTHCONTROL + GPUREG_BLENDCONTROL0, // GPU_BLENDCONTROL + GPUREG_COLORCONTROL, // GPU_COLORCONTROL + GPUREG_HICONTROL, // GPU_HICONTROL + GPUREG_CLIPCONTROL, // GPU_CLIPCONTROL + GPUREG_MODECONTROL, // GPU_MODECONTROL + GPUREG_VTECONTROL, // GPU_VTECONTROL + GPUREG_UNUSED3, + + GPUREG_EDRAMMODECONTROL, // GPU_EDRAMMODECONTROL + GPUREG_BLENDCONTROL1, // GPU_BLENDCONTROL + GPUREG_BLENDCONTROL2, // GPU_BLENDCONTROL + GPUREG_BLENDCONTROL3, // GPU_BLENDCONTROL + + // Packet 5: + + GPUREG_TESSELLATORPACKET = 0x2280, // GPU_TESSELLATORPACKET + GPUREG_PACKET5 = 0x2280, + + GPUREG_POINTSIZE = 0x2280, // GPU_POINTSIZE + GPUREG_POINTMINMAX, // GPU_POINTMINMAX + GPUREG_LINECONTROL, // GPU_LINECONTROL + GPUREG_UNUSED4, + GPUREG_OUTPUTPATHCONTROL, // GPU_OUTPUTPATHCONTROL + GPUREG_HOSCONTROL, // GPU_HOSCONTROL + GPUREG_HOSMAXTESSLEVEL, // float + GPUREG_HOSMINTESSLEVEL, // float + + GPUREG_HOSREUSEDEPTH, // DWORD + GPUREG_GROUPPRIMTYPE, // GPU_GROUPPRIMTYPE + GPUREG_GROUPFIRSTDECR, // DWORD + GPUREG_GROUPDECR, // DWORD + GPUREG_GROUPVECT0CONTROL, // GPU_GROUPVECTCONTROL + GPUREG_GROUPVECT1CONTROL, // GPU_GROUPVECTCONTROL + GPUREG_GROUPVECT0FMTCONTROL, // GPU_GROUPVECTFMTCONTROL + GPUREG_GROUPVECT1FMTCONTROL, // GPU_GROUPVECTFMTCONTROL + + GPUREG_UNUSED5, + GPUREG_UNUSED6, + GPUREG_MPASSPSCONTROL, // GPU_MPASSPSCONTROL + GPUREG_VIZQUERY, // GPU_VIZQUERY + GPUREG_ENHANCE, // GPU_ENHANCE + + // Packet 6: + + GPUREG_MISCPACKET = 0x2300, // GPU_MISCPACKET + GPUREG_PACKET6 = 0x2300, + + GPUREG_SCLINECONTROL = 0x2300, // GPU_SCLINECONTROL + GPUREG_AACONFIG, // GPU_AACONFIG + GPUREG_VTXCONTROL, // GPU_VTXCONTROL + GPUREG_GBVERTCLIPADJ, // float + GPUREG_GBVERTDISCADJ, // float + GPUREG_GBHORZCLIPADJ, // float + GPUREG_GBHORZDISCADJ, // float + GPUREG_VSCONST, // GPU_CONST + + GPUREG_PSCONST, // GPU_CONST + GPUREG_DEBUGMISC0, // GPU_DEBUGMISC0 + GPUREG_DEBUGMISC1, // GPU_DEBUGMISC1 + GPUREG_UNUSED7, + GPUREG_UNUSED8, + GPUREG_UNUSED9, + GPUREG_UNUSED10, + GPUREG_UNUSED11, + + GPUREG_UNUSED12, + GPUREG_UNUSED13, + GPUREG_AAMASK, // DWORD + GPUREG_UNUSED14, + GPUREG_UNUSED15, + GPUREG_UNUSED16, + GPUREG_VERTEXREUSEBLOCKCONTROL, // GPU_VERTEXREUSEBLOCKCONTROL + GPUREG_OUTDEALLOCCONTROL, // GPU_OUTDEALLOCCONTROL + + GPUREG_COPYCONTROL, // GPU_COPYCONTROL + GPUREG_COPYDESTBASE, // GPU_COPYDESTBASE + GPUREG_COPYDESTPITCH, // GPU_COPYDESTPITCH + GPUREG_COPYDESTINFO, // GPU_COPYDESTINFO + GPUREG_HICLEAR, // DWORD + GPUREG_DEPTHCLEAR, // DWORD + GPUREG_COLORCLEAR, // DWORD + GPUREG_COLORCLEARLO, // DWORD + + GPUREG_COPYFUNC, // GPU_COPYFUNC + GPUREG_COPYREF, // GPU_COPYREF + GPUREG_COPYMASK, // GPU_COPYMASK + GPUREG_COPYSURFACESLICE, // DWORD + GPUREG_SAMPLECOUNTCONTROL, // GPU_SAMPLECOUNTCONTROL + GPUREG_SAMPLECOUNTADDRESS, // DWORD + + // Packet 7: + + GPUREG_POINTPACKET = 0x2380, // GPU_POINTPACKET + GPUREG_PACKET7 = 0x2380, + + GPUREG_POLYOFFSETFRONTSCALE = 0x2380, // float + GPUREG_POLYOFFSETFRONTOFFSET, // float + GPUREG_POLYOFFSETBACKSCALE, // float + GPUREG_POLYOFFSETBACKOFFSET, // float + GPUREG_POINTXRAD, // float + GPUREG_POINTYRAD, // float + GPUREG_POINTCONSTANTSIZE, // float + GPUREG_POINTCULLRAD, // float + + // Other: + + GPUREG_CLIPPLANE0 = 0x2388, // float[4] + GPUREG_CLIPPLANE1 = 0x238C, // float[4] + GPUREG_CLIPPLANE2 = 0x2390, // float[4] + GPUREG_CLIPPLANE3 = 0x2394, // float[4] + GPUREG_CLIPPLANE4 = 0x2398, // float[4] + GPUREG_CLIPPLANE5 = 0x239C, // float[4] + + GPUREG_ALUCONSTANTS = 0x4000, // float[GPU_ALU_CONSTANTS][4] + + GPUREG_FETCHCONSTANTS = 0x4800, // GPUFETCH_CONSTANT[GPU_FETCH_CONSTANTS] + + GPUREG_FLOWCONSTANTS = 0x4900, // DWORD[GPU_FLOW_CONSTANTS] + GPUREG_BOOLEANCONSTANTS = 0x4900, // DWORD[GPU_BOOLEAN_CONSTANTS/32] + GPUREG_INTEGERCONSTANTS = 0x4908, // DWORD[GPU_INTEGER_CONSTANTS] + + GPUREG_FLUSHFETCHCONSTANTS = 0x5000, // DWORD[3] + +} GPUREGISTER; + +// When using GPUCOMMANDOP_SET_CONSTANT to set a register, subtract this value +// from the register address: + +#define GPU_SET_CONSTANT_REGISTER_OFFSET 0x2000 + +//------------------------------------------------------------------------------ + +typedef struct +{ + union { + DWORD FlowConstant[GPU_FLOW_CONSTANTS]; + struct { + DWORD BooleanConstant[GPU_BOOLEAN_CONSTANTS/32]; + DWORD IntegerConstant[GPU_INTEGER_CONSTANTS]; + }; + }; +} GPUFLOW_CONSTANTS; + +__forceinline +void GPU_SET_VERTEX_SHADER_CONSTANTB( + GPUFLOW_CONSTANTS* pFlowConstants, + DWORD Register, + BOOL Boolean) +{ + DWORD index = (Register + GPU_D3D_VERTEX_CONSTANTB_BASE) / 32; + DWORD shift = (Register % 32); + pFlowConstants->BooleanConstant[index] &= ~(1 << shift); + pFlowConstants->BooleanConstant[index] |= ((Boolean & 1) << shift); +} + +__forceinline +void GPU_SET_PIXEL_SHADER_CONSTANTB( + GPUFLOW_CONSTANTS* pFlowConstants, + DWORD Register, + BOOL Boolean) +{ + DWORD index = (Register + GPU_D3D_PIXEL_CONSTANTB_BASE) / 32; + DWORD shift = (Register % 32); + pFlowConstants->BooleanConstant[index] &= ~(1 << shift); + pFlowConstants->BooleanConstant[index] |= ((Boolean & 1) << shift); +} + +__forceinline +void GPU_SET_VERTEX_SHADER_CONSTANTI( + GPUFLOW_CONSTANTS* pFlowConstants, + DWORD Register, + const int* pConstantData) +{ + DWORD index = Register + GPU_D3D_VERTEX_CONSTANTI_BASE; + pFlowConstants->IntegerConstant[index] = (DWORD) ((pConstantData[0] & 0xff) + | ((pConstantData[1] & 0xff) << 8) + | ((pConstantData[2] & 0xff) << 16)); +} + +__forceinline +void GPU_SET_PIXEL_SHADER_CONSTANTI( + GPUFLOW_CONSTANTS* pFlowConstants, + DWORD Register, + const int* pConstantData) +{ + DWORD index = Register + GPU_D3D_PIXEL_CONSTANTI_BASE; + pFlowConstants->IntegerConstant[index] = (DWORD) ((pConstantData[0] & 0xff) + | ((pConstantData[1] & 0xff) << 8) + | ((pConstantData[2] & 0xff) << 16)); +} + +typedef struct +{ + DWORD Width : 24; // DWORD + DWORD : 8; +} GPUTEXTURESIZE_1D; + +typedef struct +{ + DWORD Width : 13; // DWORD + DWORD Height : 13; // DWORD + DWORD : 6; +} GPUTEXTURESIZE_2D; + +typedef struct +{ + DWORD Width : 13; // DWORD + DWORD Height : 13; // DWORD + DWORD Depth : 6; // DWORD +} GPUTEXTURESIZE_STACK; + +typedef struct +{ + DWORD Width : 11; // DWORD + DWORD Height : 11; // DWORD + DWORD Depth : 10; // DWORD +} GPUTEXTURESIZE_3D; + +typedef union { + struct { + // DWORD 0: + + DWORD Type : 2; // GPUCONSTANTTYPE + DWORD SignX : 2; // GPUSIGN + DWORD SignY : 2; // GPUSIGN + DWORD SignZ : 2; // GPUSIGN + DWORD SignW : 2; // GPUSIGN + DWORD ClampX : 3; // GPUCLAMP + DWORD ClampY : 3; // GPUCLAMP + DWORD ClampZ : 3; // GPUCLAMP + DWORD : 2; + DWORD : 1; + DWORD Pitch : 9; // DWORD + DWORD Tiled : 1; // BOOL + + // DWORD 1: + + DWORD DataFormat : 6; // GPUTEXTUREFORMAT + DWORD Endian : 2; // GPUENDIAN + DWORD RequestSize : 2; // GPUREQUESTSIZE + DWORD Stacked : 1; // BOOL + DWORD ClampPolicy : 1; // GPUCLAMPPOLICY + DWORD BaseAddress : 20; // DWORD + + // DWORD 2: + + union + { + GPUTEXTURESIZE_1D OneD; + GPUTEXTURESIZE_2D TwoD; + GPUTEXTURESIZE_3D ThreeD; + GPUTEXTURESIZE_STACK Stack; + } Size; + + // DWORD 3: + + DWORD NumFormat : 1; // GPUNUMFORMAT + DWORD SwizzleX : 3; // GPUSWIZZLE + DWORD SwizzleY : 3; // GPUSWIZZLE + DWORD SwizzleZ : 3; // GPUSWIZZLE + DWORD SwizzleW : 3; // GPUSWIZZLE + INT ExpAdjust : 6; // int + DWORD MagFilter : 2; // GPUMINMAGFILTER + DWORD MinFilter : 2; // GPUMINMAGFILTER + DWORD MipFilter : 2; // GPUMIPFILTER + DWORD AnisoFilter : 3; // GPUANISOFILTER + DWORD : 3; + DWORD BorderSize : 1; // DWORD + + // DWORD 4: + + DWORD VolMagFilter : 1; // GPUMINMAGFILTER + DWORD VolMinFilter : 1; // GPUMINMAGFILTER + DWORD MinMipLevel : 4; // DWORD + DWORD MaxMipLevel : 4; // DWORD + DWORD MagAnisoWalk : 1; // BOOL + DWORD MinAnisoWalk : 1; // BOOL + INT LODBias : 10; // int + INT GradExpAdjustH : 5; // int + INT GradExpAdjustV : 5; // int + + // DWORD 5: + + DWORD BorderColor : 2; // GPUBORDERCOLOR + DWORD ForceBCWToMax : 1; // BOOL + DWORD TriClamp : 2; // GPUTRICLAMP + INT AnisoBias : 4; // int + DWORD Dimension : 2; // GPUDIMENSION + DWORD PackedMips : 1; // BOOL + DWORD MipAddress : 20; // DWORD + }; + DWORD dword[6]; +} GPUTEXTURE_FETCH_CONSTANT; + +typedef union { + struct { + // DWORD 0: + + DWORD Type : 2; // GPUCONSTANTTYPE + DWORD BaseAddress : 30; // DWORD + + // DWORD 1: + + DWORD Endian : 2; // GPUENDIAN + DWORD Size : 24; // DWORD + DWORD AddressClamp : 1; // GPUADDRESSCLAMP + DWORD : 1; + DWORD RequestSize : 2; // GPUREQUESTSIZE + DWORD ClampDisable : 2; // BOOL + }; + DWORD dword[2]; +} GPUVERTEX_FETCH_CONSTANT; + +typedef union { + GPUTEXTURE_FETCH_CONSTANT Texture; + GPUVERTEX_FETCH_CONSTANT Vertex[3]; +} GPUFETCH_CONSTANT; + +typedef union { + struct { + // DWORD 0: + + DWORD Op : 5; // GPUTEXTUREFETCHOP + DWORD SrcGPR : 6; // DWORD + DWORD SrcLoopIndexRelative : 1; // BOOL + DWORD DestGPR : 6; // DWORD + DWORD DestLoopIndexRelative : 1; // BOOL + DWORD FetchValidOnly : 1; // BOOL + DWORD ConstIndex : 5; // DWORD + DWORD UnnormalizedTextureCoords : 1; // BOOL + DWORD SrcSelectX : 2; // DWORD + DWORD SrcSelectY : 2; // DWORD + DWORD SrcSelectZ : 2; // DWORD + + // DWORD 1: + + DWORD SwizzleX : 3; // GPUSWIZZLE + DWORD SwizzleY : 3; // GPUSWIZZLE + DWORD SwizzleZ : 3; // GPUSWIZZLE + DWORD SwizzleW : 3; // GPUSWIZZLE + DWORD MagFilter : 2; // GPUMINMAGFILTER + DWORD MinFilter : 2; // GPUMINMAGFILTER + DWORD MipFilter : 2; // GPUMIPFILTER + DWORD AnisoFilter : 3; // GPUANISOFILTER + DWORD : 3; + DWORD VolMagFilter : 2; // GPUMINMAGFILTER + DWORD VolMinFilter : 2; // GPUMINMAGFILTER + DWORD UseComputedLOD : 1; // BOOL + DWORD UseRegisterLOD : 1; // BOOL + DWORD : 1; + DWORD Predicated : 1; // BOOL + + // DWORD 2: + + DWORD UseRegisterGradients : 1; // BOOL + DWORD : 1; + INT LODBias : 7; // int + DWORD : 5; + DWORD Dimension : 2; // GPUDIMENSION (pseudo register) + INT OffsetX : 5; // int + INT OffsetY : 5; // int + INT OffsetZ : 5; // int + DWORD PredicationCondition : 1; // DWORD + }; + DWORD dword[3]; +} GPUTEXTURE_FETCH_INSTRUCTION; + +typedef union { + struct { + // DWORD 0: + + DWORD Op : 5; // GPUVERTEXFETCHOP + DWORD SrcGPR : 6; // DWORD + DWORD SrcLoopIndexRelative : 1; // BOOL + DWORD DestGPR : 6; // DWORD + DWORD DestLoopIndexRelative : 1; // BOOL + DWORD FetchValidOnly : 1; // Must be 1 + DWORD ConstIndex : 5; // DWORD + DWORD ConstIndexSelect : 2; // DWORD + DWORD PrefetchCount : 3; // DWORD + DWORD SrcSelect : 2; // DWORD + + // DWORD 1: + + DWORD SwizzleX : 3; // GPUSWIZZLE + DWORD SwizzleY : 3; // GPUSWIZZLE + DWORD SwizzleZ : 3; // GPUSWIZZLE + DWORD SwizzleW : 3; // GPUSWIZZLE + DWORD Signed : 1; // BOOL + DWORD NumFormat : 1; // GPUNUMFORMAT + DWORD : 1; + DWORD RoundIndex : 1; // BOOL + DWORD DataFormat : 6; // GPUVERTEXFORMAT + DWORD : 2; + INT ExpAdjust : 6; // int + DWORD MiniFetch : 1; // BOOL + DWORD Predicated : 1; // BOOL + + // DWORD 2: + + DWORD Stride : 8; // DWORD + INT Offset : 23; // int + DWORD PredicationCondition : 1; // DWORD + }; + DWORD dword[3]; +} GPUVERTEX_FETCH_INSTRUCTION; + +//------------------------------------------------------------------------------------------------ +// Convert logical vertex stream number to hardware format + +__forceinline +void SetVertexStream(GPUVERTEX_FETCH_INSTRUCTION* pVertexFetch, DWORD stream) +{ + // Avoid an integer division by using fixed point math + static const DWORD kRemainderAndDiv = ((DWORD) ((4.0 / 3.0) * 256 + 1)) << 16 + | (0xffff & (DWORD)((1.0 / 3.0) * 256 + 1)); + DWORD temp = ((GPU_VERTEX_FETCH_CONSTANTS - 1) - stream) * kRemainderAndDiv; + pVertexFetch->ConstIndex = (temp >> 8) & 0xff; + pVertexFetch->ConstIndexSelect = (temp >> 24) & 0x3; +} + +//------------------------------------------------------------------------------------------------ +// Convert hardware format to logical vertex stream + +__forceinline +DWORD GetVertexStream(const GPUVERTEX_FETCH_INSTRUCTION* pVertexFetch) +{ + return (GPU_VERTEX_FETCH_CONSTANTS - 1) - (pVertexFetch->ConstIndex * 3 + pVertexFetch->ConstIndexSelect); +} + +typedef union { + struct { + DWORD Address : 12; + DWORD Count : 3; + DWORD Yield : 1; + DWORD TypeAndSerialize : 12; // GPUEXECSERIALIZEMODE, GPUEXECINSTRUCTIONTYPE + DWORD VertexCacheLow : 4; // GPUEXECFETCHCACHETYPE + + DWORD VertexCacheHigh : 2; // GPUEXECFETCHCACHETYPE + DWORD : 7; + DWORD PredicateClean : 1; + DWORD : 1; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_EXEC; + +typedef union { + struct { + DWORD Address : 12; + DWORD Count : 3; + DWORD Yield : 1; + DWORD TypeAndSerialize : 12; + DWORD VertexCacheLow : 4; + + DWORD VertexCacheHigh : 2; + DWORD BooleanAddress : 8; + DWORD Condition : 1; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_COND_EXEC; + +typedef union { + struct { + DWORD Address : 12; + DWORD Count : 3; + DWORD Yield : 1; + DWORD TypeAndSerialize : 12; + DWORD VertexCacheLow : 4; + + DWORD VertexCacheHigh : 2; + DWORD : 7; + DWORD PredicateClean : 1; + DWORD Condition : 1; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_COND_EXEC_PREDS; + +typedef union { + struct { + DWORD JumpAddress : 13; + DWORD Repeat : 1; + DWORD : 2; + DWORD LoopID : 5; + DWORD : 11; + + DWORD : 11; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_LOOP_START; + +typedef union { + struct { + DWORD JumpAddress : 13; + DWORD : 3; + DWORD LoopID : 5; + DWORD PredicateBreak : 1; + DWORD : 10; + + DWORD : 10; + DWORD Condition : 1; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_LOOP_END; + +typedef union { + struct { + DWORD JumpAddress : 13; + DWORD Force : 1; + DWORD Predicated : 1; + DWORD : 17; + + DWORD : 2; + DWORD BooleanAddress : 8; + DWORD Condition : 1; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_COND_CALL; + +typedef union { + struct { + DWORD : 32; + + DWORD : 11; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_RETURN; + +typedef union { + struct { + DWORD JumpAddress : 13; + DWORD Force : 1; + DWORD Predicated : 1; + DWORD : 17; + + DWORD : 1; + DWORD ForwardOnly : 1; + DWORD BooleanAddress : 8; + DWORD Condition : 1; + DWORD AbsoluteAddressing : 1; + DWORD Op : 4; + }; +} GPUFLOW_COND_JUMP; + +typedef union { + struct { + DWORD Size : 3; + DWORD : 29; + + DWORD : 8; + DWORD DoNotSerialize : 1; + DWORD BufferSelect : 2; // GPUALLOCBUFFERSELECT + DWORD : 1; + DWORD Op : 4; + }; +} GPUFLOW_ALLOC; + +typedef union { + struct { + DWORD : 32; + + DWORD : 12; + DWORD Op : 4; // GPUFLOWOP + }; + GPUFLOW_EXEC Exec; + GPUFLOW_COND_EXEC CondExec; + GPUFLOW_COND_EXEC_PREDS CondExecPreds; + GPUFLOW_LOOP_START LoopStart; + GPUFLOW_LOOP_END LoopEnd; + GPUFLOW_COND_CALL CondCall; + GPUFLOW_RETURN Return; + GPUFLOW_COND_JUMP CondJump; + GPUFLOW_ALLOC Alloc; + DWORD dword[2]; +} GPUFLOW_INSTRUCTION; + +// Use GPU_GET_FLOW_INSTRUCTIONS() to decode GPUFLOW_INSTRUCTION_PAIR: + +typedef struct { + DWORD dword[3]; +} GPUFLOW_INSTRUCTION_PAIR; + +typedef union { + struct { + // DWORD 0: + + DWORD VectorDest : 6; + DWORD VectorDestRelative : 1; + DWORD AbsConstants : 1; + DWORD ScalarDest : 6; + DWORD ScalarDestRelative : 1; // Also used as export mask + DWORD ResultExport : 1; + DWORD VectorMask : 4; + DWORD ScalarMask : 4; + DWORD VectorSaturate : 1; + DWORD ScalarSaturate : 1; + DWORD ScalarOp : 6; // GPUALUSCALAROP + + // DWORD 1: + + DWORD SrcCSwizzle : 8; + DWORD SrcBSwizzle : 8; + DWORD SrcASwizzle : 8; + DWORD SrcCNegate : 1; + DWORD SrcBNegate : 1; + DWORD SrcANegate : 1; + DWORD PredicationCondition : 1; + DWORD Predicated : 1; + DWORD RelativeAddress : 1; + DWORD Constant1Relative : 1; + DWORD Constant0Relative : 1; + + // DWORD 2: + + DWORD SrcCRegConst : 8; + DWORD SrcBRegConst : 8; + DWORD SrcARegConst : 8; + DWORD VectorOp : 5; // GPUALUVECTOROP + DWORD SrcCSelect : 1; // GPUALUSRCSELECT + DWORD SrcBSelect : 1; // GPUALUSRCSELECT + DWORD SrcASelect : 1; // GPUALUSRCSELECT + }; + DWORD dword[3]; +} GPUALU_INSTRUCTION; + +//------------------------------------------------------------------------------ +// used for GPUALUSCALAROP_MULC0..GPUALUSCALAROP_SUBC1 + +static __forceinline +DWORD GPU_GET_SCALAROP_SOURCE2_REG( + CONST GPUALU_INSTRUCTION* pALU) +{ + return (pALU->SrcCSwizzle & 0x3C) + | (pALU->SrcCSelect << 1) + | (pALU->ScalarOp & 1); +} + +static __forceinline +VOID GPU_SET_SCALAROP_SOURCE2_REG( + GPUALU_INSTRUCTION* pALU, + DWORD reg) +{ + pALU->SrcCSwizzle = + (pALU->SrcCSwizzle & 0xC3) + | (reg & 0x3C); + pALU->SrcCSelect = reg >> 1; + pALU->ScalarOp = + (pALU->ScalarOp & 0xFE) + | (reg & 1); +} + +//------------------------------------------------------------------------------ + +typedef union { + GPUTEXTURE_FETCH_INSTRUCTION TextureFetch; + GPUVERTEX_FETCH_INSTRUCTION VertexFetch; + GPUFLOW_INSTRUCTION Flow0; + GPUFLOW_INSTRUCTION_PAIR FlowPair; + GPUALU_INSTRUCTION Alu; +} GPUSHADER_INSTRUCTION; + +//------------------------------------------------------------------------------ + +static __forceinline +void GPU_GET_FLOW_INSTRUCTIONS( + const GPUFLOW_INSTRUCTION_PAIR* pPair, + GPUFLOW_INSTRUCTION* pFlow0, + GPUFLOW_INSTRUCTION* pFlow1) +{ + pFlow0->dword[0] = pPair->dword[0]; + pFlow0->dword[1] = 0xffff & pPair->dword[1]; // Load low 16 bits. + pFlow1->dword[0] = (pPair->dword[1] >> 16) | (pPair->dword[2] << 16); + pFlow1->dword[1] = (pPair->dword[2] >> 16); +} + +static __forceinline +void GPU_PUT_FLOW_INSTRUCTIONS( + GPUFLOW_INSTRUCTION_PAIR* pPair, + const GPUFLOW_INSTRUCTION* pFlow0, + const GPUFLOW_INSTRUCTION* pFlow1) +{ + pPair->dword[0] = pFlow0->dword[0]; + pPair->dword[1] = (pFlow0->dword[1] & 0xffff) | (pFlow1->dword[0] << 16); + pPair->dword[2] = (pFlow1->dword[0] >> 16) | (pFlow1->dword[1] << 16); +} + +//------------------------------------------------------------------------------ + +typedef union { + struct { + // float x: + + DWORD BaseAddress : 30; // Physical address in DWORDs + DWORD _01 : 2; // Must be 01 + + // float y: + + DWORD _4B000000 : 32; // Must be 0x4B000000 + + // float z: + + DWORD EndianSwap : 3; // GPUENDIAN128 + DWORD : 5; + DWORD Format : 6; // GPUCOLORFORMAT + DWORD : 2; + DWORD NumericType : 3; // GPUSURFACENUMBER + DWORD ComponentSwap : 1; // GPUSURFACESWAP + DWORD _4B0 : 12; // Must be 0x4B0 + + // float w: + + DWORD StreamMaxIndex : 23; // 0..StreamMaxIndex - 1 is valid + DWORD _96 : 9; // Must be 0x96 + }; + DWORD dword[4]; + float c[4]; +} GPU_MEMEXPORT_STREAM_CONSTANT; + +//------------------------------------------------------------------------------ + +#ifdef _DEBUG + +void GPU_SET_MEMEXPORT_STREAM_CONSTANT( + GPU_MEMEXPORT_STREAM_CONSTANT* pConstant, + VOID* pBaseAddress, + DWORD StreamMaxIndex, + GPUSURFACESWAP ComponentSwap, + GPUSURFACENUMBER NumericType, + GPUCOLORFORMAT Format, + GPUENDIAN128 EndianSwap); + +#else + +__forceinline +void GPU_SET_MEMEXPORT_STREAM_CONSTANT( + GPU_MEMEXPORT_STREAM_CONSTANT* pConstant, + VOID* pBaseAddress, + DWORD StreamMaxIndex, + GPUSURFACESWAP ComponentSwap, + GPUSURFACENUMBER NumericType, + GPUCOLORFORMAT Format, + GPUENDIAN128 EndianSwap) +{ + pConstant->_01 = 0x01; + pConstant->BaseAddress = GPU_CONVERT_CPU_TO_GPU_ADDRESS(pBaseAddress) >> 2; + pConstant->_4B000000 = 0x4b000000; + pConstant->_4B0 = 0x4b0; + pConstant->ComponentSwap = ComponentSwap; + pConstant->NumericType = NumericType; + pConstant->Format = Format; + pConstant->EndianSwap = EndianSwap; + pConstant->_96 = 0x96; + pConstant->StreamMaxIndex = StreamMaxIndex; +} + +#endif // _DEBUG + +//------------------------------------------------------------------------------ + +typedef union { + struct { + // DWORD 0: + + DWORD VizQueryId : 6; + DWORD : 2; + DWORD UseVizQuery : 1; + DWORD : 23; + + // DWORD 1: + + DWORD PrimType : 6; // GPUPRIMTYPE + DWORD SrcSelect : 2; // Must be GPUINDEXSELECT_DMA + DWORD MajorMode : 3; + DWORD IndexType : 1; // GPUINDEXTYPE + DWORD NotEndOfPacket : 1; + DWORD : 3; + DWORD NumIndices : 16; + + // DWORD 2: + + DWORD IndexBase : 32; + + // DWORD 3: + + DWORD IndexSize : 24; + DWORD : 6; + DWORD Endian : 2; // GPUENDIAN + }; + DWORD dword[4]; +} GPUCOMMAND_DRAW_INDEX; + +typedef union { + struct { + // DWORD 0: + + DWORD VizQueryId : 6; + DWORD UseVizQuery : 1; + DWORD : 25; + + // DWORD 1: + + DWORD PrimType : 6; // GPUPRIMTYPE + DWORD SrcSelect : 2; // Must be GPUINDEXSELECT_AUTO + DWORD MajorMode : 3; + DWORD IndexSize : 1; + DWORD NotEndOfPacket : 1; + DWORD : 3; + DWORD NumIndices : 16; + }; + DWORD dword[2]; +} GPUCOMMAND_DRAW_AUTO; + +typedef union { + struct { + // DWORD 0: + + DWORD PrimType : 6; // GPUPRIMTYPE + DWORD SrcSelect : 2; // Must be GPUINDEXSELECT_IMMEDIATE + DWORD MajorMode : 3; + DWORD IndexType : 1; // GPUINDEXTYPE + DWORD NotEndOfPacket : 1; + DWORD : 3; + DWORD NumIndices : 16; + + // DWORD 1: + + union { + WORD Index16[]; + DWORD Index32[]; + }; + }; + DWORD dword[1]; +} GPUCOMMAND_DRAW_IMMEDIATE; + +typedef union { + struct { + // DWORD 0: + + DWORD Register : 13; + DWORD : 17; + DWORD OrImmediate : 1; + DWORD AndImmediate : 1; + + // DWORD 1: + + union { + struct { + DWORD AndMask : 32; + }; + struct { + DWORD AndRegister : 13; + DWORD : 19; + }; + }; + + // DWORD 2: + + union { + struct { + DWORD OrMask : 32; + }; + struct { + DWORD OrRegister : 13; + DWORD : 19; + }; + }; + }; + DWORD dword[3]; +} GPUCOMMAND_REG_RMW; + +typedef union { + struct { + // DWORD 0: + + DWORD DestinationSize : 4; + DWORD DestinationDisable : 1; + DWORD DestinationAddress : 27; + + // DWORD 1: + + DWORD WindowSize : 4; + DWORD WindowDisable : 1; + DWORD WindowAddress : 27; + + // DWORD 2: + + DWORD ValuesSize : 4; + DWORD ValuesDisable : 1; + DWORD ValuesAddress : 27; + + // DWORD 3: + + DWORD ProgramSize : 4; + DWORD ProgramDisable : 1; + DWORD ProgramAddress : 27; + + // DWORD 4: + + DWORD ControlSize : 4; + DWORD ControlDisable : 1; + DWORD ControlAddress : 27; + + // DWORD 5: + + DWORD TessellatorSize : 4; + DWORD TessellatorDisable : 1; + DWORD TessellatorAddress : 27; + + // DWORD 6: + + DWORD MiscSize : 4; + DWORD MiscDisable : 1; + DWORD MiscAddress : 27; + + // DWORD 7: + + DWORD PointSize : 4; + DWORD PointDisable : 1; + DWORD PointAddress : 27; + + // DWORD 8: + + DWORD : 4; + DWORD VertexShaderDisable : 1; + DWORD VertexShaderAddress : 27; + + // DWORD 9: + + DWORD VertexShaderSize : 14; + DWORD : 18; + + // DWORD 10: + + DWORD : 4; + DWORD PixelShaderDisable : 1; + DWORD PixelShaderAddress : 27; + + // DWORD 11: + + DWORD PixelShaderSize : 14; + DWORD : 18; + }; + DWORD dword[10]; +} GPUCOMMAND_SET_STATE; + +typedef union { + struct { + // DWORD 0: + + DWORD Offset : 11; + DWORD : 5; + DWORD Id : 8; // GPUCONSTANTID + DWORD : 8; + + // DWORD 1: + + DWORD Data[]; + }; + DWORD dword[1]; +} GPUCOMMAND_SET_CONSTANT; + +typedef union { + struct { + // DWORD 0: + + DWORD : 2; + DWORD Address : 30; + + // DWORD 1: + + DWORD Offset : 11; + DWORD : 21; + + // DWORD 2: + + DWORD Size : 12; + DWORD : 20; + }; + DWORD dword[3]; +} GPUCOMMAND_LOAD_ALU_CONSTANT; + +typedef union { + struct { + // DWORD 0: + + DWORD Type : 2; // GPULOADTYPE + DWORD : 3; + DWORD Address : 27; + + // DWORD 1: + + DWORD Size : 14; + DWORD : 2; + DWORD Start : 12; // Unused unless GPULOADTYPE_SHARED + DWORD : 4; + }; + DWORD dword[2]; +} GPUCOMMAND_LOAD_SHADER; + +typedef union { + struct { + DWORD Destination : 1; + DWORD Window : 1; + DWORD Values : 1; + DWORD Program : 1; + DWORD Control : 1; + DWORD Tessellator : 1; + DWORD Misc : 1; + DWORD Point : 1; + DWORD VertexShader : 1; + DWORD PixelShader : 1; + DWORD AluConstantBase : 1; + DWORD FetchConstantBase : 1; + DWORD IncrementalRegisterBase : 1; + DWORD BooleanBase : 1; + DWORD IntegerBase : 1; + DWORD : 17; + }; + DWORD dword[1]; +} GPUCOMMAND_INVALIDATE_STATE; + +typedef union { + struct { + // DWORD 0: + + DWORD Function : 3; // GPUSYNCFUNCTION + DWORD : 1; + DWORD MemSpace : 1; // GPUSYNCSPACE + DWORD : 27; + + // DWORD 1: + + union { + struct { + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + }; + struct { + DWORD Register : 15; + DWORD : 17; + }; + }; + + // DWORD 2: + + DWORD Reference : 32; + + // DWORD 3: + + DWORD Mask : 32; + + // DWORD 4: + + DWORD WaitInterval : 16; + DWORD : 16; + }; + DWORD dword[5]; +} GPUCOMMAND_WAIT_REG_MEM; + +typedef union { + struct { + // DWORD 0: + + DWORD Register : 15; + DWORD : 17; + + // DWORD 1: + + DWORD Reference : 32; + + // DWORD 2: + + DWORD Mask : 32; + + // DWORD 3: + + DWORD WaitInterval : 16; + DWORD : 16; + }; + DWORD dword[4]; +} GPUCOMMAND_WAIT_REG_EQ; + +typedef union { + struct { + // DWORD 0: + + DWORD Register : 15; + DWORD : 17; + + // DWORD 1: + + DWORD Reference : 32; + + // DWORD 2: + + DWORD Mask : 32; + + // DWORD 3: + + DWORD WaitInterval : 16; + DWORD : 16; + }; + DWORD dword[4]; +} GPUCOMMAND_WAIT_REG_GTE; + +typedef union { + struct { + // DWORD 0: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + + // DWORD 1: + + DWORD Data : 32; + }; + DWORD dword[2]; +} GPUCOMMAND_MEM_WRITE; + +typedef union { + struct { + // DWORD 0: + + DWORD Function : 3; // GPUSYNCFUNCTION + DWORD : 1; + DWORD PollSpace : 1; // GPUSYNCSPACE + DWORD : 3; + DWORD WriteSpace : 1; // GPUSYNCSPACE + DWORD : 23; + + // DWORD 1: + + union { + struct { + DWORD PollEndian : 2; // GPUENDIAN + DWORD PollAddress : 30; + }; + struct { + DWORD PollRegister : 15; + DWORD : 17; + }; + }; + + // DWORD 2: + + DWORD Reference : 32; + + // DWORD 3: + + DWORD Mask : 32; + + // DWORD 4: + + union { + struct { + DWORD WriteEndian : 2; // GPUENDIAN + DWORD WriteAddress : 30; + }; + struct { + DWORD WriteRegister : 15; + DWORD : 17; + }; + }; + + // DWORD 5: + + DWORD Data : 32; + }; + DWORD dword[6]; +} GPUCOMMAND_COND_WRITE; + +typedef union { + struct { + // DWORD 0: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + }; + DWORD dword[1]; +} GPUCOMMAND_MEM_WRITE_COUNTER; + +typedef union { + struct { + // DWORD 0: + + DWORD Initiator : 6; // GPUINITIATOR + DWORD : 24; + DWORD SoftwareManaged : 1; + DWORD UseCounter : 1; + + // DWORD 1: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + + // DWORD 2: + + DWORD Data : 32; + }; + DWORD dword[3]; +} GPUCOMMAND_EVENT_WRITE; + +typedef union { + struct { + // DWORD 0: + + DWORD Initiator : 6; // GPUINITIATOR + DWORD : 24; + DWORD SoftwareManaged : 1; + DWORD UseCounter : 1; + + // DWORD 1: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + + // DWORD 2: + + DWORD Data : 32; + }; + DWORD dword[3]; +} GPUCOMMAND_EVENT_WRITE_SHADER; + +typedef union { + struct { + // DWORD 0: + + DWORD Initiator : 6; // GPUINITIATOR + DWORD : 25; + DWORD UseCounter : 1; + + // DWORD 1: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + + // DWORD 2: + + DWORD Data : 32; + }; + DWORD dword[3]; +} GPUCOMMAND_EVENT_WRITE_CACHE_FLUSH; + +typedef union { + struct { + // DWORD 0: + + DWORD Initiator : 6; // GPUINITIATOR + DWORD : 26; + + // DWORD 1: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + }; + DWORD dword[2]; +} GPUCOMMAND_EVENT_WRITE_SCREEN_EXTENT; + +typedef union { + struct { + DWORD Initiator : 6; // GPUINITIATOR + DWORD : 26; + }; + DWORD dword[1]; +} GPUCOMMAND_EVENT_WRITE_ZPASS_DONE; + +typedef union { + struct { + // DWORD 0: + + DWORD Register : 15; + DWORD : 17; + + // DWORD 1: + + DWORD Endian : 2; // GPUENDIAN + DWORD Address : 30; + }; + DWORD dword[2]; +} GPUCOMMAND_REG_TO_MEM; + +typedef union { + struct { + DWORD Unused : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_WAIT_FOR_IDLE; + +typedef union { + struct { + DWORD Cpu0 : 1; + DWORD Cpu1 : 1; + DWORD Cpu2 : 1; + DWORD Cpu3 : 1; + DWORD Cpu4 : 1; + DWORD Cpu5 : 1; + DWORD : 26; + }; + DWORD dword[1]; +} GPUCOMMAND_CPU_INTERRUPT; + +typedef union { + struct { + DWORD Id : 6; + DWORD : 2; + DWORD End : 1; + DWORD : 23; + }; + DWORD dword[1]; +} GPUCOMMAND_VIZ_QUERY; + +typedef union { + struct { + // DWORD 0: + + DWORD PrimType : 6; // Must be GPUPRIMTYPE_RECTLIST + DWORD SrcSelect : 2; // Must be GPUINDEXSELECT_IMMEDIATE + DWORD MajorMode : 3; + DWORD IndexType : 1; // GPUINDEXTYPE + DWORD NotEndOfPacket : 1; + DWORD : 3; + DWORD NumIndices : 16; + + // DWORD 1: + + DWORD NumBaseIndices : 14; + DWORD : 18; + + // DWORD 2: + + DWORD Index32[]; + }; + DWORD dword[2]; +} GPUCOMMAND_MPEG_INDEX; + +typedef union { + struct { + DWORD Unused : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_NOP; + +typedef union { + struct { + // DWORD 0: + + DWORD Address : 32; + + // DWORD 1: + + DWORD Size : 20; + DWORD : 11; + DWORD MultiPass : 1; + }; + DWORD dword[2]; +} GPUCOMMAND_INDIRECT_BUFFER; + +typedef union { + struct { + // DWORD 0: + + DWORD Register : 15; + DWORD : 17; + + // DWORD 1: + + DWORD Value : 8; + DWORD : 24; + }; + DWORD dword[2]; +} GPUCOMMAND_FIX_2_FLT_REG; + +typedef union { + struct { + DWORD Unused : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_CONTEXT_UPDATE; + +#ifndef XAM_BUILD + +typedef union { + struct { + // DWORD 0: + + DWORD Low : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_SET_BIN_MASK_LO; + +typedef union { + struct { + // DWORD 0: + + DWORD High : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_SET_BIN_MASK_HI; + +typedef union { + struct { + // DWORD 0: + + DWORD Low : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_SET_BIN_SELECT_LO; + +typedef union { + struct { + // DWORD 0: + + DWORD High : 32; + }; + DWORD dword[1]; +} GPUCOMMAND_SET_BIN_SELECT_HI; + +#endif + +//------------------------------------------------------------------------------ +// GPU performce counters + +//------------------------------------------------------------------------------ +// GPU performance counter event select enums + +typedef enum +{ + GPUPE_CP_COUNT = 0, // Always Count + GPUPE_CP_RBIU_STALL = 1, // RBIU Transaction FIFO FUll + GPUPE_CP_RBIU_TAF = 2, // RBIU Transaction Almost FIFO + GPUPE_CP_PFP_STALL = 3, // PFP Transaction is Waiting for RBBM in RCIU + GPUPE_CP_RESERVED0 = 4, // Unused + GPUPE_CP_RESERVED1 = 5, // Unused + GPUPE_CP_NRT_RCIU_STALL = 6, // Transaction is Waiting for RBBM in RCIU + GPUPE_CP_Reserved2 = 7, // Unused + GPUPE_CP_NRT_MIU_STALL = 8, // CSF Fetcher Waiting on MIU + GPUPE_CP_CSF_PFP_I1_FULL = 9, // CSF PFP I1 Request FIFO is FUll + GPUPE_CP_CSF_PFP_I2_FULL = 10, // CSF PFP I2 Request FIFO is FUll + GPUPE_CP_CSF_PFP_REQ_FULL = 11, // CSF PFP State Request FIFO is FUll + GPUPE_CP_RESERVED3 = 12, // Unused + GPUPE_CP_RING_ROQ_FULL = 13, // Ring Reorder Queue is Full + GPUPE_CP_I1_ROQ_FULL = 14, // I1 Reorder Queue is Full + GPUPE_CP_I2_ROQ_FULL = 15, // I2 Reorder Queue is Full + GPUPE_CP_ST_ROQ_FULL = 16, // State Reorder Queue is Full + GPUPE_CP_RTST_ROQ_FULL = 17, // Vertex Shader Early Fetch Done + GPUPE_CP_MIU_TAG_MEM_FULL = 18, // MIU Tag Memory is Full + GPUPE_CP_MIU_WRITECLEAN = 19, // MIU WriteClean is In-Progress + GPUPE_CP_RESERVED4 = 20, // Unused + GPUPE_CP_RESERVED5 = 21, // Unused + GPUPE_CP_NRT_WRITE_STALL = 22, // Write Request Stalled by MIU Input FIFO + GPUPE_CP_NRT_READ_STALL = 23, // Read Request Stalled by MIU Input FIFO + GPUPE_CP_WC_FIFO_FULL = 24, // Write Confirm FIFO is FULL + GPUPE_CP_VTX_DEALLOC_FIFO_FULL = 25, // Vertex Shader Dealloc FIFO is FULL + GPUPE_CP_PIX_DEALLOC_FIFO_FULL = 26, // Pixel Shader Dealloc FIFO is FULL + GPUPE_CP_VTX_EVENT_FIFO_FULL = 27, // Vertex Shader Event FIFO is FULL + GPUPE_CP_PIX_EVENT_FIFO_FULL = 28, // Pixel Shader Event FIFO is FULL + GPUPE_CP_CF_EVENT_FIFO_FULL = 29, // Cache Flush Event FIFO is FULL + GPUPE_CP_ME_RB_STARVED = 30, // Micro Engine's RB Processing Starved by PFP + GPUPE_CP_ME_I1_STARVED = 31, // Micro Engine's I1 Processing Starved by PFP + GPUPE_CP_ME_I2_STARVED = 32, // Micro Engine's I2 Processing Starved by PFP + GPUPE_CP_ME_ST_STARVED = 33, // Micro Engine's ST Processing Starved by PFP + GPUPE_CP_RESERVED6 = 34, // Unused + GPUPE_CP_RESERVED7 = 35, // Unused + GPUPE_CP_RESERVED8 = 36, // Unused + GPUPE_CP_RESERVED9 = 37, // Unused + GPUPE_CP_RESERVED10 = 38, // Unused + GPUPE_CP_RESERVED11 = 39, // Unused + GPUPE_RCIU_RBBM_DWORD_SENT = 40, // RCIU is sending data to the RBBM + GPUPE_ME_PARSER_BUSY_CLOCKS = 41, // Micro Engine’s Parser is Busy + GPUPE_ME_WAIT_CONTEXT_AVAIL = 42, // Micro Engine is waiting for an available context + GPUPE_PFP_TYPE0_PACKET = 43, // PFP processed a Type-0 packet + GPUPE_PFP_TYPE3_PACKET = 44, // PFP processed a Type-3 packet + GPUPE_CSF_RB_WPTR_NEQ_RPTR = 45, // The CSF has more data to fetch from the Ring Command buffer + GPUPE_CSF_I1_SIZE_NEQ_ZERO = 46, // The CSF has more data to fetch from the Indirect1 Command buffer + GPUPE_CSF_I2_SIZE_NEQ_ZERO = 47, // The CSF has more data to fetch from the Indirect2 Command buffer + GPUPE_CSF_RB_I1_I2_FETCHING = 48, // The CSF has more data to fetch from any of the Command buffers (Ring/Indirect1/Indirect2) + GPUPE_CP_RESERVED12 = 49, // Unused + GPUPE_CP_RESERVED13 = 50, // Unused + GPUPE_CP_RESERVED14 = 51, // Unused + GPUPE_CP_RESERVED15 = 52, // Unused + GPUPE_CP_RESERVED16 = 53, // Unused + GPUPE_CP_RESERVED17 = 54, // Unused + GPUPE_CP_RESERVED18 = 55, // Unused + GPUPE_CP_RESERVED19 = 56, // Unused + GPUPE_CP_RESERVED20 = 57, // Unused + GPUPE_CP_RESERVED21 = 58, // Unused + GPUPE_CP_RESERVED22 = 59, // Unused + GPUPE_CP_RESERVED23 = 60, // Unused + GPUPE_CP_RESERVED24 = 61, // Unused + GPUPE_CP_RESERVED25 = 62, // Unused + GPUPE_CP_RESERVED26 = 63, // Unused +} GPUPERFEVENT_CP; + +typedef enum +{ + GPUPE_RBBM_COUNT = 0, // Count Number of Clocks + GPUPE_RBBM_NRT_BUSY = 1, // Non-Real-Time Busy + GPUPE_RBBM_BC_CNTX0_BUSY = 2, + GPUPE_RBBM_BC_CNTX17_BUSY = 3, + GPUPE_RBBM_SQ_CNTX0_BUSY = 4, + GPUPE_RBBM_SQ_CNTX17_BUSY = 5, + GPUPE_RBBM_VGT_BUSY = 6, + GPUPE_RBBM_VGT_NODMA_BUSY = 7, + GPUPE_RBBM_PA_BUSY = 8, + GPUPE_RBBM_SC_CNTX0_BUSY = 9, + GPUPE_RBBM_SC_CNTX17_BUSY = 10, + GPUPE_RBBM_TPC_BUSY = 11, + GPUPE_RBBM_TC_BUSY = 12, + GPUPE_RBBM_SX_BUSY = 13, + GPUPE_RESERVED1 = 14, + GPUPE_RBBM_CP_COHER_BUSY = 15, + GPUPE_RBBM_CP_NRT_BUSY = 16, + GPUPE_RESERVED2 = 17, + GPUPE_RBBM_CP_DMA_BUSY = 18, + GPUPE_RESERVED3 = 19, + GPUPE_RESERVED4 = 20, + GPUPE_RESERVED5 = 21, + GPUPE_RBBM_DMA_IDLE_STALL = 22, // Non-RT Waiting for CP`s DMA to go Idle + GPUPE_RESERVED6 = 23, + GPUPE_RESERVED7 = 24, + GPUPE_RBBM_GFX_IDLE_STALL = 25, // Non-RT Waiting for Graphics Pipe to be Idle + GPUPE_RBBM_GFX_IDLEC_STALL = 26, // Non-RT Waiting for Graphics Pipe to be Idle and Clean + GPUPE_RBBM_INTERRUPT = 27, // Combined Interrupt Signal to the BIF +} GPUPERFEVENT_RBBM; + +typedef enum +{ + GPUPE_SQ_PIXEL_VECTORS_SUB = 0, // Number of pixel vectors submitted + GPUPE_SQ_VERTEX_VECTORS_SUB = 1, // Number of vertex vectors submitted + GPUPE_SQ_ALU0_ACTIVE_VTX_SIMD0 = 2, // Number of cycles SIMD0's ALU0 is executing vertex shader instructions. + GPUPE_SQ_ALU1_ACTIVE_VTX_SIMD0 = 3, // Number of cycles ALU 1 is active (vertex) for SIMD0 + GPUPE_SQ_ALU0_ACTIVE_PIX_SIMD0 = 4, // Number of cycles ALU 0 is active (pixel) for SIMD0 + GPUPE_SQ_ALU1_ACTIVE_PIX_SIMD0 = 5, // Number of cycles ALU 1 is active (pixel) for SIMD0 + GPUPE_SQ_ALU0_ACTIVE_VTX_SIMD1 = 6, // Number of cycles ALU 0 is active (vertex) for SIMD1 + GPUPE_SQ_ALU1_ACTIVE_VTX_SIMD1 = 7, // Number of cycles ALU 1 is active (vertex) for SIMD1 + GPUPE_SQ_ALU0_ACTIVE_PIX_SIMD1 = 8, // Number of cycles ALU 0 is active (pixel) for SIMD1 + GPUPE_SQ_ALU1_ACTIVE_PIX_SIMD1 = 9, // Number of cycles ALU 1 is active (pixel) for SIMD1 + GPUPE_SQ_EXPORT_CYCLES = 10, // Number of clocks the SQ is exporting data + GPUPE_SQ_ALU_CST_WRITTEN = 11, // Number of ALU constants written from the CP for both pix/vtx + GPUPE_SQ_TEX_CST_WRITTEN = 12, // Number of texture constants written from the CP for both pix/vtx + GPUPE_SQ_ALU_CST_STALL = 13, // Number of clocks the constant memory is stalled because of ALU constant store full + GPUPE_SQ_ALU_TEX_STALL = 14, // Number of clocks the constant memory is stalled because of texture constant store full + GPUPE_SQ_INST_WRITTEN = 15, // Number of instructions written from the CP for both pix/vtx + GPUPE_SQ_BOOLEAN_WRITTEN = 16, // Number of control flow booleans written from the CP for both pix/vtx + GPUPE_SQ_LOOPS_WRITTEN = 17, // Number of control flow loops written from the CP for both pix/vtx + GPUPE_SQ_PIXEL_SWAP_IN = 18, // Number of times a pixel vector is de-activated, this should be (number of clauses) * number of threads + GPUPE_SQ_PIXEL_SWAP_OUT = 19, // Number of times a pixel vector is activated, this should be (number of clauses - 1) * number of threads + GPUPE_SQ_VERTEX_SWAP_IN = 20, // Number of times a vertex vector is de-activated, this should be (number of clauses) * number of threads + GPUPE_SQ_VERTEX_SWAP_OUT = 21, // Number of times a vertex vector is activated, this should be (number of clauses - 1) * number of threads + GPUPE_SQ_ALU_VTX_INST_ISSUED = 22, // Number of ALU instruction issued (vertex) include all SIMDS and ALU 0/1 + GPUPE_SQ_TEX_VTX_INST_ISSUED = 23, // Number of Texture instruction issued (vertex) + GPUPE_SQ_VC_VTX_INST_ISSUED = 24, // Number of VC instruction issued (vertex) + GPUPE_SQ_CF_VTX_INST_ISSUED = 25, // Number of control flow instruction issued (vertex) include all resources (TP,VC,all SIMDS) + GPUPE_SQ_ALU_PIX_INST_ISSUED = 26, // Number of ALU instruction issued (pixel) include all SIMDS and ALU 0/1 + GPUPE_SQ_TEX_PIX_INST_ISSUED = 27, // Number of Texture instruction issued (pixel) + GPUPE_SQ_VC_PIX_INST_ISSUED = 28, // Number of VC instruction issued (pixel) + GPUPE_SQ_CF_PIX_INST_ISSUED = 29, // Number of control flow instruction issued (pixel) include all resources (TP,VC,all SIMDS) + GPUPE_SQ_ALU0_FIFO_EMPTY_SIMD0 = 30, // aka 'SQ_ALU0_STALL_SIMD0'. Number of clocks SIMD0's ALU0 and ALU1 were both idle, when there was any pixel or vertex threads in the RS. + GPUPE_SQ_ALU1_FIFO_EMPTY_SIMD0 = 31, // Number of clocks ALU 1 FIFO was empty (busy with control flow) for SIMD0, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_ALU0_FIFO_EMPTY_SIMD1 = 32, // Number of clocks ALU 0 FIFO was empty (busy with control flow) for SIMD1, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_ALU1_FIFO_EMPTY_SIMD1 = 33, // Number of clocks ALU 1 FIFO was empty (busy with control flow) for SIMD1, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_ALU_NOPS = 34, // Number of ALU NOPs generated by the SQ. This counts the number of added ALU instructions because of the use of the address register immediately after the address is set + GPUPE_SQ_PRED_SKIP = 35, // Always zero + GPUPE_SQ_SYNC_ALU_STALL_SIMD0_VTX = 36, // Number of cycles all vertex threads are blocked because of synchronization (Alu SIMD0). This is all threads that want to go to Alu SIMD0 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_ALU_STALL_SIMD1_VTX = 37, // Number of cycles all vertex threads are blocked because of synchronization (Alu SIMD1) This is all threads that want to go to Alu SIMD1 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_TEX_STALL_VTX = 38, // Number of cycles all vertex threads are blocked because of synchronization (Texture) This is all threads that want to go to the TP but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_VC_STALL_VTX = 39, // Number of cycles all vertex threads are blocked because of synchronization (VC) This is all threads that want to go to the VC but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_CONSTANTS_USED_SIMD0 = 40, // Number of ALU constants used for SIMD0. Decodes the instruction to count how many constants there are (1,2,3) + GPUPE_SQ_CONSTANTS_SENT_SP_SIMD0 = 41, // Number of ALU constants sent to the SP for SIMD0. This is the number of reads to the constant store. If greather than SQ_CONSTANTS_USED, an instruction was recirculated because of waterfaling. + GPUPE_SQ_GPR_STALL_VTX = 42, // Number of stall cycles because of GPR resource (vertex). This prevents vertexes to be sent from the VGT. + GPUPE_SQ_GPR_STALL_PIX = 43, // Number of stall cycles because of GPR resource (pixel). This prevents pixels to be sent from the SC. + GPUPE_SQ_VTX_RS_STALL = 44, // Number of stall cycles because of Reservation Station (vertex). This prevents vertexes to be sent from the VGT. + GPUPE_SQ_PIX_RS_STALL = 45, // Number of stall cycles because of Reservation Station (pixel). This prevents pixels to be sent from the SC. + GPUPE_SQ_SX_PC_FULL = 46, // Number of cycles with parameter cache preventing export of vertex vector + GPUPE_SQ_SX_EXP_BUFF_FULL = 47, // Number of cycles with export buffers preventing export + GPUPE_SQ_SX_POS_BUFF_FULL = 48, // Number of cycles with position buffers preventing export + GPUPE_SQ_INTERP_QUADS = 49, // Number of interpolated quads. This is number of quads * number of parameters. + GPUPE_SQ_INTERP_ACTIVE = 50, // Number of active interpolation cycles. Optimaly one cycle should interpolate 4 quads for 1 parameter. + GPUPE_SQ_IN_PIXEL_STALL = 51, // Number of cycles a ready to go pixel vector stalled because of port arbitration to the GPRs + GPUPE_SQ_IN_VTX_STALL = 52, // Number of cycles a ready to go vertex vector stalled because of port arbitration to the GPRs + GPUPE_SQ_VTX_CNT = 53, // Number of individual vertexes sent to the sequencer + GPUPE_SQ_VTX_16_VECTOR = 54, // Number of vertex vectors with less than 16 vertexes + GPUPE_SQ_VTX_32_VECTOR = 55, // Number of vertex vectors with less than 32 vertexes + GPUPE_SQ_VTX_48_VECTOR = 56, // Number of vertex vectors with less than 48 vertexes + GPUPE_SQ_PIXEL_16_VECTOR = 57, // Number of pixel vectors with less than 16 pixels + GPUPE_SQ_PIXEL_32_VECTOR = 58, // Number of pixel vectors with less than 32 pixels + GPUPE_SQ_PIXEL_48_VECTOR = 59, // Number of pixel vectors with less than 48 pixels + GPUPE_SQ_CONSTANTS_USED_SIMD1 = 60, // Number of ALU constants used for SIMD1. Decodes the instruction to count how many constants there are (1,2,3) + GPUPE_SQ_CONSTANTS_SENT_SP_SIMD1 = 61, // Number of ALU constants sent to the SP for SIMD1. This is the number of reads to the constant store. If greather than SQ_CONSTANTS_USED, an instruction was recirculated because of waterfaling. + GPUPE_SQ_SX_MEM_EXP_FULL = 62, // always zero. + GPUPE_SQ_ALU0_ACTIVE_VTX_SIMD2 = 63, // Number of cycles ALU 0 is active (vertex) for SIMD2 + GPUPE_SQ_ALU1_ACTIVE_VTX_SIMD2 = 64, // Number of cycles ALU 1 is active (vertex) for SIMD2 + GPUPE_SQ_ALU0_ACTIVE_PIX_SIMD2 = 65, // Number of cycles ALU 0 is active (pixel) for SIMD2 + GPUPE_SQ_ALU1_ACTIVE_PIX_SIMD2 = 66, // Number of cycles ALU 1 is active (pixel) for SIMD2 + GPUPE_SQ_ALU0_ACTIVE_VTX_SIMD3 = 67, // Number of cycles ALU 0 is active (vertex) for SIMD3 + GPUPE_SQ_ALU1_ACTIVE_VTX_SIMD3 = 68, // Number of cycles ALU 1 is active (vertex) for SIMD3 + GPUPE_SQ_ALU0_ACTIVE_PIX_SIMD3 = 69, // Number of cycles ALU 0 is active (pixel) for SIMD3 + GPUPE_SQ_ALU1_ACTIVE_PIX_SIMD3 = 70, // Number of cycles ALU 1 is active (pixel) for SIMD3 + GPUPE_SQ_ALU0_FIFO_EMPTY_SIMD2 = 71, // Number of clocks ALU 0 FIFO was empty (busy with control flow) for SIMD2, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_ALU1_FIFO_EMPTY_SIMD2 = 72, // Number of clocks ALU 1 FIFO was empty (busy with control flow) for SIMD2, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_ALU0_FIFO_EMPTY_SIMD3 = 73, // Number of clocks ALU 0 FIFO was empty (busy with control flow) for SIMD3, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_ALU1_FIFO_EMPTY_SIMD3 = 74, // Number of clocks ALU 1 FIFO was empty (busy with control flow) for SIMD3, only counts when there is a thread in any of pixel or vertex RS + GPUPE_SQ_SYNC_ALU_STALL_SIMD2_VTX = 75, // Number of cycles all vertex threads are blocked because of synchronization (Alu SIMD2) This is all threads that want to go to Alu SIMD2 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_ALU_STALL_SIMD3_VTX = 76, // Number of cycles all vertex threads are blocked because of synchronization (Alu SIMD3) This is all threads that want to go to Alu SIMD3 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_ALU_STALL_SIMD0_PIX = 77, // Number of cycles all pixel threads are blocked because of synchronization (Alu SIMD0) This is all threads that want to go to Alu SIMD0 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_ALU_STALL_SIMD1_PIX = 78, // Number of cycles all pixel threads are blocked because of synchronization (Alu SIMD1) This is all threads that want to go to Alu SIMD1 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_ALU_STALL_SIMD2_PIX = 79, // Number of cycles all pixel threads are blocked because of synchronization (Alu SIMD2) This is all threads that want to go to Alu SIMD2 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_ALU_STALL_SIMD3_PIX = 80, // Number of cycles all pixel threads are blocked because of synchronization (Alu SIMD3) This is all threads that want to go to Alu SIMD3 but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_TEX_STALL_PIX = 81, // Number of cycles all pixel threads are blocked because of synchronization (Texture) This is all threads that want to go to the TP but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_SYNC_VC_STALL_PIX = 82, // Number of cycles all pixel threads are blocked because of synchronization (VC) This is all threads that want to go to the VC but cannot because of the VC,TP or alloc resource. + GPUPE_SQ_CONSTANTS_USED_SIMD2 = 83, // Number of ALU constants used for SIMD2. Decodes the instruction to count how many constants there are (1,2,3) + GPUPE_SQ_CONSTANTS_SENT_SP_SIMD2 = 84, // Number of ALU constants sent to the SP for SIMD2. This is the number of reads to the constant store. If greather than SQ_CONSTANTS_USED, an instruction was recirculated because of waterfaling. + GPUPE_SQ_CONSTANTS_USED_SIMD3 = 85, // Number of ALU constants used for SIMD3. Decodes the instruction to count how many constants there are (1,2,3) + GPUPE_SQ_CONSTANTS_SENT_SP_SIMD3 = 86, // Number of ALU constants sent to the SP for SIMD3. This is the number of reads to the constant store. If greather than SQ_CONSTANTS_USED, an instruction was recirculated because of waterfaling. + GPUPE_SQ_ALU0_FIFO_FULL_SIMD0 = 87, // Number of cycles ALU 0 FIFO was full for SIMD0 + GPUPE_SQ_ALU1_FIFO_FULL_SIMD0 = 88, // Number of cycles ALU 1 FIFO was full for SIMD0 + GPUPE_SQ_ALU0_FIFO_FULL_SIMD1 = 89, // Number of cycles ALU 0 FIFO was full for SIMD1 + GPUPE_SQ_ALU1_FIFO_FULL_SIMD1 = 90, // Number of cycles ALU 1 FIFO was full for SIMD1 + GPUPE_SQ_ALU0_FIFO_FULL_SIMD2 = 91, // Number of cycles ALU 0 FIFO was full for SIMD2 + GPUPE_SQ_ALU1_FIFO_FULL_SIMD2 = 92, // Number of cycles ALU 1 FIFO was full for SIMD2 + GPUPE_SQ_ALU0_FIFO_FULL_SIMD3 = 93, // Number of cycles ALU 0 FIFO was full for SIMD3 + GPUPE_SQ_ALU1_FIFO_FULL_SIMD3 = 94, // Number of cycles ALU 1 FIFO was full for SIMD3 + GPUPE_VC_PERF_STATIC = 95, // Number of cycles the VC is not ready to receive anything and the SQ is not ready to send anything + GPUPE_VC_PERF_STALLED = 96, // Number of cycles the VC is not ready to receive anything but the SQ is ready to send something + GPUPE_VC_PERF_STARVED = 97, // Number of cycles the VC is ready to receive something but the SQ is not ready to send anything + GPUPE_VC_PERF_SEND = 98, // Number of cycles the VC is ready to receive something and the SQ is is ready to send something + GPUPE_VC_PERF_ACTUAL_STARVED = 99, // Number of cycles the VC is starved + GPUPE_PIXEL_THREAD_0_ACTIVE = 100, // Number of cycles the thread 0 of pixel is active + GPUPE_VERTEX_THREAD_0_ACTIVE = 101, // Number of cycles the thread 0 of vertex is active + GPUPE_PIXEL_THREAD_0_NUMBER = 102, // Number of times the thread 0 of pixel is active + GPUPE_VERTEX_THREAD_0_NUMBER = 103, // Number of times the thread 0 of vertex is active + GPUPE_VERTEX_EVENT_NUMBER = 104, // Number of events sent in the vertex thread buffer + GPUPE_PIXEL_EVENT_NUMBER = 105, // Number of events sent in the pixel thread buffer +} GPUPERFEVENT_SQ; + +typedef enum +{ + GPUPE_VGT_SQ_EVENT_WINDOW_ACTIVE = 0, + GPUPE_VGT_SQ_SEND = 1, + GPUPE_VGT_SQ_STALLED = 2, + GPUPE_VGT_SQ_STARVED_BUSY = 3, + GPUPE_VGT_SQ_STARVED_IDLE = 4, + GPUPE_VGT_SQ_STATIC = 5, + GPUPE_VGT_PA_EVENT_WINDOW_ACTIVE = 6, + GPUPE_VGT_PA_CLIP_V_SEND = 7, + GPUPE_VGT_PA_CLIP_V_STALLED = 8, + GPUPE_VGT_PA_CLIP_V_STARVED_BUSY = 9, + GPUPE_VGT_PA_CLIP_V_STARVED_IDLE = 10, + GPUPE_VGT_PA_CLIP_V_STATIC = 11, + GPUPE_VGT_PA_CLIP_P_SEND = 12, + GPUPE_VGT_PA_CLIP_P_STALLED = 13, + GPUPE_VGT_PA_CLIP_P_STARVED_BUSY = 14, + GPUPE_VGT_PA_CLIP_P_STARVED_IDLE = 15, + GPUPE_VGT_PA_CLIP_P_STATIC = 16, + GPUPE_VGT_PA_CLIP_S_SEND = 17, + GPUPE_VGT_PA_CLIP_S_STALLED = 18, + GPUPE_VGT_PA_CLIP_S_STARVED_BUSY = 19, + GPUPE_VGT_PA_CLIP_S_STARVED_IDLE = 20, + GPUPE_VGT_PA_CLIP_S_STATIC = 21, + GPUPE_RBIU_FIFOS_EVENT_WINDOW_ACTIVE = 22, + GPUPE_RBIU_IMMED_DATA_FIFO_STARVED = 23, + GPUPE_RBIU_IMMED_DATA_FIFO_STALLED = 24, + GPUPE_RBIU_DMA_REQUEST_FIFO_STARVED = 25, + GPUPE_RBIU_DMA_REQUEST_FIFO_STALLED = 26, + GPUPE_RBIU_DRAW_INITIATOR_FIFO_STARVED = 27, + GPUPE_RBIU_DRAW_INITIATOR_FIFO_STALLED = 28, + GPUPE_SPARE29 = 29, + GPUPE_SPARE30 = 30, + GPUPE_SPARE31 = 31, + GPUPE_SPARE32 = 32, + GPUPE_SPARE33 = 33, + GPUPE_SPARE34 = 34, + GPUPE_SPARE35 = 35, + GPUPE_SPARE36 = 36, + GPUPE_SPARE37 = 37, + GPUPE_SPARE38 = 38, + GPUPE_SPARE39 = 39, + GPUPE_TE_SU_IN_VALID = 40, + GPUPE_TE_SU_IN_READ = 41, + GPUPE_TE_SU_IN_PRIM = 42, + GPUPE_TE_SU_IN_EOP = 43, + GPUPE_TE_SU_IN_NULL_PRIM = 44, + GPUPE_TE_WK_IN_VALID = 45, + GPUPE_TE_WK_IN_READ = 46, + GPUPE_TE_OUT_PRIM_VALID = 47, + GPUPE_TE_OUT_PRIM_READ = 48, +} GPUPERFEVENT_VGT; + +typedef enum +{ + GPUPE_RG_VERTICES = 0, // Number of vertices processed by RG + GPUPE_RG_CLAMPED = 1, // Number of vertices clamped by RG + GPUPE_RG_L2_REQUEST = 2, // Count of L2 Requests created by RG + GPUPE_RG_L1_REQUEST = 3, // Count of L1 Requests created by RG + GPUPE_RG_MEGAFETCH = 4, // Count of megafetches processed by RG + GPUPE_RG_END_OF_GROUP = 5, // Count of end_of_group signals received from SQ + GPUPE_RG_CONFLICT = 6, // Number of vertex pairs that conflict in the L2 + GPUPE_RG_DWORDS_REQUESTED = 7, // Number of dword requests created by RG + GPUPE_RG_SPARE0 = 8, // Reserved for RG + GPUPE_RG_SPARE1 = 9, // Reserved for RG + GPUPE_CC_STALLS = 10, // Number of clocks CC stalled due to memory latency + GPUPE_CC_HITS = 11, // L2 Requests that resulted in a cache hit + GPUPE_CC_MISSES = 12, // L2 Requests that resulted in a cache miss + GPUPE_CC_SECTOR_MISSES = 13, // L2 Requests that resulted in a sector miss + GPUPE_CC_L2B_STALLS = 14, // CC stalled due to L2B FIFO not RTR + GPUPE_CC_MI_STALLS = 15, // CC stalled due to MI not RTR + GPUPE_CC_MULTICYCLE_STALLS = 16, // CC stalled due to multicycle + GPUPE_CC_EVEN_ALLOC_STALLS = 17, // CC stalled due to even allocation stall + GPUPE_CC_ODD_ALLOC_STALLS = 18, // CC stalled due to odd allocation stall + GPUPE_CC_EVEN_BUSY_STALLS = 19, // CC stalled due to even counter busy + GPUPE_CC_ODD_BUSY_STALLS = 20, // CC stalled due to odd counter busy + GPUPE_CC_IN_FIFO_EMPTY = 21, // CC input FIFO is empty + GPUPE_CC_IN_FIFO_FULL = 22, // CC input FIFO is full + GPUPE_CC_FREEZE = 23, // CC frozen due to one of the stall conditions + GPUPE_CC_SPARE0 = 24, // Reserved for CC + GPUPE_CC_SPARE1 = 25, // Reserved for CC + GPUPE_CC_SPARE2 = 26, // Reserved for CC + GPUPE_CC_SPARE3 = 27, // Reserved for CC + GPUPE_CC_SPARE4 = 28, // Reserved for CC + GPUPE_CC_SPARE5 = 29, // Reserved for CC + GPUPE_MI_REQUESTS_TO_MH = 30, // Number of memory requests issued to memory hub + GPUPE_MI_AGP_REQUESTS = 31, // Number of AGP memory requests issued + GPUPE_MI_LATENCY_BITS_4_0 = 32, // 4:0 of the latency count + GPUPE_MI_LATENCY_BITS_9_5 = 33, // Bits 9:5 of the latency count + GPUPE_MI_LATENCY_BITS_14_10 = 34, // Bits 14:10 of the latency count + GPUPE_MI_LATENCY_BITS_17_15 = 35, // Bits 17:15 of the latency count + GPUPE_MI_INPUT_FIFOS_FULL = 36, // Number of cycles any of the four Input FIFOs to the MI requestor are full + GPUPE_MI_INPUT_FIFOS_0_FULL = 37, // Number of cycles any of the two Input FIFOs on request path 0 to the MI requestor are full + GPUPE_MI_INPUT_FIFOS_1_FULL = 38, // Number of cycles any of the two Input FIFOs on request path 1 to the MI requestor are full + GPUPE_MI_SPARE1 = 39, // Reserved for MI + GPUPE_RP_SP_DATA_VALID = 40, // Number of clocks of valid data returned to SP + GPUPE_RP_STALLED = 41, // Number of clocks RP stalled due to TC use of phase + GPUPE_RP_SPARE0 = 42, // Reserved for RP + GPUPE_RP_SPARE1 = 43, // Reserved for RP + GPUPE_RP_SPARE2 = 44, // Reserved for RP + GPUPE_RP_SPARE3 = 45, // Reserved for RP + GPUPE_RP_SPARE4 = 46, // Reserved for RP + GPUPE_RP_SPARE5 = 47, // Reserved for RP + GPUPE_RP_SPARE6 = 48, // Reserved for RP + GPUPE_RP_SPARE7 = 49, // Reserved for RP + GPUPE_DC_NUM_VALIDS = 50, // Number of valid vectors returned to the SP + GPUPE_DC_SPARE0 = 51, // Reserved for DC + GPUPE_DC_SPARE1 = 52, // Reserved for DC + GPUPE_DC_SPARE2 = 53, // Reserved for DC + GPUPE_DC_SPARE3 = 54, // Reserved for DC + GPUPE_DC_SPARE4 = 55, // Reserved for DC + GPUPE_DC_SPARE5 = 56, // Reserved for DC + GPUPE_DC_SPARE6 = 57, // Reserved for DC + GPUPE_DC_SPARE7 = 58, // Reserved for DC + GPUPE_DC_SPARE8 = 59, // Reserved for DC + GPUPE_SQ_VC_SEND = 60, // Number of clocks the SQ is passing data to the VC + GPUPE_VC_STARVED_IDLE = 61, // Number of clock cycles the VC is idle and waiting for more data from the SQ + GPUPE_VC_BUSY = 62, // Number of clock cycles the VC is busy processing data + GPUPE_VC_IDLE = 63, // Number of clock cycles the VC is idle + GPUPE_VC_SPARE0 = 64, // Reserved for VC + GPUPE_VC_SPARE1 = 65, // Reserved for VC + GPUPE_VC_SPARE2 = 66, // Reserved for VC + GPUPE_VC_SPARE3 = 67, // Reserved for VC + GPUPE_VC_SPARE4 = 68, // Reserved for VC + GPUPE_VC_SPARE5 = 69, // Reserved for VC +} GPUPERFEVENT_VC; + +typedef enum +{ + GPUPE_PERF_PAPC_PASX_REQ = 0, // Number of PA->SX requests + GPUPE_PERF_PAPC_PASX_DISABLE_PIPE = 1, // Number of transfers lost due to disabled pipe + GPUPE_PERF_PAPC_PASX_FIRST_VECTOR = 2, // Number of First Vectors from SX to PA + GPUPE_PERF_PAPC_PASX_SECOND_VECTOR = 3, // Number of Second Vectors from SX to PA + GPUPE_PERF_PAPC_PASX_FIRST_DEAD = 4, // Number of Unused First Vectors (due to granularity of 4) + GPUPE_PERF_PAPC_PASX_SECOND_DEAD = 5, // Number of Unused Second Vectors (due to granularity of 4) + GPUPE_PERF_PAPC_PASX_VTX_KILL_DISCARD = 6, // Number of vertices which have VTX KILL Enabled and Set + GPUPE_PERF_PAPC_PASX_VTX_NAN_DISCARD = 7, // Number ov vertices which have NaN and corresponding NaN discard + GPUPE_PERF_PAPC_PA_INPUT_PRIM = 8, // Number of Primitives input to PA + GPUPE_PERF_PAPC_PA_INPUT_NULL_PRIM = 9, // Number of Null Primitives input to PA + GPUPE_PERF_PAPC_PA_INPUT_EVENT_FLAG = 10, // Number of Events input to PA + GPUPE_PERF_PAPC_PA_INPUT_FIRST_PRIM_SLOT = 11, // Number of First-Prim-Of-Slots input to PA + GPUPE_PERF_PAPC_PA_INPUT_END_OF_PACKET = 12, // Number of End-Of-Packets input to PA + GPUPE_PERF_PAPC_CLPR_CULL_PRIM = 13, // Number of Prims Culled by Clipper for VV, UCP, VTX_KILL, VTX_NAN + GPUPE_PERF_PAPC_CLPR_VVUCP_CULL_PRIM = 14, // Number of Prims Culled by Clipper for VV and UCP + GPUPE_PERF_PAPC_CLPR_VV_CULL_PRIM = 15, // Number of Prims Culled by Clipper for VV + GPUPE_PERF_PAPC_CLPR_UCP_CULL_PRIM = 16, // Number of Prims Culled by Clipper for UCP + GPUPE_PERF_PAPC_CLPR_VTX_KILL_CULL_PRIM = 17, // Number of Prims Culled by Clipper for VTX_KILL + GPUPE_PERF_PAPC_CLPR_VTX_NAN_CULL_PRIM = 18, // Number of Prims Culled by Clipper for VTX_NAN + GPUPE_PERF_PAPC_CLPR_CULL_TO_NULL_PRIM = 19, // Number of Clipper Culled Prims Retained for Pipe Info + GPUPE_PERF_PAPC_CLPR_VVUCP_CLIP_PRIM = 20, // Number of Prims Clipped by Clipper for VV and/or UCP + GPUPE_PERF_PAPC_CLPR_VV_CLIP_PRIM = 21, // Number of Prims Clipped by Clipper for VV + GPUPE_PERF_PAPC_CLPR_UCP_CLIP_PRIM = 22, // Number of Prims Clipped by Clipper for UCP + GPUPE_PERF_PAPC_CLPR_POINT_CLIP_CANDIDATE = 23, // Number of Points which require detailed clip checked + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_CNT_1 = 24, // Number of Prims with 1 Clip Plane Intersection (includes VV and UCP) + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_CNT_2 = 25, // Number of Prims with 2 Clip Plane Intersections (includes VV and UCP) + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_CNT_3 = 26, // Number of Prims with 3 Clip Plane Intersections (includes VV and UCP) + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_CNT_4 = 27, // Number of Prims with 4 Clip Plane Intersections (includes VV and UCP) + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_CNT_5_8 = 28, // Number of Prims with 5-8 Clip Plane Intersections (includes VV and UCP) + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_CNT_9_12 = 29, // Number of Prims with 9-12 Clip Plane Intersections (includes VV and UCP) + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_NEAR = 30, // Number of Prims which intersect the NEAR VV Plane + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_FAR = 31, // Number of Prims which intersect the FAR VV Plane + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_LEFT = 32, // Number of Prims which intersect the LEFT VV Plane + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_RIGHT = 33, // Number of Prims which intersect the RIGHT VV Plane + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_TOP = 34, // Number of Prims which intersect the TOP VV Plane + GPUPE_PERF_PAPC_CLPR_CLIP_PLANE_BOTTOM = 35, // Number of Prims which intersect the BOTTOM VV Plane + GPUPE_PERF_PAPC_CLSM_NULL_PRIM = 36, // Number of null primitives at Clip State Machine pipe stage + GPUPE_PERF_PAPC_CLSM_TOTALLY_VISIBLE_PRIM = 37, // Number of totally visible (no-clipping) prims + GPUPE_PERF_PAPC_CLSM_CLIP_PRIM = 38, // UNUSED + GPUPE_PERF_PAPC_CLSM_CULL_TO_NULL_PRIM = 39, // Number of primitives which are culled during clip process + GPUPE_PERF_PAPC_CLSM_OUT_PRIM_CNT_1 = 40, // Number of primitives which were clipped and result in 1 primitive + GPUPE_PERF_PAPC_CLSM_OUT_PRIM_CNT_2 = 41, // Number of primitives which were clipped and result in 2 primitives + GPUPE_PERF_PAPC_CLSM_OUT_PRIM_CNT_3 = 42, // Number of primitives which were clipped and result in 3 primitives + GPUPE_PERF_PAPC_CLSM_OUT_PRIM_CNT_4 = 43, // Number of primitives which were clipped and result in 4 primitives + GPUPE_PERF_PAPC_CLSM_OUT_PRIM_CNT_5_8 = 44, // Number of primitives which were clipped and result in 5-8 primitives + GPUPE_PERF_PAPC_CLSM_OUT_PRIM_CNT_9_13 = 45, // Number of primitives which were clipped and result in 9-13 primitives + GPUPE_PERF_PAPC_CLSM_NON_TRIVIAL_CULL = 46, // UNUSED + GPUPE_PERF_PAPC_SU_INPUT_PRIM = 47, // Number of primitives input to the Setup block + GPUPE_PERF_PAPC_SU_INPUT_CLIP_PRIM = 48, // Number of clipped primitives input to the Setup block + GPUPE_PERF_PAPC_SU_INPUT_NULL_PRIM = 49, // Number of null primitives input to the Setup block + GPUPE_PERF_PAPC_SU_ZERO_AREA_CULL_PRIM = 50, // Number of primitives culled due to zero area + GPUPE_PERF_PAPC_SU_BACK_FACE_CULL_PRIM = 51, // Number of back-face primitives culled due to facedness + GPUPE_PERF_PAPC_SU_FRONT_FACE_CULL_PRIM = 52, // Number of front-face primitives culled due to facedness + GPUPE_PERF_PAPC_SU_POLYMODE_FACE_CULL = 53, // Number of polymode cull-determination primitives culled + GPUPE_PERF_PAPC_SU_POLYMODE_BACK_CULL = 54, // Number of polymode primitives discarded due to Back-Face Cull + GPUPE_PERF_PAPC_SU_POLYMODE_FRONT_CULL = 55, // Number of polymode primitives discarded due to Front-Face Cull + GPUPE_PERF_PAPC_SU_POLYMODE_INVALID_FILL = 56, // Number of polymode lines and/or points which are culled because they are an internal edge or point + GPUPE_PERF_PAPC_SU_OUTPUT_PRIM = 57, // Number of primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_CLIP_PRIM = 58, // Number of clipped primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_NULL_PRIM = 59, // Number of null primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_EVENT_FLAG = 60, // Number of events output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_FIRST_PRIM_SLOT = 61, // Number of First-Prim-Of-Slots output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_END_OF_PACKET = 62, // Number of End-Of-Packets output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_POLYMODE_FACE = 63, // Number of polymode facing primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_POLYMODE_BACK = 64, // Number of polymode back-face primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUTPUT_POLYMODE_FRONT = 65, // Number of polymode front-face primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUT_CLIP_POLYMODE_FACE = 66, // Number of clipped polymode facing primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUT_CLIP_POLYMODE_BACK = 67, // Number of clipped polymode back-face primitives output from the Setup block + GPUPE_PERF_PAPC_SU_OUT_CLIP_POLYMODE_FRONT = 68, // Number of clipped polymode front-face primitives output from the Setup block + GPUPE_PERF_PAPC_PASX_REQ_IDLE = 69, // Number of clocks PASX Requestor is Idle + GPUPE_PERF_PAPC_PASX_REQ_BUSY = 70, // Number of clocks PASX Requestor is Busy + GPUPE_PERF_PAPC_PASX_REQ_STALLED = 71, // Number of clocks PASX Requestor is Stalled + GPUPE_PERF_PAPC_PASX_REC_IDLE = 72, // Number of clocks PASX Receiver is Idle + GPUPE_PERF_PAPC_PASX_REC_BUSY = 73, // Number of clocks PASX Receiver is Busy + GPUPE_PERF_PAPC_PASX_REC_STARVED_SX = 74, // Number of clocks PASX Receiver is Stalled by SX + GPUPE_PERF_PAPC_PASX_REC_STALLED = 75, // Number of clocks PASX Reciever is Stalled by Position Memory or Clip Code Generator + GPUPE_PERF_PAPC_PASX_REC_STALLED_POS_MEM = 76, // Number of clocks PASX Reciever is Stalled by Position Memory + GPUPE_PERF_PAPC_PASX_REC_STALLED_CCGSM_IN = 77, // Number of clocks PASX Reciever is Stalled by Clip Code Generator + GPUPE_PERF_PAPC_CCGSM_IDLE = 78, // Number of clocks Clip Code Gen is Idle + GPUPE_PERF_PAPC_CCGSM_BUSY = 79, // Number of clocks Clip Code Gen is Busy + GPUPE_PERF_PAPC_CCGSM_STALLED = 80, // Number of clocks Clip Code Gen is Stalled + GPUPE_PERF_PAPC_CLPRIM_IDLE = 81, // Number of clocks Clip Primitive Machine is Idle + GPUPE_PERF_PAPC_CLPRIM_BUSY = 82, // Number of clocks Clip Primitive Machine is Busy + GPUPE_PERF_PAPC_CLPRIM_STALLED = 83, // Number of clocks Clip Primitive Machine is stalled by Clip State Machines + GPUPE_PERF_PAPC_CLPRIM_STARVED_CCGSM = 84, // Number of clocks Clip Primitive Machine is starved by Clip Code Generator + GPUPE_PERF_PAPC_CLIPSM_IDLE = 85, // Number of clocks Clip State Machines are Idle + GPUPE_PERF_PAPC_CLIPSM_BUSY = 86, // Number of clocks Clip State Machines are Busy + GPUPE_PERF_PAPC_CLIPSM_WAIT_CLIP_VERT_ENGH = 87, // Number of clocks Clip State Mahcines are waiting for Clip Vert storage resources + GPUPE_PERF_PAPC_CLIPSM_WAIT_HIGH_PRI_SEQ = 88, // Number of clocks Clip State Machines are waiting for High Priority Sequencer + GPUPE_PERF_PAPC_CLIPSM_WAIT_CLIPGA = 89, // Number of clocks Clip State Machines are waiting for ClipGA + GPUPE_PERF_PAPC_CLIPSM_WAIT_AVAIL_VTE_CLIP = 90, // Number of clocks Clip State Machines are waiting for VTE cycles + GPUPE_PERF_PAPC_CLIPSM_WAIT_CLIP_OUTSM = 91, // Number of clocks Clip State Machines are waiting for Clip Output State Machine + GPUPE_PERF_PAPC_CLIPGA_IDLE = 92, // Number of clocks Clip Ga is Idle + GPUPE_PERF_PAPC_CLIPGA_BUSY = 93, // Number of clocks Clip Ga is Busy + GPUPE_PERF_PAPC_CLIPGA_STARVED_VTE_CLIP = 94, // Number of clocks Clip Ga is Starved by VTE or Clipper + GPUPE_PERF_PAPC_CLIPGA_STALLED = 95, // Number of clocks Clip Ga is stalled + GPUPE_PERF_PAPC_CLIP_IDLE = 96, // Number of clocks Clip is Idle + GPUPE_PERF_PAPC_CLIP_BUSY = 97, // Number of clocks Clip is Busy + GPUPE_PERF_PAPC_SU_IDLE = 98, // Number of clocks Setup is Idle + GPUPE_PERF_PAPC_SU_BUSY = 99, // Number of clocks Setup is Busy + GPUPE_PERF_PAPC_SU_STARVED_CLIP = 100, // Number of clocks Setup is starved by Clipper + GPUPE_PERF_PAPC_SU_STALLED_SC = 101, // Number of clocks Setup is stalled by SC +} GPUPERFEVENT_PA_SU; + +typedef enum +{ + GPUPE_SC_SR_WINDOW_VALID = 0, // Number of clocks event-window is valid at stage_reg + GPUPE_SC_CW_WINDOW_VALID = 1, // Number of clocks event-window is valid at coarse_walker + GPUPE_SC_QM_WINDOW_VALID = 2, // Number of clocks event-window is valid at quadmask + GPUPE_SC_QPP_WINDOW_VALID = 3, // Number of clocks event-window is valid at quad pair proc + GPUPE_SC_ITER_WINDOW_VALID = 4, // Number of clocks event-window is valid at iter + GPUPE_SC_STARVED_BY_PA = 5, // sc_rtr and not pa_rts and sc_busy + GPUPE_SC_STARVED_BY_RCC = 6, // sc_tile_fifo full, rcc z return fifo empty + GPUPE_SC_STALLED_BY_PRIM_FF = 7, // sc primitive fifo full is causing a stall + GPUPE_SC_STALLED_BY_RCC = 8, // sc_rts and not rcc_rtr + GPUPE_SC_STALLED_BY_BC = 9, // sc_rts and not bc_rtr + GPUPE_SC_STALLED_BY_SX = 10, // sc_rts and not (sx0_rtr and sx1_rtr) + GPUPE_SC_STALLED_BY_SX0 = 11, // sc_rts and not sx0_rtr + GPUPE_SC_STALLED_BY_SX1 = 12, // sc_rts and not sx1_rtr + GPUPE_SC_STALLED_BY_SQ = 13, // sc_sq count >= max + GPUPE_SC_STALLED_BY_SP = 14, // sc_sp count >= max + GPUPE_SC_WAIT_FOR_R1 = 15, // qpp has a single quad and is waiting for another tile for grouping + GPUPE_SC_SCISSOR_DISCARD = 16, // prim completely discarded by scissor + GPUPE_SC_BB_DISCARD = 17, // prim discarded by bounding-box check, no pixels hit + GPUPE_SC_SUPERT_PRIM_DISCARD = 18, // prim completely discarded by super_tile optimization + GPUPE_SC_RT_PRIM = 19, // real-time prim count + GPUPE_SC_TILE_VALID = 20, // tile count + GPUPE_SC_TILE_PER_PRIM_H0 = 21, // prims with < 2 tiles + GPUPE_SC_TILE_PER_PRIM_H1 = 22, // prims with < 4 tiles + GPUPE_SC_TILE_PER_PRIM_H2 = 23, // prims with < 8 tiles + GPUPE_SC_TILE_PER_PRIM_H3 = 24, // prims with < 16 tiles + GPUPE_SC_TILE_PER_PRIM_H4 = 25, // prims with < 32 tiles + GPUPE_SC_TILE_PER_PRIM_H5 = 26, // prims with < 64 tiles + GPUPE_SC_TILE_PER_PRIM_H6 = 27, // prims with < 128 tiles + GPUPE_SC_TILE_PER_PRIM_H7 = 28, // prims with < 256 tiles + GPUPE_SC_TILE_PER_PRIM_H8 = 29, // prims with < 512 tiles + GPUPE_SC_TILE_PER_PRIM_H9 = 30, // prims with < 1K tiles + GPUPE_SC_TILE_PER_PRIM_H10 = 31, // prims with < 2K tiles + GPUPE_SC_TILE_PER_PRIM_H11 = 32, // prims with < 4K tiles + GPUPE_SC_TILE_PER_PRIM_H12 = 33, // prims with < 8K tiles + GPUPE_SC_TILE_PER_PRIM_H13 = 34, // prims with < 16K tiles + GPUPE_SC_TILE_PER_PRIM_H14 = 35, // prims with < 32K tiles + GPUPE_SC_TILE_PER_PRIM_H15 = 36, // prims with < 64K tiles + GPUPE_SC_TILE_PER_PRIM_H16 = 37, // prims with < 1M tiles + GPUPE_SC_SUPERT_TILE_DISCARD = 38, // tiles discarded by super_tile optimization + GPUPE_SC_QM_NUM_QUADS = 39, // total quads hit by coarsewalk + GPUPE_SC_QM_MASK_H0 = 40, // tiles walked with 0 quads hit + GPUPE_SC_QM_MASK_H1 = 41, // tiles walked with 1 quads hit + GPUPE_SC_QM_MASK_H2 = 42, // tiles walked with 2 quads hit + GPUPE_SC_QM_MASK_H3 = 43, // tiles walked with 3 quads hit + GPUPE_SC_QM_MASK_H4 = 44, // tiles walked with 4 quads hit + GPUPE_SC_QM_MASK_H5 = 45, // tiles walked with 5 quads hit + GPUPE_SC_QM_MASK_H6 = 46, // tiles walked with 6 quads hit + GPUPE_SC_QM_MASK_H7 = 47, // tiles walked with 7 quads hit + GPUPE_SC_QM_MASK_H8 = 48, // tiles walked with 8 quads hit + GPUPE_SC_QM_MASK_H9 = 49, // tiles walked with 9 quads hit + GPUPE_SC_QM_MASK_H10 = 50, // tiles walked with 10 quads hit + GPUPE_SC_QM_MASK_H11 = 51, // tiles walked with 11 quads hit + GPUPE_SC_QM_MASK_H12 = 52, // tiles walked with 12 quads hit + GPUPE_SC_QM_MASK_H13 = 53, // tiles walked with 13 quads hit + GPUPE_SC_QM_MASK_H14 = 54, // tiles walked with 14 quads hit + GPUPE_SC_QM_MASK_H15 = 55, // tiles walked with 15 quads hit + GPUPE_SC_QM_MASK_H16 = 56, // tiles walked with 16 quads hit + GPUPE_SC_QM_COVERED_H0 = 57, // tiles walked with 0 quads covered + GPUPE_SC_QM_COVERED_H1 = 58, // tiles walked with 1 quads covered + GPUPE_SC_QM_COVERED_H2 = 59, // tiles walked with 2 quads covered + GPUPE_SC_QM_COVERED_H3 = 60, // tiles walked with 3 quads covered + GPUPE_SC_QM_COVERED_H4 = 61, // tiles walked with 4 quads covered + GPUPE_SC_QM_COVERED_H5 = 62, // tiles walked with 5 quads covered + GPUPE_SC_QM_COVERED_H6 = 63, // tiles walked with 6 quads covered + GPUPE_SC_QM_COVERED_H7 = 64, // tiles walked with 7 quads covered + GPUPE_SC_QM_COVERED_H8 = 65, // tiles walked with 8 quads covered + GPUPE_SC_QM_COVERED_H9 = 66, // tiles walked with 9 quads covered + GPUPE_SC_QM_COVERED_H10 = 67, // tiles walked with 10 quads covered + GPUPE_SC_QM_COVERED_H11 = 68, // tiles walked with 11 quads covered + GPUPE_SC_QM_COVERED_H12 = 69, // tiles walked with 12 quads covered + GPUPE_SC_QM_COVERED_H13 = 70, // tiles walked with 13 quads covered + GPUPE_SC_QM_COVERED_H14 = 71, // tiles walked with 14 quads covered + GPUPE_SC_QM_COVERED_H15 = 72, // tiles walked with 15 quads covered + GPUPE_SC_QM_COVERED_H16 = 73, // tiles walked with 16 quads covered + GPUPE_SC_HIER_NUM_QUADS = 74, // total quads surviving z + GPUPE_SC_HIER_MASK_H0 = 75, // tiles with 0 quads surviving z + GPUPE_SC_HIER_MASK_H1 = 76, // tiles with 1 quads surviving z + GPUPE_SC_HIER_MASK_H2 = 77, // tiles with 2 quads surviving z + GPUPE_SC_HIER_MASK_H3 = 78, // tiles with 3 quads surviving z + GPUPE_SC_HIER_MASK_H4 = 79, // tiles with 4 quads surviving z + GPUPE_SC_HIER_MASK_H5 = 80, // tiles with 5 quads surviving z + GPUPE_SC_HIER_MASK_H6 = 81, // tiles with 6 quads surviving z + GPUPE_SC_HIER_MASK_H7 = 82, // tiles with 7 quads surviving z + GPUPE_SC_HIER_MASK_H8 = 83, // tiles with 8 quads surviving z + GPUPE_SC_HIER_MASK_H9 = 84, // tiles with 9 quads surviving z + GPUPE_SC_HIER_MASK_H10 = 85, // tiles with 10 quads surviving z + GPUPE_SC_HIER_MASK_H11 = 86, // tiles with 11 quads surviving z + GPUPE_SC_HIER_MASK_H12 = 87, // tiles with 12 quads surviving z + GPUPE_SC_HIER_MASK_H13 = 88, // tiles with 13 quads surviving z + GPUPE_SC_HIER_MASK_H14 = 89, // tiles with 14 quads surviving z + GPUPE_SC_HIER_MASK_H15 = 90, // tiles with 15 quads surviving z + GPUPE_SC_HIER_MASK_H16 = 91, // tiles with 16 quads surviving z + GPUPE_SC_DET_NUM_QUADS = 92, // total quads surviving detail sampler + GPUPE_SC_PKR_QD_PER_ROW_H1 = 93, // packer row outputs with 1 valid quad + GPUPE_SC_PKR_QD_PER_ROW_H2 = 94, // packer row outputs with 2 valid quad + GPUPE_SC_PKR_QD_PER_ROW_H3 = 95, // packer row outputs with 3 valid quad + GPUPE_SC_PKR_QD_PER_ROW_H4 = 96, // packer row outputs with 4 valid quad + GPUPE_SC_PKR_END_OF_VECTOR = 97, // number of pixel vectors + GPUPE_SC_PKR_ONE_CLK = 98, // number of one clock commands + GPUPE_SC_QD_WITH_1_PIX = 99, // quads with 1 pixel surviving detail + GPUPE_SC_QD_WITH_2_PIX = 100, // quads with 2 pixels surviving detail + GPUPE_SC_QD_WITH_3_PIX = 101, // quads with 3 pixels surviving detail + GPUPE_SC_QD_WITH_4_PIX = 102, // quads with 4 pixels surviving detail + GPUPE_SC_SR_WINDOW_VALID_BUSY = 103, // Event-window is valid at stage_reg with sc busy + GPUPE_SC_CW_WINDOW_VALID_BUSY = 104, // Event-window is valid at coarse_walker with sc busy + GPUPE_SC_QM_WINDOW_VALID_BUSY = 105, // Event-window is valid at quadmask with sc busy + GPUPE_SC_QPP_WINDOW_VALID_BUSY = 106, // Event-window is valid at quad pair proc with sc busy + GPUPE_SC_ITER_WINDOW_VALID_BUSY = 107, // Event-window is valid at iter with sc busy +} GPUPERFEVENT_PA_SC; + +typedef enum +{ + GPUPE_WRC_1VAL_QUADS = 0, // Number of writes to hz_mem with 1 valid quad + GPUPE_WRC_2VAL_QUADS = 1, // Number of writes to hz_mem with 2 valid quads + GPUPE_WRC_3VAL_QUADS = 2, // Number of writes to hz_mem with 3 valid quads + GPUPE_WRC_4VAL_QUADS = 3, // Number of writes to hz_mem with 4 valid quads + GPUPE_HZ_WR_BUSY = 4, // Modules on the write-side of HZ memory are busy + GPUPE_HZ_SPARE0 = 5, // Reserved for HZ + GPUPE_RDC_TILE_HIT = 6, // Number of tile hits in the Read Cache + GPUPE_RDC_STAGE3_STALL = 7, // Number of conflicts/stalls in Read Stage 3 + GPUPE_HZ_SPARE1 = 8, // Reserved for HZ + GPUPE_HZ_SPARE2 = 9, // Reserved for HZ + GPUPE_QUADS_KEPT = 10, // Number of quads kept + GPUPE_QUADS_ZCULL = 11, // Number of quads culled due to Z only + GPUPE_QUADS_SCULL = 12, // Number of quads culled due to Stencil only + GPUPE_QUADS_SZCULL = 13, // Number of quads culled due to both Z and Stencil + GPUPE_HZ_RE_BUSY = 14, // Modules on the read-side of HZ memory are busy + GPUPE_BC_SCLK_COUNT = 15, // SCLK count for BC + GPUPE_BC_HZ_VALID0 = 16, // Valid input data from BC bus 0 + GPUPE_BC_HZ_VALID1 = 17, // Valid input data from BC bus 1 + GPUPE_BC_HZ_VALID2 = 18, // Valid input data from BC bus 2 + GPUPE_BC_HZ_VALID3 = 19, // Valid input data from BC bus 3 + GPUPE_SC_SCLK_COUNT = 20, // SCLK count for SC + GPUPE_SC_HZ_COARSE_SND = 21, // SC sending coarse Z data to HZ + GPUPE_HZ_SC_COARSE_HLD = 22, // HZ holding SC from sending coarse Z data + GPUPE_HZ_SC_HIER_SND = 23, // HZ sending mask data to BC + GPUPE_SC_HZ_HIER_HLD = 24, // SC holding HZ from sending mask data + GPUPE_HZ_BC_TILE_SND = 25, // HZ sending tile data to BC + GPUPE_BC_HZ_TILE_HLD = 26, // BC holding HZ from sending tile data + GPUPE_SC_STALL_HZ = 27, // HZ stalled by SC + GPUPE_BC_STALL_HZ = 28, // HZ stalled by BC + GPUPE_EVENT_STALL = 29, // HZ stalled by an Outstanding Event + GPUPE_SC_STARVE_HZ_BUSY = 30, // HZ starved by the SC when the HZ is busy + GPUPE_SC_STARVE_HZ_IDLE = 31, // HZ starved by the SC when the HZ is idle +} GPUPERFEVENT_HZ; + +typedef enum +{ + // IPMUX receives memory sent by MH + // It can stall if the dxt decompressor isn't ready. + GPUPE_DGMMPD_IPMUX0_STALL = 0, // Number of clocks ipmux0 is stalled. Each tick means 16 bytes of Texture BW lost. + GPUPE_DGMMPD_IPMUX1_STALL = 1, // Number of clocks ipmux1 is stalled. Each tick means 16 bytes of Texture BW lost. + GPUPE_DGMMPD_IPMUX2_STALL = 2, // always 0 + GPUPE_DGMMPD_IPMUX3_STALL = 3, // always 0 + GPUPE_DGMMPD_IPMUX_ALL_STALL = 4, // always 0 + + GPUPE_OPMUX0_L2_WRITES = 5, // Number of opmux0 L2 writes + GPUPE_OPMUX1_L2_WRITES = 6, // Number of opmux1 L2 writes + GPUPE_OPMUX2_L2_WRITES = 7, // Number of opmux2 L2 writes + GPUPE_OPMUX3_L2_WRITES = 8, // Number of opmux3 L2 writes +} GPUPERFEVENT_TCR; // Texture Cache Return + +typedef enum +{ + // TCO Read Latency Fifos (256-deep). + GPUPE_QUAD0_RD_LAT_FIFO_EMPTY = 0, // Number of clocks Quad0 read latency fifo is empty + GPUPE_QUAD0_RD_LAT_FIFO_16TH_FULL = 1, // Number of clocks Quad0 read latency fifo is at least 1/16th full, but less than 1/8th + GPUPE_QUAD0_RD_LAT_FIFO_8TH_FULL = 2, // Number of clocks Quad0 read latency fifo is at least 1/8th full, but less than 1/4th + GPUPE_QUAD0_RD_LAT_FIFO_4TH_FULL = 3, // Number of clocks Quad0 read latency fifo is at least 1/4th full, but less than half + GPUPE_QUAD0_RD_LAT_FIFO_HALF_FULL = 4, // Number of clocks Quad0 read latency fifo is at least half full, but not full + GPUPE_QUAD0_RD_LAT_FIFO_FULL = 5, // Number of clocks Quad0 read latency fifo is full + GPUPE_QUAD0_RD_LAT_FIFO_LT_16TH_FULL = 6, // Number of clocks Quad0 read latency fifo is less than 1/16th full, but not empty + GPUPE_QUAD1_RD_LAT_FIFO_EMPTY = 7, // Number of clocks Quad1 read latency fifo is empty + GPUPE_QUAD1_RD_LAT_FIFO_16TH_FULL = 8, // Number of clocks Quad1 read latency fifo is at least 1/16th full, but less than 1/8th + GPUPE_QUAD1_RD_LAT_FIFO_8TH_FULL = 9, // Number of clocks Quad1 read latency fifo is at least 1/8th full, but less than 1/4th + GPUPE_QUAD1_RD_LAT_FIFO_4TH_FULL = 10, // Number of clocks Quad1 read latency fifo is at least 1/4th full, but less than half + GPUPE_QUAD1_RD_LAT_FIFO_HALF_FULL = 11, // Number of clocks Quad1 read latency fifo is at least half full, but not full + GPUPE_QUAD1_RD_LAT_FIFO_FULL = 12, // Number of clocks Quad1 read latency fifo is full + GPUPE_QUAD1_RD_LAT_FIFO_LT_16TH_FULL = 13, // Number of clocks Quad1 read latency fifo is less than 1/16th full, but not empty + GPUPE_QUAD2_RD_LAT_FIFO_EMPTY = 14, // Number of clocks Quad2 read latency fifo is empty + GPUPE_QUAD2_RD_LAT_FIFO_16TH_FULL = 15, // Number of clocks Quad2 read latency fifo is at least 1/16th full, but less than 1/8th + GPUPE_QUAD2_RD_LAT_FIFO_8TH_FULL = 16, // Number of clocks Quad2 read latency fifo is at least 1/8th full, but less than 1/4th + GPUPE_QUAD2_RD_LAT_FIFO_4TH_FULL = 17, // Number of clocks Quad2 read latency fifo is at least 1/4th full, but less than half + GPUPE_QUAD2_RD_LAT_FIFO_HALF_FULL = 18, // Number of clocks Quad2 read latency fifo is at least half full, but not full + GPUPE_QUAD2_RD_LAT_FIFO_FULL = 19, // Number of clocks Quad2 read latency fifo is full + GPUPE_QUAD2_RD_LAT_FIFO_LT_16TH_FULL = 20, // Number of clocks Quad2 read latency fifo is less than 1/16th full, but not empty + GPUPE_QUAD3_RD_LAT_FIFO_EMPTY = 21, // Number of clocks Quad3 read latency fifo is empty + GPUPE_QUAD3_RD_LAT_FIFO_16TH_FULL = 22, // Number of clocks Quad3 read latency fifo is at least 1/16th full, but less than 1/8th + GPUPE_QUAD3_RD_LAT_FIFO_8TH_FULL = 23, // Number of clocks Quad3 read latency fifo is at least 1/8th full, but less than 1/4th + GPUPE_QUAD3_RD_LAT_FIFO_4TH_FULL = 24, // Number of clocks Quad3 read latency fifo is at least 1/4th full, but less than half + GPUPE_QUAD3_RD_LAT_FIFO_HALF_FULL = 25, // Number of clocks Quad3 read latency fifo is at least half full, but not full + GPUPE_QUAD3_RD_LAT_FIFO_FULL = 26, // Number of clocks Quad3 read latency fifo is full + GPUPE_QUAD3_RD_LAT_FIFO_LT_16TH_FULL = 27, // Number of clocks Quad3 read latency fifo is less than 1/16th full, but not empty + + GPUPE_READ_STARVED_QUAD0 = 28, // Number of clocks Quad0 is starved waiting for data from MC + GPUPE_READ_STARVED_QUAD1 = 29, // Number of clocks Quad1 is starved waiting for data from MC + GPUPE_READ_STARVED_QUAD2 = 30, // Number of clocks Quad2 is starved waiting for data from MC + GPUPE_READ_STARVED_QUAD3 = 31, // Number of clocks Quad3 is starved waiting for data from MC + GPUPE_READ_STARVED = 32, // Number of clocks any quad is starved waiting for data from MC + GPUPE_READ_STALLED_QUAD0 = 33, // Number of clocks Quad0 a read is stalled off by waiting for other quads to sync up + GPUPE_READ_STALLED_QUAD1 = 34, // Number of clocks Quad1 a read is stalled off by waiting for other quads to sync up + GPUPE_READ_STALLED_QUAD2 = 35, // Number of clocks Quad2 a read is stalled off by waiting for other quads to sync up + GPUPE_READ_STALLED_QUAD3 = 36, // Number of clocks Quad3 a read is stalled off by waiting for other quads to sync up + GPUPE_READ_STALLED = 37, // Number of clocks a read is stalled off by waiting for other quads to sync up + GPUPE_VALID_READ_QUAD0 = 38, // Valid cycles of cache reads on Quad0 + GPUPE_VALID_READ_QUAD1 = 39, // Valid cycles of cache reads on Quad1 + GPUPE_VALID_READ_QUAD2 = 40, // Valid cycles of cache reads on Quad2 + GPUPE_VALID_READ_QUAD3 = 41, // Valid cycles of cache reads on Quad3 + GPUPE_TC_TP_STARVED_QUAD0 = 42, // Quad0 is waiting for another quad to be valid before sending to TP + GPUPE_TC_TP_STARVED_QUAD1 = 43, // Quad1 is waiting for another quad to be valid before sending to TP + GPUPE_TC_TP_STARVED_QUAD2 = 44, // Quad2 is waiting for another quad to be valid before sending to TP + GPUPE_TC_TP_STARVED_QUAD3 = 45, // Quad3 is waiting for another quad to be valid before sending to TP + GPUPE_TC_TP_STARVED = 46, // Some data is ready for the TP, but stalled waiting for the rest +} GPUPERFEVENT_TCM; // Texture Cache Memory + + +typedef enum +{ + // TPC Walker counters. The Walker causes the TPs to loop, for mip levels, for aniso, + // and for volume slices, to generate all the addresses needed for all their samples. + + GPUPE_VALID_CYCLES = 0, // Cycles the TPC Walker is active. (Number of cycles the walker fifo is not empty, and the aligner fifo is not full.) + GPUPE_SINGLE_PHASES = 1, // cycles the walker is processing plain point/bilin fetches + GPUPE_ANISO_PHASES = 2, // aniso, mip aniso, vol aniso, mip vol aniso + GPUPE_MIP_PHASES = 3, // mip, mip aniso, mip vol, mip vol aniso + GPUPE_VOL_PHASES = 4, // vol, mip vol, vol aniso, mip vol aniso + GPUPE_MIP_VOL_PHASES = 5, // just mip vol + GPUPE_MIP_ANISO_PHASES = 6, // just mip aniso + GPUPE_VOL_ANISO_PHASES = 7, // just vol aniso + GPUPE_ANISO_2_1_PHASES = 8, // cycles spent on 2:1 aniso + GPUPE_ANISO_4_1_PHASES = 9, // cycles spent on 4:1 aniso + GPUPE_ANISO_6_1_PHASES = 10, // cycles spent on 6:1 aniso + GPUPE_ANISO_8_1_PHASES = 11, // cycles spent on 8:1 aniso + GPUPE_ANISO_10_1_PHASES = 12, // cycles spent on 10:1 aniso + GPUPE_ANISO_12_1_PHASES = 13, // cycles spent on 12:1 aniso + GPUPE_ANISO_14_1_PHASES = 14, // cycles spent on 14:1 aniso + GPUPE_ANISO_16_1_PHASES = 15, // cycles spent on 16:1 aniso + GPUPE_MIP_VOL_ANISO_PHASES = 16, // mip vol aniso + + // TPC Aligner counters: + + GPUPE_ALIGN_2_PHASES = 17, + GPUPE_ALIGN_4_PHASES = 18, + + // TPC counters. TPC communicates between the four TPs, and sends common data + // to the TC (mainly TCA). It is responsible for making the TPs talk with TC + // at the same time, even when their fetches break down into different + // numbers of samples, due to aniso/mip differences. + + GPUPE_TPC_BUSY = 19, + GPUPE_TPC_STALLED = 20, + GPUPE_TPC_STARVED = 21, + GPUPE_TPC_WORKING = 22, + GPUPE_TPC_WALKER_BUSY = 23, + GPUPE_TPC_WALKER_STALLED = 24, + GPUPE_TPC_WALKER_WORKING = 25, + GPUPE_TPC_ALIGNER_BUSY = 26, + GPUPE_TPC_ALIGNER_STALLED = 27, + GPUPE_TPC_ALIGNER_STALLED_BY_BLEND = 28, + GPUPE_TPC_ALIGNER_STALLED_BY_CACHE = 29, + GPUPE_TPC_ALIGNER_WORKING = 30, + GPUPE_TPC_BLEND_BUSY = 31, + GPUPE_TPC_BLEND_SYNC = 32, + GPUPE_TPC_BLEND_STARVED = 33, + GPUPE_TPC_BLEND_WORKING = 34, + + // TPC Opcode counters: Incremented once per instruction per 64-vector + + GPUPE_OPCODE_0X00 = 35, // num Vfetches with UseTextureCache=true + GPUPE_OPCODE_0X01 = 36, // num Tfetches executed + GPUPE_OPCODE_0X04 = 37, // unused, always 0 + GPUPE_OPCODE_0X10 = 38, // num getBCF ops executed + GPUPE_OPCODE_0X11 = 39, // num getCompTexLOD ops executed + GPUPE_OPCODE_0X12 = 40, // num GetGradients ops executed + GPUPE_OPCODE_0X13 = 41, // num getWeights ops executed + GPUPE_OPCODE_0X18 = 42, // num setTexLOD ops executed + GPUPE_OPCODE_0X19 = 43, // num setGradientsH ops executed + GPUPE_OPCODE_0X1A = 44, // num setGradientsV ops executed + GPUPE_OPCODE_OTHER = 45, // unused, always 0 + + // Always zero: + + GPUPE_RESERVED_46 = 46, + GPUPE_RESERVED_47 = 47, + GPUPE_RESERVED_48 = 48, + GPUPE_RESERVED_49 = 49, + GPUPE_RESERVED_50 = 50, + GPUPE_RESERVED_51 = 51, + GPUPE_RESERVED_52 = 52, + GPUPE_RESERVED_53 = 53, + GPUPE_RESERVED_54 = 54, + GPUPE_RESERVED_55 = 55, + + // TP/TPC -> TCA fifos. The TCA receives sample requests from TPC and the + // 4 TPs, and breaks apart requests which cannot be sent to the Memory + // Hub in one cycle. TCA is split into 4 quarters, one per TP. + // One fifo entry contains a quad's worth of samples. + + GPUPE_IN_FIFO_0_EMPTY = 56, + GPUPE_IN_FIFO_0_LT_HALF_FULL = 57, + GPUPE_IN_FIFO_0_HALF_FULL = 58, + GPUPE_IN_FIFO_0_FULL = 59, + GPUPE_IN_FIFO_1_EMPTY = 60, + GPUPE_IN_FIFO_1_LT_HALF_FULL = 61, + GPUPE_IN_FIFO_1_HALF_FULL = 62, + GPUPE_IN_FIFO_1_FULL = 63, + GPUPE_IN_FIFO_2_EMPTY = 64, + GPUPE_IN_FIFO_2_LT_HALF_FULL = 65, + GPUPE_IN_FIFO_2_HALF_FULL = 66, + GPUPE_IN_FIFO_2_FULL = 67, + GPUPE_IN_FIFO_3_EMPTY = 68, + GPUPE_IN_FIFO_3_LT_HALF_FULL = 69, + GPUPE_IN_FIFO_3_HALF_FULL = 70, + GPUPE_IN_FIFO_3_FULL = 71, + GPUPE_IN_FIFO_TPC_EMPTY = 72, + GPUPE_IN_FIFO_TPC_LT_HALF_FULL = 73, + GPUPE_IN_FIFO_TPC_HALF_FULL = 74, + GPUPE_IN_FIFO_TPC_FULL = 75, + + // Other TCA counters: + + GPUPE_TPC_TC_XFC = 76, // TPC_TC_rts + GPUPE_TPC_TC_STATE = 77, // tca_state_rts + GPUPE_TC_STALL = 78, // Num cycles any of the TP->TCA fifos was full + GPUPE_QUAD0_TAPS = 79, // u0TCA_PM_tap_valid_count + GPUPE_QUAD1_TAPS = 80, // u1TCA_PM_tap_valid_count + GPUPE_QUAD2_TAPS = 81, // u2TCA_PM_tap_valid_count + GPUPE_QUAD3_TAPS = 82, // u3TCA_PM_tap_valid_count + GPUPE_QUADS = 83, // tca_quad_valid_count + + GPUPE_TCA_SYNC_STALL = 84, // Num cycles that 1+ TP->TCA fifos had data ready, but (not all fifos had data ready, or, some but not all of the TCA Probe Filters stalled) + GPUPE_TAG_STALL = 85, // Number of probe-filter tag stalls (sum from all 4 Probe Filter units). + GPUPE_SLICE_STALL = 86, // Number of probe-filter slice stalls (sum from all 4 Probe Filter units). + GPUPE_SKEW_STALL = 87, // No probe filter is allowed to get > 3 cycles ahead of another. SKEW_STALL is number of stalls introduced to prevent this. (sum from all 4 Probe Filter units) + GPUPE_TCB_SYNC_STALL = 88, // Num cycles that 1+ TCA probe filters had data ready for TCB, but 1+ didn't have data ready. + + // TCB (Tag Compare Block) Core counters: + + GPUPE_TCA_VALID = 89, // num cycles TCA sent data to TCB + GPUPE_PROBES_VALID = 90, // num probes sent from TCA to TCB + + // MISS_STALL: Could be called the "cache thrash" counter: + // Number of cycles the TCB & TCA were stalled because a cache miss occurred, + // but no cache lines were free (meaning, all cache lines are allocated, waiting for + // MH to return data, or for TCO to finish reading all data out of the cache lines) + + GPUPE_MISS_STALL = 91, + GPUPE_FETCH_FIFO_STALL= 92, // num cycles the TCB Fetch Fifo was full. + GPUPE_TCO_STALL = 93, // num cycles TCO wasn't ready for TCB to send it data + GPUPE_ANY_STALL = 94, // = GPUPE_MISS_STALL + GPUPE_FETCH_FIFO_STALL + GPUPE_TCO_STALL + + // Tag Compare counters: + // Each tag is built from several samples entering the TCB at the same time. + // One tag is generated per cache line. + + GPUPE_TAG_MISSES = 95, // Requested cache line was not in the cache. + GPUPE_TAG_HITS = 96, // Requested Cache line was in the cache. + GPUPE_SUB_TAG_MISSES = 97, // (Subset of TAG_HITS): Line was in the cache, but at least some of the data wasn't. + + GPUPE_SET0_INVALIDATES = 98, + GPUPE_SET1_INVALIDATES = 99, + GPUPE_SET2_INVALIDATES = 100, + GPUPE_SET3_INVALIDATES = 101, + GPUPE_SET0_TAG_MISSES = 102, + GPUPE_SET1_TAG_MISSES = 103, + GPUPE_SET2_TAG_MISSES = 104, + GPUPE_SET3_TAG_MISSES = 105, + GPUPE_SET0_TAG_HITS = 106, + GPUPE_SET1_TAG_HITS = 107, + GPUPE_SET2_TAG_HITS = 108, + GPUPE_SET3_TAG_HITS = 109, + GPUPE_SET0_SUB_TAG_MISSES = 110, + GPUPE_SET1_SUB_TAG_MISSES = 111, + GPUPE_SET2_SUB_TAG_MISSES = 112, + GPUPE_SET3_SUB_TAG_MISSES = 113, + + GPUPE_SET0_EVICT1 = 114, + GPUPE_SET0_EVICT2 = 115, + GPUPE_SET0_EVICT3 = 116, + GPUPE_SET0_EVICT4 = 117, + GPUPE_SET0_EVICT5 = 118, + GPUPE_SET0_EVICT6 = 119, + GPUPE_SET0_EVICT7 = 120, + GPUPE_SET0_EVICT8 = 121, + GPUPE_SET0_EVICT9 = 122, + GPUPE_SET0_EVICT10 = 123, + GPUPE_SET0_EVICT11 = 124, + GPUPE_SET0_EVICT12 = 125, + GPUPE_SET0_EVICT13 = 126, + GPUPE_SET0_EVICT14 = 127, + GPUPE_SET0_EVICT15 = 128, + GPUPE_SET0_EVICT16 = 129, + GPUPE_SET1_EVICT1 = 130, + GPUPE_SET1_EVICT2 = 131, + GPUPE_SET1_EVICT3 = 132, + GPUPE_SET1_EVICT4 = 133, + GPUPE_SET1_EVICT5 = 134, + GPUPE_SET1_EVICT6 = 135, + GPUPE_SET1_EVICT7 = 136, + GPUPE_SET1_EVICT8 = 137, + GPUPE_SET1_EVICT9 = 138, + GPUPE_SET1_EVICT10 = 139, + GPUPE_SET1_EVICT11 = 140, + GPUPE_SET1_EVICT12 = 141, + GPUPE_SET1_EVICT13 = 142, + GPUPE_SET1_EVICT14 = 143, + GPUPE_SET1_EVICT15 = 144, + GPUPE_SET1_EVICT16 = 145, + GPUPE_SET2_EVICT1 = 146, + GPUPE_SET2_EVICT2 = 147, + GPUPE_SET2_EVICT3 = 148, + GPUPE_SET2_EVICT4 = 149, + GPUPE_SET2_EVICT5 = 150, + GPUPE_SET2_EVICT6 = 151, + GPUPE_SET2_EVICT7 = 152, + GPUPE_SET2_EVICT8 = 153, + GPUPE_SET2_EVICT9 = 154, + GPUPE_SET2_EVICT10 = 155, + GPUPE_SET2_EVICT11 = 156, + GPUPE_SET2_EVICT12 = 157, + GPUPE_SET2_EVICT13 = 158, + GPUPE_SET2_EVICT14 = 159, + GPUPE_SET2_EVICT15 = 160, + GPUPE_SET2_EVICT16 = 161, + GPUPE_SET3_EVICT1 = 162, + GPUPE_SET3_EVICT2 = 163, + GPUPE_SET3_EVICT3 = 164, + GPUPE_SET3_EVICT4 = 165, + GPUPE_SET3_EVICT5 = 166, + GPUPE_SET3_EVICT6 = 167, + GPUPE_SET3_EVICT7 = 168, + GPUPE_SET3_EVICT8 = 169, + GPUPE_SET3_EVICT9 = 170, + GPUPE_SET3_EVICT10 = 171, + GPUPE_SET3_EVICT11 = 172, + GPUPE_SET3_EVICT12 = 173, + GPUPE_SET3_EVICT13 = 174, + GPUPE_SET3_EVICT14 = 175, + GPUPE_SET3_EVICT15 = 176, + GPUPE_SET3_EVICT16 = 177, + + // TCB fetch fifo, 8-deep + + GPUPE_FF_EMPTY = 178, + GPUPE_FF_LT_HALF_FULL = 179, + GPUPE_FF_HALF_FULL = 180, + GPUPE_FF_FULL = 181, + + GPUPE_FF_XFC = 182, + GPUPE_FF_STALLED = 183, // TCB_PM_fetch_fifo_stalled + + // TCB fetch generator + + GPUPE_FG_MASKS = 184, + GPUPE_FG_LEFT_MASKS = 185, + GPUPE_FG_LEFT_MASK_STALLED = 186, + GPUPE_FG_LEFT_NOT_DONE_STALL = 187, + GPUPE_FG_LEFT_FG_STALL = 188, + GPUPE_FG_LEFT_SECTORS = 189, + GPUPE_FG_RIGHT_MASKS = 190, + GPUPE_FG_RIGHT_MASK_STALLED = 191, + GPUPE_FG_RIGHT_NOT_DONE_STALL = 192, + GPUPE_FG_RIGHT_FG_STALL = 193, + GPUPE_FG_RIGHT_SECTORS = 194, + GPUPE_FG0_REQUESTS = 195, + GPUPE_FG0_STALLED = 196, + GPUPE_FG1_REQUESTS = 197, + GPUPE_FG1_STALLED = 198, + + // TCB MH Interface + + GPUPE_MEM_REQ512 = 199, + GPUPE_MEM_REQ_SENT = 200, + GPUPE_MEM_AGP_READ_REQ = 201, + GPUPE_MEM_LOCAL_READ_REQ = 202, + GPUPE_TC0_MH_STALLED = 203, + GPUPE_TC1_MH_STALLED = 204, +} GPUPERFEVENT_TCF; // Texture Cache Fetch + +typedef enum +{ + GPUPE_POINT_QUADS = 0, // Any Point sampled quads (includes mip, aniso, volume) + GPUPE_BILIN_QUADS = 1, // Any Bilinearly filtered quads (includes mip, aniso, volume) + GPUPE_ANISO_QUADS = 2, // Any Aniso (>1:1) filtered quads (includes mip and/or vol) + GPUPE_MIP_QUADS = 3, // Any mip filtered quads (includes aniso and/or vol) + GPUPE_VOL_QUADS = 4, // Any volume filtered quads (include mip and/or aniso) + GPUPE_MIP_VOL_QUADS = 5, // Mip and volume filtered quads (not aniso) + GPUPE_MIP_ANISO_QUADS = 6, // Mip and aniso (>1:1) filtered quads (not vol) + GPUPE_VOL_ANISO_QUADS = 7, // Volume and aniso (>1:1) filtered quads (not mip) + GPUPE_ANISO_2_1_QUADS = 8, // Any quads with 2:1 anisotropic filtering + GPUPE_ANISO_4_1_QUADS = 9, // Any quads with 4:1 anisotropic filtering + GPUPE_ANISO_6_1_QUADS = 10, // Any quads with 6:1 anisotropic filtering + GPUPE_ANISO_8_1_QUADS = 11, // Any quads with 8:1 anisotropic filtering + GPUPE_ANISO_10_1_QUADS = 12, // Any quads with 10:1 anisotropic filtering + GPUPE_ANISO_12_1_QUADS = 13, // Any quads with 12:1 anisotropic filtering + GPUPE_ANISO_14_1_QUADS = 14, // Any quads with 14:1 anisotropic filtering + GPUPE_ANISO_16_1_QUADS = 15, // Any quads with 16:1 anisotropic filtering + GPUPE_MIP_VOL_ANISO_QUADS = 16, // Mip, volume and aniso (>1:1) filtered quads + GPUPE_ALIGN_2_QUADS = 17, // 2-cycle misaligned quads + GPUPE_ALIGN_4_QUADS = 18, // 4-cycle misaligned quads + GPUPE_PIX_0_QUAD = 19, // No valid pixels in quad + GPUPE_PIX_1_QUAD = 20, // 1 valid pixel in quad + GPUPE_PIX_2_QUAD = 21, // 2 valid pixels in quad + GPUPE_PIX_3_QUAD = 22, // 3 valid pixels in quad + GPUPE_PIX_4_QUAD = 23, // 4 valid pixels in quad + GPUPE_TP_MIPMAP_LOD0 = 24, // MipMap LOD 0 + GPUPE_TP_MIPMAP_LOD1 = 25, // MipMap LOD 1 + GPUPE_TP_MIPMAP_LOD2 = 26, // MipMap LOD 2 + GPUPE_TP_MIPMAP_LOD3 = 27, // MipMap LOD 3 + GPUPE_TP_MIPMAP_LOD4 = 28, // MipMap LOD 4 + GPUPE_TP_MIPMAP_LOD5 = 29, // MipMap LOD 5 + GPUPE_TP_MIPMAP_LOD6 = 30, // MipMap LOD 6 + GPUPE_TP_MIPMAP_LOD7 = 31, // MipMap LOD 7 + GPUPE_TP_MIPMAP_LOD8 = 32, // MipMap LOD 8 + GPUPE_TP_MIPMAP_LOD9 = 33, // MipMap LOD 9 + GPUPE_TP_MIPMAP_LOD10 = 34, // MipMap LOD 10 + GPUPE_TP_MIPMAP_LOD11 = 35, // MipMap LOD 11 + GPUPE_TP_MIPMAP_LOD12 = 36, // MipMap LOD 12 + GPUPE_TP_MIPMAP_LOD13 = 37, // MipMap LOD 13 + GPUPE_TP_MIPMAP_LOD14 = 38, // MipMap LOD 14 +} GPUPERFEVENT_TP; + +typedef enum +{ + GPUPE_SX_SC_QUADS = 0, // Number of quads sent by the SC + GPUPE_SX_SC_QUAD_FIFO_FULL = 1, // Number of cycles where the SC quad FIFO is full + GPUPE_SX_EXPORT_VECTORS = 2, // Number of exported vectors + GPUPE_SX_DUMMY_QUADS = 3, // Number of dummy quads + GPUPE_SX_ALPHA_FAIL = 4, // Number of pixels that fail alpha test + GPUPE_SX_RB_QUAD_BUSY = 5, // SX sending quads to the RBs + GPUPE_SX_RB_COLOR_BUSY = 6, // SX sending colors to the RBs + GPUPE_SX_RB_QUAD_STALL = 7, // SX idle on the quad interface + GPUPE_SX_RB_COLOR_STALL = 8, // SX idle on the color interface +} GPUPERFEVENT_SX; + +typedef enum +{ + GPUPE_BC_CNTX0_BUSY = 0, // Number of cycles BC is busy processing data(bc_context0_busy) + GPUPE_BC_CNTX17_BUSY = 1, // Number of cycles BC is busy processing data(bc_context17_busy) + GPUPE_BC_RQ_STALLED = 2, // Number of cycles BC is stalled due to no available banks for reorder queue to select + GPUPE_BC_AZ_STALLED = 3, // Number of cycles BC is stalled by AZ + GPUPE_BC_MH_CPY_STALLED = 4, // Number of cycles BC is stalled by MH for copy/resolve + GPUPE_BC_MH_EXP_STALLED = 5, // Number of cycles BC is stalled by MH for memory exports + GPUPE_BC_SC_STARVED = 6, // Number of cycles SC->BC quad fifo is empty and BC has a tile from HZ to work on + GPUPE_BC_SX_STARVED = 7, // Number of cycles SX->BC quad fifo is empty and we're in color mode and BC has a tile and quads from HZ and SC + GPUPE_BC_ACC_COUNT = 8, // Number of times multiple fragments are combined into a quad (acc opcodes) + GPUPE_BC_DRAW_COUNT = 9, // Number of quads sent to AZ (draw opcodes) + GPUPE_BC_ACC2_COUNT = 10, // Number of accumulate two opcodes for 64bpp and MRT's + GPUPE_BC_DRAW2_COUNT = 11, // Number of draw two opcodes for 64bpp and MRT's + GPUPE_BC_SETZ_COUNT = 12, // Number of depth exports + GPUPE_BC_READ_COUNT = 13, // Number of read opcodes when resolving + GPUPE_BC_READ_ACC_COUNT = 14, // Number of read_acc opcodes when resolving + GPUPE_BC_STATE_COUNT = 15, // Number of state opcodes sent to AZ + GPUPE_BC_STATE2_COUNT = 16, // Number of state2 opcodes sent to AZ + GPUPE_BC_COPY_WRITE_COUNT = 17, // Number of 256-bit system memory writes for EDRAM copy/resolve + GPUPE_BC_EXPORT_COUNT = 18, // Number of memory exports from SX +} GPUPERFEVENT_BC; + +typedef enum +{ + GPUPE_RANK_BANK0_ACCESSES = 0, // Rank Bank 0 access event + GPUPE_RANK_BANK1_ACCESSES = 1, // Rank Bank 1 access event + GPUPE_RANK_BANK2_ACCESSES = 2, // Rank Bank 2 access event + GPUPE_RANK_BANK3_ACCESSES = 3, // Rank Bank 3 access event + GPUPE_RANK_BANK4_ACCESSES = 4, // Rank Bank 4 access event + GPUPE_RANK_BANK5_ACCESSES = 5, // Rank Bank 5 access event + GPUPE_RANK_BANK6_ACCESSES = 6, // Rank Bank 6 access event + GPUPE_RANK_BANK7_ACCESSES = 7, // Rank Bank 7 access event + GPUPE_RANK_BANK8_ACCESSES = 8, // Rank Bank 8 access event + GPUPE_RANK_BANK9_ACCESSES = 9, // Rank Bank 9 access event + GPUPE_RANK_BANK10_ACCESSES = 10, // Rank Bank 10 access event + GPUPE_RANK_BANK11_ACCESSES = 11, // Rank Bank 11 access event + GPUPE_RANK_BANK12_ACCESSES = 12, // Rank Bank 12 access event + GPUPE_RANK_BANK13_ACCESSES = 13, // Rank Bank 13 access event + GPUPE_RANK_BANK14_ACCESSES = 14, // Rank Bank 14 access event + GPUPE_RANK_BANK15_ACCESSES = 15, // Rank Bank 15 access event + GPUPE_READ_2_WRITE = 16, // Read to Write transition event + GPUPE_WRITE_2_READ = 17, // Write to Read transition event + GPUPE_NEW_PAGE_ACCESSES = 18, // Number of new page accesses out of the ordering engine + GPUPE_TOTAL_ACCESSES = 19, // Total accesses out of the ordering engine + GPUPE_READ_ACCESSES = 20, // Number of reads out of the ordering engine + GPUPE_ACCESS_PRESENT_NO_ISSUE_CLKS = 21, // Number of clocks in which an access is present but ordering engine doesn't issue + GPUPE_CMD_PRESENT_NO_XFER_CLKS = 22, // Number of non-transfer clocks on DRAM data bus when commands are present + GPUPE_URGENT_DC_ACCESSES = 23, // Number of urgent accesses from DC queue + GPUPE_URGENT_SB_ACCESSES = 24, // Number of urgent accesses from SB queue + GPUPE_URGENT_BIU_ACCESSES = 25, // Number of urgent accesses from BIUS (slow) queue + GPUPE_NEW_BIUF_ACCESSES = 26, // Number of new accesses from BIUF (fast) queue + GPUPE_NEW_CP_ACCESSES = 27, // Number of new accesses from CP queue + GPUPE_NEW_TC_ACCESSES = 28, // Number of new accesses from TC queue + GPUPE_NEW_VC_ACCESSES = 29, // Number of new accesses from VC queue + GPUPE_NEW_BC_CP_ACCESSES = 30, // Number of new accesses from BC_CP queue + GPUPE_NEW_BC_EX_ACCESSES = 31, // Number of new accesses from BC_EX queue + GPUPE_NEW_VGT_ACCESSES = 32, // Number of new accesses from VGT queue + GPUPE_NEW_DC_ACCESSES = 33, // Number of new accesses from DC queue + GPUPE_NEW_SB_ACCESSES = 34, // Number of new accesses from SB queue + GPUPE_NEW_BIUS_ACCESSES = 35, // Number of new accesses from BIUS (slow) queue + GPUPE_BIUS_READ_ACCESSES = 36, // Number of Read accesses from BIUS (slow) queue + GPUPE_SB_READ_ACCESSES = 37, // Number of Read accesses from SB queue + GPUPE_CP_READ_ACCESSES = 38, // Number of Read accesses from CP queue + + // For the following counters, when writing GPUPERFREG_MC*_PERFCOUNTER0_SELECT, + // "N" is the 2nd lowest byte written to the _SELECT register. For instance, + // to read MC0's GPUPE_NTH_SMPG_ACCESS_IS_TC counter with N=1, + // use GPUPE_NTH_SMPG_ACCESS_IS_TC | (0x01 << 8)) for GPUPERFREG_MC0_PERFCOUNTER0_SELECT's selection + + GPUPE_NTH_SMPG_ACCESS_IS_BIUF = 39, // Number of times the Nth access in a same page sequence is from BIUF (fast) queue + GPUPE_NTH_SMPG_ACCESS_IS_CP = 40, // Number of times the Nth access in a same page sequence is from CP queue + GPUPE_NTH_SMPG_ACCESS_IS_TC = 41, // Number of times the Nth access in a same page sequence is from TC queue + GPUPE_NTH_SMPG_ACCESS_IS_VC = 42, // Number of times the Nth access in a same page sequence is from VC queue + GPUPE_NTH_SMPG_ACCESS_IS_BC_CP = 43, // Number of times the Nth access in a same page sequence is from BC_CP queue + GPUPE_NTH_SMPG_ACCESS_IS_BC_EX = 44, // Number of times the Nth access in a same page sequence is from BC_EX queue + GPUPE_NTH_SMPG_ACCESS_IS_VGT = 45, // Number of times the Nth access in a same page sequence is from VGT queue + GPUPE_NTH_SMPG_ACCESS_IS_DC = 46, // Number of times the Nth access in a same page sequence is from DC queue + GPUPE_NTH_SMPG_ACCESS_IS_SB = 47, // Number of times the Nth access in a same page sequence is from SB queue + GPUPE_NTH_SMPG_ACCESS_IS_BIUS = 48, // Number of times the Nth access in a same page sequence is from BIUS (slow) queue + GPUPE_N_VALID_ENTRY_IN_TEXTURE_CAM_CLKS = 49, // Number of clocks where there are N valid entries in the texture cam + GPUPE_N_VALID_ENTRY_IN_VC_CAM_CLKS = 50, // Number of clocks where there are N valid entries in the VC cam + GPUPE_N_VALID_ENTRY_IN_BIUS_CAM_CLKS = 51, // Number of clocks where there are N valid entries in the BIUS cam + GPUPE_N_SB_BUF_USED_CLKS = 52, // Number of clocks when q_rdbuf_sb_buffers_used = N + GPUPE_N_TC_BUF_USED_CLKS = 53, // Number of clocks when q_rdbuf_tc_buffers_used = N + GPUPE_N_VC_BUF_USED_CLKS = 54, // Number of clocks when q_rdbuf_vc_buffers_used = N + GPUPE_N_DC_BUF_USED_CLKS = 55, // Number of clocks when q_rdbuf_dc_buffers_used = N + GPUPE_N_VGT_BUF_USED_CLK = 56, // Number of clocks when q_rdbuf_vgt_buffers_used = N + GPUPE_N_CP_BUF_USED_CLKS = 57, // Number of clocks when q_rdbuf_cp_buffers_used = N +} GPUPERFEVENT_MC; + +typedef enum +{ + GPUPE_CP_READ_MEMORY = 0, // counts cp read requests that maps to the main memory aperture + GPUPE_CP_READ_PGLB = 1, // counts cp read requests that maps to the pg line buffer aperture + GPUPE_CP_WRITE_MEMORY = 2, // counts cp write requests that maps to the main memory aperture + GPUPE_CP_WRITE_SNOOPED = 3, // counts cp write requests that is marked as snooped + GPUPE_CP_WRITE_WRITEBACK = 4, // counts cp write requests that maps to the writeback aperture + GPUPE_MH_CP_RTR = 5, // rtr from mh to cp, counts cycles where it is asserted - able to accept requests + GPUPE_VGT_READ_MEMORY = 6, // counts vgt read requests that maps to the main memory aperture + GPUPE_VGT_READ_PGLB = 7, // counts vgt read requests that maps to the pg line buffer aperture + GPUPE_MH_VGT_RTR = 8, // rtr from mh to vgt, counts cycles where it is asserted - able to accept requests + GPUPE_IOC_READ = 9, // counts ioc read requests + GPUPE_IOC_WRITE = 10, // counts ioc write requests + GPUPE_IOC_READ_BYTE_COUNT = 11, // counts the number of bytes in ioc read requests + GPUPE_IOC_WRITE_BYTE_COUNT = 12,// counts the number of bytes in ioc writes requests + GPUPE_IOC_URGENT = 13, // counts clock cycles that ioc asserts urgent + GPUPE_MH_IOC_RTR = 14, // counts clock cycles where the mh is ready to recieve requests from the ioc + GPUPE_TC0_READ = 15, // counts read requests + GPUPE_MH_TC0_RTR = 16, // counts cycles where mh is ready + GPUPE_TC1_READ = 17, // counts read requests + GPUPE_MH_TC1_RTR = 18, // counts cycles where mh is ready + GPUPE_VC0_READ_MEMORY = 19, // counts read requests to memory + GPUPE_VC0_READ_PGLB = 20, // counts read requests to pglb + GPUPE_MH_VC0_RTR = 21, // counts cycles where mh is ready + GPUPE_VC1_READ_MEMORY = 22, // counts read requests to memory + GPUPE_VC1_READ_PGLB = 23, // counts read requests to pglb + GPUPE_MH_VC1_RTR = 24, // counts cycles where mh is ready + GPUPE_BC0_CP_WRITE = 25, // counts copy write requests + GPUPE_BC0_EX_WRITE = 26, // counts export write requests + GPUPE_MH_BC0_RTR = 27, // + GPUPE_BC1_CP_WRITE = 28, // counts copy write requests + GPUPE_BC1_EX_WRITE = 29, // counts export write requests + GPUPE_MH_BC1_RTR = 30, // + GPUPE_DC_GRAPHICS_REQ = 31, // counts graphics read requests + GPUPE_DC_OVERLAY_REQ = 32, // counts overlay read requests + GPUPE_DC_URGENT = 33, // counts cycles urgent is asserted + GPUPE_PGLB_BIU_REQ = 34, // counts requests from the pglb to the biu + GPUPE_BIU_PGL_READ_DATA = 35, // counts cycles where read data is transfered from biu to pglb + GPUPE_PGL_MHS_READ_DATA = 36, // pglb to mh switch data transfer cycles + GPUPE_MH_MC0_READ_REQS = 37, // counts number of read request sent to mc0 + GPUPE_MH_MC0_WRITE_REQS = 38, // counts number of write requests sent to mc0 + GPUPE_MH_MC1_READ_REQS = 39, // counts number of read request sent to mc1 + GPUPE_MH_MC1_WRITE_REQS = 40, // counts number of write requests sent to mc1 + GPUPE_MC0_MH_READ_DATA = 41, // counts bytes returned to mh in increments of 32bytes from mc0 + GPUPE_MC1_MH_READ_DATA = 42, // counts bytes returned to mh in increments of 32bytes from mc1 + GPUPE_MH_CP_SEND = 43, // counts bytes returned to cp in increments of 4 bytes + GPUPE_MH_VGT_SEND = 44, // counts bytes returned to vgt in increments of 16 bytes + GPUPE_MH_IOC_SEND = 45, // counts bytes returned to ioc in increments of 4 bytes + GPUPE_MH_TC0_SEND = 46, // counts bytes returned to tc0 in increments of 16 bytes + GPUPE_MH_TC1_SEND = 47, // counts bytes returned to tc1 in increments of 16 bytes + GPUPE_MH_VC0_SEND = 48, // counts bytes returned to vc0 in increments of 16 bytes + GPUPE_MH_VC1_SEND = 49, // counts bytes returned to vc1 in increments of 16 bytes + GPUPE_MH_DC_SEND = 50, // counts bytes returned to dc in increments of 16 bytes + GPUPE_DC0_INFLIGHT_FULL = 51, // counts cycles where the inflight (or outstanding read request) queue was full + GPUPE_DC1_INFLIGHT_FULL = 52, // + GPUPE_VC0_INFLIGHT_FULL = 53, // + GPUPE_VC1_INFLIGHT_FULL = 54, // + GPUPE_TC0_INFLIGHT_FULL = 55, // + GPUPE_TC1_INFLIGHT_FULL = 56, // + GPUPE_CP0_INFLIGHT_FULL = 57, // + GPUPE_CP1_INFLIGHT_FULL = 58, // + GPUPE_VGT0_INFLIGHT_FULL = 59, // + GPUPE_VGT1_INFLIGHT_FULL = 60, // + GPUPE_SB0_INFLIGHT_FULL = 61, // + GPUPE_SB1_INFLIGHT_FULL = 62, // + GPUPE_VCPGL_INFLIGHT_FULL = 63, // + GPUPE_CPPGL_INFLIGHT_FULL = 64, // + GPUPE_VGTPGL_INFLIGHT_FULL = 65,// + GPUPE_MC0_DC_Q_FULL = 66, // counts cycles where the request queue in the mc was full + GPUPE_MC0_VC_Q_FULL = 67, // + GPUPE_MC0_TC_Q_FULL = 68, // + GPUPE_MC0_CP_Q_FULL = 69, // + GPUPE_MC0_SB_Q_FULL = 70, // + GPUPE_MC0_VGT_Q_FULL = 71, // + GPUPE_MC0_BCCP_Q_FULL = 72, // + GPUPE_MC0_BCEX_Q_FULL = 73, // + GPUPE_MC1_DC_Q_FULL = 74, // + GPUPE_MC1_VC_Q_FULL = 75, // + GPUPE_MC1_TC_Q_FULL = 76, // + GPUPE_MC1_CP_Q_FULL = 77, // + GPUPE_MC1_SB_Q_FULL = 78, // + GPUPE_MC1_VGT_Q_FULL = 79, // + GPUPE_MC1_BCCP_Q_FULL = 80, // + GPUPE_MC1_BCEX_Q_FULL = 81, // + GPUPE_CP_PGL_CACHE_HIT = 82, // counts pg line buffer cache hits + GPUPE_VGT_PGL_CACHE_HIT = 83, // + GPUPE_VC_PGL_CACHE_HIT = 84, // + GPUPE_CP_PGL_FULL = 85, // analagous to the request queue in the mc`s - for pg reads + GPUPE_VGT_PGL_FULL = 86, // + GPUPE_VC0_PGL_FULL = 87, // + GPUPE_VC1_PGL_FULL = 88, // + GPUPE_MC0_WDB_FULL = 89, // counts cycles where the write data buffer for mc0 was full + GPUPE_MC0_TAGBUF_FULL = 90, // counts cycles where the tag buffer for mc0 was full + GPUPE_MC1_WDB_FULL = 91, // + GPUPE_MC1_TAGBUF_FULL = 92, // + GPUPE_PGL_TAGBUF_FULL = 93, // counts cycles where the tag buffer for pgl was full + GPUPE_CP_WRITENOTIFY = 94, // counts write clean indications sent back to cp + GPUPE_BC_WRITENOTIFY = 95, // counts write cleans sent back to bc + GPUPE_IOC_SYNC = 96, // counts write cleans sent back to ioc + + // Latency counts increment by the number of pending requests of that type. + // (Their derivative is incremented when a request is sent and decremented + // when the data is actually retrieved). + // Divide the counter by the number of requests of the specified type in order to + // get the average latency. + + // The MH PGL latency counters can only be accessed through GPUPERFREG_MH_PERFCOUNTER2_SELECT + + GPUPE_PGL_BIU_LATENCY = 97, + + // The MH MC0 counters can only be accessed using GPUPERFREG_MH_PERFCOUNTER0_SELECT + + GPUPE_MH_MC0_LATENCY = 98, // + GPUPE_MH_MC0_DC_LATENCY = 99, // + GPUPE_MH_MC0_VC_LATENCY = 100, // + GPUPE_MH_MC0_TC_LATENCY = 101, // + GPUPE_MH_MC0_CP_LATENCY = 102, // + GPUPE_MH_MC0_SB_LATENCY = 103, // + GPUPE_MH_MC0_VGT_LATENCY = 104, // + + // The MH_MC1 counters can only be accessed using GPUPERFREG_MH_PERFCOUNTER1_SELECT + + GPUPE_MH_MC1_LATENCY = 105, // + GPUPE_MH_MC1_DC_LATENCY = 106, // + GPUPE_MH_MC1_VC_LATENCY = 107, // + GPUPE_MH_MC1_TC_LATENCY = 108, // + GPUPE_MH_MC1_CP_LATENCY = 109, // + GPUPE_MH_MC1_SB_LATENCY = 110, // + GPUPE_MH_MC1_VGT_LATENCY = 111, // + + // The MH PGL latency counters can only be accessed through GPUPERFREG_MH_PERFCOUNTER2_SELECT + + GPUPE_MH_PGL_LATENCY = 112, // + GPUPE_MH_PGL_CP_LATENCY = 113, // + GPUPE_MH_PGL_VC_LATENCY = 114, // + GPUPE_MH_PGL_VGT_LATENCY = 115, // + + GPUPE_TC0_RDY_AND_NOROOM = 116, // counts cycles where there was read data available to send to tc0 and there wasn`t room in tc0 to accept it + GPUPE_TC1_RDY_AND_NOROOM = 117, // + GPUPE_IOC_RDY_AND_NOROOM = 118, // +} GPUPERFEVENT_MH; + +typedef enum +{ + GPUPE_0 = 0, // Always Count + GPUPE_1 = 1, // RBBM_IF Fifo Full + GPUPE_2 = 2, // MIOC Fifo Full + GPUPE_3 = 3, // MIOC has a transaction, and is waiting for the RBBM to be ready + GPUPE_4 = 4, // SIOC Fifo Full + GPUPE_5 = 5, // SIOC has a transaction, and is waiting for the IOC to be ready +} GPUPERFEVENT_BIF; + +typedef enum +{ + GPUPE_DMIF_PER_DCREQ_EVENT = 0, + GPUPE_DMIF_PER_DCGRPH_REQ_EVENT = 1, + GPUPE_DMIF_PER_DCOVL_REQ_EVENT = 2, + GPUPE_DMIF_PER_DCREQ_SIZE_EVENT = 3, + GPUPE_DMIF_PER_DCGRPH_REQ_SIZE_EVENT = 4, + GPUPE_DMIF_PER_DCOVL_REQ_SIZE_EVENT = 5, + GPUPE_DMIF_PER_DCSURFACE_UPDATE_EVENT = 6, + GPUPE_DMIF_PER_DC_MH_REQ_EVENT = 7, + GPUPE_DMIF_PER_DC_MH_D1GRPH_REQ_EVENT = 8, + GPUPE_DMIF_PER_DC_MH_D1OVL_REQ_EVENT = 9, + GPUPE_DMIF_PER_DC_MH_REQ_SIZE_EVENT = 10, + GPUPE_DMIF_PER_DC_MH_D1GRPH_REQ_SIZE_EVENT = 11, + GPUPE_DMIF_PER_DC_MH_D1OVL_REQ_SIZE_EVENT = 12, + GPUPE_DMIF_PER_DC_MH_SURFACE_UPDATE_EVENT = 13, + GPUPE_DMIF_PER_MH_DC_RTR_EVENT = 14, + GPUPE_DMIF_PER_CMD_PROC_WAIT_RTR_STATE_EVENT = 15, + GPUPE_DMIF_PER_CMD_PROC_IDLE_STATE_EVENT = 16, + GPUPE_DMIF_PER_DC_MH_URGENT_EVENT = 17, + GPUPE_DMIF_PER_MH_DC_SEND_EVENT = 18, + GPUPE_DMIF_PER_MH_DC_SEND_D1GRPH_EVENT = 19, + GPUPE_DMIF_PER_MH_DC_SEND_D1OVL_EVENT = 20, + GPUPE_DMIF_PER_DC_MH_RTR_EVENT = 21, + GPUPE_DMIF_PER_DMIF_BUSY_EVENT = 22, + GPUPE_DMIF_PER_DMIF_BUSY_MH_DC_SEND_EVENT = 23, + GPUPE_DMIF_PER_DMIF_BUSY_DC_MH_RTR_EVENT = 24, + GPUPE_DMIF_PER_DMIF_DCSEND_EVENT = 25, + GPUPE_DMIF_PER_DMIF_DCNOT_RTS_EVENT = 26, + GPUPE_DMIF_PER_DCDMIF_NOT_RTR_EVENT = 27, + GPUPE_DCP_PER_LUT_HOST_RW_EVENT = 28, + GPUPE_DCP_PER_LUT_RW_BY_HOST_EVENT = 29, + GPUPE_DCP_PER_RTR_LOW_BY_LUT_HOST_RW_EVENT = 30, + GPUPE_DCCG_PER_SCLK_R_RBBMIF_CLOCK_ON_EVENT = 31, + GPUPE_DCCG_PER_SCLK_R_DISCLOCK_ON_EVENT = 32, + GPUPE_DCCG_PER_SCLK_G_SCL_CLOCK_ON_EVENT = 33, + GPUPE_DCCG_PER_SCLK_G_DCCLOCK_ON_EVENT = 34, + GPUPE_DCCG_PER_PCLK_CRTC_CLOCK_ON_EVENT = 35, + GPUPE_DCCG_PER_DVOACLK_C_CLOCK_ON_EVENT = 36, + GPUPE_DCCG_PER_DVOACLK_D_CLOCK_ON_EVENT = 37, + GPUPE_CRTC1_PER_START_LINE_EVENT = 38, + GPUPE_CRTC1_PER_HSYNC_A_EVENT = 39, + GPUPE_CRTC1_PER_VSYNC_A_EVENT = 40, + GPUPE_CRTC1_PER_H_DATA_ACTIVE_EVENT = 41, + GPUPE_CRTC1_PER_V_DATA_ACTIVE_EVENT = 42, + GPUPE_CRTC1_PER_DATA_ACTIVE_EVENT = 43, + GPUPE_CRTC1_PER_H_BLANK_EVENT = 44, + GPUPE_CRTC1_PER_V_BLANK_EVENT = 45, + GPUPE_CRTC1_PER_BLANK_EVENT = 46, + GPUPE_CRTC1_PER_INTERLACE_SELECT_EVENT = 47, + GPUPE_CRTC1_PER_STEREO_SELECT_EVENT = 48, + GPUPE_SCL1_PER_HOST_CONFLICT_EVENT = 49, + GPUPE_SCL1_PER_ADVANCE_FILTER_POS_EVENT = 50, + GPUPE_SCL1_PER_TAINC_EVENT = 51, + GPUPE_SCL1_PER_REQUEST_EOL_EVENT = 52, + GPUPE_SCL1_PER_V_COEF_PRELOAD_EVENT = 53, + GPUPE_SCL1_PER_EOL_EVENT = 54, + GPUPE_SCL1_PER_SOF_EVENT = 55, + GPUPE_LB_PER_DISP1_RESET_REQ_EVENT = 56, + GPUPE_LB_PER_DISP1_REQ_SEND_EVENT = 57, + GPUPE_LB_PER_DISP1_REQ_UNDERFLOW_EVENT = 58, + GPUPE_LB_PER_DISP1_DATA_UNDERFLOW_EVENT = 59, + GPUPE_LB_PER_DISP1_URGENT_EVENT = 60, + GPUPE_LB_PER_DISP1_VBLANK_STAT_EVENT = 61, + GPUPE_LB_PER_DISP1_VLINE_STAT_EVENT = 62, + GPUPE_DOUT_PER_SCL_DISP1_MODE_CHANGE_INTERRUPT_EVENT = 63, + GPUPE_DOUT_PER_LB_D1_VLINE_INTERRUPT_EVENT = 64, + GPUPE_DOUT_PER_LB_D1_VBLANK_INTERRUPT_EVENT = 65, + GPUPE_DOUT_PER_DISTIMER_INTERRUPT_EVENT = 66, + GPUPE_LOGIC1_EVENT = 256, +} DCPERFEVENT; + +typedef enum +{ + BIUPE_RECV_REQUESTS = 0, + BIUPE_RECV_RESPONSES = 1, // (pg data only), + BIUPE_IOC_READS = 2, + BIUPE_IOC_WRITES = 3, + BIUPE_MEM_READS = 4, + BIUPE_MEM_WRITES = 5, + BIUPE_FSB_SYNCS = 6, + BIUPE_EIEIOS = 7, + BIUPE_EOIS = 8, + BIUPE_FLUSH_ACKS = 9, + BIUPE_REQUEST_READ_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 10, + BIUPE_REQUEST_READ_DATA_BYTES_16_BYTE_AND_MORE_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 11, + BIUPE_REQUEST_WRITE_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 12, + BIUPE_REQUEST_WRITE_DATA_BYTES_16_BYTE_AND_MORE_TRANSFER_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 13, + BIUPE_RESERVED0 = 14, + BIUPE_XMIT_REQUESTS = 15, + BIUPE_XMIT_RESPONSES = 16, + BIUPE_READ128S = 17, + BIUPE_FLUSH_REQ_READS = 18, + BIUPE_FLUSH_REQ_WRITES = 19, + BIUPE_CPUWB = 20, + BIUPE_INTERRUPTS = 21, + BIUPE_RESPONSES_MC0 = 22, + BIUPE_RESPONSES_MC1 = 23, + BIUPE_RESPONSES_IOC_MST = 24, + BIUPE_MC0_RESPONSE_READ_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 25, + BIUPE_MC0_RESPONSE_READ_DATA_BYTES_16_BYTE_AND_MORE_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 26, + BIUPE_MC1_RESPONSE_READ_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 27, + BIUPE_MC1_RESPONSE_READ_DATA_BYTES_16_BYTE_AND_MORE_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 28, + BIUPE_IOC_MST_RESPONSE_READ_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 29, + BIUPE_IOC_MST_RESPONSE_READ_DATA_BYTES_16_BYTE_AND_MORE_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 30, + BIUPE_RESERVED1A = 31, + BIUPE_RESERVED2A = 32, + BIUPE_RESERVED3A = 33, + BIUPE_RESERVED4A = 34, + BIUPE_RESERVED5A = 35, + BIUPE_RESERVED6A = 36, + BIUPE_RESERVED7A = 37, + BIUPE_RESERVED8A = 38, + BIUPE_RESERVED9A = 39, + BIUPE_REQUESTS = 40, + BIUPE_IOC_MAST_READS = 41, + BIUPE_IOC_MAST_WRITES = 42, + BIUPE_IOC_MAST_EOIS = 43, + BIUPE_IOC_MAST_REQUEST_READ_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 44, + BIUPE_IOC_MAST_REQUEST_READ_DATA_BYTES_16_BYTE_AND_MORE_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 45, + BIUPE_IOC_MAST_REQUEST_WRITE_DATA_BYTES_8_BYTE_AND_LESS_TRANSFERS_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 46, + BIUPE_IOC_MAST_REQUEST_WRITE_DATA_BYTES_16_BYTE_AND_MORE_TRANSFER_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER = 47, + BIUPE_RESERVED10 = 48, + BIUPE_RESERVED11 = 49, + BIUPE_IOC_SLV_REQUESTS = 50, + BIUPE_IOC_SLV_SNOOP_READS = 51, + BIUPE_IOC_SLV_SNOOP_WRITES = 52, + BIUPE_IOC_SLV_INTERRUPTS = 53, + BIUPE_IOC_SLV_SYNCS = 54, + BIUPE_IOC_SLV_SNOOP_READS_NS = 55, + BIUPE_IOC_SLV_SNOOP_WRITES_NS = 56, + BIUPE_IOC_SLV_CPUWBS = 57, + BIUPE_IOC_SLV_REQUEST_READ_DATA_BYTES_DIVIDED_BY_4_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 58, + BIUPE_IOC_SLV_REQUEST_WRITE_DATA_BYTES_DIVIDED_BY_4_DEPENDENT_ON_SECONDARY_CONTROL_REGISTER_ = 59, + BIUPE_IOC_SLV_RESPONSES_BEATS_ = 60, + BIUPE_IOC_SLV_RESP_READ_DATA_BYTES_DIVIDED_BY_4_ = 61, + BIUPE_IOC_SLV_SYNCCLEANS = 62, + BIUPE_RESERVED12 = 63, + BIUPE_RESERVED13 = 64, + BIUPE_RESERVED14 = 65, + BIUPE_RESERVED15 = 66, + BIUPE_RESERVED16 = 67, + BIUPE_RESERVED17 = 68, + BIUPE_RESERVED18 = 69, + BIUPE_MC_0_FAST_PATH_CPU_READS = 70, + BIUPE_MC_0_ORDERED_CPU_PATH_READS = 71, + BIUPE_MC_0_ORDERED_CPU_PATH_WRITES = 72, + BIUPE_MC_0_ORDERED_IOC_PATH_READS = 73, + BIUPE_MC_0_ORDERED_IOC_PATH_WRITES = 74, + BIUPE_MC_0_SYNC_A = 75, + BIUPE_MC_0_SYNC_B = 76, + BIUPE_RESERVED19 = 77, + BIUPE_RESERVED20 = 78, + BIUPE_RESERVED21 = 79, + BIUPE_MC_1_FAST_PATH_CPU_READS = 80, + BIUPE_MC_1_ORDERED_CPU_PATH_READS = 81, + BIUPE_MC_1_ORDERED_CPU_PATH_WRITES = 82, + BIUPE_MC_1_ORDERED_IOC_PATH_READS = 83, + BIUPE_MC_1_ORDERED_IOC_PATH_WRITES = 84, + BIUPE_MC_1_SYNC_A = 85, + BIUPE_MC_1_SYNC_B = 86, + BIUPE_MCQF_NEARFULL = 100, + BIUPE_MCQDF_NEARFULL = 101, + BIUPE_IMQF_NEARFULL = 102, + BIUPE_PSF_NEARFULL = 103, + BIUPE_M0SF_NEARFULL = 104, + BIUPE_M1SF_NEARFULL = 105, + BIUPE_IMSF_NEARFULL = 106, + BIUPE_IMSDF_NEARFULL = 107, + BIUPE_ISQF_NEARFULL = 108, + BIUPE_ISSF_NEARFULL = 109, + BIUPE_ISYF_NEARFULL = 110, + BIUPE_CPYF_NEARFULL = 111, + BIUPE_PQF_NEARFULL = 112, + BIUPE_TOTAL_MEMORY_LATENCY_FAST_READS_MUST_BE_DIVIDED_BY_MEM_READ_REQUESTS_FOR_AVERAGE_LATENCY = 140, + BIUPE_TOTAL_MEMORY_LATENCY_ORDERED_CPU_READS_MUST_BE_DIVIDED_BY_MEM_READ_REQUESTS_FOR_AVERAGE_LATENCY = 141, + BIUPE_TOTAL_MEMORY_LATENCY_ORDERED_IOC_READS_MUST_BE_DIVIDED_BY_MEM_READ_REQUESTS_FOR_AVERAGE_LATENCY = 142, + BIUPE_TOTAL_FLUSH_LATENCY_FOR_SNOOP_READS_MUST_BE_DIVIED_BY_FLUSH_REQUESTS_FOR_AVERAGE_LATENCY = 143, + BIUPE_TOTAL_FLUSH_LATENCY_FOR_SNOOP_WRITES_MUST_BE_DIVIED_BY_FLUSH_REQUESTS_FOR_AVERAGE_LATENCY = 144, + BIUPE_SNOOP_COMPLETION_BUFFER_FULL = 145, + BIUPE_RESERVED62 = 146, + BIUPE_RESERVED63 = 147, + BIUPE_RESERVED64 = 148, + BIUPE_RESERVED65 = 149, + BIUPE_MC0_SLOW_CREDIT_COUNT_IS_ZERO = 150, + BIUPE_MC1_SLOW_CREDIT_COUNT_IS_ZERO = 151, + BIUPE_MC0_FAST_CREDIT_COUNT_IS_ZERO = 152, + BIUPE_MC1_FAST_CREDIT_COUNT_IS_ZERO = 153, + BIUPE_RESERVED66 = 154, + BIUPE_RESERVED67 = 155, + BIUPE_FSB_SLV_REQ_STALL_FOR_COMMAND_CREDITS = 156, + BIUPE_FSB_SLV_REQ_STALL_FOR_DATA_CREDITS = 157, + BIUPE_FSB_PG_REQ_STALL_FOR_CMD_CREDITS = 158, + BIUPE_SCLK_COUNTS_SCLKS_IN_THE_MCLK_DOMAIN_ = 200, + BIUPE_IOC_MASTER_REQ_STALL_BIU_HAS_DATA_BUT_IOC_NOT_READY_SCLK_DOMAIN_ = 201, + BIUPE_IOC_SLAVE_RSP_STALL_SCLK_DOMAIN_ = 202, + BIUPE_INCREMENT_BY_0_DISABLE_COUNT = 252, + BIUPE_INCREMENT_BY_1_USED_TO_COUNT_CLOCKS = 253, + BIUPE_INCREMENT_BY_63_USED_FOR_SIMULATION_TO_RAPIDLY_INCREMENT_COUNTER = 254, + BIUPE_OTHERS = 255, // Reserved +} BIUPERFEVENT; + +typedef enum +{ + IOCPE_PERF_CYCLES_WAITING_FOR_REGISTER_BUS = 0, + IOCPE_PERF_CYCLES_WAITING_FOR_BIU_SLV_REQ = 1, + IOCPE_PERF_CYCLES_WAITING_FOR_BIU_MST_CPL = 2, + IOCPE_PERF_CYCLES_WAITING_FOR_BSB_MST_REQ = 3, + IOCPE_PERF_CYCLES_WAITING_FOR_MH_SLV_REQ = 4, + IOCPE_PERF_BSB_SLV_REQ_TOTAL_REQUESTS = 5, + IOCPE_PERF_BSB_SLV_REQ_TOTAL_READS = 6, + IOCPE_PERF_BSB_SLV_REQ_TOTAL_WRITES = 7, // (includes interrupts) + IOCPE_PERF_BSB_SLV_REQ_SNOOPED_READS = 8, + IOCPE_PERF_BSB_SLV_REQ_SNOOPED_WRITES = 9, //includes interrupts, if snooped attr is true) + IOCPE_PERF_BSB_SLV_REQ_NON_SNOOPED_READS = 10, + IOCPE_PERF_BSB_SLV_REQ_NON_SNOOPED_WRITES = 11, //( includes interrupts, if non-snooped attr is true) + IOCPE_PERF_BSB_SLV_REQ_INTERRUPTS = 12, + IOCPE_PERF_BSB_SLV_REQ_TOTAL_REQUESTS_DWORDS = 13, + IOCPE_PERF_BSB_SLV_REQ_TOTAL_READS_DWORDS = 14, + IOCPE_PERF_BSB_SLV_REQ_TOTAL_WRITES_DWORDS = 15, + IOCPE_PERF_BSB_SLV_REQ_SNOOPED_READS_DWORDS = 16, + IOCPE_PERF_BSB_SLV_REQ_SNOOPED_WRITES_DWORDS = 17, + IOCPE_PERF_BSB_SLV_REQ_NON_SNOOPED_READS_DWORDS = 18, + IOCPE_PERF_BSB_SLV_REQ_NON_SNOOPED_WRITES_DWORDS = 19, + IOCPE_PERF_BSB_SLV_READ_LATENCY_CYCLES = 20, // (snooped or non-snooped dependent upon secondary control register) (used to calc average latency with # read requests) + IOCPE_PERF_BSB_SLV_CPL_TOTAL_READ_COMPLETIONS = 21, + IOCPE_PERF_BSB_SLV_CPL_SNOOPED_READ_COMPLETIONS = 22, + IOCPE_PERF_BSB_SLV_CPL_NON_SNOOPED_READ_COMPLETIONS = 23, + IOCPE_PERF_BSB_SLV_CPL_TOTAL_READ_COMPLETIONS_DWORDS = 24, + IOCPE_PERF_BSB_SLV_CPL_SNOOPED_READ_COMPLETIONS_DWORDS = 25, + IOCPE_PERF_BSB_SLV_CPL_NON_SNOOPED_READ_COMPLETIONS_DWORDS = 26, + IOCPE_PERF_BSB_SLV_CPL_URS = 27, // (counts ur's and ca's) (ca's don't happen in production mode), + IOCPE_PERF_BIF_SLV_REQ_TOTAL_REQUESTS = 28, + IOCPE_PERF_BIF_SLV_REQ_TOTAL_CP_WRITEBACKS = 29, + IOCPE_PERF_BIF_SLV_REQ_TOTAL_SNOOPED_WRITES = 30, + IOCPE_PERF_BSB_MST_REQ_TOTAL_REQUESTS = 31, + IOCPE_PERF_BSB_MST_REQ_TOTAL_READS = 32, + IOCPE_PERF_BSB_MST_REQ_TOTAL_WRITES = 33, + IOCPE_PERF_BSB_MST_REQ_TOTAL_REQUESTS_DWORDS = 34, + IOCPE_PERF_BSB_MST_REQ_TOTAL_READS_DWORDS = 35, + IOCPE_PERF_BSB_MST_REQ_TOTAL_WRITES_DWORDS = 36, + IOCPE_PERF_BSB_MST_CPL_TOTAL_COMPLETIONS = 37, + IOCPE_PERF_BSB_MST_CPL_TOTAL_COMPLETIONS_DWORDS = 38, + IOCPE_PERF_REG_BUS_REQ_TOTAL_REQUESTS = 39, + IOCPE_PERF_REG_BUS_REQ_TOTAL_READS = 40, + IOCPE_PERF_REG_BUS_REQ_TOTAL_WRITES = 41, + IOCPE_PERF_REG_BUS_CPL_READ_COMPLETIONS = 42, + IOCPE_PERF_TOTAL_SYNCS_ISSUED = 43, + IOCPE_PERF_BIU_SYNCS_ISSUED = 44, + IOCPE_PERF_MH_SYNCS_ISSUED = 45, + IOCPE_PERF_TOTAL_SYNCS_RECEIVED = 46, + IOCPE_PERF_BIU_SYNCS_RECEIVED = 47, + IOCPE_PERF_MH_SYNCS_RECEIVED = 48, + IOCPE_PERF_FIFO_BSB_MST_REQ_FULL = 49, + IOCPE_PERF_FIFO_BSB_MST_REQ_EMPTY = 50, + IOCPE_PERF_FIFO_SYNC_FULL = 51, + IOCPE_PERF_FIFO_SYNC_EMPTY = 52, + IOCPE_PERF_FIFO_INTERRUPT_FULL = 53, + IOCPE_PERF_FIFO_INTERRUPT_EMPTY = 54, + IOCPE_PERF_FIFO_REG_FULL = 55, + IOCPE_PERF_FIFO_REG_EMPTY = 56, + IOCPE_PERF_FIFO_BIU_SLV_CPL_NEARFULL = 57, + IOCPE_PERF_FIFO_BIU_SLV_CPL_EMPTY = 58, + IOCPE_PERF_FIFO_MH_SLV_CPL_FULL = 59, + IOCPE_PERF_FIFO_MH_SLV_CPL_EMPTY = 60, + IOCPE_PERF_FIFO_BSB_SLV_REQ_NEARFULL = 61, + IOCPE_PERF_FIFO_BSB_SLV_REQ_EMPTY = 62, + IOCPE_PERF_FIFO_BSB_MST_CPL_NEARFULL = 63, + IOCPE_PERF_FIFO_BSB_MST_CPL_EMPTY = 64, + IOCPE_PERF_FIFO_BIU_MST_REQ_NEARFULL = 65, + IOCPE_PERF_FIFO_BIU_MST_REQ_EMPTY = 66, + IOCPE_PERF_FIFO_BIF_SLV_REQ_NEARFULL = 67, + IOCPE_PERF_FIFO_BIF_SLV_REQ_EMPTY = 68, + IOCPE_PERF_FIFO_READ_LATENCY_FULL = 69, + IOCPE_PERF_FIFO_READ_LATENCY_EMPTY = 70, + IOCPE_PERF_NUMBER_OF_SYSTEM_CLOCKS = 71, + IOCPE_PERF_ZERO_COUNT = 72, //(disable count) + IOCPE_PERF_SIXTY_THREE_COUNT = 73, // (sim rapidly inc counter) + IOCPE_PERF_BIU_SPARE = 74, // (so dff ins don't disappear) + IOCPE_PERF_BSB_SLV_REQ_MESSAGES = 75, + IOCPE_PERF_BSB_MST_REQ_CONFIG_READS = 76, // (all 1 dword) + IOCPE_PERF_BSB_MST_REQ_CONFIG_WRITES = 77, // (all 1 dword) + IOCPE_PERF_BSB_MST_REQ_POSTED_WRITES = 78, + IOCPE_PERF_BSB_MST_REQ_POSTED_WRITES_DWORDS = 79, + IOCPE_PERF_BSB_MST_CPL_NON_POSTED_WRITES = 80, // (all 1 dword) + IOCPE_PERF_CYCLES_WAITING_FOR_INT_SYNC = 81, // (total time waiting for any type of interrupt sync) + IOCPE_PERF_CYCLES_WAITING_FOR_INT_SYNC_SNOOP_PATH = 82, // (time waiting for interrupts that only caused syncs to biu) + IOCPE_PERF_CYCLES_WAITING_FOR_INT_SYNC_NON_SNOOP_PATH = 83, // (time waiting for interrupts that only caused syncs to mh) + IOCPE_PERF_CYCLES_WAITING_FOR_INT_SYNC_BOTH_PATHS = 84, // (time waiting for interrupts that caused syncs to mh and biu) + IOCPE_PERF_CYCLES_WAITING_FOR_MST_RD_CPL_SYNC = 85, // (total time waiting for any type of mst cpl sync) + IOCPE_PERF_CYCLES_WAITING_FOR_MST_RD_CPL_SYNC_SNOOP_PATH = 86, // (time waiting for mst cpls that only caused syncs to biu) + IOCPE_PERF_CYCLES_WAITING_FOR_MST_RD_CPL_SYNC_NON_SNOOP_PATH = 87, // (time waiting for mst cpls that only caused syncs to mh) + IOCPE_PERF_CYCLES_WAITING_FOR_MST_RD_CPL_SYNC_BOTH_PATHS = 88, // (time waiting for mst cpls that caused syncs to mh and biu) + IOCPE_PERF_CYCLES_WAITING_FOR_NSR_PASS_SW = 89, + IOCPE_PERF_CYCLES_WAITING_FOR_SR_PASS_NSW = 90, + IOCPE_PERF_CYCLES_WAITING_FOR_NSW_PASS_SW = 91, + IOCPE_PERF_CYCLES_WAITING_FOR_SW_PASS_NSW = 92, + IOCPE_PERF_FIFO_MST_CPL_SYNC_TYPE_FIFO_FULL = 93, + IOCPE_PERF_FIFO_MST_CPL_SYNC_TYPE_FIFO_EMPTY = 94, + IOCPE_PERF_FIFO_BSB_SNOOP_SLV_REQ_FULL = 95, + IOCPE_PERF_FIFO_BSB_SNOOP_SLV_REQ_EMPTY = 96, + IOCPE_PERF_FIFO_BSB_SNOOP_SLV_REQ_DATA_FULL = 97, + IOCPE_PERF_FIFO_BSB_SNOOP_SLV_REQ_DATA_EMPTY = 98, + IOCPE_PERF_FIFO_READ_LATENCY_BAD_REQ_FULL = 99, + IOCPE_PERF_FIFO_READ_LATENCY_BAD_REQ_EMPTY = 100, + IOCPE_PERF_FIFO_READ_LATENCY_NON_SNOOP_CAM_ADDRESS_FULL = 101, + IOCPE_PERF_FIFO_READ_LATENCY_NON_SNOOP_CAM_ADDRESS_EMPTY = 102, +} IOCPERFEVENT; + +//------------------------------------------------------------------------------ +// GPU performance counter register offsets + +typedef enum +{ + GPUPERFREG_PA_SU_PERFCOUNTER0_SELECT = 0x0C88, + GPUPERFREG_PA_SU_PERFCOUNTER1_SELECT = 0x0C89, + GPUPERFREG_PA_SU_PERFCOUNTER2_SELECT = 0x0C8A, + GPUPERFREG_PA_SU_PERFCOUNTER3_SELECT = 0x0C8B, + GPUPERFREG_PA_SC_PERFCOUNTER0_SELECT = 0x0C98, + GPUPERFREG_PA_SC_PERFCOUNTER1_SELECT = 0x0C99, + GPUPERFREG_PA_SC_PERFCOUNTER2_SELECT = 0x0C9A, + GPUPERFREG_PA_SC_PERFCOUNTER3_SELECT = 0x0C9B, + GPUPERFREG_VGT_PERFCOUNTER0_SELECT = 0x0C48, + GPUPERFREG_VGT_PERFCOUNTER1_SELECT = 0x0C49, + GPUPERFREG_VGT_PERFCOUNTER2_SELECT = 0x0C4A, + GPUPERFREG_VGT_PERFCOUNTER3_SELECT = 0x0C4B, + GPUPERFREG_TCR_PERFCOUNTER0_SELECT = 0x0E05, + GPUPERFREG_TCR_PERFCOUNTER1_SELECT = 0x0E08, + GPUPERFREG_TP0_PERFCOUNTER0_SELECT = 0x0E1F, + GPUPERFREG_TP0_PERFCOUNTER1_SELECT = 0x0E22, + GPUPERFREG_TP1_PERFCOUNTER0_SELECT = 0x0E28, + GPUPERFREG_TP1_PERFCOUNTER1_SELECT = 0x0E2B, + GPUPERFREG_TP2_PERFCOUNTER0_SELECT = 0x0E31, + GPUPERFREG_TP2_PERFCOUNTER1_SELECT = 0x0E34, + GPUPERFREG_TP3_PERFCOUNTER0_SELECT = 0x0E3A, + GPUPERFREG_TP3_PERFCOUNTER1_SELECT = 0x0E3D, + GPUPERFREG_TCM_PERFCOUNTER0_SELECT = 0x0E54, + GPUPERFREG_TCM_PERFCOUNTER1_SELECT = 0x0E57, + GPUPERFREG_TCF_PERFCOUNTER0_SELECT = 0x0E5A, + GPUPERFREG_TCF_PERFCOUNTER1_SELECT = 0x0E5D, + GPUPERFREG_TCF_PERFCOUNTER2_SELECT = 0x0E60, + GPUPERFREG_TCF_PERFCOUNTER3_SELECT = 0x0E63, + GPUPERFREG_TCF_PERFCOUNTER4_SELECT = 0x0E66, + GPUPERFREG_TCF_PERFCOUNTER5_SELECT = 0x0E69, + GPUPERFREG_TCF_PERFCOUNTER6_SELECT = 0x0E6C, + GPUPERFREG_TCF_PERFCOUNTER7_SELECT = 0x0E6F, + GPUPERFREG_TCF_PERFCOUNTER8_SELECT = 0x0E72, + GPUPERFREG_TCF_PERFCOUNTER9_SELECT = 0x0E75, + GPUPERFREG_TCF_PERFCOUNTER10_SELECT = 0x0E78, + GPUPERFREG_TCF_PERFCOUNTER11_SELECT = 0x0E7B, + GPUPERFREG_VC_PERFCOUNTER0_SELECT = 0x0E48, + GPUPERFREG_VC_PERFCOUNTER1_SELECT = 0x0E4B, + GPUPERFREG_VC_PERFCOUNTER2_SELECT = 0x0E4E, + GPUPERFREG_VC_PERFCOUNTER3_SELECT = 0x0E51, + GPUPERFREG_SQ_PERFCOUNTER0_SELECT = 0x0DC8, + GPUPERFREG_SQ_PERFCOUNTER1_SELECT = 0x0DC9, + GPUPERFREG_SQ_PERFCOUNTER2_SELECT = 0x0DCA, + GPUPERFREG_SQ_PERFCOUNTER3_SELECT = 0x0DCB, + GPUPERFREG_SX_PERFCOUNTER0_SELECT = 0x0DD4, + GPUPERFREG_MC0_PERFCOUNTER0_SELECT = 0x0815, + GPUPERFREG_MC1_PERFCOUNTER0_SELECT = 0x0855, + GPUPERFREG_MH_PERFCOUNTER0_SELECT = 0x0A18, + GPUPERFREG_MH_PERFCOUNTER1_SELECT = 0x0A1B, + GPUPERFREG_MH_PERFCOUNTER2_SELECT = 0x0A1E, + GPUPERFREG_BIF_PERFCOUNTER0_SELECT = 0x0048, + GPUPERFREG_HZ_PERFCOUNTER0_SELECT = 0x1004, + GPUPERFREG_HZ_PERFCOUNTER1_SELECT = 0x1007, + GPUPERFREG_BC_PERFCOUNTER0_SELECT = 0x0F04, + GPUPERFREG_BC_PERFCOUNTER1_SELECT = 0x0F05, + GPUPERFREG_BC_PERFCOUNTER2_SELECT = 0x0F06, + GPUPERFREG_BC_PERFCOUNTER3_SELECT = 0x0F07, + GPUPERFREG_RBBM_PERFCOUNTER0_SELECT = 0x0395, + GPUPERFREG_RBBM_PERFCOUNTER1_SELECT = 0x0396, + GPUPERFREG_CP_PERFCOUNTER0_SELECT = 0x01E6, + GPUPERFREG_PA_SU_PERFCOUNTER0_LOW = 0x0C8C, + GPUPERFREG_PA_SU_PERFCOUNTER0_HI = 0x0C8D, + GPUPERFREG_PA_SU_PERFCOUNTER1_LOW = 0x0C8E, + GPUPERFREG_PA_SU_PERFCOUNTER1_HI = 0x0C8F, + GPUPERFREG_PA_SU_PERFCOUNTER2_LOW = 0x0C90, + GPUPERFREG_PA_SU_PERFCOUNTER2_HI = 0x0C91, + GPUPERFREG_PA_SU_PERFCOUNTER3_LOW = 0x0C92, + GPUPERFREG_PA_SU_PERFCOUNTER3_HI = 0x0C93, + GPUPERFREG_PA_SC_PERFCOUNTER0_LOW = 0x0C9C, + GPUPERFREG_PA_SC_PERFCOUNTER0_HI = 0x0C9D, + GPUPERFREG_PA_SC_PERFCOUNTER1_LOW = 0x0C9E, + GPUPERFREG_PA_SC_PERFCOUNTER1_HI = 0x0C9F, + GPUPERFREG_PA_SC_PERFCOUNTER2_LOW = 0x0CA0, + GPUPERFREG_PA_SC_PERFCOUNTER2_HI = 0x0CA1, + GPUPERFREG_PA_SC_PERFCOUNTER3_LOW = 0x0CA2, + GPUPERFREG_PA_SC_PERFCOUNTER3_HI = 0x0CA3, + GPUPERFREG_VGT_PERFCOUNTER0_LOW = 0x0C4C, + GPUPERFREG_VGT_PERFCOUNTER0_HI = 0x0C4D, + GPUPERFREG_VGT_PERFCOUNTER1_LOW = 0x0C4E, + GPUPERFREG_VGT_PERFCOUNTER1_HI = 0x0C4F, + GPUPERFREG_VGT_PERFCOUNTER2_LOW = 0x0C50, + GPUPERFREG_VGT_PERFCOUNTER2_HI = 0x0C51, + GPUPERFREG_VGT_PERFCOUNTER3_LOW = 0x0C52, + GPUPERFREG_VGT_PERFCOUNTER3_HI = 0x0C53, + GPUPERFREG_TCR_PERFCOUNTER0_LOW = 0x0E07, + GPUPERFREG_TCR_PERFCOUNTER0_HI = 0x0E06, + GPUPERFREG_TCR_PERFCOUNTER1_LOW = 0x0E0A, + GPUPERFREG_TCR_PERFCOUNTER1_HI = 0x0E09, + GPUPERFREG_TP0_PERFCOUNTER0_LOW = 0x0E21, + GPUPERFREG_TP0_PERFCOUNTER0_HI = 0x0E20, + GPUPERFREG_TP0_PERFCOUNTER1_LOW = 0x0E24, + GPUPERFREG_TP0_PERFCOUNTER1_HI = 0x0E23, + GPUPERFREG_TP1_PERFCOUNTER0_LOW = 0x0E2A, + GPUPERFREG_TP1_PERFCOUNTER0_HI = 0x0E29, + GPUPERFREG_TP1_PERFCOUNTER1_LOW = 0x0E2D, + GPUPERFREG_TP1_PERFCOUNTER1_HI = 0x0E2C, + GPUPERFREG_TP2_PERFCOUNTER0_LOW = 0x0E33, + GPUPERFREG_TP2_PERFCOUNTER0_HI = 0x0E32, + GPUPERFREG_TP2_PERFCOUNTER1_LOW = 0x0E36, + GPUPERFREG_TP2_PERFCOUNTER1_HI = 0x0E35, + GPUPERFREG_TP3_PERFCOUNTER0_LOW = 0x0E3C, + GPUPERFREG_TP3_PERFCOUNTER0_HI = 0x0E3B, + GPUPERFREG_TP3_PERFCOUNTER1_LOW = 0x0E3F, + GPUPERFREG_TP3_PERFCOUNTER1_HI = 0x0E3E, + GPUPERFREG_TCM_PERFCOUNTER0_LOW = 0x0E56, + GPUPERFREG_TCM_PERFCOUNTER0_HI = 0x0E55, + GPUPERFREG_TCM_PERFCOUNTER1_LOW = 0x0E59, + GPUPERFREG_TCM_PERFCOUNTER1_HI = 0x0E58, + GPUPERFREG_TCF_PERFCOUNTER0_LOW = 0x0E5C, + GPUPERFREG_TCF_PERFCOUNTER0_HI = 0x0E5B, + GPUPERFREG_TCF_PERFCOUNTER1_LOW = 0x0E5F, + GPUPERFREG_TCF_PERFCOUNTER1_HI = 0x0E5E, + GPUPERFREG_TCF_PERFCOUNTER2_LOW = 0x0E62, + GPUPERFREG_TCF_PERFCOUNTER2_HI = 0x0E61, + GPUPERFREG_TCF_PERFCOUNTER3_LOW = 0x0E65, + GPUPERFREG_TCF_PERFCOUNTER3_HI = 0x0E64, + GPUPERFREG_TCF_PERFCOUNTER4_LOW = 0x0E68, + GPUPERFREG_TCF_PERFCOUNTER4_HI = 0x0E67, + GPUPERFREG_TCF_PERFCOUNTER5_LOW = 0x0E6B, + GPUPERFREG_TCF_PERFCOUNTER5_HI = 0x0E6A, + GPUPERFREG_TCF_PERFCOUNTER6_LOW = 0x0E6E, + GPUPERFREG_TCF_PERFCOUNTER6_HI = 0x0E6D, + GPUPERFREG_TCF_PERFCOUNTER7_LOW = 0x0E71, + GPUPERFREG_TCF_PERFCOUNTER7_HI = 0x0E70, + GPUPERFREG_TCF_PERFCOUNTER8_LOW = 0x0E74, + GPUPERFREG_TCF_PERFCOUNTER8_HI = 0x0E73, + GPUPERFREG_TCF_PERFCOUNTER9_LOW = 0x0E77, + GPUPERFREG_TCF_PERFCOUNTER9_HI = 0x0E76, + GPUPERFREG_TCF_PERFCOUNTER10_LOW = 0x0E7A, + GPUPERFREG_TCF_PERFCOUNTER10_HI = 0x0E79, + GPUPERFREG_TCF_PERFCOUNTER11_LOW = 0x0E7D, + GPUPERFREG_TCF_PERFCOUNTER11_HI = 0x0E7C, + GPUPERFREG_VC_PERFCOUNTER0_LOW = 0x0E4A, + GPUPERFREG_VC_PERFCOUNTER0_HI = 0x0E49, + GPUPERFREG_VC_PERFCOUNTER1_LOW = 0x0E4D, + GPUPERFREG_VC_PERFCOUNTER1_HI = 0x0E4C, + GPUPERFREG_VC_PERFCOUNTER2_LOW = 0x0E50, + GPUPERFREG_VC_PERFCOUNTER2_HI = 0x0E4F, + GPUPERFREG_VC_PERFCOUNTER3_LOW = 0x0E53, + GPUPERFREG_VC_PERFCOUNTER3_HI = 0x0E52, + GPUPERFREG_SQ_PERFCOUNTER0_LOW = 0x0DCC, + GPUPERFREG_SQ_PERFCOUNTER0_HI = 0x0DCD, + GPUPERFREG_SQ_PERFCOUNTER1_LOW = 0x0DCE, + GPUPERFREG_SQ_PERFCOUNTER1_HI = 0x0DCF, + GPUPERFREG_SQ_PERFCOUNTER2_LOW = 0x0DD0, + GPUPERFREG_SQ_PERFCOUNTER2_HI = 0x0DD1, + GPUPERFREG_SQ_PERFCOUNTER3_LOW = 0x0DD2, + GPUPERFREG_SQ_PERFCOUNTER3_HI = 0x0DD3, + GPUPERFREG_SX_PERFCOUNTER0_LOW = 0x0DD8, + GPUPERFREG_SX_PERFCOUNTER0_HI = 0x0DD9, + GPUPERFREG_MC0_PERFCOUNTER0_LOW = 0x0817, + GPUPERFREG_MC0_PERFCOUNTER0_HI = 0x0816, + GPUPERFREG_MC1_PERFCOUNTER0_LOW = 0x0857, + GPUPERFREG_MC1_PERFCOUNTER0_HI = 0x0856, + GPUPERFREG_MH_PERFCOUNTER0_LOW = 0x0A1A, + GPUPERFREG_MH_PERFCOUNTER0_HI = 0x0A19, + GPUPERFREG_MH_PERFCOUNTER1_LOW = 0x0A1D, + GPUPERFREG_MH_PERFCOUNTER1_HI = 0x0A1C, + GPUPERFREG_MH_PERFCOUNTER2_LOW = 0x0A20, + GPUPERFREG_MH_PERFCOUNTER2_HI = 0x0A1F, + GPUPERFREG_BIF_PERFCOUNTER0_LOW = 0x004A, + GPUPERFREG_BIF_PERFCOUNTER0_HI = 0x0049, + GPUPERFREG_HZ_PERFCOUNTER0_LOW = 0x1006, + GPUPERFREG_HZ_PERFCOUNTER0_HI = 0x1005, + GPUPERFREG_HZ_PERFCOUNTER1_LOW = 0x1009, + GPUPERFREG_HZ_PERFCOUNTER1_HI = 0x1008, + GPUPERFREG_BC_PERFCOUNTER0_LOW = 0x0F08, + GPUPERFREG_BC_PERFCOUNTER0_HI = 0x0F09, + GPUPERFREG_BC_PERFCOUNTER1_LOW = 0x0F0A, + GPUPERFREG_BC_PERFCOUNTER1_HI = 0x0F0B, + GPUPERFREG_BC_PERFCOUNTER2_LOW = 0x0F0C, + GPUPERFREG_BC_PERFCOUNTER2_HI = 0x0F0D, + GPUPERFREG_BC_PERFCOUNTER3_LOW = 0x0F0E, + GPUPERFREG_BC_PERFCOUNTER3_HI = 0x0F0F, + GPUPERFREG_RBBM_PERFCOUNTER0_LOW = 0x0397, + GPUPERFREG_RBBM_PERFCOUNTER0_HI = 0x0398, + GPUPERFREG_RBBM_PERFCOUNTER1_LOW = 0x0399, + GPUPERFREG_RBBM_PERFCOUNTER1_HI = 0x039A, + GPUPERFREG_CP_PERFCOUNTER0_LOW = 0x01E7, + GPUPERFREG_CP_PERFCOUNTER0_HI = 0x01E8, + + GPUPERFREG_CP_PERFMON_CNTL = 0x01F5, + GPUPERFREG_VGT_EVENT_INITIATOR = 0x21F9, +} GPUPERFREGISTER; + +typedef enum +{ + BIUPERFREG_BIU_PERFCOUNTER0_SELECT = 0x408041, + BIUPERFREG_BIU_PERFCOUNTER1_SELECT = 0x408044, + BIUPERFREG_BIU_PERFCOUNTER2_SELECT = 0x408047, + BIUPERFREG_BIU_PERFCOUNTER3_SELECT = 0x40804A, + BIUPERFREG_BIU_PERFCOUNTER0_LOW = 0x408043, + BIUPERFREG_BIU_PERFCOUNTER0_HI = 0x408042, + BIUPERFREG_BIU_PERFCOUNTER1_LOW = 0x408046, + BIUPERFREG_BIU_PERFCOUNTER1_HI = 0x408045, + BIUPERFREG_BIU_PERFCOUNTER2_LOW = 0x408049, + BIUPERFREG_BIU_PERFCOUNTER2_HI = 0x408048, + BIUPERFREG_BIU_PERFCOUNTER3_LOW = 0x40804C, + BIUPERFREG_BIU_PERFCOUNTER3_HI = 0x40804B, + + BIUPERFREG_BIU_PERFMON_CNTL = 0x408040, +} BIUPERFREGISTER; + +typedef enum +{ + DCPERFREG_DC_PERFCOUNTER0_SELECT = 0x1FC8, + DCPERFREG_DC_PERFCOUNTER1_SELECT = 0x1FCB, + + DCPERFREG_DC_PERFCOUNTER0_LOW = 0x1FCA, + DCPERFREG_DC_PERFCOUNTER0_HI = 0x1FC9, + DCPERFREG_DC_PERFCOUNTER1_LOW = 0x1FCD, + DCPERFREG_DC_PERFCOUNTER1_HI = 0x1FCC, +} DCPERFREGISTER; + +typedef enum +{ + IOCPERFREG_IOC_PERFCOUNTER0_SELECT = 0x410081, + IOCPERFREG_IOC_PERFCOUNTER1_SELECT = 0x410084, + IOCPERFREG_IOC_PERFCOUNTER2_SELECT = 0x410087, + IOCPERFREG_IOC_PERFCOUNTER3_SELECT = 0x41008A, + IOCPERFREG_IOC_PERFCOUNTER0_LOW = 0x410083, + IOCPERFREG_IOC_PERFCOUNTER0_HI = 0x410082, + IOCPERFREG_IOC_PERFCOUNTER1_LOW = 0x410086, + IOCPERFREG_IOC_PERFCOUNTER1_HI = 0x410085, + IOCPERFREG_IOC_PERFCOUNTER2_LOW = 0x410089, + IOCPERFREG_IOC_PERFCOUNTER2_HI = 0x410088, + IOCPERFREG_IOC_PERFCOUNTER3_LOW = 0x41008C, + IOCPERFREG_IOC_PERFCOUNTER3_HI = 0x41008B, + + IOCPERFREG_IOC_PERFMON_CNTL = 0x410080, +} IOCPERFREGISTER; + + +//------------------------------------------------------------------------------ +// GPU performance counter register defines + +typedef union +{ + struct { + DWORD Select : 8; + DWORD N : 8; + DWORD : 16; + }; + DWORD dword; +} GPUPERFCOUNTER_SELECT; + +typedef union { + struct { + DWORD Low : 32; + DWORD High : 16; + DWORD : 16; + + }; + ULARGE_INTEGER qword; +} GPUPERFCOUNTER_VALUE; + +typedef union { + struct { + DWORD Low : 32; + DWORD High : 16; + DWORD : 16; + }; + ULARGE_INTEGER qword; +} DCPERFCOUNTER_VALUE; + +typedef union { + struct { + DWORD Low : 32; + DWORD High : 16; + DWORD : 16; + + + }; + ULARGE_INTEGER qword; +} BIUPERFCOUNTER_VALUE; + +typedef union { + struct { + DWORD Low : 32; + DWORD High : 16; + DWORD : 16; + }; + ULARGE_INTEGER qword; +} IOCPERFCOUNTER_VALUE; + +typedef union { + struct { + DWORD State : 4; + DWORD : 4; + DWORD EnableMode : 2; + DWORD : 22; + }; + DWORD dword; +} GPUPERFCOUNTER_CNTL; + +typedef union { + struct { + DWORD State : 4; + DWORD : 4; + DWORD EnableMode : 2; + DWORD : 22; + }; + DWORD dword; +} DCPERFCOUNTER_CNTL; + +typedef union { + struct { + DWORD State : 3; + DWORD : 29; + }; + DWORD dword; +} BIUPERFCOUNTER_CNTL; + +typedef union { + struct { + DWORD State : 4; + DWORD : 28; + }; + DWORD dword; +} IOCPERFCOUNTER_CNTL; + + +#if defined(_M_PPCBE) +#pragma bitfield_order(pop) +#endif + +#pragma warning(pop) + +#ifdef __cplusplus +}; +#endif + +#endif /* _D3D9GPU_H_ */ diff --git a/third_party/xbox_sdk/include/d3d9types.h b/third_party/xbox_sdk/include/d3d9types.h new file mode 100644 index 0000000..a6d8062 --- /dev/null +++ b/third_party/xbox_sdk/include/d3d9types.h @@ -0,0 +1,3141 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: d3d9types.h + * Content: Direct3D capabilities include file + * + ***************************************************************************/ + +#ifndef _d3d9TYPES_H_ +#define _d3d9TYPES_H_ + +#ifndef DIRECT3D_VERSION +#define DIRECT3D_VERSION 0x0900 +#endif //DIRECT3D_VERSION + +// include this file content only if compiling for DX9 interfaces +#if(DIRECT3D_VERSION >= 0x0900) + +// The PPC back-end of the C compiler by default defines bitfields to be +// ordered from the MSB to the LSB, which is opposite the convention on +// the X86 platform. Use the 'bitfield_order' pragma to switch the +// ordering. Note that this does not affect endianness in any way. + +#if defined(_M_PPCBE) +#pragma bitfield_order(push) +#pragma bitfield_order(lsb_to_msb) +#endif + +#include +#include "d3d9gpu.h" + +#if _MSC_VER >= 1200 +#pragma warning(push) +#endif +#pragma warning(disable:4201 4200) // anonymous unions warning +#if defined(_X86_) || defined(_IA64) +#pragma pack(push, 4) +#endif + +// D3DCOLOR is equivalent to D3DFMT_A8R8G8B8 +#ifndef D3DCOLOR_DEFINED +typedef DWORD D3DCOLOR; +#define D3DCOLOR_DEFINED +#endif + +// Canonical type for writing to GPU ring-buffers and command-buffers. +typedef DWORD* PRING; + +// maps unsigned 8 bits/channel to D3DCOLOR +#define D3DCOLOR_ARGB(a,r,g,b) \ + ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) +#define D3DCOLOR_RGBA(r,g,b,a) D3DCOLOR_ARGB(a,r,g,b) +#define D3DCOLOR_XRGB(r,g,b) D3DCOLOR_ARGB(0xff,r,g,b) + +#define D3DCOLOR_XYUV(y,u,v) D3DCOLOR_ARGB(0xff,y,u,v) +#define D3DCOLOR_AYUV(a,y,u,v) D3DCOLOR_ARGB(a,y,u,v) + +// maps floating point channels (0.f to 1.f range) to D3DCOLOR +#define D3DCOLOR_COLORVALUE(r,g,b,a) \ + D3DCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f)) + +// decodes a D3DCOLOR +#define D3DCOLOR_GETALPHA(argb) (((argb) >> 24) & 0xff) +#define D3DCOLOR_GETRED(argb) (((argb) >> 16) & 0xff) +#define D3DCOLOR_GETGREEN(argb) (((argb) >> 8) & 0xff) +#define D3DCOLOR_GETBLUE(argb) ((argb) & 0xff) + +#ifndef D3DVECTOR_DEFINED +typedef struct _D3DVECTOR { + float x; + float y; + float z; +} D3DVECTOR; +#define D3DVECTOR_DEFINED +#endif + +#ifndef D3DCOLORVALUE_DEFINED +typedef struct _D3DCOLORVALUE { + float r; + float g; + float b; + float a; +} D3DCOLORVALUE; +#define D3DCOLORVALUE_DEFINED +#endif + +#ifndef D3DRECT_DEFINED +typedef struct _D3DRECT { + LONG x1; + LONG y1; + LONG x2; + LONG y2; +} D3DRECT; +#define D3DRECT_DEFINED +#endif + +#ifndef D3DPOINT_DEFINED +typedef struct _D3DPOINT { + LONG x; + LONG y; +} D3DPOINT; +#define D3DPOINT_DEFINED +#endif + +#ifndef D3DMATRIX_DEFINED +typedef struct _D3DMATRIX { + union { + struct { + float _11, _12, _13, _14; + float _21, _22, _23, _24; + float _31, _32, _33, _34; + float _41, _42, _43, _44; + + }; + float m[4][4]; + }; +} D3DMATRIX; +#define D3DMATRIX_DEFINED +#endif + +typedef struct _D3DVIEWPORT9 { + DWORD X; + DWORD Y; /* Viewport Top left */ + DWORD Width; + DWORD Height; /* Viewport Dimensions */ + float MinZ; /* Min/max of clip Volume */ + float MaxZ; +} D3DVIEWPORT9; + +typedef struct _D3DVIEWPORTF9 { + float X; + float Y; /* Viewport Top left */ + float Width; + float Height; /* Viewport Dimensions */ + float MinZ; /* Min/max of clip Volume */ + float MaxZ; + DWORD Flags; +} D3DVIEWPORTF9; + +/* + * Values for clip fields. + */ + +// These bits could be ORed together to use with D3DRS_CLIPPLANEENABLE +// +#define D3DCLIPPLANE0 (1 << 0) +#define D3DCLIPPLANE1 (1 << 1) +#define D3DCLIPPLANE2 (1 << 2) +#define D3DCLIPPLANE3 (1 << 3) +#define D3DCLIPPLANE4 (1 << 4) +#define D3DCLIPPLANE5 (1 << 5) + +// The following bits are used in the ClipUnion and ClipIntersection +// members of the D3DCLIPSTATUS9 +// + +#define D3DCS_LEFT 0x00000001L +#define D3DCS_RIGHT 0x00000002L +#define D3DCS_TOP 0x00000004L +#define D3DCS_BOTTOM 0x00000008L +#define D3DCS_FRONT 0x00000010L +#define D3DCS_BACK 0x00000020L +#define D3DCS_PLANE0 0x00000040L +#define D3DCS_PLANE1 0x00000080L +#define D3DCS_PLANE2 0x00000100L +#define D3DCS_PLANE3 0x00000200L +#define D3DCS_PLANE4 0x00000400L +#define D3DCS_PLANE5 0x00000800L + +#define D3DCS_ALL (D3DCS_LEFT | \ + D3DCS_RIGHT | \ + D3DCS_TOP | \ + D3DCS_BOTTOM | \ + D3DCS_FRONT | \ + D3DCS_BACK | \ + D3DCS_PLANE0 | \ + D3DCS_PLANE1 | \ + D3DCS_PLANE2 | \ + D3DCS_PLANE3 | \ + D3DCS_PLANE4 | \ + D3DCS_PLANE5) + +typedef struct _D3DCLIPSTATUS9 { + DWORD ClipUnion; + DWORD ClipIntersection; +} D3DCLIPSTATUS9; + +/* + * Options for Clear + */ +#define D3DCLEAR_TARGET0 0x00000001l /* Clear target surface 0 */ +#define D3DCLEAR_TARGET1 0x00000002l /* Clear target surface 1 */ +#define D3DCLEAR_TARGET2 0x00000004l /* Clear target surface 2 */ +#define D3DCLEAR_TARGET3 0x00000008l /* Clear target surface 3 */ +#define D3DCLEAR_ALLTARGETS (D3DCLEAR_TARGET0 | D3DCLEAR_TARGET1 | D3DCLEAR_TARGET2 | D3DCLEAR_TARGET3) /* Clear all target surfaces */ +#define D3DCLEAR_TARGET D3DCLEAR_ALLTARGETS + +#define D3DCLEAR_ZBUFFER 0x00000010l /* Clear target z buffer */ +#define D3DCLEAR_STENCIL 0x00000020l /* Clear stencil planes */ +#define D3DCLEAR_HISTENCIL_CULL 0x00000040l /* Clear hi-stencil to cull all pixels */ +#define D3DCLEAR_HISTENCIL_PASS 0x00000080l /* Clear hi-stencil to pass all pixels */ + +/* + * Options for Resolve + */ +#define D3DRESOLVE_RENDERTARGET0 0x0000 /* Resolve from render target 0 */ +#define D3DRESOLVE_RENDERTARGET1 0x0001 +#define D3DRESOLVE_RENDERTARGET2 0x0002 +#define D3DRESOLVE_RENDERTARGET3 0x0003 +#define D3DRESOLVE_DEPTHSTENCIL 0x0004 /* Resolve from depth/stencil buffer */ + +#define D3DRESOLVE_ALLFRAGMENTS 0x0000 /* Automatically resolve all multisample fragments */ +#define D3DRESOLVE_FRAGMENT0 0x0010 /* Resolve only fragment 0 */ +#define D3DRESOLVE_FRAGMENT1 0x0020 +#define D3DRESOLVE_FRAGMENT2 0x0030 +#define D3DRESOLVE_FRAGMENT3 0x0040 +#define D3DRESOLVE_FRAGMENTS01 0x0050 /* Resolve fragments 0 and 1, with weight 0.5 */ +#define D3DRESOLVE_FRAGMENTS23 0x0060 /* Resolve fragments 2 and 3, with weight 0.5 */ +#define D3DRESOLVE_FRAGMENTS0123 0x0070 /* Resolve fragments 0, 1, 2 and 3, with weight 0.25 */ + +#define D3DRESOLVE_CLEARRENDERTARGET 0x0100 /* Clear the specified render target after resolving */ +#define D3DRESOLVE_CLEARDEPTHSTENCIL 0x0200 /* Clear the depth/stencil buffer after resolving */ + +#define D3DRESOLVE_EXPONENTBIAS_SHIFT 26 +#define D3DRESOLVE_EXPONENTBIAS(Bias) ((Bias) << D3DRESOLVE_EXPONENTBIAS_SHIFT) /* Bias applied to float number before formatting (-32 to 31) */ + +/* + * Options for XpsBegin + */ +#define D3DXPS_LOCK_128KB_L2 0x00000000 +#define D3DXPS_LOCK_256KB_L2 0x00000001 +#define D3DXPS_CPU0 0x01000000 +#define D3DXPS_CPU1 0x02000000 +#define D3DXPS_CPU2 0x04000000 +#define D3DXPS_CPU3 0x08000000 +#define D3DXPS_CPU4 0x10000000 +#define D3DXPS_CPU5 0x20000000 + +/* + * Options for BeginTiling + */ +#define D3DTILING_SKIP_FIRST_TILE_CLEAR 0x00000001 +#define D3DTILING_ONE_PASS_ZPASS 0x00000002 +#define D3DTILING_FIRST_TILE_INHERITS_DEPTH_BUFFER 0x00000004 +#define D3DTILING_CPU0 0x01000000 +#define D3DTILING_CPU1 0x02000000 +#define D3DTILING_CPU2 0x04000000 +#define D3DTILING_CPU3 0x08000000 +#define D3DTILING_CPU4 0x10000000 +#define D3DTILING_CPU5 0x20000000 + +/* + * Options for BeginZPass + */ +#define D3DZPASS_NO_AUTOMATIC_INVOKERENDERPASS 0x0001 + +/* + * Options for SetSurfaces + */ +#define D3DSETSURFACES_SET_AS_TILING_SURFACES 0x1 + +/* + * Options for SetPredication + */ +#define D3DPRED_TILE_Z(Tile) (0x1 << (2*(Tile))) +#define D3DPRED_TILE_RENDER(Tile) (0x2 << (2*(Tile))) +#define D3DPRED_TILE(Tile) (D3DPRED_TILE_Z(Tile) | D3DPRED_TILE_RENDER(Tile)) + +#define D3DPRED_ALL_Z 0x15555555 +#define D3DPRED_ALL_RENDER 0x2AAAAAAA + +/* + * Flags passed to D3DALLOCATECALLBACK callbacks + */ +#define D3DALLOCATE_DATA 0x1 +#define D3DALLOCATE_COMMANDS 0x2 + +/* + * Options for CreateGrowableCommandBuffer + */ +#define D3DCREATECB_DEBUG_ALLOCATOR 0x1 + +/* + * Options for BeginCommandBuffer + */ +#define D3DBEGINCB_TILING_PREDICATE_COMPONENTS 0x00000001 +#define D3DBEGINCB_TILING_PREDICATE_WHOLE 0x00000002 +#define D3DBEGINCB_ZPASS 0x00000004 +#define D3DBEGINCB_ENABLE_GETRESOURCES 0x00000008 +#define D3DBEGINCB_OVERWRITE_INHERITED_STATE 0x00000010 +#define D3DBEGINCB_RECORD_ALL_SET_STATE 0X00000020 +#define D3DBEGINCB_ONE_PASS_ZPASS 0x00000040 +#define D3DBEGINCB_FIRST_TILE_INHERITS_DEPTH_BUFFER 0x00000080 + +/* + * Parameters that can be passed to any of the create fix-up methods + */ +#define D3DFIXUP_DYNAMIC 0x1 + +/* + * Parameters for CreateSurfacesFixup + */ + +#define D3DFIXUP_HIGH_PRECISION_BLEND_ENABLE 0x80000000 + +/* + * Error values returned by the create fix-up methods + */ +#define D3DFIXUP_OUT_OF_MEMORY 0 +#define D3DFIXUP_NOT_FOUND 0Xffffffff + +/* + * Options for Deconstruct + */ +#define D3DDECONSTRUCT_DISABLE_OPTIMIZATION 0x00000001 + +/* + * Options for BeginReconstruction + */ +#define D3DRECONSTRUCT_VERIFY 0x00000001 + +/* + * Options for GetClone/CreateClone + */ +#define D3DGETCLONE_COPYFIXUPS 0x00000800 + +/* + * Options for BeginConditionalSurvey + */ +#define D3DSURVEYBEGIN_CULLGEOMETRY 0x1 + +/* + * Options for EndConditionalSurvey + */ +#define D3DSURVEYEND_SUSPEND 0x1 + +/* + * Options for CreateAsyncCommandBufferCall + */ +#define D3DCREATEASYNCCBCALL_TILING_PREDICATE_WHOLE 0x00000100 + +/* + * Options for AsyncCommandBufferCall_FixupAndSignal + */ +#define D3DFIXUPASYNCCBCALL_USE_PREDICATION_SELECT_FROM_INSERT 0x00000001 + +/* + * Options for InsertAsyncCommandBufferCall + */ +#define D3DINSERTASYNCCBCALL_NO_OVERFLOW_WAIT 0x00000001 + +/* + * Options for SetShaderGPRAllocation + */ +#define D3DSETALLOCATION_PREDICATED 0x1 + +/* + * Options for BeginExport + */ +#define D3DBEGINEXPORT_VERTEXSHADER 0x0 +#define D3DBEGINEXPORT_PIXELSHADER 0x1 + +/* + * Options for EndExport + */ +#define D3DENDEXPORT_NOT_DONE_EXPORTING 0x1 + +/* + * Options for InvalidateGpuCache and InvalidateResourceGpuCache + */ + +#define D3DINVALIDATEGPUCACHE_INLINE 0x1 + + +/* + * The following defines the rendering states + */ +typedef enum _D3DFILLMODE { + D3DFILL_POINT = 0x01, + D3DFILL_WIREFRAME = 0x25, + D3DFILL_SOLID = 0x00, + D3DFILL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DFILLMODE; + +typedef enum _D3DBLEND { + D3DBLEND_ZERO = 0, + D3DBLEND_ONE = 1, + D3DBLEND_SRCCOLOR = 4, + D3DBLEND_INVSRCCOLOR = 5, + D3DBLEND_SRCALPHA = 6, + D3DBLEND_INVSRCALPHA = 7, + D3DBLEND_DESTCOLOR = 8, + D3DBLEND_INVDESTCOLOR = 9, + D3DBLEND_DESTALPHA = 10, + D3DBLEND_INVDESTALPHA = 11, + D3DBLEND_BLENDFACTOR = 12, + D3DBLEND_INVBLENDFACTOR = 13, + D3DBLEND_CONSTANTALPHA = 14, // Xbox 360 extension + D3DBLEND_INVCONSTANTALPHA = 15, // Xbox 360 extension + D3DBLEND_SRCALPHASAT = 16, + + // The following are not supported on Xbox 360: + // + // D3DBLEND_BOTHSRCALPHA + // D3DBLEND_BOTHINVSRCALPHA + + D3DBLEND_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DBLEND; + +typedef enum _D3DBLENDOP { + D3DBLENDOP_ADD = 0, + D3DBLENDOP_SUBTRACT = 1, + D3DBLENDOP_MIN = 2, + D3DBLENDOP_MAX = 3, + D3DBLENDOP_REVSUBTRACT = 4, + D3DBLENDOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DBLENDOP; + +typedef enum _D3DTEXTUREADDRESS { + D3DTADDRESS_WRAP = 0, + D3DTADDRESS_MIRROR = 1, + D3DTADDRESS_CLAMP = 2, + D3DTADDRESS_MIRRORONCE = 3, + D3DTADDRESS_BORDER_HALF = 4, + D3DTADDRESS_MIRRORONCE_BORDER_HALF = 5, + D3DTADDRESS_BORDER = 6, + D3DTADDRESS_MIRRORONCE_BORDER = 7, + + D3DTADDRESS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTEXTUREADDRESS; + +typedef enum _D3DCULL { + D3DCULL_NONE = 0x0, + D3DCULL_CW = 0x2, + D3DCULL_CCW = 0x6, + D3DCULL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DCULL; + +typedef enum _D3DCMPFUNC { + D3DCMP_NEVER = 0, + D3DCMP_LESS = 1, + D3DCMP_EQUAL = 2, + D3DCMP_LESSEQUAL = 3, + D3DCMP_GREATER = 4, + D3DCMP_NOTEQUAL = 5, + D3DCMP_GREATEREQUAL = 6, + D3DCMP_ALWAYS = 7, + D3DCMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DCMPFUNC; + +typedef enum _D3DSTENCILOP { + D3DSTENCILOP_KEEP = 0, + D3DSTENCILOP_ZERO = 1, + D3DSTENCILOP_REPLACE = 2, + D3DSTENCILOP_INCRSAT = 3, + D3DSTENCILOP_DECRSAT = 4, + D3DSTENCILOP_INVERT = 5, + D3DSTENCILOP_INCR = 6, + D3DSTENCILOP_DECR = 7, + D3DSTENCILOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DSTENCILOP; + +typedef enum _D3DZBUFFERTYPE { + D3DZB_FALSE = 0, + D3DZB_TRUE = 1, // Z buffering + D3DZB_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ + + // D3DZB_USEW is not supported on Xbox 360 + +} D3DZBUFFERTYPE; + +typedef enum _D3DTESSELLATIONMODE { + D3DTM_DISCRETE = 0, + D3DTM_CONTINUOUS = 1, + D3DTM_PEREDGE = 2, + D3DTM_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTESSELLATIONMODE; + +// Primitives supported by draw-primitive API +typedef enum _D3DPRIMITIVETYPE { + D3DPT_POINTLIST = 1, + D3DPT_LINELIST = 2, + D3DPT_LINESTRIP = 3, + D3DPT_TRIANGLELIST = 4, + D3DPT_TRIANGLEFAN = 5, + D3DPT_TRIANGLESTRIP = 6, + D3DPT_RECTLIST = 8, // Xbox 360 extension + D3DPT_QUADLIST = 13, // Xbox 360 extension + + D3DPT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DPRIMITIVETYPE; + +// Primitives supported by DrawTessellatedPrimitive and DrawIndexedTessellatedPrimitive. +typedef enum _D3DTESSPRIMITIVETYPE { + D3DTPT_LINELIST = 2, + D3DTPT_LINESTRIP = 3, + D3DTPT_TRIANGLELIST = 4, + D3DTPT_TRIANGLEFAN = 5, + D3DTPT_TRIANGLESTRIP = 6, + D3DTPT_QUADLIST = 13, + D3DTPT_LINEPATCH = 16, + D3DTPT_TRIPATCH = 17, + D3DTPT_QUADPATCH = 18, + + D3DTPT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DTESSPRIMITIVETYPE; + +typedef struct _D3DBLENDSTATE { + DWORD SrcBlend : 5; /* D3DBLEND */ + DWORD BlendOp : 3; /* D3DBLENDOP */ + DWORD DestBlend : 8; /* D3DBLEND */ + DWORD SrcBlendAlpha : 5; /* D3DBLEND */ + DWORD BlendOpAlpha : 3; /* D3DBLENDOP */ + DWORD DestBlendAlpha : 8; /* D3DBLEND */ +} D3DBLENDSTATE; + +typedef enum _D3DHISTENCILCMPFUNC { + D3DHSCMP_EQUAL = 0, + D3DHSCMP_NOTEQUAL = 1, + + D3DHSCMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DHISTENCILCMPFUNC; + +typedef enum _D3DHIZENABLEMODE { + D3DHIZ_DISABLE = 0, + D3DHIZ_ENABLE = 1, + D3DHIZ_AUTOMATIC = 2, + + D3DHIZ_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DHIZENABLEMODE; + +typedef enum _D3DRENDERSTATETYPE { + + // The following are standard render states: + + D3DRS_ZENABLE = 40, /* TRUE to enable Z buffering */ + D3DRS_ZFUNC = 44, /* D3DCMPFUNC */ + D3DRS_ZWRITEENABLE = 48, /* TRUE to enable z writes */ + D3DRS_FILLMODE = 52, /* D3DFILLMODE */ + D3DRS_CULLMODE = 56, /* D3DCULL */ + D3DRS_ALPHABLENDENABLE = 60, /* TRUE to enable alpha blending */ + D3DRS_SEPARATEALPHABLENDENABLE = 64, /* TRUE to enable a separate blending function for the alpha channel */ + D3DRS_BLENDFACTOR = 68, /* D3DCOLOR used for a constant blend factor during alpha blending for D3DBLEND_BLENDFACTOR, etc. */ + D3DRS_SRCBLEND = 72, /* D3DBLEND */ + D3DRS_DESTBLEND = 76, /* D3DBLEND */ + D3DRS_BLENDOP = 80, /* D3DBLENDOP setting */ + D3DRS_SRCBLENDALPHA = 84, /* SRC blend factor for the alpha channel when D3DRS_SEPARATEALPHABLENDENABLE is TRUE */ + D3DRS_DESTBLENDALPHA = 88, /* DST blend factor for the alpha channel when D3DRS_SEPARATEALPHABLENDENABLE is TRUE */ + D3DRS_BLENDOPALPHA = 92, /* Blending operation for the alpha channel when D3DRS_SEPARATEALPHABLENDENABLE is TRUE */ + D3DRS_ALPHATESTENABLE = 96, /* TRUE to enable alpha tests */ + D3DRS_ALPHAREF = 100, /* BYTE */ + D3DRS_ALPHAFUNC = 104, /* D3DCMPFUNC */ + D3DRS_STENCILENABLE = 108, /* TRUE to enable stenciling */ + D3DRS_TWOSIDEDSTENCILMODE = 112, /* TRUE to enable 2 sided stenciling */ + D3DRS_STENCILFAIL = 116, /* D3DSTENCILOP to do if stencil test fails */ + D3DRS_STENCILZFAIL = 120, /* D3DSTENCILOP to do if stencil test passes and Z test fails */ + D3DRS_STENCILPASS = 124, /* D3DSTENCILOP to do if both stencil and Z tests pass */ + D3DRS_STENCILFUNC = 128, /* D3DCMPFUNC stencilfn - stencil test passes if ((ref & mask) stencilfn (stencil & mask)) is true */ + D3DRS_STENCILREF = 132, /* BYTE reference value used in stencil test */ + D3DRS_STENCILMASK = 136, /* BYTE mask value used in stencil test */ + D3DRS_STENCILWRITEMASK = 140, /* BYTE write mask applied to values written to stencil buffer */ + D3DRS_CCW_STENCILFAIL = 144, /* D3DSTENCILOP to do if CCW stencil test fails */ + D3DRS_CCW_STENCILZFAIL = 148, /* D3DSTENCILOP to do if CCW stencil test passes and Z test fails */ + D3DRS_CCW_STENCILPASS = 152, /* D3DSTENCILOP to do if both CCW stencil and Z tests pass */ + D3DRS_CCW_STENCILFUNC = 156, /* D3DCMPFUNC stencilfn - CCW stencil test passes if ((ref & mask) stencilfn (stencil & mask)) is true */ + D3DRS_CCW_STENCILREF = 160, /* BYTE reference value used in CCW stencil test */ + D3DRS_CCW_STENCILMASK = 164, /* BYTE mask value used in CCW stencil test */ + D3DRS_CCW_STENCILWRITEMASK = 168, /* BYTE write mask applied to CCW values written to stencil buffer */ + D3DRS_CLIPPLANEENABLE = 172, /* TRUE to enable SetClipPlane */ + D3DRS_POINTSIZE = 176, /* FLOAT point size */ + D3DRS_POINTSIZE_MIN = 180, /* FLOAT point size min threshold */ + D3DRS_POINTSPRITEENABLE = 184, /* TRUE to enable point sprites */ + D3DRS_POINTSIZE_MAX = 188, /* FLOAT point size max threshold */ + D3DRS_MULTISAMPLEANTIALIAS = 192, /* TRUE to enable multisample antialiasing */ + D3DRS_MULTISAMPLEMASK = 196, /* DWORD per-pixel and per-sample enable/disable */ + D3DRS_SCISSORTESTENABLE = 200, /* TRUE to enable SetScissorRect */ + D3DRS_SLOPESCALEDEPTHBIAS = 204, /* FLOAT depth-slope scaling bias */ + D3DRS_DEPTHBIAS = 208, /* FLOAT depth bias */ + D3DRS_COLORWRITEENABLE = 212, /* D3DCOLORWRITEENABLE_ALPHA, etc. per-channel write enable */ + D3DRS_COLORWRITEENABLE1 = 216, + D3DRS_COLORWRITEENABLE2 = 220, + D3DRS_COLORWRITEENABLE3 = 224, + D3DRS_TESSELLATIONMODE = 228, /* D3DTESSELLATIONMODE */ + D3DRS_MINTESSELLATIONLEVEL = 232, /* FLOAT */ + D3DRS_MAXTESSELLATIONLEVEL = 236, /* FLOAT */ + D3DRS_WRAP0 = 240, /* D3DWRAPCOORD_0, etc. for 1st texture coord. set */ + D3DRS_WRAP1 = 244, + D3DRS_WRAP2 = 248, + D3DRS_WRAP3 = 252, + D3DRS_WRAP4 = 256, + D3DRS_WRAP5 = 260, + D3DRS_WRAP6 = 264, + D3DRS_WRAP7 = 268, + D3DRS_WRAP8 = 272, + D3DRS_WRAP9 = 276, + D3DRS_WRAP10 = 280, + D3DRS_WRAP11 = 284, + D3DRS_WRAP12 = 288, + D3DRS_WRAP13 = 292, + D3DRS_WRAP14 = 296, + D3DRS_WRAP15 = 300, + + // The following are Xbox 360 extensions: + + D3DRS_VIEWPORTENABLE = 304, /* TRUE to enable viewport transformation */ + D3DRS_HIGHPRECISIONBLENDENABLE = 308, /* TRUE to enable higher precision blending operations for 2_10_10_10 and 2_10_10_10_FLOAT */ + D3DRS_HIGHPRECISIONBLENDENABLE1 = 312, /* render targets at the expense of running at half rate. 2_10_10_10 surfaces are expanded */ + D3DRS_HIGHPRECISIONBLENDENABLE2 = 316, /* out to 10:10:10:10 before the blend and 2_10_10_10_FLOAT surfaces are expanded out to */ + D3DRS_HIGHPRECISIONBLENDENABLE3 = 320, /* 16:16:16:16 before the blend. The default value is FALSE. */ + D3DRS_HALFPIXELOFFSET = 324, /* TRUE to enable (0.5, 0.5) screen-space offset */ + D3DRS_PRIMITIVERESETENABLE = 328, /* TRUE to enable primitive resets in indexed drawing. The default value is FALSE. */ + D3DRS_PRIMITIVERESETINDEX = 332, /* WORD Index reference value to trigger a primitive reset. The default value is 0xFFFF. */ + D3DRS_ALPHATOMASKENABLE = 336, /* TRUE to enable alpha to mask. The default value is FALSE. */ + D3DRS_ALPHATOMASKOFFSETS = 340, /* BYTE Packed offsets (2:2:2:2) to apply to the alpha value for each pixel in quad before it is converted to a mask. */ + D3DRS_GUARDBAND_X = 344, /* FLOAT horizontal guard band factor */ + D3DRS_GUARDBAND_Y = 348, /* FLOAT vertical guard band factor */ + D3DRS_DISCARDBAND_X = 352, /* FLOAT horizontal discard band factor */ + D3DRS_DISCARDBAND_Y = 356, /* FLOAT vertical discard band factor */ + D3DRS_HISTENCILENABLE = 360, /* TRUE to enable early culling based on hi-stencil bit */ + D3DRS_HISTENCILWRITEENABLE = 364, /* TRUE to enable update of hi-stencil bit based on hi-stencil test */ + D3DRS_HISTENCILFUNC = 368, /* D3DHISTENCILCMPFUNC - bit is set to cull if (ref histencilfn stencil) is true */ + D3DRS_HISTENCILREF = 372, /* BYTE reference value used in hi-stencil test */ + D3DRS_PRESENTINTERVAL = 376, /* D3DPRESENT_INTERVAL_ONE, etc. */ + D3DRS_PRESENTIMMEDIATETHRESHOLD = 380, /* BYTE percentage of DAC's progress in frame where a non-D3DPRESENT_INTERVAL_IMMEDIATE Present/Swap will be considered for immediate Present/Swap */ + D3DRS_HIZENABLE = 384, /* D3DHIZENABLEMODE that allows for manual control of hi-z enable */ + D3DRS_HIZWRITEENABLE = 388, /* D3DHIZENABLEMODE that allows for manual control of hi-z write enable */ + D3DRS_LASTPIXEL = 392, /* TRUE to draw the last pixel of a line */ + D3DRS_LINEWIDTH = 396, /* FLOAT width of line */ + D3DRS_BUFFER2FRAMES = 400, /* TRUE to enable D3DCREATE_BUFFER_2_FRAMES functionality */ + + D3DRS_MAX = 404, + + // The following render states are not supported on Xbox 360: + // + // D3DRS_SRGBWRITEENABLE (sRGB instead supported through the surface format) + // D3DRS_SHADEMODE + // D3DRS_CLIPPING + + D3DRS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DRENDERSTATETYPE; + +// Maximum number of simultaneous render targets D3D supports +#define D3D_MAX_SIMULTANEOUS_RENDERTARGETS 4 + +// Xbox 360 replacement for D3DRENDERSTATE_WRAPBIAS (which is not supported on Xbox 360.) +// For Windows you could use this implementation: +// #define D3DRENDERSTATE_WRAP(N) ((((INT) (N)) & 0xf) + D3DRS_WRAP0) + +#define D3DRENDERSTATE_WRAP(N) (((((INT) (N)) & 0xf) << 2) + D3DRS_WRAP0) + +/* Flags to construct the WRAP render states */ +#define D3DWRAP_U 0x00000001L +#define D3DWRAP_V 0x00000002L +#define D3DWRAP_W 0x00000004L + +/* Flags to construct the WRAP render states for 1D thru 4D texture coordinates */ +#define D3DWRAPCOORD_0 0x00000001L // same as D3DWRAP_U +#define D3DWRAPCOORD_1 0x00000002L // same as D3DWRAP_V +#define D3DWRAPCOORD_2 0x00000004L // same as D3DWRAP_W +#define D3DWRAPCOORD_3 0x00000008L + +/* Flags to construct D3DRS_COLORWRITEENABLE */ +#define D3DCOLORWRITEENABLE_RED (1L<<0) +#define D3DCOLORWRITEENABLE_GREEN (1L<<1) +#define D3DCOLORWRITEENABLE_BLUE (1L<<2) +#define D3DCOLORWRITEENABLE_ALPHA (1L<<3) +#define D3DCOLORWRITEENABLE_ALL 0xf // Xbox 360 extension + +/* Predefined values for D3DRS_ALPHATOMASKOFFSETS */ +#define D3DALPHATOMASK_DITHERED 0x00000087 +#define D3DALPHATOMASK_SOLID 0x000000AA + +/* + * State enumerants for per-sampler texture processing. + */ +typedef enum _D3DSAMPLERSTATETYPE +{ + D3DSAMP_ADDRESSU = 0, /* D3DTEXTUREADDRESS for U coordinate */ + D3DSAMP_ADDRESSV = 4, /* D3DTEXTUREADDRESS for V coordinate */ + D3DSAMP_ADDRESSW = 8, /* D3DTEXTUREADDRESS for W coordinate */ + D3DSAMP_BORDERCOLOR = 12, /* D3DCOLOR */ + D3DSAMP_MAGFILTER = 16, /* D3DTEXTUREFILTERTYPE filter to use for magnification */ + D3DSAMP_MINFILTER = 20, /* D3DTEXTUREFILTERTYPE filter to use for minification */ + D3DSAMP_MIPFILTER = 24, /* D3DTEXTUREFILTERTYPE filter to use between mipmaps during minification */ + D3DSAMP_MIPMAPLODBIAS = 28, /* Float Mipmap LOD bias */ + D3DSAMP_MAXMIPLEVEL = 32, /* DWORD 0..(n-1) LOD index of largest map to use (0 == largest) */ + D3DSAMP_MAXANISOTROPY = 36, /* DWORD maximum anisotropy */ + + // The following are Xbox 360 extensions: + + D3DSAMP_MAGFILTERZ = 40, /* D3DTEXTUREFILTERTYPE filter to use for volume/array slice magnification */ + D3DSAMP_MINFILTERZ = 44, /* D3DTEXTUREFILTERTYPE filter to use for volume/array slice minification */ + D3DSAMP_SEPARATEZFILTERENABLE = 48, /* TRUE to use MIN/MAGFILTERZ for slice filtering. FALSE to use MIN/MAGFILTER */ + D3DSAMP_MINMIPLEVEL = 52, /* DWORD 0..(n-1) LOD index of smallest map to use (0 == highest resolution map) */ + D3DSAMP_TRILINEARTHRESHOLD = 56, /* D3DTRILINEARTHRESHOLD trilinear filtering range threshold */ + D3DSAMP_ANISOTROPYBIAS = 60, /* Float bias to add to anisotropy ratio ranging from -1.875 to 0.0 */ + D3DSAMP_HGRADIENTEXPBIAS = 64, /* Signed integer bias to add to the horizontal LOD gradient ranging from -16 to 15 */ + D3DSAMP_VGRADIENTEXPBIAS = 68, /* Signed integer bias to add to the vertical LOD gradient ranging from -16 to 15 */ + D3DSAMP_WHITEBORDERCOLORW = 72, /* TRUE to override the w component of the border color with white */ + D3DSAMP_POINTBORDERENABLE = 76, /* FALSE to disable border addressing when using point filtering */ + + D3DSAMP_MAX = 80, + + // The following sampler states are not supported by Xbox 360: + // + // D3DSAMP_ELEMENTINDEX + // D3DSAMP_DMAPOFFSET + + D3DSAMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ + +} D3DSAMPLERSTATETYPE; + +/* Special sampler which is used in the tesselator */ +#define D3DDMAPSAMPLER (16) + +// Samplers used in vertex shaders +#define D3DVERTEXTEXTURESAMPLER0 ((DWORD) (D3DDMAPSAMPLER+0)) +#define D3DVERTEXTEXTURESAMPLER1 ((DWORD) (D3DDMAPSAMPLER+1)) +#define D3DVERTEXTEXTURESAMPLER2 ((DWORD) (D3DDMAPSAMPLER+2)) +#define D3DVERTEXTEXTURESAMPLER3 ((DWORD) (D3DDMAPSAMPLER+3)) + +// +// Values for D3DSAMP_***FILTER texture stage states +// +typedef enum _D3DTEXTUREFILTERTYPE +{ + D3DTEXF_NONE = 2, // filtering disabled (valid for mip filter only) + D3DTEXF_POINT = 0, // nearest + D3DTEXF_LINEAR = 1, // linear interpolation + D3DTEXF_ANISOTROPIC = 4, // anisotropic + + D3DTEXF_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum + + // The following are not supported on Xbox 360: + // + // D3DTEXF_PYRAMIDALQUAD + // D3DTEXF_GAUSSIANQUAD + +} D3DTEXTUREFILTERTYPE; + +// +// Values for D3DSAMP_TRILINEARTHRESHOLD sampler state +// + +typedef enum _D3DTRILINEARTHRESHOLD +{ + D3DTRILINEAR_IMMEDIATE = 0, + D3DTRILINEAR_ONESIXTH = 1, + D3DTRILINEAR_ONEFOURTH = 2, + D3DTRILINEAR_THREEEIGHTHS = 3, + + D3DTRILINEAR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum + +} D3DTRILINEARTHRESHOLD; + +/* Bits for Flags in ProcessVertices call */ + +#define D3DPV_DONOTCOPYDATA (1 << 0) + +//------------------------------------------------------------------- +// Flexible vertex format bits +// +#define D3DFVF_RESERVED0 0x001 +#define D3DFVF_POSITION_MASK 0x400E +#define D3DFVF_XYZ 0x002 +#define D3DFVF_XYZB1 0x006 +#define D3DFVF_XYZB2 0x008 +#define D3DFVF_XYZB3 0x00a +#define D3DFVF_XYZB4 0x00c +#define D3DFVF_XYZB5 0x00e +#define D3DFVF_XYZW 0x4002 + +#define D3DFVF_NORMAL 0x010 +#define D3DFVF_PSIZE 0x020 +#define D3DFVF_DIFFUSE 0x040 +#define D3DFVF_SPECULAR 0x080 + +#define D3DFVF_TEXCOUNT_MASK 0xf00 +#define D3DFVF_TEXCOUNT_SHIFT 8 +#define D3DFVF_TEX0 0x000 +#define D3DFVF_TEX1 0x100 +#define D3DFVF_TEX2 0x200 +#define D3DFVF_TEX3 0x300 +#define D3DFVF_TEX4 0x400 +#define D3DFVF_TEX5 0x500 +#define D3DFVF_TEX6 0x600 +#define D3DFVF_TEX7 0x700 +#define D3DFVF_TEX8 0x800 + +#define D3DFVF_LASTBETA_UBYTE4 0x1000 +#define D3DFVF_LASTBETA_D3DCOLOR 0x8000 + +#define D3DFVF_RESERVED2 0x6000 // 2 reserved bits + +//--------------------------------------------------------------------- +// Vertex Shaders +// + +// Vertex shader declaration + +// Vertex element semantics +// +typedef enum _D3DDECLUSAGE +{ + D3DDECLUSAGE_POSITION = 0, + D3DDECLUSAGE_BLENDWEIGHT, // 1 + D3DDECLUSAGE_BLENDINDICES, // 2 + D3DDECLUSAGE_NORMAL, // 3 + D3DDECLUSAGE_PSIZE, // 4 + D3DDECLUSAGE_TEXCOORD, // 5 + D3DDECLUSAGE_TANGENT, // 6 + D3DDECLUSAGE_BINORMAL, // 7 + D3DDECLUSAGE_TESSFACTOR, // 8 + D3DDECLUSAGE_COLOR=10, // 10 + D3DDECLUSAGE_FOG, // 11 + D3DDECLUSAGE_DEPTH, // 12 + D3DDECLUSAGE_SAMPLE, // 13 +} D3DDECLUSAGE; + +#define MAXD3DDECLUSAGE D3DDECLUSAGE_SAMPLE +#define MAXD3DDECLUSAGEINDEX 15 +#define MAXD3DDECLLENGTH 64 // does not include "end" marker vertex element + +typedef enum _D3DDECLMETHOD +{ + D3DDECLMETHOD_DEFAULT = 0, + D3DDECLMETHOD_PARTIALU, + D3DDECLMETHOD_PARTIALV, + D3DDECLMETHOD_CROSSUV, // Normal + D3DDECLMETHOD_UV, + D3DDECLMETHOD_LOOKUP, // Lookup a displacement map + D3DDECLMETHOD_LOOKUPPRESAMPLED, // Lookup a pre-sampled displacement map +} D3DDECLMETHOD; + +#define MAXD3DDECLMETHOD D3DDECLMETHOD_LOOKUPPRESAMPLED + +// A D3DDECLTYPE constant is an identifier that uniquely identifies +// a vertex format. It contains the following fields: + +#define D3DDECLTYPE_VERTEXFORMAT_SHIFT 0 // GPUVERTEXFORMAT +#define D3DDECLTYPE_ENDIAN_SHIFT 6 // GPUENDIAN +#define D3DDECLTYPE_VERTEXSIGN_SHIFT 8 // GPUVERTEXSIGN +#define D3DDECLTYPE_NUMFORMAT_SHIFT 9 // GPUNUMFORMAT +#define D3DDECLTYPE_SWIZZLEX_SHIFT 10 // GPUSWIZZLE +#define D3DDECLTYPE_SWIZZLEY_SHIFT 13 // GPUSWIZZLE +#define D3DDECLTYPE_SWIZZLEZ_SHIFT 16 // GPUSWIZZLE +#define D3DDECLTYPE_SWIZZLEW_SHIFT 19 // GPUSWIZZLE + +#define D3DDECLTYPE_VERTEXFORMAT_MASK 0x0000003f +#define D3DDECLTYPE_ENDIAN_MASK 0x000000c0 +#define D3DDECLTYPE_VERTEXSIGN_MASK 0x00000100 +#define D3DDECLTYPE_NUMFORMAT_MASK 0x00000200 +#define D3DDECLTYPE_SWIZZLEX_MASK 0x00001c00 +#define D3DDECLTYPE_SWIZZLEY_MASK 0x0000e000 +#define D3DDECLTYPE_SWIZZLEZ_MASK 0x00070000 +#define D3DDECLTYPE_SWIZZLEW_MASK 0x00380000 + +#define MAKED3DDECLTYPE(VertexFormat, Endian, VertexSign, NumFormat, Swizzle) \ + ((VertexFormat) << D3DDECLTYPE_VERTEXFORMAT_SHIFT | \ + (Endian) << D3DDECLTYPE_ENDIAN_SHIFT | \ + (VertexSign) << D3DDECLTYPE_VERTEXSIGN_SHIFT | \ + (NumFormat) << D3DDECLTYPE_NUMFORMAT_SHIFT | \ + (Swizzle) << D3DDECLTYPE_SWIZZLEX_SHIFT) + +#define MAKED3DDECLTYPE2(VertexFormat, Endian, VertexSign, NumFormat, SwizzleX, SwizzleY, SwizzleZ, SwizzleW) \ + ((VertexFormat) << D3DDECLTYPE_VERTEXFORMAT_SHIFT | \ + (Endian) << D3DDECLTYPE_ENDIAN_SHIFT | \ + (VertexSign) << D3DDECLTYPE_VERTEXSIGN_SHIFT | \ + (NumFormat) << D3DDECLTYPE_NUMFORMAT_SHIFT | \ + (SwizzleX) << D3DDECLTYPE_SWIZZLEX_SHIFT | \ + (SwizzleY) << D3DDECLTYPE_SWIZZLEY_SHIFT | \ + (SwizzleZ) << D3DDECLTYPE_SWIZZLEZ_SHIFT | \ + (SwizzleW) << D3DDECLTYPE_SWIZZLEW_SHIFT) + +typedef enum _D3DDECLTYPE +{ + // 1D float expanded to (value, 0., 0., 1.) + D3DDECLTYPE_FLOAT1 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_FLOAT, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_0, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 2D float expanded to (value, value, 0., 1.) + D3DDECLTYPE_FLOAT2 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_32_FLOAT, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 3D float expanded to (value, value, value, 1.) + D3DDECLTYPE_FLOAT3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_32_32_FLOAT, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 4D float + D3DDECLTYPE_FLOAT4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_32_32_32_32_FLOAT, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // 1D signed int expanded to (value, 0., 0., 1.) + D3DDECLTYPE_INT1 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_0, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 2D signed int expanded to (value, value, 0., 1.) + D3DDECLTYPE_INT2 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D signed int + D3DDECLTYPE_INT4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_32_32_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // 1D unsigned int expanded to (value, 0., 0., 1.) + D3DDECLTYPE_UINT1 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_0, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 2D unsigned int expanded to (value, value, 0., 1.) + D3DDECLTYPE_UINT2 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D unsigned int + D3DDECLTYPE_UINT4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_32_32_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // 1D signed int normalized + D3DDECLTYPE_INT1N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_0, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 2D signed int normalized + D3DDECLTYPE_INT2N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D signed int normalized + D3DDECLTYPE_INT4N = MAKED3DDECLTYPE(GPUVERTEXFORMAT_32_32_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ABGR), + + // 1D unsigned int normalized + D3DDECLTYPE_UINT1N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_0, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 2D unsigned int normalized + D3DDECLTYPE_UINT2N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D unsigned int normalized + D3DDECLTYPE_UINT4N = MAKED3DDECLTYPE(GPUVERTEXFORMAT_32_32_32_32, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ABGR), + + // 4D packed unsigned bytes mapped to 0. to 1. range + // Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A) + D3DDECLTYPE_D3DCOLOR = MAKED3DDECLTYPE(GPUVERTEXFORMAT_8_8_8_8, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ARGB), + + // 4D unsigned byte + D3DDECLTYPE_UBYTE4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_8_8_8_8, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // 4D signed byte + D3DDECLTYPE_BYTE4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_8_8_8_8, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // Each of 4 bytes is normalized by dividing to 255.0 + D3DDECLTYPE_UBYTE4N = MAKED3DDECLTYPE(GPUVERTEXFORMAT_8_8_8_8, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ABGR), + + // Each of 4 bytes is normalized by dividing to 127.0 + D3DDECLTYPE_BYTE4N = MAKED3DDECLTYPE(GPUVERTEXFORMAT_8_8_8_8, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ABGR), + + // 2D signed short expanded to (value, value, 0., 1.) + D3DDECLTYPE_SHORT2 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D signed short + D3DDECLTYPE_SHORT4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_16_16_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // 2D unsigned short expanded to (value, value, 0., 1.) + D3DDECLTYPE_USHORT2 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D unsigned short + D3DDECLTYPE_USHORT4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_16_16_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // 2D signed short normalized (v[0]/32767.0,v[1]/32767.0,0,1) + D3DDECLTYPE_SHORT2N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D signed short normalized (v[0]/32767.0,v[1]/32767.0,v[2]/32767.0,v[3]/32767.0) + D3DDECLTYPE_SHORT4N = MAKED3DDECLTYPE(GPUVERTEXFORMAT_16_16_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ABGR), + + // 2D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,0,1) + D3DDECLTYPE_USHORT2N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // 4D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,v[2]/65535.0,v[3]/65535.0) + D3DDECLTYPE_USHORT4N = MAKED3DDECLTYPE(GPUVERTEXFORMAT_16_16_16_16, GPUENDIAN_8IN16, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_ABGR), + + // 3D unsigned 10 10 10 format expanded to (value, value, value, 1) + D3DDECLTYPE_UDEC3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D signed 10 10 10 format expanded to (value, value, value, 1) + D3DDECLTYPE_DEC3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D unsigned 10 10 10 format normalized and expanded to (v[0]/1023.0, v[1]/1023.0, v[2]/1023.0, 1) + D3DDECLTYPE_UDEC3N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D signed 10 10 10 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, 1) + D3DDECLTYPE_DEC3N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 4D unsigned 10 10 10 2 format expanded to (value, value, value, value) + D3DDECLTYPE_UDEC4 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_W), + + // 4D signed 10 10 10 2 format expanded to (value, value, value, value) + D3DDECLTYPE_DEC4 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_W), + + // 4D unsigned 10 10 10 2 format normalized and expanded to (v[0]/1023.0, v[1]/1023.0, v[2]/1023.0, v[3]/3.0) + D3DDECLTYPE_UDEC4N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_W), + + // 4D signed 10 10 10 2 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, v[3]/1.0) + D3DDECLTYPE_DEC4N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_2_10_10_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_W), + + // 3D unsigned 11 11 10 format expanded to (value, value, value, 1) + D3DDECLTYPE_UHEND3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_10_11_11, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D signed 11 11 10 format expanded to (value, value, value, 1) + D3DDECLTYPE_HEND3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_10_11_11, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D unsigned 11 11 10 format normalized and expanded to (v[0]/2047.0, v[1]/2047.0, v[2]/1023.0, 1) + D3DDECLTYPE_UHEND3N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_10_11_11, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D signed 11 11 10 format normalized and expanded to (v[0]/1023.0, v[1]/1023.0, v[2]/511.0, 1) + D3DDECLTYPE_HEND3N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_10_11_11, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D unsigned 10 11 11 format expanded to (value, value, value, 1) + D3DDECLTYPE_UDHEN3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_11_11_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D signed 10 11 11 format expanded to (value, value, value, 1) + D3DDECLTYPE_DHEN3 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_11_11_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D unsigned 10 11 11 format normalized and expanded to (v[0]/1023.0, v[1]/2047.0, v[2]/2047.0, 1) + D3DDECLTYPE_UDHEN3N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_11_11_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_UNSIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // 3D signed 10 11 11 format normalized and expanded to (v[0]/511.0, v[1]/1023.0, v[2]/1023.0, 1) + D3DDECLTYPE_DHEN3N = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_11_11_10, GPUENDIAN_8IN32, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_FRACTION, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_Z, GPUSWIZZLE_1), + + // Two 16-bit floating point values, expanded to (value, value, 0, 1) + D3DDECLTYPE_FLOAT16_2 = MAKED3DDECLTYPE2(GPUVERTEXFORMAT_16_16_FLOAT, GPUENDIAN_8IN16, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_X, GPUSWIZZLE_Y, GPUSWIZZLE_0, GPUSWIZZLE_1), + + // Four 16-bit floating point values + D3DDECLTYPE_FLOAT16_4 = MAKED3DDECLTYPE(GPUVERTEXFORMAT_16_16_16_16_FLOAT, GPUENDIAN_8IN16, GPUVERTEXSIGN_SIGNED, GPUNUMFORMAT_INTEGER, GPUSWIZZLE_ABGR), + + // When the type field in a decl is unused. + D3DDECLTYPE_UNUSED = 0xffffffff, + +} D3DDECLTYPE; + +#define MAXD3DDECLTYPE D3DDECLTYPE_UNUSED + +typedef struct _D3DVERTEXELEMENT9 +{ + WORD Stream; // Stream index + WORD Offset; // Offset in the stream in bytes + DWORD Type; // Data type, e.g. D3DDECLTYPE_FLOAT3 + BYTE Method; // Processing method, e.g. D3DDECLMETHOD_DEFAULT + BYTE Usage; // Semantics, e.g. D3DDECLUSAGE_POSITION + BYTE UsageIndex; // Semantic index +} D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9; + +// This is used to initialize the last vertex element in a vertex declaration +// array +// +#define D3DDECL_END() {0xFF,0,(DWORD)D3DDECLTYPE_UNUSED,0,0,0} + +// Maximum supported number of texture coordinate sets +#define D3DDP_MAXTEXCOORD 8 + +//--------------------------------------------------------------------- +// +// Pixel Shader (PS) & Vertex Shader (VS) Instruction Token Definition +// +//--------------------------------------------------------------------- +// Version token format +// +// [07:00] minor version number +// [15:08] major version number +// [31:16] +// PS 0xFFFF +// VS 0xFFFE +// +//--------------------------------------------------------------------- +// OpCode token format +// +// [15:00] Opcode (D3DSIO_*) +// [23:16] Opcode-Specific Controls +// [27:24] Instruction length in DWORDs excluding the opcode token +// (version >= 2_0) +// [28] ps/vs < 2_x: Reserved 0x0 +// ps/vs >= 2_x: 1 means instruction is predicated +// (extra predicate source token at end) +// [29] Reserved 0x0 +// [30] ps_1_x: Co-issue flag (this inst and prev are parallel) +// ps > 1_x and all vs: Reserved 0x0 +// [31] 0x0 +// +//--------------------------------------------------------------------- +// End Token format +// +// [31:00] 0x0000FFFF +// +//--------------------------------------------------------------------- +// Comment Token format +// +// [15:00] 0xFFFE +// [30:16] DWORD Length (up to 2^15 DWORDS = 128KB) +// [31] 0x0 +// +//--------------------------------------------------------------------- +// Destination token format +// +// [10:00] Register Number (offset in register file) +// [11-12] Register type bits [3-4] +// [13] VS (version 3_x) Relative Addressing mode +// VS others Reserved 0x0 +// PS Reserved 0x0 +// [15:14] Reserved 0x0 +// [19:16] Write Mask +// [16] Component 0 (X;Red) +// [17] Component 1 (Y;Green) +// [18] Component 2 (Z;Blue) +// [19] Component 3 (W;Alpha) +// [23:20] +// Result Modifier +// [27:24] +// PS (version < 2_0) Result Shift Scale (signed ) +// VS Reserved 0x0 +// [30:28] Register type bits [0-2] +// [31] 0x1 +// +//--------------------------------------------------------------------- +// Source token format +// +// [10:00] Register Number (offset in register file) +// [11-12] Register type bits [3-4] +// [13] +// VS Relative Addressing mode +// PS (version < 3_0) Reserved 0x0 +// PS (version 3_0) Relative Addressing Mode +// [14:15] +// VS Reserved 0x0 +// PS Reserved 0x0 +// [23:16] Source Component Swizzle +// [17:16] Component 0 Swizzle +// [19:18] Component 1 Swizzle +// [21:20] Component 2 Swizzle +// [23:22] Component 3 Swizzle +// [27:24] Source Modifier +// [30:28] Register type bits [0-2] +// [31] 0x1 +// +// Swizzle defines which input component should be used as output +// component: +// 0 - component X is used +// 1 - component y is used +// 2 - component Z is used +// 3 - component W is used +// +//--------------------------------------------------------------------- +// Vertex shader version >= 2_0 only: +// +// When bit [13] (relative addressing) is set in a src or dest token, +// (where supported in the version) an additional DWORD token follows. +// The token has the same format as the source operand token, with the +// following rules: +// a. only D3DSPR_ADDR or D3DSPR_LOOP could be used as register +// types. +// b. swizzle bits are used to determine a register component +// c. bit[31] is 1 +// d. register offset is used +// e. all other bits are not used +// +//--------------------------------------------------------------------- +// Label token format +// +// (only certain instructions use this token -> for example callnz) +// +// [10:00] Register Number (offset in register file) +// [11:12] Register type bits [3-4] +// [27:13] Reserved 0x0 +// [30:28] Register type bits [0-2] +// [31] 0x1 +// +// Note: +// 1. The format is the same as the source token format,except that only +// register type and offset are used. +// 2. The register type must be D3DSPR_LABEL +// +//--------------------------------------------------------------------- +// DEF instruction format (constant definition) +// +// Token 1: D3DSIO_DEF (with instruction length = 5) +// Token 2: Destination parameter token: c# or i# +// Tokens 3-6: Four 32 bit values. For c# registers, +// these are 32 bit floats, and for i# +// registers, these are 32 bit signed +// integers. +// +//--------------------------------------------------------------------- +// DCL instruction format +// +// ps_2_0+: +// -------- +// s# dcl Format: Token 1: D3DSIO_DCL (with instruction length = 2) +// Token 2: [0-26] = Reserved 0x0 +// [27-30] = D3DSAMPLER_TEXTURE_TYPE (1D, 2D, +// cube, etc.) +// [31] = 1 +// Token 3: Destination parameter token indicating sampler +// "register" (s#). +// Register type == D3DSPR_SAMPLER, and register +// # are only fields used. +// +// v# or t# dcl Format: Token 1: D3DSIO_DCL (with instruction length = 2) +// Token 2: [0-30] = Reserved 0x0 +// [31] = 1 +// Token 3: Destination parameter token indicating v# or +// t# register, and writemask field indicating +// declared components. +// +// vs_2_0+: +// -------- +// v# dcl Format: Token 1: D3DSIO_DCL (with instruction length = 2) +// Token 2: [0-4] = D3DDECLUSAGE (i.e. +// D3DDECLUSAGE_TEXCOORD, _NORMAL etc) +// [5-15] = Reserved 0x0 +// [16-19] = Usage Index +// [20-30] = Reserved 0x0 +// [31] = 1 +// Token 3: Destination parameter token indicating v# +// register, and writemask field indicating +// declared components. +// +// ps_3_0+: +// -------- +// t# dcl Format: Token 1: D3DSIO_DCL (with instruction length = 2) +// Token 2: [0-4] = D3DDECLUSAGE (MUST be +// D3DDECLUSAGE_TEXCOORD +// or D3DDECLUSAGE_COLOR) +// [5-15] = Reserved 0x0 +// [16-19] = Usage Index (for _TEXCOORD must be +// 0-7, else must be 0) +// [20-30] = Reserved 0x0 +// [31] = 1 +// Token 3: Destination parameter token indicating t# +// register, and writemask field indicating +// declared components. +// +// vFace dcl Format: Token 1: D3DSIO_DCL (with instruction length = 2) +// Token 2: [0-30] = Reserved 0x0 +// [31] = 1 +// Token 3: Destination parameter token indicating bf +// (vFace) register. +// Writemask field must be full (although it is +// unused), and result mod/ scale fields all +// must be 0 (also unused). +// +// pos dcl Format Token 1: D3DSIO_DCL (with instruction length = 2) +// Token 2: [0-30] = Reserved 0x0 +// [31] = 1 +// Token 3: Destination parameter token indicating pos +// register, and writemask field indicating +// declared components. +//--------------------------------------------------------------------- + + +//--------------------------------------------------------------------- +// +// The internal format of Pixel Shader (PS) & Vertex Shader (VS) +// Instruction Tokens is defined in the Direct3D Device Driver Kit +// +//--------------------------------------------------------------------- + +// +// Instruction Token Bit Definitions +// +#define D3DSI_OPCODE_MASK 0x0000FFFF + +#define D3DSI_INSTLENGTH_MASK 0x0F000000 +#define D3DSI_INSTLENGTH_SHIFT 24 + +typedef enum _D3DSHADER_INSTRUCTION_OPCODE_TYPE +{ + D3DSIO_NOP = 0, + D3DSIO_MOV , + D3DSIO_ADD , + D3DSIO_SUB , + D3DSIO_MAD , + D3DSIO_MUL , + D3DSIO_RCP , + D3DSIO_RSQ , + D3DSIO_DP3 , + D3DSIO_DP4 , + D3DSIO_MIN , + D3DSIO_MAX , + D3DSIO_SLT , + D3DSIO_SGE , + D3DSIO_EXP , + D3DSIO_LOG , + D3DSIO_LIT , + D3DSIO_DST , + D3DSIO_LRP , + D3DSIO_FRC , + D3DSIO_M4x4 , + D3DSIO_M4x3 , + D3DSIO_M3x4 , + D3DSIO_M3x3 , + D3DSIO_M3x2 , + D3DSIO_CALL , + D3DSIO_CALLNZ , + D3DSIO_LOOP , + D3DSIO_RET , + D3DSIO_ENDLOOP , + D3DSIO_LABEL , + D3DSIO_DCL , + D3DSIO_POW , + D3DSIO_CRS , + D3DSIO_SGN , + D3DSIO_ABS , + D3DSIO_NRM , + D3DSIO_SINCOS , + D3DSIO_REP , + D3DSIO_ENDREP , + D3DSIO_IF , + D3DSIO_IFC , + D3DSIO_ELSE , + D3DSIO_ENDIF , + D3DSIO_BREAK , + D3DSIO_BREAKC , + D3DSIO_MOVA , + D3DSIO_DEFB , + D3DSIO_DEFI , + + D3DSIO_TEXCOORD = 64, + D3DSIO_TEXKILL , + D3DSIO_TEX , + D3DSIO_TEXBEM , + D3DSIO_TEXBEML , + D3DSIO_TEXREG2AR , + D3DSIO_TEXREG2GB , + D3DSIO_TEXM3x2PAD , + D3DSIO_TEXM3x2TEX , + D3DSIO_TEXM3x3PAD , + D3DSIO_TEXM3x3TEX , + D3DSIO_RESERVED0 , + D3DSIO_TEXM3x3SPEC , + D3DSIO_TEXM3x3VSPEC , + D3DSIO_EXPP , + D3DSIO_LOGP , + D3DSIO_CND , + D3DSIO_DEF , + D3DSIO_TEXREG2RGB , + D3DSIO_TEXDP3TEX , + D3DSIO_TEXM3x2DEPTH , + D3DSIO_TEXDP3 , + D3DSIO_TEXM3x3 , + D3DSIO_TEXDEPTH , + D3DSIO_CMP , + D3DSIO_BEM , + D3DSIO_DP2ADD , + D3DSIO_DSX , + D3DSIO_DSY , + D3DSIO_TEXLDD , + D3DSIO_SETP , + D3DSIO_TEXLDL , + D3DSIO_BREAKP , + + D3DSIO_PHASE = 0xFFFD, + D3DSIO_COMMENT = 0xFFFE, + D3DSIO_END = 0xFFFF, + + D3DSIO_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum +} D3DSHADER_INSTRUCTION_OPCODE_TYPE; + +//--------------------------------------------------------------------- +// Use these constants with D3DSIO_SINCOS macro as SRC2, SRC3 +// +#define D3DSINCOSCONST1 -1.5500992e-006f, -2.1701389e-005f, 0.0026041667f, 0.00026041668f +#define D3DSINCOSCONST2 -0.020833334f, -0.12500000f, 1.0f, 0.50000000f + +//--------------------------------------------------------------------- +// Co-Issue Instruction Modifier - if set then this instruction is to be +// issued in parallel with the previous instruction(s) for which this bit +// is not set. +// +#define D3DSI_COISSUE 0x40000000 + +//--------------------------------------------------------------------- +// Opcode specific controls + +#define D3DSP_OPCODESPECIFICCONTROL_MASK 0x00ff0000 +#define D3DSP_OPCODESPECIFICCONTROL_SHIFT 16 + +// ps_2_0 texld controls +#define D3DSI_TEXLD_PROJECT (0x01 << D3DSP_OPCODESPECIFICCONTROL_SHIFT) +#define D3DSI_TEXLD_BIAS (0x02 << D3DSP_OPCODESPECIFICCONTROL_SHIFT) + +// Comparison for dynamic conditional instruction opcodes (i.e. if, breakc) +typedef enum _D3DSHADER_COMPARISON +{ + // < = > + D3DSPC_RESERVED0= 0, // 0 0 0 + D3DSPC_GT = 1, // 0 0 1 + D3DSPC_EQ = 2, // 0 1 0 + D3DSPC_GE = 3, // 0 1 1 + D3DSPC_LT = 4, // 1 0 0 + D3DSPC_NE = 5, // 1 0 1 + D3DSPC_LE = 6, // 1 1 0 + D3DSPC_RESERVED1= 7 // 1 1 1 +} D3DSHADER_COMPARISON; + +// Comparison is part of instruction opcode token: +#define D3DSHADER_COMPARISON_SHIFT D3DSP_OPCODESPECIFICCONTROL_SHIFT +#define D3DSHADER_COMPARISON_MASK (0x7<>8)&0xFF) +#define D3DSHADER_VERSION_MINOR(_Version) (((_Version)>>0)&0xFF) + +// destination/source parameter register type +#define D3DSI_COMMENTSIZE_SHIFT 16 +#define D3DSI_COMMENTSIZE_MASK 0x7FFF0000 +#define D3DSHADER_COMMENT(_DWordSize) \ + ((((_DWordSize)<> 16))) +#define D3DTAG_COUNT(Tag) ((DWORD) ((Tag) >> 8) & 0xff) +#define D3DTAG_START(Tag) ((DWORD) ((Tag) & 0xff)) + +#define D3DTAG_GROUPFROMTAG(Tag, Offset, Count) ((D3DTAG_INDEX(Tag) << 16) | ((Count) << 8) | (D3DTAG_START(Tag) + (Offset))) +#define D3DTAG_BITFROMTAG(Tag, Offset) ((D3DTAG_INDEX(Tag) << 16) | (1 << 8) | (D3DTAG_START(Tag) + (Offset))) + +// EndBit is inclusive: + +#define D3DTAG_MASKENCODE(StartBit, EndBit) \ + ((UINT64) ((INT64) 0x8000000000000000i64 >> ((EndBit) - (StartBit))) >> (StartBit)) + +// Enums that describe individual GPU registers or groups of GPU registers: + +typedef enum _D3DTAG { + + D3DTAG_VERTEXSHADERCONSTANTS = D3DTAG_GROUP(0, 0, 64), + D3DTAG_PIXELSHADERCONSTANTS = D3DTAG_GROUP(1, 0, 64), + + // The first 32 bits are used for fetch constants (note that + // 'D3DTAG_FETCHCONSTANTS' is a union of the vertex and texture constant + // groups, D3DTAG_VERTEXFETCHCONSTANTS includes the first 18 streams only + // and D3DTAG_TEXTUREFETCHCONSTANTS includes 16 textures for the pixel + // shader and 10 for the vertex shader): + + D3DTAG_FETCHCONSTANTS = D3DTAG_GROUP(3, 32, 32), + D3DTAG_VERTEXFETCHCONSTANTS = D3DTAG_GROUP(3, 32 + GPU_D3D_VERTEX_FETCH_CONSTANT_BASE, GPU_D3D_VERTEX_FETCH_CONSTANT_COUNT), + D3DTAG_TEXTUREFETCHCONSTANTS = D3DTAG_GROUP(3, 32 + GPU_D3D_TEXTURE_FETCH_CONSTANT_BASE, GPU_D3D_TEXTURE_FETCH_CONSTANT_COUNT), + +#define D3DTAG_VERTEXFETCHCONSTANT(n) ((D3DTAG)D3DTAG_BITFROMTAG(D3DTAG_FETCHCONSTANTS, ((GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(n) * (65536/3 + 1)) >> 16))) +#define D3DTAG_TEXTUREFETCHCONSTANT(n) ((D3DTAG)D3DTAG_BITFROMTAG(D3DTAG_FETCHCONSTANTS, (n))) + + // The following group of bits are D3D inventions and don't correspond + // directly to hardware registers: + + D3DTAG_SHADERFLAGS = D3DTAG_GROUP(2, 43, 4), + D3DTAG_PIXELSHADER = D3DTAG_BIT(2, 43), + D3DTAG_VERTEXSHADER, + D3DTAG_ZPASSEDRAMMODE, + D3DTAG_HIZENABLE, + + D3DTAG_WAITUNTILIDLEFLAGS = D3DTAG_GROUP(4, 0, 2), + D3DTAG_WAITUNTILIDLE = D3DTAG_BIT(4, 0), + D3DTAG_FLUSHCACHES = D3DTAG_BIT(4, 1), + + // The hardware requires all flow control constants to be set at once + // so they only require one bit: + + D3DTAG_MISCCONSTANTS = D3DTAG_GROUP(4, 7, 2), + D3DTAG_FLOWCONSTANTS = D3DTAG_BIT(4, 7), + D3DTAG_RESERVED0, + + // The following groups must match the ordering of the corresponding hardware + // state packets. + + // Packet 0, Destination: + + D3DTAG_DESTINATIONPACKET = D3DTAG_GROUP(2, 6, 16), + D3DTAG_SURFACEINFO = D3DTAG_BIT(2, 6), // GPUREG_SURFACEINFO + D3DTAG_COLOR0INFO, // GPUREG_COLOR0INFO + D3DTAG_DEPTHINFO, // GPUREG_DEPTHINFO + D3DTAG_COLOR1INFO, // GPUREG_COLOR1INFO + D3DTAG_COLOR2INFO, // GPUREG_COLOR2INFO + D3DTAG_COLOR3INFO, // GPUREG_COLOR3INFO + D3DTAG_COHERDESTBASE0, // GPUREG_COHERDESTBASE0 + D3DTAG_COHERDESTBASE1, // GPUREG_COHERDESTBASE1 + D3DTAG_COHERDESTBASE2, // GPUREG_COHERDESTBASE2 + D3DTAG_COHERDESTBASE3, // GPUREG_COHERDESTBASE3 + D3DTAG_COHERDESTBASE4, // GPUREG_COHERDESTBASE4 + D3DTAG_COHERDESTBASE5, // GPUREG_COHERDESTBASE5 + D3DTAG_COHERDESTBASE6, // GPUREG_COHERDESTBASE6 + D3DTAG_COHERDESTBASE7, // GPUREG_COHERDESTBASE7 + D3DTAG_SCREENSCISSORTL, // GPUREG_SCREENSCISSORTL + D3DTAG_SCREENSCISSORBR, // GPUREG_SCREENSCISSORBR + + // Packet 1, Window: + + D3DTAG_WINDOWPACKET = D3DTAG_GROUP(4, 15, 3), + D3DTAG_WINDOWOFFSET = D3DTAG_BIT(4, 15), // GPUREG_WINDOWOFFSET + D3DTAG_WINDOWSCISSORTL, // GPUREG_WINDOWSCISSORTL + D3DTAG_WINDOWSCISSORBR, // GPUREG_WINDOWSCISSORBR + + // Packet 2, Values: + + D3DTAG_VALUESPACKET = D3DTAG_GROUP(2, 22, 21), + D3DTAG_MAXVTXINDX = D3DTAG_BIT(2, 22), // GPUREG_MAXVTXINDX + D3DTAG_MINVTXINDX, // GPUREG_MINVTXINDX + D3DTAG_INDXOFFSET, // GPUREG_INDXOFFSET + D3DTAG_MULTIPRIMIBRESETINDX, // GPUREG_MULTIPRIMIBRESETINDX + D3DTAG_COLORMASK, // GPUREG_COLORMASK + D3DTAG_BLENDRED, // GPUREG_BLENDRED + D3DTAG_BLENDGREEN, // GPUREG_BLENDGREEN + D3DTAG_BLENDBLUE, // GPUREG_BLENDBLUE + D3DTAG_BLENDALPHA, // GPUREG_BLENDALPHA + D3DTAG_UNUSED_VALUES0, // GPUREG_UNUSED0 + D3DTAG_UNUSED_VALUES1, // GPUREG_UNUSED1 + D3DTAG_UNUSED_VALUES2, // GPUREG_UNUSED2 + D3DTAG_STENCILREFMASKBF, // GPUREG_STENCILREFMASKBF + D3DTAG_STENCILREFMASK, // GPUREG_STENCILREFMASK + D3DTAG_ALPHAREF, // GPUREG_ALPHAREF + D3DTAG_VPORTXSCALE, // GPUREG_VPORTXSCALE + D3DTAG_VPORTXOFFSET, // GPUREG_VPORTXOFFSET + D3DTAG_VPORTYSCALE, // GPUREG_VPORTYSCALE + D3DTAG_VPORTYOFFSET, // GPUREG_VPORTYOFFSET + D3DTAG_VPORTZSCALE, // GPUREG_VPORTZSCALE + D3DTAG_VPORTZOFFSET, // GPUREG_VPORTZOFFSET + + D3DTAG_BLENDFACTOR = D3DTAG_GROUPFROMTAG(D3DTAG_BLENDRED, 0, 4), + D3DTAG_STENCILREFMASKS = D3DTAG_GROUPFROMTAG(D3DTAG_STENCILREFMASKBF, 0, 2), + + // Packet 3, Program: + + D3DTAG_PROGRAMPACKET = D3DTAG_GROUP(2, 47, 5), + D3DTAG_PROGRAMCONTROL = D3DTAG_BIT(2, 47), // GPUREG_PROGRAMCONTROL + D3DTAG_CONTEXTMISC, // GPUREG_CONTEXTMISC + D3DTAG_INTERPOLATORCONTROL, // GPUREG_INTERPOLATORCONTROL + D3DTAG_WRAPPING0, // GPUREG_WRAPPING0 + D3DTAG_WRAPPING1, // GPUREG_WRAPPING1 + + // Packet 4, Control: + + D3DTAG_CONTROLPACKET = D3DTAG_GROUP(2, 52, 12), + D3DTAG_DEPTHCONTROL = D3DTAG_BIT(2, 52), // GPUREG_DEPTHCONTROL + D3DTAG_BLENDCONTROL0, // GPUREG_BLENDCONTROL0 + D3DTAG_COLORCONTROL, // GPUREG_COLORCONTROL + D3DTAG_HICONTROL, // GPUREG_HICONTROL + D3DTAG_CLIPCONTROL, // GPUREG_CLIPCONTROL + D3DTAG_MODECONTROL, // GPUREG_MODECONTROL + D3DTAG_VTECONTROL, // GPUREG_VTECONTROL + D3DTAG_UNUSED_CONTROL0, // GPUREG_UNUSED3 + D3DTAG_EDRAMMODECONTROL, // GPUREG_EDRAMMODECONTROL + D3DTAG_BLENDCONTROL1, // GPUREG_BLENDCONTROL1 + D3DTAG_BLENDCONTROL2, // GPUREG_BLENDCONTROL2 + D3DTAG_BLENDCONTROL3, // GPUREG_BLENDCONTROL3 + + // Packet 5, Tessellator: + + D3DTAG_TESSELLATORPACKET = D3DTAG_GROUP(3, 9, 21), + D3DTAG_POINTSIZE = D3DTAG_BIT(3, 9), // GPUREG_POINTSIZE + D3DTAG_POINTMINMAX, // GPUREG_POINTMINMAX + D3DTAG_LINECONTROL, // GPUREG_LINECONTROL + D3DTAG_LINESTIPPLE, // GPUREG_UNUSED4 + D3DTAG_OUTPUTPATHCONTROL, // GPUREG_OUTPUTPATHCONTROL + D3DTAG_HOSCONTROL, // GPUREG_HOSCONTROL + D3DTAG_HOSMAXTESSLEVEL, // GPUREG_HOSMAXTESSLEVEL + D3DTAG_HOSMINTESSLEVEL, // GPUREG_HOSMINTESSLEVEL + D3DTAG_HOSREUSEDEPTH, // GPUREG_HOSREUSEDEPTH + D3DTAG_GROUPPRIMTYPE, // GPUREG_GROUPPRIMTYPE + D3DTAG_GROUPFIRSTDECR, // GPUREG_GROUPFIRSTDECR + D3DTAG_GROUPDECR, // GPUREG_GROUPDECR + D3DTAG_GROUPVECT0CONTROL, // GPUREG_GROUPVECT0CONTROL + D3DTAG_GROUPVECT1CONTROL, // GPUREG_GROUPVECT1CONTROL + D3DTAG_GROUPVECT0FMTCONTROL, // GPUREG_GROUPVECT0FMTCONTROL + D3DTAG_GROUPVECT1FMTCONTROL, // GPUREG_GROUPVECT1FMTCONTROL + D3DTAG_UNUSED_TESSELLATOR0, // GPUREG_UNUSED5 + D3DTAG_UNUSED_TESSELLATOR1, // GPUREG_UNUSED6 + D3DTAG_MPASSPSCONTROL, // GPUREG_MPASSPSCONTROL + D3DTAG_VIZQUERY, // GPUREG_VIZQUERY + D3DTAG_ENHANCE, // GPUREG_ENHANCE + + // Packet 6, Misc: + + D3DTAG_MISCPACKET = D3DTAG_GROUP(4, 26, 38), + D3DTAG_SCLINECONTROL = D3DTAG_BIT(4, 26), // GPUREG_SCLINECONTROL + D3DTAG_AACONFIG, // GPUREG_AACONFIG + D3DTAG_VTXCONTROL, // GPUREG_VTXCONTROL + D3DTAG_GBVERTCLIPADJ, // GPUREG_GBVERTCLIPADJ + D3DTAG_GBVERTDISCADJ, // GPUREG_GBVERTDISCADJ + D3DTAG_GBHORZCLIPADJ, // GPUREG_GBHORZCLIPADJ + D3DTAG_GBHORZDISCADJ, // GPUREG_GBHORZDISCADJ + D3DTAG_VSCONST, // GPUREG_VSCONST + D3DTAG_PSCONST, // GPUREG_PSCONST + D3DTAG_DEBUGMISC0, // GPUREG_DEBUGMISC0 + D3DTAG_DEBUGMISC1, // GPUREG_DEBUGMISC1 + D3DTAG_UNUSED_MISC0, // GPUREG_UNUSED7 + D3DTAG_UNUSED_MISC1, // GPUREG_UNUSED8 + D3DTAG_UNUSED_MISC2, // GPUREG_UNUSED9 + D3DTAG_UNUSED_MISC3, // GPUREG_UNUSED10 + D3DTAG_UNUSED_MISC4, // GPUREG_UNUSED11 + D3DTAG_UNUSED_MISC5, // GPUREG_UNUSED12 + D3DTAG_UNUSED_MISC6, // GPUREG_UNUSED13 + D3DTAG_AAMASK, // GPUREG_AAMASK + D3DTAG_UNUSED_MISC7, // GPUREG_UNUSED14 + D3DTAG_UNUSED_MISC8, // GPUREG_UNUSED15 + D3DTAG_UNUSED_MISC9, // GPUREG_UNUSED16 + D3DTAG_VERTEXREUSEBLOCKCONTROL, // GPUREG_VERTEXREUSEBLOCKCONTROL + D3DTAG_OUTDEALLOCCONTROL, // GPUREG_OUTDEALLOCCONTROL + D3DTAG_COPYCONTROL, // GPUREG_COPYCONTROL + D3DTAG_COPYDESTBASE, // GPUREG_COPYDESTBASE + D3DTAG_COPYDESTPITCH, // GPUREG_COPYDESTPITCH + D3DTAG_COPYDESTINFO, // GPUREG_COPYDESTINFO + D3DTAG_HICLEAR, // GPUREG_HICLEAR + D3DTAG_DEPTHCLEAR, // GPUREG_DEPTHCLEAR + D3DTAG_COLORCLEAR, // GPUREG_COLORCLEAR + D3DTAG_COLORCLEARLO, // GPUREG_COLORCLEARLO + D3DTAG_COPYFUNC, // GPUREG_COPYFUNC + D3DTAG_COPYREF, // GPUREG_COPYREF + D3DTAG_COPYMASK, // GPUREG_COPYMASK + D3DTAG_COPYSURFACESLICE, // GPUREG_COPYSURFACESLICE + D3DTAG_SAMPLECOUNTCONTROL, // GPUREG_SAMPLECOUNTCONTROL + D3DTAG_SAMPLECOUNTADDRESS, // GPUREG_SAMPLECOUNTADDRESS + + // Packet 7, Point: + + D3DTAG_POINTPACKET = D3DTAG_GROUP(4, 18, 8), + D3DTAG_POLYOFFSETFRONTSCALE = D3DTAG_BIT(4, 18), // GPUREG_POLYOFFSETFRONTSCALE + D3DTAG_POLYOFFSETFRONTOFFSET, // GPUREG_POLYOFFSETFRONTOFFSET + D3DTAG_POLYOFFSETBACKSCALE, // GPUREG_POLYOFFSETBACKSCALE + D3DTAG_POLYOFFSETBACKOFFSET, // GPUREG_POLYOFFSETBACKOFFSET + D3DTAG_POINTXRAD, // GPUREG_POINTXRAD + D3DTAG_POINTYRAD, // GPUREG_POINTYRAD + D3DTAG_POINTCONSTANTSIZE, // GPUREG_POINTCONSTANTSIZE + D3DTAG_POINTCULLRAD, // GPUREG_POINTCULLRAD + + // Non-context state: + + D3DTAG_CLIPPLANES = D3DTAG_GROUP(4, 9, 6), + D3DTAG_CLIPPLANE0 = D3DTAG_BIT(4, 9), // GPUREG_CLIPPLANE0 + D3DTAG_CLIPPLANE1, // GPUREG_CLIPPLANE1 + D3DTAG_CLIPPLANE2, // GPUREG_CLIPPLANE2 + D3DTAG_CLIPPLANE3, // GPUREG_CLIPPLANE3 + D3DTAG_CLIPPLANE4, // GPUREG_CLIPPLANE4 + D3DTAG_CLIPPLANE5, // GPUREG_CLIPPLANE5 + + // This terminator must always be at the end: + + D3DTAG_TERMINATOR, + +} D3DTAG; + +// Flags for flushing the Hi-Z/Hi-Stencil test results: + +typedef enum _D3DFHZS_FLUSHTYPE +{ + D3DFHZS_ASYNCHRONOUS, // Faster, but requires conservative Hi-Z/Hi-Stencil tests + D3DFHZS_SYNCHRONOUS // Slower, but can be used with non-conservative tests +} D3DFHZS_FLUSHTYPE; + +// Flags for GpuLoadShadersFast + +#define D3DGLS_USECURRENTVS 0x000000001 // Indicate that the vertex shader is already set +#define D3DGLS_USECURRENTPS 0x000000002 // Indicate that the pixel shader is already set +#define D3DGLS_USECURRENTFLOW 0x000000004 // Indicate that the flow constants (including shader literals) are already set + +// Constants for PIXEnableTextureTracking + +#define D3DTC_DEFAULT_COMMAND_BUFFER_SIZE (4 * 1024 * 1024) // default TrackerCommandBufferSize in PIXEnableTextureTracking() +#define D3DTC_MIN_COMMAND_BUFFER_SIZE (1024 * 1024) // minimum TrackerCommandBufferSize in PIXEnableTextureTracking() +#define D3DTC_MAX_COMMAND_BUFFER_SIZE (8 * 1024 * 1024) // maximum TrackerCommandBufferSize in PIXEnableTextureTracking() +#define D3DTC_DEFAULT_THREAD_ID 5 // default hardware thread for running collector +#define D3DTC_DEFAULT_CREATE_THREAD (D3DCREATE_CREATE_THREAD_ON_0 << D3DTC_DEFAULT_THREAD_ID) // default TrackerThread in PIXEnableTextureTracking() + +// Constants for PIXBeginTextureCapture + +#define D3DTC_MIN_AUTOSAVE_FRAMES 16 // minimum AutoSaveFrequency in BeginTextureCapture(), actual one should be 0 or multiple of it +#define D3DTC_DEFAULT_AUTOSAVE_FRAMES 16 // default AutoSaveFrequency in BeginTextureCapture() +#define D3DTC_DEFAULT_SCREEN_CAPTURE_FRAMES 16 // default SceenCaptureFrequency in BeginTextureCapture() +#define D3DTC_DEFAULT_SOFT_COMPARE_THRESHOLD 5 // default texture channel soft compare threshold in BeginTextureCapture(), in percentage +#define D3DTC_MAX_SOFT_COMPARE_THRESHOLD 99 // maximum texture channel soft compare threshold + +#if defined(_X86_) || defined(_IA64) +#pragma pack(pop) +#endif + +#if _MSC_VER >= 1200 +#pragma warning(pop) +#else +#pragma warning(default:4201) +#endif + +#if defined(_M_PPCBE) +#pragma bitfield_order(pop) +#endif + +#endif /* (DIRECT3D_VERSION >= 0x0900) */ + +#endif /* _d3d9TYPES(P)_H_ */ + diff --git a/third_party/xbox_sdk/include/d3d9xps.h b/third_party/xbox_sdk/include/d3d9xps.h new file mode 100644 index 0000000..a765103 --- /dev/null +++ b/third_party/xbox_sdk/include/d3d9xps.h @@ -0,0 +1,114 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: d3d9xps.h + * Content: Xbox 360 include file for using Xbox Procedural Synthesis + * + ****************************************************************************/ + +#ifndef _D3D9D3DXPS_H_ +#define _D3D9D3DXPS_H_ + +// Prototype for the D3D-maintained, thread-specific XPS context given to +// an XPS routine: + +typedef struct D3DXpsThread D3DXpsThread; + +// Prototype for XPS routines: + +typedef void (WINAPI *D3DXpsCallback)(__in D3DXpsThread* pThreadContext, __inout_opt void* pCallbackContext, __in CONST void* pSubmitData, DWORD InstanceIndex); + +// Size, in bytes, of the ring-buffer space consumed by various +// 'D3DXps' calls: + +#define D3DXPS_DRAWVERTICES_SIZE 132 +#define D3DXPS_DRAWINDEXEDVERTICES_SIZE 140 + +// Default command size: + +#define D3DXPS_COMMAND_SIZE D3DXPS_DRAWINDEXEDVERTICES_SIZE + +// Maximum number of threads that can be enabled for XPS: + +#define D3DXPS_MAX_THREADS 6 + +// Hardware fetch constant used for XPS: + +#define D3DXPS_FETCH_CONSTANT (GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(0) / 3) + +//------------------------------------------------------------------------------ +// The D3DXps class is only available with C++. + +#ifdef __cplusplus + +class D3DXps; + +// Builder function prototypes: + +void D3DXps_Initialize(__in D3DXps* pD3DXps, __in D3DXpsThread* pThreadContext); +void D3DXps_Uninitialize(__in D3DXps* pD3DXps); +void* D3DXps_Allocate(__in D3DXps* pD3DXps, DWORD DataSize, DWORD CommandSize); +void D3DXps_DrawVertices(__in D3DXps* pD3DXps, D3DPRIMITIVETYPE PrimitiveType, DWORD VertexCount, __in CONST void* pVertexData); +void D3DXps_DrawIndexedVertices(__in D3DXps* pD3DXps, D3DPRIMITIVETYPE PrimitiveType, DWORD IndexCount, __in CONST void* pIndexData, D3DFORMAT IndexDataFormat, __in CONST void* pVertexData); +void D3DXps_KickOff(__in D3DXps* pD3DXps); +BOOL D3DXps_KickOffAndGet(__in D3DXps* pD3DXps, __out DWORD* pInstanceIndex); +BOOL D3DXps_Get(__in D3DXps* pD3DXps, __out DWORD* pInstanceIndex); + +// 'D3DXps' is the class used by XPS routines to synchronize with the +// other XPS threads, to write to the L2 buffer, and to kick-off commands +// to the GPU. +// +// NOTE: This object is intended to be instantiated on the stack at the +// entry of every XPS data generation routine. +// +// NOTE: Once final hardware arrives, all of the member functions will become +// '__forceinline' and so will always be inlined in the calling routine. + +class D3DXps +{ +private: + + DWORD m_Reserved[100]; + +public: + + D3DXps(__in D3DXpsThread* pThreadContext) + { + D3DXps_Initialize(this, pThreadContext); + } + + ~D3DXps() + { + D3DXps_Uninitialize(this); + } + + void* WINAPI Allocate(DWORD DataSize, DWORD CommandSize = D3DXPS_COMMAND_SIZE) + { + return D3DXps_Allocate(this, DataSize, CommandSize); + } + + void WINAPI DrawVertices(D3DPRIMITIVETYPE PrimitiveType, DWORD VertexCount, __in CONST void* pVertexData) + { + D3DXps_DrawVertices(this, PrimitiveType, VertexCount, pVertexData); + } + + void WINAPI DrawIndexedVertices(D3DPRIMITIVETYPE PrimitiveType, DWORD IndexCount, __in CONST void* pIndexData, D3DFORMAT IndexDataFormat, __in CONST void* pVertexData) + { + D3DXps_DrawIndexedVertices(this, PrimitiveType, IndexCount, pIndexData, IndexDataFormat, pVertexData); + } + + void WINAPI KickOff() + { + D3DXps_KickOff(this); + } + + BOOL WINAPI KickOffAndGet(__out DWORD* pInstanceIndex) + { + return D3DXps_KickOffAndGet(this, pInstanceIndex); + } +}; + +#endif /* __cplusplus */ + +#endif /* _D3D9D3DXPS_H_ */ diff --git a/third_party/xbox_sdk/include/d3dx9.h b/third_party/xbox_sdk/include/d3dx9.h new file mode 100644 index 0000000..ba99719 --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9.h @@ -0,0 +1,102 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9.h +// Content: D3DX utility library +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef __D3DX9_H__ +#define __D3DX9_H__ + + +// Defines +#include + +#ifdef _XBOX // Implies compiling for Xbox 360 +#include "XObjBase.h" +#else +#include "ObjBase.h" +#endif + +#define D3DX_DEFAULT ((UINT) -1) +#define D3DX_DEFAULT_NONPOW2 ((UINT) -2) +#define D3DX_DEFAULT_FLOAT FLT_MAX + +#ifndef D3DXINLINE +#ifdef _MSC_VER + #if (_MSC_VER >= 1200) + #define D3DXINLINE __forceinline + #else + #define D3DXINLINE __inline + #endif +#else + #ifdef __cplusplus + #define D3DXINLINE inline + #else + #define D3DXINLINE + #endif +#endif +#endif + + + +// Includes +#include "d3d9.h" +#include "d3dx9math.h" +#include "d3dx9core.h" +#include "d3dx9mesh.h" +#include "d3dx9tex.h" +#include "d3dx9shader.h" +#include "d3dx9effect.h" +#include "d3dx9shape.h" +#include "d3dx9anim.h" +#include "d3dx9xof.h" + + +// Errors +#define _FACDD 0x876 +#define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) + +enum _D3DXERR { + D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900), + D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901), + D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902), + D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903), + D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904), + D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905), + D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906), + D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907), + + // Xbox 360 Extension + D3DXERR_MICROCODEEMPTY = MAKE_DDHRESULT(2920), + D3DXERR_MICROCODETOOBIG = MAKE_DDHRESULT(2921), + D3DXERR_MICROCODEUNSUPPORTEDTARGET = MAKE_DDHRESULT(2922), + D3DXERR_MICROCODEOPTIMIZERFAILED = MAKE_DDHRESULT(2923), + D3DXERR_MICROCODETOOMANYLEVELS = MAKE_DDHRESULT(2924), + D3DXERR_MICROCODETOOMANYREGS = MAKE_DDHRESULT(2925), + D3DXERR_MICROCODETOOMANYCONSTS = MAKE_DDHRESULT(2926), + D3DXERR_MICROCODETOOMANYRSINSTS = MAKE_DDHRESULT(2927), + D3DXERR_MICROCODETOOMANYTEXINSTS = MAKE_DDHRESULT(2928), + D3DXERR_MICROCODETOOMANYALUINSTS = MAKE_DDHRESULT(2929), + D3DXERR_MICROCODETOOMANYCFINSTS = MAKE_DDHRESULT(2930), + D3DXERR_MICROCODETOOMANYTOTALINSTS = MAKE_DDHRESULT(2931), + D3DXERR_MICROCODETOOMANYCOMPILERLITERALS = MAKE_DDHRESULT(2932), + D3DXERR_MICROCODE_DEFB_CONSTANT_OUT_OF_RANGE = MAKE_DDHRESULT(2933), + D3DXERR_MICROCODE_DEFI_CONSTANT_OUT_OF_RANGE = MAKE_DDHRESULT(2934), + D3DXERR_MICROCODE_DEF_CONSTANT_OUT_OF_RANGE = MAKE_DDHRESULT(2935), + D3DXERR_MICROCODE_DEFB_CONSTANT_OUT_OF_ALPHA_PIXEL_SHADER_RANGE = MAKE_DDHRESULT(2936), + D3DXERR_MICROCODE_DEFI_CONSTANT_OUT_OF_ALPHA_PIXEL_SHADER_RANGE = MAKE_DDHRESULT(2937), + D3DXERR_MICROCODE_DEF_CONSTANT_OUT_OF_ALPHA_PIXEL_SHADER_RANGE = MAKE_DDHRESULT(2938), + D3DXERR_MICROCODE_DEFB_CONSTANT_OUT_OF_ALPHA_VERTEX_SHADER_RANGE = MAKE_DDHRESULT(2939), + D3DXERR_MICROCODE_DEFI_CONSTANT_OUT_OF_ALPHA_VERTEX_SHADER_RANGE = MAKE_DDHRESULT(2940), + D3DXERR_MICROCODE_DEF_CONSTANT_OUT_OF_ALPHA_VERTEX_SHADER_RANGE = MAKE_DDHRESULT(2941), + D3DXERR_MICROCODE_DUPLICATE_DEFB_CONSTANT = MAKE_DDHRESULT(2942), + D3DXERR_MICROCODE_DUPLICATE_DEFI_CONSTANT = MAKE_DDHRESULT(2943), + D3DXERR_MICROCODE_DUPLICATE_DEF_CONSTANT = MAKE_DDHRESULT(2944), +}; + + +#endif //__D3DX9_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9anim.h b/third_party/xbox_sdk/include/d3dx9anim.h new file mode 100644 index 0000000..2a9dc3f --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9anim.h @@ -0,0 +1,1097 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9anim.h +// Content: D3DX mesh types and functions +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef __D3DX9ANIM_H__ +#define __D3DX9ANIM_H__ + +// {A632D591-B584-4d03-BCCD-CBB5331F21AA} +DEFINE_GUID(IID_ID3DXAnimationSet, +0xa632d591, 0xb584, 0x4d03, 0xbc, 0xcd, 0xcb, 0xb5, 0x33, 0x1f, 0x21, 0xaa); + +// {73B6DDE3-7E45-4cc8-834F-B7DCBC04D10A} +DEFINE_GUID(IID_ID3DXKeyframedAnimationSet, +0x73b6dde3, 0x7e45, 0x4cc8, 0x83, 0x4f, 0xb7, 0xdc, 0xbc, 0x4, 0xd1, 0xa); + +// {7B7228FD-EA36-4c06-9DA6-E053D688E164} +DEFINE_GUID(IID_ID3DXCompressedAnimationSet, +0x7b7228fd, 0xea36, 0x4c06, 0x9d, 0xa6, 0xe0, 0x53, 0xd6, 0x88, 0xe1, 0x64); + +// {39F628C0-CD5B-41d6-8E9C-3BBBB66FDA57} +DEFINE_GUID(IID_ID3DXAnimationController, +0x39f628c0, 0xcd5b, 0x41d6, 0x8e, 0x9c, 0x3b, 0xbb, 0xb6, 0x6f, 0xda, 0x57); + + +//---------------------------------------------------------------------------- +// D3DXMESHDATATYPE: +// ----------------- +// This enum defines the type of mesh data present in a MeshData structure. +//---------------------------------------------------------------------------- +typedef enum _D3DXMESHDATATYPE { + D3DXMESHTYPE_MESH = 0x001, // Normal ID3DXMesh data + D3DXMESHTYPE_PMESH = 0x002, // Progressive Mesh - ID3DXPMesh + D3DXMESHTYPE_PATCHMESH = 0x003, // Patch Mesh - ID3DXPatchMesh + + D3DXMESHTYPE_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DXMESHDATATYPE; + +//---------------------------------------------------------------------------- +// D3DXMESHDATA: +// ------------- +// This struct encapsulates a the mesh data that can be present in a mesh +// container. The supported mesh types are pMesh, pPMesh, pPatchMesh. +// The valid way to access this is determined by the Type enum. +//---------------------------------------------------------------------------- +typedef struct _D3DXMESHDATA +{ + D3DXMESHDATATYPE Type; + + // current mesh data interface + union + { + LPD3DXMESH pMesh; + LPD3DXPMESH pPMesh; + LPD3DXPATCHMESH pPatchMesh; + }; +} D3DXMESHDATA, *LPD3DXMESHDATA; + +//---------------------------------------------------------------------------- +// D3DXMESHCONTAINER: +// ------------------ +// This struct encapsulates a mesh object in a transformation frame +// hierarchy. The app can derive from this structure to add other app specific +// data to this. +//---------------------------------------------------------------------------- +typedef struct _D3DXMESHCONTAINER +{ + LPSTR Name; + + D3DXMESHDATA MeshData; + + LPD3DXMATERIAL pMaterials; + LPD3DXEFFECTINSTANCE pEffects; + DWORD NumMaterials; + DWORD *pAdjacency; + + LPD3DXSKININFO pSkinInfo; + + struct _D3DXMESHCONTAINER *pNextMeshContainer; +} D3DXMESHCONTAINER, *LPD3DXMESHCONTAINER; + +//---------------------------------------------------------------------------- +// D3DXFRAME: +// ---------- +// This struct is the encapsulates a transform frame in a transformation frame +// hierarchy. The app can derive from this structure to add other app specific +// data to this +//---------------------------------------------------------------------------- +typedef struct _D3DXFRAME +{ + LPSTR Name; + D3DXMATRIX TransformationMatrix; + + LPD3DXMESHCONTAINER pMeshContainer; + + struct _D3DXFRAME *pFrameSibling; + struct _D3DXFRAME *pFrameFirstChild; +} D3DXFRAME, *LPD3DXFRAME; + + +//---------------------------------------------------------------------------- +// ID3DXAllocateHierarchy: +// ----------------------- +// This interface is implemented by the application to allocate/free frame and +// mesh container objects. Methods on this are called during loading and +// destroying frame hierarchies +//---------------------------------------------------------------------------- +typedef interface ID3DXAllocateHierarchy ID3DXAllocateHierarchy; +typedef interface ID3DXAllocateHierarchy *LPD3DXALLOCATEHIERARCHY; + +#undef INTERFACE +#define INTERFACE ID3DXAllocateHierarchy + +DECLARE_INTERFACE(ID3DXAllocateHierarchy) +{ + // ID3DXAllocateHierarchy + + //------------------------------------------------------------------------ + // CreateFrame: + // ------------ + // Requests allocation of a frame object. + // + // Parameters: + // Name + // Name of the frame to be created + // ppNewFrame + // Returns the created frame object + // + //------------------------------------------------------------------------ + STDMETHOD(CreateFrame)(THIS_ __in_z LPCSTR Name, + __deref_out LPD3DXFRAME *ppNewFrame) PURE; + + //------------------------------------------------------------------------ + // CreateMeshContainer: + // -------------------- + // Requests allocation of a mesh container object. + // + // Parameters: + // Name + // Name of the mesh + // pMesh + // Pointer to the mesh object if basic polygon data found + // pPMesh + // Pointer to the progressive mesh object if progressive mesh data found + // pPatchMesh + // Pointer to the patch mesh object if patch data found + // pMaterials + // Array of materials used in the mesh + // pEffectInstances + // Array of effect instances used in the mesh + // NumMaterials + // Num elements in the pMaterials array + // pAdjacency + // Adjacency array for the mesh + // pSkinInfo + // Pointer to the skininfo object if the mesh is skinned + // pBoneNames + // Array of names, one for each bone in the skinned mesh. + // The numberof bones can be found from the pSkinMesh object + // pBoneOffsetMatrices + // Array of matrices, one for each bone in the skinned mesh. + // + //------------------------------------------------------------------------ + STDMETHOD(CreateMeshContainer)(THIS_ + __in_z LPCSTR Name, + __in CONST D3DXMESHDATA *pMeshData, + __in_ecount_opt(NumMaterials) CONST D3DXMATERIAL *pMaterials, + __in_opt CONST D3DXEFFECTINSTANCE *pEffectInstances, + DWORD NumMaterials, + __in_opt CONST DWORD *pAdjacency, + __in_opt LPD3DXSKININFO pSkinInfo, + __deref_out LPD3DXMESHCONTAINER *ppNewMeshContainer) PURE; + + //------------------------------------------------------------------------ + // DestroyFrame: + // ------------- + // Requests de-allocation of a frame object. + // + // Parameters: + // pFrameToFree + // Pointer to the frame to be de-allocated + // + //------------------------------------------------------------------------ + STDMETHOD(DestroyFrame)(THIS_ __in LPD3DXFRAME pFrameToFree) PURE; + + //------------------------------------------------------------------------ + // DestroyMeshContainer: + // --------------------- + // Requests de-allocation of a mesh container object. + // + // Parameters: + // pMeshContainerToFree + // Pointer to the mesh container object to be de-allocated + // + //------------------------------------------------------------------------ + STDMETHOD(DestroyMeshContainer)(THIS_ __in LPD3DXMESHCONTAINER pMeshContainerToFree) PURE; +}; + +//---------------------------------------------------------------------------- +// ID3DXLoadUserData: +// ------------------ +// This interface is implemented by the application to load user data in a .X file +// When user data is found, these callbacks will be used to allow the application +// to load the data. +//---------------------------------------------------------------------------- +typedef interface ID3DXLoadUserData ID3DXLoadUserData; +typedef interface ID3DXLoadUserData *LPD3DXLOADUSERDATA; + +#undef INTERFACE +#define INTERFACE ID3DXLoadUserData + +DECLARE_INTERFACE(ID3DXLoadUserData) +{ + STDMETHOD(LoadTopLevelData)(__in LPDIRECTXFILEDATA pXofChildData) PURE; + + STDMETHOD(LoadFrameChildData)(__in LPD3DXFRAME pFrame, + __in LPDIRECTXFILEDATA pXofChildData) PURE; + + STDMETHOD(LoadMeshChildData)(__in LPD3DXMESHCONTAINER pMeshContainer, + __in LPDIRECTXFILEDATA pXofChildData) PURE; +}; + +//---------------------------------------------------------------------------- +// ID3DXSaveUserData: +// ------------------ +// This interface is implemented by the application to save user data in a .X file +// The callbacks are called for all data saved. The user can then add any +// child data objects to the object provided to the callback. +//---------------------------------------------------------------------------- +typedef interface ID3DXSaveUserData ID3DXSaveUserData; +typedef interface ID3DXSaveUserData *LPD3DXSAVEUSERDATA; + +#undef INTERFACE +#define INTERFACE ID3DXSaveUserData + +DECLARE_INTERFACE(ID3DXSaveUserData) +{ + STDMETHOD(AddFrameChildData)(__in CONST D3DXFRAME *pFrame, + __in LPDIRECTXFILESAVEOBJECT pXofSave, + __in LPDIRECTXFILEDATA pXofFrameData) PURE; + + STDMETHOD(AddMeshChildData)(__in CONST D3DXMESHCONTAINER *pMeshContainer, + __in LPDIRECTXFILESAVEOBJECT pXofSave, + __in LPDIRECTXFILEDATA pXofMeshData) PURE; + + // NOTE: this is called once per Save. All top level objects should be added using the + // provided interface. One call adds objects before the frame hierarchy, the other after + STDMETHOD(AddTopLevelDataObjectsPre)(__in LPDIRECTXFILESAVEOBJECT pXofSave) PURE; + STDMETHOD(AddTopLevelDataObjectsPost)(__in LPDIRECTXFILESAVEOBJECT pXofSave) PURE; + + // callbacks for the user to register and then save templates to the XFile + STDMETHOD(RegisterTemplates)(__in LPDIRECTXFILE pXFileApi) PURE; + STDMETHOD(SaveTemplates)(__in LPDIRECTXFILESAVEOBJECT pXofSave) PURE; +}; + + +//---------------------------------------------------------------------------- +// D3DXCALLBACK_SEARCH_FLAGS: +// -------------------------- +// Flags that can be passed into ID3DXAnimationSet::GetCallback. +//---------------------------------------------------------------------------- +typedef enum _D3DXCALLBACK_SEARCH_FLAGS +{ + D3DXCALLBACK_SEARCH_EXCLUDING_INITIAL_POSITION = 0x01, // exclude callbacks at the initial position from the search + D3DXCALLBACK_SEARCH_BEHIND_INITIAL_POSITION = 0x02, // reverse the callback search direction + + D3DXCALLBACK_SEARCH_FORCE_DWORD = 0x7fffffff, +} D3DXCALLBACK_SEARCH_FLAGS; + +//---------------------------------------------------------------------------- +// ID3DXAnimationSet: +// ------------------ +// This interface implements an animation set. +//---------------------------------------------------------------------------- +typedef interface ID3DXAnimationSet ID3DXAnimationSet; +typedef interface ID3DXAnimationSet *LPD3DXANIMATIONSET; + +#undef INTERFACE +#define INTERFACE ID3DXAnimationSet + +DECLARE_INTERFACE_(ID3DXAnimationSet, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Name + STDMETHOD_(__out_z LPCSTR, GetName)(THIS) PURE; + + // Period + STDMETHOD_(DOUBLE, GetPeriod)(THIS) PURE; + STDMETHOD_(DOUBLE, GetPeriodicPosition)(THIS_ DOUBLE Position) PURE; // Maps position into animation period + + // Animation names + STDMETHOD_(UINT, GetNumAnimations)(THIS) PURE; + STDMETHOD(GetAnimationNameByIndex)(THIS_ UINT Index, __deref_out_z LPCSTR *ppName) PURE; + STDMETHOD(GetAnimationIndexByName)(THIS_ __in_z LPCSTR pName, __out UINT *pIndex) PURE; + + // SRT + STDMETHOD(GetSRT)(THIS_ + DOUBLE PeriodicPosition, // Position mapped to period (use GetPeriodicPosition) + UINT Animation, // Animation index + __out D3DXVECTOR3 *pScale, // Returns the scale + __out D3DXQUATERNION *pRotation, // Returns the rotation as a quaternion + __out D3DXVECTOR3 *pTranslation) PURE; // Returns the translation + + // Callbacks + STDMETHOD(GetCallback)(THIS_ + DOUBLE Position, // Position from which to find callbacks + DWORD Flags, // Callback search flags + __out_opt DOUBLE *pCallbackPosition, // Returns the position of the callback + __deref_opt_out LPVOID *ppCallbackData) PURE; // Returns the callback data pointer +}; + + +//---------------------------------------------------------------------------- +// D3DXPLAYBACK_TYPE: +// ------------------ +// This enum defines the type of animation set loop modes. +//---------------------------------------------------------------------------- +typedef enum _D3DXPLAYBACK_TYPE +{ + D3DXPLAY_LOOP = 0, + D3DXPLAY_ONCE = 1, + D3DXPLAY_PINGPONG = 2, + + D3DXPLAY_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DXPLAYBACK_TYPE; + + +//---------------------------------------------------------------------------- +// D3DXKEY_VECTOR3: +// ---------------- +// This structure describes a vector key for use in keyframe animation. +// It specifies a vector Value at a given Time. This is used for scale and +// translation keys. +//---------------------------------------------------------------------------- +typedef struct _D3DXKEY_VECTOR3 +{ + FLOAT Time; + D3DXVECTOR3 Value; +} D3DXKEY_VECTOR3, *LPD3DXKEY_VECTOR3; + + +//---------------------------------------------------------------------------- +// D3DXKEY_QUATERNION: +// ------------------- +// This structure describes a quaternion key for use in keyframe animation. +// It specifies a quaternion Value at a given Time. This is used for rotation +// keys. +//---------------------------------------------------------------------------- +typedef struct _D3DXKEY_QUATERNION +{ + FLOAT Time; + D3DXQUATERNION Value; +} D3DXKEY_QUATERNION, *LPD3DXKEY_QUATERNION; + + +//---------------------------------------------------------------------------- +// D3DXKEY_CALLBACK: +// ----------------- +// This structure describes an callback key for use in keyframe animation. +// It specifies a pointer to user data at a given Time. +//---------------------------------------------------------------------------- +typedef struct _D3DXKEY_CALLBACK +{ + FLOAT Time; + LPVOID pCallbackData; +} D3DXKEY_CALLBACK, *LPD3DXKEY_CALLBACK; + + +//---------------------------------------------------------------------------- +// D3DXCOMPRESSION_FLAGS: +// ---------------------- +// Flags that can be passed into ID3DXKeyframedAnimationSet::Compress. +//---------------------------------------------------------------------------- +typedef enum _D3DXCOMPRESSION_FLAGS +{ + D3DXCOMPRESS_DEFAULT = 0x00, + + D3DXCOMPRESS_FORCE_DWORD = 0x7fffffff, +} D3DXCOMPRESSION_FLAGS; + + +//---------------------------------------------------------------------------- +// ID3DXKeyframedAnimationSet: +// --------------------------- +// This interface implements a compressable keyframed animation set. +//---------------------------------------------------------------------------- +typedef interface ID3DXKeyframedAnimationSet ID3DXKeyframedAnimationSet; +typedef interface ID3DXKeyframedAnimationSet *LPD3DXKEYFRAMEDANIMATIONSET; + +#undef INTERFACE +#define INTERFACE ID3DXKeyframedAnimationSet + +DECLARE_INTERFACE_(ID3DXKeyframedAnimationSet, ID3DXAnimationSet) +{ + // ID3DXAnimationSet + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Name + STDMETHOD_(__out_z LPCSTR, GetName)(THIS) PURE; + + // Period + STDMETHOD_(DOUBLE, GetPeriod)(THIS) PURE; + STDMETHOD_(DOUBLE, GetPeriodicPosition)(THIS_ DOUBLE Position) PURE; // Maps position into animation period + + // Animation names + STDMETHOD_(UINT, GetNumAnimations)(THIS) PURE; + STDMETHOD(GetAnimationNameByIndex)(THIS_ UINT Index, __deref_out_z LPCSTR *ppName) PURE; + STDMETHOD(GetAnimationIndexByName)(THIS_ __in_z LPCSTR pName, __out UINT *pIndex) PURE; + + // SRT + STDMETHOD(GetSRT)(THIS_ + DOUBLE PeriodicPosition, // Position mapped to period (use GetPeriodicPosition) + UINT Animation, // Animation index + __out D3DXVECTOR3 *pScale, // Returns the scale + __out D3DXQUATERNION *pRotation, // Returns the rotation as a quaternion + __out D3DXVECTOR3 *pTranslation) PURE; // Returns the translation + + // Callbacks + STDMETHOD(GetCallback)(THIS_ + DOUBLE Position, // Position from which to find callbacks + DWORD Flags, // Callback search flags + __out_opt DOUBLE *pCallbackPosition, // Returns the position of the callback + __deref_opt_out LPVOID *ppCallbackData) PURE; // Returns the callback data pointer + + // Playback + STDMETHOD_(D3DXPLAYBACK_TYPE, GetPlaybackType)(THIS) PURE; + STDMETHOD_(DOUBLE, GetSourceTicksPerSecond)(THIS) PURE; + + // Scale keys + STDMETHOD_(UINT, GetNumScaleKeys)(THIS_ UINT Animation) PURE; + STDMETHOD(GetScaleKeys)(THIS_ UINT Animation, __out LPD3DXKEY_VECTOR3 pScaleKeys) PURE; + + // Rotation keys + STDMETHOD_(UINT, GetNumRotationKeys)(THIS_ UINT Animation) PURE; + STDMETHOD(GetRotationKeys)(THIS_ UINT Animation, __out LPD3DXKEY_QUATERNION pRotationKeys) PURE; + + // Translation keys + STDMETHOD_(UINT, GetNumTranslationKeys)(THIS_ UINT Animation) PURE; + STDMETHOD(GetTranslationKeys)(THIS_ UINT Animation, __out LPD3DXKEY_VECTOR3 pTranslationKeys) PURE; + + // Callback keys + STDMETHOD_(UINT, GetNumCallbackKeys)(THIS) PURE; + STDMETHOD(GetCallbackKeys)(THIS_ __out LPD3DXKEY_CALLBACK pCallbackKeys) PURE; + + // One-time animaton SRT keyframe registration + STDMETHOD(RegisterAnimationSRTKeys)(THIS_ + __in_z LPCSTR pName, // Animation name + UINT NumScaleKeys, // Number of scale keys + UINT NumRotationKeys, // Number of rotation keys + UINT NumTranslationKeys, // Number of translation keys + __in_ecount_opt(NumScaleKeys) CONST D3DXKEY_VECTOR3 *pScaleKeys, // Array of scale keys + __in_ecount_opt(NumRotationKeys) CONST D3DXKEY_QUATERNION *pRotationKeys, // Array of rotation keys + __in_ecount_opt(NumTranslationKeys) CONST D3DXKEY_VECTOR3 *pTranslationKeys) PURE; // Array of translation keys + + // Compression + STDMETHOD(Compress)(THIS_ + DWORD Flags, // Compression flags (use D3DXCOMPRESS_STRONG for better results) + FLOAT Lossiness, // Compression loss ratio in the [0, 1] range + __in_opt LPD3DXFRAME pHierarchy, // Frame hierarchy (optional) + __deref_out LPD3DXBUFFER *ppCompressedData) PURE; // Returns the compressed animation set +}; + + +//---------------------------------------------------------------------------- +// ID3DXCompressedAnimationSet: +// ---------------------------- +// This interface implements a compressed keyframed animation set. +//---------------------------------------------------------------------------- +typedef interface ID3DXCompressedAnimationSet ID3DXCompressedAnimationSet; +typedef interface ID3DXCompressedAnimationSet *LPD3DXCOMPRESSEDANIMATIONSET; + +#undef INTERFACE +#define INTERFACE ID3DXCompressedAnimationSet + +DECLARE_INTERFACE_(ID3DXCompressedAnimationSet, ID3DXAnimationSet) +{ + // ID3DXAnimationSet + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Name + STDMETHOD_(__out_z LPCSTR, GetName)(THIS) PURE; + + // Period + STDMETHOD_(DOUBLE, GetPeriod)(THIS) PURE; + STDMETHOD_(DOUBLE, GetPeriodicPosition)(THIS_ DOUBLE Position) PURE; // Maps position into animation period + + // Animation names + STDMETHOD_(UINT, GetNumAnimations)(THIS) PURE; + STDMETHOD(GetAnimationNameByIndex)(THIS_ UINT Index, __deref_out_z LPCSTR *ppName) PURE; + STDMETHOD(GetAnimationIndexByName)(THIS_ __in_z LPCSTR pName, __out UINT *pIndex) PURE; + + // SRT + STDMETHOD(GetSRT)(THIS_ + DOUBLE PeriodicPosition, // Position mapped to period (use GetPeriodicPosition) + UINT Animation, // Animation index + __out D3DXVECTOR3 *pScale, // Returns the scale + __out D3DXQUATERNION *pRotation, // Returns the rotation as a quaternion + __out D3DXVECTOR3 *pTranslation) PURE; // Returns the translation + + // Callbacks + STDMETHOD(GetCallback)(THIS_ + DOUBLE Position, // Position from which to find callbacks + DWORD Flags, // Callback search flags + __out_opt DOUBLE *pCallbackPosition, // Returns the position of the callback + __deref_opt_out LPVOID *ppCallbackData) PURE; // Returns the callback data pointer + + // Playback + STDMETHOD_(D3DXPLAYBACK_TYPE, GetPlaybackType)(THIS) PURE; + STDMETHOD_(DOUBLE, GetSourceTicksPerSecond)(THIS) PURE; + + // Scale keys + STDMETHOD(GetCompressedData)(THIS_ __deref_out LPD3DXBUFFER *ppCompressedData) PURE; + + // Callback keys + STDMETHOD_(UINT, GetNumCallbackKeys)(THIS) PURE; + STDMETHOD(GetCallbackKeys)(THIS_ __out LPD3DXKEY_CALLBACK pCallbackKeys) PURE; +}; + + +//---------------------------------------------------------------------------- +// D3DXPRIORITY_TYPE: +// ------------------ +// This enum defines the type of priority group that a track can be assigned to. +//---------------------------------------------------------------------------- +typedef enum _D3DXPRIORITY_TYPE { + D3DXPRIORITY_LOW = 0, // This track should be blended with all low priority tracks before mixed with the high priority result + D3DXPRIORITY_HIGH = 1, // This track should be blended with all high priority tracks before mixed with the low priority result + + D3DXPRIORITY_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DXPRIORITY_TYPE; + +//---------------------------------------------------------------------------- +// D3DXTRACK_DESC: +// --------------- +// This structure describes the mixing information of an animation track. +// The mixing information consists of the current position, speed, and blending +// weight for the track. The Flags field also specifies whether the track is +// low or high priority. Tracks with the same priority are blended together +// and then the two resulting values are blended using the priority blend factor. +// A track also has an animation set (stored separately) associated with it. +//---------------------------------------------------------------------------- +typedef struct _D3DXTRACK_DESC +{ + D3DXPRIORITY_TYPE Priority; + FLOAT Weight; + FLOAT Speed; + DOUBLE Position; + BOOL Enable; +} D3DXTRACK_DESC, *LPD3DXTRACK_DESC; + +//---------------------------------------------------------------------------- +// D3DXEVENT_TYPE: +// --------------- +// This enum defines the type of events keyable via the animation controller. +//---------------------------------------------------------------------------- +typedef enum _D3DXEVENT_TYPE +{ + D3DXEVENT_TRACKSPEED = 0, + D3DXEVENT_TRACKWEIGHT = 1, + D3DXEVENT_TRACKPOSITION = 2, + D3DXEVENT_TRACKENABLE = 3, + D3DXEVENT_PRIORITYBLEND = 4, + + D3DXEVENT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DXEVENT_TYPE; + +//---------------------------------------------------------------------------- +// D3DXTRANSITION_TYPE: +// -------------------- +// This enum defines the type of transtion performed on a event that +// transitions from one value to another. +//---------------------------------------------------------------------------- +typedef enum _D3DXTRANSITION_TYPE { + D3DXTRANSITION_LINEAR = 0x000, // Linear transition from one value to the next + D3DXTRANSITION_EASEINEASEOUT = 0x001, // Ease-In Ease-Out spline transtion from one value to the next + + D3DXTRANSITION_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DXTRANSITION_TYPE; + +//---------------------------------------------------------------------------- +// D3DXEVENT_DESC: +// --------------- +// This structure describes a animation controller event. +// It gives the event's type, track (if the event is a track event), global +// start time, duration, transition method, and target value. +//---------------------------------------------------------------------------- +typedef struct _D3DXEVENT_DESC +{ + D3DXEVENT_TYPE Type; + UINT Track; + DOUBLE StartTime; + DOUBLE Duration; + D3DXTRANSITION_TYPE Transition; + union + { + FLOAT Weight; + FLOAT Speed; + DOUBLE Position; + BOOL Enable; + }; +} D3DXEVENT_DESC, *LPD3DXEVENT_DESC; + +//---------------------------------------------------------------------------- +// D3DXEVENTHANDLE: +// ---------------- +// Handle values used to efficiently reference animation controller events. +//---------------------------------------------------------------------------- +typedef DWORD D3DXEVENTHANDLE; +typedef D3DXEVENTHANDLE *LPD3DXEVENTHANDLE; + + +//---------------------------------------------------------------------------- +// ID3DXAnimationCallbackHandler: +// ------------------------------ +// This interface is intended to be implemented by the application, and can +// be used to handle callbacks in animation sets generated when +// ID3DXAnimationController::AdvanceTime() is called. +//---------------------------------------------------------------------------- +typedef interface ID3DXAnimationCallbackHandler ID3DXAnimationCallbackHandler; +typedef interface ID3DXAnimationCallbackHandler *LPD3DXANIMATIONCALLBACKHANDLER; + +#undef INTERFACE +#define INTERFACE ID3DXAnimationCallbackHandler + +DECLARE_INTERFACE(ID3DXAnimationCallbackHandler) +{ + //---------------------------------------------------------------------------- + // ID3DXAnimationCallbackHandler::HandleCallback: + // ---------------------------------------------- + // This method gets called when a callback occurs for an animation set in one + // of the tracks during the ID3DXAnimationController::AdvanceTime() call. + // + // Parameters: + // Track + // Index of the track on which the callback occured. + // pCallbackData + // Pointer to user owned callback data. + // + //---------------------------------------------------------------------------- + STDMETHOD(HandleCallback)(THIS_ UINT Track, __in LPVOID pCallbackData) PURE; +}; + + +//---------------------------------------------------------------------------- +// ID3DXAnimationController: +// ------------------------- +// This interface implements the main animation functionality. It connects +// animation sets with the transform frames that are being animated. Allows +// mixing multiple animations for blended animations or for transistions +// It adds also has methods to modify blending parameters over time to +// enable smooth transistions and other effects. +//---------------------------------------------------------------------------- +typedef interface ID3DXAnimationController ID3DXAnimationController; +typedef interface ID3DXAnimationController *LPD3DXANIMATIONCONTROLLER; + +#undef INTERFACE +#define INTERFACE ID3DXAnimationController + +DECLARE_INTERFACE_(ID3DXAnimationController, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Max sizes + STDMETHOD_(UINT, GetMaxNumAnimationOutputs)(THIS) PURE; + STDMETHOD_(UINT, GetMaxNumAnimationSets)(THIS) PURE; + STDMETHOD_(UINT, GetMaxNumTracks)(THIS) PURE; + STDMETHOD_(UINT, GetMaxNumEvents)(THIS) PURE; + + // Animation output registration + STDMETHOD(RegisterAnimationOutput)(THIS_ + __in_z LPCSTR pName, + __in_opt D3DXMATRIX *pMatrix, + __in_opt D3DXVECTOR3 *pScale, + __in_opt D3DXQUATERNION *pRotation, + __in_opt D3DXVECTOR3 *pTranslation) PURE; + + // Animation set registration + STDMETHOD(RegisterAnimationSet)(THIS_ __in LPD3DXANIMATIONSET pAnimSet) PURE; + STDMETHOD(UnregisterAnimationSet)(THIS_ __in LPD3DXANIMATIONSET pAnimSet) PURE; + + STDMETHOD_(UINT, GetNumAnimationSets)(THIS) PURE; + STDMETHOD(GetAnimationSet)(THIS_ UINT Index, __deref_out LPD3DXANIMATIONSET *ppAnimationSet) PURE; + + // Global time + STDMETHOD(AdvanceTime)(THIS_ DOUBLE TimeDelta, __in LPD3DXANIMATIONCALLBACKHANDLER pCallbackHandler) PURE; + STDMETHOD(ResetTime)(THIS) PURE; + STDMETHOD_(DOUBLE, GetTime)(THIS) PURE; + + // Tracks + STDMETHOD(SetTrackAnimationSet)(THIS_ UINT Track, __in LPD3DXANIMATIONSET pAnimSet) PURE; + STDMETHOD(GetTrackAnimationSet)(THIS_ UINT Track, __deref_out LPD3DXANIMATIONSET *ppAnimSet) PURE; + + STDMETHOD(SetTrackPriority)(THIS_ UINT Track, D3DXPRIORITY_TYPE Priority) PURE; + + STDMETHOD(SetTrackSpeed)(THIS_ UINT Track, FLOAT Speed) PURE; + STDMETHOD(SetTrackWeight)(THIS_ UINT Track, FLOAT Weight) PURE; + STDMETHOD(SetTrackPosition)(THIS_ UINT Track, DOUBLE Position) PURE; + STDMETHOD(SetTrackEnable)(THIS_ UINT Track, BOOL Enable) PURE; + + STDMETHOD(SetTrackDesc)(THIS_ UINT Track, __in LPD3DXTRACK_DESC pDesc) PURE; + STDMETHOD(GetTrackDesc)(THIS_ UINT Track, __out LPD3DXTRACK_DESC pDesc) PURE; + + // Priority blending + STDMETHOD(SetPriorityBlend)(THIS_ FLOAT BlendWeight) PURE; + STDMETHOD_(FLOAT, GetPriorityBlend)(THIS) PURE; + + // Event keying + STDMETHOD_(__out D3DXEVENTHANDLE, KeyTrackSpeed)(THIS_ UINT Track, FLOAT NewSpeed, DOUBLE StartTime, DOUBLE Duration, D3DXTRANSITION_TYPE Transition) PURE; + STDMETHOD_(__out D3DXEVENTHANDLE, KeyTrackWeight)(THIS_ UINT Track, FLOAT NewWeight, DOUBLE StartTime, DOUBLE Duration, D3DXTRANSITION_TYPE Transition) PURE; + STDMETHOD_(__out D3DXEVENTHANDLE, KeyTrackPosition)(THIS_ UINT Track, DOUBLE NewPosition, DOUBLE StartTime) PURE; + STDMETHOD_(__out D3DXEVENTHANDLE, KeyTrackEnable)(THIS_ UINT Track, BOOL NewEnable, DOUBLE StartTime) PURE; + + STDMETHOD_(__out D3DXEVENTHANDLE, KeyPriorityBlend)(THIS_ FLOAT NewBlendWeight, DOUBLE StartTime, DOUBLE Duration, D3DXTRANSITION_TYPE Transition) PURE; + + // Event unkeying + STDMETHOD(UnkeyEvent)(THIS_ __in D3DXEVENTHANDLE hEvent) PURE; + + STDMETHOD(UnkeyAllTrackEvents)(THIS_ UINT Track) PURE; + STDMETHOD(UnkeyAllPriorityBlends)(THIS) PURE; + + // Event enumeration + STDMETHOD_(__out D3DXEVENTHANDLE, GetCurrentTrackEvent)(THIS_ UINT Track, D3DXEVENT_TYPE EventType) PURE; + STDMETHOD_(__out D3DXEVENTHANDLE, GetCurrentPriorityBlend)(THIS) PURE; + + STDMETHOD_(__out D3DXEVENTHANDLE, GetUpcomingTrackEvent)(THIS_ UINT Track, __in D3DXEVENTHANDLE hEvent) PURE; + STDMETHOD_(__out D3DXEVENTHANDLE, GetUpcomingPriorityBlend)(THIS_ __in D3DXEVENTHANDLE hEvent) PURE; + + STDMETHOD(ValidateEvent)(THIS_ __in D3DXEVENTHANDLE hEvent) PURE; + + STDMETHOD(GetEventDesc)(THIS_ __in D3DXEVENTHANDLE hEvent, __out LPD3DXEVENT_DESC pDesc) PURE; + + // Cloning + STDMETHOD(CloneAnimationController)(THIS_ + UINT MaxNumAnimationOutputs, + UINT MaxNumAnimationSets, + UINT MaxNumTracks, + UINT MaxNumEvents, + __deref_out LPD3DXANIMATIONCONTROLLER *ppAnimController) PURE; +}; + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + + +//---------------------------------------------------------------------------- +// D3DXLoadMeshHierarchyFromX: +// --------------------------- +// Loads the first frame hierarchy in a .X file. +// +// Parameters: +// Filename +// Name of the .X file +// MeshOptions +// Mesh creation options for meshes in the file (see d3dx9mesh.h) +// pD3DDevice +// D3D9 device on which meshes in the file are created in +// pAlloc +// Allocation interface used to allocate nodes of the frame hierarchy +// pUserDataLoader +// Application provided interface to allow loading of user data +// ppFrameHierarchy +// Returns root node pointer of the loaded frame hierarchy +// ppAnimController +// Returns pointer to an animation controller corresponding to animation +// in the .X file. This is created with default max tracks and events +// +//---------------------------------------------------------------------------- +HRESULT WINAPI +D3DXLoadMeshHierarchyFromXA + ( + __in_z LPCSTR Filename, + DWORD MeshOptions, + __in LPDIRECT3DDEVICE9 pD3DDevice, + __in LPD3DXALLOCATEHIERARCHY pAlloc, + __in_opt LPD3DXLOADUSERDATA pUserDataLoader, + __deref_out LPD3DXFRAME *ppFrameHierarchy, + __deref_opt_out LPD3DXANIMATIONCONTROLLER *ppAnimController + ); + +HRESULT WINAPI +D3DXLoadMeshHierarchyFromXW + ( + __in_z LPCWSTR Filename, + DWORD MeshOptions, + __in LPDIRECT3DDEVICE9 pD3DDevice, + __in LPD3DXALLOCATEHIERARCHY pAlloc, + __in_opt LPD3DXLOADUSERDATA pUserDataLoader, + __deref_out LPD3DXFRAME *ppFrameHierarchy, + __deref_opt_out LPD3DXANIMATIONCONTROLLER *ppAnimController + ); + +#ifdef UNICODE +#define D3DXLoadMeshHierarchyFromX D3DXLoadMeshHierarchyFromXW +#else +#define D3DXLoadMeshHierarchyFromX D3DXLoadMeshHierarchyFromXA +#endif + +HRESULT WINAPI +D3DXLoadMeshHierarchyFromXInMemory + ( + __in_bcount(SizeOfMemory) LPCVOID Memory, + DWORD SizeOfMemory, + DWORD MeshOptions, + __in LPDIRECT3DDEVICE9 pD3DDevice, + __in LPD3DXALLOCATEHIERARCHY pAlloc, + __in_opt LPD3DXLOADUSERDATA pUserDataLoader, + __deref_out LPD3DXFRAME *ppFrameHierarchy, + __deref_opt_out LPD3DXANIMATIONCONTROLLER *ppAnimController + ); + +//---------------------------------------------------------------------------- +// D3DXSaveMeshHierarchyToFile: +// ---------------------------- +// Creates a .X file and saves the mesh hierarchy and corresponding animations +// in it +// +// Parameters: +// Filename +// Name of the .X file +// XFormat +// Format of the .X file (text or binary, compressed or not, etc) +// pFrameRoot +// Root node of the hierarchy to be saved +// pAnimController +// The animation controller whose animation sets are to be stored +// pUserDataSaver +// Application provided interface to allow adding of user data to +// data objects saved to .X file +// +//---------------------------------------------------------------------------- +HRESULT WINAPI +D3DXSaveMeshHierarchyToFileA + ( + __in_z LPCSTR Filename, + DWORD XFormat, + __in CONST D3DXFRAME *pFrameRoot, + __in_opt LPD3DXANIMATIONCONTROLLER pAnimcontroller, + __in_opt LPD3DXSAVEUSERDATA pUserDataSaver + ); + +HRESULT WINAPI +D3DXSaveMeshHierarchyToFileW + ( + __in_z LPCWSTR Filename, + DWORD XFormat, + __in CONST D3DXFRAME *pFrameRoot, + __in_opt LPD3DXANIMATIONCONTROLLER pAnimController, + __in_opt LPD3DXSAVEUSERDATA pUserDataSaver + ); + +#ifdef UNICODE +#define D3DXSaveMeshHierarchyToFile D3DXSaveMeshHierarchyToFileW +#else +#define D3DXSaveMeshHierarchyToFile D3DXSaveMeshHierarchyToFileA +#endif + +//---------------------------------------------------------------------------- +// D3DXFrameDestroy: +// ----------------- +// Destroys the subtree of frames under the root, including the root +// +// Parameters: +// pFrameRoot +// Pointer to the root node +// pAlloc +// Allocation interface used to de-allocate nodes of the frame hierarchy +// +//---------------------------------------------------------------------------- +HRESULT WINAPI +D3DXFrameDestroy + ( + __inout LPD3DXFRAME pFrameRoot, + __in LPD3DXALLOCATEHIERARCHY pAlloc + ); + +//---------------------------------------------------------------------------- +// D3DXFrameAppendChild: +// --------------------- +// Add a child frame to a frame +// +// Parameters: +// pFrameParent +// Pointer to the parent node +// pFrameChild +// Pointer to the child node +// +//---------------------------------------------------------------------------- +HRESULT WINAPI +D3DXFrameAppendChild + ( + __inout LPD3DXFRAME pFrameParent, + __in CONST D3DXFRAME *pFrameChild + ); + +//---------------------------------------------------------------------------- +// D3DXFrameFind: +// -------------- +// Finds a frame with the given name. Returns NULL if no frame found. +// +// Parameters: +// pFrameRoot +// Pointer to the root node +// Name +// Name of frame to find +// +//---------------------------------------------------------------------------- +LPD3DXFRAME WINAPI +D3DXFrameFind + ( + __in CONST D3DXFRAME *pFrameRoot, + __in_z LPCSTR Name + ); + +//---------------------------------------------------------------------------- +// D3DXFrameRegisterNamedMatrices: +// ------------------------------- +// Finds all frames that have non-null names and registers each of those frame +// matrices to the given animation controller +// +// Parameters: +// pFrameRoot +// Pointer to the root node +// pAnimController +// Pointer to the animation controller where the matrices are registered +// +//---------------------------------------------------------------------------- +HRESULT WINAPI +D3DXFrameRegisterNamedMatrices + ( + __in LPD3DXFRAME pFrameRoot, + __inout LPD3DXANIMATIONCONTROLLER pAnimController + ); + +//---------------------------------------------------------------------------- +// D3DXFrameNumNamedMatrices: +// -------------------------- +// Counts number of frames in a subtree that have non-null names +// +// Parameters: +// pFrameRoot +// Pointer to the root node of the subtree +// Return Value: +// Count of frames +// +//---------------------------------------------------------------------------- +UINT WINAPI +D3DXFrameNumNamedMatrices + ( + __in CONST D3DXFRAME *pFrameRoot + ); + +//---------------------------------------------------------------------------- +// D3DXFrameCalculateBoundingSphere: +// --------------------------------- +// Computes the bounding sphere of all the meshes in the frame hierarchy. +// +// Parameters: +// pFrameRoot +// Pointer to the root node +// pObjectCenter +// Returns the center of the bounding sphere +// pObjectRadius +// Returns the radius of the bounding sphere +// +//---------------------------------------------------------------------------- +HRESULT WINAPI +D3DXFrameCalculateBoundingSphere + ( + __in CONST D3DXFRAME *pFrameRoot, + __out_opt LPD3DXVECTOR3 pObjectCenter, + __out_opt FLOAT *pObjectRadius + ); + + +//---------------------------------------------------------------------------- +// D3DXCreateKeyframedAnimationSet: +// -------------------------------- +// This function creates a compressable keyframed animations set interface. +// +// Parameters: +// pName +// Name of the animation set +// TicksPerSecond +// Number of keyframe ticks that elapse per second +// Playback +// Playback mode of keyframe looping +// NumAnimations +// Number of SRT animations +// NumCallbackKeys +// Number of callback keys +// pCallbackKeys +// Array of callback keys +// ppAnimationSet +// Returns the animation set interface +// +//----------------------------------------------------------------------------- +HRESULT WINAPI +D3DXCreateKeyframedAnimationSet + ( + __in_z LPCSTR pName, + DOUBLE TicksPerSecond, + D3DXPLAYBACK_TYPE Playback, + UINT NumAnimations, + UINT NumCallbackKeys, + __in_ecount_opt(NumCallbackKeys) CONST D3DXKEY_CALLBACK *pCallbackKeys, + __deref_out LPD3DXKEYFRAMEDANIMATIONSET *ppAnimationSet + ); + + +//---------------------------------------------------------------------------- +// D3DXCreateCompressedAnimationSet: +// -------------------------------- +// This function creates a compressed animations set interface from +// compressed data. +// +// Parameters: +// pName +// Name of the animation set +// TicksPerSecond +// Number of keyframe ticks that elapse per second +// Playback +// Playback mode of keyframe looping +// pCompressedData +// Compressed animation SRT data +// NumCallbackKeys +// Number of callback keys +// pCallbackKeys +// Array of callback keys +// ppAnimationSet +// Returns the animation set interface +// +//----------------------------------------------------------------------------- +HRESULT WINAPI +D3DXCreateCompressedAnimationSet + ( + __in_z LPCSTR pName, + DOUBLE TicksPerSecond, + D3DXPLAYBACK_TYPE Playback, + __in LPD3DXBUFFER pCompressedData, + UINT NumCallbackKeys, + __in_ecount_opt(NumCallbackKeys) CONST D3DXKEY_CALLBACK *pCallbackKeys, + __deref_out LPD3DXCOMPRESSEDANIMATIONSET *ppAnimationSet + ); + + +//---------------------------------------------------------------------------- +// D3DXCreateAnimationController: +// ------------------------------ +// This function creates an animation controller object. +// +// Parameters: +// MaxNumMatrices +// Maximum number of matrices that can be animated +// MaxNumAnimationSets +// Maximum number of animation sets that can be played +// MaxNumTracks +// Maximum number of animation sets that can be blended +// MaxNumEvents +// Maximum number of outstanding events that can be scheduled at any given time +// ppAnimController +// Returns the animation controller interface +// +//----------------------------------------------------------------------------- +HRESULT WINAPI +D3DXCreateAnimationController + ( + UINT MaxNumMatrices, + UINT MaxNumAnimationSets, + UINT MaxNumTracks, + UINT MaxNumEvents, + __deref_out LPD3DXANIMATIONCONTROLLER *ppAnimController + ); + + +#ifdef __cplusplus +} +#endif //__cplusplus + +#endif //__D3DX9ANIM_H__ + + diff --git a/third_party/xbox_sdk/include/d3dx9core.h b/third_party/xbox_sdk/include/d3dx9core.h new file mode 100644 index 0000000..38a532c --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9core.h @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9core.h +// Content: D3DX core types and functions +// +/////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9CORE_H__ +#define __D3DX9CORE_H__ + + +/////////////////////////////////////////////////////////////////////////// +// D3DX_SDK_VERSION: +// ----------------- +// This identifier is passed to D3DXCheckVersion in order to ensure that an +// application was built against the correct header files and lib files. +// This number is incremented whenever a header (or other) change would +// require applications to be rebuilt. If the version doesn't match, +// D3DXCreateVersion will return FALSE. (The number itself has no meaning.) +/////////////////////////////////////////////////////////////////////////// + +#define D3DX_VERSION 0x0901 +#define D3DX_SDK_VERSION 21 + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +BOOL WINAPI + D3DXCheckVersion(UINT D3DSdkVersion, UINT D3DXSdkVersion); + +#ifdef __cplusplus +} +#endif //__cplusplus + + + +/////////////////////////////////////////////////////////////////////////// +// D3DXGetDriverLevel: +// Returns driver version information: +// +// 700 - DX7 level driver +// 800 - DX8 level driver +// 900 - DX9 level driver +/////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +UINT WINAPI + D3DXGetDriverLevel(__in LPDIRECT3DDEVICE9 pDevice); + +#ifdef __cplusplus +} +#endif //__cplusplus + + +/////////////////////////////////////////////////////////////////////////// +// ID3DXBuffer: +// ------------ +// The buffer object is used by D3DX to return arbitrary size data. +// +// GetBufferPointer - +// Returns a pointer to the beginning of the buffer. +// +// GetBufferSize - +// Returns the size of the buffer, in bytes. +/////////////////////////////////////////////////////////////////////////// + +typedef interface ID3DXBuffer ID3DXBuffer; +typedef interface ID3DXBuffer *LPD3DXBUFFER; + +// {932E6A7E-C68E-45dd-A7BF-53D19C86DB1F} +DEFINE_GUID(IID_ID3DXBuffer, +0x932e6a7e, 0xc68e, 0x45dd, 0xa7, 0xbf, 0x53, 0xd1, 0x9c, 0x86, 0xdb, 0x1f); + +#undef INTERFACE +#define INTERFACE ID3DXBuffer + +DECLARE_INTERFACE_(ID3DXBuffer, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXBuffer + STDMETHOD_(__out LPVOID, GetBufferPointer)(THIS) PURE; + STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE; +}; + + + + +/////////////////////////////////////////////////////////////////////////// +// ID3DXLine: +// ------------ +// This object intends to provide an easy way to draw lines using D3D. +// +// Begin - +// Prepares device for drawing lines +// +// Draw - +// Draws a line strip in screen-space. +// Input is in the form of a array defining points on the line strip. of D3DXVECTOR2 +// +// DrawTransform - +// Draws a line in screen-space with a specified input transformation matrix. +// +// End - +// Restores device state to how it was when Begin was called. +// +// SetPattern - +// Applies a stipple pattern to the line. Input is one 32-bit +// DWORD which describes the stipple pattern. 1 is opaque, 0 is +// transparent. +// +// SetPatternScale - +// Stretches the stipple pattern in the u direction. Input is one +// floating-point value. 0.0f is no scaling, whereas 1.0f doubles +// the length of the stipple pattern. +// +// SetWidth - +// Specifies the thickness of the line in the v direction. Input is +// one floating-point value. +// +// SetAntialias - +// Toggles line antialiasing. Input is a BOOL. +// TRUE = Antialiasing on. +// FALSE = Antialiasing off. +// +// SetGLLines - +// Toggles non-antialiased OpenGL line emulation. Input is a BOOL. +// TRUE = OpenGL line emulation on. +// FALSE = OpenGL line emulation off. +// +// OpenGL line: Regular line: +// *\ *\ +// | \ / \ +// | \ *\ \ +// *\ \ \ \ +// \ \ \ \ +// \ * \ * +// \ | \ / +// \| * +// * +// +// OnLostDevice, OnResetDevice - +// Call OnLostDevice() on this object before calling Reset() on the +// device, so that this object can release any stateblocks and video +// memory resources. After Reset(), the call OnResetDevice(). +/////////////////////////////////////////////////////////////////////////// + + +typedef interface ID3DXLine ID3DXLine; +typedef interface ID3DXLine *LPD3DXLINE; + + +// {72CE4D70-CC40-4143-A896-32E50AD2EF35} +DEFINE_GUID( IID_ID3DXLine, +0x72ce4d70, 0xcc40, 0x4143, 0xa8, 0x96, 0x32, 0xe5, 0xa, 0xd2, 0xef, 0x35); + +#undef INTERFACE +#define INTERFACE ID3DXLine + +DECLARE_INTERFACE_(ID3DXLine, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXLine + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + + STDMETHOD(Begin)(THIS) PURE; + + STDMETHOD(Draw)(THIS_ __in_ecount(dwVertexListCount) CONST D3DXVECTOR2 *pVertexList, + DWORD dwVertexListCount, D3DCOLOR Color) PURE; + + STDMETHOD(DrawTransform)(THIS_ __in_ecount(dwVertexListCount) CONST D3DXVECTOR3 *pVertexList, + DWORD dwVertexListCount, __in CONST D3DXMATRIX* pTransform, + D3DCOLOR Color) PURE; + + STDMETHOD(SetPattern)(THIS_ DWORD dwPattern) PURE; + STDMETHOD_(DWORD, GetPattern)(THIS) PURE; + + STDMETHOD(SetPatternScale)(THIS_ FLOAT fPatternScale) PURE; + STDMETHOD_(FLOAT, GetPatternScale)(THIS) PURE; + + STDMETHOD(SetWidth)(THIS_ FLOAT fWidth) PURE; + STDMETHOD_(FLOAT, GetWidth)(THIS) PURE; + + STDMETHOD(SetAntialias)(THIS_ BOOL bAntialias) PURE; + STDMETHOD_(BOOL, GetAntialias)(THIS) PURE; + + STDMETHOD(SetGLLines)(THIS_ BOOL bGLLines) PURE; + STDMETHOD_(BOOL, GetGLLines)(THIS) PURE; + + STDMETHOD(End)(THIS) PURE; + + STDMETHOD(OnLostDevice)(THIS) PURE; + STDMETHOD(OnResetDevice)(THIS) PURE; +}; + + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + + +HRESULT WINAPI + D3DXCreateLine( + __in LPDIRECT3DDEVICE9 pDevice, + __deref_out LPD3DXLINE* ppLine); + +#ifdef __cplusplus +} +#endif //__cplusplus + +#endif //__D3DX9CORE_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9effect.h b/third_party/xbox_sdk/include/d3dx9effect.h new file mode 100644 index 0000000..951f92c --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9effect.h @@ -0,0 +1,848 @@ + +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// File: d3dx9effect.h +// Content: D3DX effect types and Shaders +// +////////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9EFFECT_H__ +#define __D3DX9EFFECT_H__ + + +//---------------------------------------------------------------------------- +// D3DXFX_DONOTSAVESTATE +// This flag is used as a parameter to ID3DXEffect::Begin(). When this flag +// is specified, device state is not saved or restored in Begin/End. +// D3DXFX_DONOTSAVESHADERSTATE +// This flag is used as a parameter to ID3DXEffect::Begin(). When this flag +// is specified, shader device state is not saved or restored in Begin/End. +// This includes pixel/vertex shaders and shader constants +// D3DXFX_DONOTSAVESAMPLERSTATE +// This flag is used as a parameter to ID3DXEffect::Begin(). When this flag +// is specified, sampler device state is not saved or restored in Begin/End. +// D3DXFX_NOT_CLONEABLE +// This flag is used as a parameter to the D3DXCreateEffect family of APIs. +// When this flag is specified, the effect will be non-cloneable and will not +// contain any shader binary data. +// Furthermore, GetPassDesc will not return shader function pointers. +// Setting this flag reduces effect memory usage by about 50%. +//---------------------------------------------------------------------------- + +#define D3DXFX_DONOTSAVESTATE (1 << 0) +#define D3DXFX_DONOTSAVESHADERSTATE (1 << 1) +#define D3DXFX_DONOTSAVESAMPLERSTATE (1 << 2) +#define D3DXFX_NOT_CLONEABLE (1 << 11) +#define D3DXFX_CREATEEFFECT_VALID_PARAMS (D3DXFX_NOT_CLONEABLE) // internal + + +//---------------------------------------------------------------------------- +// D3DX_PARAMETER_SHARED +// Indicates that the value of a parameter will be shared with all effects +// which share the same namespace. Changing the value in one effect will +// change it in all. +// +// D3DX_PARAMETER_LITERAL +// Indicates that the value of this parameter can be treated as literal. +// Literal parameters can be marked when the effect is compiled, and their +// cannot be changed after the effect is compiled. Shared parameters cannot +// be literal. +//---------------------------------------------------------------------------- + +#define D3DX_PARAMETER_SHARED (1 << 0) +#define D3DX_PARAMETER_LITERAL (1 << 1) +#define D3DX_PARAMETER_ANNOTATION (1 << 2) +#define D3DX_PARAMETER_SKIPCONSTANT (1 << 3) // internal +#define D3DX_PARAMETER_EXTERNALVALID (D3DX_PARAMETER_SHARED|D3DX_PARAMETER_LITERAL|D3DX_PARAMETER_ANNOTATION) // internal + + +//---------------------------------------------------------------------------- +// D3DXEFFECT_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXEFFECT_DESC +{ + LPCSTR Creator; // Creator string + UINT Parameters; // Number of parameters + UINT Techniques; // Number of techniques + UINT Functions; // Number of function entrypoints + +} D3DXEFFECT_DESC; + + +//---------------------------------------------------------------------------- +// D3DXPARAMETER_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXPARAMETER_DESC +{ + LPCSTR Name; // Parameter name + LPCSTR Semantic; // Parameter semantic + D3DXPARAMETER_CLASS Class; // Class + D3DXPARAMETER_TYPE Type; // Component type + UINT Rows; // Number of rows + UINT Columns; // Number of columns + UINT Elements; // Number of array elements + UINT Annotations; // Number of annotations + UINT StructMembers; // Number of structure member sub-parameters + DWORD Flags; // D3DX_PARAMETER_* flags + UINT Bytes; // Parameter size, in bytes + +} D3DXPARAMETER_DESC; + + +//---------------------------------------------------------------------------- +// D3DXTECHNIQUE_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXTECHNIQUE_DESC +{ + LPCSTR Name; // Technique name + UINT Passes; // Number of passes + UINT Annotations; // Number of annotations + +} D3DXTECHNIQUE_DESC; + + +//---------------------------------------------------------------------------- +// D3DXPASS_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXPASS_DESC +{ + LPCSTR Name; // Pass name + UINT Annotations; // Number of annotations + + CONST DWORD *pVertexShaderFunction; // Vertex shader function + CONST DWORD *pPixelShaderFunction; // Pixel shader function + +} D3DXPASS_DESC; + + +//---------------------------------------------------------------------------- +// D3DXFUNCTION_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXFUNCTION_DESC +{ + LPCSTR Name; // Function name + UINT Annotations; // Number of annotations + +} D3DXFUNCTION_DESC; + + + +////////////////////////////////////////////////////////////////////////////// +// ID3DXEffectPool /////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +typedef interface ID3DXEffectPool ID3DXEffectPool; +typedef interface ID3DXEffectPool *LPD3DXEFFECTPOOL; + +// {9537AB04-3250-412e-8213-FCD2F8677933} +DEFINE_GUID(IID_ID3DXEffectPool, +0x9537ab04, 0x3250, 0x412e, 0x82, 0x13, 0xfc, 0xd2, 0xf8, 0x67, 0x79, 0x33); + + +#undef INTERFACE +#define INTERFACE ID3DXEffectPool + +DECLARE_INTERFACE_(ID3DXEffectPool, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // No public methods +}; + + +////////////////////////////////////////////////////////////////////////////// +// ID3DXBaseEffect /////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +typedef interface ID3DXBaseEffect ID3DXBaseEffect; +typedef interface ID3DXBaseEffect *LPD3DXBASEEFFECT; + +// {3B7A6FFB-3A69-46d7-BC01-A6B2AD4C2BB0} +DEFINE_GUID(IID_ID3DXBaseEffect, +0x3b7a6ffb, 0x3a69, 0x46d7, 0xbc, 0x1, 0xa6, 0xb2, 0xad, 0x4c, 0x2b, 0xb0); + + +#undef INTERFACE +#define INTERFACE ID3DXBaseEffect + +DECLARE_INTERFACE_(ID3DXBaseEffect, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Descs + STDMETHOD(GetDesc)(THIS_ __out D3DXEFFECT_DESC* pDesc) PURE; + STDMETHOD(GetParameterDesc)(THIS_ __in D3DXHANDLE hParameter, __out D3DXPARAMETER_DESC* pDesc) PURE; + STDMETHOD(GetTechniqueDesc)(THIS_ __in D3DXHANDLE hTechnique, __out D3DXTECHNIQUE_DESC* pDesc) PURE; + STDMETHOD(GetPassDesc)(THIS_ __in D3DXHANDLE hPass, __out D3DXPASS_DESC* pDesc) PURE; + STDMETHOD(GetFunctionDesc)(THIS_ __in D3DXHANDLE hShader, __out D3DXFUNCTION_DESC* pDesc) PURE; + + // Handle operations + STDMETHOD_(__out D3DXHANDLE, GetParameter)(THIS_ __in D3DXHANDLE hParameter, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterByName)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterBySemantic)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pSemantic) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterElement)(THIS_ __in D3DXHANDLE hParameter, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetTechnique)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetTechniqueByName)(THIS_ __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetPass)(THIS_ D3DXHANDLE __in hTechnique, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetPassByName)(THIS_ __in D3DXHANDLE hTechnique, __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFunction)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFunctionByName)(THIS_ __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetAnnotation)(THIS_ __in D3DXHANDLE hObject, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetAnnotationByName)(THIS_ __in D3DXHANDLE hObject, __in_z LPCSTR pName) PURE; + + // Get/Set Parameters + STDMETHOD(SetValue)(THIS_ __in D3DXHANDLE hParameter, __in_bcount(Bytes) LPCVOID pData, UINT Bytes) PURE; + STDMETHOD(GetValue)(THIS_ __in D3DXHANDLE hParameter, __out_bcount(Bytes) LPVOID pData, UINT Bytes) PURE; + STDMETHOD(SetBool)(THIS_ __in D3DXHANDLE hParameter, BOOL b) PURE; + STDMETHOD(GetBool)(THIS_ __in D3DXHANDLE hParameter, __out BOOL* pb) PURE; + STDMETHOD(SetBoolArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST BOOL* pb, UINT Count) PURE; + STDMETHOD(GetBoolArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) BOOL* pb, UINT Count) PURE; + STDMETHOD(SetInt)(THIS_ __in D3DXHANDLE hParameter, INT n) PURE; + STDMETHOD(GetInt)(THIS_ __in D3DXHANDLE hParameter, __out INT* pn) PURE; + STDMETHOD(SetIntArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST INT* pn, UINT Count) PURE; + STDMETHOD(GetIntArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) INT* pn, UINT Count) PURE; + STDMETHOD(SetFloat)(THIS_ __in D3DXHANDLE hParameter, FLOAT f) PURE; + STDMETHOD(GetFloat)(THIS_ __in D3DXHANDLE hParameter, __out FLOAT* pf) PURE; + STDMETHOD(SetFloatArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST FLOAT* pf, UINT Count) PURE; + STDMETHOD(GetFloatArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) FLOAT* pf, UINT Count) PURE; + STDMETHOD(SetVector)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXVECTOR4* pVector) PURE; + STDMETHOD(GetVector)(THIS_ __in D3DXHANDLE hParameter, __out D3DXVECTOR4* pVector) PURE; + STDMETHOD(SetVectorArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(GetVectorArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(SetMatrix)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(GetMatrix)(THIS_ __in D3DXHANDLE hParameter, __out D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixPointerArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixPointerArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTranspose)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(GetMatrixTranspose)(THIS_ __in D3DXHANDLE hParameter, __out D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixTransposeArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixTransposeArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTransposePointerArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixTransposePointerArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetString)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pString) PURE; + STDMETHOD(GetString)(THIS_ __in D3DXHANDLE hParameter, __deref_out_z LPCSTR* ppString) PURE; + STDMETHOD(SetTexture)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DBASETEXTURE9 pTexture) PURE; + STDMETHOD(GetTexture)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DBASETEXTURE9 *ppTexture) PURE; + STDMETHOD(SetPixelShader)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DPIXELSHADER9 pPShader) PURE; + STDMETHOD(GetPixelShader)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DPIXELSHADER9 *ppPShader) PURE; + STDMETHOD(SetVertexShader)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DVERTEXSHADER9 pVShader) PURE; + STDMETHOD(GetVertexShader)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DVERTEXSHADER9 *ppVShader) PURE; + + //Set Range of an Array to pass to device + //Useful for sending only a subrange of an array down to the device + STDMETHOD(SetArrayRange)(THIS_ __in D3DXHANDLE hParameter, UINT uStart, UINT uEnd) PURE; + +}; + + +//---------------------------------------------------------------------------- +// ID3DXEffectStateManager: +// ------------------------ +// This is a user implemented interface that can be used to manage device +// state changes made by an Effect. +//---------------------------------------------------------------------------- + +typedef interface ID3DXEffectStateManager ID3DXEffectStateManager; +typedef interface ID3DXEffectStateManager *LPD3DXEFFECTSTATEMANAGER; + +// {79AAB587-6DBC-4fa7-82DE-37FA1781C5CE} +DEFINE_GUID(IID_ID3DXEffectStateManager, +0x79aab587, 0x6dbc, 0x4fa7, 0x82, 0xde, 0x37, 0xfa, 0x17, 0x81, 0xc5, 0xce); + +#undef INTERFACE +#define INTERFACE ID3DXEffectStateManager + +DECLARE_INTERFACE_(ID3DXEffectStateManager, IUnknown) +{ + // The user must correctly implement QueryInterface, AddRef, and Release. + + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // The following methods are called by the Effect when it wants to make + // the corresponding device call. Note that: + // 1. Users manage the state and are therefore responsible for making the + // the corresponding device calls themselves inside their callbacks. + // 2. Effects pay attention to the return values of the callbacks, and so + // users must pay attention to what they return in their callbacks. + + STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State, __in CONST D3DMATRIX *pMatrix) PURE; + STDMETHOD(SetMaterial)(THIS_ __in CONST D3DMATERIAL9 *pMaterial) PURE; + STDMETHOD(SetLight)(THIS_ DWORD Index, __in CONST D3DLIGHT9 *pLight) PURE; + STDMETHOD(LightEnable)(THIS_ DWORD Index, BOOL Enable) PURE; + STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE State, DWORD Value) PURE; + STDMETHOD(SetTexture)(THIS_ DWORD Stage, __in LPDIRECT3DBASETEXTURE9 pTexture) PURE; + STDMETHOD(Do_Not_Use_SetTextureStageState)(THIS_ DWORD Stage, DWORD Type, DWORD Value) PURE; + STDMETHOD(SetSamplerState)(THIS_ DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value) PURE; + STDMETHOD(SetFVF)(THIS_ DWORD FVF) PURE; + STDMETHOD(SetVertexShader)(THIS_ __in LPDIRECT3DVERTEXSHADER9 pShader) PURE; + STDMETHOD(SetVertexShaderConstantF)(THIS_ UINT RegisterIndex, __in_ecount(4*RegisterCount) CONST FLOAT *pConstantData, UINT RegisterCount) PURE; + STDMETHOD(SetVertexShaderConstantI)(THIS_ UINT RegisterIndex, __in_ecount(4*RegisterCount) CONST INT *pConstantData, UINT RegisterCount) PURE; + STDMETHOD(SetVertexShaderConstantB)(THIS_ UINT RegisterIndex, __in_ecount(RegisterCount) CONST BOOL *pConstantData, UINT RegisterCount) PURE; + STDMETHOD(SetPixelShader)(THIS_ __in LPDIRECT3DPIXELSHADER9 pShader) PURE; + STDMETHOD(SetPixelShaderConstantF)(THIS_ UINT RegisterIndex, __in_ecount(4*RegisterCount) CONST FLOAT *pConstantData, UINT RegisterCount) PURE; + STDMETHOD(SetPixelShaderConstantI)(THIS_ UINT RegisterIndex, __in_ecount(4*RegisterCount) CONST INT *pConstantData, UINT RegisterCount) PURE; + STDMETHOD(SetPixelShaderConstantB)(THIS_ UINT RegisterIndex, __in_ecount(RegisterCount) CONST BOOL *pConstantData, UINT RegisterCount) PURE; +}; + + +////////////////////////////////////////////////////////////////////////////// +// ID3DXEffect /////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +typedef interface ID3DXEffect ID3DXEffect; +typedef interface ID3DXEffect *LPD3DXEFFECT; + +// {0F0DCC9F-6152-4117-A933-FFAC29C43AA4} +DEFINE_GUID(IID_ID3DXEffect, +0xf0dcc9f, 0x6152, 0x4117, 0xa9, 0x33, 0xff, 0xac, 0x29, 0xc4, 0x3a, 0xa4); + +#undef INTERFACE +#define INTERFACE ID3DXEffect + +DECLARE_INTERFACE_(ID3DXEffect, ID3DXBaseEffect) +{ + // ID3DXBaseEffect + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Descs + STDMETHOD(GetDesc)(THIS_ __out D3DXEFFECT_DESC* pDesc) PURE; + STDMETHOD(GetParameterDesc)(THIS_ __in D3DXHANDLE hParameter, __out D3DXPARAMETER_DESC* pDesc) PURE; + STDMETHOD(GetTechniqueDesc)(THIS_ __in D3DXHANDLE hTechnique, __out D3DXTECHNIQUE_DESC* pDesc) PURE; + STDMETHOD(GetPassDesc)(THIS_ __in D3DXHANDLE hPass, __out D3DXPASS_DESC* pDesc) PURE; + STDMETHOD(GetFunctionDesc)(THIS_ __in D3DXHANDLE hShader, __out D3DXFUNCTION_DESC* pDesc) PURE; + + // Handle operations + STDMETHOD_(__out D3DXHANDLE, GetParameter)(THIS_ __in D3DXHANDLE hParameter, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterByName)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterBySemantic)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pSemantic) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterElement)(THIS_ __in D3DXHANDLE hParameter, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetTechnique)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetTechniqueByName)(THIS_ __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetPass)(THIS_ __in D3DXHANDLE hTechnique, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetPassByName)(THIS_ __in D3DXHANDLE hTechnique, __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFunction)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFunctionByName)(THIS_ __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetAnnotation)(THIS_ __in D3DXHANDLE hObject, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetAnnotationByName)(THIS_ __in D3DXHANDLE hObject, __in_z LPCSTR pName) PURE; + + // Get/Set Parameters + STDMETHOD(SetValue)(THIS_ __in D3DXHANDLE hParameter, __in_bcount(Bytes) LPCVOID pData, UINT Bytes) PURE; + STDMETHOD(GetValue)(THIS_ __in D3DXHANDLE hParameter, __out_bcount(Bytes) LPVOID pData, UINT Bytes) PURE; + STDMETHOD(SetBool)(THIS_ __in D3DXHANDLE hParameter, BOOL b) PURE; + STDMETHOD(GetBool)(THIS_ __in D3DXHANDLE hParameter, __out BOOL* pb) PURE; + STDMETHOD(SetBoolArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST BOOL* pb, UINT Count) PURE; + STDMETHOD(GetBoolArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) BOOL* pb, UINT Count) PURE; + STDMETHOD(SetInt)(THIS_ __in D3DXHANDLE hParameter, INT n) PURE; + STDMETHOD(GetInt)(THIS_ __in D3DXHANDLE hParameter, __out INT* pn) PURE; + STDMETHOD(SetIntArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST INT* pn, UINT Count) PURE; + STDMETHOD(GetIntArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) INT* pn, UINT Count) PURE; + STDMETHOD(SetFloat)(THIS_ __in D3DXHANDLE hParameter, FLOAT f) PURE; + STDMETHOD(GetFloat)(THIS_ __in D3DXHANDLE hParameter, __out FLOAT* pf) PURE; + STDMETHOD(SetFloatArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST FLOAT* pf, UINT Count) PURE; + STDMETHOD(GetFloatArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) FLOAT* pf, UINT Count) PURE; + STDMETHOD(SetVector)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXVECTOR4* pVector) PURE; + STDMETHOD(GetVector)(THIS_ __in D3DXHANDLE hParameter, __out D3DXVECTOR4* pVector) PURE; + STDMETHOD(SetVectorArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(GetVectorArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(SetMatrix)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(GetMatrix)(THIS_ __in D3DXHANDLE hParameter, __out D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixPointerArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixPointerArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTranspose)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(GetMatrixTranspose)(THIS_ __in D3DXHANDLE hParameter, __out D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixTransposeArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixTransposeArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTransposePointerArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixTransposePointerArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetString)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pString) PURE; + STDMETHOD(GetString)(THIS_ __in D3DXHANDLE hParameter, __deref_out_z LPCSTR* ppString) PURE; + STDMETHOD(SetTexture)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DBASETEXTURE9 pTexture) PURE; + STDMETHOD(GetTexture)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DBASETEXTURE9 *ppTexture) PURE; + STDMETHOD(SetPixelShader)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DPIXELSHADER9 pPShader) PURE; + STDMETHOD(GetPixelShader)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DPIXELSHADER9 *ppPShader) PURE; + STDMETHOD(SetVertexShader)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DVERTEXSHADER9 pVShader) PURE; + STDMETHOD(GetVertexShader)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DVERTEXSHADER9 *ppVShader) PURE; + + //Set Range of an Array to pass to device + //Usefull for sending only a subrange of an array down to the device + STDMETHOD(SetArrayRange)(THIS_ __in D3DXHANDLE hParameter, UINT uStart, UINT uEnd) PURE; + // ID3DXBaseEffect + + + // Pool + STDMETHOD(GetPool)(THIS_ __deref_out LPD3DXEFFECTPOOL* ppPool) PURE; + + // Selecting and setting a technique + STDMETHOD(SetTechnique)(THIS_ __in D3DXHANDLE hTechnique) PURE; + STDMETHOD_(__out D3DXHANDLE, GetCurrentTechnique)(THIS) PURE; + STDMETHOD(ValidateTechnique)(THIS_ __in D3DXHANDLE hTechnique) PURE; + STDMETHOD(FindNextValidTechnique)(THIS_ __in D3DXHANDLE hTechnique, __deref_out D3DXHANDLE *pTechnique) PURE; + STDMETHOD_(BOOL, IsParameterUsed)(THIS_ __in D3DXHANDLE hParameter, __in D3DXHANDLE hTechnique) PURE; + + // Using current technique + // Begin starts active technique + // BeginPass begins a pass + // CommitChanges updates changes to any set calls in the pass. This should be called before + // any DrawPrimitive call to d3d + // EndPass ends a pass + // End ends active technique + STDMETHOD(Begin)(THIS_ __out UINT *pPasses, DWORD Flags) PURE; + STDMETHOD(BeginPass)(THIS_ UINT Pass) PURE; + STDMETHOD(CommitChanges)(THIS) PURE; + STDMETHOD(EndPass)(THIS) PURE; + STDMETHOD(End)(THIS) PURE; + + // Managing D3D Device + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + STDMETHOD(OnLostDevice)(THIS) PURE; + STDMETHOD(OnResetDevice)(THIS) PURE; + + // Logging device calls + STDMETHOD(SetStateManager)(THIS_ __in LPD3DXEFFECTSTATEMANAGER pManager) PURE; + STDMETHOD(GetStateManager)(THIS_ __deref_out LPD3DXEFFECTSTATEMANAGER *ppManager) PURE; + + // Parameter blocks + STDMETHOD(BeginParameterBlock)(THIS) PURE; + STDMETHOD_(__out D3DXHANDLE, EndParameterBlock)(THIS) PURE; + STDMETHOD(ApplyParameterBlock)(THIS_ __in D3DXHANDLE hParameterBlock) PURE; + + // Cloning + STDMETHOD(CloneEffect)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __deref_out LPD3DXEFFECT* ppEffect) PURE; +}; + + +////////////////////////////////////////////////////////////////////////////// +// ID3DXEffectCompiler /////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +typedef interface ID3DXEffectCompiler ID3DXEffectCompiler; +typedef interface ID3DXEffectCompiler *LPD3DXEFFECTCOMPILER; + +// {15A709EB-5A8E-40a0-86A9-0C024124339B} +DEFINE_GUID(IID_ID3DXEffectCompiler, +0x15a709eb, 0x5a8e, 0x40a0, 0x86, 0xa9, 0xc, 0x2, 0x41, 0x24, 0x33, 0x9b); + + +#undef INTERFACE +#define INTERFACE ID3DXEffectCompiler + +DECLARE_INTERFACE_(ID3DXEffectCompiler, ID3DXBaseEffect) +{ + // ID3DXBaseEffect + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Descs + STDMETHOD(GetDesc)(THIS_ __out D3DXEFFECT_DESC* pDesc) PURE; + STDMETHOD(GetParameterDesc)(THIS_ __in D3DXHANDLE hParameter, __out D3DXPARAMETER_DESC* pDesc) PURE; + STDMETHOD(GetTechniqueDesc)(THIS_ __in D3DXHANDLE hTechnique, __out D3DXTECHNIQUE_DESC* pDesc) PURE; + STDMETHOD(GetPassDesc)(THIS_ __in D3DXHANDLE hPass, __out D3DXPASS_DESC* pDesc) PURE; + STDMETHOD(GetFunctionDesc)(THIS_ __in D3DXHANDLE hShader, __out D3DXFUNCTION_DESC* pDesc) PURE; + + // Handle operations + STDMETHOD_(__out D3DXHANDLE, GetParameter)(THIS_ __in D3DXHANDLE hParameter, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterByName)(THIS_ __in D3DXHANDLE hParameter, LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterBySemantic)(THIS_ __in D3DXHANDLE hParameter, LPCSTR pSemantic) PURE; + STDMETHOD_(__out D3DXHANDLE, GetParameterElement)(THIS_ __in D3DXHANDLE hParameter, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetTechnique)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetTechniqueByName)(THIS_ LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetPass)(THIS_ __in D3DXHANDLE hTechnique, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetPassByName)(THIS_ __in D3DXHANDLE hTechnique, LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFunction)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFunctionByName)(THIS_ LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetAnnotation)(THIS_ __in D3DXHANDLE hObject, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetAnnotationByName)(THIS_ __in D3DXHANDLE hObject, LPCSTR pName) PURE; + + // Get/Set Parameters + STDMETHOD(SetValue)(THIS_ __in D3DXHANDLE hParameter, __in_bcount(Bytes) LPCVOID pData, UINT Bytes) PURE; + STDMETHOD(GetValue)(THIS_ __in D3DXHANDLE hParameter, __out_bcount(Bytes) LPVOID pData, UINT Bytes) PURE; + STDMETHOD(SetBool)(THIS_ __in D3DXHANDLE hParameter, BOOL b) PURE; + STDMETHOD(GetBool)(THIS_ __in D3DXHANDLE hParameter, __out BOOL* pb) PURE; + STDMETHOD(SetBoolArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST BOOL* pb, UINT Count) PURE; + STDMETHOD(GetBoolArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) BOOL* pb, UINT Count) PURE; + STDMETHOD(SetInt)(THIS_ __in D3DXHANDLE hParameter, INT n) PURE; + STDMETHOD(GetInt)(THIS_ __in D3DXHANDLE hParameter, __out INT* pn) PURE; + STDMETHOD(SetIntArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST INT* pn, UINT Count) PURE; + STDMETHOD(GetIntArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) INT* pn, UINT Count) PURE; + STDMETHOD(SetFloat)(THIS_ __in D3DXHANDLE hParameter, FLOAT f) PURE; + STDMETHOD(GetFloat)(THIS_ __in D3DXHANDLE hParameter, __out FLOAT* pf) PURE; + STDMETHOD(SetFloatArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST FLOAT* pf, UINT Count) PURE; + STDMETHOD(GetFloatArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) FLOAT* pf, UINT Count) PURE; + STDMETHOD(SetVector)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXVECTOR4* pVector) PURE; + STDMETHOD(GetVector)(THIS_ __in D3DXHANDLE hParameter, __out D3DXVECTOR4* pVector) PURE; + STDMETHOD(SetVectorArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(GetVectorArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(SetMatrix)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(GetMatrix)(THIS_ __in D3DXHANDLE hParameter, __out D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixPointerArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixPointerArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTranspose)(THIS_ __in D3DXHANDLE hParameter, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(GetMatrixTranspose)(THIS_ __in D3DXHANDLE hParameter, __out D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixTransposeArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixTransposeArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTransposePointerArray)(THIS_ __in D3DXHANDLE hParameter, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(GetMatrixTransposePointerArray)(THIS_ __in D3DXHANDLE hParameter, __out_ecount(Count) D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetString)(THIS_ __in D3DXHANDLE hParameter, __in_z LPCSTR pString) PURE; + STDMETHOD(GetString)(THIS_ __in D3DXHANDLE hParameter, __deref_out_z LPCSTR* ppString) PURE; + STDMETHOD(SetTexture)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DBASETEXTURE9 pTexture) PURE; + STDMETHOD(GetTexture)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DBASETEXTURE9 *ppTexture) PURE; + STDMETHOD(SetPixelShader)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DPIXELSHADER9 pPShader) PURE; + STDMETHOD(GetPixelShader)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DPIXELSHADER9 *ppPShader) PURE; + STDMETHOD(SetVertexShader)(THIS_ __in D3DXHANDLE hParameter, __in LPDIRECT3DVERTEXSHADER9 pVShader) PURE; + STDMETHOD(GetVertexShader)(THIS_ __in D3DXHANDLE hParameter, __deref_out LPDIRECT3DVERTEXSHADER9 *ppVShader) PURE; + + //Set Range of an Array to pass to device + //Usefull for sending only a subrange of an array down to the device + STDMETHOD(SetArrayRange)(THIS_ __in D3DXHANDLE hParameter, UINT uStart, UINT uEnd) PURE; + // ID3DXBaseEffect + + // Parameter sharing, specialization, and information + STDMETHOD(SetLiteral)(THIS_ __in D3DXHANDLE hParameter, BOOL Literal) PURE; + STDMETHOD(GetLiteral)(THIS_ __in D3DXHANDLE hParameter, __out BOOL *pLiteral) PURE; + + // Compilation + STDMETHOD(CompileEffect)(THIS_ DWORD Flags, + __in LPD3DXBUFFER* ppEffect, __deref_opt_out LPD3DXBUFFER* ppErrorMsgs) PURE; + + STDMETHOD(CompileShader)(THIS_ __in D3DXHANDLE hFunction, __in_z LPCSTR pTarget, DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable) PURE; +}; + + +////////////////////////////////////////////////////////////////////////////// +// APIs ////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +//---------------------------------------------------------------------------- +// D3DXCreateEffectPool: +// --------------------- +// Creates an effect pool. Pools are used for sharing parameters between +// multiple effects. For all effects within a pool, shared parameters of the +// same name all share the same value. +// +// Parameters: +// ppPool +// Returns the created pool. +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXCreateEffectPool( + __deref_out LPD3DXEFFECTPOOL* ppPool); + + +//---------------------------------------------------------------------------- +// D3DXCreateEffect: +// ----------------- +// Creates an effect from an ascii or binary effect description. +// +// Parameters: +// pDevice +// Pointer of the device on which to create the effect +// pSrcFile +// Name of the file containing the effect description +// hSrcModule +// Module handle. if NULL, current module will be used. +// pSrcResource +// Resource name in module +// pSrcData +// Pointer to effect description +// SrcDataSize +// Size of the effect description in bytes +// pDefines +// Optional NULL-terminated array of preprocessor macro definitions. +// pInclude +// Optional interface pointer to use for handling #include directives. +// If this parameter is NULL, #includes will be honored when compiling +// from file, and will error when compiling from resource or memory. +// pPool +// Pointer to ID3DXEffectPool object to use for shared parameters. +// If NULL, no parameters will be shared. +// ppEffect +// Returns a buffer containing created effect. +// ppCompilationErrors +// Returns a buffer containing any error messages which occurred during +// compile. Or NULL if you do not care about the error messages. +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXCreateEffectFromFileA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __in_opt LPD3DXEFFECTPOOL pPool, + __deref_out LPD3DXEFFECT* ppEffect, + __deref_opt_out LPD3DXBUFFER* ppCompilationErrors); + +HRESULT WINAPI + D3DXCreateEffectFromFileW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __in_opt LPD3DXEFFECTPOOL pPool, + __deref_out LPD3DXEFFECT* ppEffect, + __deref_opt_out LPD3DXBUFFER* ppCompilationErrors); + +#ifdef UNICODE +#define D3DXCreateEffectFromFile D3DXCreateEffectFromFileW +#else +#define D3DXCreateEffectFromFile D3DXCreateEffectFromFileA +#endif + + +#if 0 // Not on Xbox 360 + +HRESULT WINAPI + D3DXCreateEffectFromResourceA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + CONST D3DXMACRO* pDefines, + LPD3DXINCLUDE pInclude, + DWORD Flags, + LPD3DXEFFECTPOOL pPool, + LPD3DXEFFECT* ppEffect, + LPD3DXBUFFER* ppCompilationErrors); + +HRESULT WINAPI + D3DXCreateEffectFromResourceW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + CONST D3DXMACRO* pDefines, + LPD3DXINCLUDE pInclude, + DWORD Flags, + LPD3DXEFFECTPOOL pPool, + LPD3DXEFFECT* ppEffect, + LPD3DXBUFFER* ppCompilationErrors); + +#ifdef UNICODE +#define D3DXCreateEffectFromResource D3DXCreateEffectFromResourceW +#else +#define D3DXCreateEffectFromResource D3DXCreateEffectFromResourceA +#endif + +#endif // Not on Xbox 360 + + +HRESULT WINAPI + D3DXCreateEffect( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataLen) LPCVOID pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __in_opt LPD3DXEFFECTPOOL pPool, + __deref_out LPD3DXEFFECT* ppEffect, + __deref_opt_out LPD3DXBUFFER* ppCompilationErrors); + + + +//---------------------------------------------------------------------------- +// D3DXCreateEffectCompiler: +// ------------------------- +// Creates an effect from an ascii or binary effect description. +// +// Parameters: +// pSrcFile +// Name of the file containing the effect description +// hSrcModule +// Module handle. if NULL, current module will be used. +// pSrcResource +// Resource name in module +// pSrcData +// Pointer to effect description +// SrcDataSize +// Size of the effect description in bytes +// pDefines +// Optional NULL-terminated array of preprocessor macro definitions. +// pInclude +// Optional interface pointer to use for handling #include directives. +// If this parameter is NULL, #includes will be honored when compiling +// from file, and will error when compiling from resource or memory. +// pPool +// Pointer to ID3DXEffectPool object to use for shared parameters. +// If NULL, no parameters will be shared. +// ppCompiler +// Returns a buffer containing created effect compiler. +// ppParseErrors +// Returns a buffer containing any error messages which occurred during +// parse. Or NULL if you do not care about the error messages. +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXCreateEffectCompilerFromFileA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors); + +HRESULT WINAPI + D3DXCreateEffectCompilerFromFileW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors); + +#ifdef UNICODE +#define D3DXCreateEffectCompilerFromFile D3DXCreateEffectCompilerFromFileW +#else +#define D3DXCreateEffectCompilerFromFile D3DXCreateEffectCompilerFromFileA +#endif + + +HRESULT WINAPI + D3DXCreateEffectCompilerFromFileExA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors, + __deref_inout_opt D3DXSHADER_COMPILE_PARAMETERSA* pCompileParameters); // May be NULL. + +HRESULT WINAPI + D3DXCreateEffectCompilerFromFileExW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors, + __deref_inout_opt D3DXSHADER_COMPILE_PARAMETERSW* pCompileParameters); // May be NULL. + +#ifdef UNICODE +#define D3DXCreateEffectCompilerFromFileEx D3DXCreateEffectCompilerFromFileExW +#else +#define D3DXCreateEffectCompilerFromFileEx D3DXCreateEffectCompilerFromFileExA +#endif + + +HRESULT WINAPI + D3DXCreateEffectCompilerFromResourceA( + __in HMODULE hSrcModule, + __in_z LPCSTR pSrcResource, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors); + +HRESULT WINAPI + D3DXCreateEffectCompilerFromResourceW( + __in HMODULE hSrcModule, + __in_z LPCWSTR pSrcResource, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors); + +#ifdef UNICODE +#define D3DXCreateEffectCompilerFromResource D3DXCreateEffectCompilerFromResourceW +#else +#define D3DXCreateEffectCompilerFromResource D3DXCreateEffectCompilerFromResourceA +#endif + + +HRESULT WINAPI + D3DXCreateEffectCompiler( + __in_z LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors); + +HRESULT WINAPI + D3DXCreateEffectCompilerExA( + __in_z LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors, + __deref_inout_opt D3DXSHADER_COMPILE_PARAMETERSA* pCompileParameters); // May be NULL. + +HRESULT WINAPI + D3DXCreateEffectCompilerExW( + __in_z LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXEFFECTCOMPILER* ppCompiler, + __deref_opt_out LPD3DXBUFFER* ppParseErrors, + __deref_inout_opt D3DXSHADER_COMPILE_PARAMETERSW* pCompileParameters); // May be NULL. + +#ifdef UNICODE +#define D3DXCreateEffectCompilerEx D3DXCreateEffectCompilerExW +#else +#define D3DXCreateEffectCompilerEx D3DXCreateEffectCompilerExA +#endif + +//---------------------------------------------------------------------------- +// D3DXDisassembleEffect: +// ----------------------- +// +// Parameters: +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXDisassembleEffect( + __in LPD3DXEFFECT pEffect, + BOOL EnableColorCode, + __deref_out LPD3DXBUFFER *ppDisassembly); + + + +#ifdef __cplusplus +} +#endif //__cplusplus + +#endif //__D3DX9EFFECT_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9math.h b/third_party/xbox_sdk/include/d3dx9math.h new file mode 100644 index 0000000..a66fdfc --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9math.h @@ -0,0 +1,1778 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9math.h +// Content: D3DX math types and functions +// +////////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9MATH_H__ +#define __D3DX9MATH_H__ + +//#define _NO_XBOXMATH + +#include +#ifndef _NO_XBOXMATH +#include +#endif // _NO_XBOXMATH +#if _MSC_VER >= 1200 +#pragma warning(push) +#endif +#pragma warning(disable:4201) // anonymous unions warning + +//=========================================================================== +// +// General purpose utilities +// +//=========================================================================== +#define D3DX_PI ((FLOAT) 3.141592654f) +#define D3DX_1BYPI ((FLOAT) 0.318309886f) + +#define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f)) +#define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI)) + + + +//=========================================================================== +// +// 16 bit floating point numbers +// +//=========================================================================== + +#define D3DX_16F_DIG 3 // # of decimal digits of precision +#define D3DX_16F_EPSILON 4.8875809e-4f // smallest such that 1.0 + epsilon != 1.0 +#define D3DX_16F_MANT_DIG 11 // # of bits in mantissa +#define D3DX_16F_MAX 6.550400e+004 // max value +#define D3DX_16F_MAX_10_EXP 4 // max decimal exponent +#define D3DX_16F_MAX_EXP 15 // max binary exponent +#define D3DX_16F_MIN 6.1035156e-5f // min positive value +#define D3DX_16F_MIN_10_EXP (-4) // min decimal exponent +#define D3DX_16F_MIN_EXP (-12) // min binary exponent +#define D3DX_16F_RADIX 2 // exponent radix +#define D3DX_16F_ROUNDS 1 // addition rounding: near + + +typedef struct D3DXFLOAT16 +{ +#ifdef __cplusplus +public: + D3DXFLOAT16() {}; + D3DXFLOAT16( FLOAT ); + D3DXFLOAT16( CONST D3DXFLOAT16& ); + + // casting + operator FLOAT (); + + // binary operators + BOOL operator == ( CONST D3DXFLOAT16& ) const; + BOOL operator != ( CONST D3DXFLOAT16& ) const; + +protected: +#endif //__cplusplus + WORD value; +} D3DXFLOAT16, *LPD3DXFLOAT16; + + + +//=========================================================================== +// +// Vectors +// +//=========================================================================== + + +//-------------------------- +// 2D Vector +//-------------------------- +typedef struct D3DXVECTOR2 +{ +#ifdef __cplusplus +public: + D3DXVECTOR2() {}; + D3DXVECTOR2( __in CONST FLOAT * ); + D3DXVECTOR2( __in CONST D3DXFLOAT16 * ); + D3DXVECTOR2( FLOAT x, FLOAT y ); + + // casting + operator FLOAT* (); + operator CONST FLOAT * () const; + + // assignment operators + D3DXVECTOR2& operator = ( CONST D3DXVECTOR2& ); + D3DXVECTOR2& operator += ( CONST D3DXVECTOR2& ); + D3DXVECTOR2& operator -= ( CONST D3DXVECTOR2& ); + D3DXVECTOR2& operator *= ( FLOAT ); + D3DXVECTOR2& operator /= ( FLOAT ); + + // unary operators + D3DXVECTOR2 operator + () const; + D3DXVECTOR2 operator - () const; + + // binary operators + D3DXVECTOR2 operator + ( CONST D3DXVECTOR2& ) const; + D3DXVECTOR2 operator - ( CONST D3DXVECTOR2& ) const; + D3DXVECTOR2 operator * ( FLOAT ) const; + D3DXVECTOR2 operator / ( FLOAT ) const; + + friend D3DXVECTOR2 operator * ( FLOAT, CONST D3DXVECTOR2& ); + + BOOL operator == ( CONST D3DXVECTOR2& ) const; + BOOL operator != ( CONST D3DXVECTOR2& ) const; + + +public: +#endif //__cplusplus + FLOAT x, y; +} D3DXVECTOR2, *LPD3DXVECTOR2; + + + +//-------------------------- +// 2D Vector (16 bit) +//-------------------------- + +typedef struct D3DXVECTOR2_16F +{ +#ifdef __cplusplus +public: + D3DXVECTOR2_16F() {}; + D3DXVECTOR2_16F( __in CONST FLOAT * ); + D3DXVECTOR2_16F( __in CONST D3DXFLOAT16 * ); + D3DXVECTOR2_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y ); + + // casting + operator D3DXFLOAT16* (); + operator CONST D3DXFLOAT16 * () const; + + // assignment operators + D3DXVECTOR2_16F& operator = ( CONST D3DXVECTOR2_16F& ); + + // binary operators + BOOL operator == ( CONST D3DXVECTOR2_16F& ) const; + BOOL operator != ( CONST D3DXVECTOR2_16F& ) const; + +public: +#endif //__cplusplus + D3DXFLOAT16 x, y; + +} D3DXVECTOR2_16F, *LPD3DXVECTOR2_16F; + + + +//-------------------------- +// 3D Vector +//-------------------------- +#ifdef __cplusplus +typedef struct D3DXVECTOR3 : public D3DVECTOR +{ +public: + D3DXVECTOR3() {}; + D3DXVECTOR3( __in CONST FLOAT * ); + D3DXVECTOR3( CONST D3DVECTOR& ); + D3DXVECTOR3( __in CONST D3DXFLOAT16 * ); + D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z ); + + // casting + operator FLOAT* (); + operator CONST FLOAT * () const; + + // assignment operators + D3DXVECTOR3& operator = ( CONST D3DXVECTOR3& ); + D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& ); + D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& ); + D3DXVECTOR3& operator *= ( FLOAT ); + D3DXVECTOR3& operator /= ( FLOAT ); + + // unary operators + D3DXVECTOR3 operator + () const; + D3DXVECTOR3 operator - () const; + + // binary operators + D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const; + D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const; + D3DXVECTOR3 operator * ( FLOAT ) const; + D3DXVECTOR3 operator / ( FLOAT ) const; + + friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& ); + + BOOL operator == ( CONST D3DXVECTOR3& ) const; + BOOL operator != ( CONST D3DXVECTOR3& ) const; + +} D3DXVECTOR3, *LPD3DXVECTOR3; + +#else //!__cplusplus +typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3; +#endif //!__cplusplus + + + +//-------------------------- +// 3D Vector (16 bit) +//-------------------------- +typedef struct D3DXVECTOR3_16F +{ +#ifdef __cplusplus +public: + D3DXVECTOR3_16F() {}; + D3DXVECTOR3_16F( __in CONST FLOAT * ); + D3DXVECTOR3_16F( CONST D3DVECTOR& ); + D3DXVECTOR3_16F( __in CONST D3DXFLOAT16 * ); + D3DXVECTOR3_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y, CONST D3DXFLOAT16 &z ); + + // casting + operator D3DXFLOAT16* (); + operator CONST D3DXFLOAT16 * () const; + + // assignment operators + D3DXVECTOR3_16F& operator = ( CONST D3DXVECTOR3_16F& ); + + // binary operators + BOOL operator == ( CONST D3DXVECTOR3_16F& ) const; + BOOL operator != ( CONST D3DXVECTOR3_16F& ) const; + +public: +#endif //__cplusplus + D3DXFLOAT16 x, y, z; + +} D3DXVECTOR3_16F, *LPD3DXVECTOR3_16F; + + + +//-------------------------- +// 4D Vector +//-------------------------- +typedef struct D3DXVECTOR4 +{ +#ifdef __cplusplus +public: + D3DXVECTOR4() {}; + D3DXVECTOR4( __in CONST FLOAT * ); + D3DXVECTOR4( __in CONST D3DXFLOAT16 * ); + D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w ); + + // casting + operator FLOAT* (); + operator CONST FLOAT * () const; + + // assignment operators + D3DXVECTOR4& operator = ( CONST D3DXVECTOR4& ); + D3DXVECTOR4& operator += ( CONST D3DXVECTOR4& ); + D3DXVECTOR4& operator -= ( CONST D3DXVECTOR4& ); + D3DXVECTOR4& operator *= ( FLOAT ); + D3DXVECTOR4& operator /= ( FLOAT ); + + // unary operators + D3DXVECTOR4 operator + () const; + D3DXVECTOR4 operator - () const; + + // binary operators + D3DXVECTOR4 operator + ( CONST D3DXVECTOR4& ) const; + D3DXVECTOR4 operator - ( CONST D3DXVECTOR4& ) const; + D3DXVECTOR4 operator * ( FLOAT ) const; + D3DXVECTOR4 operator / ( FLOAT ) const; + + friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& ); + + BOOL operator == ( CONST D3DXVECTOR4& ) const; + BOOL operator != ( CONST D3DXVECTOR4& ) const; + +public: +#endif //__cplusplus + FLOAT x, y, z, w; +} D3DXVECTOR4, *LPD3DXVECTOR4; + + +//-------------------------- +// 4D Vector (16 bit) +//-------------------------- +typedef struct D3DXVECTOR4_16F +{ +#ifdef __cplusplus +public: + D3DXVECTOR4_16F() {}; + D3DXVECTOR4_16F( __in CONST FLOAT * ); + D3DXVECTOR4_16F( __in CONST D3DXFLOAT16 * ); + D3DXVECTOR4_16F( CONST D3DXFLOAT16& x, CONST D3DXFLOAT16& y, CONST D3DXFLOAT16& z, CONST D3DXFLOAT16& w ); + + // casting + operator D3DXFLOAT16* (); + operator CONST D3DXFLOAT16 * () const; + + // assignment operators + D3DXVECTOR4_16F& operator = ( CONST D3DXVECTOR4_16F& ); + + // binary operators + BOOL operator == ( CONST D3DXVECTOR4_16F& ) const; + BOOL operator != ( CONST D3DXVECTOR4_16F& ) const; + +public: +#endif //__cplusplus + D3DXFLOAT16 x, y, z, w; + +} D3DXVECTOR4_16F, *LPD3DXVECTOR4_16F; + + + +//=========================================================================== +// +// Matrices +// +//=========================================================================== +#ifdef __cplusplus +typedef struct D3DXMATRIX : public D3DMATRIX +{ +public: + D3DXMATRIX() {}; + D3DXMATRIX( __in CONST FLOAT * ); + D3DXMATRIX( CONST D3DMATRIX& ); + D3DXMATRIX( __in CONST D3DXFLOAT16 * ); + D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14, + FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24, + FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34, + FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ); + + + // access grants + FLOAT& operator () ( UINT Row, UINT Col ); + FLOAT operator () ( UINT Row, UINT Col ) const; + + // casting operators + operator FLOAT* (); + operator CONST FLOAT * () const; + + // assignment operators + D3DXMATRIX& operator = ( CONST D3DXMATRIX& ); + D3DXMATRIX& operator *= ( CONST D3DXMATRIX& ); + D3DXMATRIX& operator += ( CONST D3DXMATRIX& ); + D3DXMATRIX& operator -= ( CONST D3DXMATRIX& ); + D3DXMATRIX& operator *= ( FLOAT ); + D3DXMATRIX& operator /= ( FLOAT ); + + // unary operators + D3DXMATRIX operator + () const; + D3DXMATRIX operator - () const; + + // binary operators + D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const; + D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const; + D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const; + D3DXMATRIX operator * ( FLOAT ) const; + D3DXMATRIX operator / ( FLOAT ) const; + + friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& ); + + BOOL operator == ( CONST D3DXMATRIX& ) const; + BOOL operator != ( CONST D3DXMATRIX& ) const; + +} D3DXMATRIX, *LPD3DXMATRIX; + +#else //!__cplusplus +typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX; +#endif //!__cplusplus + + +//--------------------------------------------------------------------------- +// Aligned Matrices +// +// This class helps keep matrices 16-byte aligned as preferred by P4 cpus. +// It aligns matrices on the stack and on the heap or in global scope. +// It does this using __declspec(align(16)) which works on VC7 and on VC 6 +// with the processor pack. Unfortunately there is no way to detect the +// latter so this is turned on only on VC7. On other compilers this is the +// the same as D3DXMATRIX. +// +// Using this class on a compiler that does not actually do the alignment +// can be dangerous since it will not expose bugs that ignore alignment. +// E.g if an object of this class in inside a struct or class, and some code +// memcopys data in it assuming tight packing. This could break on a compiler +// that eventually start aligning the matrix. +//--------------------------------------------------------------------------- +#ifdef __cplusplus +typedef struct _D3DXMATRIXA16 : public D3DXMATRIX +{ + _D3DXMATRIXA16() {} + _D3DXMATRIXA16( __in CONST FLOAT * ); + _D3DXMATRIXA16( CONST D3DMATRIX& ); + _D3DXMATRIXA16( __in CONST D3DXFLOAT16 * ); + _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14, + FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24, + FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34, + FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ); + + // new operators + void* operator new ( size_t ); + void* operator new[] ( size_t ); + + // delete operators + void operator delete ( void* ); // These are NOT virtual; Do not + void operator delete[] ( void* ); // cast to D3DXMATRIX and delete. + + // assignment operators + _D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& ); + +} _D3DXMATRIXA16; + +#else //!__cplusplus +typedef D3DXMATRIX _D3DXMATRIXA16; +#endif //!__cplusplus + + + +#if _MSC_VER >= 1300 // VC7 +#define D3DX_ALIGN16 __declspec(align(16)) +#else +#define D3DX_ALIGN16 // Earlier compiler may not understand this, do nothing. +#endif + +typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16; + + + +//=========================================================================== +// +// Quaternions +// +//=========================================================================== +typedef struct D3DXQUATERNION +{ +#ifdef __cplusplus +public: + D3DXQUATERNION() {} + D3DXQUATERNION( __in CONST FLOAT * ); + D3DXQUATERNION( __in CONST D3DXFLOAT16 * ); + D3DXQUATERNION( FLOAT x, FLOAT y, FLOAT z, FLOAT w ); + + // casting + operator FLOAT* (); + operator CONST FLOAT * () const; + + // assignment operators + D3DXQUATERNION& operator = ( CONST D3DXQUATERNION& ); + D3DXQUATERNION& operator += ( CONST D3DXQUATERNION& ); + D3DXQUATERNION& operator -= ( CONST D3DXQUATERNION& ); + D3DXQUATERNION& operator *= ( CONST D3DXQUATERNION& ); + D3DXQUATERNION& operator *= ( FLOAT ); + D3DXQUATERNION& operator /= ( FLOAT ); + + // unary operators + D3DXQUATERNION operator + () const; + D3DXQUATERNION operator - () const; + + // binary operators + D3DXQUATERNION operator + ( CONST D3DXQUATERNION& ) const; + D3DXQUATERNION operator - ( CONST D3DXQUATERNION& ) const; + D3DXQUATERNION operator * ( CONST D3DXQUATERNION& ) const; + D3DXQUATERNION operator * ( FLOAT ) const; + D3DXQUATERNION operator / ( FLOAT ) const; + + friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION& ); + + BOOL operator == ( CONST D3DXQUATERNION& ) const; + BOOL operator != ( CONST D3DXQUATERNION& ) const; + +#endif //__cplusplus + FLOAT x, y, z, w; +} D3DXQUATERNION, *LPD3DXQUATERNION; + + +//=========================================================================== +// +// Planes +// +//=========================================================================== +typedef struct D3DXPLANE +{ +#ifdef __cplusplus +public: + D3DXPLANE() {} + D3DXPLANE( __in CONST FLOAT * ); + D3DXPLANE( __in CONST D3DXFLOAT16 * ); + D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d ); + + // casting + operator FLOAT* (); + operator CONST FLOAT * () const; + + // assignment operators + D3DXPLANE& operator = ( CONST D3DXPLANE& ); + D3DXPLANE& operator *= ( FLOAT ); + D3DXPLANE& operator /= ( FLOAT ); + + // unary operators + D3DXPLANE operator + () const; + D3DXPLANE operator - () const; + + // binary operators + D3DXPLANE operator * ( FLOAT ) const; + D3DXPLANE operator / ( FLOAT ) const; + + friend D3DXPLANE operator * ( FLOAT, CONST D3DXPLANE& ); + + BOOL operator == ( CONST D3DXPLANE& ) const; + BOOL operator != ( CONST D3DXPLANE& ) const; + +#endif //__cplusplus + FLOAT a, b, c, d; +} D3DXPLANE, *LPD3DXPLANE; + + +//=========================================================================== +// +// Colors +// +//=========================================================================== + +typedef struct D3DXCOLOR +{ +#ifdef __cplusplus +public: + D3DXCOLOR() {} + D3DXCOLOR( DWORD argb ); + D3DXCOLOR( __in CONST FLOAT * ); + D3DXCOLOR( __in CONST D3DXFLOAT16 * ); + D3DXCOLOR( CONST D3DCOLORVALUE& ); + D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a ); + + // casting + operator DWORD () const; + + operator FLOAT* (); + operator CONST FLOAT * () const; + + operator D3DCOLORVALUE* (); + operator CONST D3DCOLORVALUE * () const; + + operator D3DCOLORVALUE& (); + operator CONST D3DCOLORVALUE& () const; + + // assignment operators + D3DXCOLOR& operator = ( CONST D3DXCOLOR& ); + D3DXCOLOR& operator += ( CONST D3DXCOLOR& ); + D3DXCOLOR& operator -= ( CONST D3DXCOLOR& ); + D3DXCOLOR& operator *= ( FLOAT ); + D3DXCOLOR& operator /= ( FLOAT ); + + // unary operators + D3DXCOLOR operator + () const; + D3DXCOLOR operator - () const; + + // binary operators + D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const; + D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const; + D3DXCOLOR operator * ( FLOAT ) const; + D3DXCOLOR operator / ( FLOAT ) const; + + friend D3DXCOLOR operator * ( FLOAT, CONST D3DXCOLOR& ); + + BOOL operator == ( CONST D3DXCOLOR& ) const; + BOOL operator != ( CONST D3DXCOLOR& ) const; + +#endif //__cplusplus + FLOAT r, g, b, a; +} D3DXCOLOR, *LPD3DXCOLOR; + + + +//=========================================================================== +// +// D3DX math functions: +// +// NOTE: +// * All these functions can take the same object as in and out parameters. +// +// * Out parameters are typically also returned as return values, so that +// the output of one function may be used as a parameter to another. +// +//=========================================================================== + +//-------------------------- +// Float16 +//-------------------------- + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +// Converts an array 32-bit floats to 16-bit floats +D3DXFLOAT16* WINAPI D3DXFloat32To16Array + ( __out_ecount(n) D3DXFLOAT16 *pOut, __in_ecount(n) CONST FLOAT *pIn, UINT n ); + +// Converts an array 16-bit floats to 32-bit floats +FLOAT* WINAPI D3DXFloat16To32Array + ( __out_ecount(n) FLOAT *pOut, __in_ecount(n) CONST D3DXFLOAT16 *pIn, UINT n ); + +#ifdef __cplusplus +} +#endif + + +//-------------------------- +// 2D Vector +//-------------------------- + +// inline + +FLOAT D3DXVec2Length + ( __in CONST D3DXVECTOR2 *pV ); + +FLOAT D3DXVec2LengthSq + ( __in CONST D3DXVECTOR2 *pV ); + +FLOAT D3DXVec2Dot + ( __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ); + +// Z component of ((x1,y1,0) cross (x2,y2,0)) +FLOAT D3DXVec2CCW + ( __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ); + +D3DXVECTOR2* D3DXVec2Add + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ); + +D3DXVECTOR2* D3DXVec2Subtract + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ); + +// Minimize each component. x = min(x1, x2), y = min(y1, y2) +D3DXVECTOR2* D3DXVec2Minimize + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ); + +// Maximize each component. x = max(x1, x2), y = max(y1, y2) +D3DXVECTOR2* D3DXVec2Maximize + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ); + +D3DXVECTOR2* D3DXVec2Scale + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV, FLOAT s ); + +// Linear interpolation. V1 + s(V2-V1) +D3DXVECTOR2* D3DXVec2Lerp + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2, + FLOAT s ); + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +D3DXVECTOR2* WINAPI D3DXVec2Normalize + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV ); + +// Hermite interpolation between position V1, tangent T1 (when s == 0) +// and position V2, tangent T2 (when s == 1). +D3DXVECTOR2* WINAPI D3DXVec2Hermite + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pT1, + __in CONST D3DXVECTOR2 *pV2, __in CONST D3DXVECTOR2 *pT2, FLOAT s ); + +// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1) +D3DXVECTOR2* WINAPI D3DXVec2CatmullRom + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV0, __in CONST D3DXVECTOR2 *pV1, + __in CONST D3DXVECTOR2 *pV2, __in CONST D3DXVECTOR2 *pV3, FLOAT s ); + +// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1) +D3DXVECTOR2* WINAPI D3DXVec2BaryCentric + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2, + __in CONST D3DXVECTOR2 *pV3, FLOAT f, FLOAT g); + +// Transform (x, y, 0, 1) by matrix. +D3DXVECTOR4* WINAPI D3DXVec2Transform + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR2 *pV, __in CONST D3DXMATRIX *pM ); + +// Transform (x, y, 0, 1) by matrix, project result back into w=1. +D3DXVECTOR2* WINAPI D3DXVec2TransformCoord + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV, __in CONST D3DXMATRIX *pM ); + +// Transform (x, y, 0, 0) by matrix. +D3DXVECTOR2* WINAPI D3DXVec2TransformNormal + ( __out D3DXVECTOR2 *pOut, __in CONST D3DXVECTOR2 *pV, __in CONST D3DXMATRIX *pM ); + +// Transform Array (x, y, 0, 1) by matrix. +D3DXVECTOR4* WINAPI D3DXVec2TransformArray + ( __out D3DXVECTOR4 *pOut, UINT OutStride, __in CONST D3DXVECTOR2 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n); + +// Transform Array (x, y, 0, 1) by matrix, project result back into w=1. +D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray + ( __out D3DXVECTOR2 *pOut, UINT OutStride, __in CONST D3DXVECTOR2 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n ); + +// Transform Array (x, y, 0, 0) by matrix. +D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray + ( __out D3DXVECTOR2 *pOut, UINT OutStride, __in CONST D3DXVECTOR2 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n ); + + + +#ifdef __cplusplus +} +#endif + + +//-------------------------- +// 3D Vector +//-------------------------- + +// inline + +FLOAT D3DXVec3Length + ( __in CONST D3DXVECTOR3 *pV ); + +FLOAT D3DXVec3LengthSq + ( __in CONST D3DXVECTOR3 *pV ); + +FLOAT D3DXVec3Dot + ( __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ); + +D3DXVECTOR3* D3DXVec3Cross + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ); + +D3DXVECTOR3* D3DXVec3Add + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ); + +D3DXVECTOR3* D3DXVec3Subtract + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ); + +// Minimize each component. x = min(x1, x2), y = min(y1, y2), ... +D3DXVECTOR3* D3DXVec3Minimize + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ); + +// Maximize each component. x = max(x1, x2), y = max(y1, y2), ... +D3DXVECTOR3* D3DXVec3Maximize + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ); + +D3DXVECTOR3* D3DXVec3Scale + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV, FLOAT s); + +// Linear interpolation. V1 + s(V2-V1) +D3DXVECTOR3* D3DXVec3Lerp + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2, + FLOAT s ); + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +D3DXVECTOR3* WINAPI D3DXVec3Normalize + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV ); + +// Hermite interpolation between position V1, tangent T1 (when s == 0) +// and position V2, tangent T2 (when s == 1). +D3DXVECTOR3* WINAPI D3DXVec3Hermite + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pT1, + __in CONST D3DXVECTOR3 *pV2, __in CONST D3DXVECTOR3 *pT2, FLOAT s ); + +// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1) +D3DXVECTOR3* WINAPI D3DXVec3CatmullRom + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV0, __in CONST D3DXVECTOR3 *pV1, + __in CONST D3DXVECTOR3 *pV2, __in CONST D3DXVECTOR3 *pV3, FLOAT s ); + +// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1) +D3DXVECTOR3* WINAPI D3DXVec3BaryCentric + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2, + __in CONST D3DXVECTOR3 *pV3, FLOAT f, FLOAT g); + +// Transform (x, y, z, 1) by matrix. +D3DXVECTOR4* WINAPI D3DXVec3Transform + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR3 *pV, __in CONST D3DXMATRIX *pM ); + +// Transform (x, y, z, 1) by matrix, project result back into w=1. +D3DXVECTOR3* WINAPI D3DXVec3TransformCoord + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV, __in CONST D3DXMATRIX *pM ); + +// Transform (x, y, z, 0) by matrix. If you transforming a normal by a +// non-affine matrix, the matrix you pass to this function should be the +// transpose of the inverse of the matrix you would use to transform a coord. +D3DXVECTOR3* WINAPI D3DXVec3TransformNormal + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV, __in CONST D3DXMATRIX *pM ); + + +// Transform Array (x, y, z, 1) by matrix. +D3DXVECTOR4* WINAPI D3DXVec3TransformArray + ( __out D3DXVECTOR4 *pOut, UINT OutStride, __in CONST D3DXVECTOR3 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n ); + +// Transform Array (x, y, z, 1) by matrix, project result back into w=1. +D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray + ( __out D3DXVECTOR3 *pOut, UINT OutStride, __in CONST D3DXVECTOR3 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n ); + +// Transform (x, y, z, 0) by matrix. If you transforming a normal by a +// non-affine matrix, the matrix you pass to this function should be the +// transpose of the inverse of the matrix you would use to transform a coord. +D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray + ( __out D3DXVECTOR3 *pOut, UINT OutStride, __in CONST D3DXVECTOR3 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n ); + +// Project vector from object space into screen space +D3DXVECTOR3* WINAPI D3DXVec3Project + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV, __in CONST D3DVIEWPORT9 *pViewport, + __in CONST D3DXMATRIX *pProjection, __in CONST D3DXMATRIX *pView, __in CONST D3DXMATRIX *pWorld); + +// Project vector from screen space into object space +D3DXVECTOR3* WINAPI D3DXVec3Unproject + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXVECTOR3 *pV, __in CONST D3DVIEWPORT9 *pViewport, + __in CONST D3DXMATRIX *pProjection, __in CONST D3DXMATRIX *pView, __in CONST D3DXMATRIX *pWorld); + +// Project vector Array from object space into screen space +D3DXVECTOR3* WINAPI D3DXVec3ProjectArray + ( __out D3DXVECTOR3 *pOut, UINT OutStride,__in CONST D3DXVECTOR3 *pV, UINT VStride,__in CONST D3DVIEWPORT9 *pViewport, + __in CONST D3DXMATRIX *pProjection, __in CONST D3DXMATRIX *pView, __in CONST D3DXMATRIX *pWorld, UINT n); + +// Project vector Array from screen space into object space +D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray + ( __out D3DXVECTOR3 *pOut, UINT OutStride, __in CONST D3DXVECTOR3 *pV, UINT VStride, __in CONST D3DVIEWPORT9 *pViewport, + __in CONST D3DXMATRIX *pProjection, __in CONST D3DXMATRIX *pView, __in CONST D3DXMATRIX *pWorld, UINT n); + + +#ifdef __cplusplus +} +#endif + + + +//-------------------------- +// 4D Vector +//-------------------------- + +// inline + +FLOAT D3DXVec4Length + ( __in CONST D3DXVECTOR4 *pV ); + +FLOAT D3DXVec4LengthSq + ( __in CONST D3DXVECTOR4 *pV ); + +FLOAT D3DXVec4Dot + ( __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2 ); + +D3DXVECTOR4* D3DXVec4Add + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2); + +D3DXVECTOR4* D3DXVec4Subtract + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2); + +// Minimize each component. x = min(x1, x2), y = min(y1, y2), ... +D3DXVECTOR4* D3DXVec4Minimize + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2); + +// Maximize each component. x = max(x1, x2), y = max(y1, y2), ... +D3DXVECTOR4* D3DXVec4Maximize + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2); + +D3DXVECTOR4* D3DXVec4Scale + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV, FLOAT s); + +// Linear interpolation. V1 + s(V2-V1) +D3DXVECTOR4* D3DXVec4Lerp + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2, + FLOAT s ); + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +// Cross-product in 4 dimensions. +D3DXVECTOR4* WINAPI D3DXVec4Cross + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2, + __in CONST D3DXVECTOR4 *pV3); + +D3DXVECTOR4* WINAPI D3DXVec4Normalize + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV ); + +// Hermite interpolation between position V1, tangent T1 (when s == 0) +// and position V2, tangent T2 (when s == 1). +D3DXVECTOR4* WINAPI D3DXVec4Hermite + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pT1, + __in CONST D3DXVECTOR4 *pV2, __in CONST D3DXVECTOR4 *pT2, FLOAT s ); + +// CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1) +D3DXVECTOR4* WINAPI D3DXVec4CatmullRom + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV0, __in CONST D3DXVECTOR4 *pV1, + __in CONST D3DXVECTOR4 *pV2, __in CONST D3DXVECTOR4 *pV3, FLOAT s ); + +// Barycentric coordinates. V1 + f(V2-V1) + g(V3-V1) +D3DXVECTOR4* WINAPI D3DXVec4BaryCentric + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2, + __in CONST D3DXVECTOR4 *pV3, FLOAT f, FLOAT g); + +// Transform vector by matrix. +D3DXVECTOR4* WINAPI D3DXVec4Transform + ( __out D3DXVECTOR4 *pOut, __in CONST D3DXVECTOR4 *pV, __in CONST D3DXMATRIX *pM ); + +// Transform vector array by matrix. +D3DXVECTOR4* WINAPI D3DXVec4TransformArray + ( __out D3DXVECTOR4 *pOut, UINT OutStride, __in CONST D3DXVECTOR4 *pV, UINT VStride, __in CONST D3DXMATRIX *pM, UINT n ); + +#ifdef __cplusplus +} +#endif + + +//-------------------------- +// 4D Matrix +//-------------------------- + +// inline + +D3DXMATRIX* D3DXMatrixIdentity + ( __out D3DXMATRIX *pOut ); + +BOOL D3DXMatrixIsIdentity + ( __in CONST D3DXMATRIX *pM ); + + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +FLOAT WINAPI D3DXMatrixDeterminant + ( __in CONST D3DXMATRIX *pM ); + +D3DXMATRIX* WINAPI D3DXMatrixTranspose + ( __out D3DXMATRIX *pOut, __in CONST D3DXMATRIX *pM ); + +// Matrix multiplication. The result represents the transformation M2 +// followed by the transformation M1. (Out = M1 * M2) +D3DXMATRIX* WINAPI D3DXMatrixMultiply + ( __out D3DXMATRIX *pOut, __in CONST D3DXMATRIX *pM1, __in CONST D3DXMATRIX *pM2 ); + +// Matrix multiplication, followed by a transpose. (Out = T(M1 * M2)) +D3DXMATRIX* WINAPI D3DXMatrixMultiplyTranspose + ( __out D3DXMATRIX *pOut, __in CONST D3DXMATRIX *pM1, __in CONST D3DXMATRIX *pM2 ); + +// Calculate inverse of matrix. Inversion my fail, in which case NULL will +// be returned. The determinant of pM is also returned it pfDeterminant +// is non-NULL. +D3DXMATRIX* WINAPI D3DXMatrixInverse + ( __out D3DXMATRIX *pOut, FLOAT *pDeterminant, __in CONST D3DXMATRIX *pM ); + +// Build a matrix which scales by (sx, sy, sz) +D3DXMATRIX* WINAPI D3DXMatrixScaling + ( __out D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz ); + +// Build a matrix which translates by (x, y, z) +D3DXMATRIX* WINAPI D3DXMatrixTranslation + ( __out D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z ); + +// Build a matrix which rotates around the X axis +D3DXMATRIX* WINAPI D3DXMatrixRotationX + ( __out D3DXMATRIX *pOut, FLOAT Angle ); + +// Build a matrix which rotates around the Y axis +D3DXMATRIX* WINAPI D3DXMatrixRotationY + ( __out D3DXMATRIX *pOut, FLOAT Angle ); + +// Build a matrix which rotates around the Z axis +D3DXMATRIX* WINAPI D3DXMatrixRotationZ + ( __out D3DXMATRIX *pOut, FLOAT Angle ); + +// Build a matrix which rotates around an arbitrary axis +D3DXMATRIX* WINAPI D3DXMatrixRotationAxis + ( __out D3DXMATRIX *pOut, __in CONST D3DXVECTOR3 *pV, FLOAT Angle ); + +// Build a matrix from a quaternion +D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion + ( __out D3DXMATRIX *pOut, __in CONST D3DXQUATERNION *pQ); + +// Yaw around the Y axis, a pitch around the X axis, +// and a roll around the Z axis. +D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll + ( __out D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll ); + +// Build transformation matrix. NULL arguments are treated as identity. +// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt +D3DXMATRIX* WINAPI D3DXMatrixTransformation + ( __out D3DXMATRIX *pOut, __in_opt CONST D3DXVECTOR3 *pScalingCenter, + __in_opt CONST D3DXQUATERNION *pScalingRotation, __in_opt CONST D3DXVECTOR3 *pScaling, + __in_opt CONST D3DXVECTOR3 *pRotationCenter, __in_opt CONST D3DXQUATERNION *pRotation, + __in_opt CONST D3DXVECTOR3 *pTranslation); + +// Build 2D transformation matrix in XY plane. NULL arguments are treated as identity. +// Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt +D3DXMATRIX* WINAPI D3DXMatrixTransformation2D + ( __out D3DXMATRIX *pOut, __in_opt CONST D3DXVECTOR2 * pScalingCenter, + FLOAT ScalingRotation, __in_opt CONST D3DXVECTOR2 * pScaling, + __in_opt CONST D3DXVECTOR2 * pRotationCenter, FLOAT Rotation, + __in_opt CONST D3DXVECTOR2 * pTranslation); + +// Build affine transformation matrix. NULL arguments are treated as identity. +// Mout = Ms * Mrc-1 * Mr * Mrc * Mt +D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation + ( __out D3DXMATRIX *pOut, FLOAT Scaling, __in_opt CONST D3DXVECTOR3 *pRotationCenter, + __in_opt CONST D3DXQUATERNION *pRotation, __in_opt CONST D3DXVECTOR3 *pTranslation); + +// Build 2D affine transformation matrix in XY plane. NULL arguments are treated as identity. +// Mout = Ms * Mrc-1 * Mr * Mrc * Mt +D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D + ( __out D3DXMATRIX *pOut, FLOAT Scaling, __in_opt CONST D3DXVECTOR2 * pRotationCenter, + FLOAT Rotation, __in_opt CONST D3DXVECTOR2 * pTranslation); + +// Build a lookat matrix. (right-handed) +D3DXMATRIX* WINAPI D3DXMatrixLookAtRH + ( __out D3DXMATRIX *pOut, __in CONST D3DXVECTOR3 *pEye, __in CONST D3DXVECTOR3 *pAt, + __in CONST D3DXVECTOR3 *pUp ); + +// Build a lookat matrix. (left-handed) +D3DXMATRIX* WINAPI D3DXMatrixLookAtLH + ( __out D3DXMATRIX *pOut, __in CONST D3DXVECTOR3 *pEye, __in CONST D3DXVECTOR3 *pAt, + __in CONST D3DXVECTOR3 *pUp ); + +// Build a perspective projection matrix. (right-handed) +D3DXMATRIX* WINAPI D3DXMatrixPerspectiveRH + ( __out D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf ); + +// Build a perspective projection matrix. (left-handed) +D3DXMATRIX* WINAPI D3DXMatrixPerspectiveLH + ( __out D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf ); + +// Build a perspective projection matrix. (right-handed) +D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovRH + ( __out D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf ); + +// Build a perspective projection matrix. (left-handed) +D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH + ( __out D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf ); + +// Build a perspective projection matrix. (right-handed) +D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterRH + ( __out D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, + FLOAT zf ); + +// Build a perspective projection matrix. (left-handed) +D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterLH + ( __out D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, + FLOAT zf ); + +// Build an ortho projection matrix. (right-handed) +D3DXMATRIX* WINAPI D3DXMatrixOrthoRH + ( __out D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf ); + +// Build an ortho projection matrix. (left-handed) +D3DXMATRIX* WINAPI D3DXMatrixOrthoLH + ( __out D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf ); + +// Build an ortho projection matrix. (right-handed) +D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterRH + ( __out D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, + FLOAT zf ); + +// Build an ortho projection matrix. (left-handed) +D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterLH + ( __out D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, + FLOAT zf ); + +// Build a matrix which flattens geometry into a plane, as if casting +// a shadow from a light. +D3DXMATRIX* WINAPI D3DXMatrixShadow + ( __out D3DXMATRIX *pOut, __in CONST D3DXVECTOR4 *pLight, + __in CONST D3DXPLANE *pPlane ); + +// Build a matrix which reflects the coordinate system about a plane +D3DXMATRIX* WINAPI D3DXMatrixReflect + ( __out D3DXMATRIX *pOut, __in CONST D3DXPLANE *pPlane ); + +#ifdef __cplusplus +} +#endif + + +//-------------------------- +// Quaternion +//-------------------------- + +// inline + +FLOAT D3DXQuaternionLength + ( __in CONST D3DXQUATERNION *pQ ); + +// Length squared, or "norm" +FLOAT D3DXQuaternionLengthSq + ( __in CONST D3DXQUATERNION *pQ ); + +FLOAT D3DXQuaternionDot + ( __in CONST D3DXQUATERNION *pQ1, __in CONST D3DXQUATERNION *pQ2 ); + +// (0, 0, 0, 1) +D3DXQUATERNION* D3DXQuaternionIdentity + ( __out D3DXQUATERNION *pOut ); + +BOOL D3DXQuaternionIsIdentity + ( __in CONST D3DXQUATERNION *pQ ); + +// (-x, -y, -z, w) +D3DXQUATERNION* D3DXQuaternionConjugate + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ ); + + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +// Compute a quaternin's axis and angle of rotation. Expects unit quaternions. +void WINAPI D3DXQuaternionToAxisAngle + ( __in CONST D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, FLOAT *pAngle ); + +// Build a quaternion from a rotation matrix. +D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix + ( __out D3DXQUATERNION *pOut, __in CONST D3DXMATRIX *pM); + +// Rotation about arbitrary axis. +D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis + ( __out D3DXQUATERNION *pOut, __in CONST D3DXVECTOR3 *pV, FLOAT Angle ); + +// Yaw around the Y axis, a pitch around the X axis, +// and a roll around the Z axis. +D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll + ( __out D3DXQUATERNION *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll ); + +// Quaternion multiplication. The result represents the rotation Q2 +// followed by the rotation Q1. (Out = Q2 * Q1) +D3DXQUATERNION* WINAPI D3DXQuaternionMultiply + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ1, + __in CONST D3DXQUATERNION *pQ2 ); + +D3DXQUATERNION* WINAPI D3DXQuaternionNormalize + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ ); + +// Conjugate and re-norm +D3DXQUATERNION* WINAPI D3DXQuaternionInverse + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ ); + +// Expects unit quaternions. +// if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v) +D3DXQUATERNION* WINAPI D3DXQuaternionLn + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ ); + +// Expects pure quaternions. (w == 0) w is ignored in calculation. +// if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v) +D3DXQUATERNION* WINAPI D3DXQuaternionExp + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ ); + +// Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1). +// Expects unit quaternions. +D3DXQUATERNION* WINAPI D3DXQuaternionSlerp + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ1, + __in CONST D3DXQUATERNION *pQ2, FLOAT t ); + +// Spherical quadrangle interpolation. +// Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t)) +D3DXQUATERNION* WINAPI D3DXQuaternionSquad + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ1, + __in CONST D3DXQUATERNION *pA, __in CONST D3DXQUATERNION *pB, + __in CONST D3DXQUATERNION *pC, FLOAT t ); + +// Setup control points for spherical quadrangle interpolation +// from Q1 to Q2. The control points are chosen in such a way +// to ensure the continuity of tangents with adjacent segments. +void WINAPI D3DXQuaternionSquadSetup + ( __out D3DXQUATERNION *pAOut, D3DXQUATERNION *pBOut, D3DXQUATERNION *pCOut, + __in CONST D3DXQUATERNION *pQ0, __in CONST D3DXQUATERNION *pQ1, + __in CONST D3DXQUATERNION *pQ2, __in CONST D3DXQUATERNION *pQ3 ); + +// Barycentric interpolation. +// Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g)) +D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric + ( __out D3DXQUATERNION *pOut, __in CONST D3DXQUATERNION *pQ1, + __in CONST D3DXQUATERNION *pQ2, __in CONST D3DXQUATERNION *pQ3, + FLOAT f, FLOAT g ); + +#ifdef __cplusplus +} +#endif + + +//-------------------------- +// Plane +//-------------------------- + +// inline + +// ax + by + cz + dw +FLOAT D3DXPlaneDot + ( __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR4 *pV); + +// ax + by + cz + d +FLOAT D3DXPlaneDotCoord + ( __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR3 *pV); + +// ax + by + cz +FLOAT D3DXPlaneDotNormal + ( __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR3 *pV); + +D3DXPLANE* D3DXPlaneScale + (__out D3DXPLANE *pOut, __in CONST D3DXPLANE *pP, FLOAT s); + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +// Normalize plane (so that |a,b,c| == 1) +D3DXPLANE* WINAPI D3DXPlaneNormalize + ( __out D3DXPLANE *pOut, __in CONST D3DXPLANE *pP); + +// Find the intersection between a plane and a line. If the line is +// parallel to the plane, NULL is returned. +D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine + ( __out D3DXVECTOR3 *pOut, __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR3 *pV1, + __in CONST D3DXVECTOR3 *pV2); + +// Construct a plane from a point and a normal +D3DXPLANE* WINAPI D3DXPlaneFromPointNormal + ( __out D3DXPLANE *pOut, __in CONST D3DXVECTOR3 *pPoint, __in CONST D3DXVECTOR3 *pNormal); + +// Construct a plane from 3 points +D3DXPLANE* WINAPI D3DXPlaneFromPoints + ( __out D3DXPLANE *pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2, + __in CONST D3DXVECTOR3 *pV3); + +// Transform a plane by a matrix. The vector (a,b,c) must be normal. +// M should be the inverse transpose of the transformation desired. +D3DXPLANE* WINAPI D3DXPlaneTransform + ( __out D3DXPLANE *pOut, __in CONST D3DXPLANE *pP, __in CONST D3DXMATRIX *pM ); + +// Transform an array of planes by a matrix. The vectors (a,b,c) must be normal. +// M should be the inverse transpose of the transformation desired. +D3DXPLANE* WINAPI D3DXPlaneTransformArray + ( __out D3DXPLANE *pOut, UINT OutStride, __in CONST D3DXPLANE *pP, UINT PStride, __in CONST D3DXMATRIX *pM, UINT n ); + +#ifdef __cplusplus +} +#endif + + +//-------------------------- +// Color +//-------------------------- + +// inline + +// (1-r, 1-g, 1-b, a) +D3DXCOLOR* D3DXColorNegative + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC); + +D3DXCOLOR* D3DXColorAdd + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2); + +D3DXCOLOR* D3DXColorSubtract + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2); + +D3DXCOLOR* D3DXColorScale + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC, FLOAT s); + +// (r1*r2, g1*g2, b1*b2, a1*a2) +D3DXCOLOR* D3DXColorModulate + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2); + +// Linear interpolation of r,g,b, and a. C1 + s(C2-C1) +D3DXCOLOR* D3DXColorLerp + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2, FLOAT s); + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +// Interpolate r,g,b between desaturated color and color. +// DesaturatedColor + s(Color - DesaturatedColor) +D3DXCOLOR* WINAPI D3DXColorAdjustSaturation + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC, FLOAT s); + +// Interpolate r,g,b between 50% grey and color. Grey + s(Color - Grey) +D3DXCOLOR* WINAPI D3DXColorAdjustContrast + (__out D3DXCOLOR *pOut, __in CONST D3DXCOLOR *pC, FLOAT c); + +#ifdef __cplusplus +} +#endif + + + + +//-------------------------- +// Misc +//-------------------------- + +#ifdef __cplusplus +extern "C" { +#endif + +// Calculate Fresnel term given the cosine of theta (likely obtained by +// taking the dot of two normals), and the refraction index of the material. +FLOAT WINAPI D3DXFresnelTerm + (FLOAT CosTheta, FLOAT RefractionIndex); + +#ifdef __cplusplus +} +#endif + + + +//=========================================================================== +// +// Matrix Stack +// +//=========================================================================== + +typedef struct ID3DXMatrixStack ID3DXMatrixStack; +typedef struct ID3DXMatrixStack *LPD3DXMATRIXSTACK; + +// {E3357330-CC5E-11d2-A434-00A0C90629A8} +DEFINE_GUID( IID_ID3DXMatrixStack, +0xe3357330, 0xcc5e, 0x11d2, 0xa4, 0x34, 0x0, 0xa0, 0xc9, 0x6, 0x29, 0xa8); + + +#undef INTERFACE +#define INTERFACE ID3DXMatrixStack + +DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown) +{ + // + // IUnknown methods + // + STDMETHOD(QueryInterface)(THIS_ REFIID riid, __deref_out LPVOID * ppvObj) PURE; + STDMETHOD_(ULONG,AddRef)(THIS) PURE; + STDMETHOD_(ULONG,Release)(THIS) PURE; + + // + // ID3DXMatrixStack methods + // + + // Pops the top of the stack, returns the current top + // *after* popping the top. + STDMETHOD(Pop)(THIS) PURE; + + // Pushes the stack by one, duplicating the current matrix. + STDMETHOD(Push)(THIS) PURE; + + // Loads identity in the current matrix. + STDMETHOD(LoadIdentity)(THIS) PURE; + + // Loads the given matrix into the current matrix + STDMETHOD(LoadMatrix)(THIS_ __in CONST D3DXMATRIX * pM ) PURE; + + // Right-Multiplies the given matrix to the current matrix. + // (transformation is about the current world origin) + STDMETHOD(MultMatrix)(THIS_ __in CONST D3DXMATRIX * pM ) PURE; + + // Left-Multiplies the given matrix to the current matrix + // (transformation is about the local origin of the object) + STDMETHOD(MultMatrixLocal)(THIS_ __in CONST D3DXMATRIX * pM ) PURE; + + // Right multiply the current matrix with the computed rotation + // matrix, counterclockwise about the given axis with the given angle. + // (rotation is about the current world origin) + STDMETHOD(RotateAxis) + (THIS_ __in CONST D3DXVECTOR3 * pV, FLOAT Angle) PURE; + + // Left multiply the current matrix with the computed rotation + // matrix, counterclockwise about the given axis with the given angle. + // (rotation is about the local origin of the object) + STDMETHOD(RotateAxisLocal) + (THIS_ __in CONST D3DXVECTOR3 * pV, FLOAT Angle) PURE; + + // Right multiply the current matrix with the computed rotation + // matrix. All angles are counterclockwise. (rotation is about the + // current world origin) + + // The rotation is composed of a yaw around the Y axis, a pitch around + // the X axis, and a roll around the Z axis. + STDMETHOD(RotateYawPitchRoll) + (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE; + + // Left multiply the current matrix with the computed rotation + // matrix. All angles are counterclockwise. (rotation is about the + // local origin of the object) + + // The rotation is composed of a yaw around the Y axis, a pitch around + // the X axis, and a roll around the Z axis. + STDMETHOD(RotateYawPitchRollLocal) + (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE; + + // Right multiply the current matrix with the computed scale + // matrix. (transformation is about the current world origin) + STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE; + + // Left multiply the current matrix with the computed scale + // matrix. (transformation is about the local origin of the object) + STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE; + + // Right multiply the current matrix with the computed translation + // matrix. (transformation is about the current world origin) + STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE; + + // Left multiply the current matrix with the computed translation + // matrix. (transformation is about the local origin of the object) + STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE; + + // Obtain the current matrix at the top of the stack + STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +HRESULT WINAPI + D3DXCreateMatrixStack( + DWORD Flags, + __deref_out LPD3DXMATRIXSTACK* ppStack); + +#ifdef __cplusplus +} +#endif + +//=========================================================================== +// +// Spherical Harmonic Runtime Routines +// +// NOTE: +// * Most of these functions can take the same object as in and out parameters. +// The exceptions are the rotation functions. +// +// * Out parameters are typically also returned as return values, so that +// the output of one function may be used as a parameter to another. +// +//============================================================================ + + +// non-inline +#ifdef __cplusplus +extern "C" { +#endif + +//============================================================================ +// +// Basic Spherical Harmonic math routines +// +//============================================================================ + +#define D3DXSH_MINORDER 2 +#define D3DXSH_MAXORDER 6 + +//============================================================================ +// +// D3DXSHEvalDirection: +// -------------------- +// Evaluates the Spherical Harmonic basis functions +// +// Parameters: +// pOut +// Output SH coefficients - basis function Ylm is stored at l*l + m+l +// This is the pointer that is returned. +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pDir +// Direction to evaluate in - assumed to be normalized +// +//============================================================================ + +FLOAT* WINAPI D3DXSHEvalDirection + ( __out FLOAT *pOut, UINT Order, __in CONST D3DXVECTOR3 *pDir ); + +//============================================================================ +// +// D3DXSHRotate: +// -------------------- +// Rotates SH vector by a rotation matrix +// +// Parameters: +// pOut +// Output SH coefficients - basis function Ylm is stored at l*l + m+l +// This is the pointer that is returned (should not alias with pIn.) +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pMatrix +// Matrix used for rotation - rotation sub matrix should be orthogonal +// and have a unit determinant. +// pIn +// Input SH coeffs (rotated), incorect results if this is also output. +// +//============================================================================ + +FLOAT* WINAPI D3DXSHRotate + ( __out FLOAT *pOut, UINT Order, __in CONST D3DXMATRIX *pMatrix, __in CONST FLOAT *pIn ); + +//============================================================================ +// +// D3DXSHRotateZ: +// -------------------- +// Rotates the SH vector in the Z axis by an angle +// +// Parameters: +// pOut +// Output SH coefficients - basis function Ylm is stored at l*l + m+l +// This is the pointer that is returned (should not alias with pIn.) +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// Angle +// Angle in radians to rotate around the Z axis. +// pIn +// Input SH coeffs (rotated), incorect results if this is also output. +// +//============================================================================ + + +FLOAT* WINAPI D3DXSHRotateZ + ( __out FLOAT *pOut, UINT Order, CONST FLOAT Angle, __in CONST FLOAT *pIn ); + +//============================================================================ +// +// D3DXSHAdd: +// -------------------- +// Adds two SH vectors, pOut[i] = pA[i] + pB[i]; +// +// Parameters: +// pOut +// Output SH coefficients - basis function Ylm is stored at l*l + m+l +// This is the pointer that is returned. +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pA +// Input SH coeffs. +// pB +// Input SH coeffs (second vector.) +// +//============================================================================ + +FLOAT* WINAPI D3DXSHAdd + ( __out FLOAT *pOut, UINT Order, __in CONST FLOAT *pA, __in CONST FLOAT *pB ); + +//============================================================================ +// +// D3DXSHScale: +// -------------------- +// Adds two SH vectors, pOut[i] = pA[i]*Scale; +// +// Parameters: +// pOut +// Output SH coefficients - basis function Ylm is stored at l*l + m+l +// This is the pointer that is returned. +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pIn +// Input SH coeffs. +// Scale +// Scale factor. +// +//============================================================================ + +FLOAT* WINAPI D3DXSHScale + ( __out FLOAT *pOut, UINT Order, __in CONST FLOAT *pIn, CONST FLOAT Scale ); + +//============================================================================ +// +// D3DXSHDot: +// -------------------- +// Computes the dot product of two SH vectors +// +// Parameters: +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pA +// Input SH coeffs. +// pB +// Second set of input SH coeffs. +// +//============================================================================ + +FLOAT WINAPI D3DXSHDot + ( __out UINT Order, __in CONST FLOAT *pA, __in CONST FLOAT *pB ); + +//============================================================================ +// +// Basic Spherical Harmonic lighting routines +// +//============================================================================ + +//============================================================================ +// +// D3DXSHEvalDirectionalLight: +// -------------------- +// Evaluates a directional light and returns spectral SH data. The output +// vector is computed so that if the intensity of R/G/B is unit the resulting +// exit radiance of a point directly under the light on a diffuse object with +// an albedo of 1 would be 1.0. This will compute 3 spectral samples, pROut +// has to be specified, while pGout and pBout are optional. +// +// Parameters: +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pDir +// Direction light is coming from (assumed to be normalized.) +// RIntensity +// Red intensity of light. +// GIntensity +// Green intensity of light. +// BIntensity +// Blue intensity of light. +// pROut +// Output SH vector for Red. +// pGOut +// Output SH vector for Green (optional.) +// pBOut +// Output SH vector for Blue (optional.) +// +//============================================================================ + +HRESULT WINAPI D3DXSHEvalDirectionalLight + ( UINT Order, __in CONST D3DXVECTOR3 *pDir, + FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity, + __out FLOAT *pROut, __out FLOAT *pGOut, __out FLOAT *pBOut ); + +//============================================================================ +// +// D3DXSHEvalSphericalLight: +// -------------------- +// Evaluates a spherical light and returns spectral SH data. There is no +// normalization of the intensity of the light like there is for directional +// lights, care has to be taken when specifiying the intensities. This will +// compute 3 spectral samples, pROut has to be specified, while pGout and +// pBout are optional. +// +// Parameters: +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pPos +// Position of light - reciever is assumed to be at the origin. +// Radius +// Radius of the spherical light source. +// RIntensity +// Red intensity of light. +// GIntensity +// Green intensity of light. +// BIntensity +// Blue intensity of light. +// pROut +// Output SH vector for Red. +// pGOut +// Output SH vector for Green (optional.) +// pBOut +// Output SH vector for Blue (optional.) +// +//============================================================================ + +HRESULT WINAPI D3DXSHEvalSphericalLight + ( UINT Order, __in CONST D3DXVECTOR3 *pPos, FLOAT Radius, + FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity, + __out FLOAT *pROut, __out FLOAT *pGOut, __out FLOAT *pBOut ); + +//============================================================================ +// +// D3DXSHEvalConeLight: +// -------------------- +// Evaluates a light that is a cone of constant intensity and returns spectral +// SH data. The output vector is computed so that if the intensity of R/G/B is +// unit the resulting exit radiance of a point directly under the light oriented +// in the cone direction on a diffuse object with an albedo of 1 would be 1.0. +// This will compute 3 spectral samples, pROut has to be specified, while pGout +// and pBout are optional. +// +// Parameters: +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pDir +// Direction light is coming from (assumed to be normalized.) +// Radius +// Radius of cone in radians. +// RIntensity +// Red intensity of light. +// GIntensity +// Green intensity of light. +// BIntensity +// Blue intensity of light. +// pROut +// Output SH vector for Red. +// pGOut +// Output SH vector for Green (optional.) +// pBOut +// Output SH vector for Blue (optional.) +// +//============================================================================ + +HRESULT WINAPI D3DXSHEvalConeLight + ( UINT Order, __in CONST D3DXVECTOR3 *pDir, FLOAT Radius, + FLOAT RIntensity, FLOAT GIntensity, FLOAT BIntensity, + __out FLOAT *pROut, __out FLOAT *pGOut, __out FLOAT *pBOut ); + +//============================================================================ +// +// D3DXSHEvalHemisphereLight: +// -------------------- +// Evaluates a light that is a linear interpolant between two colors over the +// sphere. The interpolant is linear along the axis of the two points, not +// over the surface of the sphere (ie: if the axis was (0,0,1) it is linear in +// Z, not in the azimuthal angle.) The resulting spherical lighting function +// is normalized so that a point on a perfectly diffuse surface with no +// shadowing and a normal pointed in the direction pDir would result in exit +// radiance with a value of 1 if the top color was white and the bottom color +// was black. This is a very simple model where Top represents the intensity +// of the "sky" and Bottom represents the intensity of the "ground". +// +// Parameters: +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pDir +// Axis of the hemisphere. +// Top +// Color of the upper hemisphere. +// Bottom +// Color of the lower hemisphere. +// pROut +// Output SH vector for Red. +// pGOut +// Output SH vector for Green +// pBOut +// Output SH vector for Blue +// +//============================================================================ + +HRESULT WINAPI D3DXSHEvalHemisphereLight + ( UINT Order, __in CONST D3DXVECTOR3 *pDir, D3DXCOLOR Top, D3DXCOLOR Bottom, + __out FLOAT *pROut, __out FLOAT *pGOut, __out FLOAT *pBOut ); + +//============================================================================ +// +// Basic Spherical Harmonic projection routines +// +//============================================================================ + +//============================================================================ +// +// D3DXSHProjectCubeMap: +// -------------------- +// Projects a function represented on a cube map into spherical harmonics. +// +// Parameters: +// Order +// Order of the SH evaluation, generates Order^2 coefs, degree is Order-1 +// pCubeMap +// CubeMap that is going to be projected into spherical harmonics +// pROut +// Output SH vector for Red. +// pGOut +// Output SH vector for Green +// pBOut +// Output SH vector for Blue +// +//============================================================================ + +HRESULT WINAPI D3DXSHProjectCubeMap + ( UINT uOrder, __in LPDIRECT3DCUBETEXTURE9 pCubeMap, + __out FLOAT *pROut, __out FLOAT *pGOut, __out FLOAT *pBOut ); + + +#ifdef __cplusplus +} +#endif + + +#include "d3dx9math.inl" + +#if _MSC_VER >= 1200 +#pragma warning(pop) +#else +#pragma warning(default:4201) +#endif + +#endif // __D3DX9MATH_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9math.inl b/third_party/xbox_sdk/include/d3dx9math.inl new file mode 100644 index 0000000..85a3c53 --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9math.inl @@ -0,0 +1,3201 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9math.inl +// Content: D3DX math inline functions +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef __D3DX9MATH_INL__ +#define __D3DX9MATH_INL__ + +#ifndef _NO_XBOXMATH +//=========================================================================== +// +// XM_NO_MISALIGNED_VECTOR_ACCESS versions of functions copied from the +// xboxmath/XNAMath library. +// +//=========================================================================== + +#pragma warning(push) +#pragma warning(disable:4616 6001) + +XMFINLINE XMVECTOR D3DX_LoadFloat2(__in CONST XMFLOAT2 * pSource) +{ +#if defined(_NO_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + ((UINT *)(&V.vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->x))[0]; + ((UINT *)(&V.vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->y))[0]; + V.vector4_f32[2] = V.vector4_f32[3] = 0.0f; + return V; +#elif defined(_XM_SSE_INTRINSICS_) + // This reads 2 floats past the memory that should be ignored. + return _mm_loadu_ps( &pSource->x ); +#else // XM_NO_MISALIGNED_VECTOR_ACCESS + XMVECTOR V; + XMVECTOR V0, V1; + XMVECTOR Permute; + V0 = __lvx(pSource, 0); // Load the 16 bytes starting at address pSource & ~0xF + Permute = __lvsl(pSource, 0); // Compute the permute control vector for shift left + V1 = __lvx(pSource, 7); // Load the 16 bytes starting at address ((BYTE*)pSource + 7) & ~0xF + V = __vperm(V0, V1, Permute); // Align the vector + return V; +#endif +} + +XMFINLINE XMVECTOR D3DX_LoadFloat3(__in CONST XMFLOAT3 * pSource) +{ +#if defined(_NO_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + ((UINT *)(&V.vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->x))[0]; + ((UINT *)(&V.vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->y))[0]; + ((UINT *)(&V.vector4_f32[2]))[0] = ((__in CONST UINT *)(&pSource->z))[0]; + V.vector4_f32[3] = 0.0f; + return V; +#elif defined(_XM_SSE_INTRINSICS_) + // This reads 1 floats past the memory that should be ignored. + return _mm_loadu_ps( &pSource->x ); +#else // XM_NO_MISALIGNED_VECTOR_ACCESS + XMVECTOR V; + XMVECTOR V0, V1; + XMVECTOR Permute; + + V0 = __lvx(pSource, 0); // Load the 16 bytes starting at address pSource & ~0xF + Permute = __lvsl(pSource, 0); // Compute the permute control vector for shift left + V1 = __lvx(pSource, 11); // Load the 16 bytes starting at address ((BYTE*)pSource + 11) & ~0xF + V = __vperm(V0, V1, Permute); // Align the vector + + return V; +#endif +} + +XMFINLINE XMVECTOR D3DX_LoadFloat4(__in CONST XMFLOAT4 * pSource) +{ +#if defined(_NO_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + ((UINT *)(&V.vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->x))[0]; + ((UINT *)(&V.vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->y))[0]; + ((UINT *)(&V.vector4_f32[2]))[0] = ((__in CONST UINT *)(&pSource->z))[0]; + ((UINT *)(&V.vector4_f32[3]))[0] = ((__in CONST UINT *)(&pSource->w))[0]; + return V; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_loadu_ps( &pSource->x ); +#else // XM_NO_MISALIGNED_VECTOR_ACCESS + XMVECTOR V; + XMVECTOR V0, V1; + XMVECTOR Permute; + + V0 = __lvx(pSource, 0); // Load the 16 bytes starting at address pSource & ~0xF + Permute = __lvsl(pSource, 0); // Compute the permute control vector for shift left + V1 = __lvx(pSource, 15); // Load the 16 bytes starting at address ((BYTE*)pSource + 15) & ~0xF + V = __vperm(V0, V1, Permute); // Align the vector + + return V; +#endif +} + +XMFINLINE XMMATRIX D3DX_LoadFloat4x4(__in CONST XMFLOAT4X4 * pSource) +{ +#if defined(_NO_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + + ((UINT *)(&M.r[0].vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->m[0][0]))[0]; + ((UINT *)(&M.r[0].vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->m[0][1]))[0]; + ((UINT *)(&M.r[0].vector4_f32[2]))[0] = ((__in CONST UINT *)(&pSource->m[0][2]))[0]; + ((UINT *)(&M.r[0].vector4_f32[3]))[0] = ((__in CONST UINT *)(&pSource->m[0][3]))[0]; + + ((UINT *)(&M.r[1].vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->m[1][0]))[0]; + ((UINT *)(&M.r[1].vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->m[1][1]))[0]; + ((UINT *)(&M.r[1].vector4_f32[2]))[0] = ((__in CONST UINT *)(&pSource->m[1][2]))[0]; + ((UINT *)(&M.r[1].vector4_f32[3]))[0] = ((__in CONST UINT *)(&pSource->m[1][3]))[0]; + + ((UINT *)(&M.r[2].vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->m[2][0]))[0]; + ((UINT *)(&M.r[2].vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->m[2][1]))[0]; + ((UINT *)(&M.r[2].vector4_f32[2]))[0] = ((__in CONST UINT *)(&pSource->m[2][2]))[0]; + ((UINT *)(&M.r[2].vector4_f32[3]))[0] = ((__in CONST UINT *)(&pSource->m[2][3]))[0]; + + ((UINT *)(&M.r[3].vector4_f32[0]))[0] = ((__in CONST UINT *)(&pSource->m[3][0]))[0]; + ((UINT *)(&M.r[3].vector4_f32[1]))[0] = ((__in CONST UINT *)(&pSource->m[3][1]))[0]; + ((UINT *)(&M.r[3].vector4_f32[2]))[0] = ((__in CONST UINT *)(&pSource->m[3][2]))[0]; + ((UINT *)(&M.r[3].vector4_f32[3]))[0] = ((__in CONST UINT *)(&pSource->m[3][3]))[0]; + + return M; +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + + M.r[0] = _mm_loadu_ps( &pSource->_11 ); + M.r[1] = _mm_loadu_ps( &pSource->_21 ); + M.r[2] = _mm_loadu_ps( &pSource->_31 ); + M.r[3] = _mm_loadu_ps( &pSource->_41 ); + + return M; +#else // XM_NO_MISALIGNED_VECTOR_ACCESS + XMMATRIX M; + XMVECTOR V0, V1, V2, V3, V4; + XMVECTOR Permute; + + V0 = __lvx(pSource, 0); + Permute = __lvsl(pSource, 0); + V1 = __lvx(pSource, 16); + V2 = __lvx(pSource, 32); + V3 = __lvx(pSource, 48); + V4 = __lvx(pSource, 63); + M.r[0] = __vperm(V0, V1, Permute); + M.r[1] = __vperm(V1, V2, Permute); + M.r[2] = __vperm(V2, V3, Permute); + M.r[3] = __vperm(V3, V4, Permute); + + return M; +#endif +} + +XMFINLINE FLOAT D3DX_ConvertHalfToFloat(HALF Value) +{ +#if defined(_NO_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + + UINT Mantissa; + UINT Exponent; + UINT Result; + + Mantissa = (UINT)(Value & 0x03FF); + + if ((Value & 0x7C00) != 0) // The value is normalized + { + Exponent = (UINT)((Value >> 10) & 0x1F); + } + else if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x0400) == 0); + + Mantissa &= 0x03FF; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result = ((Value & 0x8000) << 16) | // Sign + ((Exponent + 112) << 23) | // Exponent + (Mantissa << 13); // Mantissa + + return *(FLOAT*)&Result; + +#else // XM_NO_MISALIGNED_VECTOR_ACCESS + XMVECTOR ValueV; + XMVECTOR Permute; + FLOAT Result; + + Permute = __lvsl(&Value, 0); + ValueV = __lvx(&Value, 0); + Permute = __vsldoi(Permute, Permute, 1 << 2); + ValueV = __vperm(ValueV, ValueV, Permute); + ValueV = __vupkd3d(ValueV, VPACK_FLOAT16_2); + ValueV = __vspltw(ValueV, 0); + + __stvewx(ValueV, &Result, 0); + + return Result; +#endif +} + +XMFINLINE FLOAT* D3DX_ConvertHalfToFloatStream(__out FLOAT* pOutputStream, UINT OutputStride, __in CONST HALF * pInputStream, UINT InputStride, UINT HalfCount) +{ + UINT i; + BYTE* pHalf = (BYTE*)pInputStream; + BYTE* pFloat = (BYTE*)pOutputStream; + + for (i = 0; i < HalfCount; i++) + { + *(FLOAT*)pFloat = D3DX_ConvertHalfToFloat(*(HALF*)pHalf); + pHalf += InputStride; + pFloat += OutputStride; + } + + return pOutputStream; +} + +XMFINLINE HALF D3DX_ConvertFloatToHalf(FLOAT Value) +{ +#if defined(_NO_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + UINT Result; + + UINT IValue = reinterpret_cast(&Value)[0]; + UINT Sign = (IValue & 0x80000000U) >> 16U; + IValue = IValue & 0x7FFFFFFFU; // Hack off the sign + + if (IValue > 0x47FFEFFFU) + { + // The number is too large to be represented as a half. Saturate to infinity. + Result = 0x7FFFU; + } + else + { + if (IValue < 0x38800000U) + { + // The number is too small to be represented as a normalized half. + // Convert it to a denormalized value. + UINT Shift = 113U - (IValue >> 23U); + IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift; + } + else + { + // Rebias the exponent to represent the value as a normalized half. + IValue += 0xC8000000U; + } + + Result = ((IValue + 0x0FFFU + ((IValue >> 13U) & 1U)) >> 13U)&0x7FFFU; + } + return static_cast(Result|Sign); + +#else // XM_NO_MISALIGNED_VECTOR_ACCESS + XMVECTOR ValueV; + XMVECTOR Permute; + HALF Result; + + ValueV = __lvx(&Value, 0); + Permute = __lvsl(&Value, 0); + ValueV = __vperm(ValueV, ValueV, Permute); + ValueV = __vpkd3d(ValueV, ValueV, VPACK_FLOAT16_4, VPACK_64LO, 2); + ValueV = __vsplth(ValueV, 0); + + __stvehx(ValueV, &Result, 0); + + return Result; +#endif +} + +XMFINLINE HALF* D3DX_ConvertFloatToHalfStream(__out HALF* pOutputStream, UINT OutputStride, __in CONST FLOAT * pInputStream, UINT InputStride, UINT FloatCount) +{ + UINT i; + BYTE* pFloat = (BYTE*)pInputStream; + BYTE* pHalf = (BYTE*)pOutputStream; + + for (i = 0; i < FloatCount; i++) + { + *(HALF*)pHalf = D3DX_ConvertFloatToHalf(*(FLOAT*)pFloat); + pFloat += InputStride; + pHalf += OutputStride; + } + + return pOutputStream; +} + +XMFINLINE XMVECTOR D3DX_VectorReplicate(FLOAT Value) +{ +#if !defined(_NO_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_) + return _mm_set_ps1( Value ); +#else + XMVECTOR V; + + V.vector4_f32[0] = + V.vector4_f32[1] = + V.vector4_f32[2] = + V.vector4_f32[3] = Value; + + return V; +#endif +} + +XMFINLINE XMVECTOR D3DX_VectorLerp(XMVECTOR V0, XMVECTOR V1, FLOAT t) +{ +#if !defined(_NO_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_) + XMVECTOR L, S; + XMVECTOR Result; + + L = _mm_sub_ps( V1, V0 ); + + S = _mm_set_ps1( t ); + + Result = _mm_mul_ps( L, S ); + + return _mm_add_ps( Result, V0 ); +#else + XMVECTOR Scale; + XMVECTOR Length; + XMVECTOR Result; + + Scale = D3DX_VectorReplicate(t); + Length = XMVectorSubtract(V1, V0); + Result = XMVectorMultiplyAdd(Length, Scale, V0); + + return Result; +#endif +} + +#pragma warning(pop) +#endif // _NO_XBOXMATH + +//=========================================================================== +// +// Inline Class Methods +// +//=========================================================================== + +#ifdef __cplusplus + +//-------------------------- +// Float16 +//-------------------------- + +D3DXINLINE +D3DXFLOAT16::D3DXFLOAT16( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + D3DXFloat32To16Array(this, &f, 1); +#else + value = D3DX_ConvertFloatToHalf(f); +#endif +} + +D3DXINLINE +D3DXFLOAT16::D3DXFLOAT16( CONST D3DXFLOAT16& f ) +{ + value = f.value; +} + +// casting +D3DXINLINE +D3DXFLOAT16::operator FLOAT () +{ +#ifdef _NO_XBOXMATH + FLOAT f; + D3DXFloat16To32Array(&f, this, 1); + return f; +#else + return D3DX_ConvertHalfToFloat(value); +#endif +} + +// binary operators +D3DXINLINE BOOL +D3DXFLOAT16::operator == ( CONST D3DXFLOAT16& f ) const +{ + return value == f.value; +} + +D3DXINLINE BOOL +D3DXFLOAT16::operator != ( CONST D3DXFLOAT16& f ) const +{ + return value != f.value; +} + + +//-------------------------- +// 2D Vector +//-------------------------- + +D3DXINLINE +D3DXVECTOR2::D3DXVECTOR2( __in CONST FLOAT *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + x = pf[0]; + y = pf[1]; +} + +D3DXINLINE +D3DXVECTOR2::D3DXVECTOR2( __in CONST D3DXFLOAT16 *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&x, pf, 2); +#else + D3DX_ConvertHalfToFloatStream(&x, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 2); +#endif +} + +D3DXINLINE +D3DXVECTOR2::D3DXVECTOR2( FLOAT fx, FLOAT fy ) +{ + x = fx; + y = fy; +} + +// casting +D3DXINLINE +D3DXVECTOR2::operator FLOAT* () +{ + return (FLOAT *) &x; +} + +D3DXINLINE +D3DXVECTOR2::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &x; +} + +// assignment operators +D3DXINLINE D3DXVECTOR2& +D3DXVECTOR2::operator = ( CONST D3DXVECTOR2& v ) +{ + x = v.x; + y = v.y; + return *this; +} + +D3DXINLINE D3DXVECTOR2& +D3DXVECTOR2::operator += ( CONST D3DXVECTOR2& v ) +{ + x += v.x; + y += v.y; + return *this; +} + +D3DXINLINE D3DXVECTOR2& +D3DXVECTOR2::operator -= ( CONST D3DXVECTOR2& v ) +{ + x -= v.x; + y -= v.y; + return *this; +} + +D3DXINLINE D3DXVECTOR2& +D3DXVECTOR2::operator *= ( FLOAT f ) +{ + x *= f; + y *= f; + return *this; +} + +D3DXINLINE D3DXVECTOR2& +D3DXVECTOR2::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + x *= fInv; + y *= fInv; +#else // !_NO_XBOXMATH + XMVECTOR V, S; + S = D3DX_VectorReplicate(f); + V = D3DX_LoadFloat2((__in CONST XMFLOAT2 *)this); + S = XMVectorReciprocal(S); + V = XMVectorMultiply(V, S); + XMStoreFloat2((XMFLOAT2*)this, V); +#endif // !_NO_XBOXMATH + return *this; +} + +// unary operators +D3DXINLINE D3DXVECTOR2 +D3DXVECTOR2::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXVECTOR2 +D3DXVECTOR2::operator - () const +{ + return D3DXVECTOR2(-x, -y); +} + +// binary operators +D3DXINLINE D3DXVECTOR2 +D3DXVECTOR2::operator + ( CONST D3DXVECTOR2& v ) const +{ + return D3DXVECTOR2(x + v.x, y + v.y); +} + +D3DXINLINE D3DXVECTOR2 +D3DXVECTOR2::operator - ( CONST D3DXVECTOR2& v ) const +{ + return D3DXVECTOR2(x - v.x, y - v.y); +} + +D3DXINLINE D3DXVECTOR2 +D3DXVECTOR2::operator * ( FLOAT f ) const +{ + return D3DXVECTOR2(x * f, y * f); +} + +D3DXINLINE D3DXVECTOR2 +D3DXVECTOR2::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXVECTOR2(x * fInv, y * fInv); +#else // !_NO_XBOXMATH + XMVECTOR V, S; + D3DXVECTOR2 Result; + + S = D3DX_VectorReplicate(f); + V = D3DX_LoadFloat2((__in CONST XMFLOAT2 *)this); + S = XMVectorReciprocal(S); + V = XMVectorMultiply(V, S); + XMStoreFloat2((XMFLOAT2*)&Result, V); + return Result; +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXVECTOR2 +operator * ( FLOAT f, CONST D3DXVECTOR2& v ) +{ + return D3DXVECTOR2(f * v.x, f * v.y); +} + +D3DXINLINE BOOL +D3DXVECTOR2::operator == ( CONST D3DXVECTOR2& v ) const +{ + return x == v.x && y == v.y; +} + +D3DXINLINE BOOL +D3DXVECTOR2::operator != ( CONST D3DXVECTOR2& v ) const +{ + return x != v.x || y != v.y; +} + + + +//-------------------------- +// 2D Vector (16 bit) +//-------------------------- + +D3DXINLINE +D3DXVECTOR2_16F::D3DXVECTOR2_16F( __in CONST FLOAT *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat32To16Array(&x, pf, 2); +#else + D3DX_ConvertFloatToHalfStream((HALF*)&x, sizeof(D3DXFLOAT16), pf, sizeof(FLOAT), 2); +#endif +} + +D3DXINLINE +D3DXVECTOR2_16F::D3DXVECTOR2_16F( __in CONST D3DXFLOAT16 *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + *((DWORD *) &x) = *((DWORD *) &pf[0]); +} + +D3DXINLINE +D3DXVECTOR2_16F::D3DXVECTOR2_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy ) +{ + x = fx; + y = fy; +} + +// casting +D3DXINLINE +D3DXVECTOR2_16F::operator D3DXFLOAT16* () +{ + return (D3DXFLOAT16*) &x; +} + +D3DXINLINE +D3DXVECTOR2_16F::operator __in CONST D3DXFLOAT16 * () const +{ + return (__in CONST D3DXFLOAT16 *) &x; +} + +// assignment operators +D3DXINLINE D3DXVECTOR2_16F& +D3DXVECTOR2_16F::operator = ( CONST D3DXVECTOR2_16F& v ) +{ + x = v.x; + y = v.y; + return *this; +} + +// binary operators +D3DXINLINE BOOL +D3DXVECTOR2_16F::operator == ( CONST D3DXVECTOR2_16F &v ) const +{ + return *((DWORD *) &x) == *((DWORD *) &v.x); +} + +D3DXINLINE BOOL +D3DXVECTOR2_16F::operator != ( CONST D3DXVECTOR2_16F &v ) const +{ + return *((DWORD *) &x) != *((DWORD *) &v.x); +} + + +//-------------------------- +// 3D Vector +//-------------------------- +D3DXINLINE +D3DXVECTOR3::D3DXVECTOR3( __in CONST FLOAT *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + x = pf[0]; + y = pf[1]; + z = pf[2]; +} + +D3DXINLINE +D3DXVECTOR3::D3DXVECTOR3( CONST D3DVECTOR& v ) +{ + x = v.x; + y = v.y; + z = v.z; +} + +D3DXINLINE +D3DXVECTOR3::D3DXVECTOR3( __in CONST D3DXFLOAT16 *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&x, pf, 3); +#else + D3DX_ConvertHalfToFloatStream(&x, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 3); +#endif +} + +D3DXINLINE +D3DXVECTOR3::D3DXVECTOR3( FLOAT fx, FLOAT fy, FLOAT fz ) +{ + x = fx; + y = fy; + z = fz; +} + + +// casting +D3DXINLINE +D3DXVECTOR3::operator FLOAT* () +{ + return (FLOAT *) &x; +} + +D3DXINLINE +D3DXVECTOR3::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &x; +} + + +// assignment operators +D3DXINLINE D3DXVECTOR3& +D3DXVECTOR3::operator = ( CONST D3DXVECTOR3& v ) +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +D3DXINLINE D3DXVECTOR3& +D3DXVECTOR3::operator += ( CONST D3DXVECTOR3& v ) +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + +D3DXINLINE D3DXVECTOR3& +D3DXVECTOR3::operator -= ( CONST D3DXVECTOR3& v ) +{ + x -= v.x; + y -= v.y; + z -= v.z; + return *this; +} + +D3DXINLINE D3DXVECTOR3& +D3DXVECTOR3::operator *= ( FLOAT f ) +{ + x *= f; + y *= f; + z *= f; + return *this; +} + +D3DXINLINE D3DXVECTOR3& +D3DXVECTOR3::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + x *= fInv; + y *= fInv; + z *= fInv; +#else // !_NO_XBOXMATH + XMVECTOR V, S; + S = D3DX_VectorReplicate(f); + V = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)this); + S = XMVectorReciprocal(S); + V = XMVectorMultiply(V, S); + XMStoreFloat3((XMFLOAT3*)this, V); +#endif // !_NO_XBOXMATH + return *this; +} + + +// unary operators +D3DXINLINE D3DXVECTOR3 +D3DXVECTOR3::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXVECTOR3 +D3DXVECTOR3::operator - () const +{ + return D3DXVECTOR3(-x, -y, -z); +} + + +// binary operators +D3DXINLINE D3DXVECTOR3 +D3DXVECTOR3::operator + ( CONST D3DXVECTOR3& v ) const +{ + return D3DXVECTOR3(x + v.x, y + v.y, z + v.z); +} + +D3DXINLINE D3DXVECTOR3 +D3DXVECTOR3::operator - ( CONST D3DXVECTOR3& v ) const +{ + return D3DXVECTOR3(x - v.x, y - v.y, z - v.z); +} + +D3DXINLINE D3DXVECTOR3 +D3DXVECTOR3::operator * ( FLOAT f ) const +{ + return D3DXVECTOR3(x * f, y * f, z * f); +} + +D3DXINLINE D3DXVECTOR3 +D3DXVECTOR3::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXVECTOR3(x * fInv, y * fInv, z * fInv); +#else // !_NO_XBOXMATH + XMVECTOR V, S; + D3DXVECTOR3 Result; + + S = D3DX_VectorReplicate(f); + V = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)this); + S = XMVectorReciprocal(S); + V = XMVectorMultiply(V, S); + XMStoreFloat3((XMFLOAT3*)&Result, V); + return Result; +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXVECTOR3 +operator * ( FLOAT f, CONST struct D3DXVECTOR3& v ) +{ + return D3DXVECTOR3(f * v.x, f * v.y, f * v.z); +} + + +D3DXINLINE BOOL +D3DXVECTOR3::operator == ( CONST D3DXVECTOR3& v ) const +{ + return x == v.x && y == v.y && z == v.z; +} + +D3DXINLINE BOOL +D3DXVECTOR3::operator != ( CONST D3DXVECTOR3& v ) const +{ + return x != v.x || y != v.y || z != v.z; +} + + + +//-------------------------- +// 3D Vector (16 bit) +//-------------------------- + +D3DXINLINE +D3DXVECTOR3_16F::D3DXVECTOR3_16F( __in CONST FLOAT *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat32To16Array(&x, pf, 3); +#else + D3DX_ConvertFloatToHalfStream((HALF*)&x, sizeof(D3DXFLOAT16), pf, sizeof(FLOAT), 3); +#endif +} + +D3DXINLINE +D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DVECTOR& v ) +{ +#ifdef _NO_XBOXMATH + D3DXFloat32To16Array(&x, &v.x, 1); + D3DXFloat32To16Array(&y, &v.y, 1); + D3DXFloat32To16Array(&z, &v.z, 1); +#else + x = D3DX_ConvertFloatToHalf(v.x); + y = D3DX_ConvertFloatToHalf(v.y); + z = D3DX_ConvertFloatToHalf(v.z); +#endif +} + +D3DXINLINE +D3DXVECTOR3_16F::D3DXVECTOR3_16F( __in CONST D3DXFLOAT16 *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + *((DWORD *) &x) = *((DWORD *) &pf[0]); + *((WORD *) &z) = *((WORD *) &pf[2]); +} + +D3DXINLINE +D3DXVECTOR3_16F::D3DXVECTOR3_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz ) +{ + x = fx; + y = fy; + z = fz; +} + +// casting +D3DXINLINE +D3DXVECTOR3_16F::operator D3DXFLOAT16* () +{ + return (D3DXFLOAT16*) &x; +} + +D3DXINLINE +D3DXVECTOR3_16F::operator __in CONST D3DXFLOAT16 * () const +{ + return (__in CONST D3DXFLOAT16 *) &x; +} + +// assignment operators +D3DXINLINE D3DXVECTOR3_16F& +D3DXVECTOR3_16F::operator = ( CONST D3DXVECTOR3_16F& v ) +{ + x = v.x; + y = v.y; + z = v.z; + return *this; +} + +// binary operators +D3DXINLINE BOOL +D3DXVECTOR3_16F::operator == ( CONST D3DXVECTOR3_16F &v ) const +{ + return *((DWORD *) &x) == *((DWORD *) &v.x) && + *((WORD *) &z) == *((WORD *) &v.z); +} + +D3DXINLINE BOOL +D3DXVECTOR3_16F::operator != ( CONST D3DXVECTOR3_16F &v ) const +{ + return *((DWORD *) &x) != *((DWORD *) &v.x) || + *((WORD *) &z) != *((WORD *) &v.z); +} + + + +//-------------------------- +// 4D Vector +//-------------------------- +D3DXINLINE +D3DXVECTOR4::D3DXVECTOR4( __in CONST FLOAT *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + x = pf[0]; + y = pf[1]; + z = pf[2]; + w = pf[3]; +} + +D3DXINLINE +D3DXVECTOR4::D3DXVECTOR4( __in CONST D3DXFLOAT16 *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&x, pf, 4); +#else + D3DX_ConvertHalfToFloatStream(&x, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 4); +#endif +} + +D3DXINLINE +D3DXVECTOR4::D3DXVECTOR4( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw ) +{ + x = fx; + y = fy; + z = fz; + w = fw; +} + +// casting +D3DXINLINE +D3DXVECTOR4::operator FLOAT* () +{ + return (FLOAT *) &x; +} + +D3DXINLINE +D3DXVECTOR4::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &x; +} + + +// assignment operators +D3DXINLINE D3DXVECTOR4& +D3DXVECTOR4::operator = ( CONST D3DXVECTOR4& v ) +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; + return *this; +} + +D3DXINLINE D3DXVECTOR4& +D3DXVECTOR4::operator += ( CONST D3DXVECTOR4& v ) +{ + x += v.x; + y += v.y; + z += v.z; + w += v.w; + return *this; +} + +D3DXINLINE D3DXVECTOR4& +D3DXVECTOR4::operator -= ( CONST D3DXVECTOR4& v ) +{ + x -= v.x; + y -= v.y; + z -= v.z; + w -= v.w; + return *this; +} + +D3DXINLINE D3DXVECTOR4& +D3DXVECTOR4::operator *= ( FLOAT f ) +{ + x *= f; + y *= f; + z *= f; + w *= f; + return *this; +} + +D3DXINLINE D3DXVECTOR4& +D3DXVECTOR4::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + x *= fInv; + y *= fInv; + z *= fInv; + w *= fInv; +#else // !_NO_XBOXMATH + XMVECTOR V, S; + S = D3DX_VectorReplicate(f); + V = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + V = XMVectorMultiply(V, S); + XMStoreFloat4NC((XMFLOAT4*)this, V); +#endif // !_NO_XBOXMATH + return *this; +} + + +// unary operators +D3DXINLINE D3DXVECTOR4 +D3DXVECTOR4::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXVECTOR4 +D3DXVECTOR4::operator - () const +{ + return D3DXVECTOR4(-x, -y, -z, -w); +} + + +// binary operators +D3DXINLINE D3DXVECTOR4 +D3DXVECTOR4::operator + ( CONST D3DXVECTOR4& v ) const +{ + return D3DXVECTOR4(x + v.x, y + v.y, z + v.z, w + v.w); +} + +D3DXINLINE D3DXVECTOR4 +D3DXVECTOR4::operator - ( CONST D3DXVECTOR4& v ) const +{ + return D3DXVECTOR4(x - v.x, y - v.y, z - v.z, w - v.w); +} + +D3DXINLINE D3DXVECTOR4 +D3DXVECTOR4::operator * ( FLOAT f ) const +{ + return D3DXVECTOR4(x * f, y * f, z * f, w * f); +} + +D3DXINLINE D3DXVECTOR4 +D3DXVECTOR4::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXVECTOR4(x * fInv, y * fInv, z * fInv, w * fInv); +#else // !_NO_XBOXMATH + XMVECTOR V, S; + D3DXVECTOR4 Result; + + S = D3DX_VectorReplicate(f); + V = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + V = XMVectorMultiply(V, S); + XMStoreFloat4NC((XMFLOAT4*)&Result, V); + return Result; +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXVECTOR4 +operator * ( FLOAT f, CONST D3DXVECTOR4& v ) +{ + return D3DXVECTOR4(f * v.x, f * v.y, f * v.z, f * v.w); +} + + +D3DXINLINE BOOL +D3DXVECTOR4::operator == ( CONST D3DXVECTOR4& v ) const +{ + return x == v.x && y == v.y && z == v.z && w == v.w; +} + +D3DXINLINE BOOL +D3DXVECTOR4::operator != ( CONST D3DXVECTOR4& v ) const +{ + return x != v.x || y != v.y || z != v.z || w != v.w; +} + + + +//-------------------------- +// 4D Vector (16 bit) +//-------------------------- + +D3DXINLINE +D3DXVECTOR4_16F::D3DXVECTOR4_16F( __in CONST FLOAT *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat32To16Array(&x, pf, 4); +#else + D3DX_ConvertFloatToHalfStream((HALF*)&x, sizeof(D3DXFLOAT16), pf, sizeof(FLOAT), 4); +#endif +} + +D3DXINLINE +D3DXVECTOR4_16F::D3DXVECTOR4_16F( __in CONST D3DXFLOAT16 *pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + *((DWORD *) &x) = *((DWORD *) &pf[0]); + *((DWORD *) &z) = *((DWORD *) &pf[2]); +} + +D3DXINLINE +D3DXVECTOR4_16F::D3DXVECTOR4_16F( CONST D3DXFLOAT16 &fx, CONST D3DXFLOAT16 &fy, CONST D3DXFLOAT16 &fz, CONST D3DXFLOAT16 &fw ) +{ + x = fx; + y = fy; + z = fz; + w = fw; +} + +// casting +D3DXINLINE +D3DXVECTOR4_16F::operator D3DXFLOAT16* () +{ + return (D3DXFLOAT16*) &x; +} + +D3DXINLINE +D3DXVECTOR4_16F::operator __in CONST D3DXFLOAT16 * () const +{ + return (__in CONST D3DXFLOAT16 *) &x; +} + +// assignment operators +D3DXINLINE D3DXVECTOR4_16F& +D3DXVECTOR4_16F::operator = ( CONST D3DXVECTOR4_16F& v ) +{ + x = v.x; + y = v.y; + z = v.z; + w = v.w; + return *this; +} + +// binary operators +D3DXINLINE BOOL +D3DXVECTOR4_16F::operator == ( CONST D3DXVECTOR4_16F &v ) const +{ + return *((DWORD *) &x) == *((DWORD *) &v.x) && + *((DWORD *) &z) == *((DWORD *) &v.z); +} + +D3DXINLINE BOOL +D3DXVECTOR4_16F::operator != ( CONST D3DXVECTOR4_16F &v ) const +{ + return *((DWORD *) &x) != *((DWORD *) &v.x) || + *((DWORD *) &z) != *((DWORD *) &v.z); +} + + +//-------------------------- +// Matrix +//-------------------------- +D3DXINLINE +D3DXMATRIX::D3DXMATRIX( __in CONST FLOAT * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + memcpy(&_11, pf, sizeof(D3DXMATRIX)); +} + +D3DXINLINE +D3DXMATRIX::D3DXMATRIX( CONST D3DMATRIX& mat ) +{ + memcpy(&_11, &mat, sizeof(D3DXMATRIX)); +} + +D3DXINLINE +D3DXMATRIX::D3DXMATRIX( __in CONST D3DXFLOAT16 * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&_11, pf, 16); +#else + D3DX_ConvertHalfToFloatStream(&_11, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 16); +#endif +} + +D3DXINLINE +D3DXMATRIX::D3DXMATRIX( FLOAT f11, FLOAT f12, FLOAT f13, FLOAT f14, + FLOAT f21, FLOAT f22, FLOAT f23, FLOAT f24, + FLOAT f31, FLOAT f32, FLOAT f33, FLOAT f34, + FLOAT f41, FLOAT f42, FLOAT f43, FLOAT f44 ) +{ + _11 = f11; _12 = f12; _13 = f13; _14 = f14; + _21 = f21; _22 = f22; _23 = f23; _24 = f24; + _31 = f31; _32 = f32; _33 = f33; _34 = f34; + _41 = f41; _42 = f42; _43 = f43; _44 = f44; +} + + + +// access grants +D3DXINLINE FLOAT& +D3DXMATRIX::operator () ( UINT iRow, UINT iCol ) +{ + return m[iRow][iCol]; +} + +D3DXINLINE FLOAT +D3DXMATRIX::operator () ( UINT iRow, UINT iCol ) const +{ + return m[iRow][iCol]; +} + + +// casting operators +D3DXINLINE +D3DXMATRIX::operator FLOAT* () +{ + return (FLOAT *) &_11; +} + +D3DXINLINE +D3DXMATRIX::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &_11; +} + + +// assignment operators +D3DXINLINE D3DXMATRIX& +D3DXMATRIX::operator = ( CONST D3DXMATRIX& mat ) +{ + _11 = mat._11; _12 = mat._12; _13 = mat._13; _14 = mat._14; + _21 = mat._21; _22 = mat._22; _23 = mat._23; _24 = mat._24; + _31 = mat._31; _32 = mat._32; _33 = mat._33; _34 = mat._34; + _41 = mat._41; _42 = mat._42; _43 = mat._43; _44 = mat._44; + return *this; +} + +D3DXINLINE D3DXMATRIX& +D3DXMATRIX::operator *= ( CONST D3DXMATRIX& mat ) +{ + D3DXMatrixMultiply(this, this, &mat); + return *this; +} + +D3DXINLINE D3DXMATRIX& +D3DXMATRIX::operator += ( CONST D3DXMATRIX& mat ) +{ + _11 += mat._11; _12 += mat._12; _13 += mat._13; _14 += mat._14; + _21 += mat._21; _22 += mat._22; _23 += mat._23; _24 += mat._24; + _31 += mat._31; _32 += mat._32; _33 += mat._33; _34 += mat._34; + _41 += mat._41; _42 += mat._42; _43 += mat._43; _44 += mat._44; + return *this; +} + +D3DXINLINE D3DXMATRIX& +D3DXMATRIX::operator -= ( CONST D3DXMATRIX& mat ) +{ + _11 -= mat._11; _12 -= mat._12; _13 -= mat._13; _14 -= mat._14; + _21 -= mat._21; _22 -= mat._22; _23 -= mat._23; _24 -= mat._24; + _31 -= mat._31; _32 -= mat._32; _33 -= mat._33; _34 -= mat._34; + _41 -= mat._41; _42 -= mat._42; _43 -= mat._43; _44 -= mat._44; + return *this; +} + +D3DXINLINE D3DXMATRIX& +D3DXMATRIX::operator *= ( FLOAT f ) +{ + _11 *= f; _12 *= f; _13 *= f; _14 *= f; + _21 *= f; _22 *= f; _23 *= f; _24 *= f; + _31 *= f; _32 *= f; _33 *= f; _34 *= f; + _41 *= f; _42 *= f; _43 *= f; _44 *= f; + return *this; +} + +D3DXINLINE D3DXMATRIX& +D3DXMATRIX::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + _11 *= fInv; _12 *= fInv; _13 *= fInv; _14 *= fInv; + _21 *= fInv; _22 *= fInv; _23 *= fInv; _24 *= fInv; + _31 *= fInv; _32 *= fInv; _33 *= fInv; _34 *= fInv; + _41 *= fInv; _42 *= fInv; _43 *= fInv; _44 *= fInv; +#else // !_NO_XBOXMATH + XMMATRIX M; + XMVECTOR S; + + S = D3DX_VectorReplicate(f); + M = D3DX_LoadFloat4x4((__in CONST XMFLOAT4X4 *)this); + S = XMVectorReciprocal(S); + M.r[0] = XMVectorMultiply(M.r[0], S); + M.r[1] = XMVectorMultiply(M.r[1], S); + M.r[2] = XMVectorMultiply(M.r[2], S); + M.r[3] = XMVectorMultiply(M.r[3], S); + XMStoreFloat4x4NC((XMFLOAT4X4*)this, M); +#endif // !_NO_XBOXMATH + return *this; +} + + +// unary operators +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator - () const +{ + return D3DXMATRIX(-_11, -_12, -_13, -_14, + -_21, -_22, -_23, -_24, + -_31, -_32, -_33, -_34, + -_41, -_42, -_43, -_44); +} + + +// binary operators +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator * ( CONST D3DXMATRIX& mat ) const +{ + D3DXMATRIX matT; + D3DXMatrixMultiply(&matT, this, &mat); + return matT; +} + +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator + ( CONST D3DXMATRIX& mat ) const +{ + return D3DXMATRIX(_11 + mat._11, _12 + mat._12, _13 + mat._13, _14 + mat._14, + _21 + mat._21, _22 + mat._22, _23 + mat._23, _24 + mat._24, + _31 + mat._31, _32 + mat._32, _33 + mat._33, _34 + mat._34, + _41 + mat._41, _42 + mat._42, _43 + mat._43, _44 + mat._44); +} + +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator - ( CONST D3DXMATRIX& mat ) const +{ + return D3DXMATRIX(_11 - mat._11, _12 - mat._12, _13 - mat._13, _14 - mat._14, + _21 - mat._21, _22 - mat._22, _23 - mat._23, _24 - mat._24, + _31 - mat._31, _32 - mat._32, _33 - mat._33, _34 - mat._34, + _41 - mat._41, _42 - mat._42, _43 - mat._43, _44 - mat._44); +} + +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator * ( FLOAT f ) const +{ + return D3DXMATRIX(_11 * f, _12 * f, _13 * f, _14 * f, + _21 * f, _22 * f, _23 * f, _24 * f, + _31 * f, _32 * f, _33 * f, _34 * f, + _41 * f, _42 * f, _43 * f, _44 * f); +} + +D3DXINLINE D3DXMATRIX +D3DXMATRIX::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXMATRIX(_11 * fInv, _12 * fInv, _13 * fInv, _14 * fInv, + _21 * fInv, _22 * fInv, _23 * fInv, _24 * fInv, + _31 * fInv, _32 * fInv, _33 * fInv, _34 * fInv, + _41 * fInv, _42 * fInv, _43 * fInv, _44 * fInv); +#else // !_NO_XBOXMATH + XMMATRIX M; + XMVECTOR S; + D3DXMATRIX Result; + + S = D3DX_VectorReplicate(f); + M = D3DX_LoadFloat4x4((__in CONST XMFLOAT4X4 *)this); + S = XMVectorReciprocal(S); + M.r[0] = XMVectorMultiply(M.r[0], S); + M.r[1] = XMVectorMultiply(M.r[1], S); + M.r[2] = XMVectorMultiply(M.r[2], S); + M.r[3] = XMVectorMultiply(M.r[3], S); + XMStoreFloat4x4NC((XMFLOAT4X4*)&Result, M); + return Result; +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXMATRIX +operator * ( FLOAT f, CONST D3DXMATRIX& mat ) +{ + return D3DXMATRIX(f * mat._11, f * mat._12, f * mat._13, f * mat._14, + f * mat._21, f * mat._22, f * mat._23, f * mat._24, + f * mat._31, f * mat._32, f * mat._33, f * mat._34, + f * mat._41, f * mat._42, f * mat._43, f * mat._44); +} + + +D3DXINLINE BOOL +D3DXMATRIX::operator == ( CONST D3DXMATRIX& mat ) const +{ + return 0 == memcmp(this, &mat, sizeof(D3DXMATRIX)); +} + +D3DXINLINE BOOL +D3DXMATRIX::operator != ( CONST D3DXMATRIX& mat ) const +{ + return 0 != memcmp(this, &mat, sizeof(D3DXMATRIX)); +} + + + +//-------------------------- +// Aligned Matrices +//-------------------------- + +D3DXINLINE +_D3DXMATRIXA16::_D3DXMATRIXA16( __in CONST FLOAT * f ) : + D3DXMATRIX( f ) +{ +} + +D3DXINLINE +_D3DXMATRIXA16::_D3DXMATRIXA16( CONST D3DMATRIX& m ) : + D3DXMATRIX( m ) +{ +} + +D3DXINLINE +_D3DXMATRIXA16::_D3DXMATRIXA16( __in CONST D3DXFLOAT16 * f ) : + D3DXMATRIX( f ) +{ +} + +D3DXINLINE +_D3DXMATRIXA16::_D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14, + FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24, + FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34, + FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ) : + D3DXMATRIX(_11, _12, _13, _14, + _21, _22, _23, _24, + _31, _32, _33, _34, + _41, _42, _43, _44) +{ +} + +D3DXINLINE void* +_D3DXMATRIXA16::operator new( size_t s ) +{ + LPBYTE p = ::new BYTE[s + 16]; + if (p) + { + BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15)); + p += offset; + p[-1] = offset; + } + return p; +} + +D3DXINLINE void* +_D3DXMATRIXA16::operator new[]( size_t s ) +{ + LPBYTE p = ::new BYTE[s + 16]; + if (p) + { + BYTE offset = (BYTE)(16 - ((UINT_PTR)p & 15)); + p += offset; + p[-1] = offset; + } + return p; +} + +D3DXINLINE void +_D3DXMATRIXA16::operator delete(void* p) +{ + if(p) + { + BYTE* pb = static_cast(p); + pb -= pb[-1]; + ::delete [] pb; + } +} + +D3DXINLINE void +_D3DXMATRIXA16::operator delete[](void* p) +{ + if(p) + { + BYTE* pb = static_cast(p); + pb -= pb[-1]; + ::delete [] pb; + } +} + +D3DXINLINE _D3DXMATRIXA16& +_D3DXMATRIXA16::operator=(CONST D3DXMATRIX& rhs) +{ + memcpy(&_11, &rhs, sizeof(D3DXMATRIX)); + return *this; +} + + +//-------------------------- +// Quaternion +//-------------------------- + +D3DXINLINE +D3DXQUATERNION::D3DXQUATERNION( __in CONST FLOAT * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + x = pf[0]; + y = pf[1]; + z = pf[2]; + w = pf[3]; +} + +D3DXINLINE +D3DXQUATERNION::D3DXQUATERNION( __in CONST D3DXFLOAT16 * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&x, pf, 4); +#else + D3DX_ConvertHalfToFloatStream(&x, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 4); +#endif +} + +D3DXINLINE +D3DXQUATERNION::D3DXQUATERNION( FLOAT fx, FLOAT fy, FLOAT fz, FLOAT fw ) +{ + x = fx; + y = fy; + z = fz; + w = fw; +} + + +// casting +D3DXINLINE +D3DXQUATERNION::operator FLOAT* () +{ + return (FLOAT *) &x; +} + +D3DXINLINE +D3DXQUATERNION::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &x; +} + + +// assignment operators +D3DXINLINE D3DXQUATERNION& +D3DXQUATERNION::operator = ( CONST D3DXQUATERNION& q ) +{ + x = q.x; + y = q.y; + z = q.z; + w = q.w; + return *this; +} + +D3DXINLINE D3DXQUATERNION& +D3DXQUATERNION::operator += ( CONST D3DXQUATERNION& q ) +{ + x += q.x; + y += q.y; + z += q.z; + w += q.w; + return *this; +} + +D3DXINLINE D3DXQUATERNION& +D3DXQUATERNION::operator -= ( CONST D3DXQUATERNION& q ) +{ + x -= q.x; + y -= q.y; + z -= q.z; + w -= q.w; + return *this; +} + +D3DXINLINE D3DXQUATERNION& +D3DXQUATERNION::operator *= ( CONST D3DXQUATERNION& q ) +{ +#ifdef _NO_XBOXMATH + D3DXQuaternionMultiply(this, this, &q); +#else + XMVECTOR Q0, Q1; + Q0 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + Q1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)&q); + Q0 = XMQuaternionMultiply(Q0, Q1); + XMStoreFloat4NC((XMFLOAT4*)this, Q0); +#endif + return *this; +} + +D3DXINLINE D3DXQUATERNION& +D3DXQUATERNION::operator *= ( FLOAT f ) +{ + x *= f; + y *= f; + z *= f; + w *= f; + return *this; +} + +D3DXINLINE D3DXQUATERNION& +D3DXQUATERNION::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + x *= fInv; + y *= fInv; + z *= fInv; + w *= fInv; +#else // !_NO_XBOXMATH + XMVECTOR Q, S; + S = D3DX_VectorReplicate(f); + Q = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + Q = XMVectorMultiply(Q, S); + XMStoreFloat4NC((XMFLOAT4*)this, Q); +#endif // !_NO_XBOXMATH + return *this; +} + + +// unary operators +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator - () const +{ + return D3DXQUATERNION(-x, -y, -z, -w); +} + + +// binary operators +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator + ( CONST D3DXQUATERNION& q ) const +{ + return D3DXQUATERNION(x + q.x, y + q.y, z + q.z, w + q.w); +} + +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator - ( CONST D3DXQUATERNION& q ) const +{ + return D3DXQUATERNION(x - q.x, y - q.y, z - q.z, w - q.w); +} + +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator * ( CONST D3DXQUATERNION& q ) const +{ + D3DXQUATERNION qT; +#ifdef _NO_XBOXMATH + D3DXQuaternionMultiply(&qT, this, &q); +#else + XMVECTOR Q0, Q1; + Q0 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + Q1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)&q); + Q0 = XMQuaternionMultiply(Q0, Q1); + XMStoreFloat4NC((XMFLOAT4*)&qT, Q0); +#endif + return qT; +} + +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator * ( FLOAT f ) const +{ + return D3DXQUATERNION(x * f, y * f, z * f, w * f); +} + +D3DXINLINE D3DXQUATERNION +D3DXQUATERNION::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXQUATERNION(x * fInv, y * fInv, z * fInv, w * fInv); +#else // !_NO_XBOXMATH + XMVECTOR Q, S; + D3DXQUATERNION Result; + + S = D3DX_VectorReplicate(f); + Q = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + Q = XMVectorMultiply(Q, S); + XMStoreFloat4NC((XMFLOAT4*)&Result, Q); + return Result; +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXQUATERNION +operator * (FLOAT f, CONST D3DXQUATERNION& q ) +{ + return D3DXQUATERNION(f * q.x, f * q.y, f * q.z, f * q.w); +} + + +D3DXINLINE BOOL +D3DXQUATERNION::operator == ( CONST D3DXQUATERNION& q ) const +{ + return x == q.x && y == q.y && z == q.z && w == q.w; +} + +D3DXINLINE BOOL +D3DXQUATERNION::operator != ( CONST D3DXQUATERNION& q ) const +{ + return x != q.x || y != q.y || z != q.z || w != q.w; +} + + + +//-------------------------- +// Plane +//-------------------------- + +D3DXINLINE +D3DXPLANE::D3DXPLANE( __in CONST FLOAT * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + a = pf[0]; + b = pf[1]; + c = pf[2]; + d = pf[3]; +} + +D3DXINLINE +D3DXPLANE::D3DXPLANE( __in CONST D3DXFLOAT16 * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&a, pf, 4); +#else + D3DX_ConvertHalfToFloatStream(&a, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 4); +#endif +} + +D3DXINLINE +D3DXPLANE::D3DXPLANE( FLOAT fa, FLOAT fb, FLOAT fc, FLOAT fd ) +{ + a = fa; + b = fb; + c = fc; + d = fd; +} + + +// casting +D3DXINLINE +D3DXPLANE::operator FLOAT* () +{ + return (FLOAT *) &a; +} + +D3DXINLINE +D3DXPLANE::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &a; +} + + +// assignment operators +D3DXINLINE D3DXPLANE& +D3DXPLANE::operator = ( CONST D3DXPLANE& p ) +{ + a = p.a; + b = p.b; + c = p.c; + d = p.d; + return *this; +} + +D3DXINLINE D3DXPLANE& +D3DXPLANE::operator *= ( FLOAT f ) +{ + a *= f; + b *= f; + c *= f; + d *= f; + return *this; +} + +D3DXINLINE D3DXPLANE& +D3DXPLANE::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + a *= fInv; + b *= fInv; + c *= fInv; + d *= fInv; +#else // !_NO_XBOXMATH + XMVECTOR P, S; + S = D3DX_VectorReplicate(f); + P = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + P = XMVectorMultiply(P, S); + XMStoreFloat4NC((XMFLOAT4*)this, P); +#endif // !_NO_XBOXMATH + return *this; +} + + +// unary operators +D3DXINLINE D3DXPLANE +D3DXPLANE::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXPLANE +D3DXPLANE::operator - () const +{ + return D3DXPLANE(-a, -b, -c, -d); +} + + +// binary operators +D3DXINLINE D3DXPLANE +D3DXPLANE::operator * ( FLOAT f ) const +{ + return D3DXPLANE(a * f, b * f, c * f, d * f); +} + +D3DXINLINE D3DXPLANE +D3DXPLANE::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXPLANE(a * fInv, b * fInv, c * fInv, d * fInv); +#else // !_NO_XBOXMATH + XMVECTOR P, S; + D3DXPLANE Result; + + S = D3DX_VectorReplicate(f); + P = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + P = XMVectorMultiply(P, S); + XMStoreFloat4NC((XMFLOAT4*)&Result, P); + return Result; +#endif // !_NO_XBOXMATH +} + +D3DXINLINE D3DXPLANE +operator * (FLOAT f, CONST D3DXPLANE& p ) +{ + return D3DXPLANE(f * p.a, f * p.b, f * p.c, f * p.d); +} + +D3DXINLINE BOOL +D3DXPLANE::operator == ( CONST D3DXPLANE& p ) const +{ + return a == p.a && b == p.b && c == p.c && d == p.d; +} + +D3DXINLINE BOOL +D3DXPLANE::operator != ( CONST D3DXPLANE& p ) const +{ + return a != p.a || b != p.b || c != p.c || d != p.d; +} + + + + +//-------------------------- +// Color +//-------------------------- + +D3DXINLINE +D3DXCOLOR::D3DXCOLOR( DWORD dw ) +{ + CONST FLOAT f = 1.0f / 255.0f; + r = f * (FLOAT) (unsigned char) (dw >> 16); + g = f * (FLOAT) (unsigned char) (dw >> 8); + b = f * (FLOAT) (unsigned char) (dw >> 0); + a = f * (FLOAT) (unsigned char) (dw >> 24); +} + +D3DXINLINE +D3DXCOLOR::D3DXCOLOR( __in CONST FLOAT * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + + r = pf[0]; + g = pf[1]; + b = pf[2]; + a = pf[3]; +} + +D3DXINLINE +D3DXCOLOR::D3DXCOLOR( __in CONST D3DXFLOAT16 * pf ) +{ +#ifdef D3DX_DEBUG + if(!pf) + return; +#endif + +#ifdef _NO_XBOXMATH + D3DXFloat16To32Array(&r, pf, 4); +#else + D3DX_ConvertHalfToFloatStream(&r, sizeof(FLOAT), (__in CONST HALF *)pf, sizeof(D3DXFLOAT16), 4); +#endif +} + +D3DXINLINE +D3DXCOLOR::D3DXCOLOR( CONST D3DCOLORVALUE& c ) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +D3DXINLINE +D3DXCOLOR::D3DXCOLOR( FLOAT fr, FLOAT fg, FLOAT fb, FLOAT fa ) +{ + r = fr; + g = fg; + b = fb; + a = fa; +} + + +// casting +D3DXINLINE +D3DXCOLOR::operator DWORD () const +{ +#ifdef _NO_XBOXMATH + DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f); + DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f); + DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f); + DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f); + + return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB; +#else + XMVECTOR ColorSrc; + XMCOLOR ColorDst; + + ColorSrc = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + XMStoreColor(&ColorDst, ColorSrc); + + return ColorDst.c; +#endif +} + + +D3DXINLINE +D3DXCOLOR::operator FLOAT * () +{ + return (FLOAT *) &r; +} + +D3DXINLINE +D3DXCOLOR::operator __in CONST FLOAT * () const +{ + return (__in CONST FLOAT *) &r; +} + + +D3DXINLINE +D3DXCOLOR::operator D3DCOLORVALUE * () +{ + return (D3DCOLORVALUE *) &r; +} + +D3DXINLINE +D3DXCOLOR::operator __in CONST D3DCOLORVALUE * () const +{ + return (__in CONST D3DCOLORVALUE *) &r; +} + + +D3DXINLINE +D3DXCOLOR::operator D3DCOLORVALUE& () +{ + return *((D3DCOLORVALUE *) &r); +} + +D3DXINLINE +D3DXCOLOR::operator CONST D3DCOLORVALUE& () const +{ + return *((__in CONST D3DCOLORVALUE *) &r); +} + + +// assignment operators +D3DXINLINE D3DXCOLOR& +D3DXCOLOR::operator = ( CONST D3DXCOLOR& c ) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; + return *this; +} + +D3DXINLINE D3DXCOLOR& +D3DXCOLOR::operator += ( CONST D3DXCOLOR& c ) +{ + r += c.r; + g += c.g; + b += c.b; + a += c.a; + return *this; +} + +D3DXINLINE D3DXCOLOR& +D3DXCOLOR::operator -= ( CONST D3DXCOLOR& c ) +{ + r -= c.r; + g -= c.g; + b -= c.b; + a -= c.a; + return *this; +} + +D3DXINLINE D3DXCOLOR& +D3DXCOLOR::operator *= ( FLOAT f ) +{ + r *= f; + g *= f; + b *= f; + a *= f; + return *this; +} + +D3DXINLINE D3DXCOLOR& +D3DXCOLOR::operator /= ( FLOAT f ) +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + r *= fInv; + g *= fInv; + b *= fInv; + a *= fInv; +#else // !_NO_XBOXMATH + XMVECTOR C, S; + S = D3DX_VectorReplicate(f); + C = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + C = XMVectorMultiply(C, S); + XMStoreFloat4NC((XMFLOAT4*)this, C); +#endif // !_NO_XBOXMATH + return *this; +} + + +// unary operators +D3DXINLINE D3DXCOLOR +D3DXCOLOR::operator + () const +{ + return *this; +} + +D3DXINLINE D3DXCOLOR +D3DXCOLOR::operator - () const +{ + return D3DXCOLOR(-r, -g, -b, -a); +} + + +// binary operators +D3DXINLINE D3DXCOLOR +D3DXCOLOR::operator + ( CONST D3DXCOLOR& c ) const +{ + return D3DXCOLOR(r + c.r, g + c.g, b + c.b, a + c.a); +} + +D3DXINLINE D3DXCOLOR +D3DXCOLOR::operator - ( CONST D3DXCOLOR& c ) const +{ + return D3DXCOLOR(r - c.r, g - c.g, b - c.b, a - c.a); +} + +D3DXINLINE D3DXCOLOR +D3DXCOLOR::operator * ( FLOAT f ) const +{ + return D3DXCOLOR(r * f, g * f, b * f, a * f); +} + +D3DXINLINE D3DXCOLOR +D3DXCOLOR::operator / ( FLOAT f ) const +{ +#ifdef _NO_XBOXMATH + FLOAT fInv = 1.0f / f; + return D3DXCOLOR(r * fInv, g * fInv, b * fInv, a * fInv); +#else // !_NO_XBOXMATH + XMVECTOR C, S; + D3DXCOLOR Result; + + S = D3DX_VectorReplicate(f); + C = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)this); + S = XMVectorReciprocal(S); + C = XMVectorMultiply(C, S); + XMStoreFloat4NC((XMFLOAT4*)&Result, C); + return Result; +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXCOLOR +operator * (FLOAT f, CONST D3DXCOLOR& c ) +{ + return D3DXCOLOR(f * c.r, f * c.g, f * c.b, f * c.a); +} + + +D3DXINLINE BOOL +D3DXCOLOR::operator == ( CONST D3DXCOLOR& c ) const +{ + return r == c.r && g == c.g && b == c.b && a == c.a; +} + +D3DXINLINE BOOL +D3DXCOLOR::operator != ( CONST D3DXCOLOR& c ) const +{ + return r != c.r || g != c.g || b != c.b || a != c.a; +} + + +#endif //__cplusplus + + + +//=========================================================================== +// +// Inline functions +// +//=========================================================================== + + +//-------------------------- +// 2D Vector +//-------------------------- + +D3DXINLINE FLOAT D3DXVec2Length + ( __in CONST D3DXVECTOR2 *pV ) +{ +#ifdef D3DX_DEBUG + if(!pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + +#ifdef __cplusplus + return sqrtf(pV->x * pV->x + pV->y * pV->y); +#else + return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y); +#endif + +#else // !_NO_XBOXMATH + + XMVECTOR V, Result; + + V = D3DX_LoadFloat2((__in CONST XMFLOAT2 *)pV); + Result = XMVector2Length(V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXVec2LengthSq + ( __in CONST D3DXVECTOR2 *pV ) +{ +#ifdef D3DX_DEBUG + if(!pV) + return 0.0f; +#endif + + return pV->x * pV->x + pV->y * pV->y; +} + +D3DXINLINE FLOAT D3DXVec2Dot + ( __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pV1 || !pV2) + return 0.0f; +#endif + + return pV1->x * pV2->x + pV1->y * pV2->y; +} + +D3DXINLINE FLOAT D3DXVec2CCW + ( __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pV1 || !pV2) + return 0.0f; +#endif + + return pV1->x * pV2->y - pV1->y * pV2->x; +} + +D3DXINLINE D3DXVECTOR2* D3DXVec2Add + ( __out D3DXVECTOR2 * pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x + pV2->x; + pOut->y = pV1->y + pV2->y; + return pOut; +} + +D3DXINLINE D3DXVECTOR2* D3DXVec2Subtract + ( __out D3DXVECTOR2 * pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x - pV2->x; + pOut->y = pV1->y - pV2->y; + return pOut; +} + +D3DXINLINE D3DXVECTOR2* D3DXVec2Minimize + ( __out D3DXVECTOR2 * pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x; + pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y; + return pOut; +} + +D3DXINLINE D3DXVECTOR2* D3DXVec2Maximize + ( __out D3DXVECTOR2 * pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x; + pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y; + return pOut; +} + +D3DXINLINE D3DXVECTOR2* D3DXVec2Scale + ( __out D3DXVECTOR2 * pOut, __in CONST D3DXVECTOR2 *pV, FLOAT s ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV) + return NULL; +#endif + + pOut->x = pV->x * s; + pOut->y = pV->y * s; + return pOut; +} + +D3DXINLINE D3DXVECTOR2* D3DXVec2Lerp + ( __out D3DXVECTOR2 * pOut, __in CONST D3DXVECTOR2 *pV1, __in CONST D3DXVECTOR2 *pV2, + FLOAT s ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x + s * (pV2->x - pV1->x); + pOut->y = pV1->y + s * (pV2->y - pV1->y); + return pOut; +} + + +//-------------------------- +// 3D Vector +//-------------------------- + +D3DXINLINE FLOAT D3DXVec3Length + ( __in CONST D3DXVECTOR3 *pV ) +{ +#ifdef D3DX_DEBUG + if(!pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + +#ifdef __cplusplus + return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z); +#else + return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z); +#endif + +#else // !_NO_XBOXMATH + + XMVECTOR V, Result; + + V = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV); + Result = XMVector3Length(V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXVec3LengthSq + ( __in CONST D3DXVECTOR3 *pV ) +{ +#ifdef D3DX_DEBUG + if(!pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z; + +#else // !_NO_XBOXMATH + + XMVECTOR V, Result; + + V = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV); + Result = XMVector3LengthSq(V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXVec3Dot + ( __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pV1 || !pV2) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV1); + V2 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV2); + Result = XMVector3Dot(V1, V2); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Cross + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + D3DXVECTOR3 v; + + v.x = pV1->y * pV2->z - pV1->z * pV2->y; + v.y = pV1->z * pV2->x - pV1->x * pV2->z; + v.z = pV1->x * pV2->y - pV1->y * pV2->x; + + *pOut = v; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV1); + V2 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV2); + Result = XMVector3Cross(V1, V2); + XMStoreFloat3((XMFLOAT3*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Add + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x + pV2->x; + pOut->y = pV1->y + pV2->y; + pOut->z = pV1->z + pV2->z; + return pOut; +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x - pV2->x; + pOut->y = pV1->y - pV2->y; + pOut->z = pV1->z - pV2->z; + return pOut; +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Minimize + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x; + pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y; + pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV1); + V2 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV2); + Result = XMVectorMinimize(V1, V2); + XMStoreFloat3((XMFLOAT3*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Maximize + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x; + pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y; + pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV1); + V2 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV2); + Result = XMVectorMaximize(V1, V2); + XMStoreFloat3((XMFLOAT3*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Scale + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV, FLOAT s) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV) + return NULL; +#endif + + pOut->x = pV->x * s; + pOut->y = pV->y * s; + pOut->z = pV->z * s; + return pOut; +} + +D3DXINLINE D3DXVECTOR3* D3DXVec3Lerp + ( __out D3DXVECTOR3 * pOut, __in CONST D3DXVECTOR3 *pV1, __in CONST D3DXVECTOR3 *pV2, + FLOAT s ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pV1->x + s * (pV2->x - pV1->x); + pOut->y = pV1->y + s * (pV2->y - pV1->y); + pOut->z = pV1->z + s * (pV2->z - pV1->z); + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV1); + V2 = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV2); + Result = D3DX_VectorLerp(V1, V2, s); + XMStoreFloat3((XMFLOAT3*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + + +//-------------------------- +// 4D Vector +//-------------------------- + +D3DXINLINE FLOAT D3DXVec4Length + ( __in CONST D3DXVECTOR4 *pV ) +{ +#ifdef D3DX_DEBUG + if(!pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + +#ifdef __cplusplus + return sqrtf(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w); +#else + return (FLOAT) sqrt(pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w); +#endif + +#else // !_NO_XBOXMATH + + XMVECTOR V, Result; + + V = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV); + Result = XMVector4Length(V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXVec4LengthSq + ( __in CONST D3DXVECTOR4 *pV ) +{ +#ifdef D3DX_DEBUG + if(!pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pV->x * pV->x + pV->y * pV->y + pV->z * pV->z + pV->w * pV->w; + +#else // !_NO_XBOXMATH + + XMVECTOR V, Result; + + V = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV); + Result = XMVector4LengthSq(V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXVec4Dot + ( __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2 ) +{ +#ifdef D3DX_DEBUG + if(!pV1 || !pV2) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z + pV1->w * pV2->w; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV1); + V2 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV2); + Result = XMVector4Dot(V1, V2); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE D3DXVECTOR4* D3DXVec4Add + ( __out D3DXVECTOR4 * pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x + pV2->x; + pOut->y = pV1->y + pV2->y; + pOut->z = pV1->z + pV2->z; + pOut->w = pV1->w + pV2->w; + return pOut; +} + +D3DXINLINE D3DXVECTOR4* D3DXVec4Subtract + ( __out D3DXVECTOR4 * pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + + pOut->x = pV1->x - pV2->x; + pOut->y = pV1->y - pV2->y; + pOut->z = pV1->z - pV2->z; + pOut->w = pV1->w - pV2->w; + return pOut; +} + +D3DXINLINE D3DXVECTOR4* D3DXVec4Minimize + ( __out D3DXVECTOR4 * pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pV1->x < pV2->x ? pV1->x : pV2->x; + pOut->y = pV1->y < pV2->y ? pV1->y : pV2->y; + pOut->z = pV1->z < pV2->z ? pV1->z : pV2->z; + pOut->w = pV1->w < pV2->w ? pV1->w : pV2->w; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV1); + V2 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV2); + Result = XMVectorMinimize(V1, V2); + XMStoreFloat4NC((XMFLOAT4*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + +D3DXINLINE D3DXVECTOR4* D3DXVec4Maximize + ( __out D3DXVECTOR4 * pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pV1->x > pV2->x ? pV1->x : pV2->x; + pOut->y = pV1->y > pV2->y ? pV1->y : pV2->y; + pOut->z = pV1->z > pV2->z ? pV1->z : pV2->z; + pOut->w = pV1->w > pV2->w ? pV1->w : pV2->w; + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV1); + V2 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV2); + Result = XMVectorMaximize(V1, V2); + XMStoreFloat4NC((XMFLOAT4*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + +D3DXINLINE D3DXVECTOR4* D3DXVec4Scale + ( __out D3DXVECTOR4 * pOut, __in CONST D3DXVECTOR4 *pV, FLOAT s) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV) + return NULL; +#endif + + pOut->x = pV->x * s; + pOut->y = pV->y * s; + pOut->z = pV->z * s; + pOut->w = pV->w * s; + return pOut; +} + +D3DXINLINE D3DXVECTOR4* D3DXVec4Lerp + ( __out D3DXVECTOR4 * pOut, __in CONST D3DXVECTOR4 *pV1, __in CONST D3DXVECTOR4 *pV2, + FLOAT s ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pV1 || !pV2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pV1->x + s * (pV2->x - pV1->x); + pOut->y = pV1->y + s * (pV2->y - pV1->y); + pOut->z = pV1->z + s * (pV2->z - pV1->z); + pOut->w = pV1->w + s * (pV2->w - pV1->w); + +#else // !_NO_XBOXMATH + + XMVECTOR V1, V2, Result; + + V1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV1); + V2 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV2); + Result = D3DX_VectorLerp(V1, V2, s); + XMStoreFloat4NC((XMFLOAT4*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + + +//-------------------------- +// 4D Matrix +//-------------------------- + +D3DXINLINE D3DXMATRIX* D3DXMatrixIdentity + ( __out D3DXMATRIX * pOut ) +{ +#ifdef D3DX_DEBUG + if(!pOut) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->m[0][1] = pOut->m[0][2] = pOut->m[0][3] = + pOut->m[1][0] = pOut->m[1][2] = pOut->m[1][3] = + pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] = + pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f; + + pOut->m[0][0] = pOut->m[1][1] = pOut->m[2][2] = pOut->m[3][3] = 1.0f; + +#else // !_NO_XBOXMATH + + XMMATRIX M; + M = XMMatrixIdentity(); + XMStoreFloat4x4NC((XMFLOAT4X4*)pOut, M); + +#endif // !_NO_XBOXMATH + + return pOut; +} + + +D3DXINLINE BOOL D3DXMatrixIsIdentity + ( __in CONST D3DXMATRIX *pM ) +{ +#ifdef D3DX_DEBUG + if(!pM) + return FALSE; +#endif + +#ifdef _NO_XBOXMATH + + return pM->m[0][0] == 1.0f && pM->m[0][1] == 0.0f && pM->m[0][2] == 0.0f && pM->m[0][3] == 0.0f && + pM->m[1][0] == 0.0f && pM->m[1][1] == 1.0f && pM->m[1][2] == 0.0f && pM->m[1][3] == 0.0f && + pM->m[2][0] == 0.0f && pM->m[2][1] == 0.0f && pM->m[2][2] == 1.0f && pM->m[2][3] == 0.0f && + pM->m[3][0] == 0.0f && pM->m[3][1] == 0.0f && pM->m[3][2] == 0.0f && pM->m[3][3] == 1.0f; + +#else // !_NO_XBOXMATH + + XMMATRIX M; + M = D3DX_LoadFloat4x4((__in CONST XMFLOAT4X4 *)pM); + return XMMatrixIsIdentity(M); + +#endif // !_NO_XBOXMATH +} + + +//-------------------------- +// Quaternion +//-------------------------- + +D3DXINLINE FLOAT D3DXQuaternionLength + ( __in CONST D3DXQUATERNION *pQ ) +{ +#ifdef D3DX_DEBUG + if(!pQ) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + +#ifdef __cplusplus + return sqrtf(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w); +#else + return (FLOAT) sqrt(pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w); +#endif + +#else // !_NO_XBOXMATH + + XMVECTOR Q, Result; + + Q = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pQ); + Result = XMQuaternionLength(Q); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXQuaternionLengthSq + ( __in CONST D3DXQUATERNION *pQ ) +{ +#ifdef D3DX_DEBUG + if(!pQ) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pQ->x * pQ->x + pQ->y * pQ->y + pQ->z * pQ->z + pQ->w * pQ->w; + +#else // !_NO_XBOXMATH + + XMVECTOR Q, Result; + + Q = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pQ); + Result = XMQuaternionLengthSq(Q); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXQuaternionDot + ( __in CONST D3DXQUATERNION *pQ1, __in CONST D3DXQUATERNION *pQ2 ) +{ +#ifdef D3DX_DEBUG + if(!pQ1 || !pQ2) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pQ1->x * pQ2->x + pQ1->y * pQ2->y + pQ1->z * pQ2->z + pQ1->w * pQ2->w; + +#else // !_NO_XBOXMATH + + XMVECTOR Q1, Q2, Result; + + Q1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pQ1); + Q2 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pQ2); + Result = XMQuaternionDot(Q1, Q2); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXQUATERNION* D3DXQuaternionIdentity + ( __out D3DXQUATERNION * pOut ) +{ +#ifdef D3DX_DEBUG + if(!pOut) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->x = pOut->y = pOut->z = 0.0f; + pOut->w = 1.0f; + +#else // !_NO_XBOXMATH + + XMVECTOR Q; + Q = XMQuaternionIdentity(); + XMStoreFloat4NC((XMFLOAT4*)pOut, Q); + +#endif // !_NO_XBOXMATH + + return pOut; +} + +D3DXINLINE BOOL D3DXQuaternionIsIdentity + ( __in CONST D3DXQUATERNION *pQ ) +{ +#ifdef D3DX_DEBUG + if(!pQ) + return FALSE; +#endif + +#ifdef _NO_XBOXMATH + + return pQ->x == 0.0f && pQ->y == 0.0f && pQ->z == 0.0f && pQ->w == 1.0f; + +#else // !_NO_XBOXMATH + + XMVECTOR Q; + Q = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pQ); + return XMQuaternionIsIdentity(Q); + +#endif // !_NO_XBOXMATH +} + + +D3DXINLINE D3DXQUATERNION* D3DXQuaternionConjugate + ( __out D3DXQUATERNION * pOut, __in CONST D3DXQUATERNION *pQ ) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pQ) + return NULL; +#endif + + pOut->x = -pQ->x; + pOut->y = -pQ->y; + pOut->z = -pQ->z; + pOut->w = pQ->w; + return pOut; +} + + +//-------------------------- +// Plane +//-------------------------- + +D3DXINLINE FLOAT D3DXPlaneDot + ( __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR4 *pV) +{ +#ifdef D3DX_DEBUG + if(!pP || !pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d * pV->w; + +#else // !_NO_XBOXMATH + + XMVECTOR P, V, Result; + + P = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pP); + V = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pV); + Result = XMPlaneDot(P, V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXPlaneDotCoord + ( __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR3 *pV) +{ +#ifdef D3DX_DEBUG + if(!pP || !pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d; + +#else // !_NO_XBOXMATH + + XMVECTOR P, V, Result; + + P = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pP); + V = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV); + Result = XMPlaneDotCoord(P, V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE FLOAT D3DXPlaneDotNormal + ( __in CONST D3DXPLANE *pP, __in CONST D3DXVECTOR3 *pV) +{ +#ifdef D3DX_DEBUG + if(!pP || !pV) + return 0.0f; +#endif + +#ifdef _NO_XBOXMATH + + return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z; + +#else // !_NO_XBOXMATH + + XMVECTOR P, V, Result; + + P = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pP); + V = D3DX_LoadFloat3((__in CONST XMFLOAT3 *)pV); + Result = XMPlaneDotNormal(P, V); + + return XMVectorGetX( Result ); + +#endif // !_NO_XBOXMATH +} + +D3DXINLINE D3DXPLANE* D3DXPlaneScale + (__out D3DXPLANE * pOut, __in CONST D3DXPLANE *pP, FLOAT s) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pP) + return NULL; +#endif + + pOut->a = pP->a * s; + pOut->b = pP->b * s; + pOut->c = pP->c * s; + pOut->d = pP->d * s; + return pOut; +} + + +//-------------------------- +// Color +//-------------------------- + +D3DXINLINE D3DXCOLOR* D3DXColorNegative + (__out D3DXCOLOR * pOut, __in CONST D3DXCOLOR *pC) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pC) + return NULL; +#endif + + pOut->r = 1.0f - pC->r; + pOut->g = 1.0f - pC->g; + pOut->b = 1.0f - pC->b; + pOut->a = pC->a; + return pOut; +} + +D3DXINLINE D3DXCOLOR* D3DXColorAdd + (__out D3DXCOLOR * pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pC1 || !pC2) + return NULL; +#endif + + pOut->r = pC1->r + pC2->r; + pOut->g = pC1->g + pC2->g; + pOut->b = pC1->b + pC2->b; + pOut->a = pC1->a + pC2->a; + return pOut; +} + +D3DXINLINE D3DXCOLOR* D3DXColorSubtract + (__out D3DXCOLOR * pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pC1 || !pC2) + return NULL; +#endif + + pOut->r = pC1->r - pC2->r; + pOut->g = pC1->g - pC2->g; + pOut->b = pC1->b - pC2->b; + pOut->a = pC1->a - pC2->a; + return pOut; +} + +D3DXINLINE D3DXCOLOR* D3DXColorScale + (__out D3DXCOLOR * pOut, __in CONST D3DXCOLOR *pC, FLOAT s) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pC) + return NULL; +#endif + + pOut->r = pC->r * s; + pOut->g = pC->g * s; + pOut->b = pC->b * s; + pOut->a = pC->a * s; + return pOut; +} + +D3DXINLINE D3DXCOLOR* D3DXColorModulate + (__out D3DXCOLOR * pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pC1 || !pC2) + return NULL; +#endif + + pOut->r = pC1->r * pC2->r; + pOut->g = pC1->g * pC2->g; + pOut->b = pC1->b * pC2->b; + pOut->a = pC1->a * pC2->a; + return pOut; +} + +D3DXINLINE D3DXCOLOR* D3DXColorLerp + (__out D3DXCOLOR * pOut, __in CONST D3DXCOLOR *pC1, __in CONST D3DXCOLOR *pC2, FLOAT s) +{ +#ifdef D3DX_DEBUG + if(!pOut || !pC1 || !pC2) + return NULL; +#endif + +#ifdef _NO_XBOXMATH + + pOut->r = pC1->r + s * (pC2->r - pC1->r); + pOut->g = pC1->g + s * (pC2->g - pC1->g); + pOut->b = pC1->b + s * (pC2->b - pC1->b); + pOut->a = pC1->a + s * (pC2->a - pC1->a); + +#else // !_NO_XBOXMATH + + XMVECTOR C1, C2, Result; + + C1 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pC1); + C2 = D3DX_LoadFloat4((__in CONST XMFLOAT4 *)pC2); + Result = D3DX_VectorLerp(C1, C2, s); + XMStoreFloat4NC((XMFLOAT4*)pOut, Result); + +#endif // !_NO_XBOXMATH + + return pOut; +} + + +#endif // __D3DX9MATH_INL__ diff --git a/third_party/xbox_sdk/include/d3dx9mesh.h b/third_party/xbox_sdk/include/d3dx9mesh.h new file mode 100644 index 0000000..e258bba --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9mesh.h @@ -0,0 +1,2117 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9mesh.h +// Content: D3DX mesh types and functions +// +////////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9MESH_H__ +#define __D3DX9MESH_H__ + +#include "d3d9fftypes.h" +#include "dxfile.h" + +// {4F5621A3-7F25-46dc-8239-820B823795CB} +DEFINE_GUID(IID_ID3DXBaseMesh, +0x4f5621a3, 0x7f25, 0x46dc, 0x82, 0x39, 0x82, 0xb, 0x82, 0x37, 0x95, 0xcb); + +// {29E3EB8D-4DD6-4524-B1A2-1EF0581E778D} +DEFINE_GUID(IID_ID3DXMesh, +0x29e3eb8d, 0x4dd6, 0x4524, 0xb1, 0xa2, 0x1e, 0xf0, 0x58, 0x1e, 0x77, 0x8d); + +// {1da4801f-a26e-4623-bd5471ff57f4bd02} +DEFINE_GUID(IID_ID3DXPMesh, +0x1da4801f, 0xa26e, 0x4623, 0xbd, 0x54, 0x71, 0xff, 0x57, 0xf4, 0xbd, 0x2); + +// {1C4E77C5-8391-4951-A019-D4C5A9539EEC} +DEFINE_GUID(IID_ID3DXSPMesh, +0x1c4e77c5, 0x8391, 0x4951, 0xa0, 0x19, 0xd4, 0xc5, 0xa9, 0x53, 0x9e, 0xec); + +// {0E7DBBF3-421A-4dd8-B738-A5DAC3A48767} +DEFINE_GUID(IID_ID3DXSkinInfo, +0xe7dbbf3, 0x421a, 0x4dd8, 0xb7, 0x38, 0xa5, 0xda, 0xc3, 0xa4, 0x87, 0x67); + +// {0AD3E8BC-290D-4dc7-91AB-73A82755B13E} +DEFINE_GUID(IID_ID3DXPatchMesh, +0xad3e8bc, 0x290d, 0x4dc7, 0x91, 0xab, 0x73, 0xa8, 0x27, 0x55, 0xb1, 0x3e); + +//patch mesh can be quads or tris +typedef enum _D3DXPATCHMESHTYPE { + D3DXPATCHMESH_RECT = 0x001, + D3DXPATCHMESH_TRI = 0x002, + D3DXPATCHMESH_NPATCH = 0x003, + + D3DXPATCHMESH_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ +} D3DXPATCHMESHTYPE; + +// Mesh options - lower 3 bytes only, upper byte used by _D3DXMESHOPT option flags +enum _D3DXMESH { + D3DXMESH_32BIT = 0x001, // If set, then use 32 bit indices, if not set use 16 bit indices. + D3DXMESH_DONOTCLIP = 0x002, // Use D3DUSAGE_DONOTCLIP for VB & IB. + D3DXMESH_POINTS = 0x004, // Use D3DUSAGE_POINTS for VB & IB. + D3DXMESH_RTPATCHES = 0x008, // Use D3DUSAGE_RTPATCHES for VB & IB. + D3DXMESH_NPATCHES = 0x4000,// Use D3DUSAGE_NPATCHES for VB & IB. + D3DXMESH_VB_SYSTEMMEM = 0x010, // Use D3DPOOL_SYSTEMMEM for VB. Overrides D3DXMESH_MANAGEDVERTEXBUFFER + D3DXMESH_VB_MANAGED = 0x020, // Use D3DPOOL_MANAGED for VB. + D3DXMESH_VB_WRITEONLY = 0x040, // Use D3DUSAGE_WRITEONLY for VB. + D3DXMESH_VB_DYNAMIC = 0x080, // Use D3DUSAGE_DYNAMIC for VB. + D3DXMESH_VB_SOFTWAREPROCESSING = 0x8000, // Use D3DUSAGE_SOFTWAREPROCESSING for VB. + D3DXMESH_IB_SYSTEMMEM = 0x100, // Use D3DPOOL_SYSTEMMEM for IB. Overrides D3DXMESH_MANAGEDINDEXBUFFER + D3DXMESH_IB_MANAGED = 0x200, // Use D3DPOOL_MANAGED for IB. + D3DXMESH_IB_WRITEONLY = 0x400, // Use D3DUSAGE_WRITEONLY for IB. + D3DXMESH_IB_DYNAMIC = 0x800, // Use D3DUSAGE_DYNAMIC for IB. + D3DXMESH_IB_SOFTWAREPROCESSING= 0x10000, // Use D3DUSAGE_SOFTWAREPROCESSING for IB. + + D3DXMESH_VB_SHARE = 0x1000, // Valid for Clone* calls only, forces cloned mesh/pmesh to share vertex buffer + + D3DXMESH_USEHWONLY = 0x2000, // Valid for ID3DXSkinInfo::ConvertToBlendedMesh + + // Helper options + D3DXMESH_SYSTEMMEM = 0x110, // D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM + D3DXMESH_MANAGED = 0x220, // D3DXMESH_VB_MANAGED | D3DXMESH_IB_MANAGED + D3DXMESH_WRITEONLY = 0x440, // D3DXMESH_VB_WRITEONLY | D3DXMESH_IB_WRITEONLY + D3DXMESH_DYNAMIC = 0x880, // D3DXMESH_VB_DYNAMIC | D3DXMESH_IB_DYNAMIC + D3DXMESH_SOFTWAREPROCESSING = 0x18000, // D3DXMESH_VB_SOFTWAREPROCESSING | D3DXMESH_IB_SOFTWAREPROCESSING + + // Begin internal + D3DXMESH_VALIDBITS = 0x1cfff, + D3DXMESH_VALIDCLONEBITS = 0x1dfff, + D3DXMESH_VALIDBLENDEDBITS = 0x1efff, + // End internal +}; + +//patch mesh options +enum _D3DXPATCHMESH { + D3DXPATCHMESH_DEFAULT = 000, +}; +// option field values for specifying min value in D3DXGeneratePMesh and D3DXSimplifyMesh +enum _D3DXMESHSIMP +{ + D3DXMESHSIMP_VERTEX = 0x1, + D3DXMESHSIMP_FACE = 0x2, + + // begin internal + D3DXMESHSIMP_VALIDBITS =0x03 + // end internal +}; + +enum _MAX_FVF_DECL_SIZE +{ + MAX_FVF_DECL_SIZE = MAXD3DDECLLENGTH + 1 // +1 for END +}; + +typedef struct ID3DXBaseMesh *LPD3DXBASEMESH; +typedef struct ID3DXMesh *LPD3DXMESH; +typedef struct ID3DXPMesh *LPD3DXPMESH; +typedef struct ID3DXSPMesh *LPD3DXSPMESH; +typedef struct ID3DXSkinInfo *LPD3DXSKININFO; +typedef struct ID3DXPatchMesh *LPD3DXPATCHMESH; + +typedef struct _D3DXATTRIBUTERANGE +{ + DWORD AttribId; + DWORD FaceStart; + DWORD FaceCount; + DWORD VertexStart; + DWORD VertexCount; +} D3DXATTRIBUTERANGE; + +typedef D3DXATTRIBUTERANGE* LPD3DXATTRIBUTERANGE; + +typedef struct _D3DXMATERIAL +{ + D3DMATERIAL9 MatD3D; + LPSTR pTextureFilename; +} D3DXMATERIAL; +typedef D3DXMATERIAL *LPD3DXMATERIAL; + +typedef enum _D3DXEFFECTDEFAULTTYPE +{ + D3DXEDT_STRING = 0x1, // pValue points to a null terminated ASCII string + D3DXEDT_FLOATS = 0x2, // pValue points to an array of floats - number of floats is NumBytes / sizeof(float) + D3DXEDT_DWORD = 0x3, // pValue points to a DWORD + + D3DXEDT_FORCEDWORD = 0x7fffffff +} D3DXEFFECTDEFAULTTYPE; + +typedef struct _D3DXEFFECTDEFAULT +{ + LPSTR pParamName; + D3DXEFFECTDEFAULTTYPE Type; // type of the data pointed to by pValue + DWORD NumBytes; // size in bytes of the data pointed to by pValue + LPVOID pValue; // data for the default of the effect +} D3DXEFFECTDEFAULT, *LPD3DXEFFECTDEFAULT; + +typedef struct _D3DXEFFECTINSTANCE +{ + LPSTR pEffectFilename; + DWORD NumDefaults; + LPD3DXEFFECTDEFAULT pDefaults; +} D3DXEFFECTINSTANCE, *LPD3DXEFFECTINSTANCE; + +typedef struct _D3DXATTRIBUTEWEIGHTS +{ + FLOAT Position; + FLOAT Boundary; + FLOAT Normal; + FLOAT Diffuse; + FLOAT Specular; + FLOAT Texcoord[8]; + FLOAT Tangent; + FLOAT Binormal; +} D3DXATTRIBUTEWEIGHTS, *LPD3DXATTRIBUTEWEIGHTS; + +enum _D3DXWELDEPSILONSFLAGS +{ + D3DXWELDEPSILONS_WELDALL = 0x1, // weld all vertices marked by adjacency as being overlapping + + D3DXWELDEPSILONS_WELDPARTIALMATCHES = 0x2, // if a given vertex component is within epsilon, modify partial matched + // vertices so that both components identical AND if all components "equal" + // remove one of the vertices + D3DXWELDEPSILONS_DONOTREMOVEVERTICES = 0x4, // instructs weld to only allow modifications to vertices and not removal + // ONLY valid if D3DXWELDEPSILONS_WELDPARTIALMATCHES is set + // useful to modify vertices to be equal, but not allow vertices to be removed + + D3DXWELDEPSILONS_DONOTSPLIT = 0x8, // instructs weld to specify the D3DXMESHOPT_DONOTSPLIT flag when doing an Optimize(ATTR_SORT) + // if this flag is not set, all vertices that are in separate attribute groups + // will remain split and not welded. Setting this flag can slow down software vertex processing + + // begin internal + D3DXWELDEPSILONS_VALIDBITS = 0xf, + // end internal +}; + +typedef struct _D3DXWELDEPSILONS +{ + FLOAT Position; // NOTE: This does NOT replace the epsilon in GenerateAdjacency + // in general, it should be the same value or greater than the one passed to GeneratedAdjacency + FLOAT BlendWeights; + FLOAT Normal; + FLOAT PSize; + FLOAT Specular; + FLOAT Diffuse; + FLOAT Texcoord[8]; + FLOAT Tangent; + FLOAT Binormal; + FLOAT TessFactor; +} D3DXWELDEPSILONS; + +typedef D3DXWELDEPSILONS* LPD3DXWELDEPSILONS; + + +#undef INTERFACE +#define INTERFACE ID3DXBaseMesh + +DECLARE_INTERFACE_(ID3DXBaseMesh, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXBaseMesh + STDMETHOD(DrawSubset)(THIS_ DWORD AttribId) PURE; + STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE; + STDMETHOD_(DWORD, GetFVF)(THIS) PURE; + STDMETHOD(GetDeclaration)(THIS_ __out_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + STDMETHOD_(DWORD, GetNumBytesPerVertex)(THIS) PURE; + STDMETHOD_(DWORD, GetOptions)(THIS) PURE; + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, + DWORD FVF, __in LPDIRECT3DDEVICE9 pD3DDevice, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(CloneMesh)(THIS_ DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, __in LPDIRECT3DDEVICE9 pD3DDevice, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(GetVertexBuffer)(THIS_ __deref_out LPDIRECT3DVERTEXBUFFER9* ppVB) PURE; + STDMETHOD(GetIndexBuffer)(THIS_ __deref_out LPDIRECT3DINDEXBUFFER9* ppIB) PURE; + STDMETHOD(LockVertexBuffer)(THIS_ DWORD Flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockVertexBuffer)(THIS) PURE; + STDMETHOD(LockIndexBuffer)(THIS_ DWORD Flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockIndexBuffer)(THIS) PURE; + STDMETHOD(GetAttributeTable)( + THIS_ __out_ecount_opt(*pAttribTableSize) D3DXATTRIBUTERANGE *pAttribTable, __inout DWORD* pAttribTableSize) PURE; + + STDMETHOD(ConvertPointRepsToAdjacency)(THIS_ __in CONST DWORD* pPRep, __out DWORD* pAdjacency) PURE; + STDMETHOD(ConvertAdjacencyToPointReps)(THIS_ __in CONST DWORD* pAdjacency, __out DWORD* pPRep) PURE; + STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Epsilon, __out DWORD* pAdjacency) PURE; + + STDMETHOD(UpdateSemantics)(THIS_ __in_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; +}; + + +#undef INTERFACE +#define INTERFACE ID3DXMesh + +DECLARE_INTERFACE_(ID3DXMesh, ID3DXBaseMesh) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXBaseMesh + STDMETHOD(DrawSubset)(THIS_ DWORD AttribId) PURE; + STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE; + STDMETHOD_(DWORD, GetFVF)(THIS) PURE; + STDMETHOD(GetDeclaration)(THIS_ __out_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + STDMETHOD_(DWORD, GetNumBytesPerVertex)(THIS) PURE; + STDMETHOD_(DWORD, GetOptions)(THIS) PURE; + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, + DWORD FVF, __in LPDIRECT3DDEVICE9 pD3DDevice, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(CloneMesh)(THIS_ DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, __in LPDIRECT3DDEVICE9 pD3DDevice, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(GetVertexBuffer)(THIS_ __deref_out LPDIRECT3DVERTEXBUFFER9* ppVB) PURE; + STDMETHOD(GetIndexBuffer)(THIS_ __deref_out LPDIRECT3DINDEXBUFFER9* ppIB) PURE; + STDMETHOD(LockVertexBuffer)(THIS_ DWORD Flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockVertexBuffer)(THIS) PURE; + STDMETHOD(LockIndexBuffer)(THIS_ DWORD Flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockIndexBuffer)(THIS) PURE; + STDMETHOD(GetAttributeTable)( + THIS_ __out_ecount_opt(*pAttribTableSize) D3DXATTRIBUTERANGE *pAttribTable, __inout DWORD* pAttribTableSize) PURE; + + STDMETHOD(ConvertPointRepsToAdjacency)(THIS_ __in CONST DWORD* pPRep, __out DWORD* pAdjacency) PURE; + STDMETHOD(ConvertAdjacencyToPointReps)(THIS_ __in CONST DWORD* pAdjacency, __out DWORD* pPRep) PURE; + STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Epsilon, __out DWORD* pAdjacency) PURE; + + STDMETHOD(UpdateSemantics)(THIS_ __in_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + + // ID3DXMesh + STDMETHOD(LockAttributeBuffer)(THIS_ DWORD Flags, __deref_out DWORD** ppData) PURE; + STDMETHOD(UnlockAttributeBuffer)(THIS) PURE; + STDMETHOD(Optimize)(THIS_ DWORD Flags, __in_opt CONST DWORD* pAdjacencyIn, __out_opt DWORD* pAdjacencyOut, + __out_opt DWORD* pFaceRemap, __deref_opt_out LPD3DXBUFFER *ppVertexRemap, + __deref_out LPD3DXMESH* ppOptMesh) PURE; + STDMETHOD(OptimizeInplace)(THIS_ DWORD Flags, __in_opt CONST DWORD* pAdjacencyIn, __out_opt DWORD* pAdjacencyOut, + __out_opt DWORD* pFaceRemap, __deref_opt_out LPD3DXBUFFER *ppVertexRemap) PURE; + STDMETHOD(SetAttributeTable)(THIS_ __in_ecount(cAttribTableSize) CONST D3DXATTRIBUTERANGE *pAttribTable, DWORD cAttribTableSize) PURE; +}; + + +#undef INTERFACE +#define INTERFACE ID3DXPMesh + +DECLARE_INTERFACE_(ID3DXPMesh, ID3DXBaseMesh) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXBaseMesh + STDMETHOD(DrawSubset)(THIS_ DWORD AttribId) PURE; + STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE; + STDMETHOD_(DWORD, GetFVF)(THIS) PURE; + STDMETHOD(GetDeclaration)(THIS_ __out_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + STDMETHOD_(DWORD, GetNumBytesPerVertex)(THIS) PURE; + STDMETHOD_(DWORD, GetOptions)(THIS) PURE; + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, + DWORD FVF, __in LPDIRECT3DDEVICE9 pD3DDevice, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(CloneMesh)(THIS_ DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, __in LPDIRECT3DDEVICE9 pD3DDevice, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(GetVertexBuffer)(THIS_ __deref_out LPDIRECT3DVERTEXBUFFER9* ppVB) PURE; + STDMETHOD(GetIndexBuffer)(THIS_ __deref_out LPDIRECT3DINDEXBUFFER9* ppIB) PURE; + STDMETHOD(LockVertexBuffer)(THIS_ DWORD Flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockVertexBuffer)(THIS) PURE; + STDMETHOD(LockIndexBuffer)(THIS_ DWORD Flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockIndexBuffer)(THIS) PURE; + STDMETHOD(GetAttributeTable)( + THIS_ __out_ecount_opt(*pAttribTableSize) D3DXATTRIBUTERANGE *pAttribTable, __inout DWORD* pAttribTableSize) PURE; + + STDMETHOD(ConvertPointRepsToAdjacency)(THIS_ __in CONST DWORD* pPRep, __out DWORD* pAdjacency) PURE; + STDMETHOD(ConvertAdjacencyToPointReps)(THIS_ __in CONST DWORD* pAdjacency, __out DWORD* pPRep) PURE; + STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Epsilon, __out DWORD* pAdjacency) PURE; + + STDMETHOD(UpdateSemantics)(THIS_ __in_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + + // ID3DXPMesh + STDMETHOD(ClonePMeshFVF)(THIS_ DWORD Options, + DWORD FVF, __in LPDIRECT3DDEVICE9 pD3D, __deref_out LPD3DXPMESH* ppCloneMesh) PURE; + STDMETHOD(ClonePMesh)(THIS_ DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, __in LPDIRECT3DDEVICE9 pD3D, __deref_out LPD3DXPMESH* ppCloneMesh) PURE; + STDMETHOD(SetNumFaces)(THIS_ DWORD Faces) PURE; + STDMETHOD(SetNumVertices)(THIS_ DWORD Vertices) PURE; + STDMETHOD_(DWORD, GetMaxFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetMinFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetMaxVertices)(THIS) PURE; + STDMETHOD_(DWORD, GetMinVertices)(THIS) PURE; + STDMETHOD(Save)(THIS_ __in IStream *pStream, __in_ecount_opt(NumMaterials) CONST D3DXMATERIAL* pMaterials, __in_opt CONST D3DXEFFECTINSTANCE* pEffectInstances, DWORD NumMaterials) PURE; + + STDMETHOD(Optimize)(THIS_ DWORD Flags, __out_opt DWORD* pAdjacencyOut, + __out_opt DWORD* pFaceRemap, __deref_opt_out LPD3DXBUFFER *ppVertexRemap, + __deref_out LPD3DXMESH* ppOptMesh) PURE; + + STDMETHOD(OptimizeBaseLOD)(THIS_ DWORD Flags, __out_opt DWORD* pFaceRemap) PURE; + STDMETHOD(TrimByFaces)(THIS_ DWORD NewFacesMin, DWORD NewFacesMax, __out_opt DWORD *rgiFaceRemap, __out_opt DWORD *rgiVertRemap) PURE; + STDMETHOD(TrimByVertices)(THIS_ DWORD NewVerticesMin, DWORD NewVerticesMax, __out_opt DWORD *rgiFaceRemap, __out_opt DWORD *rgiVertRemap) PURE; + + STDMETHOD(GetAdjacency)(THIS_ __out DWORD* pAdjacency) PURE; + + // Used to generate the immediate "ancestor" for each vertex when it is removed by a vsplit. Allows generation of geomorphs + // Vertex buffer must be equal to or greater than the maximum number of vertices in the pmesh + STDMETHOD(GenerateVertexHistory)(THIS_ __out DWORD* pVertexHistory) PURE; +}; + + +#undef INTERFACE +#define INTERFACE ID3DXSPMesh + +DECLARE_INTERFACE_(ID3DXSPMesh, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXSPMesh + STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE; + STDMETHOD_(DWORD, GetFVF)(THIS) PURE; + STDMETHOD(GetDeclaration)(THIS_ __out_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + STDMETHOD_(DWORD, GetOptions)(THIS) PURE; + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, + DWORD FVF, __in LPDIRECT3DDEVICE9 pD3D, __out_opt DWORD *pAdjacencyOut, __out_opt DWORD *pVertexRemapOut, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(CloneMesh)(THIS_ DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, __in LPDIRECT3DDEVICE9 pD3DDevice, __out_opt DWORD *pAdjacencyOut, __out_opt DWORD *pVertexRemapOut, __deref_out LPD3DXMESH* ppCloneMesh) PURE; + STDMETHOD(ClonePMeshFVF)(THIS_ DWORD Options, + DWORD FVF, __in LPDIRECT3DDEVICE9 pD3D, __out_opt DWORD *pVertexRemapOut, __out_opt FLOAT *pErrorsByFace, __deref_out LPD3DXPMESH* ppCloneMesh) PURE; + STDMETHOD(ClonePMesh)(THIS_ DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, __in LPDIRECT3DDEVICE9 pD3D, __out_opt DWORD *pVertexRemapOut, __out_opt FLOAT *pErrorsbyFace, __deref_out LPD3DXPMESH* ppCloneMesh) PURE; + STDMETHOD(ReduceFaces)(THIS_ DWORD Faces) PURE; + STDMETHOD(ReduceVertices)(THIS_ DWORD Vertices) PURE; + STDMETHOD_(DWORD, GetMaxFaces)(THIS) PURE; + STDMETHOD_(DWORD, GetMaxVertices)(THIS) PURE; + STDMETHOD(GetVertexAttributeWeights)(THIS_ __out LPD3DXATTRIBUTEWEIGHTS pVertexAttributeWeights) PURE; + STDMETHOD(GetVertexWeights)(THIS_ __out FLOAT *pVertexWeights) PURE; +}; + +#define UNUSED16 (0xffff) +#define UNUSED32 (0xffffffff) + +// ID3DXMesh::Optimize options - upper byte only, lower 3 bytes used from _D3DXMESH option flags +enum _D3DXMESHOPT { + D3DXMESHOPT_COMPACT = 0x01000000, + D3DXMESHOPT_ATTRSORT = 0x02000000, + D3DXMESHOPT_VERTEXCACHE = 0x04000000, + D3DXMESHOPT_STRIPREORDER = 0x08000000, + D3DXMESHOPT_IGNOREVERTS = 0x10000000, // optimize faces only, don't touch vertices + D3DXMESHOPT_DONOTSPLIT = 0x20000000, // do not split vertices shared between attribute groups when attribute sorting + D3DXMESHOPT_DEVICEINDEPENDENT = 0x00400000, // Only affects VCache. uses a static known good cache size for all cards + + // D3DXMESHOPT_SHAREVB has been removed, please use D3DXMESH_VB_SHARE instead + + // Start of internal data + // NOTE: DEVICEINDEPENDENT is using a bit from the D3DXMESH_* flag space + + D3DXMESHOPT_VALIDBITS = 0x3f401000, + + D3DXMESHOPTINT_ALREADYATTRSORTED = 0x40000000, + D3DXMESHOPTINT_INVERTFACEREMAP = 0x80000000, + D3DXMESHOPTINT_PMESHSAVE = 0x00800000, // NOTE: a bit from the D3DXMESH_* flag space + D3DXMESHOPTINT_VALIDBITS = 0xffc01000, + // end of internal data +}; + +// Subset of the mesh that has the same attribute and bone combination. +// This subset can be rendered in a single draw call +typedef struct _D3DXBONECOMBINATION +{ + DWORD AttribId; + DWORD FaceStart; + DWORD FaceCount; + DWORD VertexStart; + DWORD VertexCount; + DWORD* BoneId; +} D3DXBONECOMBINATION, *LPD3DXBONECOMBINATION; + +// The following types of patch combinations are supported: +// Patch type Basis Degree +// Rect Bezier 2,3,5 +// Rect B-Spline 2,3,5 +// Rect Catmull-Rom 3 +// Tri Bezier 2,3,5 +// N-Patch N/A 3 + +typedef struct _D3DXPATCHINFO +{ + D3DXPATCHMESHTYPE PatchType; + D3DDEGREETYPE Degree; + D3DBASISTYPE Basis; +} D3DXPATCHINFO, *LPD3DXPATCHINFO; + +#undef INTERFACE +#define INTERFACE ID3DXPatchMesh + +DECLARE_INTERFACE_(ID3DXPatchMesh, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXPatchMesh + + // Return creation parameters + STDMETHOD_(DWORD, GetNumPatches)(THIS) PURE; + STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE; + STDMETHOD(GetDeclaration)(THIS_ __out LPD3DVERTEXELEMENT9) PURE; + STDMETHOD_(DWORD, GetControlVerticesPerPatch)(THIS) PURE; + STDMETHOD_(DWORD, GetOptions)(THIS) PURE; + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9 *ppDevice) PURE; + STDMETHOD(GetPatchInfo)(THIS_ __out LPD3DXPATCHINFO PatchInfo) PURE; + + // Control mesh access + STDMETHOD(GetVertexBuffer)(THIS_ __deref_out LPDIRECT3DVERTEXBUFFER9* ppVB) PURE; + STDMETHOD(GetIndexBuffer)(THIS_ __deref_out LPDIRECT3DINDEXBUFFER9* ppIB) PURE; + STDMETHOD(LockVertexBuffer)(THIS_ DWORD flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockVertexBuffer)(THIS) PURE; + STDMETHOD(LockIndexBuffer)(THIS_ DWORD flags, __deref_out LPVOID *ppData) PURE; + STDMETHOD(UnlockIndexBuffer)(THIS) PURE; + STDMETHOD(LockAttributeBuffer)(THIS_ DWORD flags, __deref_out DWORD** ppData) PURE; + STDMETHOD(UnlockAttributeBuffer)(THIS) PURE; + + // This function returns the size of the tessellated mesh given a tessellation level. + // This assumes uniform tessellation. For adaptive tessellation the Adaptive parameter must + // be set to TRUE and TessellationLevel should be the max tessellation. + // This will result in the max mesh size necessary for adaptive tessellation. + STDMETHOD(GetTessSize)(THIS_ FLOAT fTessLevel,DWORD Adapative, __out DWORD *NumTriangles, __out DWORD *NumVertices) PURE; + + //GenerateAdjacency determines which patches are adjacent with provided tolerance + //this information is used internally to optimize tessellation + STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Tolerance) PURE; + + //CloneMesh Creates a new patchmesh with the specified decl, and converts the vertex buffer + //to the new decl. Entries in the new decl which are new are set to 0. If the current mesh + //has adjacency, the new mesh will also have adjacency + STDMETHOD(CloneMesh)(THIS_ DWORD Options, __in_opt CONST D3DVERTEXELEMENT9 *pDecl, __deref_out LPD3DXPATCHMESH *pMesh) PURE; + + // Optimizes the patchmesh for efficient tessellation. This function is designed + // to perform one time optimization for patch meshes that need to be tessellated + // repeatedly by calling the Tessellate() method. The optimization performed is + // independent of the actual tessellation level used. + // Currently Flags is unused. + // If vertices are changed, Optimize must be called again + STDMETHOD(Optimize)(THIS_ DWORD flags) PURE; + + //gets and sets displacement parameters + //displacement maps can only be 2D textures MIP-MAPPING is ignored for non adapative tessellation + STDMETHOD(SetDisplaceParam)(THIS_ __in LPDIRECT3DBASETEXTURE9 Texture, + D3DTEXTUREFILTERTYPE MinFilter, + D3DTEXTUREFILTERTYPE MagFilter, + D3DTEXTUREFILTERTYPE MipFilter, + D3DTEXTUREADDRESS Wrap, + DWORD dwLODBias) PURE; + + STDMETHOD(GetDisplaceParam)(THIS_ __deref_out LPDIRECT3DBASETEXTURE9 *Texture, + __out D3DTEXTUREFILTERTYPE *MinFilter, + __out D3DTEXTUREFILTERTYPE *MagFilter, + __out D3DTEXTUREFILTERTYPE *MipFilter, + __out D3DTEXTUREADDRESS *Wrap, + __out DWORD *dwLODBias) PURE; + + // Performs the uniform tessellation based on the tessellation level. + // This function will perform more efficiently if the patch mesh has been optimized using the Optimize() call. + STDMETHOD(Tessellate)(THIS_ FLOAT fTessLevel, __inout LPD3DXMESH pMesh) PURE; + + // Performs adaptive tessellation based on the Z based adaptive tessellation criterion. + // pTrans specifies a 4D vector that is dotted with the vertices to get the per vertex + // adaptive tessellation amount. Each edge is tessellated to the average of the criterion + // at the 2 vertices it connects. + // MaxTessLevel specifies the upper limit for adaptive tesselation. + // This function will perform more efficiently if the patch mesh has been optimized using the Optimize() call. + STDMETHOD(TessellateAdaptive)(THIS_ + __in CONST D3DXVECTOR4 *pTrans, + DWORD dwMaxTessLevel, + DWORD dwMinTessLevel, + __inout LPD3DXMESH pMesh) PURE; + +}; + +#undef INTERFACE +#define INTERFACE ID3DXSkinInfo + +DECLARE_INTERFACE_(ID3DXSkinInfo, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // Specify the which vertices do each bones influence and by how much + STDMETHOD(SetBoneInfluence)(THIS_ DWORD bone, DWORD numInfluences, __in_ecount(numInfluences) CONST DWORD* vertices, __in_ecount(numInfluences) CONST FLOAT* weights) PURE; + STDMETHOD_(DWORD, GetNumBoneInfluences)(THIS_ DWORD bone) PURE; + STDMETHOD(GetBoneInfluence)(THIS_ DWORD bone, __out DWORD* vertices, __out FLOAT* weights) PURE; + STDMETHOD(GetMaxVertexInfluences)(THIS_ __out DWORD* maxVertexInfluences) PURE; + STDMETHOD_(DWORD, GetNumBones)(THIS) PURE; + + // This gets the max face influences based on a triangle mesh with the specified index buffer + STDMETHOD(GetMaxFaceInfluences)(THIS_ __in LPDIRECT3DINDEXBUFFER9 pIB, DWORD NumFaces, __out DWORD* maxFaceInfluences) PURE; + + // Set min bone influence. Bone influences that are smaller than this are ignored + STDMETHOD(SetMinBoneInfluence)(THIS_ FLOAT MinInfl) PURE; + // Get min bone influence. + STDMETHOD_(FLOAT, GetMinBoneInfluence)(THIS) PURE; + + // Bone names are returned by D3DXLoadSkinMeshFromXof. They are not used by any other method of this object + STDMETHOD(SetBoneName)(THIS_ DWORD Bone, __in_z LPCSTR pName) PURE; // pName is copied to an internal string buffer + STDMETHOD_(__out_z LPCSTR, GetBoneName)(THIS_ DWORD Bone) PURE; // A pointer to an internal string buffer is returned. Do not free this. + + // Bone offset matrices are returned by D3DXLoadSkinMeshFromXof. They are not used by any other method of this object + STDMETHOD(SetBoneOffsetMatrix)(THIS_ DWORD Bone, __in CONST D3DXMATRIX *pBoneTransform) PURE; // pBoneTransform is copied to an internal buffer + STDMETHOD_(__out LPD3DXMATRIX, GetBoneOffsetMatrix)(THIS_ DWORD Bone) PURE; // A pointer to an internal matrix is returned. Do not free this. + + // Clone a skin info object + STDMETHOD(Clone)(THIS_ __deref_out LPD3DXSKININFO* ppSkinInfo) PURE; + + // Update bone influence information to match vertices after they are reordered. This should be called + // if the target vertex buffer has been reordered externally. + STDMETHOD(Remap)(THIS_ DWORD NumVertices, __in_ecount(NumVertices) DWORD* pVertexRemap) PURE; + + // These methods enable the modification of the vertex layout of the vertices that will be skinned + STDMETHOD(SetFVF)(THIS_ DWORD FVF) PURE; + STDMETHOD(SetDeclaration)(THIS_ __in CONST D3DVERTEXELEMENT9 *pDeclaration) PURE; + STDMETHOD_(DWORD, GetFVF)(THIS) PURE; + STDMETHOD(GetDeclaration)(THIS_ __out_ecount(MAX_FVF_DECL_SIZE) D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE; + + // Apply SW skinning based on current pose matrices to the target vertices. + STDMETHOD(UpdateSkinnedMesh)(THIS_ + __in CONST D3DXMATRIX* pBoneTransforms, + __in CONST D3DXMATRIX* pBoneInvTransposeTransforms, + __in LPCVOID pVerticesSrc, + __out PVOID pVerticesDst) PURE; + + // Takes a mesh and returns a new mesh with per vertex blend weights and a bone combination + // table that describes which bones affect which subsets of the mesh + STDMETHOD(ConvertToBlendedMesh)(THIS_ + __in LPD3DXMESH pMesh, + DWORD Options, + __in CONST DWORD *pAdjacencyIn, + __out LPDWORD pAdjacencyOut, + __out_opt DWORD* pFaceRemap, + __deref_opt_out LPD3DXBUFFER *ppVertexRemap, + __out DWORD* pMaxFaceInfl, + __out DWORD* pNumBoneCombinations, + __deref_out LPD3DXBUFFER* ppBoneCombinationTable, + __deref_out LPD3DXMESH* ppMesh) PURE; + + // Takes a mesh and returns a new mesh with per vertex blend weights and indices + // and a bone combination table that describes which bones palettes affect which subsets of the mesh + STDMETHOD(ConvertToIndexedBlendedMesh)(THIS_ + __in LPD3DXMESH pMesh, + DWORD Options, + DWORD paletteSize, + __in CONST DWORD *pAdjacencyIn, + __out LPDWORD pAdjacencyOut, + __out_opt DWORD* pFaceRemap, + __deref_opt_out LPD3DXBUFFER *ppVertexRemap, + __out DWORD* pMaxVertexInfl, + __out DWORD* pNumBoneCombinations, + __deref_out LPD3DXBUFFER* ppBoneCombinationTable, + __deref_out LPD3DXMESH* ppMesh) PURE; +}; + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + + +HRESULT WINAPI + D3DXCreateMesh( + DWORD NumFaces, + DWORD NumVertices, + DWORD Options, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_out LPD3DXMESH* ppMesh); + +HRESULT WINAPI + D3DXCreateMeshFVF( + DWORD NumFaces, + DWORD NumVertices, + DWORD Options, + DWORD FVF, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_out LPD3DXMESH* ppMesh); + +HRESULT WINAPI + D3DXCreateSPMesh( + __in LPD3DXMESH pMesh, + __in CONST DWORD* pAdjacency, + __in_opt CONST D3DXATTRIBUTEWEIGHTS *pVertexAttributeWeights, + __in_opt CONST FLOAT *pVertexWeights, + __deref_out LPD3DXSPMESH* ppSMesh); + +// clean a mesh up for simplification, try to make manifold +HRESULT WINAPI + D3DXCleanMesh( + __in LPD3DXMESH pMeshIn, + __in CONST DWORD* pAdjacencyIn, + __deref_out LPD3DXMESH* ppMeshOut, + __out DWORD* pAdjacencyOut, + __deref_opt_out LPD3DXBUFFER* ppErrorsAndWarnings); + +HRESULT WINAPI + D3DXValidMesh( + __in LPD3DXMESH pMeshIn, + __in CONST DWORD* pAdjacency, + __deref_opt_out LPD3DXBUFFER* ppErrorsAndWarnings); + +HRESULT WINAPI + D3DXGeneratePMesh( + __in LPD3DXMESH pMesh, + __in CONST DWORD* pAdjacency, + __in_opt CONST D3DXATTRIBUTEWEIGHTS *pVertexAttributeWeights, + __in_opt CONST FLOAT *pVertexWeights, + DWORD MinValue, + DWORD Options, + __deref_out LPD3DXPMESH* ppPMesh); + +HRESULT WINAPI + D3DXSimplifyMesh( + __in LPD3DXMESH pMesh, + __in CONST DWORD* pAdjacency, + __in_opt CONST D3DXATTRIBUTEWEIGHTS *pVertexAttributeWeights, + __in_opt CONST FLOAT *pVertexWeights, + DWORD MinValue, + DWORD Options, + __deref_out LPD3DXMESH* ppMesh); + +HRESULT WINAPI + D3DXComputeBoundingSphere( + __in CONST D3DXVECTOR3 *pFirstPosition, // pointer to first position + DWORD NumVertices, + DWORD dwStride, // count in bytes to subsequent position vectors + __out D3DXVECTOR3 *pCenter, + __out FLOAT *pRadius); + +HRESULT WINAPI + D3DXComputeBoundingBox( + __in CONST D3DXVECTOR3 *pFirstPosition, // pointer to first position + DWORD NumVertices, + DWORD dwStride, // count in bytes to subsequent position vectors + __out D3DXVECTOR3 *pMin, + __out D3DXVECTOR3 *pMax); + +HRESULT WINAPI + D3DXComputeNormals( + __inout LPD3DXBASEMESH pMesh, + __in_opt CONST DWORD *pAdjacency); + +HRESULT WINAPI + D3DXCreateBuffer( + DWORD NumBytes, + __deref_out LPD3DXBUFFER *ppBuffer); + + +HRESULT WINAPI + D3DXLoadMeshFromXA( + __in_z LPCSTR pFilename, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_opt_out LPD3DXBUFFER *ppAdjacency, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD *pNumMaterials, + __deref_out LPD3DXMESH *ppMesh); + +HRESULT WINAPI + D3DXLoadMeshFromXW( + __in_z LPCWSTR pFilename, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_opt_out LPD3DXBUFFER *ppAdjacency, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD *pNumMaterials, + __deref_out LPD3DXMESH *ppMesh); + +#ifdef UNICODE +#define D3DXLoadMeshFromX D3DXLoadMeshFromXW +#else +#define D3DXLoadMeshFromX D3DXLoadMeshFromXA +#endif + +HRESULT WINAPI + D3DXLoadMeshFromXInMemory( + __in_bcount(SizeOfMemory) LPCVOID Memory, + DWORD SizeOfMemory, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_opt_out LPD3DXBUFFER *ppAdjacency, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD *pNumMaterials, + __deref_out LPD3DXMESH *ppMesh); + +HRESULT WINAPI + D3DXLoadMeshFromXResource( + __in HMODULE Module, + __in_z LPCSTR Name, + __in_z LPCSTR Type, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_opt_out LPD3DXBUFFER *ppAdjacency, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD *pNumMaterials, + __deref_out LPD3DXMESH *ppMesh); + +HRESULT WINAPI + D3DXSaveMeshToXA( + __in_z LPCSTR pFilename, + __in LPD3DXMESH pMesh, + __in_opt CONST DWORD* pAdjacency, + __in_opt CONST D3DXMATERIAL* pMaterials, + __in_opt CONST D3DXEFFECTINSTANCE* pEffectInstances, + DWORD NumMaterials, + DWORD Format + ); + +HRESULT WINAPI + D3DXSaveMeshToXW( + __in_z LPCWSTR pFilename, + __in LPD3DXMESH pMesh, + __in_opt CONST DWORD* pAdjacency, + __in_opt CONST D3DXMATERIAL* pMaterials, + __in_opt CONST D3DXEFFECTINSTANCE* pEffectInstances, + DWORD NumMaterials, + DWORD Format + ); + +#ifdef UNICODE +#define D3DXSaveMeshToX D3DXSaveMeshToXW +#else +#define D3DXSaveMeshToX D3DXSaveMeshToXA +#endif + + +HRESULT WINAPI + D3DXCreatePMeshFromStream( + __in IStream *pStream, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3DDevice, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD* pNumMaterials, + __deref_out LPD3DXPMESH *ppPMesh); + +// Creates a skin info object based on the number of vertices, number of bones, and a declaration describing the vertex layout of the target vertices +// The bone names and initial bone transforms are not filled in the skin info object by this method. +HRESULT WINAPI + D3DXCreateSkinInfo( + DWORD NumVertices, + __in CONST D3DVERTEXELEMENT9 *pDeclaration, + DWORD NumBones, + __deref_out LPD3DXSKININFO* ppSkinInfo); + +// Creates a skin info object based on the number of vertices, number of bones, and a FVF describing the vertex layout of the target vertices +// The bone names and initial bone transforms are not filled in the skin info object by this method. +HRESULT WINAPI + D3DXCreateSkinInfoFVF( + DWORD NumVertices, + DWORD FVF, + DWORD NumBones, + __deref_out LPD3DXSKININFO* ppSkinInfo); + +#ifdef __cplusplus +} + +extern "C" { +#endif //__cplusplus + +HRESULT WINAPI + D3DXLoadMeshFromXof( + __in LPDIRECTXFILEDATA pXofObjMesh, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3DDevice, + __deref_opt_out LPD3DXBUFFER *ppAdjacency, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD *pNumMaterials, + __deref_out LPD3DXMESH *ppMesh); + +// This similar to D3DXLoadMeshFromXof, except also returns skinning info if present in the file +// If skinning info is not present, ppSkinInfo will be NULL +HRESULT WINAPI + D3DXLoadSkinMeshFromXof( + __in LPDIRECTXFILEDATA pxofobjMesh, + DWORD Options, + __in LPDIRECT3DDEVICE9 pD3D, + __deref_opt_out LPD3DXBUFFER* ppAdjacency, + __deref_opt_out LPD3DXBUFFER* ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt DWORD *pMatOut, + __deref_out LPD3DXSKININFO* ppSkinInfo, + __deref_out LPD3DXMESH* ppMesh); + +// The inverse of D3DXConvertTo{Indexed}BlendedMesh() functions. It figures out the skinning info from +// the mesh and the bone combination table and populates a skin info object with that data. The bone +// names and initial bone transforms are not filled in the skin info object by this method. This works +// with either a non-indexed or indexed blended mesh. It examines the FVF or declarator of the mesh to +// determine what type it is. +HRESULT WINAPI + D3DXCreateSkinInfoFromBlendedMesh( + __in LPD3DXBASEMESH pMesh, + DWORD NumBoneCombinations, + __in_ecount(NumBoneCombinations) CONST D3DXBONECOMBINATION *pBoneCombinationTable, + __deref_out LPD3DXSKININFO* ppSkinInfo); + +HRESULT WINAPI + D3DXTessellateNPatches( + __in LPD3DXMESH pMeshIn, + __in_opt CONST DWORD* pAdjacencyIn, + FLOAT NumSegs, + BOOL QuadraticInterpNormals, // if false use linear intrep for normals, if true use quadratic + __deref_out LPD3DXMESH *ppMeshOut, + __deref_opt_out LPD3DXBUFFER *ppAdjacencyOut); + + +//generates implied outputdecl from input decl +//the decl generated from this should be used to generate the output decl for +//the tessellator subroutines. + +HRESULT WINAPI + D3DXGenerateOutputDecl( + __out D3DVERTEXELEMENT9 *pOutput, + __in CONST D3DVERTEXELEMENT9 *pInput); + +//loads patches from an XFileData +//since an X file can have up to 6 different patch meshes in it, +//returns them in an array - pNumPatches will contain the number of +//meshes in the actual file. +HRESULT WINAPI + D3DXLoadPatchMeshFromXof( + __in LPDIRECTXFILEDATA pXofObjMesh, + DWORD Options, + __in LPDIRECT3DDEVICE9 pDevice, + __deref_opt_out LPD3DXBUFFER *ppMaterials, + __deref_opt_out LPD3DXBUFFER *ppEffectInstances, + __out_opt PDWORD pNumMaterials, + __deref_out LPD3DXPATCHMESH *ppMesh); + +//computes the size a single rect patch. +HRESULT WINAPI + D3DXRectPatchSize( + __in CONST FLOAT *pfNumSegs, //segments for each edge (4) + __out DWORD *pdwTriangles, //output number of triangles + __out DWORD *pdwVertices); //output number of vertices + +//computes the size of a single triangle patch +HRESULT WINAPI + D3DXTriPatchSize( + __in CONST FLOAT *pfNumSegs, //segments for each edge (3) + __out DWORD *pdwTriangles, //output number of triangles + __out DWORD *pdwVertices); //output number of vertices + + +//tessellates a patch into a created mesh +//similar to D3D RT patch +HRESULT WINAPI + D3DXTessellateRectPatch( + __in LPDIRECT3DVERTEXBUFFER9 pVB, + __in CONST FLOAT *pNumSegs, + __in CONST D3DVERTEXELEMENT9 *pdwInDecl, + __in CONST D3DRECTPATCH_INFO *pRectPatchInfo, + __inout LPD3DXMESH pMesh); + + +HRESULT WINAPI + D3DXTessellateTriPatch( + __in LPDIRECT3DVERTEXBUFFER9 pVB, + __in CONST FLOAT *pNumSegs, + __in CONST D3DVERTEXELEMENT9 *pInDecl, + __in CONST D3DTRIPATCH_INFO *pTriPatchInfo, + __inout LPD3DXMESH pMesh); + + + +//creates an NPatch PatchMesh from a D3DXMESH +HRESULT WINAPI + D3DXCreateNPatchMesh( + __in LPD3DXMESH pMeshSysMem, + __deref_out LPD3DXPATCHMESH *ppPatchMesh); + + +//creates a patch mesh +HRESULT WINAPI + D3DXCreatePatchMesh( + __in CONST D3DXPATCHINFO *pInfo, //patch type + DWORD dwNumPatches, //number of patches + DWORD dwNumVertices, //number of control vertices + DWORD dwOptions, //options + __in CONST D3DVERTEXELEMENT9 *pDecl, //format of control vertices + __in LPDIRECT3DDEVICE9 pDevice, + __deref_out LPD3DXPATCHMESH *ppPatchMesh); + + +//returns the number of degenerates in a patch mesh - +//text output put in string. +HRESULT WINAPI + D3DXValidPatchMesh(__in LPD3DXPATCHMESH pMesh, + __out DWORD *dwcDegenerateVertices, + __out DWORD *dwcDegeneratePatches, + __deref_opt_out LPD3DXBUFFER *ppErrorsAndWarnings); + +UINT WINAPI + D3DXGetFVFVertexSize(DWORD FVF); + +UINT WINAPI + D3DXGetDeclVertexSize(__in CONST D3DVERTEXELEMENT9 *pDecl,DWORD Stream); + +UINT WINAPI + D3DXGetDeclLength(__in CONST D3DVERTEXELEMENT9 *pDecl); + +HRESULT WINAPI + D3DXDeclaratorFromFVF( + DWORD FVF, + __out D3DVERTEXELEMENT9 pDeclarator[MAX_FVF_DECL_SIZE]); + +HRESULT WINAPI + D3DXFVFFromDeclarator( + __in CONST D3DVERTEXELEMENT9 *pDeclarator, + __out DWORD *pFVF); + +HRESULT WINAPI + D3DXWeldVertices( + __inout LPD3DXMESH pMesh, + DWORD Flags, + __in_opt CONST D3DXWELDEPSILONS *pEpsilons, + __in_opt CONST DWORD *pAdjacencyIn, + __out_opt DWORD *pAdjacencyOut, + __out_opt DWORD *pFaceRemap, + __deref_opt_out LPD3DXBUFFER *ppVertexRemap); + +typedef struct _D3DXINTERSECTINFO +{ + DWORD FaceIndex; // index of face intersected + FLOAT U; // Barycentric Hit Coordinates + FLOAT V; // Barycentric Hit Coordinates + FLOAT Dist; // Ray-Intersection Parameter Distance +} D3DXINTERSECTINFO, *LPD3DXINTERSECTINFO; + + +HRESULT WINAPI + D3DXIntersect( + __in LPD3DXBASEMESH pMesh, + __in CONST D3DXVECTOR3 *pRayPos, + __in CONST D3DXVECTOR3 *pRayDir, + __out BOOL *pHit, // True if any faces were intersected + __out_opt DWORD *pFaceIndex, // index of closest face intersected + __out_opt FLOAT *pU, // Barycentric Hit Coordinates + __out_opt FLOAT *pV, // Barycentric Hit Coordinates + __out_opt FLOAT *pDist, // Ray-Intersection Parameter Distance + __deref_opt_out LPD3DXBUFFER *ppAllHits, // Array of D3DXINTERSECTINFOs for all hits (not just closest) + __out_opt DWORD *pCountOfHits); // Number of entries in AllHits array + +HRESULT WINAPI + D3DXIntersectSubset( + __in LPD3DXBASEMESH pMesh, + DWORD AttribId, + __in CONST D3DXVECTOR3 *pRayPos, + __in CONST D3DXVECTOR3 *pRayDir, + __out BOOL *pHit, // True if any faces were intersected + __out_opt DWORD *pFaceIndex, // index of closest face intersected + __out_opt FLOAT *pU, // Barycentric Hit Coordinates + __out_opt FLOAT *pV, // Barycentric Hit Coordinates + __out_opt FLOAT *pDist, // Ray-Intersection Parameter Distance + __deref_opt_out LPD3DXBUFFER *ppAllHits, // Array of D3DXINTERSECTINFOs for all hits (not just closest) + __out_opt DWORD *pCountOfHits); // Number of entries in AllHits array + + +HRESULT WINAPI D3DXSplitMesh + ( + __in LPD3DXMESH pMeshIn, + __in_opt CONST DWORD *pAdjacencyIn, + CONST DWORD MaxSize, + CONST DWORD Options, + __out DWORD *pMeshesOut, + __deref_out LPD3DXBUFFER *ppMeshArrayOut, + __deref_opt_out LPD3DXBUFFER *ppAdjacencyArrayOut, + __deref_opt_out LPD3DXBUFFER *ppFaceRemapArrayOut, + __deref_opt_out LPD3DXBUFFER *ppVertRemapArrayOut + ); + +BOOL WINAPI D3DXIntersectTri +( + __in CONST D3DXVECTOR3 *p0, // Triangle vertex 0 position + __in CONST D3DXVECTOR3 *p1, // Triangle vertex 1 position + __in CONST D3DXVECTOR3 *p2, // Triangle vertex 2 position + __in CONST D3DXVECTOR3 *pRayPos, // Ray origin + __in CONST D3DXVECTOR3 *pRayDir, // Ray direction + __out_opt FLOAT *pU, // Barycentric Hit Coordinates + __out_opt FLOAT *pV, // Barycentric Hit Coordinates + __out_opt FLOAT *pDist); // Ray-Intersection Parameter Distance + +BOOL WINAPI + D3DXSphereBoundProbe( + __in CONST D3DXVECTOR3 *pCenter, + FLOAT Radius, + __in CONST D3DXVECTOR3 *pRayPosition, + __in CONST D3DXVECTOR3 *pRayDirection); + +BOOL WINAPI + D3DXBoxBoundProbe( + __in CONST D3DXVECTOR3 *pMin, + __in CONST D3DXVECTOR3 *pMax, + __in CONST D3DXVECTOR3 *pRayPosition, + __in CONST D3DXVECTOR3 *pRayDirection); + + + +//D3DXComputeTangent +// +//Computes the Tangent vectors for the TexStage texture coordinates +//and places the results in the TANGENT[TangentIndex] specified in the meshes' DECL +//puts the binorm in BINORM[BinormIndex] also specified in the decl. +// +//If neither the binorm or the tangnet are in the meshes declaration, +//the function will fail. +// +//If a tangent or Binorm field is in the Decl, but the user does not +//wish D3DXComputeTangent to replace them, then D3DX_DEFAULT specified +//in the TangentIndex or BinormIndex will cause it to ignore the specified +//semantic. +// +//Wrap should be specified if the texture coordinates wrap. + +HRESULT WINAPI D3DXComputeTangent(__in LPD3DXMESH Mesh, + DWORD TexStage, + DWORD TangentIndex, + DWORD BinormIndex, + DWORD Wrap, + __in_opt CONST DWORD *pAdjacency); + +HRESULT WINAPI + D3DXConvertMeshSubsetToSingleStrip( + __in LPD3DXBASEMESH MeshIn, + DWORD AttribId, + DWORD IBOptions, + __deref_out LPDIRECT3DINDEXBUFFER9 *ppIndexBuffer, + __out_opt DWORD *pNumIndices); + +HRESULT WINAPI + D3DXConvertMeshSubsetToStrips( + __in LPD3DXBASEMESH MeshIn, + DWORD AttribId, + DWORD IBOptions, + __deref_out LPDIRECT3DINDEXBUFFER9 *ppIndexBuffer, + __out_opt DWORD *pNumIndices, + __deref_opt_out LPD3DXBUFFER *ppStripLengths, + __out_opt DWORD *pNumStrips); + + +//============================================================================ +// +// D3DXOptimizeFaces: +// -------------------- +// Generate a face remapping for a triangle list that more effectively utilizes +// vertex caches. This optimization is identical to the one provided +// by ID3DXMesh::Optimize with the hardware independent option enabled. +// +// Parameters: +// pbIndices +// Triangle list indices to use for generating a vertex ordering +// NumFaces +// Number of faces in the triangle list +// NumVertices +// Number of vertices referenced by the triangle list +// b32BitIndices +// TRUE if indices are 32 bit, FALSE if indices are 16 bit +// pFaceRemap +// Destination buffer to store face ordering +// The number stored for a given element is where in the new ordering +// the face will have come from. See ID3DXMesh::Optimize for more info. +// +//============================================================================ +HRESULT WINAPI + D3DXOptimizeFaces( + __in LPCVOID pbIndices, + UINT cFaces, + UINT cVertices, + BOOL b32BitIndices, + __out_ecount(cFaces) DWORD* pFaceRemap); + +//============================================================================ +// +// D3DXOptimizeVertices: +// -------------------- +// Generate a vertex remapping to optimize for in order use of vertices for +// a given set of indices. This is commonly used after applying the face +// remap generated by D3DXOptimizeFaces +// +// Parameters: +// pbIndices +// Triangle list indices to use for generating a vertex ordering +// NumFaces +// Number of faces in the triangle list +// NumVertices +// Number of vertices referenced by the triangle list +// b32BitIndices +// TRUE if indices are 32 bit, FALSE if indices are 16 bit +// pVertexRemap +// Destination buffer to store vertex ordering +// The number stored for a given element is where in the new ordering +// the vertex will have come from. See ID3DXMesh::Optimize for more info. +// +//============================================================================ +HRESULT WINAPI + D3DXOptimizeVertices( + __in LPCVOID pbIndices, + UINT cFaces, + UINT cVertices, + BOOL b32BitIndices, + __out_ecount(cVertices) DWORD* pVertexRemap); + +#ifdef __cplusplus +} +#endif //__cplusplus + +//=========================================================================== +// +// Data structures for Spherical Harmonic Precomputation +// +// +//============================================================================ + + +typedef enum _D3DXSHCOMPRESSQUALITYTYPE { + D3DXSHCQUAL_FASTLOWQUALITY = 1, + D3DXSHCQUAL_SLOWHIGHQUALITY = 2, + D3DXSHCQUAL_FORCE_DWORD = 0x7fffffff +} D3DXSHCOMPRESSQUALITYTYPE; + +// for all properties that are colors the red channel is used +// if the simulator is run with bSpectral FALSE + +typedef struct _D3DXSHMATERIAL { + D3DCOLORVALUE Diffuse; // Diffuse albedo of the surface. (Ignored if object is a Mirror) + BOOL bMirror; // Must be set to FALSE. bMirror == TRUE not currently supported + BOOL bSubSurf; // true if the object does subsurface scattering - can't do this and be a mirror + + // subsurface scattering parameters + FLOAT RelativeIndexOfRefraction; + D3DCOLORVALUE Absorption; + D3DCOLORVALUE ReducedScattering; + +} D3DXSHMATERIAL; + +typedef struct _D3DXSHPRTBUFFER_DESC { + UINT NumSamples; // number of texels or vertices sampled + UINT Order; // order of spherical harmonics used + UINT NumChannels; + UINT Width; + UINT Height; +} D3DXSHPRTBUFFER_DESC; + +typedef struct _D3DXSHPRTCOMPBUFFER_DESC { + UINT SampleSize; + UINT NumSamples; // number of texels or vertices sampled + UINT NumClusters; + UINT NumPCA; + UINT Order; // order of spherical harmonics used + UINT NumChannels; +} D3DXSHPRTCOMPBUFFER_DESC; + +// allocated in D3DXSHPRTCompSplitMeshSC +// vertices are duplicated into multiple super clusters but +// only have a valid status in one super cluster (fill in the rest) + +typedef struct _D3DXSHPRTSPLITMESHVERTDATA { + UINT uVertRemap; // vertex in original mesh this corresponds to + UINT uSubCluster; // cluster index relative to super cluster + UCHAR ucVertStatus; // 1 if vertex has valid data, 0 if it is "fill" +} D3DXSHPRTSPLITMESHVERTDATA; + +// used in D3DXSHPRTCompSplitMeshSC +// information for each super cluster that maps into face/vert arrays + +typedef struct _D3DXSHPRTSPLITMESHCLUSTERDATA { + UINT uVertStart; // initial index into remapped vertex array + UINT uVertLength; // number of vertices in this super cluster + + UINT uFaceStart; // initial index into face array + UINT uFaceLength; // number of faces in this super cluster + + UINT uClusterStart; // initial index into cluster array + UINT uClusterLength; // number of clusters in this super cluster +} D3DXSHPRTSPLITMESHCLUSTERDATA; + +// call back function for simulator +// return S_OK to keep running the simulator - anything else represents +// failure and the simulator will abort. + +typedef HRESULT (WINAPI *LPD3DXSHPRTSIMCB)(float fPercentDone); + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +//=========================================================================== +// +// Spherical Harmonic Precomputation Routines +// +// NOTE: +// * These functions are intended for offline use, extraction routines can +// be used at load time, but the simulators and compressor should only be +// used when authoring content. +// +//============================================================================ + +//============================================================================ +// +// D3DXSHPRTSimulation: +// -------------------- +// Runs the PRT simulation on a set of input meshes using a corresponding +// set of materials. This function can take a long time to run and should +// only done offline. +// +// Parameters: +// Order +// Order of SH to use, generates Order^2 coeffs (Degree is Order - 1) +// NumMeshes +// Number of meshes in the scene, where each mesh has a unique material +// ppScene +// Meshes that represent the scene +// ppMaterials +// Materials for each corresponding mesh +// NumRays +// Number of rays to shoot at each vertex +// NumBounces +// Number of bounces simulated - if this is not zero inter-reflections +// are computed +// EnableSubSurf +// Indicates whether or not Subsurface Scattering is to be used +// LengthScale +// Scale used for subsurface scattering (1 would be a 1mm cube) +// EnableSpectral +// TRUE enables color bleeding by computing RGB transfer vectors +// FALSE just uses the red channel for material properties +// ppSimulationResults +// Buffer that is allocated and filled in by the simulator +// pProgressCallback +// Optional function pointer that is called periodically +// Must return S_OK or simulator exits +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTSimulation + ( + UINT Order, + UINT NumMeshes, + __in_ecount(NumMeshes) LPD3DXMESH *ppScene, + __in_ecount(NumMeshes) D3DXSHMATERIAL **ppMaterials, + UINT NumRays, + UINT NumBounces, + BOOL EnableSubSurf, + FLOAT LengthScale, + BOOL EnableSpectral, + __deref_out LPD3DXBUFFER *ppSimulationResults, + __in_opt LPD3DXSHPRTSIMCB pProgressCallback + ); + + +//============================================================================ +// +// D3DXSHPRTExtractChannel: +// ------------------------ +// Pulls the data for a given channel out of pSimulationResults +// +// Parameters: +// Order +// Order of spherical harmonic coefficients to extract +// pTransferCoefficients +// Array of Order^2 floats into which transfer coefficients for the +// specified channel are written +// Channel +// Specifies the channel to extract (0/1/2 for R/G/B) +// pSimulationResults +// Buffer obtained from D3DXSHPRTSimulation +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTExtractChannel + ( + UINT Order, + __out FLOAT *pTransferCoefficients, + UINT Channel, + __in LPD3DXBUFFER pSimulationResults + ); + + +//============================================================================ +// +// D3DXSHPRTGetRawDataPointer: +// --------------------------- +// Given a buffer that has been simulated, makes ppData reference the +// raw data in the buffer. This pointer is invalid after the buffer +// has been released. The data is formatted as follows: +// FLOAT fRawData[NumSamples][NumChannels][Order*Order] +// where NumSamples is the number of texels/vertices in the scene. +// +// Parameters: +// pSimulationResults +// Buffer obtained from the simulator that contains transfer vectors +// ppRawData +// Returns a pointer to the raw data inside the buffer +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTGetRawDataPointer + ( + __in LPD3DXBUFFER pSimulationResults, + __deref_out FLOAT **ppRawData + ); + + +//============================================================================ +// +// D3DXSHPRTExtractDesc: +// --------------------- +// Given the result of a PRT simulation, this function extracts its +// description. +// +// Parameters: +// pSimulationResults +// Buffer obtained from the simulator +// pDesc +// Structure to be filled in with information from the buffer +// Width/Height non-zero only if the textured simulator was used +// +//============================================================================ + + +HRESULT WINAPI + D3DXSHPRTExtractDesc + ( + __in LPD3DXBUFFER pSimulationResults, + __out D3DXSHPRTBUFFER_DESC *pDesc + ); + +//============================================================================ +// +// D3DXSHPRTSimulationTex: +// ----------------------- +// Runs the PRT simulation on an input mesh in texture space. +// Returns a buffer that contains PRT results for every texel. +// This function can take a long time to run and should only done offline. +// +// Parameters: +// Order +// Order of SH to use, generates Order^2 coeffs per channel per texel +// pScene +// Mesh that represents the scene +// pMaterial +// Material which specifies the albedo for the scene (if no albedo +// texture was specified), and the subsurface scattering properties +// NumRays +// Number of rays to shoot at each texel +// NumBounces +// Number of bounces simulated - if this is not zero inter-reflections +// are computed +// EnableSubSurf +// Indicates whether or not subsurface scattering is to be used +// LengthScale +// Scale used for subsurface scattering (1 would be a 1mm cube) +// EnableSpectral +// TRUE enables color bleeding by computing RGB transfer vectors +// FALSE just uses the red channel for material properties +// ppSimulationResults +// Buffer that is allocated and filled in by the simulator +// Width +// Number of texels to sample across horizontally +// Height +// Number of texels to sample across vertically +// pAlbedoTexture +// Albedo (diffuse reflectance) of surface (can be NULL) +// pProgressCallback +// Optional function pointer that is called periodically +// (must return S_OK or simulator exits) +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTSimulationTex + ( + UINT Order, + __in LPD3DXMESH pScene, + __in D3DXSHMATERIAL *pMaterial, + UINT NumRays, + UINT NumBounces, + BOOL EnableSubSurf, + FLOAT LengthScale, + BOOL EnableSpectral, + __deref_out LPD3DXBUFFER *ppSimulationResults, + UINT Width, + UINT Height, + __in_opt LPDIRECT3DTEXTURE9 pAlbedoTexture, + __in_opt LPD3DXSHPRTSIMCB pProgressCallback + ); + +//============================================================================ +// +// D3DXSHPRTExtractTexture: +// ------------------------ +// Pulls the data for a given channel out of pSimulationResults. +// +// Parameters: +// Channel +// Channel to be extracted. +// StartCoefficient +// Initial coefficient to extract +// NumCoefficients +// Number of coefficients to extract +// pSimulationResults +// Buffer obtained from D3DXSHPRTSimulationTex +// pTexture +// Texture where data will be stored - must match dimensions specified +// when simulator was run and be a signed or float format +// +// Example: +// For an order 4 simulation, there are 16 coefficients, which can be +// stored into four 4-channel textures by calling D3DXSPHRTExtractTexture +// 4 times with NumCoefficients set to 4, and StartCoefficient set to +// 0, 4, 8, and 12 in succession. +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTExtractTexture + ( + UINT Channel, + UINT StartCoefficent, + UINT NumCoefficients, + __in LPD3DXBUFFER pSimulationResults, + __in LPDIRECT3DTEXTURE9 pTexture + ); + +//============================================================================ +// +// D3DXSHPRTExtractToMesh: +// ----------------------- +// Pulls transfer coefficients from the buffer containing the simulation +// results and attaches them to the input mesh. +// Can only be called on single channel buffers (use D3DXSHPRTExtractChannel +// otherwise). +// +// Parameters: +// Order +// Order of SH to use, generates Order^2 coeffs, degree is Order-1 +// pScene +// Single mesh that data is going to be packed into +// pSimulationResults +// Buffer obtained from D3DXSHPRTSimulation +// Usage +// D3DDECLUSAGE where coefficients are to be stored +// UsageIndexStart +// Starting index for coefficients to be stored +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTExtractToMesh + ( + UINT Order, + __in LPD3DXMESH pScene, + __in LPD3DXBUFFER pSimulationResults, + D3DDECLUSAGE Usage, + UINT UsageIndexStart + ); + + +//============================================================================ +// +// D3DXSHPRTCompress: +// ------------------ +// This function compresses a PRT buffer, generating a new compressed +// buffer. +// +// Parameters: +// Order +// Order of SH to compress, generates Order^2 coeffs, degree is Order-1 +// pSimulationResults +// Buffer obtained from the simulator that contains transfer vectors. +// Quality +// Type of compression to use +// NumClusters +// Number of clusters to use for compression +// NumPCA +// Number of PCA vectors to use in each cluster +// ppCompressedResults +// Returns the compressed data +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompress + ( + UINT Order, + __in LPD3DXBUFFER pSimulationResults, + D3DXSHCOMPRESSQUALITYTYPE Quality, + UINT NumClusters, + UINT NumPCA, + __deref_out LPD3DXBUFFER *ppCompressedResults + ); + +//============================================================================ +// +// D3DXSHPRTCompExtractToMesh: +// --------------------------- +// Pulls PCA coefficients from compressed buffer and attaches them to the +// mesh. +// +// Parameters: +// NumPCA +// Number of PCA coefficients to extract +// pScene +// Single mesh that data is going to be packed into +// pCompressedResults +// Buffer obtained from D3DXSHPRTCompress +// Usage +// D3DDECLUSAGE where coefficients are to be stored +// UsageIndexStart +// Starting index for coefficients to be stored +// +//============================================================================ + + +HRESULT WINAPI + D3DXSHPRTCompExtractToMesh + ( + UINT NumPCA, + __in LPD3DXMESH pScene, + __in LPD3DXBUFFER pCompressedResults, + D3DDECLUSAGE Usage, + UINT UsageIndexStart + ); + +//============================================================================ +// +// D3DXSHPRTCompExtractDesc: +// ------------------------- +// Given a compressed buffer, extracts a description of the data. +// +// Parameters: +// pCompressedResults +// Buffer obtained D3DXSHPRTCompress +// pDesc +// Structure to be filled in with information from the buffer +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompExtractDesc + ( + __in LPD3DXBUFFER pCompressedResults, + __out D3DXSHPRTCOMPBUFFER_DESC *pDesc + ); + +//============================================================================ +// +// D3DXSHPRTCompNormalizeData: +// --------------------------- +// Given a compressed buffer, rescales all of the PCA projection coefficients +// so that they are within [-1, 1]. The PCA vectors are scaled so that +// reconstruction is still correct. This maximizes precision when packing +// into textures. +// +// Parameters: +// pCompressedResults +// Buffer obtained from D3DXSHPRTCompress +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompNormalizeData + ( + __inout LPD3DXBUFFER pCompressedResults + ); + +//============================================================================ +// +// D3DXSHPRTCompExtractBasis: +// -------------------------- +// Extracts the mean + PCA basis vectors for a given cluster from a +// compressed buffer. The data is laid out in memory: +// FLOAT fData[NumSamples][NumChannels][Order*Order] +// Where NumSamples/NumChannels/Order are from the D3DXSHPRTCOMPBUFFER_DESC +// that can be extracted from pBuffer. +// +// Parameters: +// Cluster +// Cluster whose basis is going to be extracted +// pCompressedResults +// Buffer obtained from D3DXSHPRTCompress +// pClusterBasis +// Array of floats into which cluster basis is written +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompExtractBasis + ( + UINT Cluster, + __in LPD3DXBUFFER pCompressedResults, + __out FLOAT *pClusterBasis + ); + +//============================================================================ +// +// D3DXSHPRTCompExtractClusterIDs: +// ------------------------------- +// Extracts the per sample cluster ID from a compressed data set. +// +// Parameters: +// pCompressedResults +// Buffer obtained from D3DXSHPRTCompress +// pClusterIDs +// Pointer where D3DXSHPRTCOMPBUFFER_DESC::NumSamples IDs are written +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompExtractClusterIDs + ( + __in LPD3DXBUFFER pCompressedResults, + __out UINT *pClusterIDs + ); + +//============================================================================ +// +// D3DXSHPRTCompExtractPCA: +// ------------------------ +// Extracts the per-sample PCA coefficients from a compressed buffer. +// +// Parameters: +// StartPCA +// Starting PCA projection coefficient to extract +// NumExtract +// Number of PCA projection coefficients to extract +// pCompressedResults +// Buffer obtained from D3DXSHPRTCompress +// pPCACoefficients +// Pointer where NumSamples * NumPCA PCA coefficients are written +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompExtractPCA + ( + UINT StartPCA, + UINT NumExtract, + __in LPD3DXBUFFER pCompressedResults, + __out FLOAT *pPCACoefficients + ); + +//============================================================================ +// +// D3DXSHPRTCompExtractTexture: +// ---------------------------- +// Extracts the per sample PCA coefficients from a compressed data set. They +// are extracted into a texture that has already been allocated. +// +// Parameters: +// StartPCA +// Starting PCA projection coefficient to extract +// NumExtract +// Number of PCA projection coefficients to extract +// pCompressedResults +// Buffer obtained from D3DXSHPRTCompress +// pTexture +// Texture where data is stored - must match dimensions of simulator +// and be a signed or floating point format +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompExtractTexture + ( + UINT StartPCA, + UINT NumExtract, + __in LPD3DXBUFFER pCompressedResults, + __inout LPDIRECT3DTEXTURE9 pTexture + ); + +//============================================================================ +// +// D3DXSHPRTCompSuperCluster: +// -------------------------- +// Used with compressed results of D3DXSHPRTSimulation. +// Generates "super clusters" - groups of clusters that can be drawn in +// the same draw call. A greedy algorithm that minimizes overdraw is used +// to group the clusters. +// +// Parameters: +// pClusterIDs +// NumVerts cluster ID's (extracted from a compressed buffer) +// pScene +// Mesh that represents composite scene passed to the simulator +// MaxNumClusters +// Maximum number of clusters allocated per super cluster +// NumClusters +// Number of clusters computed in the simulator +// pSuperClusterIDs +// Array of length NumClusters, contains index of super cluster +// that corresponding cluster was assigned to +// pNumSuperClusters +// Returns the number of super clusters allocated +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompSuperCluster + ( + __in UINT *pClusterIDs, + __in LPD3DXMESH pScene, + UINT MaxNumClusters, + UINT NumClusters, + __out_ecount(NumClusters) UINT *pSuperClusterIDs, + __out UINT *pNumSuperClusters + ); + +//============================================================================ +// +// D3DXSHPRTCompSplitMeshSC: +// ------------------------- +// Used with compressed results of the vertex version of the PRT simulator. +// After D3DXSHRTCompSuperCluster has been called this function can be used +// to split the mesh into a group of faces/vertices per super cluster. +// Each super cluster contains all of the faces that contain any vertex +// classified in one of its clusters. All of the vertices connected to this +// set of faces are also included with the returned array ppVertStatus +// indicating whether or not the vertex belongs to the supercluster. +// +// Parameters: +// pClusterIDs +// NumVerts cluster ID's (extracted from a compressed buffer) +// NumVertices +// Number of vertices in original mesh +// NumClusters +// Number of clusters (input parameter to compression) +// pSuperClusterIDs +// Array of size NumClusters that will contain super cluster ID's (from +// D3DXSHCompSuerCluster) +// NumSuperClusters +// Number of superclusters allocated in D3DXSHCompSuerCluster +// pInputIB +// Raw index buffer for mesh - format depends on bInputIBIs32Bit +// InputIBIs32Bit +// Indicates whether the input index buffer is 32-bit (otherwise 16-bit +// is assumed) +// NumFaces +// Number of faces in the original mesh (pInputIB is 3 times this length) +// ppIBData +// Raw index buffer that will contain the resulting split faces. Format +// determined by bIBIs32Bit. Allocated by function +// pIBDataLength +// Length of ppIBData, assigned in function +// OutputIBIs32Bit +// Indicates whether the output index buffer is to be 32-bit (otherwise +// 16-bit is assumed) +// ppFaceRemap +// Mapping of each face in ppIBData to original faces. Length is +// *pIBDataLength/3. Allocated in function +// ppVertData +// New vertex data structure. Size of pVertDataLength +// pVertDataLength +// Number of new vertices in split mesh. Assigned in function +// pSCClusterList +// Array of length NumClusters which pSCData indexes into (Cluster* fields) +// for each SC, contains clusters sorted by super cluster +// pSCData +// Structure per super cluster - contains indices into ppIBData, +// pSCClusterList and ppVertData +// +//============================================================================ + +HRESULT WINAPI + D3DXSHPRTCompSplitMeshSC + ( + __in UINT *pClusterIDs, + UINT NumVertices, + UINT NumClusters, + __out_ecount(NumClusters) UINT *pSuperClusterIDs, + UINT NumSuperClusters, + __in LPVOID pInputIB, + BOOL InputIBIs32Bit, + UINT NumFaces, + __deref_out LPVOID *ppIBData, + __out UINT *pIBDataLength, + BOOL OutputIBIs32Bit, + __deref_out UINT **ppFaceRemap, + __deref_out D3DXSHPRTSPLITMESHVERTDATA **ppVertData, + __out UINT *pVertDataLength, + __out UINT *pSCClusterList, + __out D3DXSHPRTSPLITMESHCLUSTERDATA *pSCData + ); + +#ifdef __cplusplus +} +#endif //__cplusplus + + +////////////////////////////////////////////////////////////////////////////// +// +// Definitions of .X file templates used by mesh load/save functions +// that are not RM standard +// +////////////////////////////////////////////////////////////////////////////// + +// {3CF169CE-FF7C-44ab-93C0-F78F62D172E2} +DEFINE_GUID(DXFILEOBJ_XSkinMeshHeader, +0x3cf169ce, 0xff7c, 0x44ab, 0x93, 0xc0, 0xf7, 0x8f, 0x62, 0xd1, 0x72, 0xe2); + +// {B8D65549-D7C9-4995-89CF-53A9A8B031E3} +DEFINE_GUID(DXFILEOBJ_VertexDuplicationIndices, +0xb8d65549, 0xd7c9, 0x4995, 0x89, 0xcf, 0x53, 0xa9, 0xa8, 0xb0, 0x31, 0xe3); + +// {A64C844A-E282-4756-8B80-250CDE04398C} +DEFINE_GUID(DXFILEOBJ_FaceAdjacency, +0xa64c844a, 0xe282, 0x4756, 0x8b, 0x80, 0x25, 0xc, 0xde, 0x4, 0x39, 0x8c); + +// {6F0D123B-BAD2-4167-A0D0-80224F25FABB} +DEFINE_GUID(DXFILEOBJ_SkinWeights, +0x6f0d123b, 0xbad2, 0x4167, 0xa0, 0xd0, 0x80, 0x22, 0x4f, 0x25, 0xfa, 0xbb); + +// {A3EB5D44-FC22-429d-9AFB-3221CB9719A6} +DEFINE_GUID(DXFILEOBJ_Patch, +0xa3eb5d44, 0xfc22, 0x429d, 0x9a, 0xfb, 0x32, 0x21, 0xcb, 0x97, 0x19, 0xa6); + +// {D02C95CC-EDBA-4305-9B5D-1820D7704BBF} +DEFINE_GUID(DXFILEOBJ_PatchMesh, +0xd02c95cc, 0xedba, 0x4305, 0x9b, 0x5d, 0x18, 0x20, 0xd7, 0x70, 0x4b, 0xbf); + +// {B9EC94E1-B9A6-4251-BA18-94893F02C0EA} +DEFINE_GUID(DXFILEOBJ_PatchMesh9, +0xb9ec94e1, 0xb9a6, 0x4251, 0xba, 0x18, 0x94, 0x89, 0x3f, 0x2, 0xc0, 0xea); + +// {B6C3E656-EC8B-4b92-9B62-681659522947} +DEFINE_GUID(DXFILEOBJ_PMInfo, +0xb6c3e656, 0xec8b, 0x4b92, 0x9b, 0x62, 0x68, 0x16, 0x59, 0x52, 0x29, 0x47); + +// {917E0427-C61E-4a14-9C64-AFE65F9E9844} +DEFINE_GUID(DXFILEOBJ_PMAttributeRange, +0x917e0427, 0xc61e, 0x4a14, 0x9c, 0x64, 0xaf, 0xe6, 0x5f, 0x9e, 0x98, 0x44); + +// {574CCC14-F0B3-4333-822D-93E8A8A08E4C} +DEFINE_GUID(DXFILEOBJ_PMVSplitRecord, +0x574ccc14, 0xf0b3, 0x4333, 0x82, 0x2d, 0x93, 0xe8, 0xa8, 0xa0, 0x8e, 0x4c); + +// {B6E70A0E-8EF9-4e83-94AD-ECC8B0C04897} +DEFINE_GUID(DXFILEOBJ_FVFData, +0xb6e70a0e, 0x8ef9, 0x4e83, 0x94, 0xad, 0xec, 0xc8, 0xb0, 0xc0, 0x48, 0x97); + +// {F752461C-1E23-48f6-B9F8-8350850F336F} +DEFINE_GUID(DXFILEOBJ_VertexElement, +0xf752461c, 0x1e23, 0x48f6, 0xb9, 0xf8, 0x83, 0x50, 0x85, 0xf, 0x33, 0x6f); + +// {BF22E553-292C-4781-9FEA-62BD554BDD93} +DEFINE_GUID(DXFILEOBJ_DeclData, +0xbf22e553, 0x292c, 0x4781, 0x9f, 0xea, 0x62, 0xbd, 0x55, 0x4b, 0xdd, 0x93); + +// {F1CFE2B3-0DE3-4e28-AFA1-155A750A282D} +DEFINE_GUID(DXFILEOBJ_EffectFloats, +0xf1cfe2b3, 0xde3, 0x4e28, 0xaf, 0xa1, 0x15, 0x5a, 0x75, 0xa, 0x28, 0x2d); + +// {D55B097E-BDB6-4c52-B03D-6051C89D0E42} +DEFINE_GUID(DXFILEOBJ_EffectString, +0xd55b097e, 0xbdb6, 0x4c52, 0xb0, 0x3d, 0x60, 0x51, 0xc8, 0x9d, 0xe, 0x42); + +// {622C0ED0-956E-4da9-908A-2AF94F3CE716} +DEFINE_GUID(DXFILEOBJ_EffectDWord, +0x622c0ed0, 0x956e, 0x4da9, 0x90, 0x8a, 0x2a, 0xf9, 0x4f, 0x3c, 0xe7, 0x16); + +// {3014B9A0-62F5-478c-9B86-E4AC9F4E418B} +DEFINE_GUID(DXFILEOBJ_EffectParamFloats, +0x3014b9a0, 0x62f5, 0x478c, 0x9b, 0x86, 0xe4, 0xac, 0x9f, 0x4e, 0x41, 0x8b); + +// {1DBC4C88-94C1-46ee-9076-2C28818C9481} +DEFINE_GUID(DXFILEOBJ_EffectParamString, +0x1dbc4c88, 0x94c1, 0x46ee, 0x90, 0x76, 0x2c, 0x28, 0x81, 0x8c, 0x94, 0x81); + +// {E13963BC-AE51-4c5d-B00F-CFA3A9D97CE5} +DEFINE_GUID(DXFILEOBJ_EffectParamDWord, +0xe13963bc, 0xae51, 0x4c5d, 0xb0, 0xf, 0xcf, 0xa3, 0xa9, 0xd9, 0x7c, 0xe5); + +// {E331F7E4-0559-4cc2-8E99-1CEC1657928F} +DEFINE_GUID(DXFILEOBJ_EffectInstance, +0xe331f7e4, 0x559, 0x4cc2, 0x8e, 0x99, 0x1c, 0xec, 0x16, 0x57, 0x92, 0x8f); + +// {9E415A43-7BA6-4a73-8743-B73D47E88476} +DEFINE_GUID(DXFILEOBJ_AnimTicksPerSecond, +0x9e415a43, 0x7ba6, 0x4a73, 0x87, 0x43, 0xb7, 0x3d, 0x47, 0xe8, 0x84, 0x76); + +#define XSKINEXP_TEMPLATES \ + "xof 0303txt 0032\ + template XSkinMeshHeader \ + { \ + <3CF169CE-FF7C-44ab-93C0-F78F62D172E2> \ + WORD nMaxSkinWeightsPerVertex; \ + WORD nMaxSkinWeightsPerFace; \ + WORD nBones; \ + } \ + template VertexDuplicationIndices \ + { \ + \ + DWORD nIndices; \ + DWORD nOriginalVertices; \ + array DWORD indices[nIndices]; \ + } \ + template FaceAdjacency \ + { \ + \ + DWORD nIndices; \ + array DWORD indices[nIndices]; \ + } \ + template SkinWeights \ + { \ + <6F0D123B-BAD2-4167-A0D0-80224F25FABB> \ + STRING transformNodeName; \ + DWORD nWeights; \ + array DWORD vertexIndices[nWeights]; \ + array float weights[nWeights]; \ + Matrix4x4 matrixOffset; \ + } \ + template Patch \ + { \ + \ + DWORD nControlIndices; \ + array DWORD controlIndices[nControlIndices]; \ + } \ + template PatchMesh \ + { \ + \ + DWORD nVertices; \ + array Vector vertices[nVertices]; \ + DWORD nPatches; \ + array Patch patches[nPatches]; \ + [ ... ] \ + } \ + template PatchMesh9 \ + { \ + \ + DWORD Type; \ + DWORD Degree; \ + DWORD Basis; \ + DWORD nVertices; \ + array Vector vertices[nVertices]; \ + DWORD nPatches; \ + array Patch patches[nPatches]; \ + [ ... ] \ + } " \ + "template EffectFloats \ + { \ + \ + DWORD nFloats; \ + array float Floats[nFloats]; \ + } \ + template EffectString \ + { \ + \ + STRING Value; \ + } \ + template EffectDWord \ + { \ + <622C0ED0-956E-4da9-908A-2AF94F3CE716> \ + DWORD Value; \ + } " \ + "template EffectParamFloats \ + { \ + <3014B9A0-62F5-478c-9B86-E4AC9F4E418B> \ + STRING ParamName; \ + DWORD nFloats; \ + array float Floats[nFloats]; \ + } " \ + "template EffectParamString \ + { \ + <1DBC4C88-94C1-46ee-9076-2C28818C9481> \ + STRING ParamName; \ + STRING Value; \ + } \ + template EffectParamDWord \ + { \ + \ + STRING ParamName; \ + DWORD Value; \ + } \ + template EffectInstance \ + { \ + \ + STRING EffectFilename; \ + [ ... ] \ + } " \ + "template AnimTicksPerSecond \ + { \ + <9E415A43-7BA6-4a73-8743-B73D47E88476> \ + DWORD AnimTicksPerSecond; \ + } " + +#define XEXTENSIONS_TEMPLATES \ + "xof 0303txt 0032\ + template FVFData \ + { \ + \ + DWORD dwFVF; \ + DWORD nDWords; \ + array DWORD data[nDWords]; \ + } \ + template VertexElement \ + { \ + \ + DWORD Type; \ + DWORD Method; \ + DWORD Usage; \ + DWORD UsageIndex; \ + } \ + template DeclData \ + { \ + \ + DWORD nElements; \ + array VertexElement Elements[nElements]; \ + DWORD nDWords; \ + array DWORD data[nDWords]; \ + } \ + template PMAttributeRange \ + { \ + <917E0427-C61E-4a14-9C64-AFE65F9E9844> \ + DWORD iFaceOffset; \ + DWORD nFacesMin; \ + DWORD nFacesMax; \ + DWORD iVertexOffset; \ + DWORD nVerticesMin; \ + DWORD nVerticesMax; \ + } \ + template PMVSplitRecord \ + { \ + <574CCC14-F0B3-4333-822D-93E8A8A08E4C> \ + DWORD iFaceCLW; \ + DWORD iVlrOffset; \ + DWORD iCode; \ + } \ + template PMInfo \ + { \ + \ + DWORD nAttributes; \ + array PMAttributeRange attributeRanges[nAttributes]; \ + DWORD nMaxValence; \ + DWORD nMinLogicalVertices; \ + DWORD nMaxLogicalVertices; \ + DWORD nVSplits; \ + array PMVSplitRecord splitRecords[nVSplits]; \ + DWORD nAttributeMispredicts; \ + array DWORD attributeMispredicts[nAttributeMispredicts]; \ + } " + +#endif //__D3DX9MESH_H__ + + diff --git a/third_party/xbox_sdk/include/d3dx9shader.h b/third_party/xbox_sdk/include/d3dx9shader.h new file mode 100644 index 0000000..440986c --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9shader.h @@ -0,0 +1,1475 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// File: d3dx9shader.h +// Content: D3DX Shader APIs +// +////////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9SHADER_H__ +#define __D3DX9SHADER_H__ + + +//--------------------------------------------------------------------------- +// D3DXTX_VERSION: +// -------------- +// Version token used to create a procedural texture filler in effects +// Used by D3DXFill[]TX functions +//--------------------------------------------------------------------------- +#define D3DXTX_VERSION(_Major,_Minor) (('T' << 24) | ('X' << 16) | ((_Major) << 8) | (_Minor)) + + +// begin_internal +//---------------------------------------------------------------------------- +// D3DXFXL_VERSION: +// ---------------- +// Version token used by host expression evaluator. +//---------------------------------------------------------------------------- + +#define D3DXFXL_VERSION(_Major,_Minor) (('F' << 24) | ('X' << 16) | ((_Major) << 8) | (_Minor)) // internal +// end_internal + + +//---------------------------------------------------------------------------- +// D3DXSHADER/EX flags: +// ----------------- +// D3DXSHADER_DEBUG +// Insert debug file/line/type/symbol information. +// +// D3DXSHADER_SKIPVALIDATION +// Do not validate the generated code against known capabilities and +// constraints. This option is only recommended when compiling shaders +// you KNOW will work. (ie. have compiled before without this option.) +// Shaders are always validated by D3D before they are set to the device. +// +// D3DXSHADER_SKIPOPTIMIZATION (valid for D3DXCompileShader calls only) +// Instructs the compiler to skip optimization steps during code generation. +// Unless you are trying to isolate a problem in your code, and suspect the +// compiler, using this option is not recommended. +// +// D3DXSHADER_PACKMATRIX_ROWMAJOR +// Unless explicitly specified, matrices will be packed in row-major order +// on input and output from the shader. +// +// D3DXSHADER_PACKMATRIX_COLUMNMAJOR +// Unless explicitly specified, matrices will be packed in column-major +// order on input and output from the shader. This is generally more +// efficient, since it allows vector-matrix multiplication to be performed +// using a series of dot-products. +// +// D3DXSHADER_PARTIAL_PRECISION +// Force all computations in resulting shader to occur at partial precision. +// This may result in faster evaluation of shaders on some hardware. +// +// D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT +// Force compiler to compile against the next highest available software +// target for vertex shaders. This flag also turns optimizations off, +// and debugging on. +// +// D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT +// Force compiler to compile against the next highest available software +// target for pixel shaders. This flag also turns optimizations off, +// and debugging on. +// +// D3DXSHADER_NO_PRESHADER +// Disables Preshaders. Using this flag will cause the compiler to not +// pull out static expression for evaluation on the host cpu +// +// D3DXSHADER_AVOID_FLOW_CONTROL +// Hint compiler to avoid flow-control constructs where possible. +// +// D3DXSHADER_PREFER_FLOW_CONTROL +// Hint compiler to prefer flow-control constructs where possible. +// +// D3D10_SHADER_ENABLE_STRICTNESS +// By default, the HLSL/Effect compilers are not strict on deprecated syntax. +// Specifying this flag enables the strict mode. Deprecated syntax may be +// removed in a future release, and enabling syntax is a good way to make sure +// your shaders comply to the latest spec. +// +// D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY +// This enables older shaders to compile to 4_0 targets. + +// begin internal +// +// D3DXSHADER_FRAGMENT +// Indicates that you are compiling code as a fragment, to be linked +// together at a later time. This flag implies D3DXSHADER_SKIPVALIDATION. +// +// D3DXSHADER_SKIPASMBLOCKS +// Indicates that the parser should skip over ASM blocks without invoking +// the assembler. This flag is implied by D3DXCompileShader APIs. +// end internal +//---------------------------------------------------------------------------- + +#define D3DXSHADER_DEBUG (1 << 0) +#define D3DXSHADER_SKIPVALIDATION (1 << 1) +#define D3DXSHADER_SKIPOPTIMIZATION (1 << 2) +#define D3DXSHADER_PACKMATRIX_ROWMAJOR (1 << 3) +#define D3DXSHADER_PACKMATRIX_COLUMNMAJOR (1 << 4) +#define D3DXSHADER_PARTIALPRECISION (1 << 5) +#define D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT (1 << 6) +#define D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT (1 << 7) +#define D3DXSHADER_NO_PRESHADER (1 << 8) +#define D3DXSHADER_AVOID_FLOW_CONTROL (1 << 9) +#define D3DXSHADER_PREFER_FLOW_CONTROL (1 << 10) +#define D3D10_SHADER_ENABLE_STRICTNESS (1 << 11) +#define D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY (1 << 12) +#define D3DXSHADER_SKIPMICROCODEOPTIMIZATION_DEPRECATED (1 << 17) // Xbox extension +#define D3DXSHADER_ZERO_INIT_LOCAL_VARS (1 << 18) // Xbox extension +#define D3DXSHADER_DISABLE_ZPASS_COMPARISON_VALIDATION (1 << 19) //Xbox extension +#define D3DXSHADER_SKIPMICROCODE_DEPRECATED (1 << 20) // Xbox extension +#define D3DXSHADER_ENABLEVERIFIER (1 << 22) // Xbox extension +#define D3DXSHADER_MICROCODE_BACKEND_NEW (1 << 24) // Xbox extension +#define D3DXSHADER_MICROCODE_BACKEND_OLD_DEPRECATED (1 << 25) // Xbox extension +// from fxl.h +//#define D3DXSHADER_FXLANNOTATE_VARIABLE_NAMES (1 << 26) +//#define D3DXSHADER_FXLANNOTATE_SEMANTIC_NAMES (1 << 27) +//#define D3DXSHADER_FXLPARAMETERS_AS_VARIABLE_NAMES (1 << 28) +//#define D3DXSHADER_FXLEFFECT_NATIVE_ENDIAN (1 << 29) +#define D3DXSHADER_FRAGMENT (1 << 30) // internal +#define D3DXSHADER_SKIPASMBLOCKS (1 << 31) // internal + + +// begin internal +#define D3DXSHADER_VALID_ASSEMBLER_FLAGS \ + ( D3DXSHADER_DEBUG | \ + D3DXSHADER_SKIPVALIDATION | \ + D3DXSHADER_SKIPMICROCODE_DEPRECATED | \ + D3DXSHADER_SKIPMICROCODEOPTIMIZATION_DEPRECATED | \ + D3DXSHADER_DISABLE_ZPASS_COMPARISON_VALIDATION) + +#define D3DXSHADER_VALID_COMPILER_FLAGS \ + ( D3DXSHADER_DEBUG | \ + D3DXSHADER_SKIPVALIDATION | \ + D3DXSHADER_SKIPOPTIMIZATION | \ + D3DXSHADER_PACKMATRIX_ROWMAJOR | \ + D3DXSHADER_PACKMATRIX_COLUMNMAJOR | \ + D3DXSHADER_PARTIALPRECISION | \ + D3DXSHADER_AVOID_FLOW_CONTROL | \ + D3DXSHADER_PREFER_FLOW_CONTROL | \ + D3D10_SHADER_ENABLE_STRICTNESS | \ + D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY | \ + D3DXSHADER_SKIPMICROCODE_DEPRECATED | \ + D3DXSHADER_SKIPMICROCODEOPTIMIZATION_DEPRECATED | \ + D3DXSHADER_ZERO_INIT_LOCAL_VARS | \ + D3DXSHADER_MICROCODE_BACKEND_OLD_DEPRECATED | \ + D3DXSHADER_MICROCODE_BACKEND_NEW | \ + D3DXSHADER_ENABLEVERIFIER | \ + D3DXSHADER_DISABLE_ZPASS_COMPARISON_VALIDATION) + +#define D3DXSHADER_VALID \ + ( D3DXSHADER_VALID_ASSEMBLER_FLAGS | \ + D3DXSHADER_VALID_COMPILER_FLAGS | \ + D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT | \ + D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT ) + +#define D3DXSHADEREX_CPUCODE_NO_INTRINSICS (1 << 0) // Xbox extension +#define D3DXSHADEREX_GENERATE_UPDB (1 << 1) // Xbox extension +#define D3DXSHADEREX_OPTIMIZE_UCODE (1 << 2) // Xbox extension +#define D3DXSHADEREX_NO_MASKED_EXPORTS (1 << 3) // Xbox extension +#define D3DXSHADEREX_DEBUGGABLE_UCODE (1 << 4) // Xbox extension +#define D3DXSHADEREX_AUTOZ (1 << 5) // Xbox extension +#define D3DXSHADEREX_REMOVE_UNUSED_PS_INPUTS (1 << 6) // Xbox extension +#define D3DXSHADEREX_AUTO_VFETCHE (1 << 7) // Xbox extension +#define D3DXSHADEREX_ENABLE_ASSERTIONS (1 << 8) // Xbox extension +#define D3DXSHADEREX_ISOLATE_ASSERTIONS (1 << 9) // Xbox extension +#define D3DXSHADEREX_ENABLE_ASSERTIONS_FOR_PIX (1 << 10) // Xbox extension +#define D3DXSHADEREX_ENABLE_DBGPRINT_FOR_PIX (1 << 11)// Xbox extension +#define D3DXSHADEREX_ENABLE_DBGPRINT_FOR_PIX_DEBUGGER (1 << 12)// Xbox extension + +#define D3DXSHADEREX_VALID_COMPILER_FLAGS \ + ( D3DXSHADEREX_CPUCODE_NO_INTRINSICS | \ + D3DXSHADEREX_GENERATE_UPDB | \ + D3DXSHADEREX_OPTIMIZE_UCODE | \ + D3DXSHADEREX_NO_MASKED_EXPORTS | \ + D3DXSHADEREX_DEBUGGABLE_UCODE | \ + D3DXSHADEREX_AUTOZ | \ + D3DXSHADEREX_REMOVE_UNUSED_PS_INPUTS | \ + D3DXSHADEREX_AUTO_VFETCHE | \ + D3DXSHADEREX_ENABLE_ASSERTIONS | \ + D3DXSHADEREX_ISOLATE_ASSERTIONS | \ + D3DXSHADEREX_ENABLE_ASSERTIONS_FOR_PIX | \ + D3DXSHADEREX_ENABLE_ASSERTIONS_FOR_PIX_DEBUGGER) +// end internal + +#define D3DXDISASSEMBLER_ENABLE_COLOR (1 << 0) +#define D3DXDISASSEMBLER_SHOW_CONSTANT_TABLE_DEFAULTS (1 << 1) +#define D3DXDISASSEMBLER_SHOW_DETAILS (1 << 2) +#define D3DXDISASSEMBLER_HIDE_PATCHED (1 << 3) +#define D3DXDISASSEMBLER_OUTPUT_FORMAT_RTF (1 << 4) +#define D3DXDISASSEMBLER_SHOW_ADDRESSES (1 << 6) +#define D3DXDISASSEMBLER_SHOW_MICROCODE_DEFAULTS (1 << 7) +#define D3DXDISASSEMBLER_SHOW_RUNTIME_DATA (1 << 8) +#define D3DXDISASSEMBLER_SHOW_TIMING_ESTIMATE (1 << 11) + +// begin internal +//---------------------------------------------------------------------------- +// D3DXAPI: +// -------- +// Identifies different API entrypoint sets. Used by D3DXGetTargetDesc. +//---------------------------------------------------------------------------- + +#define D3DXAPI_ASSEMBLE_SHADER (1 << 0) +#define D3DXAPI_COMPILE_SHADER (1 << 1) +#define D3DXAPI_FILL_TEXTURE (1 << 2) +// end internal + + +//---------------------------------------------------------------------------- +// D3DXHANDLE: +// ----------- +// Handle values used to efficiently reference shader and effect parameters. +// On Xbox 360, strings cannot be used as handles (handles are never strings). +//---------------------------------------------------------------------------- + +typedef UINT_PTR D3DXHANDLE; +typedef D3DXHANDLE *LPD3DXHANDLE; + + +//---------------------------------------------------------------------------- +// D3DXMACRO: +// ---------- +// Preprocessor macro definition. The application pass in a NULL-terminated +// array of this structure to various D3DX APIs. This enables the application +// to #define tokens at runtime, before the file is parsed. +//---------------------------------------------------------------------------- + +typedef struct _D3DXMACRO +{ + LPCSTR Name; + LPCSTR Definition; + +} D3DXMACRO, *LPD3DXMACRO; + + +//---------------------------------------------------------------------------- +// D3DXSEMANTIC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXSEMANTIC +{ + UINT Usage; + UINT UsageIndex; + +} D3DXSEMANTIC, *LPD3DXSEMANTIC; + + +// begin internal +//---------------------------------------------------------------------------- +// D3DXTARGET_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXTARGET_DESC +{ + LPCSTR Name; + DWORD Version; + DWORD API; + +} D3DXTARGET_DESC, *LPD3DXTARGET_DESC; +// end internal + + +//---------------------------------------------------------------------------- +// D3DXFRAGMENT_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXFRAGMENT_DESC +{ + LPCSTR Name; + DWORD Target; + +} D3DXFRAGMENT_DESC, *LPD3DXFRAGMENT_DESC; + + +//---------------------------------------------------------------------------- +// D3DXREGISTER_SET: +//---------------------------------------------------------------------------- + +typedef enum _D3DXREGISTER_SET +{ + D3DXRS_BOOL, + D3DXRS_INT4, + D3DXRS_FLOAT4, + D3DXRS_SAMPLER, + + // force 32-bit size enum + D3DXRS_FORCE_DWORD = 0x7fffffff + +} D3DXREGISTER_SET, *LPD3DXREGISTER_SET; + + +//---------------------------------------------------------------------------- +// D3DXPARAMETER_CLASS: +//---------------------------------------------------------------------------- + +typedef enum _D3DXPARAMETER_CLASS +{ + D3DXPC_SCALAR, + D3DXPC_VECTOR, + D3DXPC_MATRIX_ROWS, + D3DXPC_MATRIX_COLUMNS, + D3DXPC_OBJECT, + D3DXPC_STRUCT, + + // force 32-bit size enum + D3DXPC_FORCE_DWORD = 0x7fffffff + +} D3DXPARAMETER_CLASS, *LPD3DXPARAMETER_CLASS; + + +//---------------------------------------------------------------------------- +// D3DXPARAMETER_TYPE: +//---------------------------------------------------------------------------- + +typedef enum _D3DXPARAMETER_TYPE +{ + D3DXPT_VOID, + D3DXPT_BOOL, + D3DXPT_INT, + D3DXPT_FLOAT, + D3DXPT_STRING, + D3DXPT_TEXTURE, + D3DXPT_TEXTURE1D, + D3DXPT_TEXTURE2D, + D3DXPT_TEXTURE3D, + D3DXPT_TEXTURECUBE, + D3DXPT_SAMPLER, + D3DXPT_SAMPLER1D, + D3DXPT_SAMPLER2D, + D3DXPT_SAMPLER3D, + D3DXPT_SAMPLERCUBE, + D3DXPT_PIXELSHADER, + D3DXPT_VERTEXSHADER, + D3DXPT_PIXELFRAGMENT, + D3DXPT_VERTEXFRAGMENT, + + // force 32-bit size enum + D3DXPT_FORCE_DWORD = 0x7fffffff + +} D3DXPARAMETER_TYPE, *LPD3DXPARAMETER_TYPE; + + +//---------------------------------------------------------------------------- +// D3DXCONSTANTTABLE_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXCONSTANTTABLE_DESC +{ + LPCSTR Creator; // Creator string + DWORD Version; // Shader version + UINT Constants; // Number of constants + +} D3DXCONSTANTTABLE_DESC, *LPD3DXCONSTANTTABLE_DESC; + + +//---------------------------------------------------------------------------- +// D3DXCONSTANT_DESC: +//---------------------------------------------------------------------------- + +typedef struct _D3DXCONSTANT_DESC +{ + LPCSTR Name; // Constant name + + D3DXREGISTER_SET RegisterSet; // Register set + UINT RegisterIndex; // Register index + UINT RegisterCount; // Number of registers occupied + + D3DXPARAMETER_CLASS Class; // Class + D3DXPARAMETER_TYPE Type; // Component type + + UINT Rows; // Number of rows + UINT Columns; // Number of columns + UINT Elements; // Number of array elements + UINT StructMembers; // Number of structure member sub-parameters + + UINT Bytes; // Data size, in bytes + LPCVOID DefaultValue; // Pointer to default value + +} D3DXCONSTANT_DESC, *LPD3DXCONSTANT_DESC; + + + +//---------------------------------------------------------------------------- +// ID3DXConstantTable: +//---------------------------------------------------------------------------- + +// {9DCA3190-38B9-4fc3-92E3-39C6DDFB358B} +DEFINE_GUID( IID_ID3DXConstantTable, + 0x9dca3190, 0x38b9, 0x4fc3, 0x92, 0xe3, 0x39, 0xc6, 0xdd, 0xfb, 0x35, 0x8b); + + +#undef INTERFACE +#define INTERFACE ID3DXConstantTable + +DECLARE_INTERFACE_(ID3DXConstantTable, ID3DXBuffer) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXBuffer + STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE; + STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE; + + // Descs + STDMETHOD(GetDesc)(THIS_ __out D3DXCONSTANTTABLE_DESC *pDesc) PURE; + STDMETHOD(GetConstantDesc)(THIS_ __in D3DXHANDLE hConstant, __out_ecount_part(*pCount, *pCount) D3DXCONSTANT_DESC *pConstantDesc, __out UINT *pCount) PURE; + STDMETHOD_(UINT, GetSamplerIndex)(THIS_ __in D3DXHANDLE hConstant) PURE; + + // Handle operations + STDMETHOD_(__out D3DXHANDLE, GetConstant)(THIS_ __in D3DXHANDLE hConstant, UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetConstantByName)(THIS_ __in D3DXHANDLE hConstant, __in_z LPCSTR pName) PURE; + STDMETHOD_(__out D3DXHANDLE, GetConstantElement)(THIS_ __in D3DXHANDLE hConstant, UINT Index) PURE; + + // Set Constants + STDMETHOD(SetDefaults)(THIS_ __in LPDIRECT3DDEVICE9 pDevice) PURE; + STDMETHOD(SetValue)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_bcount(Bytes) LPCVOID pData, UINT Bytes) PURE; + STDMETHOD(SetBool)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, BOOL b) PURE; + STDMETHOD(SetBoolArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST BOOL* pb, UINT Count) PURE; + STDMETHOD(SetInt)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, INT n) PURE; + STDMETHOD(SetIntArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST INT* pn, UINT Count) PURE; + STDMETHOD(SetFloat)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, FLOAT f) PURE; + STDMETHOD(SetFloatArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST FLOAT* pf, UINT Count) PURE; + STDMETHOD(SetVector)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in CONST D3DXVECTOR4* pVector) PURE; + STDMETHOD(SetVectorArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST D3DXVECTOR4* pVector, UINT Count) PURE; + STDMETHOD(SetMatrix)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixPointerArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTranspose)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in CONST D3DXMATRIX* pMatrix) PURE; + STDMETHOD(SetMatrixTransposeArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST D3DXMATRIX* pMatrix, UINT Count) PURE; + STDMETHOD(SetMatrixTransposePointerArray)(THIS_ __in LPDIRECT3DDEVICE9 pDevice, __in D3DXHANDLE hConstant, __in_ecount(Count) CONST D3DXMATRIX** ppMatrix, UINT Count) PURE; +}; + +typedef interface ID3DXConstantTable ID3DXConstantTable; +typedef interface ID3DXConstantTable *LPD3DXCONSTANTTABLE; + + +//---------------------------------------------------------------------------- +// ID3DXFragmentLinker +//---------------------------------------------------------------------------- + +#undef INTERFACE +#define INTERFACE ID3DXFragmentLinker + +// {D59D3777-C973-4a3c-B4B0-2A62CD3D8B40} +DEFINE_GUID(IID_ID3DXFragmentLinker, + 0xd59d3777, 0xc973, 0x4a3c, 0xb4, 0xb0, 0x2a, 0x62, 0xcd, 0x3d, 0x8b, 0x40); + + +DECLARE_INTERFACE_(ID3DXFragmentLinker, IUnknown) +{ + // IUnknown + STDMETHOD(QueryInterface)(THIS_ REFIID iid, __deref_out LPVOID *ppv) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + + // ID3DXFragmentLinker + + // fragment access and information retrieval functions + STDMETHOD(GetDevice)(THIS_ __deref_out LPDIRECT3DDEVICE9* ppDevice) PURE; + STDMETHOD_(UINT, GetNumberOfFragments)(THIS) PURE; + + STDMETHOD_(__out D3DXHANDLE, GetFragmentHandleByIndex)(THIS_ UINT Index) PURE; + STDMETHOD_(__out D3DXHANDLE, GetFragmentHandleByName)(THIS_ __in_z LPCSTR Name) PURE; + STDMETHOD(GetFragmentDesc)(THIS_ __in D3DXHANDLE Name, __out LPD3DXFRAGMENT_DESC FragDesc) PURE; + + // add the fragments in the buffer to the linker + STDMETHOD(AddFragments)(THIS_ __in CONST DWORD *Fragments) PURE; + + // Create a buffer containing the fragments. Suitable for saving to disk + STDMETHOD(GetAllFragments)(THIS_ __deref_out LPD3DXBUFFER *ppBuffer) PURE; + STDMETHOD(GetFragment)(THIS_ __in D3DXHANDLE Name, __deref_out LPD3DXBUFFER *ppBuffer) PURE; + + STDMETHOD(LinkShader)(THIS_ __in_z LPCSTR pProfile, DWORD Flags, __in_ecount(cFragments) CONST D3DXHANDLE *rgFragmentHandles, UINT cFragments, __deref_out LPD3DXBUFFER *ppBuffer, __deref_opt_out LPD3DXBUFFER *ppErrorMsgs) PURE; + STDMETHOD(LinkVertexShader)(THIS_ __in_z LPCSTR pProfile, DWORD Flags, __in_ecount(cFragments) CONST D3DXHANDLE *rgFragmentHandles, UINT cFragments, __deref_out LPDIRECT3DVERTEXSHADER9 *ppVShader, __deref_opt_out LPD3DXBUFFER *ppErrorMsgs) PURE; + STDMETHOD(LinkPixelShader)(THIS_ __in_z LPCSTR pProfile, DWORD Flags, __in_ecount(cFragments) CONST D3DXHANDLE *rgFragmentHandles, UINT cFragments, __deref_out LPDIRECT3DPIXELSHADER9 *ppPShader, __deref_opt_out LPD3DXBUFFER *ppErrorMsgs) PURE; + + STDMETHOD(ClearCache)(THIS) PURE; +}; + + +//---------------------------------------------------------------------------- +// D3DXINCLUDE_TYPE: +//---------------------------------------------------------------------------- + +typedef enum _D3DXINCLUDE_TYPE +{ + D3DXINC_LOCAL, + D3DXINC_SYSTEM, + + // force 32-bit size enum + D3DXINC_FORCE_DWORD = 0x7fffffff + +} D3DXINCLUDE_TYPE, *LPD3DXINCLUDE_TYPE; + + +//---------------------------------------------------------------------------- +// ID3DXInclude: +// ------------- +// This interface is intended to be implemented by the application, and can +// be used by various D3DX APIs. This enables application-specific handling +// of #include directives in source files. +// +// Open() +// Opens an include file. If successful, it should fill in ppData and +// pBytes. The data pointer returned must remain valid until Close is +// subsequently called. +// +// Xbox 360 Extension: To aid source level debugging, Open() may optionally +// return the full path to the found include file, by storing it in the +// buffer pointed to by pFullPath. The full path may be up to cbFullPath +// characters long, including the terminating '\0' character. +// +// Close() +// Closes an include file. If Open was successful, Close is guaranteed +// to be called before the API using this interface returns. +//---------------------------------------------------------------------------- + +typedef interface ID3DXInclude ID3DXInclude; +typedef interface ID3DXInclude *LPD3DXINCLUDE; + +#undef INTERFACE +#define INTERFACE ID3DXInclude + +DECLARE_INTERFACE(ID3DXInclude) +{ + STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE IncludeType, __in_z LPCSTR pFileName, __in LPCVOID pParentData, + __deref_out_bcount(*pBytes) LPCVOID *ppData, __out UINT *pBytes, + /* OUT */ __out_bcount_z(cbFullPath) LPSTR pFullPath, DWORD cbFullPath) PURE; + STDMETHOD(Close)(THIS_ __in LPCVOID pData) PURE; +}; + +//---------------------------------------------------------------------------- +// D3DXSHADER_COMPILE_PARAMETERS: +//---------------------------------------------------------------------------- + +typedef struct _D3DXSHADER_COMPILE_PARAMETERSA +{ + // Fields use by both assembler and compiler: + + DWORD Flags; // D3DXSHADEREX_* flags + DWORD UPDBTimestamp; // UPDB Timestamp for this compile. + LPCSTR UPDBPath; // UPDB path for this compile. + LPD3DXBUFFER pUPDBBuffer; // OUT parameter, the resulting UPDB data, caller is responsible for releasing. + DWORD TempRegisterLimit; // Maximum number of general registers available to the generated microcode. + LPVOID pUPDBB; // Must be NULL. + + // Compiler-specific fields: + + LPCSTR CpuFunctionName; // Name to use for generated CPU shader function (NULL to use HLSL entry-point) + BOOL bXbox360ExtensionUsed; // Filled in by CParse and/or the new back end. Used to avoid calling the old back end + DWORD PixelShaderSamplerRegisterBase; // Starting sampler register available to pixel shaders. + DWORD PixelShaderSamplerRegisterCount; // Number of sampler registers available to pixel shaders. + DWORD VertexShaderSamplerRegisterBase; // Starting sampler register available to vertex shaders. + DWORD VertexShaderSamplerRegisterCount; // Number of sampler registers available to vertex shaders. + DWORD PixelShaderInstructionCount_DEPRECATED; // Number of instruction slots available to pixel shaders. + DWORD VertexShaderInstructionCount_DEPRECATED; // Number of instruction slots available to vertex shaders. + WORD PixAssertAddressReg; + WORD PixDebugPrintAddressReg; + WORD PixDebugPrintSamplerReg; + WORD PixDebugPrintEnableReg; + WORD PixDiagnosticIndexReg; +} D3DXSHADER_COMPILE_PARAMETERSA, *LPD3DXSHADER_COMPILE_PARAMETERSA; + +typedef struct _D3DXSHADER_COMPILE_PARAMETERSW +{ + // Fields use by both assembler and compiler: + + DWORD Flags; // D3DXSHADEREX_* flags + DWORD UPDBTimestamp; // UPDB Timestamp for this compile. + LPWSTR UPDBPath; // UPDB path for this compile. + LPD3DXBUFFER pUPDBBuffer; // OUT parameter, the resulting UPDB data, caller is responsible for releasing. + DWORD TempRegisterLimit; // Maximum number of general registers available to the generated microcode. + LPVOID pUPDBB; // Used internally. Must be NULL. + + // Compiler-specific fields: + + LPCSTR CpuFunctionName; // Name to use for generated CPU shader function (NULL to use HLSL entry-point) + BOOL bXbox360ExtensionUsed; // Filled in by CParse and/or the new back end. Used to avoid calling the old back end + DWORD PixelShaderSamplerRegisterBase; // Starting sampler register available to pixel shaders. + DWORD PixelShaderSamplerRegisterCount; // Number of sampler registers available to pixel shaders. + DWORD VertexShaderSamplerRegisterBase; // Starting sampler register available to vertex shaders. + DWORD VertexShaderSamplerRegisterCount; // Number of sampler registers available to vertex shaders. + DWORD PixelShaderInstructionCount_DEPRECATED; // Number of instruction slots available to pixel shaders. + DWORD VertexShaderInstructionCount_DEPRECATED; // Number of instruction slots available to vertex shaders. + WORD PixAssertAddressReg; + WORD PixDebugPrintAddressReg; + WORD PixDebugPrintSamplerReg; + WORD PixDebugPrintEnableReg; + WORD PixDiagnosticIndexReg; +} D3DXSHADER_COMPILE_PARAMETERSW, *LPD3DXSHADER_COMPILE_PARAMETERSW; + +#ifdef UNICODE +#define D3DXSHADER_COMPILE_PARAMETERS D3DXSHADER_COMPILE_PARAMETERSW +#define LPD3DXSHADER_COMPILE_PARAMETERS LPD3DXSHADER_COMPILE_PARAMETERSW +#else +#define D3DXSHADER_COMPILE_PARAMETERS D3DXSHADER_COMPILE_PARAMETERSA +#define LPD3DXSHADER_COMPILE_PARAMETERS LPD3DXSHADER_COMPILE_PARAMETERSA +#endif + +////////////////////////////////////////////////////////////////////////////// +// APIs ////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + + + //---------------------------------------------------------------------------- + // D3DXAssembleShader/Ex: + // ------------------- + // Assembles a shader. + // + // Parameters: + // pSrcFile + // Source file name + // hSrcModule + // Module handle. if NULL, current module will be used + // pSrcResource + // Resource name in module + // pSrcData + // Pointer to source code + // SrcDataLen + // Size of source code, in bytes + // pDefines + // Optional NULL-terminated array of preprocessor macro definitions. + // pInclude + // Optional interface pointer to use for handling #include directives. + // If this parameter is NULL, #includes will be honored when assembling + // from file, and will error when assembling from resource or memory. + // Flags + // See D3DXSHADER_xxx flags + // ppShader + // Returns a buffer containing the created shader. This buffer contains + // the assembled shader code, as well as any embedded debug info. + // ppErrorMsgs + // Returns a buffer containing a listing of errors and warnings that were + // encountered during assembly. If you are running in a debugger, + // these are the same messages you will see in your debug output. + //---------------------------------------------------------------------------- + + + HRESULT WINAPI + D3DXAssembleShaderFromFileA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + HRESULT WINAPI + D3DXAssembleShaderFromFileW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + +#ifdef UNICODE +#define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileW +#else +#define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileA +#endif + + + HRESULT WINAPI + D3DXAssembleShader( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + // Ex version: + + HRESULT WINAPI + D3DXAssembleShaderFromFileExA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __in LPD3DXSHADER_COMPILE_PARAMETERSA pParameters); + + HRESULT WINAPI + D3DXAssembleShaderFromFileExW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __in LPD3DXSHADER_COMPILE_PARAMETERSW pParameters); + +#ifdef UNICODE +#define D3DXAssembleShaderFromFileEx D3DXAssembleShaderFromFileExW +#else +#define D3DXAssembleShaderFromFileEx D3DXAssembleShaderFromFileExA +#endif + + + HRESULT WINAPI + D3DXAssembleShaderExA( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __in LPD3DXSHADER_COMPILE_PARAMETERSA pParameters); + + + HRESULT WINAPI + D3DXAssembleShaderExW( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __in LPD3DXSHADER_COMPILE_PARAMETERSW pParameters); + +#ifdef UNICODE +#define D3DXAssembleShaderEx D3DXAssembleShaderExW +#else +#define D3DXAssembleShaderEx D3DXAssembleShaderExA +#endif + + + //---------------------------------------------------------------------------- + // D3DXCompileShader/Ex: + // ------------------ + // Compiles a shader. + // + // Parameters: + // pSrcFile + // Source file name. + // hSrcModule + // Module handle. if NULL, current module will be used. + // pSrcResource + // Resource name in module. + // pSrcData + // Pointer to source code. + // SrcDataLen + // Size of source code, in bytes. + // pDefines + // Optional NULL-terminated array of preprocessor macro definitions. + // pInclude + // Optional interface pointer to use for handling #include directives. + // If this parameter is NULL, #includes will be honored when compiling + // from file, and will error when compiling from resource or memory. + // pFunctionName + // Name of the entrypoint function where execution should begin. + // pProfile + // Instruction set to be used when generating code. Currently supported + // profiles are "vs_3_0", "ps_3_0", and "tx_1_0". For backwards compatibility + // any profile starting with "vs" will automatically be promoted to "vs_3_0", and + // any profile starting with "ps" will automatically be promoted to "ps_3_0". + // + // + // Flags + // See D3DXSHADER_xxx flags. + // ppShader + // Returns a buffer containing the created shader. This buffer contains + // the compiled shader code, as well as any embedded debug and symbol + // table info. (See D3DXGetShaderConstantTable) + // ppErrorMsgs + // Returns a buffer containing a listing of errors and warnings that were + // encountered during the compile. If you are running in a debugger, + // these are the same messages you will see in your debug output. + // ppConstantTable + // Returns a ID3DXConstantTable object which can be used to set + // shader constants to the device. Alternatively, an application can + // parse the D3DXSHADER_CONSTANTTABLE block embedded as a comment within + // the shader. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXCompileShaderFromFileA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable); + + HRESULT WINAPI + D3DXCompileShaderFromFileW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable); + +#ifdef UNICODE +#define D3DXCompileShaderFromFile D3DXCompileShaderFromFileW +#else +#define D3DXCompileShaderFromFile D3DXCompileShaderFromFileA +#endif + + + HRESULT WINAPI + D3DXCompileShader( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable); + + + + HRESULT WINAPI + D3DXCompileShaderFromFileExA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable, + __in LPD3DXSHADER_COMPILE_PARAMETERSA pParameters); + + HRESULT WINAPI + D3DXCompileShaderFromFileExW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable, + __in LPD3DXSHADER_COMPILE_PARAMETERSW pParameters); + +#ifdef UNICODE +#define D3DXCompileShaderFromFileEx D3DXCompileShaderFromFileExW +#else +#define D3DXCompileShaderFromFileEx D3DXCompileShaderFromFileExA +#endif + + + HRESULT WINAPI + D3DXCompileShaderExA( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable, + __in LPD3DXSHADER_COMPILE_PARAMETERSA pParameters); + + HRESULT WINAPI + D3DXCompileShaderExW( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __in_z LPCSTR pFunctionName, + __in_z LPCSTR pProfile, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs, + __deref_opt_out LPD3DXCONSTANTTABLE* ppConstantTable, + __in LPD3DXSHADER_COMPILE_PARAMETERSW pParameters); + +#ifdef UNICODE +#define D3DXCompileShaderEx D3DXCompileShaderExW +#else +#define D3DXCompileShaderEx D3DXCompileShaderExA +#endif + + //---------------------------------------------------------------------------- + // D3DXDisassembleShader: + // ---------------------- + // Takes a binary shader, and returns a buffer containing text assembly. + // + // Parameters: + // pShader + // Pointer to the shader byte code. + // ShaderSizeInBytes + // Size of the shader byte code in bytes. + // EnableColorCode + // Emit HTML tags for color coding the output? + // pComments + // Pointer to a comment string to include at the top of the shader. + // ppDisassembly + // Returns a buffer containing the disassembled shader. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXDisassembleShader( + __in CONST DWORD* pShader, + BOOL EnableColorCode, + __in_z_opt LPCSTR pComments, + __deref_out LPD3DXBUFFER* ppDisassembly); + + //---------------------------------------------------------------------------- + // D3DXDisassembleShaderEx: + // ---------------------- + // Takes a binary shader, and returns a buffer containing text assembly. + // + // Parameters: + // pShader + // Pointer to the shader byte code. + // ShaderSizeInBytes + // Size of the shader byte code in bytes. + // Flags + // combination of D3DXDISASSEMBLER flags controlling output format. + // pComments + // Pointer to a comment string to include at the top of the shader. + // ppDisassembly + // Returns a buffer containing the disassembled shader. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXDisassembleShaderEx( + __in CONST DWORD* pShader, + DWORD Flags, + __in_z_opt LPCSTR pComments, + __deref_out LPD3DXBUFFER* ppDisassembly); + + //---------------------------------------------------------------------------- + // D3DXGetPixelShaderProfile/D3DXGetVertexShaderProfile: + // ----------------------------------------------------- + // Returns the name of the HLSL profile best suited to a given device. + // + // Parameters: + // pDevice + // Pointer to the device in question + //---------------------------------------------------------------------------- + + LPCSTR WINAPI + D3DXGetPixelShaderProfile( + __in LPDIRECT3DDEVICE9 pDevice); + + LPCSTR WINAPI + D3DXGetVertexShaderProfile( + __in LPDIRECT3DDEVICE9 pDevice); + + + //---------------------------------------------------------------------------- + // D3DXFindShaderComment: + // ---------------------- + // Searches through a shader for a particular comment, denoted by a FourCC in + // the first DWORD of the comment. If the comment is not found, and no other + // error has occurred, S_FALSE is returned. + // + // Parameters: + // pFunction + // Pointer to the function DWORD stream + // FourCC + // FourCC used to identify the desired comment block. + // ppData + // Returns a pointer to the comment data (not including comment token + // and FourCC). Can be NULL. + // pSizeInBytes + // Returns the size of the comment data in bytes. Can be NULL. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXFindShaderComment( + __in CONST DWORD* pFunction, + DWORD FourCC, + __deref_opt_out LPCVOID* ppData, + __out_opt UINT* pSizeInBytes); + + + //---------------------------------------------------------------------------- + // D3DXGetShaderSize: + // ------------------ + // Returns the size of the shader byte-code, in bytes. + // + // Parameters: + // pFunction + // Pointer to the function DWORD stream + //---------------------------------------------------------------------------- + + UINT WINAPI + D3DXGetShaderSize( + __in CONST DWORD* pFunction); + + //---------------------------------------------------------------------------- + // D3DXGetShaderVersion: + // ----------------------- + // Returns the shader version of a given shader. Returns zero if the shader + // function is NULL. + // + // Parameters: + // pFunction + // Pointer to the function DWORD stream + //---------------------------------------------------------------------------- + + DWORD WINAPI + D3DXGetShaderVersion( + __in CONST DWORD* pFunction); + + + //---------------------------------------------------------------------------- + // D3DXGetShaderSemantics: + // ----------------------- + // Gets semantics for all input elements referenced inside a given shader. + // + // Parameters: + // pFunction + // Pointer to the function DWORD stream + // pSemantics + // Pointer to an array of D3DXSEMANTIC structures. The function will + // fill this array with the semantics for each input element referenced + // inside the shader. This array is assumed to contain at least + // MAXD3DDECLLENGTH elements. + // pCount + // Returns the number of elements referenced by the shader + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXGetShaderInputSemantics( + __in CONST DWORD* pFunction, + __out_opt D3DXSEMANTIC* pSemantics, + __out_opt UINT* pCount); + + HRESULT WINAPI + D3DXGetShaderOutputSemantics( + __in CONST DWORD* pFunction, + __out_opt D3DXSEMANTIC* pSemantics, + __out_opt UINT* pCount); + + + //---------------------------------------------------------------------------- + // D3DXGetShaderSamplers: + // ---------------------- + // Gets semantics for all input elements referenced inside a given shader. + // + // pFunction + // Pointer to the function DWORD stream + // pSamplers + // Pointer to an array of LPCSTRs. The function will fill this array + // with pointers to the sampler names contained within pFunction, for + // each sampler referenced inside the shader. This array is assumed to + // contain at least 32 elements. + // pCount + // Returns the number of samplers referenced by the shader + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXGetShaderSamplers( + __in CONST DWORD* pFunction, + __out_ecount_part(32, *pCount) LPCSTR* pSamplers, + __out_opt UINT* pCount); + + + //---------------------------------------------------------------------------- + // D3DXGetShaderConstantTable: + // --------------------------- + // Gets shader constant table embedded inside shader. A constant table is + // generated by D3DXAssembleShader and D3DXCompileShader, and is embedded in + // the body of the shader. + // + // Parameters: + // pFunction + // Pointer to the function DWORD stream + // ppConstantTable + // Returns a ID3DXConstantTable object which can be used to set + // shader constants to the device. Alternatively, an application can + // parse the D3DXSHADER_CONSTANTTABLE block embedded as a comment within + // the shader. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXGetShaderConstantTable( + __in CONST DWORD* pFunction, + __deref_out LPD3DXCONSTANTTABLE* ppConstantTable); + + + //---------------------------------------------------------------------------- + // D3DXGatherFragments: + // ------------------- + // Assembles shader fragments into a buffer to be passed to a fragment linker. + // will generate shader fragments for all fragments in the file + // + // Parameters: + // pSrcFile + // Source file name + // hSrcModule + // Module handle. if NULL, current module will be used + // pSrcResource + // Resource name in module + // pSrcData + // Pointer to source code + // SrcDataLen + // Size of source code, in bytes + // pDefines + // Optional NULL-terminated array of preprocessor macro definitions. + // pInclude + // Optional interface pointer to use for handling #include directives. + // If this parameter is NULL, #includes will be honored when assembling + // from file, and will error when assembling from resource or memory. + // Flags + // See D3DXSHADER_xxx flags + // ppShader + // Returns a buffer containing the created shader fragments. This buffer contains + // the assembled shader code, as well as any embedded debug info. + // ppErrorMsgs + // Returns a buffer containing a listing of errors and warnings that were + // encountered during assembly. If you are running in a debugger, + // these are the same messages you will see in your debug output. + //---------------------------------------------------------------------------- + + + HRESULT WINAPI + D3DXGatherFragmentsFromFileA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + HRESULT WINAPI + D3DXGatherFragmentsFromFileW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + +#ifdef UNICODE +#define D3DXGatherFragmentsFromFile D3DXGatherFragmentsFromFileW +#else +#define D3DXGatherFragmentsFromFile D3DXGatherFragmentsFromFileA +#endif + + + HRESULT WINAPI + D3DXGatherFragments( + __in_ecount_z(SrcDataLen) LPCSTR pSrcData, + UINT SrcDataLen, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out LPD3DXBUFFER* ppShader, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + typedef ID3DXFragmentLinker *LPD3DXFRAGMENTLINKER; + + + //---------------------------------------------------------------------------- + // D3DXCreateFragmentLinker: + // ------------------------- + // Creates a fragment linker with a given cache size. The interface returned + // can be used to link together shader fragments. (both HLSL & ASM fragements) + // + // Parameters: + // pDevice + // Pointer to the device on which to create the shaders + // ShaderCacheSize + // Size of the shader cache + // ppFragmentLinker + // pointer to a memory location to put the created interface pointer + // + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXCreateFragmentLinker( + __in LPDIRECT3DDEVICE9 pDevice, + UINT ShaderCacheSize, + __deref_out LPD3DXFRAGMENTLINKER* ppFragmentLinker); + + + //---------------------------------------------------------------------------- + // D3DXPreprocessShader: + // --------------------- + // Runs the preprocessor on the specified shader or effect, but does + // not actually compile it. This is useful for evaluating the #includes + // and #defines in a shader and then emitting a reformatted token stream + // for debugging purposes or for generating a self-contained shader. + // + // Parameters: + // pSrcFile + // Source file name + // hSrcModule + // Module handle. if NULL, current module will be used + // pSrcResource + // Resource name in module + // pSrcData + // Pointer to source code + // SrcDataLen + // Size of source code, in bytes + // pDefines + // Optional NULL-terminated array of preprocessor macro definitions. + // pInclude + // Optional interface pointer to use for handling #include directives. + // If this parameter is NULL, #includes will be honored when assembling + // from file, and will error when assembling from resource or memory. + // ppShaderText + // Returns a buffer containing a single large string that represents + // the resulting formatted token stream + // ppErrorMsgs + // Returns a buffer containing a listing of errors and warnings that were + // encountered during assembly. If you are running in a debugger, + // these are the same messages you will see in your debug output. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXPreprocessShaderFromFileA( + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __deref_out LPD3DXBUFFER* ppShaderText, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + HRESULT WINAPI + D3DXPreprocessShaderFromFileW( + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __deref_out LPD3DXBUFFER* ppShaderText, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + +#ifdef UNICODE +#define D3DXPreprocessShaderFromFile D3DXPreprocessShaderFromFileW +#else +#define D3DXPreprocessShaderFromFile D3DXPreprocessShaderFromFileA +#endif + +#ifndef _XBOX + + HRESULT WINAPI + D3DXPreprocessShaderFromResourceA( + __in HMODULE hSrcModule, + __in_z LPCSTR pSrcResource, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __deref_out LPD3DXBUFFER* ppShaderText, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + HRESULT WINAPI + D3DXPreprocessShaderFromResourceW( + __in HMODULE hSrcModule, + __in_z LPCWSTR pSrcResource, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __deref_out LPD3DXBUFFER* ppShaderText, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + +#ifdef UNICODE +#define D3DXPreprocessShaderFromResource D3DXPreprocessShaderFromResourceW +#else +#define D3DXPreprocessShaderFromResource D3DXPreprocessShaderFromResourceA +#endif + +#endif + + HRESULT WINAPI + D3DXPreprocessShader( + __in_ecount_z(SrcDataSize) LPCSTR pSrcData, + UINT SrcDataSize, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + __deref_out LPD3DXBUFFER* ppShaderText, + __deref_opt_out LPD3DXBUFFER* ppErrorMsgs); + + // begin internal + //---------------------------------------------------------------------------- + // D3DXGetTargetDesc: + // ------------------ + // Functions to lookup and describe various shader target versions. + //---------------------------------------------------------------------------- + + HRESULT WINAPI + D3DXGetTargetDescByName( + __in_z LPCSTR pName, + DWORD API, + __out D3DXTARGET_DESC* pTargetDesc); + + HRESULT WINAPI + D3DXGetTargetDescByVersion( + DWORD Version, + DWORD API, + __out D3DXTARGET_DESC* pDesc); + // end internal + + +#ifdef __cplusplus +} +#endif //__cplusplus + + +////////////////////////////////////////////////////////////////////////////// +// Shader comment block layouts ////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +//---------------------------------------------------------------------------- +// D3DXSHADER_CONSTANTTABLE: +// ------------------------- +// Shader constant information; included as an CTAB comment block inside +// shaders. All offsets are BYTE offsets from start of CONSTANTTABLE struct. +// Entries in the table are sorted by Name in ascending order. +//---------------------------------------------------------------------------- + +typedef struct _D3DXSHADER_CONSTANTTABLE +{ + DWORD Size; // sizeof(D3DXSHADER_CONSTANTTABLE) + DWORD Creator; // LPCSTR offset + DWORD Version; // shader version + DWORD Constants; // number of constants + DWORD ConstantInfo; // D3DXSHADER_CONSTANTINFO[Constants] offset + DWORD Flags; // flags shader was compiled with + DWORD Target; // LPCSTR offset + +} D3DXSHADER_CONSTANTTABLE, *LPD3DXSHADER_CONSTANTTABLE; + +// begin internal +#define CONSTANTINFOFLAG_STATIC 0x1 +#define CONSTANTINFOFLAG_USEROFFSET 0x2 +#define CONSTANTINFOFLAG_USEROFFSETSHIFT 2 +// end internal + +typedef struct _D3DXSHADER_CONSTANTINFO +{ + DWORD Name; // LPCSTR offset + WORD RegisterSet; // D3DXREGISTER_SET + WORD RegisterIndex; // register number + WORD RegisterCount; // number of registers + WORD Flags; // Fragment linker flags (internal field. this field is also known as Reserved). + DWORD TypeInfo; // D3DXSHADER_TYPEINFO offset + DWORD DefaultValue; // offset of default value + +} D3DXSHADER_CONSTANTINFO, *LPD3DXSHADER_CONSTANTINFO; + + +typedef struct _D3DXSHADER_TYPEINFO +{ + WORD Class; // D3DXPARAMETER_CLASS + WORD Type; // D3DXPARAMETER_TYPE + WORD Rows; // number of rows (matrices) + WORD Columns; // number of columns (vectors and matrices) + WORD Elements; // array dimension + WORD StructMembers; // number of struct members + DWORD StructMemberInfo; // D3DXSHADER_STRUCTMEMBERINFO[Members] offset + +} D3DXSHADER_TYPEINFO, *LPD3DXSHADER_TYPEINFO; + + +typedef struct _D3DXSHADER_STRUCTMEMBERINFO +{ + DWORD Name; // LPCSTR offset + DWORD TypeInfo; // D3DXSHADER_TYPEINFO offset + +} D3DXSHADER_STRUCTMEMBERINFO, *LPD3DXSHADER_STRUCTMEMBERINFO; + + + +// begin internal + +//---------------------------------------------------------------------------- +// D3DXGetShaderDebugInfo: +// ----------------------- +// Gets shader debug info. Debug info is generated D3DXAssembleShader and +// D3DXCompileShader and is embedded the body of the shader. +// +// Parameters: +// pFunction +// Pointer to the function DWORD stream +// ppDebugInfo +// Buffer used to return debug info. For information about the layout +// of this buffer, see definition of D3DXSHADER_DEBUGINFO above. +//---------------------------------------------------------------------------- + +HRESULT WINAPI +D3DXGetShaderDebugInfo( + __in CONST DWORD* pFunction, + __deref_out LPD3DXBUFFER* ppDebugInfo); + +//---------------------------------------------------------------------------- +// D3DXSHADER_DEBUGINFO: +// --------------------- +// Shader debug information; included as an DBUG comment block inside shaders. +// All offsets are BYTE offsets from start of DEBUGINFO struct. +//---------------------------------------------------------------------------- + +typedef struct _D3DXSHADER_DEBUGINFO +{ + DWORD Size; // sizeof(D3DXSHADER_DEBUGINFO) + DWORD Creator; // LPCSTR offset + DWORD SourceCode; // LPCSTR offset + DWORD Files; // number of source files + DWORD FileInfo; // D3DXSHADER_FILEINFO[Files] offset + DWORD Instructions; // number of instructions + DWORD InstructionInfo; // D3DXSHADER_INSTRUCTIONINFO[Instructions] offset + DWORD Variables; // number of variables + DWORD VariableInfo; // D3DXSHADER_VARIABLEINFO[Variables] offset + DWORD EntrypointName; // LPCSTR offset + +} D3DXSHADER_DEBUGINFO, *LPD3DXSHADER_DEBUGINFO; + + +typedef struct _D3DXSHADER_FILEINFO +{ + DWORD Name; // LPCSTR offset + +} D3DXSHADER_FILEINFO, *LPD3DXSHADER_FILEINFO; + + +typedef struct _D3DXSHADER_INSTRUCTIONINFO +{ + WORD Line; // line number + WORD File; // file index + DWORD Offset; // BYTE offset of instruction from start of shader + +} D3DXSHADER_INSTRUCTIONINFO, *LPD3DXSHADER_INSTRUCTIONINFO; + + +typedef struct _D3DXSHADER_VARIABLEINFO +{ + DWORD Scope; // LPCSTR scope + DWORD Name; // LPCSTR offset + DWORD TypeInfo; // D3DXSHADER_TYPEINFO offset + DWORD Writes; // number of writes + DWORD WriteInfo; // D3DXSHADER_WRITEINFO[Writes] offset + +} D3DXSHADER_VARIABLEINFO, *LPD3DXSHADER_VARIABLEINFO; + + +typedef struct _D3DXSHADER_WRITEINFO +{ + DWORD Instruction; // instruction index + WORD Component[4]; // variable component per output value + +} D3DXSHADER_WRITEINFO, *LPD3DXSHADER_WRITEINFO; +// end internal + +#endif //__D3DX9SHADER_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9shape.h b/third_party/xbox_sdk/include/d3dx9shape.h new file mode 100644 index 0000000..45c6705 --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9shape.h @@ -0,0 +1,176 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9shapes.h +// Content: D3DX simple shapes +// +/////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9SHAPES_H__ +#define __D3DX9SHAPES_H__ + +/////////////////////////////////////////////////////////////////////////// +// Functions: +/////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + + +//------------------------------------------------------------------------- +// D3DXCreatePolygon: +// ------------------ +// Creates a mesh containing an n-sided polygon. The polygon is centered +// at the origin. +// +// Parameters: +// +// pDevice The D3D device with which the mesh is going to be used. +// Length Length of each side. +// Sides Number of sides the polygon has. (Must be >= 3) +// ppMesh The mesh object which will be created +// ppAdjacency Returns a buffer containing adjacency info. Can be NULL. +//------------------------------------------------------------------------- +HRESULT WINAPI + D3DXCreatePolygon( + __in LPDIRECT3DDEVICE9 pDevice, + FLOAT Length, + UINT Sides, + __deref_out LPD3DXMESH* ppMesh, + __deref_opt_out LPD3DXBUFFER* ppAdjacency); + + +//------------------------------------------------------------------------- +// D3DXCreateBox: +// -------------- +// Creates a mesh containing an axis-aligned box. The box is centered at +// the origin. +// +// Parameters: +// +// pDevice The D3D device with which the mesh is going to be used. +// Width Width of box (along X-axis) +// Height Height of box (along Y-axis) +// Depth Depth of box (along Z-axis) +// ppMesh The mesh object which will be created +// ppAdjacency Returns a buffer containing adjacency info. Can be NULL. +//------------------------------------------------------------------------- +HRESULT WINAPI + D3DXCreateBox( + __in LPDIRECT3DDEVICE9 pDevice, + FLOAT Width, + FLOAT Height, + FLOAT Depth, + __deref_out LPD3DXMESH* ppMesh, + __deref_opt_out LPD3DXBUFFER* ppAdjacency); + + +//------------------------------------------------------------------------- +// D3DXCreateCylinder: +// ------------------- +// Creates a mesh containing a cylinder. The generated cylinder is +// centered at the origin, and its axis is aligned with the Z-axis. +// +// Parameters: +// +// pDevice The D3D device with which the mesh is going to be used. +// Radius1 Radius at -Z end (should be >= 0.0f) +// Radius2 Radius at +Z end (should be >= 0.0f) +// Length Length of cylinder (along Z-axis) +// Slices Number of slices about the main axis +// Stacks Number of stacks along the main axis +// ppMesh The mesh object which will be created +// ppAdjacency Returns a buffer containing adjacency info. Can be NULL. +//------------------------------------------------------------------------- +HRESULT WINAPI + D3DXCreateCylinder( + __in LPDIRECT3DDEVICE9 pDevice, + FLOAT Radius1, + FLOAT Radius2, + FLOAT Length, + UINT Slices, + UINT Stacks, + __deref_out LPD3DXMESH* ppMesh, + __deref_opt_out LPD3DXBUFFER* ppAdjacency); + + +//------------------------------------------------------------------------- +// D3DXCreateSphere: +// ----------------- +// Creates a mesh containing a sphere. The sphere is centered at the +// origin. +// +// Parameters: +// +// pDevice The D3D device with which the mesh is going to be used. +// Radius Radius of the sphere (should be >= 0.0f) +// Slices Number of slices about the main axis +// Stacks Number of stacks along the main axis +// ppMesh The mesh object which will be created +// ppAdjacency Returns a buffer containing adjacency info. Can be NULL. +//------------------------------------------------------------------------- +HRESULT WINAPI + D3DXCreateSphere( + __in LPDIRECT3DDEVICE9 pDevice, + FLOAT Radius, + UINT Slices, + UINT Stacks, + __deref_out LPD3DXMESH* ppMesh, + __deref_opt_out LPD3DXBUFFER* ppAdjacency); + + +//------------------------------------------------------------------------- +// D3DXCreateTorus: +// ---------------- +// Creates a mesh containing a torus. The generated torus is centered at +// the origin, and its axis is aligned with the Z-axis. +// +// Parameters: +// +// pDevice The D3D device with which the mesh is going to be used. +// InnerRadius Inner radius of the torus (should be >= 0.0f) +// OuterRadius Outer radius of the torue (should be >= 0.0f) +// Sides Number of sides in a cross-section (must be >= 3) +// Rings Number of rings making up the torus (must be >= 3) +// ppMesh The mesh object which will be created +// ppAdjacency Returns a buffer containing adjacency info. Can be NULL. +//------------------------------------------------------------------------- +HRESULT WINAPI + D3DXCreateTorus( + __in LPDIRECT3DDEVICE9 pDevice, + FLOAT InnerRadius, + FLOAT OuterRadius, + UINT Sides, + UINT Rings, + __deref_out LPD3DXMESH* ppMesh, + __deref_opt_out LPD3DXBUFFER* ppAdjacency); + + +//------------------------------------------------------------------------- +// D3DXCreateTeapot: +// ----------------- +// Creates a mesh containing a teapot. +// +// Parameters: +// +// pDevice The D3D device with which the mesh is going to be used. +// ppMesh The mesh object which will be created +// ppAdjacency Returns a buffer containing adjacency info. Can be NULL. +//------------------------------------------------------------------------- +HRESULT WINAPI + D3DXCreateTeapot( + __in LPDIRECT3DDEVICE9 pDevice, + __deref_out LPD3DXMESH* ppMesh, + __deref_opt_out LPD3DXBUFFER* ppAdjacency); + + +#ifdef __cplusplus +} +#endif //__cplusplus + +#endif //__D3DX9SHAPES_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9tex.h b/third_party/xbox_sdk/include/d3dx9tex.h new file mode 100644 index 0000000..6cf2292 --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9tex.h @@ -0,0 +1,1810 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9tex.h +// Content: D3DX texturing APIs +// +////////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#ifndef __D3DX9TEX_H__ +#define __D3DX9TEX_H__ + +//------------------------------------------------------------------------- +// D3DXSetDXT3DXT5 +// --------------- +// +// Set premultiplied alpha format for DXT surface and texture processing. +// When set to TRUE, DXT surfaces will be processed with nonpremultiplied +// alpha i.e. DXT3 / DXT5 format. When set to FALSE, surfaces will be +// processed with premultiplied alpha, i.e. DXT2 / DXT4 format. The default +// is nonpremultiplied alpha - DXT3 / DXT5. +// +//------------------------------------------------------------------------- + +VOID WINAPI D3DXSetDXT3DXT5(BOOL Set); + +//------------------------------------------------------------------------- +// D3DXGetDXT3DXT5 +// --------------- +// +// Get whether D3DX is currently using nonpremultiplied alpha format - +// DXT3 / DXT5 or premultiplied alpha format - DXT2 / DXT4 for DXT surface +// and texture processing. +// +//------------------------------------------------------------------------- + +BOOL WINAPI D3DXGetDXT3DXT5(VOID); + +//---------------------------------------------------------------------------- +// D3DX_FILTER flags: +// ------------------ +// +// A valid filter must contain one of these values: +// +// D3DX_FILTER_NONE +// No scaling or filtering will take place. Pixels outside the bounds +// of the source image are assumed to be transparent black. +// D3DX_FILTER_POINT +// Each destination pixel is computed by sampling the nearest pixel +// from the source image. +// D3DX_FILTER_LINEAR +// Each destination pixel is computed by linearly interpolating between +// the nearest pixels in the source image. This filter works best +// when the scale on each axis is less than 2. +// D3DX_FILTER_TRIANGLE +// Every pixel in the source image contributes equally to the +// destination image. This is the slowest of all the filters. +// D3DX_FILTER_BOX +// Each pixel is computed by averaging a 2x2(x2) box pixels from +// the source image. Only works when the dimensions of the +// destination are half those of the source. (as with mip maps) +// +// And can be OR'd with any of these optional flags: +// +// D3DX_FILTER_MIRROR_U +// Indicates that pixels off the edge of the texture on the U-axis +// should be mirrored, not wraped. +// D3DX_FILTER_MIRROR_V +// Indicates that pixels off the edge of the texture on the V-axis +// should be mirrored, not wraped. +// D3DX_FILTER_MIRROR_W +// Indicates that pixels off the edge of the texture on the W-axis +// should be mirrored, not wraped. +// D3DX_FILTER_MIRROR +// Same as specifying D3DX_FILTER_MIRROR_U | D3DX_FILTER_MIRROR_V | +// D3DX_FILTER_MIRROR_V +// D3DX_FILTER_DITHER +// Dithers the resulting image using a 4x4 order dither pattern. +// D3DX_FILTER_SRGB_IN +// Denotes that the input data is in sRGB (gamma 2.2) colorspace. +// D3DX_FILTER_SRGB_OUT +// Denotes that the output data is in sRGB (gamma 2.2) colorspace. +// D3DX_FILTER_SRGB +// Same as specifying D3DX_FILTER_SRGB_IN | D3DX_FILTER_SRGB_OUT +// +//---------------------------------------------------------------------------- + +#define D3DX_FILTER_NONE (1 << 0) +#define D3DX_FILTER_POINT (2 << 0) +#define D3DX_FILTER_LINEAR (3 << 0) +#define D3DX_FILTER_TRIANGLE (4 << 0) +#define D3DX_FILTER_BOX (5 << 0) + +#define D3DX_FILTER_MIRROR_U (1 << 16) +#define D3DX_FILTER_MIRROR_V (2 << 16) +#define D3DX_FILTER_MIRROR_W (4 << 16) +#define D3DX_FILTER_MIRROR (7 << 16) + +#define D3DX_FILTER_DITHER (1 << 19) +#define D3DX_FILTER_DITHER_DIFFUSION (2 << 19) + +#define D3DX_FILTER_SRGB_IN (1 << 21) +#define D3DX_FILTER_SRGB_OUT (2 << 21) +#define D3DX_FILTER_SRGB (3 << 21) + + +//---------------------------------------------------------------------------- +// D3DX_NORMALMAP flags: +// --------------------- +// These flags are used to control how D3DXComputeNormalMap generates normal +// maps. Any number of these flags may be OR'd together in any combination. +// +// D3DX_NORMALMAP_MIRROR_U +// Indicates that pixels off the edge of the texture on the U-axis +// should be mirrored, not wraped. +// D3DX_NORMALMAP_MIRROR_V +// Indicates that pixels off the edge of the texture on the V-axis +// should be mirrored, not wraped. +// D3DX_NORMALMAP_MIRROR +// Same as specifying D3DX_NORMALMAP_MIRROR_U | D3DX_NORMALMAP_MIRROR_V +// D3DX_NORMALMAP_INVERTSIGN +// Inverts the direction of each normal +// D3DX_NORMALMAP_COMPUTE_OCCLUSION +// Compute the per pixel Occlusion term and encodes it into the alpha. +// An Alpha of 1 means that the pixel is not obscured in anyway, and +// an alpha of 0 would mean that the pixel is completly obscured. +// +//---------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- + +#define D3DX_NORMALMAP_MIRROR_U (1 << 16) +#define D3DX_NORMALMAP_MIRROR_V (2 << 16) +#define D3DX_NORMALMAP_MIRROR (3 << 16) +#define D3DX_NORMALMAP_INVERTSIGN (8 << 16) +#define D3DX_NORMALMAP_COMPUTE_OCCLUSION (16 << 16) + + + + +//---------------------------------------------------------------------------- +// D3DX_CHANNEL flags: +// ------------------- +// These flags are used by functions which operate on or more channels +// in a texture. +// +// D3DX_CHANNEL_RED +// Indicates the red channel should be used +// D3DX_CHANNEL_BLUE +// Indicates the blue channel should be used +// D3DX_CHANNEL_GREEN +// Indicates the green channel should be used +// D3DX_CHANNEL_ALPHA +// Indicates the alpha channel should be used +// D3DX_CHANNEL_LUMINANCE +// Indicates the luminaces of the red green and blue channels should be +// used. +// +//---------------------------------------------------------------------------- + +#define D3DX_CHANNEL_RED (1 << 0) +#define D3DX_CHANNEL_BLUE (1 << 1) +#define D3DX_CHANNEL_GREEN (1 << 2) +#define D3DX_CHANNEL_ALPHA (1 << 3) +#define D3DX_CHANNEL_LUMINANCE (1 << 4) + + + + +//---------------------------------------------------------------------------- +// D3DXIMAGE_FILEFORMAT: +// --------------------- +// This enum is used to describe supported image file formats. +// +//---------------------------------------------------------------------------- + +typedef enum _D3DXIMAGE_FILEFORMAT +{ + D3DXIFF_BMP = 0, + D3DXIFF_JPG = 1, + D3DXIFF_TGA = 2, + D3DXIFF_PNG = 3, + D3DXIFF_DDS = 4, + D3DXIFF_PPM = 5, + D3DXIFF_DIB = 6, + D3DXIFF_HDR = 7, //high dynamic range formats + D3DXIFF_PFM = 8, // + D3DXIFF_FORCE_DWORD = 0x7fffffff + +} D3DXIMAGE_FILEFORMAT; + + +//---------------------------------------------------------------------------- +// LPD3DXFILL2D and LPD3DXFILL3D: +// ------------------------------ +// Function types used by the texture fill functions. +// +// Parameters: +// pOut +// Pointer to a vector which the function uses to return its result. +// X,Y,Z,W will be mapped to R,G,B,A respectivly. +// pTexCoord +// Pointer to a vector containing the coordinates of the texel currently +// being evaluated. Textures and VolumeTexture texcoord components +// range from 0 to 1. CubeTexture texcoord component range from -1 to 1. +// pTexelSize +// Pointer to a vector containing the dimensions of the current texel. +// pData +// Pointer to user data. +// +//---------------------------------------------------------------------------- + +typedef VOID (WINAPI *LPD3DXFILL2D)(__out D3DXVECTOR4 *pOut, + __in CONST D3DXVECTOR2 *pTexCoord, __in CONST D3DXVECTOR2 *pTexelSize, __in_opt LPVOID pData); + +typedef VOID (WINAPI *LPD3DXFILL3D)(__out D3DXVECTOR4 *pOut, + __in CONST D3DXVECTOR3 *pTexCoord, __in CONST D3DXVECTOR3 *pTexelSize, __in_opt LPVOID pData); + + + +//---------------------------------------------------------------------------- +// D3DXIMAGE_INFO: +// --------------- +// This structure is used to return a rough description of what the +// the original contents of an image file looked like. +// +// Width +// Width of original image in pixels +// Height +// Height of original image in pixels +// Depth +// Depth of original image in pixels +// MipLevels +// Number of mip levels in original image +// Format +// D3D format which most closely describes the data in original image +// ResourceType +// D3DRESOURCETYPE representing the type of texture stored in the file. +// D3DRTYPE_TEXTURE, D3DRTYPE_VOLUMETEXTURE, or D3DRTYPE_CUBETEXTURE. +// ImageFileFormat +// D3DXIMAGE_FILEFORMAT representing the format of the image file. +// +//---------------------------------------------------------------------------- + +typedef struct _D3DXIMAGE_INFO +{ + UINT Width; + UINT Height; + UINT Depth; + UINT MipLevels; + D3DFORMAT Format; + D3DRESOURCETYPE ResourceType; + D3DXIMAGE_FILEFORMAT ImageFileFormat; + +} D3DXIMAGE_INFO; + + + +#ifndef _PALETTEENTRY_DEFINED +#define _PALETTEENTRY_DEFINED + +typedef struct tagPALETTEENTRY { + BYTE peRed; + BYTE peGreen; + BYTE peBlue; + BYTE peFlags; +} PALETTEENTRY, *PPALETTEENTRY, FAR *LPPALETTEENTRY; + +#endif + + +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + + + +////////////////////////////////////////////////////////////////////////////// +// Image File APIs /////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +; +//---------------------------------------------------------------------------- +// GetImageInfoFromFile/Resource: +// ------------------------------ +// Fills in a D3DXIMAGE_INFO struct with information about an image file. +// +// Parameters: +// pSrcFile +// File name of the source image. +// pSrcModule +// Module where resource is located, or NULL for module associated +// with image the os used to create the current process. +// pSrcResource +// Resource name +// pSrcData +// Pointer to file in memory. +// SrcDataSize +// Size in bytes of file in memory. +// pSrcInfo +// Pointer to a D3DXIMAGE_INFO structure to be filled in with the +// description of the data in the source image file. +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXGetImageInfoFromFileA( + __in_z LPCSTR pSrcFile, + __out D3DXIMAGE_INFO* pSrcInfo); + +HRESULT WINAPI + D3DXGetImageInfoFromFileW( + __in_z LPCWSTR pSrcFile, + __out D3DXIMAGE_INFO* pSrcInfo); + +#ifdef UNICODE +#define D3DXGetImageInfoFromFile D3DXGetImageInfoFromFileW +#else +#define D3DXGetImageInfoFromFile D3DXGetImageInfoFromFileA +#endif + +#if 0 // Unsupported on Xbox + +HRESULT WINAPI + D3DXGetImageInfoFromResourceA( + HMODULE hSrcModule, + LPCSTR pSrcResource, + D3DXIMAGE_INFO* pSrcInfo); + +HRESULT WINAPI + D3DXGetImageInfoFromResourceW( + HMODULE hSrcModule, + LPCWSTR pSrcResource, + D3DXIMAGE_INFO* pSrcInfo); + +#ifdef UNICODE +#define D3DXGetImageInfoFromResource D3DXGetImageInfoFromResourceW +#else +#define D3DXGetImageInfoFromResource D3DXGetImageInfoFromResourceA +#endif + +#endif + +HRESULT WINAPI + D3DXGetImageInfoFromFileInMemory( + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + __out D3DXIMAGE_INFO* pSrcInfo); + + + + +////////////////////////////////////////////////////////////////////////////// +// Load/Save Surface APIs //////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +//---------------------------------------------------------------------------- +// D3DXLoadSurfaceFromFile/Resource: +// --------------------------------- +// Load surface from a file or resource +// +// Parameters: +// pDestSurface +// Destination surface, which will receive the image. +// pDestPalette +// Destination palette of 256 colors, or NULL +// pDestRect +// Destination rectangle, or NULL for entire surface +// pSrcFile +// File name of the source image. +// pSrcModule +// Module where resource is located, or NULL for module associated +// with image the os used to create the current process. +// pSrcResource +// Resource name +// pSrcData +// Pointer to file in memory. +// SrcDataSize +// Size in bytes of file in memory. +// pSrcRect +// Source rectangle, or NULL for entire image +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// pSrcInfo +// Pointer to a D3DXIMAGE_INFO structure to be filled in with the +// description of the data in the source image file, or NULL. +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXLoadSurfaceFromFileA( + __in LPDIRECT3DSURFACE9 pDestSurface, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST RECT* pDestRect, + __in_z LPCSTR pSrcFile, + __in_opt CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo); + +HRESULT WINAPI + D3DXLoadSurfaceFromFileW( + __in LPDIRECT3DSURFACE9 pDestSurface, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST RECT* pDestRect, + __in_z LPCWSTR pSrcFile, + __in_opt CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo); + +#ifdef UNICODE +#define D3DXLoadSurfaceFromFile D3DXLoadSurfaceFromFileW +#else +#define D3DXLoadSurfaceFromFile D3DXLoadSurfaceFromFileA +#endif + + +#if 0 // Unsupported on Xbox + +HRESULT WINAPI + D3DXLoadSurfaceFromResourceA( + LPDIRECT3DSURFACE9 pDestSurface, + CONST PALETTEENTRY* pDestPalette, + CONST RECT* pDestRect, + HMODULE hSrcModule, + LPCSTR pSrcResource, + CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo); + +HRESULT WINAPI + D3DXLoadSurfaceFromResourceW( + LPDIRECT3DSURFACE9 pDestSurface, + CONST PALETTEENTRY* pDestPalette, + CONST RECT* pDestRect, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo); + + +#ifdef UNICODE +#define D3DXLoadSurfaceFromResource D3DXLoadSurfaceFromResourceW +#else +#define D3DXLoadSurfaceFromResource D3DXLoadSurfaceFromResourceA +#endif + +#endif + + + +HRESULT WINAPI + D3DXLoadSurfaceFromFileInMemory( + __in LPDIRECT3DSURFACE9 pDestSurface, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST RECT* pDestRect, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + __in_opt CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo); + + + +//---------------------------------------------------------------------------- +// D3DXLoadSurfaceFromSurface: +// --------------------------- +// Load surface from another surface (with color conversion) +// +// Parameters: +// pDestSurface +// Destination surface, which will receive the image. +// pDestPalette +// Destination palette of 256 colors, or NULL +// pDestRect +// Destination rectangle, or NULL for entire surface +// pSrcSurface +// Source surface +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcRect +// Source rectangle, or NULL for entire surface +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXLoadSurfaceFromSurface( + __in LPDIRECT3DSURFACE9 pDestSurface, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST RECT* pDestRect, + __in LPDIRECT3DSURFACE9 pSrcSurface, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST RECT* pSrcRect, + DWORD Filter, + D3DCOLOR ColorKey); + + +//---------------------------------------------------------------------------- +// D3DXLoadSurfaceFromMemory: +// -------------------------- +// Load surface from memory. +// +// Parameters: +// pDestSurface +// Destination surface, which will receive the image. +// pDestPalette +// Destination palette of 256 colors, or NULL +// pDestRect +// Destination rectangle, or NULL for entire surface +// pSrcMemory +// Pointer to the top-left corner of the source image in memory +// SrcFormat +// Pixel format of the source image. +// SrcPitch +// Pitch of source image, in bytes. For DXT formats, this number +// should represent the width of one row of cells, in bytes. +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcRect +// Source rectangle. +// SrcParentPacked +// TRUE if the source image is part of a texture containing a packed +// mip tail, FALSE otherwise. +// SrcParentWidth +// Width of the base texture containing the source image. This +// is ignored if the source image is not tiled or does not contain +// a packed mip tail. +// SrcParentHeight +// Height of the base texture containing the source image. This +// is ignored if the source image is not tiled or does not contain +// a packed mip tail. +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXLoadSurfaceFromMemory( + __in LPDIRECT3DSURFACE9 pDestSurface, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST RECT* pDestRect, + __in LPCVOID pSrcMemory, + D3DFORMAT SrcFormat, + UINT SrcPitch, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST RECT* pSrcRect, + BOOL SrcPacked, + UINT SrcParentWidth, + UINT SrcParentHeight, + DWORD Filter, + D3DCOLOR ColorKey); + + +//---------------------------------------------------------------------------- +// D3DXSaveSurfaceToFile: +// ---------------------- +// Save a surface to a image file. +// +// Parameters: +// pDestFile +// File name of the destination file +// DestFormat +// D3DXIMAGE_FILEFORMAT specifying file format to use when saving. +// pSrcSurface +// Source surface, containing the image to be saved +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcRect +// Source rectangle, or NULL for the entire image +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXSaveSurfaceToFileA( + __in_z LPCSTR pDestFile, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DSURFACE9 pSrcSurface, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST RECT* pSrcRect); + +HRESULT WINAPI + D3DXSaveSurfaceToFileW( + __in_z LPCWSTR pDestFile, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DSURFACE9 pSrcSurface, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST RECT* pSrcRect); + +#ifdef UNICODE +#define D3DXSaveSurfaceToFile D3DXSaveSurfaceToFileW +#else +#define D3DXSaveSurfaceToFile D3DXSaveSurfaceToFileA +#endif + +//---------------------------------------------------------------------------- +// D3DXSaveSurfaceToFileInMemory: +// ---------------------- +// Save a surface to a image file. +// +// Parameters: +// ppDestBuf +// address of pointer to d3dxbuffer for returning data bits +// DestFormat +// D3DXIMAGE_FILEFORMAT specifying file format to use when saving. +// pSrcSurface +// Source surface, containing the image to be saved +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcRect +// Source rectangle, or NULL for the entire image +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXSaveSurfaceToFileInMemory( + __deref_out LPD3DXBUFFER* ppDestBuf, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DSURFACE9 pSrcSurface, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST RECT* pSrcRect); + + +////////////////////////////////////////////////////////////////////////////// +// Load/Save Volume APIs ///////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +//---------------------------------------------------------------------------- +// D3DXLoadVolumeFromFile/Resource: +// -------------------------------- +// Load volume from a file or resource +// +// Parameters: +// pDestVolume +// Destination volume, which will receive the image. +// pDestPalette +// Destination palette of 256 colors, or NULL +// pDestBox +// Destination box, or NULL for entire volume +// pSrcFile +// File name of the source image. +// pSrcModule +// Module where resource is located, or NULL for module associated +// with image the os used to create the current process. +// pSrcResource +// Resource name +// pSrcData +// Pointer to file in memory. +// SrcDataSize +// Size in bytes of file in memory. +// pSrcBox +// Source box, or NULL for entire image +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// pSrcInfo +// Pointer to a D3DXIMAGE_INFO structure to be filled in with the +// description of the data in the source image file, or NULL. +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXLoadVolumeFromFileA( + __in LPDIRECT3DVOLUME9 pDestVolume, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST D3DBOX* pDestBox, + __in_z LPCSTR pSrcFile, + __in_opt CONST D3DBOX* pSrcBox, + DWORD Filter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo); + +HRESULT WINAPI + D3DXLoadVolumeFromFileW( + __in LPDIRECT3DVOLUME9 pDestVolume, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST D3DBOX* pDestBox, + __in_z LPCWSTR pSrcFile, + __in_opt CONST D3DBOX* pSrcBox, + DWORD Filter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo); + +#ifdef UNICODE +#define D3DXLoadVolumeFromFile D3DXLoadVolumeFromFileW +#else +#define D3DXLoadVolumeFromFile D3DXLoadVolumeFromFileA +#endif + + +#if 0 // Unsupported on Xbox + +HRESULT WINAPI + D3DXLoadVolumeFromResourceA( + LPDIRECT3DVOLUME9 pDestVolume, + CONST PALETTEENTRY* pDestPalette, + CONST D3DBOX* pDestBox, + HMODULE hSrcModule, + LPCSTR pSrcResource, + CONST D3DBOX* pSrcBox, + DWORD Filter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo); + +HRESULT WINAPI + D3DXLoadVolumeFromResourceW( + LPDIRECT3DVOLUME9 pDestVolume, + CONST PALETTEENTRY* pDestPalette, + CONST D3DBOX* pDestBox, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + CONST D3DBOX* pSrcBox, + DWORD Filter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo); + +#ifdef UNICODE +#define D3DXLoadVolumeFromResource D3DXLoadVolumeFromResourceW +#else +#define D3DXLoadVolumeFromResource D3DXLoadVolumeFromResourceA +#endif + +#endif + + +HRESULT WINAPI + D3DXLoadVolumeFromFileInMemory( + __in LPDIRECT3DVOLUME9 pDestVolume, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST D3DBOX* pDestBox, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + __in_opt CONST D3DBOX* pSrcBox, + DWORD Filter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo); + + + +//---------------------------------------------------------------------------- +// D3DXLoadVolumeFromVolume: +// ------------------------- +// Load volume from another volume (with color conversion) +// +// Parameters: +// pDestVolume +// Destination volume, which will receive the image. +// pDestPalette +// Destination palette of 256 colors, or NULL +// pDestBox +// Destination box, or NULL for entire volume +// pSrcVolume +// Source volume +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcBox +// Source box, or NULL for entire volume +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXLoadVolumeFromVolume( + __in LPDIRECT3DVOLUME9 pDestVolume, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST D3DBOX* pDestBox, + __in LPDIRECT3DVOLUME9 pSrcVolume, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST D3DBOX* pSrcBox, + DWORD Filter, + D3DCOLOR ColorKey); + + + +//---------------------------------------------------------------------------- +// D3DXLoadVolumeFromMemory: +// ------------------------- +// Load volume from memory. +// +// Parameters: +// pDestVolume +// Destination volume, which will receive the image. +// pDestPalette +// Destination palette of 256 colors, or NULL +// pDestBox +// Destination box, or NULL for entire volume +// pSrcMemory +// Pointer to the top-left corner of the source volume in memory +// SrcFormat +// Pixel format of the source volume. +// SrcRowPitch +// Pitch of source image, in bytes. For DXT formats, this number +// should represent the size of one row of cells, in bytes. +// SrcSlicePitch +// Pitch of source image, in bytes. For DXT formats, this number +// should represent the size of one slice of cells, in bytes. +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcBox +// Source box. +// SrcParentPacked +// TRUE if the source volume is part of a texture containing a packed +// mip tail, FALSE otherwise. +// SrcParentWidth +// Width of the base texture containing the source volume. This +// is ignored if the source volume is not tiled or does not contain +// a packed mip tail. +// SrcParentHeight +// Height of the base texture containing the source volume. This +// is ignored if the source volume is not tiled or does not contain +// a packed mip tail. +// SrcParentDepth +// Depth of the base texture containing the source volume. This +// is ignored if the source volume is not tiled or does not contain +// a packed mip tail. +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXLoadVolumeFromMemory( + __in LPDIRECT3DVOLUME9 pDestVolume, + __in_opt CONST PALETTEENTRY* pDestPalette, + __in_opt CONST D3DBOX* pDestBox, + __in LPCVOID pSrcMemory, + D3DFORMAT SrcFormat, + UINT SrcRowPitch, + UINT SrcSlicePitch, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST D3DBOX* pSrcBox, + BOOL SrcParentPacked, + UINT SrcParentWidth, + UINT SrcParentHeight, + UINT SrcParentDepth, + DWORD Filter, + D3DCOLOR ColorKey); + + + +//---------------------------------------------------------------------------- +// D3DXSaveVolumeToFile: +// --------------------- +// Save a volume to a image file. +// +// Parameters: +// pDestFile +// File name of the destination file +// DestFormat +// D3DXIMAGE_FILEFORMAT specifying file format to use when saving. +// pSrcVolume +// Source volume, containing the image to be saved +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcBox +// Source box, or NULL for the entire volume +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXSaveVolumeToFileA( + __in_z LPCSTR pDestFile, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DVOLUME9 pSrcVolume, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST D3DBOX* pSrcBox); + +HRESULT WINAPI + D3DXSaveVolumeToFileW( + __in_z LPCWSTR pDestFile, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DVOLUME9 pSrcVolume, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST D3DBOX* pSrcBox); + +#ifdef UNICODE +#define D3DXSaveVolumeToFile D3DXSaveVolumeToFileW +#else +#define D3DXSaveVolumeToFile D3DXSaveVolumeToFileA +#endif + + +//---------------------------------------------------------------------------- +// D3DXSaveVolumeToFileInMemory: +// --------------------- +// Save a volume to a image file. +// +// Parameters: +// pDestFile +// File name of the destination file +// DestFormat +// D3DXIMAGE_FILEFORMAT specifying file format to use when saving. +// pSrcVolume +// Source volume, containing the image to be saved +// pSrcPalette +// Source palette of 256 colors, or NULL +// pSrcBox +// Source box, or NULL for the entire volume +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXSaveVolumeToFileInMemory( + __deref_out LPD3DXBUFFER* ppDestBuf, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DVOLUME9 pSrcVolume, + __in_opt CONST PALETTEENTRY* pSrcPalette, + __in_opt CONST D3DBOX* pSrcBox); + +////////////////////////////////////////////////////////////////////////////// +// Create/Save Texture APIs ////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +//---------------------------------------------------------------------------- +// D3DXCheckTextureRequirements: +// ----------------------------- +// Checks texture creation parameters. If parameters are invalid, this +// function returns corrected parameters. +// +// Parameters: +// +// pDevice +// The D3D device to be used +// pWidth, pHeight, pDepth, pSize +// Desired size in pixels, or NULL. Returns corrected size. +// pNumMipLevels +// Number of desired mipmap levels, or NULL. Returns corrected number. +// Usage +// Texture usage flags +// pFormat +// Desired pixel format, or NULL. Returns corrected format. +// Pool +// Memory pool to be used to create texture +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXCheckTextureRequirements( + __in LPDIRECT3DDEVICE9 pDevice, + __inout_opt UINT* pWidth, + __inout_opt UINT* pHeight, + __inout_opt UINT* pNumMipLevels, + DWORD Usage, + __inout_opt D3DFORMAT* pFormat, + D3DPOOL Pool); + +HRESULT WINAPI + D3DXCheckCubeTextureRequirements( + __in LPDIRECT3DDEVICE9 pDevice, + __inout_opt UINT* pSize, + __inout_opt UINT* pNumMipLevels, + DWORD Usage, + __inout_opt D3DFORMAT* pFormat, + D3DPOOL Pool); + +HRESULT WINAPI + D3DXCheckVolumeTextureRequirements( + __in LPDIRECT3DDEVICE9 pDevice, + __inout_opt UINT* pWidth, + __inout_opt UINT* pHeight, + __inout_opt UINT* pDepth, + __inout_opt UINT* pNumMipLevels, + DWORD Usage, + __inout_opt D3DFORMAT* pFormat, + D3DPOOL Pool); + + +//---------------------------------------------------------------------------- +// D3DXCreateTexture: +// ------------------ +// Create an empty texture +// +// Parameters: +// +// pDevice +// The D3D device with which the texture is going to be used. +// Width, Height, Depth, Size +// size in pixels. these must be non-zero +// MipLevels +// number of mip levels desired. if zero or D3DX_DEFAULT, a complete +// mipmap chain will be created. +// Usage +// Texture usage flags +// Format +// Pixel format. +// Pool +// Memory pool to be used to create texture +// ppTexture, ppCubeTexture, ppVolumeTexture +// The texture object that will be created +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXCreateTexture( + __in LPDIRECT3DDEVICE9 pDevice, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateCubeTexture( + __in LPDIRECT3DDEVICE9 pDevice, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTexture( + __in LPDIRECT3DDEVICE9 pDevice, + UINT Width, + UINT Height, + UINT Depth, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + + + +//---------------------------------------------------------------------------- +// D3DXCreateTextureFromFile/Resource: +// ----------------------------------- +// Create a texture object from a file or resource. +// +// Parameters: +// +// pDevice +// The D3D device with which the texture is going to be used. +// pSrcFile +// File name. +// hSrcModule +// Module handle. if NULL, current module will be used. +// pSrcResource +// Resource name in module +// pvSrcData +// Pointer to file in memory. +// SrcDataSize +// Size in bytes of file in memory. +// Width, Height, Depth, Size +// Size in pixels. If zero or D3DX_DEFAULT, the size will be taken from +// the file and rounded up to a power of two. If D3DX_DEFAULT_NONPOW2, +// the size will be not be rounded, if the device supports NONPOW2 textures. +// MipLevels +// Number of mip levels. If zero or D3DX_DEFAULT, a complete mipmap +// chain will be created. +// Usage +// Texture usage flags +// Format +// Desired pixel format. If D3DFMT_UNKNOWN, the format will be +// taken from the file. +// Pool +// Memory pool to be used to create texture +// Filter +// D3DX_FILTER flags controlling how the image is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_TRIANGLE. +// MipFilter +// D3DX_FILTER flags controlling how each miplevel is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_BOX, +// ColorKey +// Color to replace with transparent black, or 0 to disable colorkey. +// This is always a 32-bit ARGB color, independent of the source image +// format. Alpha is significant, and should usually be set to FF for +// opaque colorkeys. (ex. Opaque black == 0xff000000) +// pSrcInfo +// Pointer to a D3DXIMAGE_INFO structure to be filled in with the +// description of the data in the source image file, or NULL. +// pPalette +// 256 color palette to be filled in, or NULL +// ppTexture, ppCubeTexture, ppVolumeTexture +// The texture object that will be created +// +//---------------------------------------------------------------------------- + + +// FromFile + +HRESULT WINAPI + D3DXCreateTextureFromFileA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateTextureFromFileW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +#ifdef UNICODE +#define D3DXCreateTextureFromFile D3DXCreateTextureFromFileW +#else +#define D3DXCreateTextureFromFile D3DXCreateTextureFromFileA +#endif + + +HRESULT WINAPI + D3DXCreateCubeTextureFromFileA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateCubeTextureFromFileW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +#ifdef UNICODE +#define D3DXCreateCubeTextureFromFile D3DXCreateCubeTextureFromFileW +#else +#define D3DXCreateCubeTextureFromFile D3DXCreateCubeTextureFromFileA +#endif + + +HRESULT WINAPI + D3DXCreateVolumeTextureFromFileA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTextureFromFileW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +#ifdef UNICODE +#define D3DXCreateVolumeTextureFromFile D3DXCreateVolumeTextureFromFileW +#else +#define D3DXCreateVolumeTextureFromFile D3DXCreateVolumeTextureFromFileA +#endif + + +// FromResource + +#if 0 // Unsupported on Xbox + +HRESULT WINAPI + D3DXCreateTextureFromResourceA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateTextureFromResourceW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + LPDIRECT3DTEXTURE9* ppTexture); + +#ifdef UNICODE +#define D3DXCreateTextureFromResource D3DXCreateTextureFromResourceW +#else +#define D3DXCreateTextureFromResource D3DXCreateTextureFromResourceA +#endif + + +HRESULT WINAPI + D3DXCreateCubeTextureFromResourceA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateCubeTextureFromResourceW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +#ifdef UNICODE +#define D3DXCreateCubeTextureFromResource D3DXCreateCubeTextureFromResourceW +#else +#define D3DXCreateCubeTextureFromResource D3DXCreateCubeTextureFromResourceA +#endif + + +HRESULT WINAPI + D3DXCreateVolumeTextureFromResourceA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTextureFromResourceW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +#ifdef UNICODE +#define D3DXCreateVolumeTextureFromResource D3DXCreateVolumeTextureFromResourceW +#else +#define D3DXCreateVolumeTextureFromResource D3DXCreateVolumeTextureFromResourceA +#endif + +#endif // 0 + +// FromFileEx + +HRESULT WINAPI + D3DXCreateTextureFromFileExA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateTextureFromFileExW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +#ifdef UNICODE +#define D3DXCreateTextureFromFileEx D3DXCreateTextureFromFileExW +#else +#define D3DXCreateTextureFromFileEx D3DXCreateTextureFromFileExA +#endif + + +HRESULT WINAPI + D3DXCreateCubeTextureFromFileExA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateCubeTextureFromFileExW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +#ifdef UNICODE +#define D3DXCreateCubeTextureFromFileEx D3DXCreateCubeTextureFromFileExW +#else +#define D3DXCreateCubeTextureFromFileEx D3DXCreateCubeTextureFromFileExA +#endif + + +HRESULT WINAPI + D3DXCreateVolumeTextureFromFileExA( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCSTR pSrcFile, + UINT Width, + UINT Height, + UINT Depth, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTextureFromFileExW( + __in LPDIRECT3DDEVICE9 pDevice, + __in_z LPCWSTR pSrcFile, + UINT Width, + UINT Height, + UINT Depth, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +#ifdef UNICODE +#define D3DXCreateVolumeTextureFromFileEx D3DXCreateVolumeTextureFromFileExW +#else +#define D3DXCreateVolumeTextureFromFileEx D3DXCreateVolumeTextureFromFileExA +#endif + + +// FromResourceEx + +#if 0 // Unsupported on Xbox + +HRESULT WINAPI + D3DXCreateTextureFromResourceExA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo, + PALETTEENTRY* pPalette, + LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateTextureFromResourceExW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo, + PALETTEENTRY* pPalette, + LPDIRECT3DTEXTURE9* ppTexture); + +#ifdef UNICODE +#define D3DXCreateTextureFromResourceEx D3DXCreateTextureFromResourceExW +#else +#define D3DXCreateTextureFromResourceEx D3DXCreateTextureFromResourceExA +#endif + + +HRESULT WINAPI + D3DXCreateCubeTextureFromResourceExA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo, + PALETTEENTRY* pPalette, + LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateCubeTextureFromResourceExW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo, + PALETTEENTRY* pPalette, + LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +#ifdef UNICODE +#define D3DXCreateCubeTextureFromResourceEx D3DXCreateCubeTextureFromResourceExW +#else +#define D3DXCreateCubeTextureFromResourceEx D3DXCreateCubeTextureFromResourceExA +#endif + + +HRESULT WINAPI + D3DXCreateVolumeTextureFromResourceExA( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCSTR pSrcResource, + UINT Width, + UINT Height, + UINT Depth, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo, + PALETTEENTRY* pPalette, + LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTextureFromResourceExW( + LPDIRECT3DDEVICE9 pDevice, + HMODULE hSrcModule, + LPCWSTR pSrcResource, + UINT Width, + UINT Height, + UINT Depth, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + D3DXIMAGE_INFO* pSrcInfo, + PALETTEENTRY* pPalette, + LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + +#ifdef UNICODE +#define D3DXCreateVolumeTextureFromResourceEx D3DXCreateVolumeTextureFromResourceExW +#else +#define D3DXCreateVolumeTextureFromResourceEx D3DXCreateVolumeTextureFromResourceExA +#endif + +#endif // 0 + +// FromFileInMemory + +HRESULT WINAPI + D3DXCreateTextureFromFileInMemory( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateCubeTextureFromFileInMemory( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTextureFromFileInMemory( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + + +// FromFileInMemoryEx + +HRESULT WINAPI + D3DXCreateTextureFromFileInMemoryEx( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + UINT Width, + UINT Height, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DTEXTURE9* ppTexture); + +HRESULT WINAPI + D3DXCreateCubeTextureFromFileInMemoryEx( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + UINT Size, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DCUBETEXTURE9* ppCubeTexture); + +HRESULT WINAPI + D3DXCreateVolumeTextureFromFileInMemoryEx( + __in LPDIRECT3DDEVICE9 pDevice, + __in_bcount(SrcDataSize) LPCVOID pSrcData, + UINT SrcDataSize, + UINT Width, + UINT Height, + UINT Depth, + UINT MipLevels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + DWORD Filter, + DWORD MipFilter, + D3DCOLOR ColorKey, + __out_opt D3DXIMAGE_INFO* pSrcInfo, + __out_opt PALETTEENTRY* pPalette, + __deref_out LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture); + + + +//---------------------------------------------------------------------------- +// D3DXSaveTextureToFile: +// ---------------------- +// Save a texture to a file. +// +// Parameters: +// pDestFile +// File name of the destination file +// DestFormat +// D3DXIMAGE_FILEFORMAT specifying file format to use when saving. +// pSrcTexture +// Source texture, containing the image to be saved +// pSrcPalette +// Source palette of 256 colors, or NULL +// +//---------------------------------------------------------------------------- + + +HRESULT WINAPI + D3DXSaveTextureToFileA( + __in_z LPCSTR pDestFile, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DBASETEXTURE9 pSrcTexture, + __in_opt CONST PALETTEENTRY* pSrcPalette); + +HRESULT WINAPI + D3DXSaveTextureToFileW( + __in_z LPCWSTR pDestFile, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DBASETEXTURE9 pSrcTexture, + __in_opt CONST PALETTEENTRY* pSrcPalette); + +#ifdef UNICODE +#define D3DXSaveTextureToFile D3DXSaveTextureToFileW +#else +#define D3DXSaveTextureToFile D3DXSaveTextureToFileA +#endif + + +//---------------------------------------------------------------------------- +// D3DXSaveTextureToFileInMemory: +// ---------------------- +// Save a texture to a file. +// +// Parameters: +// ppDestBuf +// address of a d3dxbuffer pointer to return the image data +// DestFormat +// D3DXIMAGE_FILEFORMAT specifying file format to use when saving. +// pSrcTexture +// Source texture, containing the image to be saved +// pSrcPalette +// Source palette of 256 colors, or NULL +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXSaveTextureToFileInMemory( + __deref_out LPD3DXBUFFER* ppDestBuf, + D3DXIMAGE_FILEFORMAT DestFormat, + __in LPDIRECT3DBASETEXTURE9 pSrcTexture, + __in_opt CONST PALETTEENTRY* pSrcPalette); + + + + +////////////////////////////////////////////////////////////////////////////// +// Misc Texture APIs ///////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +//---------------------------------------------------------------------------- +// D3DXFilterTexture: +// ------------------ +// Filters mipmaps levels of a texture. +// +// Parameters: +// pBaseTexture +// The texture object to be filtered +// pPalette +// 256 color palette to be used, or NULL for non-palettized formats +// SrcLevel +// The level whose image is used to generate the subsequent levels. +// Filter +// D3DX_FILTER flags controlling how each miplevel is filtered. +// Or D3DX_DEFAULT for D3DX_FILTER_BOX, +// +//---------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXFilterTexture( + __in LPDIRECT3DBASETEXTURE9 pBaseTexture, + __in_opt CONST PALETTEENTRY* pPalette, + UINT SrcLevel, + DWORD Filter); + +#define D3DXFilterCubeTexture D3DXFilterTexture +#define D3DXFilterVolumeTexture D3DXFilterTexture + + + +//---------------------------------------------------------------------------- +// D3DXFillTexture: +// ---------------- +// Uses a user provided function to fill each texel of each mip level of a +// given texture. +// +// Paramters: +// pTexture, pCubeTexture, pVolumeTexture +// Pointer to the texture to be filled. +// pFunction +// Pointer to user provided evalutor function which will be used to +// compute the value of each texel. +// pData +// Pointer to an arbitrary block of user defined data. This pointer +// will be passed to the function provided in pFunction +//----------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXFillTexture( + __in LPDIRECT3DTEXTURE9 pTexture, + __in LPD3DXFILL2D pFunction, + __in_opt LPVOID pData); + +HRESULT WINAPI + D3DXFillCubeTexture( + __in LPDIRECT3DCUBETEXTURE9 pCubeTexture, + __in LPD3DXFILL3D pFunction, + __in_opt LPVOID pData); + +HRESULT WINAPI + D3DXFillVolumeTexture( + __in LPDIRECT3DVOLUMETEXTURE9 pVolumeTexture, + __in LPD3DXFILL3D pFunction, + __in_opt LPVOID pData); + +//---------------------------------------------------------------------------- +// D3DXFillTextureTX: +// ---------------- +// Uses a TX Shader target to function to fill each texel of each mip level of a +// given texture. The TX Shader target should be a compiled function taking 2 +// 2 paramters and returning a float4 color. +// +// Paramters: +// pTexture, pCubeTexture, pVolumeTexture +// Pointer to the texture to be filled. +// pFunction: +// Pointer to the compiled function returned by D3DX +// pConstants +// Constants used by program. Should be filled by user by parsing constant +// Table information +// Constants +// Number of Constants +//----------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXFillTextureTX( + __in LPDIRECT3DTEXTURE9 pTexture, + __in CONST DWORD* pFunction, + __in_ecount_opt(Constants) CONST D3DXVECTOR4* pConstants, + UINT Constants); + + +HRESULT WINAPI + D3DXFillCubeTextureTX( + __in LPDIRECT3DCUBETEXTURE9 pCubeTexture, + __in CONST DWORD* pFunction, + __in_ecount_opt(Constants) CONST D3DXVECTOR4* pConstants, + UINT Constants); + + +HRESULT WINAPI + D3DXFillVolumeTextureTX( + __in LPDIRECT3DVOLUMETEXTURE9 pVolumeTexture, + __in CONST DWORD* pFunction, + __in_ecount_opt(Constants) CONST D3DXVECTOR4* pConstants, + UINT Constants); + + +//---------------------------------------------------------------------------- +// D3DXComputeNormalMap: +// --------------------- +// Converts a height map into a normal map. The (x,y,z) components of each +// normal are mapped to the (r,g,b) channels of the output texture. +// +// Parameters +// pTexture +// Pointer to the destination texture +// pSrcTexture +// Pointer to the source heightmap texture +// pSrcPalette +// Source palette of 256 colors, or NULL +// Flags +// D3DX_NORMALMAP flags +// Channel +// D3DX_CHANNEL specifying source of height information +// Amplitude +// The constant value which the height information is multiplied by. +//--------------------------------------------------------------------------- + +HRESULT WINAPI + D3DXComputeNormalMap( + __in LPDIRECT3DTEXTURE9 pTexture, + __in LPDIRECT3DTEXTURE9 pSrcTexture, + __in_opt CONST PALETTEENTRY* pSrcPalette, + DWORD Flags, + DWORD Channel, + FLOAT Amplitude); + + + + +#ifdef __cplusplus +} +#endif //__cplusplus + +#endif //__D3DX9TEX_H__ + diff --git a/third_party/xbox_sdk/include/d3dx9xof.h b/third_party/xbox_sdk/include/d3dx9xof.h new file mode 100644 index 0000000..f857a7e --- /dev/null +++ b/third_party/xbox_sdk/include/d3dx9xof.h @@ -0,0 +1,298 @@ +/////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Microsoft Corporation. All Rights Reserved. +// +// File: d3dx9xof.h +// Content: D3DX .X File types and functions +// +/////////////////////////////////////////////////////////////////////////// + +#include "d3dx9.h" + +#if !defined( __D3DX9XOF_H__ ) +#define __D3DX9XOF_H__ + +#if defined( __cplusplus ) +extern "C" { +#endif // defined( __cplusplus ) + +//---------------------------------------------------------------------------- +// D3DXF_FILEFORMAT +// This flag is used to specify what file type to use when saving to disk. +// _LEGACYBINARY, _BINARY, and _TEXT are mutually exclusive, while +// _COMPRESSED is an optional setting that works with all file types. +//---------------------------------------------------------------------------- +typedef DWORD D3DXF_FILEFORMAT; + +#define D3DXF_FILEFORMAT_LEGACYBINARY 0 +#define D3DXF_FILEFORMAT_BINARY 1 +#define D3DXF_FILEFORMAT_TEXT 2 +#define D3DXF_FILEFORMAT_COMPRESSED 4 +#define D3DXF_FILEFORMAT_VALID 0x7 // internal (this is a mask) + +//---------------------------------------------------------------------------- +// D3DXF_FILESAVEOPTIONS +// This flag is used to specify where to save the file to. Each flag is +// mutually exclusive, indicates the data location of the file, and also +// chooses which additional data will specify the location. +// _TOFILE is paired with a filename (LPCSTR) +// _TOWFILE is paired with a filename (LPWSTR) +//---------------------------------------------------------------------------- +typedef DWORD D3DXF_FILESAVEOPTIONS; + +#define D3DXF_FILESAVE_TOFILE 0x00L +#define D3DXF_FILESAVE_TOWFILE 0x01L +#define D3DXF_FILESAVE_VALID 0x01L // internal + +//---------------------------------------------------------------------------- +// D3DXF_FILELOADOPTIONS +// This flag is used to specify where to load the file from. Each flag is +// mutually exclusive, indicates the data location of the file, and also +// chooses which additional data will specify the location. +// _FROMFILE is paired with a filename (LPCSTR) +// _FROMWFILE is paired with a filename (LPWSTR) +// _FROMRESOURCE is paired with a (D3DXF_FILELOADRESOUCE*) description. +// _FROMMEMORY is paired with a (D3DXF_FILELOADMEMORY*) description. +//---------------------------------------------------------------------------- +typedef DWORD D3DXF_FILELOADOPTIONS; + +#define D3DXF_FILELOAD_FROMFILE 0x00L +#define D3DXF_FILELOAD_FROMWFILE 0x01L +#define D3DXF_FILELOAD_FROMRESOURCE 0x02L +#define D3DXF_FILELOAD_FROMMEMORY 0x03L + +//---------------------------------------------------------------------------- +// D3DXF_FILELOADRESOURCE: +//---------------------------------------------------------------------------- + +typedef struct _D3DXF_FILELOADRESOURCE +{ + HMODULE hModule; // Desc + LPCSTR lpName; // Desc + LPCSTR lpType; // Desc +} D3DXF_FILELOADRESOURCE; + +//---------------------------------------------------------------------------- +// D3DXF_FILELOADMEMORY: +//---------------------------------------------------------------------------- + +typedef struct _D3DXF_FILELOADMEMORY +{ + LPCVOID lpMemory; // Desc + SIZE_T dSize; // Desc +} D3DXF_FILELOADMEMORY; + +#if defined( _WIN32 ) && !defined( _NO_COM ) + +// {cef08cf9-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_ID3DXFile, +0xcef08cf9, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// {cef08cfa-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_ID3DXFileSaveObject, +0xcef08cfa, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// {cef08cfb-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_ID3DXFileSaveData, +0xcef08cfb, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// {cef08cfc-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_ID3DXFileEnumObject, +0xcef08cfc, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// {cef08cfd-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_ID3DXFileData, +0xcef08cfd, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// begin internal +// {cef08cfe-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_TEnumObject, +0xcef08cfe, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// {cef08cff-7b4f-4429-9624-2a690a933201} +DEFINE_GUID( IID_TBinaryLoad, +0xcef08cff, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 ); + +// end_internal +#endif // defined( _WIN32 ) && !defined( _NO_COM ) + +#if defined( __cplusplus ) +#if !defined( DECLSPEC_UUID ) +#if _MSC_VER >= 1100 +#define DECLSPEC_UUID( x ) __declspec( uuid( x ) ) +#else // !( _MSC_VER >= 1100 ) +#define DECLSPEC_UUID( x ) +#endif // !( _MSC_VER >= 1100 ) +#endif // !defined( DECLSPEC_UUID ) + +interface DECLSPEC_UUID( "cef08cf9-7b4f-4429-9624-2a690a933201" ) + ID3DXFile; +interface DECLSPEC_UUID( "cef08cfa-7b4f-4429-9624-2a690a933201" ) + ID3DXFileSaveObject; +interface DECLSPEC_UUID( "cef08cfb-7b4f-4429-9624-2a690a933201" ) + ID3DXFileSaveData; +interface DECLSPEC_UUID( "cef08cfc-7b4f-4429-9624-2a690a933201" ) + ID3DXFileEnumObject; +interface DECLSPEC_UUID( "cef08cfd-7b4f-4429-9624-2a690a933201" ) + ID3DXFileData; + +#if defined( _COM_SMARTPTR_TYPEDEF ) +_COM_SMARTPTR_TYPEDEF( ID3DXFile, + __uuidof( ID3DXFile ) ); +_COM_SMARTPTR_TYPEDEF( ID3DXFileSaveObject, + __uuidof( ID3DXFileSaveObject ) ); +_COM_SMARTPTR_TYPEDEF( ID3DXFileSaveData, + __uuidof( ID3DXFileSaveData ) ); +_COM_SMARTPTR_TYPEDEF( ID3DXFileEnumObject, + __uuidof( ID3DXFileEnumObject ) ); +_COM_SMARTPTR_TYPEDEF( ID3DXFileData, + __uuidof( ID3DXFileData ) ); +#endif // defined( _COM_SMARTPTR_TYPEDEF ) +#endif // defined( __cplusplus ) + +typedef interface ID3DXFile ID3DXFile; +typedef interface ID3DXFileSaveObject ID3DXFileSaveObject; +typedef interface ID3DXFileSaveData ID3DXFileSaveData; +typedef interface ID3DXFileEnumObject ID3DXFileEnumObject; +typedef interface ID3DXFileData ID3DXFileData; + +////////////////////////////////////////////////////////////////////////////// +// ID3DXFile ///////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +#undef INTERFACE +#define INTERFACE ID3DXFile + +DECLARE_INTERFACE_( ID3DXFile, IUnknown ) +{ + STDMETHOD( QueryInterface )( THIS_ REFIID, __deref_out LPVOID* ) PURE; + STDMETHOD_( ULONG, AddRef )( THIS ) PURE; + STDMETHOD_( ULONG, Release )( THIS ) PURE; + + STDMETHOD( CreateEnumObject )( THIS_ __in LPCVOID, D3DXF_FILELOADOPTIONS, + __deref_out ID3DXFileEnumObject** ) PURE; + STDMETHOD( CreateSaveObject )( THIS_ __in LPCVOID, D3DXF_FILESAVEOPTIONS, + D3DXF_FILEFORMAT, __deref_out ID3DXFileSaveObject** ) PURE; + STDMETHOD( RegisterTemplates )( THIS_ __in LPCVOID, SIZE_T) PURE; + STDMETHOD( RegisterEnumTemplates )( THIS_ __in ID3DXFileEnumObject* ) PURE; +}; + +////////////////////////////////////////////////////////////////////////////// +// ID3DXFileSaveObject /////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +#undef INTERFACE +#define INTERFACE ID3DXFileSaveObject + +DECLARE_INTERFACE_( ID3DXFileSaveObject, IUnknown ) +{ + STDMETHOD( QueryInterface )( THIS_ REFIID, __deref_out LPVOID* ) PURE; + STDMETHOD_( ULONG, AddRef )( THIS ) PURE; + STDMETHOD_( ULONG, Release )( THIS ) PURE; + + STDMETHOD( GetFile )( THIS_ __deref_out ID3DXFile** ) PURE; + STDMETHOD( AddDataObject )( THIS_ REFGUID, __in_z LPCSTR, __in CONST GUID*, + SIZE_T, __in LPCVOID, __deref_out ID3DXFileSaveData** ) PURE; + STDMETHOD( Save )( THIS ) PURE; +}; + +////////////////////////////////////////////////////////////////////////////// +// ID3DXFileSaveData ///////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +#undef INTERFACE +#define INTERFACE ID3DXFileSaveData + +DECLARE_INTERFACE_( ID3DXFileSaveData, IUnknown ) +{ + STDMETHOD( QueryInterface )( THIS_ REFIID, __deref_out LPVOID* ) PURE; + STDMETHOD_( ULONG, AddRef )( THIS ) PURE; + STDMETHOD_( ULONG, Release )( THIS ) PURE; + + STDMETHOD( GetSave )( THIS_ __deref_out ID3DXFileSaveObject** ) PURE; + STDMETHOD( GetName )( THIS_ __out_z LPSTR, __out SIZE_T* ) PURE; + STDMETHOD( GetId )( THIS_ __out LPGUID ) PURE; + STDMETHOD( GetType )( THIS_ __out GUID* ) PURE; + STDMETHOD( AddDataObject )( THIS_ REFGUID, __in_z LPCSTR, __in CONST GUID*, + SIZE_T, __in LPCVOID, __deref_out ID3DXFileSaveData** ) PURE; + STDMETHOD( AddDataReference )( THIS_ __in_z LPCSTR, __in CONST GUID* ) PURE; +}; + +////////////////////////////////////////////////////////////////////////////// +// ID3DXFileEnumObject /////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +#undef INTERFACE +#define INTERFACE ID3DXFileEnumObject + +DECLARE_INTERFACE_( ID3DXFileEnumObject, IUnknown ) +{ + STDMETHOD( QueryInterface )( THIS_ REFIID, __deref_out LPVOID* ) PURE; + STDMETHOD_( ULONG, AddRef )( THIS ) PURE; + STDMETHOD_( ULONG, Release )( THIS ) PURE; + + STDMETHOD( GetFile )( THIS_ __deref_out ID3DXFile** ) PURE; + STDMETHOD( GetChildren )( THIS_ __out SIZE_T* ) PURE; + STDMETHOD( GetChild )( THIS_ SIZE_T, __deref_out ID3DXFileData** ) PURE; + STDMETHOD( GetDataObjectById )( THIS_ REFGUID, __deref_out ID3DXFileData** ) PURE; + STDMETHOD( GetDataObjectByName )( THIS_ __in_z LPCSTR, __deref_out ID3DXFileData** ) PURE; +}; + +////////////////////////////////////////////////////////////////////////////// +// ID3DXFileData ///////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +#undef INTERFACE +#define INTERFACE ID3DXFileData + +DECLARE_INTERFACE_( ID3DXFileData, IUnknown ) +{ + STDMETHOD( QueryInterface )( THIS_ REFIID, __deref_out LPVOID* ) PURE; + STDMETHOD_( ULONG, AddRef )( THIS ) PURE; + STDMETHOD_( ULONG, Release )( THIS ) PURE; + + STDMETHOD( GetEnum )( THIS_ __deref_out ID3DXFileEnumObject** ) PURE; + STDMETHOD( GetName )( THIS_ __out_z LPSTR, __out SIZE_T* ) PURE; + STDMETHOD( GetId )( THIS_ __out LPGUID ) PURE; + STDMETHOD( Lock )( THIS_ __out SIZE_T*, __deref_out LPCVOID* ) PURE; + STDMETHOD( Unlock )( THIS ) PURE; + STDMETHOD( GetType )( THIS_ __out GUID* ) PURE; + STDMETHOD( IsReference )( THIS ) PURE; + STDMETHOD( GetChildren )( THIS_ __out SIZE_T* ) PURE; + STDMETHOD( GetChild )( THIS_ SIZE_T, __deref_out ID3DXFileData** ) PURE; +}; + +STDAPI D3DXFileCreate( __deref_out ID3DXFile** lplpDirectXFile ); + +/* + * DirectX File errors. + */ + +#define _FACD3DXF 0x876 + +#define D3DXFERR_BADOBJECT MAKE_HRESULT( 1, _FACD3DXF, 850 ) +#define D3DXFERR_BADVALUE MAKE_HRESULT( 1, _FACD3DXF, 851 ) +#define D3DXFERR_BADTYPE MAKE_HRESULT( 1, _FACD3DXF, 852 ) +#define D3DXFERR_NOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 853 ) +#define D3DXFERR_NOTDONEYET MAKE_HRESULT( 1, _FACD3DXF, 854 ) +#define D3DXFERR_FILENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 855 ) +#define D3DXFERR_RESOURCENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 856 ) +#define D3DXFERR_BADRESOURCE MAKE_HRESULT( 1, _FACD3DXF, 857 ) +#define D3DXFERR_BADFILETYPE MAKE_HRESULT( 1, _FACD3DXF, 858 ) +#define D3DXFERR_BADFILEVERSION MAKE_HRESULT( 1, _FACD3DXF, 859 ) +#define D3DXFERR_BADFILEFLOATSIZE MAKE_HRESULT( 1, _FACD3DXF, 860 ) +#define D3DXFERR_BADFILE MAKE_HRESULT( 1, _FACD3DXF, 861 ) +#define D3DXFERR_PARSEERROR MAKE_HRESULT( 1, _FACD3DXF, 862 ) +#define D3DXFERR_BADARRAYSIZE MAKE_HRESULT( 1, _FACD3DXF, 863 ) +#define D3DXFERR_BADDATAREFERENCE MAKE_HRESULT( 1, _FACD3DXF, 864 ) +#define D3DXFERR_NOMOREOBJECTS MAKE_HRESULT( 1, _FACD3DXF, 865 ) +#define D3DXFERR_NOMOREDATA MAKE_HRESULT( 1, _FACD3DXF, 866 ) +#define D3DXFERR_BADCACHEFILE MAKE_HRESULT( 1, _FACD3DXF, 867 ) + +#if defined( __cplusplus ) +} // extern "C" +#endif // defined( __cplusplus ) + +#endif // !defined( __D3DX9XOF_H__ ) + + diff --git a/third_party/xbox_sdk/include/dxfile.h b/third_party/xbox_sdk/include/dxfile.h new file mode 100644 index 0000000..5220482 --- /dev/null +++ b/third_party/xbox_sdk/include/dxfile.h @@ -0,0 +1,239 @@ +/*************************************************************************** + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: dxfile.h + * + * Content: DirectX File public header file + * + ***************************************************************************/ + +#ifndef __DXFILE_H__ +#define __DXFILE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef DWORD DXFILEFORMAT; + +#define DXFILEFORMAT_BINARY 0 +#define DXFILEFORMAT_TEXT 1 +#define DXFILEFORMAT_COMPRESSED 2 + +typedef DWORD DXFILELOADOPTIONS; + +#define DXFILELOAD_FROMFILE 0x00L +#define DXFILELOAD_FROMRESOURCE 0x01L +#define DXFILELOAD_FROMMEMORY 0x02L +#define DXFILELOAD_FROMSTREAM 0x04L +#define DXFILELOAD_FROMURL 0x08L + +typedef struct _DXFILELOADRESOURCE { + HMODULE hModule; + LPCTSTR lpName; + LPCTSTR lpType; +}DXFILELOADRESOURCE, *LPDXFILELOADRESOURCE; + +typedef struct _DXFILELOADMEMORY { + LPVOID lpMemory; + DWORD dSize; +}DXFILELOADMEMORY, *LPDXFILELOADMEMORY; + +/* + * DirectX File object types. + */ + +#ifndef WIN_TYPES +#define WIN_TYPES(itype, ptype) typedef interface itype *LP##ptype, **LPLP##ptype +#endif + +WIN_TYPES(IDirectXFile, DIRECTXFILE); +WIN_TYPES(IDirectXFileEnumObject, DIRECTXFILEENUMOBJECT); +WIN_TYPES(IDirectXFileSaveObject, DIRECTXFILESAVEOBJECT); +WIN_TYPES(IDirectXFileObject, DIRECTXFILEOBJECT); +WIN_TYPES(IDirectXFileData, DIRECTXFILEDATA); +WIN_TYPES(IDirectXFileDataReference, DIRECTXFILEDATAREFERENCE); +WIN_TYPES(IDirectXFileBinary, DIRECTXFILEBINARY); + +/* + * API for creating IDirectXFile interface. + */ + +STDAPI DirectXFileCreate(LPDIRECTXFILE *lplpDirectXFile); + +/* + * The methods for IUnknown + */ + +#define IUNKNOWN_METHODS(kind) \ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, __deref_out LPVOID *ppvObj) kind; \ + STDMETHOD_(ULONG, AddRef) (THIS) kind; \ + STDMETHOD_(ULONG, Release) (THIS) kind + +/* + * The methods for IDirectXFileObject + */ + +#define IDIRECTXFILEOBJECT_METHODS(kind) \ + STDMETHOD(GetName) (THIS_ LPSTR, LPDWORD) kind; \ + STDMETHOD(GetId) (THIS_ LPGUID) kind + +/* + * DirectX File interfaces. + */ + +#undef INTERFACE +#define INTERFACE IDirectXFile + +DECLARE_INTERFACE_(IDirectXFile, IUnknown) +{ + IUNKNOWN_METHODS(PURE); + STDMETHOD(CreateEnumObject) (THIS_ __in LPVOID, DXFILELOADOPTIONS, + __deref_out LPDIRECTXFILEENUMOBJECT *) PURE; + STDMETHOD(CreateSaveObject) (THIS_ __in_z LPCSTR, DXFILEFORMAT, + __deref_out LPDIRECTXFILESAVEOBJECT *) PURE; + STDMETHOD(RegisterTemplates) (THIS_ __in_bcount(cbSize) LPVOID, DWORD cbSize) PURE; +}; + +#undef INTERFACE +#define INTERFACE IDirectXFileEnumObject + +DECLARE_INTERFACE_(IDirectXFileEnumObject, IUnknown) +{ + IUNKNOWN_METHODS(PURE); + STDMETHOD(GetNextDataObject) (THIS_ __deref_out LPDIRECTXFILEDATA *) PURE; + STDMETHOD(GetDataObjectById) (THIS_ REFGUID, __deref_out LPDIRECTXFILEDATA *) PURE; + STDMETHOD(GetDataObjectByName) (THIS_ __in_z LPCSTR, __deref_out LPDIRECTXFILEDATA *) PURE; +}; + +#undef INTERFACE +#define INTERFACE IDirectXFileSaveObject + +DECLARE_INTERFACE_(IDirectXFileSaveObject, IUnknown) +{ + IUNKNOWN_METHODS(PURE); + STDMETHOD(SaveTemplates) (THIS_ DWORD cTemplates, __in_ecount(cTemplates) const GUID **) PURE; + STDMETHOD(CreateDataObject) (THIS_ REFGUID, __in_z LPCSTR, __in_opt const GUID *, + DWORD cbSize, __in_bcount_opt(cbSize) LPVOID, __deref_out LPDIRECTXFILEDATA *) PURE; + STDMETHOD(SaveData) (THIS_ __in LPDIRECTXFILEDATA) PURE; +}; + + +#undef INTERFACE +#define INTERFACE IDirectXFileObject + +DECLARE_INTERFACE_(IDirectXFileObject, IUnknown) +{ + IUNKNOWN_METHODS(PURE); + IDIRECTXFILEOBJECT_METHODS(PURE); +}; + +#undef INTERFACE +#define INTERFACE IDirectXFileData + +DECLARE_INTERFACE_(IDirectXFileData, IDirectXFileObject) +{ + IUNKNOWN_METHODS(PURE); + IDIRECTXFILEOBJECT_METHODS(PURE); + + STDMETHOD(GetData) (THIS_ __in_z LPCSTR, __out DWORD * pcbSize, __deref_out_bcount(*pcbSize) void ** ppvData) PURE; + STDMETHOD(GetType) (THIS_ __deref_out const GUID **) PURE; + STDMETHOD(GetNextObject) (THIS_ __deref_out LPDIRECTXFILEOBJECT *) PURE; + STDMETHOD(AddDataObject) (THIS_ __in LPDIRECTXFILEDATA) PURE; + STDMETHOD(AddDataReference) (THIS_ __in_z LPCSTR, __in const GUID *) PURE; + STDMETHOD(AddBinaryObject) (THIS_ __in_z LPCSTR, __in const GUID *, __in_z LPCSTR, __in_bcount(cbSize) LPVOID, DWORD cbSize) PURE; +}; + +#undef INTERFACE +#define INTERFACE IDirectXFileDataReference + +DECLARE_INTERFACE_(IDirectXFileDataReference, IDirectXFileObject) +{ + IUNKNOWN_METHODS(PURE); + IDIRECTXFILEOBJECT_METHODS(PURE); + + STDMETHOD(Resolve) (THIS_ __deref_out LPDIRECTXFILEDATA *) PURE; +}; + +#undef INTERFACE +#define INTERFACE IDirectXFileBinary + +DECLARE_INTERFACE_(IDirectXFileBinary, IDirectXFileObject) +{ + IUNKNOWN_METHODS(PURE); + IDIRECTXFILEOBJECT_METHODS(PURE); + + STDMETHOD(GetSize) (THIS_ __out DWORD *) PURE; + STDMETHOD(GetMimeType) (THIS_ __deref_out_z LPCSTR *) PURE; + STDMETHOD(Read) (THIS_ __out_bcount_part(cbSize, *pcbRead) LPVOID pvData, DWORD cbSize, __out LPDWORD pcbRead) PURE; +}; + +/* + * DirectXFile Object Class Id (for CoCreateInstance()) + */ + +DEFINE_GUID(CLSID_CDirectXFile, 0x4516ec43, 0x8f20, 0x11d0, 0x9b, 0x6d, 0x00, 0x00, 0xc0, 0x78, 0x1b, 0xc3); + +/* + * DirectX File Interface GUIDs. + */ + +DEFINE_GUID(IID_IDirectXFile, 0x3d82ab40, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); +DEFINE_GUID(IID_IDirectXFileEnumObject, 0x3d82ab41, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); +DEFINE_GUID(IID_IDirectXFileSaveObject, 0x3d82ab42, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); +DEFINE_GUID(IID_IDirectXFileObject, 0x3d82ab43, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); +DEFINE_GUID(IID_IDirectXFileData, 0x3d82ab44, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); +DEFINE_GUID(IID_IDirectXFileDataReference, 0x3d82ab45, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); +DEFINE_GUID(IID_IDirectXFileBinary, 0x3d82ab46, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); + +/* + * DirectX File Header template's GUID. + */ + +DEFINE_GUID(TID_DXFILEHeader, 0x3d82ab43, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); + + +/* + * DirectX File errors. + */ + +#define _FACDD 0x876 +#define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code ) + +#define DXFILE_OK 0 + +#define DXFILEERR_BADOBJECT MAKE_DDHRESULT(850) +#define DXFILEERR_BADVALUE MAKE_DDHRESULT(851) +#define DXFILEERR_BADTYPE MAKE_DDHRESULT(852) +#define DXFILEERR_BADSTREAMHANDLE MAKE_DDHRESULT(853) +#define DXFILEERR_BADALLOC MAKE_DDHRESULT(854) +#define DXFILEERR_NOTFOUND MAKE_DDHRESULT(855) +#define DXFILEERR_NOTDONEYET MAKE_DDHRESULT(856) +#define DXFILEERR_FILENOTFOUND MAKE_DDHRESULT(857) +#define DXFILEERR_RESOURCENOTFOUND MAKE_DDHRESULT(858) +#define DXFILEERR_URLNOTFOUND MAKE_DDHRESULT(859) +#define DXFILEERR_BADRESOURCE MAKE_DDHRESULT(860) +#define DXFILEERR_BADFILETYPE MAKE_DDHRESULT(861) +#define DXFILEERR_BADFILEVERSION MAKE_DDHRESULT(862) +#define DXFILEERR_BADFILEFLOATSIZE MAKE_DDHRESULT(863) +#define DXFILEERR_BADFILECOMPRESSIONTYPE MAKE_DDHRESULT(864) +#define DXFILEERR_BADFILE MAKE_DDHRESULT(865) +#define DXFILEERR_PARSEERROR MAKE_DDHRESULT(866) +#define DXFILEERR_NOTEMPLATE MAKE_DDHRESULT(867) +#define DXFILEERR_BADARRAYSIZE MAKE_DDHRESULT(868) +#define DXFILEERR_BADDATAREFERENCE MAKE_DDHRESULT(869) +#define DXFILEERR_INTERNALERROR MAKE_DDHRESULT(870) +#define DXFILEERR_NOMOREOBJECTS MAKE_DDHRESULT(871) +#define DXFILEERR_BADINTRINSICS MAKE_DDHRESULT(872) +#define DXFILEERR_NOMORESTREAMHANDLES MAKE_DDHRESULT(873) +#define DXFILEERR_NOMOREDATA MAKE_DDHRESULT(874) +#define DXFILEERR_BADCACHEFILE MAKE_DDHRESULT(875) +#define DXFILEERR_NOINTERNET MAKE_DDHRESULT(876) + + +#ifdef __cplusplus +}; +#endif + +#endif /* _DXFILE_H_ */ diff --git a/third_party/xbox_sdk/include/fxl.h b/third_party/xbox_sdk/include/fxl.h new file mode 100644 index 0000000..85858ec --- /dev/null +++ b/third_party/xbox_sdk/include/fxl.h @@ -0,0 +1,1497 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: fxl.h + * Content: Xenon Effects include file + * + ****************************************************************************/ + +#ifndef _FXL_H_ +#define _FXL_H_ + +#include + +#pragma warning(push) + +// Disable nameless struct/union, zero-sized array, constant conditional +// expression, and padded structures from FXLALIGN16 warnings for this header. + +#pragma warning(disable:4201 4200 4127 4324) + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_M_PPCBE) +#pragma bitfield_order(push) +#pragma bitfield_order(lsb_to_msb) +#endif + +#define FXLRESTRICT //__restrict +#define FXLINLINE __inline +#define FXLFINLINE __forceinline +#define FXLALIGN16 __declspec(align(16)) +#define FXLALIGN128 __declspec(align(128)) +#ifdef __cplusplus +#define FXLEXTERN extern "C" +#else +#define FXLEXTERN extern +#endif + +/* + * Begin technique flags + */ + +#define FXL_RESTORE_DEFAULT_RENDER_STATE 0x0001 +#define FXL_RESTORE_DEFAULT_SAMPLER_STATE 0x0002 +#define FXL_SET_NO_RENDER_STATE 0x0004 +#define FXL_SET_NO_SAMPLER_STATE 0x0008 +#define FXL_COMMIT_DYNAMIC_RENDER_STATE 0x0010 +#define FXL_COMMIT_DYNAMIC_SAMPLER_STATE 0x0020 + +#define FXL_RESTORE_DEFAULT_STATE (FXL_RESTORE_DEFAULT_RENDER_STATE | FXL_RESTORE_DEFAULT_SAMPLER_STATE) +#define FXL_SET_NO_STATE (FXL_SET_NO_RENDER_STATE | FXL_SET_NO_SAMPLER_STATE) +#define FXL_COMMIT_DYNAMIC_STATE (FXL_COMMIT_DYNAMIC_RENDER_STATE | FXL_COMMIT_DYNAMIC_SAMPLER_STATE) + +/* + * Parameter desc flags + */ + +#define FXLPFLAG_SHARED 0x1 + +/* + * Compile effect flags + */ + +#define D3DXSHADER_FXLANNOTATE_VARIABLE_NAMES (1 << 26) +#define D3DXSHADER_FXLANNOTATE_SEMANTIC_NAMES (1 << 27) +#define D3DXSHADER_FXLPARAMETERS_AS_VARIABLE_NAMES (1 << 28) +#define D3DXSHADER_FXLEFFECT_NATIVE_ENDIAN (1 << 29) + +/* + * Binary effect data version + */ + +#define FXLDATA_IDENTIFIER 0xA3D7 +#define FXLDATA_VERSION_MAJOR 1 +#define FXLDATA_VERSION_MINOR 5 + +/* + * Publicly accessible globals - Feel free to modify the values. + */ + +// Set FXL__EnforceSharedCorrelation to TRUE to enforce a correlation of +// shared parameter register assignments across all effects in a single +// global pool. When this global is set to TRUE, FXL will RIP under any +// of the following conditions: +// +// - More than one effect pool is created +// +// - The shader register assignment(s) for any shared parameter added +// to the global pool differ in base indices from the register +// assignment(s) of the matching parameter already present in the pool +// (but the register counts for a matching parameter are allowed to +// fluctuate) +// +// - The shader register assignment(s) for any shared parameter added +// to the global pool interfere with the assignment(s) of any non- +// matching parameter already present in the pool +// +// - The register assignment(s) for a local parameter of any effect (or +// shared parameter of any effect not placed in the global pool) +// conflict with the assignments of any shared parameters in the +// global pool +// +// - The register assignments for literal constants used by any shader +// in any effect interfere with the assignments of any shared +// parameters in the global pool +// +// - The integer literal constants used in conjuction with a shared loop +// parameter added to the global pool are not identical in value to the +// integer literal constants associated with a matching parameter +// already present in the pool +// +// +// When the correlation of shared parameters is preserved, Commit will only +// send shared parameter data to the hardware when explicitly modified in value +// through a parameter 'Set' call. Without correlation, all shared parameters +// must be updated in the hardware at the first Commit of every pass. + +FXLEXTERN BOOL FXL__EnforceSharedCorrelation; + +/* + * Data types + */ + +typedef DWORD FXLHANDLE; + +typedef FXLALIGN16 FLOAT FXLFLOATA; +typedef FXLALIGN16 INT FXLINTA; +typedef FXLALIGN16 BOOL FXLBOOLA; + +typedef XMVECTOR FXLVECTOR; +typedef XMMATRIX FXLMATRIX; + +typedef struct FXLEffect FXLEffect; +typedef struct FXLEffect* PFXLEFFECT, *LPFXLEFFECT; + +typedef struct FXLEffectPool FXLEffectPool; +typedef struct FXLEffectPool* PFXLEFFECTPOOL, *LPFXLEFFECTPOOL; + +/* + * FXLPA_CONTENT + */ + +typedef enum _FXLPA_CONTENT +{ + FXLPACONTENT_DATA = 0, + FXLPACONTENT_STRUCT = 1, + FXLPACONTENT_ARRAY = 2, +} FXLPA_CONTENT; + +/* + * FXLDATA_TYPE + */ + +typedef enum _FXLDATA_TYPE +{ + FXLDTYPE_FLOAT = 0, + FXLDTYPE_INT = 1, + FXLDTYPE_BOOL = 2, + FXLDTYPE_SAMPLER = 3, + FXLDTYPE_STRING = 4, + FXLDTYPE_CONTAINER = 5, +} FXLDATA_TYPE; + +/* + * FXLDATA_CLASS + */ + +typedef enum _FXLDATA_CLASS +{ + FXLDCLASS_SCALAR = 0, + FXLDCLASS_VECTOR = 1, + FXLDCLASS_RMATRIX = 2, + FXLDCLASS_CMATRIX = 3, + FXLDCLASS_SAMPLER = 4, + FXLDCLASS_SAMPLER1D = 5, + FXLDCLASS_SAMPLER2D = 6, + FXLDCLASS_SAMPLER3D = 7, + FXLDCLASS_SAMPLERCUBE = 8, + FXLDCLASS_CONTAINER = 9, +} FXLDATA_CLASS; + +/* + * FXLPARAMETER_CONTEXT + */ + +#define FXLPCONTEXT_VERTEXSHADERCONSTANTF 0x0001 +#define FXLPCONTEXT_PIXELSHADERCONSTANTF 0x0002 +#define FXLPCONTEXT_VERTEXSHADERCONSTANTI 0x0004 +#define FXLPCONTEXT_PIXELSHADERCONSTANTI 0x0008 +#define FXLPCONTEXT_VERTEXSHADERCONSTANTB 0x0010 +#define FXLPCONTEXT_PIXELSHADERCONSTANTB 0x0020 +#define FXLPCONTEXT_VERTEXSHADERSAMPLER 0x0040 +#define FXLPCONTEXT_PIXELSHADERSAMPLER 0x0080 + +typedef DWORD FXLPARAMETER_CONTEXT; + +/* + * FXLREGISTER_UPDATE + */ + +typedef enum _FXLREGISTER_UPDATE +{ + FXLREGUPDATE_MANUAL = 0, + FXLREGUPDATE_AUTOMATIC = 1, +} FXLREGISTER_UPDATE; + +/* + * FXLEFFECT_DESC + */ + +typedef struct _FXLEFFECT_DESC +{ + CONST CHAR* pCreator; + UINT Parameters; + UINT Techniques; + UINT Functions; + UINT Annotations; +} FXLEFFECT_DESC; + +/* + * FXLTECHNIQUE_DESC + */ + +typedef struct _FXLTECHNIQUE_DESC +{ + CONST CHAR* pName; + UINT Passes; + UINT Annotations; +} FXLTECHNIQUE_DESC; + +/* + * FXLPASS_DESC + */ + +typedef struct _FXLPASS_DESC +{ + CONST CHAR* pName; + UINT Annotations; + UINT RenderStates; + UINT SamplerStates; + DWORD* pVertexShaderFunction; + UINT VertexShaderFunctionSize; + DWORD* pPixelShaderFunction; + UINT PixelShaderFunctionSize; +} FXLPASS_DESC; + +/* + * FXLPARAMETER_DESC + */ + +typedef struct _FXLPARAMETER_DESC +{ + CONST CHAR* pName; + FXLPA_CONTENT Content; + FXLDATA_TYPE Type; + FXLDATA_CLASS Class; + UINT Rows; + UINT Columns; + UINT Elements; + UINT Annotations; + DWORD Flags; + UINT Size; +} FXLPARAMETER_DESC; + +/* + * FXLANNOTATION_DESC + */ + +typedef struct _FXLANNOTATION_DESC +{ + CONST CHAR* pName; + FXLPA_CONTENT Content; + FXLDATA_TYPE Type; + FXLDATA_CLASS Class; + UINT Rows; + UINT Columns; + UINT Elements; + UINT Size; +} FXLANNOTATION_DESC; + +/* + * Render state type and value pair + */ + +typedef struct _FXLRENDERSTATE +{ + D3DRENDERSTATETYPE Type; + DWORD Value; +} FXLRENDERSTATE; + +/* + * Sampler state type and value pair + */ + +typedef struct _FXLSAMPLERSTATE +{ + D3DSAMPLERSTATETYPE Type; + DWORD Value; +} FXLSAMPLERSTATE; + +/**************************************************************************** + * + * Begin: Private internal data - Please don't access these directly, as + * they're subject to change. + * + ****************************************************************************/ + +/* + * Flag groups. Just enough space reserved to clear with a single __dcbz128 + */ + +#define FXL_MAX_PARAMETER_FLAG_GROUPS 16 + +/* + * Parameter content + */ + +#define FXLPACONTENTI_DATA 0 +#define FXLPACONTENTI_STRUCT 1 +#define FXLPACONTENTI_ARRAY 2 + +/* + * Parameter type + */ + +#define FXLDTYPEI_FLOAT 0 +#define FXLDTYPEI_INT 1 +#define FXLDTYPEI_BOOL 2 +#define FXLDTYPEI_SAMPLER 3 // Samplers are supported as parameters, but not as annotations +#define FXLDTYPEI_STRING 3 // Strings are supported as annotations, but not as parameters + +/* + * Parameter class + */ + +#define FXLDCLASSI_SCALAR 0 +#define FXLDCLASSI_VECTOR 1 +#define FXLDCLASSI_RMATRIX 2 +#define FXLDCLASSI_CMATRIX 3 +#define FXLDCLASSI_SAMPLER 0 +#define FXLDCLASSI_SAMPLER1D 1 +#define FXLDCLASSI_SAMPLER2D 2 +#define FXLDCLASSI_SAMPLER3D 3 +#define FXLDCLASSI_SAMPLERCUBE 4 + +/* + * FXLDIRTYFLAGS + */ + +typedef FXLALIGN128 UINT64 FXLDIRTYFLAGS[FXL_MAX_PARAMETER_FLAG_GROUPS]; + +/* + * Data parameter + */ + +typedef union _FXLPARAMETERDATA +{ + DWORD DWord[2]; + + struct + { + // DWord[0] + + DWORD Content : 2; + DWORD Type : 2; + DWORD Class : 3; + DWORD Rows : 2; + DWORD Columns : 2; + DWORD : 5; + DWORD Flags : 5; + DWORD Annotations : 11; + + // DWord[1] + + DWORD DataOffset : 16; + DWORD Size : 16; + }; +} FXLPARAMETERDATA; + +/* + * Struct parameter + */ + +typedef union _FXLPARAMETERSTRUCT +{ + DWORD DWord[2]; + + struct + { + // DWord[0] + + DWORD Content : 2; + DWORD Members : 14; + DWORD Flags : 5; + DWORD Annotations : 11; + + // DWord[1] + + DWORD NextOffset : 16; + DWORD Size : 16; + }; +} FXLPARAMETERSTRUCT; + +/* + * Array parameter + */ + +typedef union _FXLPARAMETERARRAY +{ + DWORD DWord[2]; + + struct + { + // DWord[0] + + DWORD Content : 2; + DWORD Elements : 14; + DWORD Flags : 5; + DWORD Annotations : 11; + + // DWord[1] + + DWORD NextOffset : 16; + DWORD Size : 16; + }; +} FXLPARAMETERARRAY; + +/* + * Generic parameter entry. The specific contents of the parameter depend + * on the 'Content' field. + */ + +typedef union _FXLPARAMETERENTRY +{ + FXLPARAMETERDATA Data; + FXLPARAMETERSTRUCT Struct; + FXLPARAMETERARRAY Array; + + DWORD DWord[2]; + + struct + { + // DWord[0] + + DWORD Content : 2; + DWORD : 14; + DWORD Flags : 5; + DWORD Annotations : 11; + + // DWord[1] + + DWORD Offset : 16; + DWORD Size : 16; + }; +} FXLPARAMETERENTRY; + +/* + * Parameter reference in a pass. The reference is used to map + * parameter data to shader registers and any literal constant + * data packed into the registers with the parameter data. + */ + +typedef FXLALIGN16 union _FXLPASSPARAMETERREF +{ + DWORD DWord[4]; + + struct + { + // DWord[0] + + FXLHANDLE ParameterHandle; + + // DWord[1] + + DWORD VSFRegisterIndex : 10; + DWORD VSFRegisterCount : 2; + DWORD VSIRegisterIndex : 8; + DWORD VSIRegisterCount : 2; + DWORD VSSRegisterIndex : 8; + DWORD VSBRegisterCount : 2; + + // DWord[2] + + DWORD PSFRegisterIndex : 10; + DWORD PSFRegisterCount : 2; + DWORD PSIRegisterIndex : 8; + DWORD PSIRegisterCount : 2; + DWORD PSSRegisterIndex : 8; + DWORD PSBRegisterCount : 2; + + // DWord[3] + + DWORD VSBRegisterIndex : 8; + DWORD PSBRegisterIndex : 8; + DWORD VSILiteralOffset : 8; // 16 byte multiple + DWORD PSILiteralOffset : 8; // 16 byte multiple + }; +} FXLPASSPARAMETERREF; + +/* + * Vertex shader + */ + +typedef struct _FXLVERTEXSHADERENTRY +{ + DWORD dwObject; // IDirect3DVertexShader9* + DWORD FunctionSize; + DWORD pFunction[0]; +} FXLVERTEXSHADERENTRY; + +/* + * Pixel shader + */ + +typedef struct _FXLPIXELSHADERENTRY +{ + DWORD dwObject; // IDirect3DPixelShader9* + DWORD FunctionSize; + DWORD pFunction[0]; +} FXLPIXELSHADERENTRY; + +/* + * Shader state entry - Vertex shader, pixel shader, literal constant data, + * shader constant reference lists, and usage flags. + */ + +typedef struct _FXLSHADERSTATEENTRY +{ + DWORD dwVSFUsageFlagsLocal; // UINT64* + DWORD dwPSFUsageFlagsLocal; + DWORD dwVSIUsageFlagsLocal; + DWORD dwPSIUsageFlagsLocal; + DWORD dwVSBUsageFlagsLocal; + DWORD dwPSBUsageFlagsLocal; + DWORD dwVSSUsageFlagsLocal; + DWORD dwPSSUsageFlagsLocal; + DWORD dwVSFUsageFlagsShared; + DWORD dwPSFUsageFlagsShared; + DWORD dwVSIUsageFlagsShared; + DWORD dwPSIUsageFlagsShared; + DWORD dwVSBUsageFlagsShared; + DWORD dwPSBUsageFlagsShared; + DWORD dwVSSUsageFlagsShared; + DWORD dwPSSUsageFlagsShared; + + DWORD dwReferenceListLocal; // FXLPASSPARAMETERREF* + DWORD dwReferenceListShared; + + DWORD dwVertexShader; // FXLVERTEXSHADERENTRY* + DWORD dwPixelShader; // FXLPIXELSHADERENTRY* + + DWORD dwIntLiteralData; // XMFLOAT4A16* - Storage of integer flow control literal data placed into components of parameter registers + UINT IntLiteralDataSize; +} FXLSHADERSTATEENTRY; + +/* + * Render state data + */ + +typedef struct _FXLRENDERSTATEDATA +{ + DWORD Type; + DWORD Value; +} FXLRENDERSTATEDATA; + +/* + * Render state entry + */ + +typedef struct _FXLRENDERSTATEENTRY +{ + FXLALIGN16 UINT64 RenderStateUsageFlags[2]; + UINT DynamicFCount; + UINT DynamicICount; + UINT StaticCount; + FXLRENDERSTATEDATA pStateList[0]; +} FXLRENDERSTATEENTRY; + +/* + * Sampler state data + */ + +typedef struct _FXLSAMPLERSTATEDATA +{ + WORD Index; + WORD Type; + DWORD Value; +} FXLSAMPLERSTATEDATA; + +/* + * Sampler state entry + */ + +typedef struct _FXLSAMPLERSTATEENTRY +{ + FXLALIGN16 UINT64 SamplerStateUsageFlags[16]; + UINT DynamicFCount; + UINT DynamicICount; + UINT StaticCount; + FXLSAMPLERSTATEDATA pStateList[0]; +} FXLSAMPLERSTATEENTRY; + +/* + * Pass entry + */ + +typedef struct _FXLPASSENTRY +{ + DWORD dwName; // CHAR* + UINT AnnotationCount; + DWORD dwShaderStates; // FXLSHADERSTATEENTRY* + DWORD dwRenderStates; // FXLRENDERSTATEENTRY* + DWORD dwSamplerStates; // FXLSAMPLERSTATEENTRY* +} FXLPASSENTRY; + +/* + * Technique entry + */ + +typedef struct _FXLTECHNIQUEENTRY +{ + DWORD dwName; // CHAR* + UINT PassCount; + UINT AnnotationCount; + UINT SamplerStateGroupCount; + DWORD pdwPassList[0]; // FXLPASSENTRY* +} FXLTECHNIQUEENTRY; + +/* + * Globals + */ + +FXLEXTERN BOOL FXL__SharedCorrelation; + +/**************************************************************************** + * + * End: Private internal data. + * + ****************************************************************************/ + +/* + * Effect Pool + */ + +struct FXLEffectPool +{ +#ifdef __cplusplus + + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + VOID WINAPI SetFloat(FXLHANDLE Parameter, FLOAT Data); + FLOAT WINAPI GetFloat(FXLHANDLE Parameter); + VOID WINAPI SetScalarF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI GetScalarF(FXLHANDLE Parameter, __out FLOAT* pData); + VOID WINAPI SetScalarArrayF(FXLHANDLE Parameter, __in_ecount(Count) CONST FLOAT* pData, UINT Count); + VOID WINAPI GetScalarArrayF(FXLHANDLE Parameter, __out_ecount(Count) FLOAT* pData, UINT Count); + VOID WINAPI SetInt(FXLHANDLE Parameter, INT Data); + INT WINAPI GetInt(FXLHANDLE Parameter); + VOID WINAPI SetScalarI(FXLHANDLE Parameter, __in CONST INT* pData); + VOID WINAPI GetScalarI(FXLHANDLE Parameter, __out INT* pData); + VOID WINAPI SetScalarArrayI(FXLHANDLE Parameter, __in_ecount(Count) CONST INT* pData, UINT Count); + VOID WINAPI GetScalarArrayI(FXLHANDLE Parameter, __out_ecount(Count) INT* pData, UINT Count); + VOID WINAPI SetBool(FXLHANDLE Parameter, BOOL Data); + BOOL WINAPI GetBool(FXLHANDLE Parameter); + VOID WINAPI SetScalarB(FXLHANDLE Parameter, __in CONST BOOL* pData); + VOID WINAPI GetScalarB(FXLHANDLE Parameter, __out BOOL* pData); + VOID WINAPI SetScalarArrayB(FXLHANDLE Parameter, __in_ecount(Count) CONST BOOL* pData, UINT Count); + VOID WINAPI GetScalarArrayB(FXLHANDLE Parameter, __out_ecount(Count) BOOL* pData, UINT Count); + VOID WINAPI SetVector(FXLHANDLE Parameter, FXLVECTOR Data); + FXLVECTOR WINAPI GetVector(FXLHANDLE Parameter); + VOID WINAPI SetVectorF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI SetVectorFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); + VOID WINAPI GetVectorF(FXLHANDLE Parameter, __out FLOAT* pData); + VOID WINAPI SetVectorArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI SetVectorArrayF4A(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI GetVectorArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); + VOID WINAPI SetVectorI(FXLHANDLE Parameter, __in CONST INT* pData); + VOID WINAPI SetVectorIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData); + VOID WINAPI GetVectorI(FXLHANDLE Parameter, __out INT* pData); + VOID WINAPI SetVectorB(FXLHANDLE Parameter, __in CONST BOOL* pData); + VOID WINAPI SetVectorBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); + VOID WINAPI GetVectorB(FXLHANDLE Parameter, __out BOOL* pData); + VOID WINAPI SetMatrix(FXLHANDLE Parameter, __in FXLMATRIX* pData); + VOID WINAPI GetMatrix(FXLHANDLE Parameter, __out FXLMATRIX* pData); + VOID WINAPI SetMatrixRaw(FXLHANDLE Parameter, __in FXLMATRIX* pData); + VOID WINAPI SetMatrixF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI SetMatrixFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); + VOID WINAPI GetMatrixF(FXLHANDLE Parameter, __out FLOAT* pData); + VOID WINAPI SetMatrixF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); + VOID WINAPI SetMatrixF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); + VOID WINAPI GetMatrixF4x4(FXLHANDLE Parameter, __out_ecount(16) FLOAT* pData); + VOID WINAPI SetMatrixRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI SetMatrixRawFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); + VOID WINAPI SetMatrixRawF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); + VOID WINAPI SetMatrixRawF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); + VOID WINAPI SetMatrixArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI GetMatrixArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); + VOID WINAPI GetMatrixArrayF4x4(FXLHANDLE Parameter, __out_ecount(16*Count) FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayRawF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayRawF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); + VOID WINAPI SetMatrixI(FXLHANDLE Parameter, __in CONST INT* pData); + VOID WINAPI SetMatrixIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData); + VOID WINAPI GetMatrixI(FXLHANDLE Parameter, __out INT* pData); + VOID WINAPI SetMatrixB(FXLHANDLE Parameter, __in CONST BOOL* pData); + VOID WINAPI SetMatrixBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); + VOID WINAPI GetMatrixB(FXLHANDLE Parameter, __out BOOL* pData); + VOID WINAPI SetSampler(FXLHANDLE Parameter, __in_opt CONST IDirect3DBaseTexture9* pTexture); + VOID WINAPI GetSampler(FXLHANDLE Parameter, __deref_out IDirect3DBaseTexture9** pTexture); + VOID WINAPI SetParameter(FXLHANDLE Parameter, __in CONST VOID* pData); + VOID WINAPI GetParameter(FXLHANDLE Parameter, __out VOID* pData); + + FXLHANDLE WINAPI GetParameterHandle(__in_z CONST CHAR* pParameterName); + FXLHANDLE WINAPI GetMemberHandle(__in FXLHANDLE Struct, __in_z CONST CHAR* pMemberName); + FXLHANDLE WINAPI GetMemberHandleFromIndex(__in FXLHANDLE Struct, UINT MemberIndex); + FXLHANDLE WINAPI GetElementHandle(__in FXLHANDLE Array, UINT ElementIndex); + + VOID WINAPI GetParameterDesc(__in FXLHANDLE Parameter, __out FXLPARAMETER_DESC* pDesc); + + VOID WINAPI SetParameterRegisterUpdate(__in FXLHANDLE Parameter, FXLREGISTER_UPDATE UpdateMode); + +#endif __cplusplus + + // Private internal data (please do not access directly): + + FXLDIRTYFLAGS m_DirtyFlags; // Shared parameter dirty flags + FXLALIGN128 UINT64 m_UpdateFlags[FXL_MAX_PARAMETER_FLAG_GROUPS]; + DWORD m_dwParameterList; // FXLPARAMETERENTRY* - Pointer to the list of parameters in the pool + UINT m_ParameterListEntries; // Number of entries in the parameter list + DWORD m_dwParameterData; // XMFLOAT4A16* - Pointer to the list of shared parameter data in the pool + UINT m_ParameterDataEntries; // Number of parameter data groups in the pool + UINT m_ParameterDataSize; // Size of the shared parameter data in bytes (inclusive of all shared data present in the pool at the time the effect was created) + UINT m_ParameterBitGroups; // Count of QWords used in the shared parameter bit groups + + UINT m_ParameterCount; // Number of top-level parameters in the the pool + + DWORD m_dwNameList; // CHAR* - Ordered list of all top level parameter names in the pool + UINT m_NameListSize; + + DWORD m_dwParameterNameMap; // DWORD* - CHAR** - Map of parameter names based on parameter index +}; + +/* + * Effect + */ + +struct FXLEffect +{ +#ifdef __cplusplus + + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + VOID WINAPI BeginTechnique(FXLHANDLE Technique, DWORD Flags); + VOID WINAPI BeginTechniqueFromIndex(UINT TechniqueIndex, DWORD Flags); + VOID WINAPI EndTechnique(); + VOID WINAPI BeginPass(FXLHANDLE Pass); + VOID WINAPI BeginPassFromIndex(UINT PassIndex); + VOID WINAPI EndPass(); + + VOID WINAPI SetFloat(FXLHANDLE Parameter, FLOAT Data); + FLOAT WINAPI GetFloat(FXLHANDLE Parameter); + VOID WINAPI SetScalarF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI GetScalarF(FXLHANDLE Parameter, __out FLOAT* pData); + VOID WINAPI SetScalarArrayF(FXLHANDLE Parameter, __in_ecount(Count) CONST FLOAT* pData, UINT Count); + VOID WINAPI GetScalarArrayF(FXLHANDLE Parameter, __out_ecount(Count) FLOAT* pData, UINT Count); + VOID WINAPI SetInt(FXLHANDLE Parameter, INT Data); + INT WINAPI GetInt(FXLHANDLE Parameter); + VOID WINAPI SetScalarI(FXLHANDLE Parameter, __in CONST INT* pData); + VOID WINAPI GetScalarI(FXLHANDLE Parameter, __out INT* pData); + VOID WINAPI SetScalarArrayI(FXLHANDLE Parameter, __in_ecount(Count) CONST INT* pData, UINT Count); + VOID WINAPI GetScalarArrayI(FXLHANDLE Parameter, __out_ecount(Count) INT* pData, UINT Count); + VOID WINAPI SetBool(FXLHANDLE Parameter, BOOL Data); + BOOL WINAPI GetBool(FXLHANDLE Parameter); + VOID WINAPI SetScalarB(FXLHANDLE Parameter, __in CONST BOOL* pData); + VOID WINAPI GetScalarB(FXLHANDLE Parameter, __out BOOL* pData); + VOID WINAPI SetScalarArrayB(FXLHANDLE Parameter, __in_ecount(Count) CONST BOOL* pData, UINT Count); + VOID WINAPI GetScalarArrayB(FXLHANDLE Parameter, __out_ecount(Count) BOOL* pData, UINT Count); + VOID WINAPI SetVector(FXLHANDLE Parameter, FXLVECTOR Data); + FXLVECTOR WINAPI GetVector(FXLHANDLE Parameter); + VOID WINAPI SetVectorF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI SetVectorFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); + VOID WINAPI GetVectorF(FXLHANDLE Parameter, __out FLOAT* pData); + VOID WINAPI SetVectorArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI SetVectorArrayF4A(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData, UINT Count); + VOID WINAPI GetVectorArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); + VOID WINAPI SetVectorI(FXLHANDLE Parameter, __in CONST INT* pData); + VOID WINAPI SetVectorIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData); + VOID WINAPI GetVectorI(FXLHANDLE Parameter, __out INT* pData); + VOID WINAPI SetVectorB(FXLHANDLE Parameter, __in CONST BOOL* pData); + VOID WINAPI SetVectorBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); + VOID WINAPI GetVectorB(FXLHANDLE Parameter, __out BOOL* pData); + VOID WINAPI SetMatrix(FXLHANDLE Parameter, __in FXLMATRIX* pData); + VOID WINAPI GetMatrix(FXLHANDLE Parameter, __out FXLMATRIX* pData); + VOID WINAPI SetMatrixRaw(FXLHANDLE Parameter, __in FXLMATRIX* pData); + VOID WINAPI SetMatrixF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI SetMatrixFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); + VOID WINAPI GetMatrixF(FXLHANDLE Parameter, __out FLOAT* pData); + VOID WINAPI SetMatrixF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); + VOID WINAPI SetMatrixF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); + VOID WINAPI GetMatrixF4x4(FXLHANDLE Parameter, __out_ecount(16) FLOAT* pData); + VOID WINAPI SetMatrixRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData); + VOID WINAPI SetMatrixRawFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); + VOID WINAPI SetMatrixRawF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); + VOID WINAPI SetMatrixRawF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); + VOID WINAPI SetMatrixArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI GetMatrixArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); + VOID WINAPI GetMatrixArrayF4x4(FXLHANDLE Parameter, __out_ecount(16*Count) FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayRawF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); + VOID WINAPI SetMatrixArrayRawF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); + VOID WINAPI SetMatrixI(FXLHANDLE Parameter, __in CONST INT* pData); + VOID WINAPI SetMatrixIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData); + VOID WINAPI GetMatrixI(FXLHANDLE Parameter, __out INT* pData); + VOID WINAPI SetMatrixB(FXLHANDLE Parameter, __in CONST BOOL* pData); + VOID WINAPI SetMatrixBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); + VOID WINAPI GetMatrixB(FXLHANDLE Parameter, __out BOOL* pData); + VOID WINAPI SetSampler(FXLHANDLE Parameter, __in_opt CONST IDirect3DBaseTexture9* pTexture); + VOID WINAPI GetSampler(FXLHANDLE Parameter, __deref_out IDirect3DBaseTexture9** pTexture); + VOID WINAPI SetParameter(FXLHANDLE Parameter, __in CONST VOID* pData); + VOID WINAPI GetParameter(FXLHANDLE Parameter, __out VOID* pData); + + VOID WINAPI Commit(); + VOID WINAPI CommitU(); + + FXLHANDLE WINAPI GetParameterHandle(__in_z CONST CHAR* pParameterName); + FXLHANDLE WINAPI GetParameterHandleFromIndex(UINT ParameterIndex); + FXLHANDLE WINAPI GetAnnotationHandle(FXLHANDLE Anchor, __in_z CONST CHAR* pAnnotationName); + FXLHANDLE WINAPI GetAnnotationHandleFromIndex(FXLHANDLE Anchor, UINT AnnotationIndex); + FXLHANDLE WINAPI GetMemberHandle(FXLHANDLE Struct, __in_z CONST CHAR* pMemberName); + FXLHANDLE WINAPI GetMemberHandleFromIndex(FXLHANDLE Struct, UINT MemberIndex); + FXLHANDLE WINAPI GetElementHandle(FXLHANDLE Array, UINT ElementIndex); + FXLHANDLE WINAPI GetTechniqueHandle(__in_z CONST CHAR* pTechniqueName); + FXLHANDLE WINAPI GetTechniqueHandleFromIndex(UINT TechniqueIndex); + FXLHANDLE WINAPI GetPassHandle(FXLHANDLE Technique, __in_z CONST CHAR* pPassName); + FXLHANDLE WINAPI GetPassHandleFromIndex(FXLHANDLE Technique, UINT PassIndex); + + VOID WINAPI GetEffectDesc(__out FXLEFFECT_DESC* pDesc); + VOID WINAPI GetTechniqueDesc(FXLHANDLE Technique, __out FXLTECHNIQUE_DESC* pDesc); + VOID WINAPI GetPassDesc(FXLHANDLE Pass, __out FXLPASS_DESC* pDesc); + VOID WINAPI GetParameterDesc(FXLHANDLE Parameter, __out FXLPARAMETER_DESC* pDesc); + VOID WINAPI GetAnnotationDesc(FXLHANDLE Annotation, __out FXLANNOTATION_DESC* pDesc); + + FXLHANDLE WINAPI GetActiveTechnique(); + FXLHANDLE WINAPI GetActivePass(); + VOID WINAPI GetRenderStateList(FXLHANDLE Pass, __out_ecount_opt(*pCount) FXLRENDERSTATE* pList, __out UINT* pCount); + VOID WINAPI GetSamplerStateList(FXLHANDLE Sampler, __out_ecount_opt(*pCount) FXLSAMPLERSTATE* pList, __out UINT* pCount); + VOID WINAPI GetRenderState(FXLHANDLE Pass, UINT StateIndex, __out D3DRENDERSTATETYPE* pStateType, __out DWORD* pStateValue); + VOID WINAPI GetSamplerState(FXLHANDLE Pass, UINT StateIndex, __out UINT* pSamplerIndex, __out D3DSAMPLERSTATETYPE* pStateType, __out DWORD* pStateValue); + FXLPARAMETER_CONTEXT WINAPI GetParameterContext(FXLHANDLE Pass, FXLHANDLE Parameter); + VOID WINAPI GetParameterRegister(FXLHANDLE Pass, FXLHANDLE Parameter, FXLPARAMETER_CONTEXT Context, __out UINT* pRegisterIndex, __out UINT* pRegisterCount); + VOID WINAPI GetAnnotation(FXLHANDLE Annotation, __out VOID* pData); + + VOID WINAPI SetParameterRegisterUpdate(FXLHANDLE Parameter, FXLREGISTER_UPDATE UpdateMode); + + HRESULT WINAPI CreateInstance(__deref_out FXLEffect** pEffectInstance); + VOID WINAPI GetPool(__deref_out FXLEffectPool** pPool); + + HRESULT WINAPI ChangeDevice(__in_opt IDirect3DDevice9* pDevice); + HRESULT WINAPI OnLostDevice(); + HRESULT WINAPI OnResetDevice(); + +#endif __cplusplus + + // Private internal data (please do not access directly): + + FXLDIRTYFLAGS m_DirtyFlagsLocal; // Local parameter dirty flags + FXLALIGN128 UINT64 m_UpdateFlagsLocal[FXL_MAX_PARAMETER_FLAG_GROUPS]; + DWORD m_dwDirtyFlagsShared; // UINT64* - Pointer to the dirty flags contained in the shared pool + DWORD m_dwUpdateFlagsShared; + + DWORD m_dwParameterListLocal; // FXLPARAMETERENTRY* - Pointer to the list of local parameters in the effect + DWORD m_dwParameterListShared; // DWORD* - FXLPARAMETERENTRY** - Pointer to the list of shared parameters in the pool + UINT m_ParameterCountLocal; // Number of local top-level parameters in the effect + UINT m_ParameterCountShared; // Number of shared top-level parameters in the effect + UINT m_ParameterListEntriesLocal; // Number of entries in the local parameter list + UINT m_ParameterListEntriesShared; // Number of entries in the shared parameter list + UINT m_ParameterBitGroupsLocal; // Count of QWords used in the local parameter bit groups (dirty and usage flags) + UINT m_ParameterBitGroupsShared; // Count of QWords used in the shared parameter bit groups + + DWORD m_dwParameterDataLocal; // XMFLOAT4A16* - Pointer to the list of local parameter data in the effect + DWORD m_dwParameterDataShared; // DWORD* - XMFLOAT4A16** - Pointer to the list of shared parameter data in the pool + UINT m_ParameterDataEntriesLocal; // Number of local parameter data groups in the effect (i.e. parameter list leaf nodes) + UINT m_ParameterDataEntriesShared; // Number of shared parameter data groups in the effect (total number of groups in the pool at a time just after the effect was created) + UINT m_ParameterDataSizeLocal; // Size of the local parameter data in bytes + UINT m_ParameterDataSizeShared; // Size of the shared parameter data in bytes (inclusive of all shared data present in the pool at the time the effect was created) + + FXLALIGN16 UINT64 m_RenderStateDirtyFlags[2]; // Flags to track render state changes made by a technique + FXLALIGN128 UINT64 m_SamplerStateDirtyFlags[16]; // Flags to track sampler state changes made by a technique + + DWORD m_dwTechniqueList; // DWORD* - FXLTECHNIQUEENTRY** - Pointer to the list of techniques in the effect + DWORD m_dwActiveTechnique; // FXLTECHNIQUEENTRY* - Pointer to the currently active technique in the effect + FXLHANDLE m_ActiveTechniqueHandle; // Handle to the currently active technique in the effect + UINT m_TechniqueCount; // Number of techniques present in the effect + + DWORD m_dwPassList; // FXLPASSENTRY* - Pointer to the list of passes in the effect + DWORD m_dwActivePass; // FXLPASSENTRY* - Pointer to the currently active pass in the effect + DWORD m_dwActiveShader; // FXLSHADERSTATEENTRY* - Pointer to the FXLSHADERSTATEENTRY used by the active pass + DWORD m_dwPreviousPass; // FXLPASSENTRY* - Pointer to the last active pass in the effect + UINT m_PassCount; // Number of unique passes in the effect + + DWORD m_dwShaderStateList; // FXLSHADERSTATEENTRY* - List of unique groups of shader state (based on vertex and pixel shader pairs) used by passes in the effect + UINT m_ShaderStateCount; // Number of unique groups of shader state in the effect + UINT m_ShaderStateListSize; // Size of the shader state list + + DWORD m_dwVertexShaderList; // FXLVERTEXSHADERENTRY* - List of unique vertex shaders used by the passes in the effect + UINT m_VertexShaderCount; // Number of unique vertex shaders in the effect + UINT m_VertexShaderListSize; // Size of the vertex shader list + + DWORD m_dwPixelShaderList; // FXLPIXELSHADERENTRY* - List of unique pixel shaders used by the passes in the effect + UINT m_PixelShaderCount; // Number of unique pixel shaders in the effect + UINT m_PixelShaderListSize; // Size of the pixel shader list + + DWORD m_dwRenderStateList; // FXLRENDERSTATEENTRY* - List of unique groups of render state used by passes in the effect + UINT m_RenderStateCount; // Number of unique groups of render state in the effect + UINT m_RenderStateListSize; // Size of the render state list + + DWORD m_dwSamplerStateList; // FXLSAMPLERSTATEENTRY* - List of unique groups of sampler state used by passes in the effect + UINT m_SamplerStateCount; // Number of unique groups of sampler state in the effect + UINT m_SamplerStateListSize; // Size of the sampler state list + + DWORD m_dwAnnotationList; // FXLPARAMETERENTRY* - List of global annotations (strings) followed by all annotations attached to techniques, passes, and parameters (both local and shared) + UINT m_AnnotationListEntries; // Number of entries in the annotation list + UINT m_AnnotationListGlobals; // Number of global annotations (those not attached to any anchor) in the list + + DWORD m_dwAnnotationData; // DWORD* - Annotation data + UINT m_AnnotationDataSize; // Size of the annotation data + + DWORD m_dwAnnotationEntryMapTechnique; // WORD* - Map from a technique list offset to an offset in the annotation list to the set of annotations belonging to the technique + DWORD m_dwAnnotationEntryMapPass; // WORD* - Map from a pass list offset to an offset in the annotation list to the set of annotations belonging to the pass + DWORD m_dwAnnotationEntryMapLocal; // WORD* - Map from a local parameter list offset to an offset in the annotation list to the set of annotations belonging to the parameter + DWORD m_dwAnnotationEntryMapShared; // WORD* - Map from a shared parameter list offset to an offset in the annotation list to the set of annotations belonging to the parameter + + DWORD m_dwAnnotationCountListShared; // WORD* - List of annotation counts for shared parameters (which cannot be stored in the Annotations field of an FXLPARAMETERENTRY since the count can vary across effects) + + DWORD m_dwNameListLocal; // CHAR* - Ordered list of all top level local parameter names followed after by a collection of member names, technique names, pass names, and annotation names + UINT m_NameListSizeLocal; // Size of the local parameter name list in bytes + DWORD m_dwNameListShared; // DWORD* - CHAR** - Ordered list of all top level shared parameter names in the effect/pool followed after by member names + UINT m_NameListSizeShared; // Size of the shared parameter name list in bytes + + DWORD m_dwParameterNameMapLocal; // DWORD* - CHAR** + DWORD m_dwParameterNameMapShared; // DWORD* - DWORD** - CHAR*** + DWORD m_dwAnnotationNameMap; // DWORD* - CHAR** + + DWORD m_dwCreatorName; // CHAR* - Name of the effect creator + + DWORD m_dwParameterHandleIndexMap; // FXLHANDLE* + UINT m_ParameterHandleIndexMapSize; // Number of entries in the index map. + + DWORD m_CompilationFlags; // Copy of the flags given when the effect was compiled + + DWORD m_TechniqueFlags; // Copy of the flags given to BeginTechnique + + DWORD m_dwEffectPool; // FXLEffectPool* - Pointer to the pool used by the effect + + DWORD m_dwDevice; // D3DDevice* +}; + +/* + * Effect Pool functions and methods. + */ + +ULONG WINAPI FXLEffectPool_AddRef(__in FXLEffectPool* pEffectPool); +ULONG WINAPI FXLEffectPool_Release(__in FXLEffectPool* pEffectPool); + +VOID WINAPI FXLEffectPool_SetFloat(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, FLOAT Data); +FLOAT WINAPI FXLEffectPool_GetFloat(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter); +VOID WINAPI FXLEffectPool_SetScalarF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffectPool_GetScalarF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out FLOAT* pData); +VOID WINAPI FXLEffectPool_SetScalarArrayF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(Count) CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_GetScalarArrayF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out_ecount(Count) FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetInt(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, INT Data); +INT WINAPI FXLEffectPool_GetInt(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter); +VOID WINAPI FXLEffectPool_SetScalarI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST INT* pData); +VOID WINAPI FXLEffectPool_GetScalarI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out INT* pData); +VOID WINAPI FXLEffectPool_SetScalarArrayI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(Count) CONST INT* pData, UINT Count); +VOID WINAPI FXLEffectPool_GetScalarArrayI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out_ecount(Count) INT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetBool(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, BOOL Data); +BOOL WINAPI FXLEffectPool_GetBool(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter); +VOID WINAPI FXLEffectPool_SetScalarB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST BOOL* pData); +VOID WINAPI FXLEffectPool_GetScalarB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out BOOL* pData); +VOID WINAPI FXLEffectPool_SetScalarArrayB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(Count) CONST BOOL* pData, UINT Count); +VOID WINAPI FXLEffectPool_GetScalarArrayB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out_ecount(Count) BOOL* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetVector(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, FXLVECTOR Data); +FXLVECTOR WINAPI FXLEffectPool_GetVector(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter); +VOID WINAPI FXLEffectPool_SetVectorF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffectPool_SetVectorFA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); +VOID WINAPI FXLEffectPool_GetVectorF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out FLOAT* pData); +VOID WINAPI FXLEffectPool_SetVectorArrayF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetVectorArrayF4A(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData, UINT Count); +VOID WINAPI FXLEffectPool_GetVectorArrayF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetVectorI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST INT* pData); +VOID WINAPI FXLEffectPool_SetVectorIA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLINTA* pData); +VOID WINAPI FXLEffectPool_GetVectorI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out INT* pData); +VOID WINAPI FXLEffectPool_SetVectorB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST BOOL* pData); +VOID WINAPI FXLEffectPool_SetVectorBA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); +VOID WINAPI FXLEffectPool_GetVectorB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out BOOL* pData); +VOID WINAPI FXLEffectPool_SetMatrix(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in FXLMATRIX* pData); +VOID WINAPI FXLEffectPool_GetMatrix(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out FXLMATRIX* pData); +VOID WINAPI FXLEffectPool_SetMatrixRaw(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in FXLMATRIX* pData); +VOID WINAPI FXLEffectPool_SetMatrixF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffectPool_SetMatrixFA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); +VOID WINAPI FXLEffectPool_GetMatrixF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out FLOAT* pData); +VOID WINAPI FXLEffectPool_SetMatrixF4x4(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); +VOID WINAPI FXLEffectPool_SetMatrixF4x4A(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); +VOID WINAPI FXLEffectPool_GetMatrixF4x4(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out_ecount(16) FLOAT* pData); +VOID WINAPI FXLEffectPool_SetMatrixRawF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffectPool_SetMatrixRawFA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); +VOID WINAPI FXLEffectPool_SetMatrixRawF4x4(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); +VOID WINAPI FXLEffectPool_SetMatrixRawF4x4A(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); +VOID WINAPI FXLEffectPool_SetMatrixArrayF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_GetMatrixArrayF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetMatrixArrayF4x4(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetMatrixArrayF4x4A(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); +VOID WINAPI FXLEffectPool_GetMatrixArrayF4x4(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out_ecount(16*Count) FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetMatrixArrayRawF(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetMatrixArrayRawF4x4(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetMatrixArrayRawF4x4A(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); +VOID WINAPI FXLEffectPool_SetMatrixI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST INT* pData); +VOID WINAPI FXLEffectPool_SetMatrixIA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLINTA* pData); +VOID WINAPI FXLEffectPool_GetMatrixI(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out INT* pData); +VOID WINAPI FXLEffectPool_SetMatrixB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST BOOL* pData); +VOID WINAPI FXLEffectPool_SetMatrixBA(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); +VOID WINAPI FXLEffectPool_GetMatrixB(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out BOOL* pData); +VOID WINAPI FXLEffectPool_SetSampler(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in_opt CONST IDirect3DBaseTexture9* pTexture); +VOID WINAPI FXLEffectPool_GetSampler(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __deref_out IDirect3DBaseTexture9** pTexture); +VOID WINAPI FXLEffectPool_SetParameter(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __in CONST VOID* pData); +VOID WINAPI FXLEffectPool_GetParameter(__in FXLEffectPool* pEffectPool, FXLHANDLE Parameter, __out VOID* pData); + +FXLHANDLE WINAPI FXLEffectPool_GetParameterHandle(__in FXLEffectPool* pEffectPool, __in_z CONST CHAR* pParameterName); +FXLHANDLE WINAPI FXLEffectPool_GetMemberHandle(__in FXLEffectPool* pEffectPool, __in FXLHANDLE Struct, __in_z CONST CHAR* pMemberName); +FXLHANDLE WINAPI FXLEffectPool_GetMemberHandleFromIndex(__in FXLEffectPool* pEffectPool, __in FXLHANDLE Struct, UINT MemberIndex); +FXLHANDLE WINAPI FXLEffectPool_GetElementHandle(__in FXLEffectPool* pEffectPool, __in FXLHANDLE Array, UINT ElementIndex); + +VOID WINAPI FXLEffectPool_GetParameterDesc(__in FXLEffectPool* pEffectPool, __in FXLHANDLE Parameter, __out FXLPARAMETER_DESC* pDesc); + +VOID WINAPI FXLEffectPool_SetParameterRegisterUpdate(__in FXLEffectPool* pEffectPool, __in FXLHANDLE Parameter, FXLREGISTER_UPDATE UpdateMode); + +HRESULT WINAPI FXLEffectPool_Dump(FXLEffectPool* pPool, ID3DXBuffer** pOutput); + +#ifdef __cplusplus + +FXLFINLINE ULONG WINAPI FXLEffectPool::AddRef() { return FXLEffectPool_AddRef(this); } +FXLFINLINE ULONG WINAPI FXLEffectPool::Release() { return FXLEffectPool_Release(this); } + +FXLFINLINE VOID WINAPI FXLEffectPool::SetFloat(FXLHANDLE Parameter, FLOAT Data) { FXLEffectPool_SetFloat(this, Parameter, Data); } +FXLFINLINE FLOAT WINAPI FXLEffectPool::GetFloat(FXLHANDLE Parameter) { return FXLEffectPool_GetFloat(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetScalarF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffectPool_SetScalarF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetScalarF(FXLHANDLE Parameter, __out FLOAT* pData) { FXLEffectPool_GetScalarF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetScalarArrayF(FXLHANDLE Parameter, __in_ecount(Count) CONST FLOAT* pData, UINT Count) { FXLEffectPool_SetScalarArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetScalarArrayF(FXLHANDLE Parameter, __out_ecount(Count) FLOAT* pData, UINT Count) { FXLEffectPool_GetScalarArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetInt(FXLHANDLE Parameter, INT Data) { FXLEffectPool_SetInt(this, Parameter, Data); } +FXLFINLINE INT WINAPI FXLEffectPool::GetInt(FXLHANDLE Parameter) { return FXLEffectPool_GetInt(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetScalarI(FXLHANDLE Parameter, __in CONST INT* pData) { FXLEffectPool_SetScalarI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetScalarI(FXLHANDLE Parameter, __out INT* pData) { FXLEffectPool_GetScalarI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetScalarArrayI(FXLHANDLE Parameter, __in_ecount(Count) CONST INT* pData, UINT Count) { FXLEffectPool_SetScalarArrayI(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetScalarArrayI(FXLHANDLE Parameter, __out_ecount(Count) INT* pData, UINT Count) { FXLEffectPool_GetScalarArrayI(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetBool(FXLHANDLE Parameter, BOOL Data) { FXLEffectPool_SetBool(this, Parameter, Data); } +FXLFINLINE BOOL WINAPI FXLEffectPool::GetBool(FXLHANDLE Parameter) { return FXLEffectPool_GetBool(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetScalarB(FXLHANDLE Parameter, __in CONST BOOL* pData) { FXLEffectPool_SetScalarB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetScalarB(FXLHANDLE Parameter, __out BOOL* pData) { FXLEffectPool_GetScalarB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetScalarArrayB(FXLHANDLE Parameter, __in_ecount(Count) CONST BOOL* pData, UINT Count) { FXLEffectPool_SetScalarArrayB(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetScalarArrayB(FXLHANDLE Parameter, __out_ecount(Count) BOOL* pData, UINT Count) { FXLEffectPool_GetScalarArrayB(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffectPool_SetVectorF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVector(FXLHANDLE Parameter, FXLVECTOR Data) { FXLEffectPool_SetVector(this, Parameter, Data); } +FXLFINLINE FXLVECTOR WINAPI FXLEffectPool::GetVector(FXLHANDLE Parameter) { return FXLEffectPool_GetVector(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData) { FXLEffectPool_SetVectorFA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetVectorF(FXLHANDLE Parameter, __out FLOAT* pData) { FXLEffectPool_GetVectorF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count) { FXLEffectPool_SetVectorArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorArrayF4A(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData, UINT Count) { FXLEffectPool_SetVectorArrayF4A(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetVectorArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count) { FXLEffectPool_GetVectorArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorI(FXLHANDLE Parameter, __in CONST INT* pData) { FXLEffectPool_SetVectorI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData) { FXLEffectPool_SetVectorIA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetVectorI(FXLHANDLE Parameter, __out INT* pData) { FXLEffectPool_GetVectorI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorB(FXLHANDLE Parameter, __in CONST BOOL* pData) { FXLEffectPool_SetVectorB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetVectorBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData) { FXLEffectPool_SetVectorBA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetVectorB(FXLHANDLE Parameter, __out BOOL* pData) { FXLEffectPool_GetVectorB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrix(FXLHANDLE Parameter, __in FXLMATRIX* pData) { FXLEffectPool_SetMatrix(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrix(FXLHANDLE Parameter, __out FXLMATRIX* pData) { FXLEffectPool_GetMatrix(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixRaw(FXLHANDLE Parameter, __in FXLMATRIX* pData) { FXLEffectPool_SetMatrixRaw(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffectPool_SetMatrixF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData) { FXLEffectPool_SetMatrixFA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrixF(FXLHANDLE Parameter, __out FLOAT* pData) { FXLEffectPool_GetMatrixF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData) { FXLEffectPool_SetMatrixF4x4(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData) { FXLEffectPool_SetMatrixF4x4A(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrixF4x4(FXLHANDLE Parameter, __out_ecount(16) FLOAT* pData) { FXLEffectPool_GetMatrixF4x4(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffectPool_SetMatrixRawF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixRawFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData) { FXLEffectPool_SetMatrixRawFA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixRawF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData) { FXLEffectPool_SetMatrixRawF4x4(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixRawF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData) { FXLEffectPool_SetMatrixRawF4x4A(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count) { FXLEffectPool_SetMatrixArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrixArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count) { FXLEffectPool_GetMatrixArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixArrayF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count) { FXLEffectPool_SetMatrixArrayF4x4(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixArrayF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count) { FXLEffectPool_SetMatrixArrayF4x4A(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrixArrayF4x4(FXLHANDLE Parameter, __out_ecount(16*Count) FLOAT* pData, UINT Count) { FXLEffectPool_GetMatrixArrayF4x4(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixArrayRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count) { FXLEffectPool_SetMatrixArrayRawF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixArrayRawF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count) { FXLEffectPool_SetMatrixArrayRawF4x4(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixArrayRawF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count) { FXLEffectPool_SetMatrixArrayRawF4x4A(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixI(FXLHANDLE Parameter, __in CONST INT* pData) { FXLEffectPool_SetMatrixI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData) { FXLEffectPool_SetMatrixIA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrixI(FXLHANDLE Parameter, __out INT* pData) { FXLEffectPool_GetMatrixI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixB(FXLHANDLE Parameter, __in CONST BOOL* pData) { FXLEffectPool_SetMatrixB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetMatrixBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData) { FXLEffectPool_SetMatrixBA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetMatrixB(FXLHANDLE Parameter, __out BOOL* pData) { FXLEffectPool_GetMatrixB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetSampler(FXLHANDLE Parameter, __in_opt CONST IDirect3DBaseTexture9* pTexture) { FXLEffectPool_SetSampler(this, Parameter, pTexture); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetSampler(FXLHANDLE Parameter, __deref_out IDirect3DBaseTexture9** pTexture) { FXLEffectPool_GetSampler(this, Parameter, pTexture); } +FXLFINLINE VOID WINAPI FXLEffectPool::SetParameter(FXLHANDLE Parameter, __in CONST VOID* pData) { FXLEffectPool_SetParameter(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffectPool::GetParameter(FXLHANDLE Parameter, __out VOID* pData) { FXLEffectPool_GetParameter(this, Parameter, pData); } + +FXLFINLINE FXLHANDLE WINAPI FXLEffectPool::GetParameterHandle(__in_z CONST CHAR* pParameterName) { return FXLEffectPool_GetParameterHandle(this, pParameterName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffectPool::GetMemberHandle(__in FXLHANDLE Struct, __in_z CONST CHAR* pMemberName) { return FXLEffectPool_GetMemberHandle(this, Struct, pMemberName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffectPool::GetMemberHandleFromIndex(__in FXLHANDLE Struct, UINT MemberIndex) { return FXLEffectPool_GetMemberHandleFromIndex(this, Struct, MemberIndex); } +FXLFINLINE FXLHANDLE WINAPI FXLEffectPool::GetElementHandle(__in FXLHANDLE Array, UINT ElementIndex) { return FXLEffectPool_GetElementHandle(this, Array, ElementIndex); } + +FXLFINLINE VOID WINAPI FXLEffectPool::GetParameterDesc(__in FXLHANDLE Parameter, __out FXLPARAMETER_DESC* pDesc) { FXLEffectPool_GetParameterDesc(this, Parameter, pDesc); } + +FXLFINLINE VOID WINAPI FXLEffectPool::SetParameterRegisterUpdate(__in FXLHANDLE Parameter, FXLREGISTER_UPDATE UpdateMode) { FXLEffectPool_SetParameterRegisterUpdate(this, Parameter, UpdateMode); } + +#endif __cplusplus + +/* + * Effect functions and methods. + */ + +ULONG WINAPI FXLEffect_AddRef(__in FXLEffect* pEffect); +ULONG WINAPI FXLEffect_Release(__in FXLEffect* pEffect); + +VOID WINAPI FXLEffect_BeginTechnique(__in FXLEffect* pEffect, FXLHANDLE Technique, DWORD Flags); +VOID WINAPI FXLEffect_BeginTechniqueFromIndex(__in FXLEffect* pEffect, UINT TechniqueIndex, DWORD Flags); +VOID WINAPI FXLEffect_EndTechnique(__in FXLEffect* pEffect); +VOID WINAPI FXLEffect_BeginPass(__in FXLEffect* pEffect, FXLHANDLE Pass); +VOID WINAPI FXLEffect_BeginPassFromIndex(__in FXLEffect* pEffect, UINT PassIndex); +VOID WINAPI FXLEffect_EndPass(__in FXLEffect* pEffect); + +VOID WINAPI FXLEffect_SetFloat(__in FXLEffect* pEffect, FXLHANDLE Parameter, FLOAT Data); +FLOAT WINAPI FXLEffect_GetFloat(__in FXLEffect* pEffect, FXLHANDLE Parameter); +VOID WINAPI FXLEffect_SetScalarF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffect_GetScalarF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FLOAT* pData); +VOID WINAPI FXLEffect_SetScalarArrayF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(Count) CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_GetScalarArrayF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out_ecount(Count) FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetInt(__in FXLEffect* pEffect, FXLHANDLE Parameter, INT Data); +INT WINAPI FXLEffect_GetInt(__in FXLEffect* pEffect, FXLHANDLE Parameter); +VOID WINAPI FXLEffect_SetScalarI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST INT* pData); +VOID WINAPI FXLEffect_GetScalarI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out INT* pData); +VOID WINAPI FXLEffect_SetScalarArrayI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(Count) CONST INT* pData, UINT Count); +VOID WINAPI FXLEffect_GetScalarArrayI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out_ecount(Count) INT* pData, UINT Count); +VOID WINAPI FXLEffect_SetBool(__in FXLEffect* pEffect, FXLHANDLE Parameter, BOOL Data); +BOOL WINAPI FXLEffect_GetBool(__in FXLEffect* pEffect, FXLHANDLE Parameter); +VOID WINAPI FXLEffect_SetScalarB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST BOOL* pData); +VOID WINAPI FXLEffect_GetScalarB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out BOOL* pData); +VOID WINAPI FXLEffect_SetScalarArrayB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(Count) CONST BOOL* pData, UINT Count); +VOID WINAPI FXLEffect_GetScalarArrayB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out_ecount(Count) BOOL* pData, UINT Count); +VOID WINAPI FXLEffect_SetVector(__in FXLEffect* pEffect, FXLHANDLE Parameter, FXLVECTOR Data); +FXLVECTOR WINAPI FXLEffect_GetVector(__in FXLEffect* pEffect, FXLHANDLE Parameter); +VOID WINAPI FXLEffect_SetVectorF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffect_SetVectorFA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); +VOID WINAPI FXLEffect_GetVectorF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FLOAT* pData); +VOID WINAPI FXLEffect_SetVectorArrayF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetVectorArrayF4A(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData, UINT Count); +VOID WINAPI FXLEffect_GetVectorArrayF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetVectorI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST INT* pData); +VOID WINAPI FXLEffect_SetVectorIA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLINTA* pData); +VOID WINAPI FXLEffect_GetVectorI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out INT* pData); +VOID WINAPI FXLEffect_SetVectorB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST BOOL* pData); +VOID WINAPI FXLEffect_SetVectorBA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); +VOID WINAPI FXLEffect_GetVectorB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out BOOL* pData); +VOID WINAPI FXLEffect_SetMatrix(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in FXLMATRIX* pData); +VOID WINAPI FXLEffect_GetMatrix(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FXLMATRIX* pData); +VOID WINAPI FXLEffect_SetMatrixRaw(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in FXLMATRIX* pData); +VOID WINAPI FXLEffect_SetMatrixF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffect_SetMatrixFA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); +VOID WINAPI FXLEffect_GetMatrixF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FLOAT* pData); +VOID WINAPI FXLEffect_SetMatrixF4x4(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); +VOID WINAPI FXLEffect_SetMatrixF4x4A(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); +VOID WINAPI FXLEffect_GetMatrixF4x4(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out_ecount(16) FLOAT* pData); +VOID WINAPI FXLEffect_SetMatrixRawF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData); +VOID WINAPI FXLEffect_SetMatrixRawFA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLFLOATA* pData); +VOID WINAPI FXLEffect_SetMatrixRawF4x4(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData); +VOID WINAPI FXLEffect_SetMatrixRawF4x4A(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData); +VOID WINAPI FXLEffect_SetMatrixArrayF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_GetMatrixArrayF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetMatrixArrayF4x4(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetMatrixArrayF4x4A(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); +VOID WINAPI FXLEffect_GetMatrixArrayF4x4(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out_ecount(16*Count) FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetMatrixArrayRawF(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetMatrixArrayRawF4x4(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count); +VOID WINAPI FXLEffect_SetMatrixArrayRawF4x4A(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count); +VOID WINAPI FXLEffect_SetMatrixI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST INT* pData); +VOID WINAPI FXLEffect_SetMatrixIA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLINTA* pData); +VOID WINAPI FXLEffect_GetMatrixI(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out INT* pData); +VOID WINAPI FXLEffect_SetMatrixB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST BOOL* pData); +VOID WINAPI FXLEffect_SetMatrixBA(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST FXLBOOLA* pData); +VOID WINAPI FXLEffect_GetMatrixB(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out BOOL* pData); +VOID WINAPI FXLEffect_SetSampler(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in_opt CONST IDirect3DBaseTexture9* pTexture); +VOID WINAPI FXLEffect_GetSampler(__in FXLEffect* pEffect, FXLHANDLE Parameter, __deref_out IDirect3DBaseTexture9** pTexture); +VOID WINAPI FXLEffect_SetParameter(__in FXLEffect* pEffect, FXLHANDLE Parameter, __in CONST VOID* pData); +VOID WINAPI FXLEffect_GetParameter(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out VOID* pData); + +VOID WINAPI FXLEffect_Commit(__in FXLEffect* pEffect); +VOID WINAPI FXLEffect_CommitU(__in FXLEffect* pEffect); + +FXLHANDLE WINAPI FXLEffect_GetParameterHandle(__in FXLEffect* pEffect, __in_z CONST CHAR* pParameterName); +FXLHANDLE WINAPI FXLEffect_GetParameterHandleFromIndex(__in FXLEffect* pEffect, UINT ParameterIndex); +FXLHANDLE WINAPI FXLEffect_GetAnnotationHandle(__in FXLEffect* pEffect, FXLHANDLE Anchor, __in_z CONST CHAR* pAnnotationName); +FXLHANDLE WINAPI FXLEffect_GetAnnotationHandleFromIndex(__in FXLEffect* pEffect, FXLHANDLE Anchor, UINT AnnotationIndex); +FXLHANDLE WINAPI FXLEffect_GetMemberHandle(__in FXLEffect* pEffect, FXLHANDLE Struct, __in_z CONST CHAR* pMemberName); +FXLHANDLE WINAPI FXLEffect_GetMemberHandleFromIndex(__in FXLEffect* pEffect, FXLHANDLE Struct, UINT MemberIndex); +FXLHANDLE WINAPI FXLEffect_GetElementHandle(__in FXLEffect* pEffect, FXLHANDLE Array, UINT ElementIndex); +FXLHANDLE WINAPI FXLEffect_GetTechniqueHandle(__in FXLEffect* pEffect, __in_z CONST CHAR* pTechniqueName); +FXLHANDLE WINAPI FXLEffect_GetTechniqueHandleFromIndex(__in FXLEffect* pEffect, UINT TechniqueIndex); +FXLHANDLE WINAPI FXLEffect_GetPassHandle(__in FXLEffect* pEffect, FXLHANDLE Technique, __in_z CONST CHAR* pPassName); +FXLHANDLE WINAPI FXLEffect_GetPassHandleFromIndex(__in FXLEffect* pEffect, FXLHANDLE Technique, UINT PassIndex); + +VOID WINAPI FXLEffect_GetEffectDesc(__in FXLEffect* pEffect, __out FXLEFFECT_DESC* pDesc); +VOID WINAPI FXLEffect_GetTechniqueDesc(__in FXLEffect* pEffect, FXLHANDLE Technique, __out FXLTECHNIQUE_DESC* pDesc); +VOID WINAPI FXLEffect_GetPassDesc(__in FXLEffect* pEffect, FXLHANDLE Pass, __out FXLPASS_DESC* pDesc); +VOID WINAPI FXLEffect_GetParameterDesc(__in FXLEffect* pEffect, FXLHANDLE Parameter, __out FXLPARAMETER_DESC* pDesc); +VOID WINAPI FXLEffect_GetAnnotationDesc(__in FXLEffect* pEffect, FXLHANDLE Annotation, __out FXLANNOTATION_DESC* pDesc); + +FXLHANDLE WINAPI FXLEffect_GetActiveTechnique(__in FXLEffect* pEffect); +FXLHANDLE WINAPI FXLEffect_GetActivePass(__in FXLEffect* pEffect); +VOID WINAPI FXLEffect_GetRenderStateList(__in FXLEffect* pEffect, FXLHANDLE Pass, __out_ecount_opt(*pCount) FXLRENDERSTATE* pList, __out UINT* pCount); +VOID WINAPI FXLEffect_GetSamplerStateList(__in FXLEffect* pEffect, FXLHANDLE Sampler, __out_ecount_opt(*pCount) FXLSAMPLERSTATE* pList, __out UINT* pCount); +VOID WINAPI FXLEffect_GetRenderState(__in FXLEffect* pEffect, FXLHANDLE Pass, UINT StateIndex, __out D3DRENDERSTATETYPE* pStateType, __out DWORD* pStateValue); +VOID WINAPI FXLEffect_GetSamplerState(__in FXLEffect* pEffect, FXLHANDLE Pass, UINT StateIndex, __out UINT* pSamplerIndex, __out D3DSAMPLERSTATETYPE* pStateType, __out DWORD* pStateValue); +FXLPARAMETER_CONTEXT WINAPI FXLEffect_GetParameterContext(__in FXLEffect* pEffect, FXLHANDLE Pass, FXLHANDLE Parameter); +VOID WINAPI FXLEffect_GetParameterRegister(__in FXLEffect* pEffect, FXLHANDLE Pass, FXLHANDLE Parameter, FXLPARAMETER_CONTEXT Context, __out UINT* pRegisterIndex, __out UINT* pRegisterCount); +VOID WINAPI FXLEffect_GetAnnotation(__in FXLEffect* pEffect, FXLHANDLE Annotation, __out VOID* pData); + +VOID WINAPI FXLEffect_SetParameterRegisterUpdate(__in FXLEffect* pEffect, FXLHANDLE Parameter, FXLREGISTER_UPDATE UpdateMode); + +HRESULT WINAPI FXLEffect_CreateInstance(__in FXLEffect* pEffect, __deref_out FXLEffect** pEffectInstance); +VOID WINAPI FXLEffect_GetPool(__in FXLEffect* pEffect, __deref_out FXLEffectPool** pPool); + +HRESULT WINAPI FXLEffect_ChangeDevice(__in FXLEffect* pEffect, __in_opt IDirect3DDevice9* pDevice); +HRESULT WINAPI FXLEffect_OnLostDevice(__in FXLEffect* pEffect); +HRESULT WINAPI FXLEffect_OnResetDevice(__in FXLEffect* pEffect); + +HRESULT WINAPI FXLEffect_Dump(FXLEffect* pEffect, ID3DXBuffer** pOutput); + +#ifdef __cplusplus + +FXLFINLINE ULONG WINAPI FXLEffect::AddRef() { return FXLEffect_AddRef(this); } +FXLFINLINE ULONG WINAPI FXLEffect::Release() { return FXLEffect_Release(this); } + +FXLFINLINE VOID WINAPI FXLEffect::BeginTechnique(FXLHANDLE Technique, DWORD Flags) { FXLEffect_BeginTechnique(this, Technique, Flags); } +FXLFINLINE VOID WINAPI FXLEffect::BeginTechniqueFromIndex(UINT TechniqueIndex, DWORD Flags) { FXLEffect_BeginTechniqueFromIndex(this, TechniqueIndex, Flags); } +FXLFINLINE VOID WINAPI FXLEffect::EndTechnique() { FXLEffect_EndTechnique(this); } +FXLFINLINE VOID WINAPI FXLEffect::BeginPass(FXLHANDLE Pass) { FXLEffect_BeginPass(this, Pass); } +FXLFINLINE VOID WINAPI FXLEffect::BeginPassFromIndex(UINT PassIndex) { FXLEffect_BeginPassFromIndex(this, PassIndex); } +FXLFINLINE VOID WINAPI FXLEffect::EndPass() { FXLEffect_EndPass(this); } + +FXLFINLINE VOID WINAPI FXLEffect::SetFloat(FXLHANDLE Parameter, FLOAT Data) { FXLEffect_SetFloat(this, Parameter, Data); } +FXLFINLINE FLOAT WINAPI FXLEffect::GetFloat(FXLHANDLE Parameter) { return FXLEffect_GetFloat(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffect::SetScalarF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffect_SetScalarF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetScalarF(FXLHANDLE Parameter, __out FLOAT* pData) { FXLEffect_GetScalarF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetScalarArrayF(FXLHANDLE Parameter, __in_ecount(Count) CONST FLOAT* pData, UINT Count) { FXLEffect_SetScalarArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::GetScalarArrayF(FXLHANDLE Parameter, __out_ecount(Count) FLOAT* pData, UINT Count) { FXLEffect_GetScalarArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetInt(FXLHANDLE Parameter, INT Data) { FXLEffect_SetInt(this, Parameter, Data); } +FXLFINLINE INT WINAPI FXLEffect::GetInt(FXLHANDLE Parameter) { return FXLEffect_GetInt(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffect::SetScalarI(FXLHANDLE Parameter, __in CONST INT* pData) { FXLEffect_SetScalarI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetScalarI(FXLHANDLE Parameter, __out INT* pData) { FXLEffect_GetScalarI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetScalarArrayI(FXLHANDLE Parameter, __in_ecount(Count) CONST INT* pData, UINT Count) { FXLEffect_SetScalarArrayI(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::GetScalarArrayI(FXLHANDLE Parameter, __out_ecount(Count) INT* pData, UINT Count) { FXLEffect_GetScalarArrayI(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetBool(FXLHANDLE Parameter, BOOL Data) { FXLEffect_SetBool(this, Parameter, Data); } +FXLFINLINE BOOL WINAPI FXLEffect::GetBool(FXLHANDLE Parameter) { return FXLEffect_GetBool(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffect::SetScalarB(FXLHANDLE Parameter, __in CONST BOOL* pData) { FXLEffect_SetScalarB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetScalarB(FXLHANDLE Parameter, __out BOOL* pData) { FXLEffect_GetScalarB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetScalarArrayB(FXLHANDLE Parameter, __in_ecount(Count) CONST BOOL* pData, UINT Count) { FXLEffect_SetScalarArrayB(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::GetScalarArrayB(FXLHANDLE Parameter, __out_ecount(Count) BOOL* pData, UINT Count) { FXLEffect_GetScalarArrayB(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetVector(FXLHANDLE Parameter, FXLVECTOR Data) { FXLEffect_SetVector(this, Parameter, Data); } +FXLFINLINE FXLVECTOR WINAPI FXLEffect::GetVector(FXLHANDLE Parameter) { return FXLEffect_GetVector(this, Parameter); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffect_SetVectorF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData) { FXLEffect_SetVectorFA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetVectorF(FXLHANDLE Parameter, __out FLOAT* pData) { FXLEffect_GetVectorF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count) { FXLEffect_SetVectorArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorArrayF4A(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData, UINT Count) { FXLEffect_SetVectorArrayF4A(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::GetVectorArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count) { FXLEffect_GetVectorArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorI(FXLHANDLE Parameter, __in CONST INT* pData) { FXLEffect_SetVectorI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData) { FXLEffect_SetVectorIA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetVectorI(FXLHANDLE Parameter, __out INT* pData) { FXLEffect_GetVectorI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorB(FXLHANDLE Parameter, __in CONST BOOL* pData) { FXLEffect_SetVectorB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetVectorBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData) { FXLEffect_SetVectorBA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetVectorB(FXLHANDLE Parameter, __out BOOL* pData) { FXLEffect_GetVectorB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrix(FXLHANDLE Parameter, __in FXLMATRIX* pData) { FXLEffect_SetMatrix(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrix(FXLHANDLE Parameter, __out FXLMATRIX* pData) { FXLEffect_GetMatrix(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixRaw(FXLHANDLE Parameter, __in FXLMATRIX* pData) { FXLEffect_SetMatrixRaw(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffect_SetMatrixF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData) { FXLEffect_SetMatrixFA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrixF(FXLHANDLE Parameter, __out FLOAT* pData) { FXLEffect_GetMatrixF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData) { FXLEffect_SetMatrixF4x4(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData) { FXLEffect_SetMatrixF4x4A(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrixF4x4(FXLHANDLE Parameter, __out_ecount(16) FLOAT* pData) { FXLEffect_GetMatrixF4x4(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData) { FXLEffect_SetMatrixRawF(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixRawFA(FXLHANDLE Parameter, __in CONST FXLFLOATA* pData) { FXLEffect_SetMatrixRawFA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixRawF4x4(FXLHANDLE Parameter, __in_ecount(16) CONST FLOAT* pData) { FXLEffect_SetMatrixRawF4x4(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixRawF4x4A(FXLHANDLE Parameter, __in_ecount(16) CONST FXLFLOATA* pData) { FXLEffect_SetMatrixRawF4x4A(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixArrayF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count) { FXLEffect_SetMatrixArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrixArrayF(FXLHANDLE Parameter, __out FLOAT* pData, UINT Count) { FXLEffect_GetMatrixArrayF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixArrayF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count) { FXLEffect_SetMatrixArrayF4x4(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixArrayF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count) { FXLEffect_SetMatrixArrayF4x4A(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrixArrayF4x4(FXLHANDLE Parameter, __out_ecount(16*Count) FLOAT* pData, UINT Count) { FXLEffect_GetMatrixArrayF4x4(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixArrayRawF(FXLHANDLE Parameter, __in CONST FLOAT* pData, UINT Count) { FXLEffect_SetMatrixArrayRawF(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixArrayRawF4x4(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FLOAT* pData, UINT Count) { FXLEffect_SetMatrixArrayRawF4x4(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixArrayRawF4x4A(FXLHANDLE Parameter, __in_ecount(16*Count) CONST FXLFLOATA* pData, UINT Count) { FXLEffect_SetMatrixArrayRawF4x4A(this, Parameter, pData, Count); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixI(FXLHANDLE Parameter, __in CONST INT* pData) { FXLEffect_SetMatrixI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixIA(FXLHANDLE Parameter, __in CONST FXLINTA* pData) { FXLEffect_SetMatrixIA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrixI(FXLHANDLE Parameter, __out INT* pData) { FXLEffect_GetMatrixI(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixB(FXLHANDLE Parameter, __in CONST BOOL* pData) { FXLEffect_SetMatrixB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetMatrixBA(FXLHANDLE Parameter, __in CONST FXLBOOLA* pData) { FXLEffect_SetMatrixBA(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetMatrixB(FXLHANDLE Parameter, __out BOOL* pData) { FXLEffect_GetMatrixB(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::SetSampler(FXLHANDLE Parameter, __in_opt CONST IDirect3DBaseTexture9* pTexture) { FXLEffect_SetSampler(this, Parameter, pTexture); } +FXLFINLINE VOID WINAPI FXLEffect::GetSampler(FXLHANDLE Parameter, __deref_out IDirect3DBaseTexture9** pTexture) { FXLEffect_GetSampler(this, Parameter, pTexture); } +FXLFINLINE VOID WINAPI FXLEffect::SetParameter(FXLHANDLE Parameter, __in CONST VOID* pData) { FXLEffect_SetParameter(this, Parameter, pData); } +FXLFINLINE VOID WINAPI FXLEffect::GetParameter(FXLHANDLE Parameter, __out VOID* pData) { FXLEffect_GetParameter(this, Parameter, pData); } + +FXLFINLINE VOID WINAPI FXLEffect::Commit() { FXLEffect_Commit(this); } +FXLFINLINE VOID WINAPI FXLEffect::CommitU() { FXLEffect_CommitU(this); } + +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetParameterHandle(__in_z CONST CHAR* pParameterName) { return FXLEffect_GetParameterHandle(this, pParameterName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetParameterHandleFromIndex(UINT ParameterIndex) { return FXLEffect_GetParameterHandleFromIndex(this, ParameterIndex); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetAnnotationHandle(FXLHANDLE Anchor, __in_z CONST CHAR* pAnnotationName) { return FXLEffect_GetAnnotationHandle(this, Anchor, pAnnotationName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetAnnotationHandleFromIndex(FXLHANDLE Anchor, UINT AnnotationIndex) { return FXLEffect_GetAnnotationHandleFromIndex(this, Anchor, AnnotationIndex); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetMemberHandle(FXLHANDLE Struct, __in_z CONST CHAR* pMemberName) { return FXLEffect_GetMemberHandle(this, Struct, pMemberName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetMemberHandleFromIndex(FXLHANDLE Struct, UINT MemberIndex) { return FXLEffect_GetMemberHandleFromIndex(this, Struct, MemberIndex); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetElementHandle(FXLHANDLE Array, UINT ElementIndex) { return FXLEffect_GetElementHandle(this, Array, ElementIndex); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetTechniqueHandle(__in_z CONST CHAR* pTechniqueName) { return FXLEffect_GetTechniqueHandle(this, pTechniqueName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetTechniqueHandleFromIndex(UINT TechniqueIndex) { return FXLEffect_GetTechniqueHandleFromIndex(this, TechniqueIndex); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetPassHandle(FXLHANDLE Technique, __in_z CONST CHAR* pPassName) { return FXLEffect_GetPassHandle(this, Technique, pPassName); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetPassHandleFromIndex(FXLHANDLE Technique, UINT PassIndex) { return FXLEffect_GetPassHandleFromIndex(this, Technique, PassIndex); } + +FXLFINLINE VOID WINAPI FXLEffect::GetEffectDesc(__out FXLEFFECT_DESC* pDesc) { FXLEffect_GetEffectDesc(this, pDesc); } +FXLFINLINE VOID WINAPI FXLEffect::GetTechniqueDesc(FXLHANDLE Technique, __out FXLTECHNIQUE_DESC* pDesc) { FXLEffect_GetTechniqueDesc(this, Technique, pDesc); } +FXLFINLINE VOID WINAPI FXLEffect::GetPassDesc(FXLHANDLE Pass, __out FXLPASS_DESC* pDesc) { FXLEffect_GetPassDesc(this, Pass, pDesc); } +FXLFINLINE VOID WINAPI FXLEffect::GetParameterDesc(FXLHANDLE Parameter, __out FXLPARAMETER_DESC* pDesc) { FXLEffect_GetParameterDesc(this, Parameter, pDesc); } +FXLFINLINE VOID WINAPI FXLEffect::GetAnnotationDesc(FXLHANDLE Annotation, __out FXLANNOTATION_DESC* pDesc) { FXLEffect_GetAnnotationDesc(this, Annotation, pDesc); } + +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetActiveTechnique() { return FXLEffect_GetActiveTechnique(this); } +FXLFINLINE FXLHANDLE WINAPI FXLEffect::GetActivePass() { return FXLEffect_GetActivePass(this); } +FXLFINLINE VOID WINAPI FXLEffect::GetRenderStateList(FXLHANDLE Pass, __out_ecount_opt(*pCount) FXLRENDERSTATE* pList, __out UINT* pCount) { FXLEffect_GetRenderStateList(this, Pass, pList, pCount); } +FXLFINLINE VOID WINAPI FXLEffect::GetSamplerStateList(FXLHANDLE Sampler, __out_ecount_opt(*pCount) FXLSAMPLERSTATE* pList, __out UINT* pCount) { FXLEffect_GetSamplerStateList(this, Sampler, pList, pCount); } +FXLFINLINE VOID WINAPI FXLEffect::GetRenderState(FXLHANDLE Pass, UINT StateIndex, __out D3DRENDERSTATETYPE* pStateType, __out DWORD* pStateValue) { FXLEffect_GetRenderState(this, Pass, StateIndex, pStateType, pStateValue); } +FXLFINLINE VOID WINAPI FXLEffect::GetSamplerState(FXLHANDLE Pass, UINT StateIndex, __out UINT* pSamplerIndex, __out D3DSAMPLERSTATETYPE* pStateType, __out DWORD* pStateValue) { FXLEffect_GetSamplerState(this, Pass, StateIndex, pSamplerIndex, pStateType, pStateValue); } +FXLFINLINE FXLPARAMETER_CONTEXT WINAPI FXLEffect::GetParameterContext(FXLHANDLE Pass, FXLHANDLE Parameter) { return FXLEffect_GetParameterContext(this, Pass, Parameter); } +FXLFINLINE VOID WINAPI FXLEffect::GetParameterRegister(FXLHANDLE Pass, FXLHANDLE Parameter, FXLPARAMETER_CONTEXT Context, __out UINT* pRegisterIndex, __out UINT* pRegisterCount) { FXLEffect_GetParameterRegister(this, Pass, Parameter, Context, pRegisterIndex, pRegisterCount); } +FXLFINLINE VOID WINAPI FXLEffect::GetAnnotation(FXLHANDLE Annotation, __out VOID* pData) { FXLEffect_GetAnnotation(this, Annotation, pData); } + +FXLFINLINE VOID WINAPI FXLEffect::SetParameterRegisterUpdate(FXLHANDLE Parameter, FXLREGISTER_UPDATE UpdateMode) { FXLEffect_SetParameterRegisterUpdate(this, Parameter, UpdateMode); } + +FXLFINLINE HRESULT WINAPI FXLEffect::CreateInstance(__deref_out FXLEffect** pEffectInstance) { return FXLEffect_CreateInstance(this, pEffectInstance); } +FXLFINLINE VOID WINAPI FXLEffect::GetPool(__deref_out FXLEffectPool** pPool) { FXLEffect_GetPool(this, pPool); } + +FXLFINLINE HRESULT WINAPI FXLEffect::ChangeDevice(__in_opt IDirect3DDevice9* pDevice) { return FXLEffect_ChangeDevice(this, pDevice); } +FXLFINLINE HRESULT WINAPI FXLEffect::OnLostDevice() { return FXLEffect_OnLostDevice(this); } +FXLFINLINE HRESULT WINAPI FXLEffect::OnResetDevice() { return FXLEffect_OnResetDevice(this); } + +#endif __cplusplus + +/* + * Compile and create functions. + */ + +HRESULT WINAPI FXLCompileEffect( + __in_ecount_z(SourceDataLength) CONST CHAR* pSourceData, + UINT SourceDataLength, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out ID3DXBuffer** pCompiledData, + __deref_opt_out ID3DXBuffer** pErrorMessages + ); + +HRESULT WINAPI FXLCompileEffectExA( + __in_ecount_z(SourceDataLength) CONST CHAR* pSourceData, + UINT SourceDataLength, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out ID3DXBuffer** pCompiledData, + __deref_opt_out ID3DXBuffer** pErrorMessages, + __in_opt LPD3DXSHADER_COMPILE_PARAMETERSA pParameters + ); + +HRESULT WINAPI FXLCompileEffectExW( + __in_ecount_z(SourceDataLength) CONST CHAR* pSourceData, + UINT SourceDataLength, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out ID3DXBuffer** pCompiledData, + __deref_opt_out ID3DXBuffer** pErrorMessages, + __in_opt LPD3DXSHADER_COMPILE_PARAMETERSW pParameters + ); + +#ifdef UNICODE +#define FXLCompileEffectEx FXLCompileEffectExW +#else +#define FXLCompileEffectEx FXLCompileEffectExA +#endif + +HRESULT WINAPI FXLCompileEffectFromFileExA( + __in_z CONST CHAR* pSourceFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out ID3DXBuffer** pCompiledData, + __deref_opt_out ID3DXBuffer** pErrorMessages, + __in_opt LPD3DXSHADER_COMPILE_PARAMETERSA pParameters + ); + +HRESULT WINAPI FXLCompileEffectFromFileExW( + __in_z CONST WCHAR* pSourceFile, + __in_opt CONST D3DXMACRO* pDefines, + __in_opt LPD3DXINCLUDE pInclude, + DWORD Flags, + __deref_out ID3DXBuffer** pCompiledData, + __deref_opt_out ID3DXBuffer** pErrorMessages, + __in_opt LPD3DXSHADER_COMPILE_PARAMETERSW pParameters + ); + +#ifdef UNICODE +#define FXLCompileEffectFromFileEx FXLCompileEffectFromFileExW +#else +#define FXLCompileEffectFromFileEx FXLCompileEffectFromFileExA +#endif + +HRESULT WINAPI FXLCreateEffect( + __in_opt IDirect3DDevice9* pDevice, // May be NULL. + __in CONST VOID* pCompiledData, + __in_opt FXLEffectPool* pPool, + __deref_out FXLEffect** pEffect + ); + +HRESULT WINAPI FXLCreateEffectPool( + __deref_out FXLEffectPool** pEffectPool + ); + +HRESULT WINAPI FXLDisassembleEffect( + __in CONST VOID* pCompiledData, + DWORD Flags, + __in_z_opt LPCSTR pComments, + __deref_out ID3DXBuffer** pDisassembly + ); + +/* + * Default state management functions. + */ + +VOID WINAPI FXLSetDefaultRenderState( + D3DRENDERSTATETYPE StateType, + DWORD StateValue + ); + +VOID WINAPI FXLGetDefaultRenderState( + D3DRENDERSTATETYPE StateType, + __out DWORD* pStateValue + ); + +VOID WINAPI FXLSetDefaultSamplerState( + D3DSAMPLERSTATETYPE StateType, + DWORD StateValue + ); + +VOID WINAPI FXLGetDefaultSamplerState( + D3DSAMPLERSTATETYPE StateType, + __out DWORD* pStateValue + ); + +VOID WINAPI FXLApplyDefaultRenderStates( + __in IDirect3DDevice9* pDevice + ); + +VOID WINAPI FXLApplyDefaultSamplerStates( + __in IDirect3DDevice9* pDevice + ); + +#if defined(_M_PPCBE) +#pragma bitfield_order(pop) +#endif + +#ifdef __cplusplus +}; // extern "C" +#endif + +#include + +#pragma warning(pop) + +#endif /* _FXL_H_ */ diff --git a/third_party/xbox_sdk/include/fxl.inl b/third_party/xbox_sdk/include/fxl.inl new file mode 100644 index 0000000..08d4512 --- /dev/null +++ b/third_party/xbox_sdk/include/fxl.inl @@ -0,0 +1,8231 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: fxl.inl + * Content: Xenon Effects inline function file + * + ****************************************************************************/ + +#pragma once + +#ifndef __FXL_INL__ +#define __FXL_INL__ + +#pragma warning(push) +#pragma warning(disable:4616 6326 6385 6387) + +#ifdef _XBOX +#include +#endif + +#ifdef __cplusplus +//extern "C" { +#endif + +/**************************************************************************** + * + * Begin: Private internal interfaces and data - Please don't access these + * directly, as they're subject to change. + * + ****************************************************************************/ + +#define FXLCONST extern CONST __declspec(selectany) + +#define FXLHANDLE_PARAMETER_OFFSET_SHIFT 18 +#define FXLHANDLE_PARAMETER_OFFSET_MASK 0xFFFC0000 +#define FXLHANDLE_PARAMETER_INDEX_SHIFT 1 +#define FXLHANDLE_PARAMETER_INDEX_MASK 0x0003FFFE + +#define FXLHANDLE_PASS_OFFSET_SHIFT FXLHANDLE_PARAMETER_OFFSET_SHIFT +#define FXLHANDLE_PASS_OFFSET_MASK FXLHANDLE_PARAMETER_OFFSET_MASK +#define FXLHANDLE_PASS_IDENTIFIER FXLHANDLE_PARAMETER_INDEX_MASK + +#define FXLHANDLE_TECHNIQUE_OFFSET_SHIFT FXLHANDLE_PARAMETER_OFFSET_SHIFT +#define FXLHANDLE_TECHNIQUE_OFFSET_MASK FXLHANDLE_PARAMETER_OFFSET_MASK +#define FXLHANDLE_TECHNIQUE_IDENTIFIER (((FXLHANDLE_PARAMETER_INDEX_MASK >> FXLHANDLE_PARAMETER_INDEX_SHIFT) - 1) << FXLHANDLE_PARAMETER_INDEX_SHIFT) + +#define FXLHANDLE_ANNOTATION_OFFSET_SHIFT FXLHANDLE_PARAMETER_OFFSET_SHIFT +#define FXLHANDLE_ANNOTATION_OFFSET_MASK FXLHANDLE_PARAMETER_OFFSET_MASK +#define FXLHANDLE_ANNOTATION_IDENTIFIER (((FXLHANDLE_PARAMETER_INDEX_MASK >> FXLHANDLE_PARAMETER_INDEX_SHIFT) - 2) << FXLHANDLE_PARAMETER_INDEX_SHIFT) + +#define FXL_MAX_PARAMETER_DATA_ENTRIES ((FXLHANDLE_PARAMETER_INDEX_MASK >> FXLHANDLE_PARAMETER_INDEX_SHIFT) - 2) + +#define FXL_DEFAULT_RENDER_STATE_ENTRIES 90 +#define FXL_DEFAULT_SAMPLER_STATE_ENTRIES 20 + +//------------------------------------------------------------------------------ + +FXLEXTERN FXLRENDERSTATEDATA g_FXLIDefaultRenderStateList[FXL_DEFAULT_RENDER_STATE_ENTRIES]; +FXLEXTERN FXLSAMPLERSTATEDATA g_FXLIDefaultSamplerStateList[FXL_DEFAULT_SAMPLER_STATE_ENTRIES]; + +//------------------------------------------------------------------------------ + +FXLCONST XMVECTORI g_FXLITypeSelect[2] = {{0, 0, 0, 0}, {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}}; + +//------------------------------------------------------------------------------ + +FXLCONST DWORD g_FXLIRegisterIndexOffset[] = +{ + 1, + 2, + 1, + 2, + 3, + 3, + 1, + 2, +}; + +//------------------------------------------------------------------------------ + +FXLCONST DWORD g_FXLIRegisterIndexMask[] = +{ + 0x000003FF, + 0x000003FF, + 0x000FF000, + 0x000FF000, + 0x000000FF, + 0x0000FF00, + 0x3FC00000, + 0x3FC00000, +}; + +//------------------------------------------------------------------------------ + +FXLCONST DWORD g_FXLIRegisterIndexShift[] = +{ + 0, + 0, + 12, + 12, + 0, + 8, + 22, + 22, +}; + +//------------------------------------------------------------------------------ + +FXLCONST DWORD g_FXLIRegisterCountOffset[] = +{ + 1, + 2, + 1, + 2, + 1, + 2, + 1, // Don't care + 1, // Don't care +}; + +//------------------------------------------------------------------------------ + +FXLCONST DWORD g_FXLIRegisterCountMask[] = +{ + 0x00000C00, + 0x00000C00, + 0x00300000, + 0x00300000, + 0xC0000000, + 0xC0000000, + 0x00000000, + 0x00000000, +}; + +//------------------------------------------------------------------------------ + +FXLCONST DWORD g_FXLIRegisterCountShift[] = +{ + 10, + 10, + 20, + 20, + 30, + 30, + 0, + 0, +}; + +/**************************************************************************** + * + * Debugging routines. + * + ****************************************************************************/ + +#if DBG + + #define PARAMETER_CHECK 1 + + VOID FXLPRINT(__in_z PCHAR Format, ...); + VOID FXLRIP(__in_z PCHAR Format, ...); + VOID FXLWARNING(__in_z PCHAR Format, ...); + VOID FXLASSERTMSG(BOOL cond, __in_z PCHAR Format, ...); + + #if defined(_PREFAST_) + #define FXLASSERT(cond) { __analysis_assume((cond)); } + #else + #define FXLASSERT(cond) { if (!(cond)) FXLRIP("Assertion failure: %s\n", #cond); } + #endif + + #if i386 + #define FXLBREAK() { __asm { int 3 } } + #else + #define FXLBREAK() { __debugbreak(); } + #endif + +#else + + #define PARAMETER_CHECK 0 + + VOID FXLPRINT(__in_z PCHAR Format, ...); + + #define FXLRIP 1 ? (void)0 : (void) + #define FXLWARNING 1 ? (void)0 : (void) + #define FXLASSERTMSG 1 ? (void)0 : (void) + + #if defined(_PREFAST_) + #define FXLASSERT(cond) { __analysis_assume((cond)); } + #else + #define FXLASSERT(cond) {} + #endif + + #define FXLBREAK() + +#endif + +/**************************************************************************** + * + * 32-bit pointer access. + * + ****************************************************************************/ + +template < typename T > +__forceinline +T* FXLDWORDToPtr(DWORD dw) +{ + return D3DDWORDToPtr(dw); +} + +__forceinline +void* FXLDWORDToPtr(DWORD dw) +{ + return D3DDWORDToPtr(dw); +} + +__forceinline +DWORD FXLPtrToDWORD(void const* ptr) +{ + return D3DPtrToDWORD(ptr); +} + +FXLFINLINE __out UINT64* FXLI_pUsageFlags (__in FXLSHADERSTATEENTRY const* pEntry, DWORD i) { return FXLDWORDToPtr((&pEntry->dwVSFUsageFlagsLocal )[i]); } +FXLFINLINE __out UINT64* FXLI_pVSFUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSFUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pPSFUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSFUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pVSIUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSIUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pPSIUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSIUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pVSBUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSBUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pPSBUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSBUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pVSSUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSSUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pPSSUsageFlagsLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSSUsageFlagsLocal ); } +FXLFINLINE __out UINT64* FXLI_pVSFUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSFUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pPSFUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSFUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pVSIUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSIUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pPSIUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSIUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pVSBUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSBUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pPSBUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSBUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pVSSUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVSSUsageFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pPSSUsageFlagsShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPSSUsageFlagsShared ); } +FXLFINLINE __out FXLPASSPARAMETERREF* FXLI_pReferenceListLocal (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwReferenceListLocal ); } +FXLFINLINE __out FXLPASSPARAMETERREF* FXLI_pReferenceListShared(__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwReferenceListShared ); } +FXLFINLINE __out FXLVERTEXSHADERENTRY* FXLI_pVertexShader (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwVertexShader ); } +FXLFINLINE __out FXLPIXELSHADERENTRY* FXLI_pPixelShader (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwPixelShader ); } +FXLFINLINE __out XMFLOAT4A16* FXLI_pIntLiteralData (__in FXLSHADERSTATEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwIntLiteralData ); } + +FXLFINLINE __out_z CHAR* FXLI_pName (__in FXLPASSENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwName ); } +FXLFINLINE __out FXLSHADERSTATEENTRY* FXLI_pShaderStates (__in FXLPASSENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwShaderStates ); } +FXLFINLINE __out FXLRENDERSTATEENTRY* FXLI_pRenderStates (__in FXLPASSENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwRenderStates ); } +FXLFINLINE __out FXLSAMPLERSTATEENTRY* FXLI_pSamplerStates(__in FXLPASSENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwSamplerStates); } + +FXLFINLINE __out_z CHAR* FXLI_pName(__in FXLTECHNIQUEENTRY const* pEntry) { return FXLDWORDToPtr(pEntry->dwName ); } +FXLFINLINE __out FXLPASSENTRY* FXLI_pPass(__in FXLTECHNIQUEENTRY const* pEntry, DWORD i) { return FXLDWORDToPtr(pEntry->pdwPassList[i]); } + +FXLFINLINE __out FXLPARAMETERENTRY* FXLI_pParameterList (__in FXLEffectPool const* pEffectPool) { return FXLDWORDToPtr(pEffectPool->m_dwParameterList ); } +FXLFINLINE __out XMFLOAT4A16* FXLI_pParameterData (__in FXLEffectPool const* pEffectPool) { return FXLDWORDToPtr(pEffectPool->m_dwParameterData ); } +FXLFINLINE __out_z CHAR* FXLI_pNameList (__in FXLEffectPool const* pEffectPool) { return FXLDWORDToPtr(pEffectPool->m_dwNameList ); } +FXLFINLINE __out DWORD* FXLI_pParameterNameMap(__in FXLEffectPool const* pEffectPool) { return FXLDWORDToPtr(pEffectPool->m_dwParameterNameMap ); } +FXLFINLINE __out_z CHAR* FXLI_pParameterName (__in FXLEffectPool const* pEffectPool, DWORD i) { return FXLDWORDToPtr(FXLI_pParameterNameMap(pEffectPool)[i]); } + +FXLFINLINE __out UINT64* FXLI_pDirtyFlagsShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwDirtyFlagsShared ); } +FXLFINLINE __out UINT64* FXLI_pUpdateFlagsShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwUpdateFlagsShared ); } +FXLFINLINE __out FXLPARAMETERENTRY* FXLI_pParameterListLocal (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwParameterListLocal ); } +FXLFINLINE __out FXLPARAMETERENTRY* FXLI_pParameterListShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(*FXLDWORDToPtr(pEffect->m_dwParameterListShared) ); } +FXLFINLINE __out XMFLOAT4A16* FXLI_pParameterDataLocal (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwParameterDataLocal ); } +FXLFINLINE __out XMFLOAT4A16* FXLI_pParameterDataShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(*FXLDWORDToPtr(pEffect->m_dwParameterDataShared) ); } +FXLFINLINE __out DWORD* FXLI_pTechniqueList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwTechniqueList ); } +FXLFINLINE __out FXLTECHNIQUEENTRY* FXLI_pTechnique (__in FXLEffect const* pEffect, DWORD i) { return FXLDWORDToPtr(FXLDWORDToPtr(pEffect->m_dwTechniqueList)[i] ); } +FXLFINLINE __out FXLTECHNIQUEENTRY* FXLI_pActiveTechnique (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwActiveTechnique ); } +FXLFINLINE __out FXLPASSENTRY* FXLI_pPassList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwPassList ); } +FXLFINLINE __out FXLPASSENTRY* FXLI_pPass (__in FXLEffect const* pEffect, DWORD i) { return FXLDWORDToPtr(pEffect->m_dwPassList ) + i; } +FXLFINLINE __out FXLPASSENTRY* FXLI_pActivePass (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwActivePass ); } +FXLFINLINE __out FXLSHADERSTATEENTRY* FXLI_pActiveShader (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwActiveShader ); } +FXLFINLINE __out FXLPASSENTRY* FXLI_pPreviousPass (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwPreviousPass ); } +FXLFINLINE __out FXLSHADERSTATEENTRY* FXLI_pShaderStateList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwShaderStateList ); } +FXLFINLINE __out FXLVERTEXSHADERENTRY* FXLI_pVertexShaderList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwVertexShaderList ); } +FXLFINLINE __out FXLPIXELSHADERENTRY* FXLI_pPixelShaderList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwPixelShaderList ); } +FXLFINLINE __out FXLRENDERSTATEENTRY* FXLI_pRenderStateList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwRenderStateList ); } +FXLFINLINE __out FXLSAMPLERSTATEENTRY* FXLI_pSamplerStateList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwSamplerStateList ); } +FXLFINLINE __out FXLPARAMETERENTRY* FXLI_pAnnotationList (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationList ); } +FXLFINLINE __out DWORD* FXLI_pAnnotationData (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationData ); } +FXLFINLINE __out WORD* FXLI_pAnnotationEntryMapTechnique(__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationEntryMapTechnique ); } +FXLFINLINE __out WORD* FXLI_pAnnotationEntryMapPass (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationEntryMapPass ); } +FXLFINLINE __out WORD* FXLI_pAnnotationEntryMapLocal (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationEntryMapLocal ); } +FXLFINLINE __out WORD* FXLI_pAnnotationEntryMapShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationEntryMapShared ); } +FXLFINLINE __out WORD* FXLI_pAnnotationCountListShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationCountListShared ); } +FXLFINLINE __out_z CHAR* FXLI_pNameListLocal (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwNameListLocal ); } +FXLFINLINE __out_z CHAR* FXLI_pNameListShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(*FXLDWORDToPtr(pEffect->m_dwNameListShared) ); } +FXLFINLINE __out DWORD* FXLI_pParameterNameMapLocal (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwParameterNameMapLocal ); } +FXLFINLINE __out DWORD* FXLI_pParameterNameMapShared (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(*FXLDWORDToPtr(pEffect->m_dwParameterNameMapShared)); } +FXLFINLINE __out DWORD* FXLI_pAnnotationNameMap (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwAnnotationNameMap ); } +FXLFINLINE __out_z CHAR* FXLI_pAnnotationNameMap (__in FXLEffect const* pEffect, DWORD i) { return FXLDWORDToPtr(FXLDWORDToPtr(pEffect->m_dwAnnotationNameMap)[i] ); } +FXLFINLINE __out_z CHAR* FXLI_pCreatorName (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwCreatorName ); } +FXLFINLINE __out FXLHANDLE* FXLI_pParameterHandleIndexMap (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwParameterHandleIndexMap ); } +FXLFINLINE __out FXLEffectPool* FXLI_pEffectPool (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwEffectPool ); } +FXLFINLINE __out D3DDevice* FXLI_pDevice (__in FXLEffect const* pEffect) { return FXLDWORDToPtr(pEffect->m_dwDevice ); } + +/**************************************************************************** + * + * Internal routines. + * + ****************************************************************************/ + +VOID WINAPI FXLSetShaders(__in IDirect3DDevice9* pDevice, __in FXLSHADERSTATEENTRY* pShaderStateData); + +/**************************************************************************** + * + * Helper routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_CountLeadingZeros( + UINT Value) +{ +#ifndef _XBOX + UINT Count; + + for (Count = 0; (Value < (1 << 31)) && (Count < 32); Count++) + { + Value <<= 1; + } + + return Count; +#else + return _CountLeadingZeros(Value); +#endif +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_CountLeadingZeros64( + UINT64 Value) +{ +#ifndef _XBOX + UINT Count; + + for (Count = 0; (Value < (1ull << 63)) && (Count < 64); Count++) + { + Value <<= 1; + } + + return Count; +#else + return _CountLeadingZeros64(Value); +#endif +} + +//------------------------------------------------------------------------------ + +FXLFINLINE BOOL FXLI_IsPow2( + DWORD Value) +{ + return (((Value - 1) & Value) == 0); +} + +//------------------------------------------------------------------------------ + +template < typename T > +FXLFINLINE BOOL FXLI_Is32Bits(T v) +{ + if (sizeof(T) <= 4) + { + return TRUE; + } + + if (T(-1) > 0) + { + // Unsigned type. + return v <= 0xFFFFFFFFU; + } + else + { + // Signed type. + return v >= -0x7FFFFFFF-1 && v <= 0x7FFFFFFF; + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE DWORD FXLI_Log2( + DWORD Value) +{ + FXLASSERT((Value != 0) && (FXLI_IsPow2(Value))); + + return 31 - FXLI_CountLeadingZeros(Value); +} + +//------------------------------------------------------------------------------ + +#define FXLI_SelectMatrix(RM, M1, M2, Control) \ + RM.r[0] = XMVectorSelect(M1.r[0], M2.r[0], Control); \ + RM.r[1] = XMVectorSelect(M1.r[1], M2.r[1], Control); \ + RM.r[2] = XMVectorSelect(M1.r[2], M2.r[2], Control); \ + RM.r[3] = XMVectorSelect(M1.r[3], M2.r[3], Control); + +/**************************************************************************** + * + * Handle management routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +template < typename T > +FXLFINLINE T FXLI_SelectValue( + FXLHANDLE Parameter, + T LocalValue, + T SharedValue) +{ + T const Select = T(Parameter & 1) - 1; + T const Local = LocalValue & Select; + T const Shared = SharedValue & ~Select; + return Local + Shared; +} + +//------------------------------------------------------------------------------ + +// Specialization for pointers. + +template < typename T > +FXLFINLINE __out T* FXLI_SelectValue( + FXLHANDLE Parameter, + __in T* LocalValue, + __in T* SharedValue) +{ + UINT_PTR const Select = UINT_PTR(Parameter & 1) - 1; + UINT_PTR const Local = UINT_PTR(LocalValue) & Select; + UINT_PTR const Shared = UINT_PTR(SharedValue) & ~Select; + return (T*) (Local + Shared); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_GetParameterOffset( + FXLHANDLE Parameter) +{ + return (Parameter >> FXLHANDLE_PARAMETER_OFFSET_SHIFT); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_GetParameterIndex( + FXLHANDLE Parameter) +{ + return (Parameter & FXLHANDLE_PARAMETER_INDEX_MASK) >> FXLHANDLE_PARAMETER_INDEX_SHIFT; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE DWORD FXLI_GetHandleIdentifier( + FXLHANDLE Handle) +{ + return (Handle & FXLHANDLE_PARAMETER_INDEX_MASK); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE BOOL FXLI_IsParameterShared( + FXLHANDLE Parameter) +{ + return (BOOL)(Parameter & 1); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLPARAMETERENTRY* FXLEffectI_GetParameterEntry( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + DWORD Offset = FXLI_GetParameterOffset(Parameter); + FXLPARAMETERENTRY* Entry = FXLI_SelectValue(Parameter, FXLI_pParameterListLocal(pEffect), FXLI_pParameterListShared(pEffect)); + return Entry + Offset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out XMFLOAT4A16* FXLEffectI_GetParameterData( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + return FXLI_SelectValue(Parameter, FXLI_pParameterDataLocal(pEffect), FXLI_pParameterDataShared(pEffect)); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out UINT64* FXLEffectI_GetDirtyFlags( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + return FXLI_SelectValue(Parameter, pEffect->m_DirtyFlagsLocal, FXLI_pDirtyFlagsShared(pEffect)); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FLOAT* FXLEffectI_GetDynamicStateValue( + __in FXLEffect* pEffect, + DWORD DynamicValue) +{ + return (FLOAT*)(FXLI_SelectValue(DynamicValue >> 31, FXLI_pParameterDataLocal(pEffect), FXLI_pParameterDataShared(pEffect)) + (DynamicValue & ~(FXLPFLAG_SHARED << 31))); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_EncodeParameterHandle( + DWORD ListOffset, + DWORD DataIndex, + DWORD Shared) +{ + FXLASSERT(DataIndex < FXL_MAX_PARAMETER_DATA_ENTRIES); + FXLASSERT((DataIndex & ~(FXLHANDLE_PARAMETER_INDEX_MASK >> FXLHANDLE_PARAMETER_INDEX_SHIFT)) == 0); + FXLASSERT((ListOffset & ~(FXLHANDLE_PARAMETER_OFFSET_MASK >> FXLHANDLE_PARAMETER_OFFSET_SHIFT)) == 0); + + return (ListOffset << FXLHANDLE_PARAMETER_OFFSET_SHIFT) | (DataIndex << FXLHANDLE_PARAMETER_INDEX_SHIFT) | Shared; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_EncodeTechniqueHandle( + UINT TechniqueIndex) +{ + FXLASSERT((TechniqueIndex & ~(FXLHANDLE_TECHNIQUE_OFFSET_MASK >> FXLHANDLE_TECHNIQUE_OFFSET_SHIFT)) == 0); + + return (TechniqueIndex << FXLHANDLE_TECHNIQUE_OFFSET_SHIFT) | FXLHANDLE_TECHNIQUE_IDENTIFIER; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_EncodePassHandle( + __in_opt FXLPASSENTRY* pPass, + __in_opt FXLPASSENTRY* pPassList) +{ + UINT const PassIndex = UINT(pPass - pPassList); + + FXLASSERT(FXLI_Is32Bits(pPass - pPassList)); + FXLASSERT((PassIndex & ~(FXLHANDLE_PASS_OFFSET_MASK >> FXLHANDLE_PASS_OFFSET_SHIFT)) == 0); + + return (PassIndex << FXLHANDLE_PASS_OFFSET_SHIFT) | FXLHANDLE_PASS_IDENTIFIER; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_EncodeAnnotationHandle( + UINT AnnotationOffset) +{ + FXLASSERT((AnnotationOffset & ~(FXLHANDLE_ANNOTATION_OFFSET_MASK >> FXLHANDLE_ANNOTATION_OFFSET_SHIFT)) == 0); + + return (AnnotationOffset << FXLHANDLE_ANNOTATION_OFFSET_SHIFT) | FXLHANDLE_ANNOTATION_IDENTIFIER; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLEffectI_ValidateParameterHandle( + __in FXLEffect* pEffect, + FXLHANDLE Handle) +{ + if (Handle == 0) + { + FXLRIP("ValidateParameterHandle - The given handle is NULL.\n"); + } + + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) >= FXL_MAX_PARAMETER_DATA_ENTRIES) + { + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLRIP("ValidateParameterHandle - The given handle corresponds to a technique.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_PASS_IDENTIFIER) + { + FXLRIP("ValidateParameterHandle - The given handle corresponds to a pass.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLRIP("ValidateParameterHandle - The given handle corresponds to an annotation.\n"); + } + } + + DWORD Index = FXLI_GetParameterIndex(Handle); + + if (Index >= FXLI_SelectValue(Handle, pEffect->m_ParameterDataEntriesLocal, pEffect->m_ParameterDataEntriesShared)) + { + FXLRIP("ValidateParameterHandle - Invalid parameter index.\n"); + } + + DWORD Offset = FXLI_GetParameterOffset(Handle); + + if (Offset >= FXLI_SelectValue(Handle, pEffect->m_ParameterListEntriesLocal, pEffect->m_ParameterListEntriesShared)) + { + FXLRIP("ValidateParameterHandle - Invalid parameter offset.\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLEffectI_ValidateTechniqueHandle( + __in FXLEffect* pEffect, + FXLHANDLE Handle) +{ + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) != FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_PASS_IDENTIFIER) + { + FXLRIP("ValidateTechniqueHandle - The given handle corresponds to a pass.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLRIP("ValidateTechniqueHandle - The given handle corresponds to an annotation.\n"); + } + else + { + FXLRIP("ValidateTechniqueHandle - The given handle corresponds to a parameter.\n"); + } + } + + if ((Handle >> FXLHANDLE_TECHNIQUE_OFFSET_SHIFT) >= pEffect->m_TechniqueCount) + { + FXLRIP("ValidateTechniqueHandle - Invalid technique index.\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLEffectI_ValidatePassHandle( + __in FXLEffect* pEffect, + FXLHANDLE Handle) +{ + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) != FXLHANDLE_PASS_IDENTIFIER) + { + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLRIP("ValidatePassHandle - The given handle corresponds to a technique.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLRIP("ValidatePassHandle - The given handle corresponds to an annotation.\n"); + } + else + { + FXLRIP("ValidatePassHandle - The given handle corresponds to a parameter.\n"); + } + } + + if ((Handle >> FXLHANDLE_PASS_OFFSET_SHIFT) >= pEffect->m_PassCount) + { + FXLRIP("ValidatePassHandle - Invalid pass index.\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLEffectI_ValidateAnnotationHandle( + __in FXLEffect* pEffect, + FXLHANDLE Handle) +{ + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) != FXLHANDLE_ANNOTATION_IDENTIFIER) + { + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLRIP("ValidateAnnotationHandle - The given handle corresponds to a technique.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_PASS_IDENTIFIER) + { + FXLRIP("ValidateAnnotationHandle - The given handle corresponds to a pass.\n"); + } + else + { + FXLRIP("ValidateAnnotationHandle - The given handle corresponds to a parameter.\n"); + } + } + + if ((Handle >> FXLHANDLE_ANNOTATION_OFFSET_SHIFT) >= pEffect->m_AnnotationListEntries) + { + FXLRIP("ValidateAnnotationHandle - Invalid annotation index.\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLPARAMETERENTRY* FXLEffectPoolI_GetParameterEntry( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter) +{ + DWORD Offset = FXLI_GetParameterOffset(Parameter); + return FXLI_pParameterList(pEffectPool) + Offset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLEffectPoolI_ValidateParameterHandle( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Handle) +{ + if (Handle == 0) + { + FXLRIP("ValidateParameterHandle - The given handle is NULL.\n"); + } + + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) >= FXL_MAX_PARAMETER_DATA_ENTRIES) + { + if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLRIP("ValidateParameterHandle - The given handle corresponds to a technique.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_PASS_IDENTIFIER) + { + FXLRIP("ValidateParameterHandle - The given handle corresponds to a pass.\n"); + } + else if ((Handle & FXLHANDLE_PARAMETER_INDEX_MASK) == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLRIP("ValidateParameterHandle - The given handle corresponds to an annotation.\n"); + } + } + + DWORD Index = FXLI_GetParameterIndex(Handle); + + if (Index >= pEffectPool->m_ParameterDataEntries) + { + FXLRIP("ValidateParameterHandle - Invalid parameter index.\n"); + } + + DWORD Offset = FXLI_GetParameterOffset(Handle); + + if (Offset >= pEffectPool->m_ParameterListEntries) + { + FXLRIP("ValidateParameterHandle - Invalid parameter offset.\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_ValidateParameterDataArray( + __in FXLPARAMETERENTRY* pParameter, + DWORD Type, + UINT Count, + __in_z CONST CHAR* pFunction) +{ + if (pParameter->Content != FXLPACONTENTI_ARRAY) + { + FXLRIP("%s - The given parameter is not an array (content %d).\n", pFunction, pParameter->Content); + } + + if (pParameter[1].Content != FXLPACONTENTI_DATA) + { + FXLRIP("%s - The given parameter is not an array of data elements.\n", pFunction); + } + + if (pParameter[1].Data.Type != Type) + { + FXLRIP("%s - Invalid array element data type %d.\n", pFunction, pParameter[1].Data.Type); + } + + if (Count > pParameter->Array.Elements) + { + FXLRIP("%s - The given count exceeds the number of elements in the array.\n", pFunction); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_SelectArrayCount( + UINT Count, + UINT Elements) +{ + DWORD Select = (FXLI_CountLeadingZeros((DWORD)Count) >> 5) - 1; + return (UINT)((Count & Select) + (Elements & ~Select)); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetDirtyFlag( + DWORD ParameterIndex, + __inout UINT64* pDirtyFlags) +{ + // Set the dirty bit corresponding to the given parameter index. + + // sld is expensive. Let's not do it. + //pDirtyFlags[ParameterIndex >> 6] |= (1ull << (63 - (ParameterIndex & 63))); + + static CONST UCHAR BitMasks[] = + { + 128, 64, 32, 16, 8, 4, 2, 1 + }; + + // Do a table lookup instead of the variable amount shift + + ((UCHAR*)pDirtyFlags)[ParameterIndex >> 3] |= BitMasks[ParameterIndex & 7]; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_Set4DirtyFlags( + DWORD ParameterIndex, + __inout UINT64* pDirtyFlags) +{ + // Set four dirty bits at a time, for the specified index and the next three. + // This reduces the total number of operations, and avoids a lot of load-hit-stores. + + static CONST USHORT Bit4Masks[] = + { + 0xF << 12, 0xF << 11, 0xF << 10, 0xF << 9, + 0xF << 8, 0xF << 7, 0xF << 6, 0xF << 5, + }; + + // This horrible expression identifes the two bytes that contain the flags we + // are interested in. Occasionally (one out of 32 random accesses, less in reality) + // this will cause a read/write that crosses a 32-byte boundary, giving two ~50 + // cycle penalties, but the savings in load-hit-stores makes it a good tradeoff. + + *((USHORT*)(((UCHAR*)pDirtyFlags) + (ParameterIndex >> 3))) |= + Bit4Masks[ParameterIndex & 7]; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_Set8DirtyFlags( + DWORD ParameterIndex, + __inout UINT64* pDirtyFlags) +{ + // Set eight dirty bits at a time, for the specified index and the next seven. + // This reduces the total number of operations, and avoids a lot of load-hit-stores. + + static CONST USHORT Bit8Masks[] = + { + 0xFF << 8, 0xFF << 7, 0xFF << 6, 0xFF << 5, + 0xFF << 4, 0xFF << 3, 0xFF << 2, 0xFF << 1, + }; + + *((USHORT*)(((UCHAR*)pDirtyFlags) + (ParameterIndex >> 3))) |= + Bit8Masks[ParameterIndex & 7]; +} + +/**************************************************************************** + * + * Routines to obtain effect information. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_GetSiblingParameterEntryOffset( + __in FXLPARAMETERENTRY const* pEntry) +{ + return (pEntry->Content == FXLPACONTENTI_DATA) ? 1 : pEntry->Offset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLPARAMETERENTRY* FXLEffectI_GetParameterEntryLocal( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + DWORD Offset = FXLI_GetParameterOffset(Parameter); + return FXLI_pParameterListLocal(pEffect) + Offset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLPARAMETERENTRY* FXLEffectI_GetParameterEntryShared( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + DWORD Offset = FXLI_GetParameterOffset(Parameter); + return FXLI_pParameterListShared(pEffect) + Offset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out XMFLOAT4A16* FXLEffectI_GetParameterValue( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pData = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + XMFLOAT4A16* DataList = FXLI_SelectValue(Parameter, FXLI_pParameterDataLocal(pEffect), FXLI_pParameterDataShared(pEffect)); + return DataList + pData->DataOffset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out XMFLOAT4A16* FXLEffectI_GetParameterValueLocal( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pData = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntryLocal(pEffect, Parameter); + return FXLI_pParameterDataLocal(pEffect) + pData->DataOffset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out XMFLOAT4A16* FXLEffectI_GetParameterValueShared( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pData = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntryShared(pEffect, Parameter); + return FXLI_pParameterDataShared(pEffect) + pData->DataOffset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLPARAMETERENTRY* FXLEffectI_GetParameterList( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + return FXLI_SelectValue(Parameter, FXLI_pParameterListLocal(pEffect), FXLI_pParameterListShared(pEffect)); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out_z CHAR* FXLEffectI_GetNameList( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + return FXLI_SelectValue(Parameter, FXLI_pNameListLocal(pEffect), FXLI_pNameListShared(pEffect)); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out DWORD* FXLEffectI_GetNameMap( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + return FXLI_SelectValue(Parameter, FXLI_pParameterNameMapLocal(pEffect), FXLI_pParameterNameMapShared(pEffect)); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLTECHNIQUEENTRY* FXLEffectI_GetTechnique( + __in FXLEffect* pEffect, + FXLHANDLE Technique) +{ + return FXLI_pTechnique(pEffect, Technique >> FXLHANDLE_TECHNIQUE_OFFSET_SHIFT); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLPASSENTRY* FXLEffectI_GetPass( + __in FXLEffect* pEffect, + FXLHANDLE Pass) +{ + return FXLI_pPass(pEffect, Pass >> FXLHANDLE_PASS_OFFSET_SHIFT); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLPARAMETERENTRY* FXLEffectI_GetAnnotationEntry( + __in FXLEffect* pEffect, + FXLHANDLE Annotation) +{ + return &FXLI_pAnnotationList(pEffect)[Annotation >> FXLHANDLE_ANNOTATION_OFFSET_SHIFT]; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out DWORD* FXLEffectI_GetAnnotationData( + __in FXLEffect* pEffect, + __in FXLPARAMETERDATA* pAnnotation) +{ + return &FXLI_pAnnotationData(pEffect)[pAnnotation->DataOffset]; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out XMFLOAT4A16* FXLEffectPoolI_GetParameterValue( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pData = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + return FXLI_pParameterData(pEffectPool) + pData->DataOffset; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_GetPassParameterRefIndex( + __in FXLPASSPARAMETERREF* pRef, + UINT ContextIndex) +{ + return (pRef->DWord[g_FXLIRegisterIndexOffset[ContextIndex]] & g_FXLIRegisterIndexMask[ContextIndex]) >> g_FXLIRegisterIndexShift[ContextIndex]; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetPassParameterRefIndex( + __in FXLPASSPARAMETERREF* pRef, + UINT ContextIndex, + UINT RegisterIndex) +{ + FXLASSERT((RegisterIndex & ~(g_FXLIRegisterIndexMask[ContextIndex] >> g_FXLIRegisterIndexShift[ContextIndex])) == 0); + DWORD* pDWord = &pRef->DWord[g_FXLIRegisterIndexOffset[ContextIndex]]; + *pDWord = (*pDWord & ~g_FXLIRegisterIndexMask[ContextIndex]) | (RegisterIndex << g_FXLIRegisterIndexShift[ContextIndex]); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_GetPassParameterRefCount( + __in FXLPASSPARAMETERREF* pRef, + UINT ContextIndex) +{ + return ((pRef->DWord[g_FXLIRegisterCountOffset[ContextIndex]] & g_FXLIRegisterCountMask[ContextIndex]) >> g_FXLIRegisterCountShift[ContextIndex]) + 1; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetPassParameterRefCount( + __in FXLPASSPARAMETERREF* pRef, + UINT ContextIndex, + UINT RegisterCount) +{ + FXLASSERT(RegisterCount > 0); + FXLASSERT((ContextIndex < 6) || RegisterCount == 1); + FXLASSERT(((RegisterCount - 1) & ~(g_FXLIRegisterCountMask[ContextIndex] >> g_FXLIRegisterCountShift[ContextIndex])) == 0); + DWORD* pDWord = &pRef->DWord[g_FXLIRegisterCountOffset[ContextIndex]]; + *pDWord = (*pDWord & ~g_FXLIRegisterCountMask[ContextIndex]) | ((RegisterCount - 1) << g_FXLIRegisterCountShift[ContextIndex]); +} + +/**************************************************************************** + * + * Routines to obtain FXLHANDLE values. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_GetParameterHandle( + __in_z CONST CHAR* pParameterName, + __in_z CHAR* pEntryName, + __in FXLPARAMETERENTRY* pParameterList, + UINT ParameterCount, + DWORD Shared) +{ + CONST CHAR* pParameterChar; + CHAR* pEntryChar; + DWORD ParameterIndex; + + // Find the index of the parameter in the name list. The name list is an ordered list of all parameter names. + + for (ParameterIndex = 0; ParameterIndex < ParameterCount; ParameterIndex++) + { + for (pEntryChar = pEntryName, pParameterChar = pParameterName; + *pEntryChar != '\0' && *pParameterChar != '\0' && *pEntryChar == *pParameterChar; + pEntryChar++, pParameterChar++); + + if (*pEntryChar == '\0' && + *pParameterChar == '\0') + { + // The parameter was found in the list. + + FXLPARAMETERENTRY* pEntry; + UINT EntryIndex; + DWORD EntryOffset; + + for (EntryIndex = 0, pEntry = pParameterList + 1; // The first entry is a guard entry and prevents NULL handle values. + EntryIndex < ParameterIndex; + EntryIndex++, pEntry += EntryOffset) + { + EntryOffset = FXLI_GetSiblingParameterEntryOffset(pEntry); + } + + FXLASSERT(FXLI_Is32Bits(pEntry - pParameterList)); + + DWORD ParameterOffset = DWORD(pEntry - pParameterList); + ParameterIndex = 0; + + for (EntryIndex = 1, pEntry = pParameterList + 1; + EntryIndex < ParameterOffset; + EntryIndex++, pEntry++) + { + if (pEntry->Content == FXLPACONTENTI_DATA) + { + ParameterIndex++; + } + } + + return FXLI_EncodeParameterHandle(ParameterOffset, ParameterIndex, Shared); + } + else + { + for (; *pEntryChar != '\0'; pEntryChar++); + pEntryName = pEntryChar + 1; + } + } + + // The parameter was not found. + + return 0; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE UINT FXLI_GetMemberHandleIndex( + __in_z CONST CHAR* pMemberName, + __in FXLPARAMETERSTRUCT* pStruct, + __in FXLPARAMETERENTRY* pParameterList, + __in DWORD* pNameMap) +{ + if (PARAMETER_CHECK) + { + if (pStruct->Content != FXLPACONTENTI_STRUCT) + { + FXLRIP("GetMemberHandle - The given handle does not correspond to a structure.\n"); + return 0; + } + + if (pMemberName == NULL || + *pMemberName == '\0') + { + FXLRIP("GetMemberHandle - The given member name is NULL.\n"); + } + } + + DWORD EntryIndex; + DWORD EntryOffset; + + FXLPARAMETERENTRY* pEntry = (FXLPARAMETERENTRY*)pStruct; + + for (EntryIndex = 0, pEntry++; + EntryIndex < pStruct->Members; + EntryIndex++, pEntry += EntryOffset) + { + if (strcmp(FXLDWORDToPtr(pNameMap[pEntry - pParameterList]), pMemberName) == 0) + { + break; + } + + EntryOffset = FXLI_GetSiblingParameterEntryOffset(pEntry); + } + + return EntryIndex; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_GetMemberHandleFromIndex( + FXLHANDLE Struct, + UINT MemberIndex, + __in FXLPARAMETERSTRUCT* pStruct, + __in FXLPARAMETERENTRY* pParameterList) +{ + DWORD GroupIndex; + DWORD EntryIndex; + DWORD EntryOffset; + DWORD ParameterIndex = FXLI_GetParameterIndex(Struct); + + if (PARAMETER_CHECK) + { + if (pStruct->Content != FXLPACONTENTI_STRUCT) + { + FXLRIP("GetMemberHandleFromIndex - The given handle does not correspond to a structure.\n"); + return 0; + } + + if (MemberIndex >= pStruct->Members) + { + FXLRIP("GetMemberHandleFromIndex - The given index exceeds the number of members in the structure.\n"); + return 0; + } + } + + FXLPARAMETERENTRY* pEntry = (FXLPARAMETERENTRY*)pStruct; + + pEntry++; + for (EntryIndex = 0; EntryIndex < MemberIndex; EntryIndex++) + { + if (pEntry->Content == FXLPACONTENTI_DATA) + { + ParameterIndex++; + pEntry++; + } + else + { + EntryOffset = pEntry->Offset; + for (GroupIndex = 0; GroupIndex < EntryOffset; GroupIndex++, pEntry++) + { + if (pEntry->Content == FXLPACONTENTI_DATA) + { + ParameterIndex++; + } + } + } + } + + FXLASSERT(FXLI_Is32Bits(pEntry - pParameterList)); + + DWORD ParameterOffset = DWORD(pEntry - pParameterList); + + if (FXLI_GetHandleIdentifier(Struct) == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + return FXLI_EncodeAnnotationHandle(ParameterOffset); + } + else + { + return FXLI_EncodeParameterHandle(ParameterOffset, ParameterIndex, (Struct & 1)); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FXLHANDLE FXLI_GetElementHandle( + FXLHANDLE Array, + UINT ElementIndex, + __in FXLPARAMETERARRAY* pArray, + __in FXLPARAMETERENTRY* pParameterList) +{ + DWORD ParameterIndex = FXLI_GetParameterIndex(Array); + DWORD GroupIndex; + DWORD EntryIndex; + DWORD EntryOffset; + + if (PARAMETER_CHECK) + { + if (pArray->Content != FXLPACONTENTI_ARRAY) + { + FXLRIP("GetElementHandle - The given handle does not correspond to an array.\n"); + return 0; + } + + if (ElementIndex >= pArray->Elements) + { + FXLRIP("GetElementHandle - The given index exceeds the number of elements in the array.\n"); + return 0; + } + } + + FXLPARAMETERENTRY* pEntry = (FXLPARAMETERENTRY*)pArray; + + pEntry++; + for (EntryIndex = 0; EntryIndex < ElementIndex; EntryIndex++) + { + if (pEntry->Content == FXLPACONTENTI_DATA) + { + ParameterIndex++; + pEntry++; + } + else + { + EntryOffset = pEntry->Offset; + for (GroupIndex = 0; GroupIndex < EntryOffset; GroupIndex++, pEntry++) + { + if (pEntry->Content == FXLPACONTENTI_DATA) + { + ParameterIndex++; + } + } + } + } + + FXLASSERT(FXLI_Is32Bits(pEntry - pParameterList)); + + DWORD ParameterOffset = DWORD(pEntry - pParameterList); + + if (FXLI_GetHandleIdentifier(Array) == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + return FXLI_EncodeAnnotationHandle(ParameterOffset); + } + else + { + return FXLI_EncodeParameterHandle(ParameterOffset, ParameterIndex, (Array & 1)); + } +} + +/**************************************************************************** + * + * Routines to set and get parameter data. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetFloat( + DWORD ParameterIndex, + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __inout UINT64* pDirtyFlags, + FLOAT Value) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("SetScalar - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_SCALAR) + { + FXLRIP("SetScalar - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("SetScalar - Invalid parameter type of 'sampler.'\n"); + } + } + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + *(FLOAT*)(pDataList + pParameter->DataOffset) = Value; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetScalar( + DWORD ParameterIndex, + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __in UINT64* pDirtyFlags, + XMVECTOR Value) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("SetScalar - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_SCALAR) + { + FXLRIP("SetScalar - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("SetScalar - Invalid parameter type of 'sampler.'\n"); + } + } + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + +#ifndef _XBOX + XMStoreScalar(pDataList + pParameter->DataOffset, Value); +#else + __stvewx(Value, pDataList + pParameter->DataOffset, 0); +#endif +} + +//------------------------------------------------------------------------------ +// If you use this function you are responsible for setting the dirty bits. + +FXLFINLINE VOID FXLI_SetScalarNoDirty( + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + XMVECTOR Value) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("SetScalar - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_SCALAR) + { + FXLRIP("SetScalar - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("SetScalar - Invalid parameter type of 'sampler.'\n"); + } + } + +#ifndef _XBOX + XMStoreScalar(pDataList + pParameter->DataOffset, Value); +#else + __stvewx(Value, pDataList + pParameter->DataOffset, 0); +#endif +} + +//------------------------------------------------------------------------------ + +FXLFINLINE FLOAT FXLI_GetFloat( + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("GetScalar - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_SCALAR) + { + FXLRIP("GetScalar - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("GetScalar - Invalid parameter type of 'sampler.'\n"); + } + } + + return *(FLOAT*)(pDataList + pParameter->DataOffset); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE XMVECTOR FXLI_GetScalar( + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("GetScalar - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_SCALAR) + { + FXLRIP("GetScalar - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("GetScalar - Invalid parameter type of 'sampler.'\n"); + } + } + + return XMLoadVector4A(pDataList + pParameter->DataOffset); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_ValidateSetVectorParameter( + __in FXLPARAMETERDATA* pParameter) +{ + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("SetVector - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_VECTOR) + { + FXLRIP("SetVector - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("SetVector - Invalid parameter type of 'sampler.'\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE XMVECTOR FXLI_LoadVectorData( + __in FXLPARAMETERDATA* pParameter, + __in CONST VOID* pData) +{ + XMVECTOR Data; + +#ifndef _XBOX + if (pParameter->Columns == 3) + { + Data = XMLoadFloat4((XMFLOAT4*)pData); + } + else if (pParameter->Columns == 2) + { + Data = XMLoadFloat3((XMFLOAT3*)pData); + } + else if (pParameter->Columns == 1) + { + Data = XMLoadFloat2((XMFLOAT2*)pData); + } + else + { + Data = XMLoadScalar(pData); + } +#else + XMVECTOR VL, VR, VS; + DWORD Columns = pParameter->Columns; + INT Offset = 4 * (Columns + 1); + + VS.vector4_u32[3] = (3 - Columns) << 5; + + VR = __lvrx(pData, Offset); + VL = __lvlx(pData, 0); + + VR = __vslo(VR, VS); + Data = __vor(VL, VR); +#endif + + return Data; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_StoreVectorData( + __in FXLPARAMETERDATA* pParameter, + XMVECTOR Value, + __out_bcount(sizeof(FLOAT)*pParameter->Columns) VOID* pData) +{ + if (pParameter->Columns == 3) + { + XMStoreFloat4((XMFLOAT4*)pData, Value); + } + else if (pParameter->Columns == 2) + { + XMStoreFloat3((XMFLOAT3*)pData, Value); + } + else if (pParameter->Columns == 1) + { + XMStoreFloat2((XMFLOAT2*)pData, Value); + } + else + { + XMStoreScalar(pData, Value); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetVector( + DWORD ParameterIndex, + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __inout UINT64* pDirtyFlags, + XMVECTOR Value) +{ + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + XMStoreVector4A(pDataList + pParameter->DataOffset, Value); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE XMVECTOR FXLI_GetVector( + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("GetVector - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_VECTOR) + { + FXLRIP("GetVector - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("GetVector - Invalid parameter type of 'sampler.'\n"); + } + } + + return XMLoadVector4A(pDataList + pParameter->DataOffset); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_ValidateSetMatrixParameter( + __in FXLPARAMETERDATA* pParameter) +{ + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("SetMatrix - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_RMATRIX && + pParameter->Class != FXLDCLASSI_CMATRIX) + { + FXLRIP("SetMatrix - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("SetMatrix - Invalid parameter type of 'sampler.'\n"); + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_LoadMatrixData( + __in FXLPARAMETERDATA* pParameter, + __in_bcount(4*sizeof(FLOAT)*pParameter->Columns) CONST VOID* pData, + __out XMMATRIX* pMatrix) +{ + DWORD* pSource = (DWORD*)pData; + +#ifndef _XBOX + + UINT Rows = pParameter->Rows + 1; + UINT Columns = pParameter->Columns + 1; + UINT Row; + if (pParameter->Columns == 3) + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadFloat4((XMFLOAT4*)(pSource + Columns * Row)); + } + } + else if (pParameter->Columns == 2) + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadFloat3((XMFLOAT3*)(pSource + Columns * Row)); + } + } + else if (pParameter->Columns == 1) + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadFloat2((XMFLOAT2*)(pSource + Columns * Row)); + } + } + else + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadScalar(pSource + Columns * Row); + } + } + +#else + + XMVECTOR VL0, VL1, VL2, VL3, VR0, VR1, VR2, VR3, VS; + DWORD* pSource1, *pSource2, *pSource3; + DWORD Rows = pParameter->Rows; + DWORD Columns = pParameter->Columns + 1; + INT Offset = 4 * Columns; + VS.vector4_u32[3] = (4 - Columns) << 5; + + pSource3 = pSource + Columns * Rows; + pSource2 = pSource + Columns * (Rows & 2); + pSource1 = pSource + Columns * ((Rows & 1) | (Rows >> 1)); + + VR0 = __lvrx(pSource, Offset); + VL0 = __lvlx(pSource, 0); + VR3 = __lvrx(pSource3, Offset); + VL3 = __lvlx(pSource3, 0); + + VR2 = __lvrx(pSource2, Offset); + VL2 = __lvlx(pSource2, 0); + VR1 = __lvrx(pSource1, Offset); + VL1 = __lvlx(pSource1, 0); + + VR0 = __vslo(VR0, VS); + VR3 = __vslo(VR3, VS); + VR2 = __vslo(VR2, VS); + VR1 = __vslo(VR1, VS); + + pMatrix->r[0] = __vor(VL0, VR0); + pMatrix->r[3] = __vor(VL3, VR3); + pMatrix->r[2] = __vor(VL2, VR2); + pMatrix->r[1] = __vor(VL1, VR1); + +#endif +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_LoadMatrixDataA( + __in FXLPARAMETERDATA* pParameter, + __in_bcount(4*sizeof(FLOAT)*pParameter->Columns) CONST VOID* pData, + __out XMMATRIX* pMatrix) +{ + DWORD* pSource = (DWORD*)pData; + +#ifndef _XBOX + + UINT Rows = pParameter->Rows + 1; + UINT Columns = pParameter->Columns + 1; + UINT Row; + if (pParameter->Columns == 3) + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadFloat4((XMFLOAT4*)(pSource + Columns * Row)); + } + } + else if (pParameter->Columns == 2) + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadFloat3((XMFLOAT3*)(pSource + Columns * Row)); + } + } + else if (pParameter->Columns == 1) + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadFloat2((XMFLOAT2*)(pSource + Columns * Row)); + } + } + else + { + for (Row = 0; Row < Rows; Row++) + { + pMatrix->r[Row] = XMLoadScalar(pSource + Columns * Row); + } + } + +#else + + XMVECTOR VL1, VL2, VL3, VR1, VR2, VR3, VS; + DWORD* pSource1, *pSource2, *pSource3; + DWORD Rows = pParameter->Rows; + DWORD Columns = pParameter->Columns + 1; + INT Offset = 4 * Columns; + VS.vector4_u32[3] = (4 - Columns) << 5; + + pSource3 = pSource + Columns * Rows; + pSource2 = pSource + Columns * (Rows & 2); + pSource1 = pSource + Columns * ((Rows & 1) | (Rows >> 1)); + + pMatrix->r[0] = __lvx(pSource, 0); + VR3 = __lvrx(pSource3, Offset); + VL3 = __lvlx(pSource3, 0); + + VR2 = __lvrx(pSource2, Offset); + VL2 = __lvlx(pSource2, 0); + VR1 = __lvrx(pSource1, Offset); + VL1 = __lvlx(pSource1, 0); + + VR3 = __vslo(VR3, VS); + VR2 = __vslo(VR2, VS); + VR1 = __vslo(VR1, VS); + + pMatrix->r[3] = __vor(VL3, VR3); + pMatrix->r[2] = __vor(VL2, VR2); + pMatrix->r[1] = __vor(VL1, VR1); + +#endif +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_StoreMatrixData( + __in FXLPARAMETERDATA* pParameter, + CXMMATRIX Value, + __out VOID* pData) +{ + UINT Row; + UINT Rows = pParameter->Rows + 1; + + if (pParameter->Columns == 3) + { + for (Row = 0; Row < Rows; Row++) + { + XMStoreFloat4((XMFLOAT4*)pData + Row, Value.r[Row]); + } + } + else if (pParameter->Columns == 2) + { + for (Row = 0; Row < Rows; Row++) + { + XMStoreFloat3((XMFLOAT3*)pData + Row, Value.r[Row]); + } + } + else if (pParameter->Columns == 1) + { + for (Row = 0; Row < Rows; Row++) + { + XMStoreFloat2((XMFLOAT2*)pData + Row, Value.r[Row]); + } + } + else + { + for (Row = 0; Row < Rows; Row++) + { +#ifdef _XBOX + XMVECTOR Scalar = XMVectorSplatX(Value.r[Row]); + __stvewx(Scalar, (FLOAT*)pData + Row, 0); +#else + *((DWORD*)pData + Row) = XMVectorGetIntX( Value.r[Row] ); +#endif + } + } +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetMatrix( + DWORD ParameterIndex, + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __inout UINT64* pDirtyFlags, + CXMMATRIX Value) +{ + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter->Class + 1) >> 2]; + + XMMATRIX ValueT = XMMatrixTranspose(Value); + + XMMATRIX ValueR; + FXLI_SelectMatrix(ValueR, Value, ValueT, SelectOrder); + + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter->DataOffset); + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, ValueR); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetMatrixRaw( + DWORD ParameterIndex, + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __inout UINT64* pDirtyFlags, + CXMMATRIX Value) +{ + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter->DataOffset); + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Value); +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_GetMatrix( + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __out XMMATRIX* pMatrix) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("GetMatrix - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Class != FXLDCLASSI_RMATRIX && + pParameter->Class != FXLDCLASSI_CMATRIX) + { + FXLRIP("GetMatrix - Invalid parameter class %d.\n", pParameter->Class); + } + if (pParameter->Type == FXLDTYPEI_SAMPLER) + { + FXLRIP("GetMatrix - Invalid parameter type of 'sampler.'\n"); + } + } + + XMMATRIX Value = XMLoadFloat4x4A16((XMFLOAT4X4A16*)(pDataList + pParameter->DataOffset)); + + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter->Class + 1) >> 2]; + + XMMATRIX ValueT = XMMatrixTranspose(Value); + + FXLI_SelectMatrix(Value, Value, ValueT, SelectOrder); + + *pMatrix = Value; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE VOID FXLI_SetSampler( + DWORD ParameterIndex, + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList, + __inout UINT64* pDirtyFlags, + __in_opt CONST IDirect3DBaseTexture9* pTexture) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("SetSampler - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Type != FXLDTYPEI_SAMPLER) + { + FXLRIP("SetSampler - Invalid parameter type %d.'\n", pParameter->Type); + } + } + + CONST IDirect3DBaseTexture9** pDestination = (CONST IDirect3DBaseTexture9**)(pDataList + pParameter->DataOffset); + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + *pDestination = pTexture; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out IDirect3DBaseTexture9* FXLI_GetSampler( + __in FXLPARAMETERDATA* pParameter, + __in XMFLOAT4A16* pDataList) +{ + if (PARAMETER_CHECK) + { + if (pParameter->Content != FXLPACONTENTI_DATA) + { + FXLRIP("GetSampler - Invalid parameter content %d.\n", pParameter->Content); + } + if (pParameter->Type != FXLDTYPEI_SAMPLER) + { + FXLRIP("GetSampler - Invalid parameter type of %d.\n", pParameter->Type); + } + } + + return *(IDirect3DBaseTexture9**)(pDataList + pParameter->DataOffset); +} + +/**************************************************************************** + * + * Description routines. + * + ****************************************************************************/ + +FXLFINLINE VOID FXLI_InitializeParameterDesc( + FXLHANDLE Parameter, + __in FXLPARAMETERENTRY* pParameter, + __in DWORD* pNameMap, + DWORD Offset, + __out FXLPARAMETER_DESC* pDesc) +{ + pDesc->pName = FXLDWORDToPtr(pNameMap[Offset]); + pDesc->Content = (FXLPA_CONTENT)pParameter->Content; + pDesc->Flags = pParameter->Flags | (Parameter & 1); // Add the shared flag as appropriate + pDesc->Size = pParameter->Size << 2; + + if (pParameter->Content == FXLPACONTENT_DATA) + { + pDesc->Type = (FXLDATA_TYPE)pParameter->Data.Type; + pDesc->Class = (FXLDATA_CLASS)(pParameter->Data.Class + ((pParameter->Data.Type + 1) & 4)); + pDesc->Rows = pParameter->Data.Rows + 1; + pDesc->Columns = pParameter->Data.Columns + 1; + pDesc->Elements = 0; + } + else + { + pDesc->Type = FXLDTYPE_CONTAINER; + pDesc->Class = FXLDCLASS_CONTAINER; + pDesc->Rows = 1; + pDesc->Columns = 1; + pDesc->Elements = pParameter->Struct.Members; // Same bit-field location as pParameter->Array.Elements. + } +} + +/**************************************************************************** + * + * Dynamic state setting routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLRENDERSTATEDATA* FXLI_SetDynamicRenderStates( + __in IDirect3DDevice9* pDevice, + __in FXLRENDERSTATEENTRY* pRenderStateData, + __in XMFLOAT4A16* pParameterDataLocal, + __in XMFLOAT4A16* pParameterDataShared) +{ + XMVECTOR StateValueV; + UINT StateIndex; + DWORD Value; + FLOAT* pValue; + FXLRENDERSTATEDATA* pRenderState = pRenderStateData->pStateList; + + for (StateIndex = 0; StateIndex < pRenderStateData->DynamicFCount; StateIndex++) + { + Value = pRenderState->Value; + pValue = (FLOAT*)(FXLI_SelectValue(Value >> 31, pParameterDataLocal, pParameterDataShared) + (Value & ~(FXLPFLAG_SHARED << 31))); + + pDevice->SetRenderState((D3DRENDERSTATETYPE)pRenderState->Type, *(DWORD*)pValue); + ++pRenderState; + } + + for (StateIndex = 0; StateIndex < pRenderStateData->DynamicICount; StateIndex++) + { + Value = pRenderState->Value; + pValue = (FLOAT*)(FXLI_SelectValue(Value >> 31, pParameterDataLocal, pParameterDataShared) + (Value & ~(FXLPFLAG_SHARED << 31))); + + StateValueV = XMLoadScalar(pValue); + StateValueV = XMConvertVectorFloatToInt(StateValueV, 0); + pDevice->SetRenderState((D3DRENDERSTATETYPE)pRenderState->Type, XMVectorGetIntX( StateValueV )); + ++pRenderState; + } + + return pRenderState; +} + +//------------------------------------------------------------------------------ + +FXLFINLINE __out FXLSAMPLERSTATEDATA* FXLI_SetDynamicSamplerStates( + __in IDirect3DDevice9* pDevice, + __in FXLSAMPLERSTATEENTRY* pSamplerStateData, + __in XMFLOAT4A16* pParameterDataLocal, + __in XMFLOAT4A16* pParameterDataShared) +{ + XMVECTOR StateValueV; + UINT StateIndex; + DWORD Value; + FLOAT* pValue; + FXLSAMPLERSTATEDATA* pSamplerState = pSamplerStateData->pStateList; + + for (StateIndex = 0; StateIndex < pSamplerStateData->DynamicFCount; StateIndex++) + { + Value = pSamplerState->Value; + pValue = (FLOAT*)(FXLI_SelectValue(Value >> 31, pParameterDataLocal, pParameterDataShared) + (Value & ~(FXLPFLAG_SHARED << 31))); + + pDevice->SetSamplerState(pSamplerState->Index, (D3DSAMPLERSTATETYPE)pSamplerState->Type, *(DWORD*)pValue); + ++pSamplerState; + } + + for (StateIndex = 0; StateIndex < pSamplerStateData->DynamicICount; StateIndex++) + { + Value = pSamplerState->Value; + pValue = (FLOAT*)(FXLI_SelectValue(Value >> 31, pParameterDataLocal, pParameterDataShared) + (Value & ~(FXLPFLAG_SHARED << 31))); + + StateValueV = XMLoadScalar(pValue); + StateValueV = XMConvertVectorFloatToInt(StateValueV, 0); + pDevice->SetSamplerState(pSamplerState->Index, (D3DSAMPLERSTATETYPE)pSamplerState->Type, XMVectorGetIntX( StateValueV )); + ++pSamplerState; + } + + return pSamplerState; +} + +/**************************************************************************** + * + * Technique and pass routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE VOID FXLI_BeginTechnique( + __in FXLEffect* pEffect, + __in FXLTECHNIQUEENTRY* pTechnique, + DWORD Flags) +{ + if (PARAMETER_CHECK) + { +#if DBG + if (FXL__EnforceSharedCorrelation && + (FXL__SharedCorrelation == FALSE)) + { + FXLRIP("BeginTechnique - Shared parameter correlation was lost before the \n" + "FXL__EnforceSharedCorrelation global was set to TRUE (or execution \n" + "proceeded after the lost correlation RIP was encountered). Set the global \n" + "to TRUE before creating any effects or pools in order to determine what \n" + "condition caused correlation to be lost.\n"); + } +#endif + + if (((Flags & FXL_SET_NO_STATE) != 0) && + ((Flags & FXL_COMMIT_DYNAMIC_STATE) != 0)) + { + FXLRIP("BeginTechnique - One or more FXL_SET_NO_STATE flags was given in \n" + "conjunction with one or more FXL_COMMIT_DYNAMIC_STATE flags. It is not \n" + "possible to simultaneously request that no state be set and that dynamic \n" + "state be set during every Commit.\n"); + } + } + + // Save the flags. + + pEffect->m_TechniqueFlags = Flags; + + // Ensure that all dirty flags are updated on the first pass. + + pEffect->m_dwPreviousPass = 0; + + if (pEffect->m_TechniqueFlags & FXL_RESTORE_DEFAULT_STATE) + { + // Clear render and sampler state dirty flags. + + XMVECTOR Zero = XMVectorZero(); + XMStoreFloat4A16((XMFLOAT4A16*)pEffect->m_RenderStateDirtyFlags, Zero); +#ifdef _XBOX + __dcbz128(0, pEffect->m_SamplerStateDirtyFlags); +#else + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 2), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 4), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 6), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 8), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 10), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 12), Zero); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 14), Zero); +#endif + } + + pEffect->m_dwActiveTechnique = FXLPtrToDWORD(pTechnique); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID FXLI_BeginPass( + __in FXLEffect* pEffect, + __in FXLPASSENTRY* pPass) +{ + // Dirty the parameter flags if either of the shaders has changed from the previous pass. + + FXLSHADERSTATEENTRY* pShaderStateData = FXLI_pShaderStates(pPass); + FXLRENDERSTATEENTRY* pRenderStateData = FXLI_pRenderStates(pPass); + FXLSAMPLERSTATEENTRY* pSamplerStateData = FXLI_pSamplerStates(pPass); + + FXLASSERT(pShaderStateData != NULL); + FXLASSERT(pRenderStateData != NULL); + FXLASSERT(pSamplerStateData != NULL); + + if ((FXLI_pPreviousPass(pEffect) == NULL) || + (pShaderStateData != FXLI_pShaderStates(FXLI_pPreviousPass(pEffect)))) + { + XMVECTOR Flags = XMVectorTrueInt(); + UINT Group; + + // Dirty all local parameters. + +#ifdef _XBOX + C_ASSERT((FXL_MAX_PARAMETER_FLAG_GROUPS * sizeof(UINT64)) == 128); + __dcbz128(0, pEffect->m_DirtyFlagsLocal); +#endif + for (Group = 0; Group < pEffect->m_ParameterBitGroupsLocal; Group+=2) + { + XMStoreFloat4A16((XMFLOAT4A16*)&pEffect->m_DirtyFlagsLocal[Group], Flags); + } + + // Dirty all shared parameters if shared parameter correlation has not been preserved in the system. + + if ((FXL__SharedCorrelation == FALSE) || + (pEffect->m_dwEffectPool == 0)) + { +#ifdef _XBOX + __dcbz128(0, FXLI_pDirtyFlagsShared(pEffect)); +#endif + for (Group = 0; Group < pEffect->m_ParameterBitGroupsShared; Group+=2) + { + XMStoreFloat4A16((XMFLOAT4A16*)&FXLI_pDirtyFlagsShared(pEffect)[Group], Flags); + } + } + } + + // Set the shaders. + + IDirect3DDevice9* pDevice = FXLI_pDevice(pEffect); + + FXLSetShaders(pDevice, pShaderStateData); + + // Set render and sampler states if necessary. + + DWORD ProcessRenderState = (pRenderStateData->StaticCount | + pRenderStateData->DynamicFCount | + pRenderStateData->DynamicICount) & + (((pEffect->m_TechniqueFlags & FXL_SET_NO_RENDER_STATE) >> 2) - 1); + + DWORD ProcessSamplerState = (pSamplerStateData->StaticCount | + pSamplerStateData->DynamicFCount | + pSamplerStateData->DynamicICount) & + (((pEffect->m_TechniqueFlags & FXL_SET_NO_SAMPLER_STATE) >> 3) - 1); + + if ((ProcessRenderState | ProcessSamplerState) != 0) + { + XMFLOAT4A16* pParameterDataShared = FXLI_pParameterDataShared(pEffect); + XMFLOAT4A16* pParameterDataLocal = FXLI_pParameterDataLocal(pEffect); + UINT StateIndex; + + if (ProcessRenderState != 0) + { + // Set the render states. + + FXLRENDERSTATEDATA* pRenderState = FXLI_SetDynamicRenderStates(pDevice, + pRenderStateData, + pParameterDataLocal, + pParameterDataShared); + + for (StateIndex = 0; StateIndex < pRenderStateData->StaticCount; StateIndex++) + { + pDevice->SetRenderState((D3DRENDERSTATETYPE)pRenderState->Type, pRenderState->Value); + ++pRenderState; + } + } + + if (ProcessSamplerState != 0) + { + // Set the sampler states. + + FXLSAMPLERSTATEDATA* pSamplerState = FXLI_SetDynamicSamplerStates(pDevice, + pSamplerStateData, + pParameterDataLocal, + pParameterDataShared); + + for (StateIndex = 0; StateIndex < pSamplerStateData->StaticCount; StateIndex++) + { + pDevice->SetSamplerState(pSamplerState->Index, (D3DSAMPLERSTATETYPE)pSamplerState->Type, pSamplerState->Value); + ++pSamplerState; + } + } + } + + // Update the render and sampler state dirty flags + + if (pEffect->m_TechniqueFlags & FXL_RESTORE_DEFAULT_STATE) + { + XMVECTOR StateDirtyFlags[9]; + XMVECTOR StateUsageFlags[9]; + + StateDirtyFlags[0] = XMLoadFloat4A16((XMFLOAT4A16*)pEffect->m_RenderStateDirtyFlags); + StateUsageFlags[0] = XMLoadFloat4A16((XMFLOAT4A16*)pRenderStateData->RenderStateUsageFlags); + StateDirtyFlags[1] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags)); + StateUsageFlags[1] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags)); + StateDirtyFlags[2] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 2)); + StateUsageFlags[2] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 2)); + StateDirtyFlags[3] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 4)); + StateUsageFlags[3] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 4)); + StateDirtyFlags[4] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 6)); + StateUsageFlags[4] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 6)); + StateDirtyFlags[5] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 8)); + StateUsageFlags[5] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 8)); + StateDirtyFlags[6] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 10)); + StateUsageFlags[6] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 10)); + StateDirtyFlags[7] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 12)); + StateUsageFlags[7] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 12)); + StateDirtyFlags[8] = XMLoadFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 14)); + StateUsageFlags[8] = XMLoadFloat4A16((XMFLOAT4A16*)(pSamplerStateData->SamplerStateUsageFlags + 14)); + + StateDirtyFlags[0] = XMVectorOrInt(StateDirtyFlags[0], StateUsageFlags[0]); + StateDirtyFlags[1] = XMVectorOrInt(StateDirtyFlags[1], StateUsageFlags[1]); + StateDirtyFlags[2] = XMVectorOrInt(StateDirtyFlags[2], StateUsageFlags[2]); + StateDirtyFlags[3] = XMVectorOrInt(StateDirtyFlags[3], StateUsageFlags[3]); + StateDirtyFlags[4] = XMVectorOrInt(StateDirtyFlags[4], StateUsageFlags[4]); + StateDirtyFlags[5] = XMVectorOrInt(StateDirtyFlags[5], StateUsageFlags[5]); + StateDirtyFlags[6] = XMVectorOrInt(StateDirtyFlags[6], StateUsageFlags[6]); + StateDirtyFlags[7] = XMVectorOrInt(StateDirtyFlags[7], StateUsageFlags[7]); + StateDirtyFlags[8] = XMVectorOrInt(StateDirtyFlags[8], StateUsageFlags[8]); + + XMStoreFloat4A16((XMFLOAT4A16*)pEffect->m_RenderStateDirtyFlags, StateDirtyFlags[0]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags), StateDirtyFlags[1]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 2), StateDirtyFlags[2]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 4), StateDirtyFlags[3]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 6), StateDirtyFlags[4]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 8), StateDirtyFlags[5]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 10), StateDirtyFlags[6]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 12), StateDirtyFlags[7]); + XMStoreFloat4A16((XMFLOAT4A16*)(pEffect->m_SamplerStateDirtyFlags + 14), StateDirtyFlags[8]); + } + + pEffect->m_dwActivePass = FXLPtrToDWORD(pPass); + pEffect->m_dwActiveShader = FXLPtrToDWORD(pShaderStateData); +} + +/**************************************************************************** + * + * End: Private internal interfaces and data. + * + ****************************************************************************/ + + + +/**************************************************************************** + * + * Public routines to obtain FXLHANDLE values. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetParameterHandle( + __in FXLEffect* pEffect, + __in_z CONST CHAR* pParameterName) +{ + CHAR* pEntryName; + DWORD ParameterCount; + FXLPARAMETERENTRY* pParameterList; + DWORD ListIndex; + FXLHANDLE Handle; + + if (PARAMETER_CHECK) + { + if (pParameterName == NULL || + *pParameterName == '\0') + { + FXLRIP("GetParameterHandle - The given parameter name is NULL.\n"); + } + } + + // Find the index of the parameter in the name list. The name list is an ordered list of all parameter names. + + ParameterCount = pEffect->m_ParameterCountLocal; + pParameterList = FXLI_pParameterListLocal(pEffect); + + pEntryName = FXLI_pNameListLocal(pEffect); + + for (ListIndex = 0; ListIndex < 2; ListIndex++) + { + Handle = FXLI_GetParameterHandle(pParameterName, pEntryName, pParameterList, ParameterCount, ListIndex); + if (Handle != 0) + { + return Handle; + } + + ParameterCount = pEffect->m_ParameterCountShared; + pParameterList = FXLI_pParameterListShared(pEffect); + pEntryName = FXLI_pNameListShared(pEffect); + } + + // The parameter was not found. + + return 0; +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetParameterHandleFromIndex( + __in FXLEffect* pEffect, + UINT ParameterIndex) +{ + if (PARAMETER_CHECK) + { + if (ParameterIndex >= (pEffect->m_ParameterHandleIndexMapSize)) + { + FXLRIP("GetParameterHandleFromIndex - The given index exceeds the number of parameters in the effect.\n"); + } + } + + // The original index cannot be inferred from the position of a parameter in a list since + // local and shared parameters have been split into separate lists. The handle is instead + // retreived from a map created during compilation. + + return FXLI_pParameterHandleIndexMap(pEffect)[ParameterIndex]; +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetAnnotationHandle( + __in FXLEffect* pEffect, + FXLHANDLE Anchor, + __in_z CONST CHAR* pAnnotationName) +{ + DWORD AnnotationEntryOffset = 0; + + if (PARAMETER_CHECK) + { + if (pAnnotationName == NULL || + *pAnnotationName == '\0') + { + FXLRIP("GetAnnotationHandle - The given annotation name is NULL.\n"); + } + } + + FXLPARAMETERENTRY* const pAnnotationList = FXLI_pAnnotationList(pEffect); + + if (Anchor == NULL) + { + if (PARAMETER_CHECK) + { + if (pEffect->m_AnnotationListGlobals == 0) + { + FXLRIP("GetAnnotationHandle - The effect has no global string annotations.\n"); + return 0; + } + } + + FXLPARAMETERENTRY* pEntry = pAnnotationList; + UINT Index; + + for (Index = 0; Index < pEffect->m_AnnotationListGlobals; Index++) + { + FXLASSERT(FXLI_Is32Bits(pEntry - pAnnotationList)); + + AnnotationEntryOffset = DWORD(pEntry - pAnnotationList); + + if (strcmp(FXLI_pAnnotationNameMap(pEffect, AnnotationEntryOffset), pAnnotationName) == 0) + { + break; + } + + pEntry += FXLI_GetSiblingParameterEntryOffset(pEntry); + } + + if (Index == pEffect->m_AnnotationListGlobals) + { + // The annotation was not found. + + return 0; + } + } + else + { + DWORD AnchorType = FXLI_GetHandleIdentifier(Anchor); + + if (PARAMETER_CHECK) + { + if (AnchorType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLRIP("GetAnnotationHandleFromIndex - The given anchor is itself an annotation.\n"); + return 0; + } + if (AnchorType == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLEffectI_ValidateTechniqueHandle(pEffect, Anchor); + } + else if (AnchorType == FXLHANDLE_PASS_IDENTIFIER) + { + FXLEffectI_ValidatePassHandle(pEffect, Anchor); + } + else + { + FXLEffectI_ValidateParameterHandle(pEffect, Anchor); + } + } + + DWORD AnchorOffset = Anchor >> FXLHANDLE_PARAMETER_OFFSET_SHIFT; + UINT AnnotationCount; + + if (AnchorType == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLTECHNIQUEENTRY* pTechnique = FXLEffectI_GetTechnique(pEffect, Anchor); + AnnotationCount = pTechnique->AnnotationCount; + + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapTechnique(pEffect)[AnchorOffset]; + } + else if (AnchorType == FXLHANDLE_PASS_IDENTIFIER) + { + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Anchor); + AnnotationCount = pPass->AnnotationCount; + + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapPass(pEffect)[AnchorOffset]; + } + else if (FXLI_IsParameterShared(Anchor) == FALSE) + { + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntryLocal(pEffect, Anchor); + AnnotationCount = pParameter->Annotations; + + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapLocal(pEffect)[AnchorOffset]; + } + else + { + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntryShared(pEffect, Anchor); + AnnotationCount = (pEffect->m_AnnotationListEntries > 0) ? FXLI_pAnnotationCountListShared(pEffect)[pParameter - FXLI_pParameterListShared(pEffect)] : 0; + + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapShared(pEffect)[AnchorOffset]; + } + + if (PARAMETER_CHECK) + { + if (AnnotationCount == 0) + { + FXLRIP("GetAnnotationHandle - The given anchor has no attached annotations.\n"); + } + } + + FXLPARAMETERENTRY* pAnnotation = pAnnotationList + AnnotationEntryOffset; + UINT Index; + + for (Index = 0; Index < AnnotationCount; Index++) + { + if (strcmp(FXLI_pAnnotationNameMap(pEffect, DWORD(pAnnotation - pAnnotationList)), pAnnotationName) == 0) + { + break; + } + + pAnnotation += FXLI_GetSiblingParameterEntryOffset(pAnnotation); + } + + if (Index < AnnotationCount) + { + FXLASSERT(FXLI_Is32Bits(pAnnotation - pAnnotationList)); + + AnnotationEntryOffset = DWORD(pAnnotation - pAnnotationList); + } + else + { + // The annotation was not found. + + return 0; + } + } + + return FXLI_EncodeAnnotationHandle(AnnotationEntryOffset); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetAnnotationHandleFromIndex( + __in FXLEffect* pEffect, + FXLHANDLE Anchor, + UINT AnnotationIndex) +{ + DWORD AnnotationEntryOffset; + + FXLPARAMETERENTRY* const pAnnotationList = FXLI_pAnnotationList(pEffect); + + if (Anchor == NULL) + { + if (PARAMETER_CHECK) + { + if (AnnotationIndex >= (pEffect->m_AnnotationListGlobals)) + { + FXLRIP("GetAnnotationHandleFromIndex - The given index exceeds the number of global string annotations in the effect.\n"); + return 0; + } + } + + FXLPARAMETERENTRY* pEntry = pAnnotationList; + + for (UINT Index = 0; Index < AnnotationIndex; Index++) + { + pEntry += FXLI_GetSiblingParameterEntryOffset(pEntry); + } + + FXLASSERT(FXLI_Is32Bits(pEntry - pAnnotationList)); + + AnnotationEntryOffset = DWORD(pEntry - pAnnotationList); + } + else + { + DWORD AnchorType = FXLI_GetHandleIdentifier(Anchor); + + if (PARAMETER_CHECK) + { + UINT AnnotationCount; + + if (AnchorType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLRIP("GetAnnotationHandleFromIndex - The given anchor is itself an annotation.\n"); + return 0; + } + if (AnchorType == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + FXLEffectI_ValidateTechniqueHandle(pEffect, Anchor); + + FXLTECHNIQUEENTRY* pTechnique = FXLEffectI_GetTechnique(pEffect, Anchor); + AnnotationCount = pTechnique->AnnotationCount; + } + else if (AnchorType == FXLHANDLE_PASS_IDENTIFIER) + { + FXLEffectI_ValidatePassHandle(pEffect, Anchor); + + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Anchor); + AnnotationCount = pPass->AnnotationCount; + } + else if (FXLI_IsParameterShared(Anchor) == FALSE) + { + FXLEffectI_ValidateParameterHandle(pEffect, Anchor); + + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntryLocal(pEffect, Anchor); + AnnotationCount = pParameter->Annotations; + } + else + { + FXLEffectI_ValidateParameterHandle(pEffect, Anchor); + + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntryShared(pEffect, Anchor); + AnnotationCount = (pEffect->m_AnnotationListEntries > 0) ? FXLI_pAnnotationCountListShared(pEffect)[pParameter - FXLI_pParameterListShared(pEffect)] : 0; + } + + if (AnnotationCount == 0) + { + FXLRIP("GetAnnotationHandleFromIndex - The given anchor has no attached annotations.\n"); + } + if (AnnotationIndex >= AnnotationCount) + { + FXLRIP("GetAnnotationHandleFromIndex - The given index exceeds the number of annotations attached to the given anchor.\n"); + } + } + + DWORD AnchorOffset = Anchor >> FXLHANDLE_PARAMETER_OFFSET_SHIFT; + + if (AnchorType == FXLHANDLE_TECHNIQUE_IDENTIFIER) + { + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapTechnique(pEffect)[AnchorOffset]; + } + else if (AnchorType == FXLHANDLE_PASS_IDENTIFIER) + { + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapPass(pEffect)[AnchorOffset]; + } + else if (FXLI_IsParameterShared(Anchor) == FALSE) + { + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapLocal(pEffect)[AnchorOffset]; + } + else + { + AnnotationEntryOffset = (DWORD)FXLI_pAnnotationEntryMapShared(pEffect)[AnchorOffset]; + } + + FXLPARAMETERENTRY* pAnnotation = pAnnotationList + AnnotationEntryOffset; + for (UINT Index = 0; Index < AnnotationIndex; Index++) + { + pAnnotation += FXLI_GetSiblingParameterEntryOffset(pAnnotation); + } + + FXLASSERT(FXLI_Is32Bits(pAnnotation - pAnnotationList)); + + AnnotationEntryOffset = DWORD(pAnnotation - pAnnotationList); + } + + return FXLI_EncodeAnnotationHandle(AnnotationEntryOffset); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetMemberHandle( + __in FXLEffect* pEffect, + FXLHANDLE Struct, + __in_z CONST CHAR* pMemberName) +{ + DWORD StructType = FXLI_GetHandleIdentifier(Struct); + + if (PARAMETER_CHECK) + { + if (StructType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLEffectI_ValidateAnnotationHandle(pEffect, Struct); + } + else + { + FXLEffectI_ValidateParameterHandle(pEffect, Struct); + } + } + + FXLPARAMETERSTRUCT* pStruct; + FXLPARAMETERENTRY* pParameterList; + DWORD* pParameterNameMap; + + if (StructType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + pStruct = (FXLPARAMETERSTRUCT*)FXLEffectI_GetAnnotationEntry(pEffect, Struct); + pParameterList = FXLI_pAnnotationList(pEffect); + pParameterNameMap = FXLI_pAnnotationNameMap(pEffect); + } + else + { + pStruct = (FXLPARAMETERSTRUCT*)FXLEffectI_GetParameterEntry(pEffect, Struct); + pParameterList = FXLEffectI_GetParameterList(pEffect, Struct); + pParameterNameMap = FXLI_SelectValue(Struct, FXLI_pParameterNameMapLocal(pEffect), FXLI_pParameterNameMapShared(pEffect)); + } + + UINT Index = FXLI_GetMemberHandleIndex(pMemberName, pStruct, pParameterList, pParameterNameMap); + + if (Index < pStruct->Members) + { + return FXLEffect_GetMemberHandleFromIndex(pEffect, Struct, Index); + } + else + { + // The parameter was not found. + + return 0; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetMemberHandleFromIndex( + __in FXLEffect* pEffect, + FXLHANDLE Struct, + UINT MemberIndex) +{ + DWORD StructType = FXLI_GetHandleIdentifier(Struct); + + if (PARAMETER_CHECK) + { + if (StructType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLEffectI_ValidateAnnotationHandle(pEffect, Struct); + } + else + { + FXLEffectI_ValidateParameterHandle(pEffect, Struct); + } + } + + FXLPARAMETERSTRUCT* pStruct; + FXLPARAMETERENTRY* pParameterList; + + if (StructType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + pStruct = (FXLPARAMETERSTRUCT*)FXLEffectI_GetAnnotationEntry(pEffect, Struct); + pParameterList = FXLI_pAnnotationList(pEffect); + } + else + { + pStruct = (FXLPARAMETERSTRUCT*)FXLEffectI_GetParameterEntry(pEffect, Struct); + pParameterList = FXLEffectI_GetParameterList(pEffect, Struct); + } + + return FXLI_GetMemberHandleFromIndex(Struct, MemberIndex, pStruct, pParameterList); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetElementHandle( + __in FXLEffect* pEffect, + FXLHANDLE Array, + UINT ElementIndex) +{ + DWORD ArrayType = FXLI_GetHandleIdentifier(Array); + + if (PARAMETER_CHECK) + { + if (ArrayType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + FXLEffectI_ValidateAnnotationHandle(pEffect, Array); + } + else + { + FXLEffectI_ValidateParameterHandle(pEffect, Array); + } + } + + FXLPARAMETERARRAY* pArray; + FXLPARAMETERENTRY* pParameterList; + + if (ArrayType == FXLHANDLE_ANNOTATION_IDENTIFIER) + { + pArray = (FXLPARAMETERARRAY*)FXLEffectI_GetAnnotationEntry(pEffect, Array); + pParameterList = FXLI_pAnnotationList(pEffect); + } + else + { + pArray = (FXLPARAMETERARRAY*)FXLEffectI_GetParameterEntry(pEffect, Array); + pParameterList = FXLEffectI_GetParameterList(pEffect, Array); + } + + return FXLI_GetElementHandle(Array, ElementIndex, pArray, pParameterList); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetTechniqueHandle( + __in FXLEffect* pEffect, + __in_z CONST CHAR* pTechniqueName) +{ + if (PARAMETER_CHECK) + { + if (pTechniqueName == NULL || + *pTechniqueName == '\0') + { + FXLRIP("GetTechniqueHandle - The given technique name is NULL.\n"); + } + } + + for (UINT TechniqueIndex = 0; TechniqueIndex < pEffect->m_TechniqueCount; TechniqueIndex++) + { + FXLTECHNIQUEENTRY* const pTechnique = FXLI_pTechnique(pEffect, TechniqueIndex); + + if (strcmp(FXLI_pName(pTechnique), pTechniqueName) == 0) + { + return FXLI_EncodeTechniqueHandle(TechniqueIndex); + } + } + + return 0; +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetTechniqueHandleFromIndex( + __in FXLEffect* pEffect, + UINT TechniqueIndex) +{ + if (PARAMETER_CHECK) + { + if (TechniqueIndex >= pEffect->m_TechniqueCount) + { + FXLRIP("GetTechniqueHandleFromIndex - The given technique index exceeds the number of techniques in the effect.\n"); + } + } + + return FXLI_EncodeTechniqueHandle(TechniqueIndex); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetPassHandle( + __in FXLEffect* pEffect, + FXLHANDLE Technique, + __in_z CONST CHAR* pPassName) +{ + if (PARAMETER_CHECK) + { + if (pPassName == NULL || + *pPassName == '\0') + { + FXLRIP("GetPassHandle - The given pass name is NULL.\n"); + } + + FXLEffectI_ValidateTechniqueHandle(pEffect, Technique); + } + + FXLTECHNIQUEENTRY* pTechnique = FXLEffectI_GetTechnique(pEffect, Technique); + + for (UINT PassIndex = 0; PassIndex < pTechnique->PassCount; PassIndex++) + { + FXLPASSENTRY* const pPass = FXLI_pPass(pTechnique, PassIndex); + + if (strcmp(FXLI_pName(pPass), pPassName) == 0) + { + return FXLI_EncodePassHandle(pPass, FXLI_pPassList(pEffect)); + } + } + + return 0; +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetPassHandleFromIndex( + __in FXLEffect* pEffect, + FXLHANDLE Technique, + UINT PassIndex) +{ + FXLTECHNIQUEENTRY* pTechnique = FXLEffectI_GetTechnique(pEffect, Technique); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateTechniqueHandle(pEffect, Technique); + + if (PassIndex >= pTechnique->PassCount) + { + FXLRIP("GetPassHandleFromIndex - The given pass index exceeds the number of passes in the technique.\n"); + } + } + + return FXLI_EncodePassHandle(FXLI_pPass(pTechnique, PassIndex), FXLI_pPassList(pEffect)); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffectPool_GetParameterHandle( + __in FXLEffectPool* pEffectPool, + __in_z CONST CHAR* pParameterName) +{ + if (PARAMETER_CHECK) + { + if (pParameterName == NULL || + *pParameterName == '\0') + { + FXLRIP("GetParameterHandle - NULL parameter name given.\n"); + } + } + + return FXLI_GetParameterHandle(pParameterName, FXLI_pNameList(pEffectPool), FXLI_pParameterList(pEffectPool), pEffectPool->m_ParameterCount, 1); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffectPool_GetMemberHandle( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Struct, + __in_z CONST CHAR* pMemberName) +{ + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Struct); + } + + FXLPARAMETERSTRUCT* pStruct = (FXLPARAMETERSTRUCT*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Struct); + + UINT Index = FXLI_GetMemberHandleIndex(pMemberName, pStruct, FXLI_pParameterList(pEffectPool), FXLI_pParameterNameMap(pEffectPool)); + + if (Index < pStruct->Members) + { + return FXLEffectPool_GetMemberHandleFromIndex(pEffectPool, Struct, Index); + } + else + { + // The parameter was not found. + + return 0; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffectPool_GetMemberHandleFromIndex( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Struct, + UINT MemberIndex) +{ + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Struct); + } + + FXLPARAMETERSTRUCT* pStruct = (FXLPARAMETERSTRUCT*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Struct); + + return FXLI_GetMemberHandleFromIndex(Struct, MemberIndex, pStruct, FXLI_pParameterList(pEffectPool)); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffectPool_GetElementHandle( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Array, + UINT ElementIndex) +{ + FXLPARAMETERARRAY* pArray = (FXLPARAMETERARRAY*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Array); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Array); + } + + return FXLI_GetElementHandle(Array, ElementIndex, pArray, FXLI_pParameterList(pEffectPool)); +} + +/**************************************************************************** + * + * Public routines to set and get parameter data. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetFloat( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + FLOAT Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetFloat/SetScalarF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetFloat(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FLOAT WINAPI FXLEffect_GetFloat( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetFloat/GetScalarF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + return FXLI_GetFloat(pParameter, pDataList); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetScalarF( + __in FXLEffect* pEffect, + __in FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLASSERT(pData != NULL); + + FXLEffect_SetFloat(pEffect, Parameter, *pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetScalarF( + __in FXLEffect* pEffect, + __in FXLHANDLE Parameter, + __out FLOAT* pData) +{ + FXLASSERT(pData != NULL); + + *pData = FXLEffect_GetFloat(pEffect, Parameter); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetScalarArrayF( + __in FXLEffect* pEffect, + __in FXLHANDLE Parameter, + __in_ecount(Count) CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetScalarArrayF"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + XMVECTOR DataV; + + for (ElementCount += ParameterIndex; (ParameterIndex + 3) < ElementCount; ParameterIndex += 4) + { + DataV = XMLoadVector4(pSource); + FXLI_Set4DirtyFlags(ParameterIndex, pDirtyFlags); + FXLI_SetScalarNoDirty(&pParameter[1].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[2].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[3].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[4].Data, pDataList, DataV); + pParameter += 4; + pSource += 4; + } + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + DataV = XMLoadScalar(pSource); + FXLI_SetScalar(ParameterIndex, &pParameter->Data, pDataList, pDirtyFlags, DataV); + ++pSource; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetScalarArrayF( + __in FXLEffect* pEffect, + __in FXLHANDLE Parameter, + __out_ecount(Count) FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetScalarArrayF"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + FLOAT* pDestination = pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetScalar(&pParameter->Data, pDataList); + XMStoreScalar(pDestination, Value); + + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetInt( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + INT Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetInt - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(&Data); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, pDataList, pDirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE INT WINAPI FXLEffect_GetInt( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetInt - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetScalar(pParameter, pDataList); + INT ValueI; + + Value = XMConvertVectorFloatToInt(Value, 0); + XMStoreScalar(&ValueI, Value); + + return ValueI; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetScalarI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetScalarI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(pData); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, pDataList, pDirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetScalarI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetScalarI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetScalar(pParameter, pDataList); + + Value = XMConvertVectorFloatToInt(Value, 0); + XMStoreScalar(pData, Value); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetScalarArrayI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(Count) CONST INT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_INT, Count, "SetScalarArrayI"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST INT* pSource = pData; + XMVECTOR DataV; + + for (ElementCount += ParameterIndex; (ParameterIndex + 3) < ElementCount; ParameterIndex += 4) + { + DataV = XMLoadVector4(pSource); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_Set4DirtyFlags(ParameterIndex, pDirtyFlags); + FXLI_SetScalarNoDirty(&pParameter[1].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[2].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[3].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[4].Data, pDataList, DataV); + pParameter += 4; + pSource += 4; + } + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + DataV = XMLoadScalar(pSource); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, &pParameter->Data, pDataList, pDirtyFlags, DataV); + ++pSource; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetScalarArrayI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out_ecount(Count) INT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_INT, Count, "GetScalarArrayI"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + INT* pDestination = pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetScalar(&pParameter->Data, pDataList); + Value = XMConvertVectorFloatToInt(Value, 0); + XMStoreScalar(pDestination, Value); + + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetBool( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + BOOL Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetBool - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(&Data); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, pDataList, pDirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE BOOL WINAPI FXLEffect_GetBool( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetBool - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetScalar(pParameter, pDataList); + BOOL ValueB; + + Value = XMConvertVectorFloatToUInt(Value, 0); + XMStoreScalar(&ValueB, Value); + + return ValueB; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetScalarB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetScalarB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(pData); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, pDataList, pDirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetScalarB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetScalarB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetScalar(pParameter, pDataList); + + Value = XMConvertVectorFloatToUInt(Value, 0); + XMStoreScalar(pData, Value); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetScalarArrayB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(Count) CONST BOOL* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_BOOL, Count, "SetScalarArrayB"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST BOOL* pSource = pData; + XMVECTOR DataV; + + for (ElementCount += ParameterIndex; (ParameterIndex + 3) < ElementCount; ParameterIndex += 4) + { + DataV = XMLoadVector4(pSource); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_Set4DirtyFlags(ParameterIndex, pDirtyFlags); + FXLI_SetScalarNoDirty(&pParameter[1].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[2].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[3].Data, pDataList, DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[4].Data, pDataList, DataV); + pParameter += 4; + pSource += 4; + } + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + DataV = XMLoadScalar(pSource); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, &pParameter->Data, pDataList, pDirtyFlags, DataV); + ++pSource; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetScalarArrayB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out_ecount(Count) BOOL* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_BOOL, Count, "GetScalarArrayB"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + BOOL* pDestination = pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetScalar(&pParameter->Data, pDataList); + Value = XMConvertVectorFloatToUInt(Value, 0); + XMStoreScalar(pDestination, Value); + + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVector( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + FXLVECTOR Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetVector - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLVECTOR WINAPI FXLEffect_GetVector( + __in FXLEffect* pEffect, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetVectorF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetVector(pParameter, pDataList); + + return Value; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetVectorF - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR Data = FXLI_LoadVectorData(pParameter, pData); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorFA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetVectorFA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR Data = XMLoadFloat4A16((XMFLOAT4A16*)pData); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetVectorF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetVectorF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetVector(pParameter, pDataList); + + FXLI_StoreVectorData(pParameter, Value, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorArrayF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetVectorArrayF"); + FXLI_ValidateSetVectorParameter(&pParameter[1].Data); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + + for (ElementCount += ParameterIndex; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + + XMVECTOR Data = FXLI_LoadVectorData(&pParameter->Data, pSource); + FXLI_SetVector(ParameterIndex, &pParameter->Data, pDataList, pDirtyFlags, Data); + + pSource += (pParameter->Data.Columns + 1); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorArrayF4A( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetVectorArrayF4A"); + FXLI_ValidateSetVectorParameter(&pParameter[1].Data); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + + for (ElementCount += ParameterIndex; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + + XMVECTOR Data = XMLoadFloat4A16((XMFLOAT4A16*)pSource); + FXLI_SetVector(ParameterIndex, &pParameter->Data, pDataList, pDirtyFlags, Data); + + pSource += 4; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetVectorArrayF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetVectorArrayF"); + FXLASSERT(pData != NULL); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + DWORD* pDestination = (DWORD*)pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetVector(&pParameter->Data, pDataList); + FXLI_StoreVectorData(&pParameter->Data, Value, pDestination); + + pDestination += (pParameter->Data.Columns + 1); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetVectorI - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR IntData = FXLI_LoadVectorData(pParameter, pData); + XMVECTOR Data = XMConvertVectorIntToFloat(IntData, 0); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorIA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLINTA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetVectorIA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR IntData = XMLoadFloat4A16((XMFLOAT4A16*)pData); + XMVECTOR Data = XMConvertVectorIntToFloat(IntData, 0); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetVectorI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetVectorI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetVector(pParameter, pDataList); + XMVECTOR IntValue = XMConvertVectorFloatToInt(Value, 0); + + FXLI_StoreVectorData(pParameter, IntValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetVectorB - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR BoolData = FXLI_LoadVectorData(pParameter, pData); + XMVECTOR Data = XMConvertVectorUIntToFloat(BoolData, 0); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetVectorBA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLBOOLA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetVectorBA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR BoolData = XMLoadFloat4A16((XMFLOAT4A16*)pData); + XMVECTOR Data = XMConvertVectorUIntToFloat(BoolData, 0); + + FXLI_SetVector(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetVectorB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetVectorB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMVECTOR Value = FXLI_GetVector(pParameter, pDataList); + XMVECTOR BoolValue = XMConvertVectorFloatToUInt(Value, 0); + + FXLI_StoreVectorData(pParameter, BoolValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrix( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in FXLMATRIX* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrix - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, *pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrix( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out FXLMATRIX* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetMatrixF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + FXLI_GetMatrix(pParameter, pDataList, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixRaw( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in FXLMATRIX* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRaw - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, pDataList, pDirtyFlags, *pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixF - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixData(pParameter, pData, &Data); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixFA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixFA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixDataA(pParameter, pData, &Data); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrixF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetMatrixF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMMATRIX Value; + FXLI_GetMatrix(pParameter, pDataList, &Value); + + FXLI_StoreMatrixData(pParameter, Value, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixF4x4( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(16) CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixF4x4 - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4((XMFLOAT4X4*)pData); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixF4x4A( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(16) CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixF4x4A - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4A16((XMFLOAT4X4A16*)pData); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixRawF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawF - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixData(pParameter, pData, &Data); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixRawFA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawFA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixDataA(pParameter, pData, &Data); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixRawF4x4( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawF4x4 - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4((XMFLOAT4X4*)pData); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixRawF4x4A( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawF4x4A - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4A16((XMFLOAT4X4A16*)pData); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrixF4x4( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out_ecount(16) FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetMatrixF4x4 - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMMATRIX Value; + FXLI_GetMatrix(pParameter, pDataList, &Value); + + XMStoreFloat4x4((XMFLOAT4X4*)pData, Value); +} + +//------------------------------------------------------------------------------ + +#if defined(_XM_ISVS2005_) && defined(_XM_X64_) +#pragma warning(push) +#pragma warning(disable : 4328) +#endif + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixArrayF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayF"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + XMMATRIX DataT[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + ++pParameter; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter->Data.DataOffset); + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter->Data.Class + 1) >> 2]; + UINT MatrixSizeInDwords = ((pParameter->Data.Rows + 1) * (pParameter->Data.Columns + 1)); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[1]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[2]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[3]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[4]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[5]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[6]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[7]); + pSource += MatrixSizeInDwords; + + DataT[0] = XMMatrixTranspose(Data[0]); + DataT[1] = XMMatrixTranspose(Data[1]); + DataT[2] = XMMatrixTranspose(Data[2]); + DataT[3] = XMMatrixTranspose(Data[3]); + DataT[4] = XMMatrixTranspose(Data[4]); + DataT[5] = XMMatrixTranspose(Data[5]); + DataT[6] = XMMatrixTranspose(Data[6]); + DataT[7] = XMMatrixTranspose(Data[7]); + + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + FXLI_SelectMatrix(Data[1], Data[1], DataT[1], SelectOrder); + FXLI_SelectMatrix(Data[2], Data[2], DataT[2], SelectOrder); + FXLI_SelectMatrix(Data[3], Data[3], DataT[3], SelectOrder); + FXLI_SelectMatrix(Data[4], Data[4], DataT[4], SelectOrder); + FXLI_SelectMatrix(Data[5], Data[5], DataT[5], SelectOrder); + FXLI_SelectMatrix(Data[6], Data[6], DataT[6], SelectOrder); + FXLI_SelectMatrix(Data[7], Data[7], DataT[7], SelectOrder); + + FXLI_Set8DirtyFlags(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + DataT[0] = XMMatrixTranspose(Data[0]); + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + + pSource += MatrixSizeInDwords; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixArrayF4x4( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(16*Count) CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayF4x4"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + XMMATRIX DataT[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter[1].Data.DataOffset); + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter[1].Data.Class + 1) >> 2]; + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4(pSource); + Data[1] = XMLoadFloat4x4(pSource + 1); + Data[2] = XMLoadFloat4x4(pSource + 2); + Data[3] = XMLoadFloat4x4(pSource + 3); + Data[4] = XMLoadFloat4x4(pSource + 4); + Data[5] = XMLoadFloat4x4(pSource + 5); + Data[6] = XMLoadFloat4x4(pSource + 6); + Data[7] = XMLoadFloat4x4(pSource + 7); + + DataT[0] = XMMatrixTranspose(Data[0]); + DataT[1] = XMMatrixTranspose(Data[1]); + DataT[2] = XMMatrixTranspose(Data[2]); + DataT[3] = XMMatrixTranspose(Data[3]); + DataT[4] = XMMatrixTranspose(Data[4]); + DataT[5] = XMMatrixTranspose(Data[5]); + DataT[6] = XMMatrixTranspose(Data[6]); + DataT[7] = XMMatrixTranspose(Data[7]); + + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + FXLI_SelectMatrix(Data[1], Data[1], DataT[1], SelectOrder); + FXLI_SelectMatrix(Data[2], Data[2], DataT[2], SelectOrder); + FXLI_SelectMatrix(Data[3], Data[3], DataT[3], SelectOrder); + FXLI_SelectMatrix(Data[4], Data[4], DataT[4], SelectOrder); + FXLI_SelectMatrix(Data[5], Data[5], DataT[5], SelectOrder); + FXLI_SelectMatrix(Data[6], Data[6], DataT[6], SelectOrder); + FXLI_SelectMatrix(Data[7], Data[7], DataT[7], SelectOrder); + + FXLI_Set8DirtyFlags(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4(pSource); + DataT[0] = XMMatrixTranspose(Data[0]); + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixArrayF4x4A( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(16*Count) CONST FXLFLOATA* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayF4x4A"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + XMMATRIX DataT[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter[1].Data.DataOffset); + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter[1].Data.Class + 1) >> 2]; + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4A16(pSource); + Data[1] = XMLoadFloat4x4A16(pSource + 1); + Data[2] = XMLoadFloat4x4A16(pSource + 2); + Data[3] = XMLoadFloat4x4A16(pSource + 3); + Data[4] = XMLoadFloat4x4A16(pSource + 4); + Data[5] = XMLoadFloat4x4A16(pSource + 5); + Data[6] = XMLoadFloat4x4A16(pSource + 6); + Data[7] = XMLoadFloat4x4A16(pSource + 7); + + DataT[0] = XMMatrixTranspose(Data[0]); + DataT[1] = XMMatrixTranspose(Data[1]); + DataT[2] = XMMatrixTranspose(Data[2]); + DataT[3] = XMMatrixTranspose(Data[3]); + DataT[4] = XMMatrixTranspose(Data[4]); + DataT[5] = XMMatrixTranspose(Data[5]); + DataT[6] = XMMatrixTranspose(Data[6]); + DataT[7] = XMMatrixTranspose(Data[7]); + + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + FXLI_SelectMatrix(Data[1], Data[1], DataT[1], SelectOrder); + FXLI_SelectMatrix(Data[2], Data[2], DataT[2], SelectOrder); + FXLI_SelectMatrix(Data[3], Data[3], DataT[3], SelectOrder); + FXLI_SelectMatrix(Data[4], Data[4], DataT[4], SelectOrder); + FXLI_SelectMatrix(Data[5], Data[5], DataT[5], SelectOrder); + FXLI_SelectMatrix(Data[6], Data[6], DataT[6], SelectOrder); + FXLI_SelectMatrix(Data[7], Data[7], DataT[7], SelectOrder); + + FXLI_Set8DirtyFlags(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4A16(pSource); + DataT[0] = XMMatrixTranspose(Data[0]); + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixArrayRawF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayRawF"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + ++pParameter; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter->Data.DataOffset); + UINT MatrixSizeInDwords = ((pParameter->Data.Rows + 1) * (pParameter->Data.Columns + 1)); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[1]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[2]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[3]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[4]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[5]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[6]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[7]); + pSource += MatrixSizeInDwords; + + FXLI_Set8DirtyFlags(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + XMStoreFloat4x4A16(pDestination, Data[0]); + + pSource += MatrixSizeInDwords; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixArrayRawF4x4( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(16*Count) CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayRawF4x4"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter[1].Data.DataOffset); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4(pSource); + Data[1] = XMLoadFloat4x4(pSource + 1); + Data[2] = XMLoadFloat4x4(pSource + 2); + Data[3] = XMLoadFloat4x4(pSource + 3); + Data[4] = XMLoadFloat4x4(pSource + 4); + Data[5] = XMLoadFloat4x4(pSource + 5); + Data[6] = XMLoadFloat4x4(pSource + 6); + Data[7] = XMLoadFloat4x4(pSource + 7); + + FXLI_Set8DirtyFlags(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4(pSource); + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixArrayRawF4x4A( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_ecount(16*Count) CONST FXLFLOATA* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayRawF4x4A"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(pDataList + pParameter[1].Data.DataOffset); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4A16(pSource); + Data[1] = XMLoadFloat4x4A16(pSource + 1); + Data[2] = XMLoadFloat4x4A16(pSource + 2); + Data[3] = XMLoadFloat4x4A16(pSource + 3); + Data[4] = XMLoadFloat4x4A16(pSource + 4); + Data[5] = XMLoadFloat4x4A16(pSource + 5); + Data[6] = XMLoadFloat4x4A16(pSource + 6); + Data[7] = XMLoadFloat4x4A16(pSource + 7); + + FXLI_Set8DirtyFlags(ParameterIndex, pDirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4A16(pSource); + FXLI_SetDirtyFlag(ParameterIndex, pDirtyFlags); + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrixArrayF( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetMatrixArrayF"); + FXLASSERT(pData != NULL); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + DWORD* pDestination = (DWORD*)pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMMATRIX Value; + FXLI_GetMatrix(&pParameter->Data, pDataList, &Value); + FXLI_StoreMatrixData(&pParameter->Data, Value, pDestination); + + pDestination += ((pParameter->Data.Rows + 1) * (pParameter->Data.Columns + 1)); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrixArrayF4x4( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out_ecount(16*Count) FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetMatrixArrayF4x4"); + FXLASSERT(pData != NULL); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + DWORD* pDestination = (DWORD*)pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMMATRIX Value; + FXLI_GetMatrix(&pParameter->Data, pDataList, &Value); + XMStoreFloat4x4((XMFLOAT4X4*)pDestination, Value); + + pDestination += 16; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetMatrixI - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX IntData; + XMMATRIX Data; + + FXLI_LoadMatrixData(pParameter, pData, &IntData); + + Data.r[0] = XMConvertVectorIntToFloat(IntData.r[0], 0); + Data.r[1] = XMConvertVectorIntToFloat(IntData.r[1], 0); + Data.r[2] = XMConvertVectorIntToFloat(IntData.r[2], 0); + Data.r[3] = XMConvertVectorIntToFloat(IntData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixIA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLINTA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetMatrixIA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX IntData; + XMMATRIX Data; + + FXLI_LoadMatrixDataA(pParameter, pData, &IntData); + + Data.r[0] = XMConvertVectorIntToFloat(IntData.r[0], 0); + Data.r[1] = XMConvertVectorIntToFloat(IntData.r[1], 0); + Data.r[2] = XMConvertVectorIntToFloat(IntData.r[2], 0); + Data.r[3] = XMConvertVectorIntToFloat(IntData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrixI( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetMatrixI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMMATRIX Value; + XMMATRIX IntValue; + + FXLI_GetMatrix(pParameter, pDataList, &Value); + + IntValue.r[0] = XMConvertVectorFloatToInt(Value.r[0], 0); + IntValue.r[1] = XMConvertVectorFloatToInt(Value.r[1], 0); + IntValue.r[2] = XMConvertVectorFloatToInt(Value.r[2], 0); + IntValue.r[3] = XMConvertVectorFloatToInt(Value.r[3], 0); + + FXLI_StoreMatrixData(pParameter, IntValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetMatrixB - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX BoolData; + XMMATRIX Data; + + FXLI_LoadMatrixData(pParameter, pData, &BoolData); + + Data.r[0] = XMConvertVectorUIntToFloat(BoolData.r[0], 0); + Data.r[1] = XMConvertVectorUIntToFloat(BoolData.r[1], 0); + Data.r[2] = XMConvertVectorUIntToFloat(BoolData.r[2], 0); + Data.r[3] = XMConvertVectorUIntToFloat(BoolData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetMatrixBA( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in CONST FXLBOOLA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetMatrixBA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX BoolData; + XMMATRIX Data; + + FXLI_LoadMatrixDataA(pParameter, pData, &BoolData); + + Data.r[0] = XMConvertVectorUIntToFloat(BoolData.r[0], 0); + Data.r[1] = XMConvertVectorUIntToFloat(BoolData.r[1], 0); + Data.r[2] = XMConvertVectorUIntToFloat(BoolData.r[2], 0); + Data.r[3] = XMConvertVectorUIntToFloat(BoolData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, pDataList, pDirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetMatrixB( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetMatrixB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + XMMATRIX Value; + XMMATRIX BoolValue; + + FXLI_GetMatrix(pParameter, pDataList, &Value); + + BoolValue.r[0] = XMConvertVectorFloatToUInt(Value.r[0], 0); + BoolValue.r[1] = XMConvertVectorFloatToUInt(Value.r[1], 0); + BoolValue.r[2] = XMConvertVectorFloatToUInt(Value.r[2], 0); + BoolValue.r[3] = XMConvertVectorFloatToUInt(Value.r[3], 0); + + FXLI_StoreMatrixData(pParameter, BoolValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_SetSampler( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __in_opt CONST IDirect3DBaseTexture9* pTexture) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + UINT64* pDirtyFlags = FXLEffectI_GetDirtyFlags(pEffect, Parameter); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetSampler(ParameterIndex, pParameter, pDataList, pDirtyFlags, pTexture); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetSampler( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __deref_out IDirect3DBaseTexture9** pTexture) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectI_GetParameterEntry(pEffect, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + + FXLASSERT(pTexture != NULL); + } + + XMFLOAT4A16* pDataList = FXLEffectI_GetParameterData(pEffect, Parameter); + + *pTexture = FXLI_GetSampler(pParameter, pDataList); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetFloat( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + FLOAT Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetFloat/SetScalarF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetFloat(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FLOAT WINAPI FXLEffectPool_GetFloat( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetScalarF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + return FXLI_GetFloat(pParameter, FXLI_pParameterData(pEffectPool)); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetScalarF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLASSERT(pData != NULL); + + FXLEffectPool_SetFloat(pEffectPool, Parameter, *pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetScalarF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FLOAT* pData) +{ + FXLASSERT(pData != NULL); + + *pData = FXLEffectPool_GetFloat(pEffectPool, Parameter); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetScalarArrayF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(Count) CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetScalarArrayF"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + XMVECTOR DataV; + + for (ElementCount += ParameterIndex; (ParameterIndex + 3) < ElementCount; ParameterIndex += 4) + { + DataV = XMLoadVector4(pSource); + FXLI_Set4DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + FXLI_SetScalarNoDirty(&pParameter[1].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[2].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[3].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[4].Data, FXLI_pParameterData(pEffectPool), DataV); + pParameter += 4; + pSource += 4; + } + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + DataV = XMLoadScalar(pSource); + FXLI_SetScalar(ParameterIndex, &pParameter->Data, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); + ++pSource; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetScalarArrayF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out_ecount(Count) FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetScalarArrayF"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + FLOAT* pDestination = pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetScalar(&pParameter->Data, FXLI_pParameterData(pEffectPool)); + XMStoreScalar(pDestination, Value); + + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetInt( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + INT Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetInt - Invalid parameter type %d.\n", pParameter->Type); + } + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(&Data); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE INT WINAPI FXLEffectPool_GetInt( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetInt - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetScalar(pParameter, FXLI_pParameterData(pEffectPool)); + INT ValueI; + + Value = XMConvertVectorFloatToInt(Value, 0); + XMStoreScalar(&ValueI, Value); + + return ValueI; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetScalarI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetScalarI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(pData); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetScalarI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetScalarI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetScalar(pParameter, FXLI_pParameterData(pEffectPool)); + + Value = XMConvertVectorFloatToInt(Value, 0); + XMStoreScalar(pData, Value); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetScalarArrayI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(Count) CONST INT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_INT, Count, "SetScalarArrayI"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST INT* pSource = pData; + XMVECTOR DataV; + + for (ElementCount += ParameterIndex; (ParameterIndex + 3) < ElementCount; ParameterIndex += 4) + { + DataV = XMLoadVector4(pSource); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_Set4DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + FXLI_SetScalarNoDirty(&pParameter[1].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[2].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[3].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[4].Data, FXLI_pParameterData(pEffectPool), DataV); + pParameter += 4; + pSource += 4; + } + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + DataV = XMLoadScalar(pSource); + DataV = XMConvertVectorIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, &pParameter->Data, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); + ++pSource; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetScalarArrayI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out_ecount(Count) INT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_INT, Count, "GetScalarArrayI"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + INT* pDestination = pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetScalar(&pParameter->Data, FXLI_pParameterData(pEffectPool)); + Value = XMConvertVectorFloatToInt(Value, 0); + XMStoreScalar(pDestination, Value); + + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetBool( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + BOOL Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetBool - Invalid parameter type %d.\n", pParameter->Type); + } + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(&Data); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE BOOL WINAPI FXLEffectPool_GetBool( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetBool - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetScalar(pParameter, FXLI_pParameterData(pEffectPool)); + BOOL ValueB; + + Value = XMConvertVectorFloatToUInt(Value, 0); + XMStoreScalar(&ValueB, Value); + + return ValueB; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetScalarB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetScalarB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMVECTOR DataV = XMLoadScalar(pData); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetScalarB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetScalarB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetScalar(pParameter, FXLI_pParameterData(pEffectPool)); + + Value = XMConvertVectorFloatToUInt(Value, 0); + XMStoreScalar(pData, Value); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetScalarArrayB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(Count) CONST BOOL* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_BOOL, Count, "SetScalarArrayB"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST BOOL* pSource = pData; + XMVECTOR DataV; + + for (ElementCount += ParameterIndex; (ParameterIndex + 3) < ElementCount; ParameterIndex += 4) + { + DataV = XMLoadVector4(pSource); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_Set4DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + FXLI_SetScalarNoDirty(&pParameter[1].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[2].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[3].Data, FXLI_pParameterData(pEffectPool), DataV); + DataV = XMVectorRotateLeft(DataV, 1); + FXLI_SetScalarNoDirty(&pParameter[4].Data, FXLI_pParameterData(pEffectPool), DataV); + pParameter += 4; + pSource += 4; + } + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + DataV = XMLoadScalar(pSource); + DataV = XMConvertVectorUIntToFloat(DataV, 0); + FXLI_SetScalar(ParameterIndex, &pParameter->Data, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, DataV); + ++pSource; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetScalarArrayB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out_ecount(Count) BOOL* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_BOOL, Count, "GetScalarArrayB"); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + BOOL* pDestination = pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetScalar(&pParameter->Data, FXLI_pParameterData(pEffectPool)); + Value = XMConvertVectorFloatToUInt(Value, 0); + XMStoreScalar(pDestination, Value); + + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVector( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + FXLVECTOR Data) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetVector - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLVECTOR WINAPI FXLEffectPool_GetVector( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetVectorF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetVector(pParameter, FXLI_pParameterData(pEffectPool)); + + return Value; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetVectorF - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMVECTOR Data = FXLI_LoadVectorData(pParameter, pData); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorFA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetVectorFA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMVECTOR Data = XMLoadFloat4A16((XMFLOAT4A16*)pData); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetVectorF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetVectorF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetVector(pParameter, FXLI_pParameterData(pEffectPool)); + + FXLI_StoreVectorData(pParameter, Value, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorArrayF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetVectorArrayF"); + FXLI_ValidateSetVectorParameter(&pParameter[1].Data); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + + for (ElementCount += ParameterIndex; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + + XMVECTOR Data = FXLI_LoadVectorData(&pParameter->Data, pSource); + FXLI_SetVector(ParameterIndex, &pParameter->Data, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); + + pSource += (pParameter->Data.Columns + 1); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorArrayF4A( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetVectorArrayF4A"); + FXLI_ValidateSetVectorParameter(&pParameter[1].Data); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + + for (ElementCount += ParameterIndex; ParameterIndex < ElementCount; ++ParameterIndex) + { + ++pParameter; + + XMVECTOR Data = XMLoadFloat4A16((XMFLOAT4A16*)pSource); + FXLI_SetVector(ParameterIndex, &pParameter->Data, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); + + pSource += 4; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetVectorArrayF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetVectorArrayF"); + FXLASSERT(pData != NULL); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + DWORD* pDestination = (DWORD*)pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMVECTOR Value = FXLI_GetVector(&pParameter->Data, FXLI_pParameterData(pEffectPool)); + FXLI_StoreVectorData(&pParameter->Data, Value, pDestination); + + pDestination += (pParameter->Data.Columns + 1); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetVectorI - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMVECTOR IntData = FXLI_LoadVectorData(pParameter, pData); + XMVECTOR Data = XMConvertVectorIntToFloat(IntData, 0); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorIA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLINTA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetVectorIA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMVECTOR IntData = XMLoadFloat4A16((XMFLOAT4A16*)pData); + XMVECTOR Data = XMConvertVectorIntToFloat(IntData, 0); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetVectorI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetVectorI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetVector(pParameter, FXLI_pParameterData(pEffectPool)); + XMVECTOR IntValue = XMConvertVectorFloatToInt(Value, 0); + + FXLI_StoreVectorData(pParameter, IntValue, pData); +} + + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetVectorB - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMVECTOR BoolData = FXLI_LoadVectorData(pParameter, pData); + XMVECTOR Data = XMConvertVectorUIntToFloat(BoolData, 0); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetVectorBA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLBOOLA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetVectorBA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetVectorParameter(pParameter); + } + + XMVECTOR BoolData = XMLoadFloat4A16((XMFLOAT4A16*)pData); + XMVECTOR Data = XMConvertVectorUIntToFloat(BoolData, 0); + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetVector(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetVectorB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetVectorB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMVECTOR Value = FXLI_GetVector(pParameter, FXLI_pParameterData(pEffectPool)); + XMVECTOR BoolValue = XMConvertVectorFloatToUInt(Value, 0); + + FXLI_StoreVectorData(pParameter, BoolValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrix( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in FXLMATRIX* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrix - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, *pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrix( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FXLMATRIX* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetMatrix - Invalid parameter type %d.\n", pParameter->Type); + } + } + + FXLI_GetMatrix(pParameter, FXLI_pParameterData(pEffectPool), pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixRaw( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in FXLMATRIX* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRaw - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, *pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixF - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixData(pParameter, pData, &Data); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixFA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixFA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixDataA(pParameter, pData, &Data); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrixF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetMatrixF - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMMATRIX Value; + FXLI_GetMatrix(pParameter, FXLI_pParameterData(pEffectPool), &Value); + + FXLI_StoreMatrixData(pParameter, Value, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrixF4x4( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out_ecount(16) FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("GetMatrixF4x4 - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMMATRIX Value; + FXLI_GetMatrix(pParameter, FXLI_pParameterData(pEffectPool), &Value); + + XMStoreFloat4x4((XMFLOAT4X4*)pData, Value); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixF4x4( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16) CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixF4x4 - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4((XMFLOAT4X4*)pData); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixF4x4A( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16) CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixF4x4A - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4A16((XMFLOAT4X4A16*)pData); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixRawF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawF - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixData(pParameter, pData, &Data); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixRawFA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawFA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data; + FXLI_LoadMatrixDataA(pParameter, pData, &Data); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixRawF4x4( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16) CONST FLOAT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawF4x4 - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4((XMFLOAT4X4*)pData); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixRawF4x4A( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16) CONST FXLFLOATA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_FLOAT) + { + FXLRIP("SetMatrixRawF4x4A - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX Data = XMLoadFloat4x4A16((XMFLOAT4X4A16*)pData); + + FXLI_SetMatrixRaw(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixArrayF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayF"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + XMMATRIX DataT[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + ++pParameter; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(FXLI_pParameterData(pEffectPool) + pParameter->Data.DataOffset); + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter->Data.Class + 1) >> 2]; + UINT MatrixSizeInDwords = ((pParameter->Data.Rows + 1) * (pParameter->Data.Columns + 1)); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[1]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[2]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[3]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[4]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[5]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[6]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[7]); + pSource += MatrixSizeInDwords; + + DataT[0] = XMMatrixTranspose(Data[0]); + DataT[1] = XMMatrixTranspose(Data[1]); + DataT[2] = XMMatrixTranspose(Data[2]); + DataT[3] = XMMatrixTranspose(Data[3]); + DataT[4] = XMMatrixTranspose(Data[4]); + DataT[5] = XMMatrixTranspose(Data[5]); + DataT[6] = XMMatrixTranspose(Data[6]); + DataT[7] = XMMatrixTranspose(Data[7]); + + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + FXLI_SelectMatrix(Data[1], Data[1], DataT[1], SelectOrder); + FXLI_SelectMatrix(Data[2], Data[2], DataT[2], SelectOrder); + FXLI_SelectMatrix(Data[3], Data[3], DataT[3], SelectOrder); + FXLI_SelectMatrix(Data[4], Data[4], DataT[4], SelectOrder); + FXLI_SelectMatrix(Data[5], Data[5], DataT[5], SelectOrder); + FXLI_SelectMatrix(Data[6], Data[6], DataT[6], SelectOrder); + FXLI_SelectMatrix(Data[7], Data[7], DataT[7], SelectOrder); + + FXLI_Set8DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + DataT[0] = XMMatrixTranspose(Data[0]); + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + + FXLI_SetDirtyFlag(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + + pSource += MatrixSizeInDwords; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixArrayF4x4( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16*Count) CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayF4x4"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + XMMATRIX DataT[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(FXLI_pParameterData(pEffectPool) + pParameter[1].Data.DataOffset); + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter[1].Data.Class + 1) >> 2]; + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4(pSource); + Data[1] = XMLoadFloat4x4(pSource + 1); + Data[2] = XMLoadFloat4x4(pSource + 2); + Data[3] = XMLoadFloat4x4(pSource + 3); + Data[4] = XMLoadFloat4x4(pSource + 4); + Data[5] = XMLoadFloat4x4(pSource + 5); + Data[6] = XMLoadFloat4x4(pSource + 6); + Data[7] = XMLoadFloat4x4(pSource + 7); + + DataT[0] = XMMatrixTranspose(Data[0]); + DataT[1] = XMMatrixTranspose(Data[1]); + DataT[2] = XMMatrixTranspose(Data[2]); + DataT[3] = XMMatrixTranspose(Data[3]); + DataT[4] = XMMatrixTranspose(Data[4]); + DataT[5] = XMMatrixTranspose(Data[5]); + DataT[6] = XMMatrixTranspose(Data[6]); + DataT[7] = XMMatrixTranspose(Data[7]); + + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + FXLI_SelectMatrix(Data[1], Data[1], DataT[1], SelectOrder); + FXLI_SelectMatrix(Data[2], Data[2], DataT[2], SelectOrder); + FXLI_SelectMatrix(Data[3], Data[3], DataT[3], SelectOrder); + FXLI_SelectMatrix(Data[4], Data[4], DataT[4], SelectOrder); + FXLI_SelectMatrix(Data[5], Data[5], DataT[5], SelectOrder); + FXLI_SelectMatrix(Data[6], Data[6], DataT[6], SelectOrder); + FXLI_SelectMatrix(Data[7], Data[7], DataT[7], SelectOrder); + + FXLI_Set8DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4(pSource); + DataT[0] = XMMatrixTranspose(Data[0]); + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + + FXLI_SetDirtyFlag(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixArrayF4x4A( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16*Count) CONST FXLFLOATA* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayF4x4A"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + XMMATRIX DataT[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(FXLI_pParameterData(pEffectPool) + pParameter[1].Data.DataOffset); + XMVECTOR SelectOrder = *(XMVECTOR*)&g_FXLITypeSelect[(pParameter[1].Data.Class + 1) >> 2]; + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4A16(pSource); + Data[1] = XMLoadFloat4x4A16(pSource + 1); + Data[2] = XMLoadFloat4x4A16(pSource + 2); + Data[3] = XMLoadFloat4x4A16(pSource + 3); + Data[4] = XMLoadFloat4x4A16(pSource + 4); + Data[5] = XMLoadFloat4x4A16(pSource + 5); + Data[6] = XMLoadFloat4x4A16(pSource + 6); + Data[7] = XMLoadFloat4x4A16(pSource + 7); + + DataT[0] = XMMatrixTranspose(Data[0]); + DataT[1] = XMMatrixTranspose(Data[1]); + DataT[2] = XMMatrixTranspose(Data[2]); + DataT[3] = XMMatrixTranspose(Data[3]); + DataT[4] = XMMatrixTranspose(Data[4]); + DataT[5] = XMMatrixTranspose(Data[5]); + DataT[6] = XMMatrixTranspose(Data[6]); + DataT[7] = XMMatrixTranspose(Data[7]); + + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + FXLI_SelectMatrix(Data[1], Data[1], DataT[1], SelectOrder); + FXLI_SelectMatrix(Data[2], Data[2], DataT[2], SelectOrder); + FXLI_SelectMatrix(Data[3], Data[3], DataT[3], SelectOrder); + FXLI_SelectMatrix(Data[4], Data[4], DataT[4], SelectOrder); + FXLI_SelectMatrix(Data[5], Data[5], DataT[5], SelectOrder); + FXLI_SelectMatrix(Data[6], Data[6], DataT[6], SelectOrder); + FXLI_SelectMatrix(Data[7], Data[7], DataT[7], SelectOrder); + + FXLI_Set8DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4A16(pSource); + DataT[0] = XMMatrixTranspose(Data[0]); + FXLI_SelectMatrix(Data[0], Data[0], DataT[0], SelectOrder); + + FXLI_SetDirtyFlag(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixArrayRawF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayRawF"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST DWORD* pSource = (CONST DWORD*)pData; + ++pParameter; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(FXLI_pParameterData(pEffectPool) + pParameter->Data.DataOffset); + UINT MatrixSizeInDwords = ((pParameter->Data.Rows + 1) * (pParameter->Data.Columns + 1)); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[1]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[2]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[3]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[4]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[5]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[6]); + pSource += MatrixSizeInDwords; + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[7]); + pSource += MatrixSizeInDwords; + + FXLI_Set8DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + FXLI_LoadMatrixData(&pParameter->Data, pSource, &Data[0]); + FXLI_SetDirtyFlag(ParameterIndex, pEffectPool->m_DirtyFlags); + XMStoreFloat4x4A16(pDestination, Data[0]); + + pSource += MatrixSizeInDwords; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixArrayRawF4x4( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16) CONST FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayRawF4x4"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(FXLI_pParameterData(pEffectPool) + pParameter[1].Data.DataOffset); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4(pSource); + Data[1] = XMLoadFloat4x4(pSource + 1); + Data[2] = XMLoadFloat4x4(pSource + 2); + Data[3] = XMLoadFloat4x4(pSource + 3); + Data[4] = XMLoadFloat4x4(pSource + 4); + Data[5] = XMLoadFloat4x4(pSource + 5); + Data[6] = XMLoadFloat4x4(pSource + 6); + Data[7] = XMLoadFloat4x4(pSource + 7); + + FXLI_Set8DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4(pSource); + FXLI_SetDirtyFlag(ParameterIndex, pEffectPool->m_DirtyFlags); + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixArrayRawF4x4A( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_ecount(16) CONST FXLFLOATA* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "SetMatrixArrayRawF4x4A"); + FXLI_ValidateSetMatrixParameter(&pParameter[1].Data); + } + + CONST UINT UnrollCount = 8; + XMMATRIX Data[UnrollCount]; + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + UINT UnrollElementCount = ElementCount & ~(UnrollCount - 1); + UINT ParameterIndex = FXLI_GetParameterIndex(Parameter); + CONST XMFLOAT4X4A16* pSource = (CONST XMFLOAT4X4A16*)pData; + XMFLOAT4X4A16* pDestination = (XMFLOAT4X4A16*)(FXLI_pParameterData(pEffectPool) + pParameter[1].Data.DataOffset); + + UnrollElementCount += ParameterIndex; + ElementCount += ParameterIndex; + + for (; ParameterIndex < UnrollElementCount; ParameterIndex += UnrollCount) + { + C_ASSERT(UnrollCount == 8); + + Data[0] = XMLoadFloat4x4A16(pSource); + Data[1] = XMLoadFloat4x4A16(pSource + 1); + Data[2] = XMLoadFloat4x4A16(pSource + 2); + Data[3] = XMLoadFloat4x4A16(pSource + 3); + Data[4] = XMLoadFloat4x4A16(pSource + 4); + Data[5] = XMLoadFloat4x4A16(pSource + 5); + Data[6] = XMLoadFloat4x4A16(pSource + 6); + Data[7] = XMLoadFloat4x4A16(pSource + 7); + + FXLI_Set8DirtyFlags(ParameterIndex, pEffectPool->m_DirtyFlags); + + XMStoreFloat4x4A16(pDestination, Data[0]); + XMStoreFloat4x4A16(pDestination + 1, Data[1]); + XMStoreFloat4x4A16(pDestination + 2, Data[2]); + XMStoreFloat4x4A16(pDestination + 3, Data[3]); + XMStoreFloat4x4A16(pDestination + 4, Data[4]); + XMStoreFloat4x4A16(pDestination + 5, Data[5]); + XMStoreFloat4x4A16(pDestination + 6, Data[6]); + XMStoreFloat4x4A16(pDestination + 7, Data[7]); + + pSource += UnrollCount; + pDestination += UnrollCount; + } + + for (; ParameterIndex < ElementCount; ++ParameterIndex) + { + Data[0] = XMLoadFloat4x4A16(pSource); + FXLI_SetDirtyFlag(ParameterIndex, pEffectPool->m_DirtyFlags); + XMStoreFloat4x4A16(pDestination, Data[0]); + + ++pSource; + ++pDestination; + } +} + + +#if defined(_XM_ISVS2005_) && defined(_XM_X64_) +#pragma warning(pop) +#endif + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrixArrayF( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetMatrixArrayF"); + FXLASSERT(pData != NULL); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + DWORD* pDestination = (DWORD*)pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMMATRIX Value; + FXLI_GetMatrix(&pParameter->Data, FXLI_pParameterData(pEffectPool), &Value); + FXLI_StoreMatrixData(&pParameter->Data, Value, pDestination); + + pDestination += ((pParameter->Data.Rows + 1) * (pParameter->Data.Columns + 1)); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrixArrayF4x4( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out_ecount(16*Count) FLOAT* pData, + UINT Count) +{ + FXLPARAMETERENTRY* pParameter = FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLI_ValidateParameterDataArray(pParameter, FXLDTYPEI_FLOAT, Count, "GetMatrixArrayF4x4"); + FXLASSERT(pData != NULL); + } + + UINT ElementCount = FXLI_SelectArrayCount(Count, pParameter->Array.Elements); + DWORD* pDestination = (DWORD*)pData; + + for (UINT EntryIndex = 0; EntryIndex < ElementCount; ++EntryIndex) + { + ++pParameter; + + XMMATRIX Value; + FXLI_GetMatrix(&pParameter->Data, FXLI_pParameterData(pEffectPool), &Value); + XMStoreFloat4x4((XMFLOAT4X4*)pDestination, Value); + + pDestination += 16; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetMatrixI - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX IntData; + XMMATRIX Data; + + FXLI_LoadMatrixData(pParameter, pData, &IntData); + + Data.r[0] = XMConvertVectorIntToFloat(IntData.r[0], 0); + Data.r[1] = XMConvertVectorIntToFloat(IntData.r[1], 0); + Data.r[2] = XMConvertVectorIntToFloat(IntData.r[2], 0); + Data.r[3] = XMConvertVectorIntToFloat(IntData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixIA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLINTA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("SetMatrixIA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX IntData; + XMMATRIX Data; + + FXLI_LoadMatrixDataA(pParameter, pData, &IntData); + + Data.r[0] = XMConvertVectorIntToFloat(IntData.r[0], 0); + Data.r[1] = XMConvertVectorIntToFloat(IntData.r[1], 0); + Data.r[2] = XMConvertVectorIntToFloat(IntData.r[2], 0); + Data.r[3] = XMConvertVectorIntToFloat(IntData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrixI( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out INT* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_INT) + { + FXLRIP("GetMatrixI - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMMATRIX Value; + XMMATRIX IntValue; + + FXLI_GetMatrix(pParameter, FXLI_pParameterData(pEffectPool), &Value); + + IntValue.r[0] = XMConvertVectorFloatToInt(Value.r[0], 0); + IntValue.r[1] = XMConvertVectorFloatToInt(Value.r[1], 0); + IntValue.r[2] = XMConvertVectorFloatToInt(Value.r[2], 0); + IntValue.r[3] = XMConvertVectorFloatToInt(Value.r[3], 0); + + FXLI_StoreMatrixData(pParameter, IntValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetMatrixB - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX BoolData; + XMMATRIX Data; + + FXLI_LoadMatrixData(pParameter, pData, &BoolData); + + Data.r[0] = XMConvertVectorUIntToFloat(BoolData.r[0], 0); + Data.r[1] = XMConvertVectorUIntToFloat(BoolData.r[1], 0); + Data.r[2] = XMConvertVectorUIntToFloat(BoolData.r[2], 0); + Data.r[3] = XMConvertVectorUIntToFloat(BoolData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetMatrixBA( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in CONST FXLBOOLA* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("SetMatrixBA - Invalid parameter type %d.\n", pParameter->Type); + } + + FXLI_ValidateSetMatrixParameter(pParameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + XMMATRIX BoolData; + XMMATRIX Data; + + FXLI_LoadMatrixDataA(pParameter, pData, &BoolData); + + Data.r[0] = XMConvertVectorUIntToFloat(BoolData.r[0], 0); + Data.r[1] = XMConvertVectorUIntToFloat(BoolData.r[1], 0); + Data.r[2] = XMConvertVectorUIntToFloat(BoolData.r[2], 0); + Data.r[3] = XMConvertVectorUIntToFloat(BoolData.r[3], 0); + + FXLI_SetMatrix(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, Data); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetMatrixB( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out BOOL* pData) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pData != NULL); + + if (pParameter->Type != FXLDTYPEI_BOOL) + { + FXLRIP("GetMatrixB - Invalid parameter type %d.\n", pParameter->Type); + } + } + + XMMATRIX Value; + XMMATRIX BoolValue; + + FXLI_GetMatrix(pParameter, FXLI_pParameterData(pEffectPool), &Value); + + BoolValue.r[0] = XMConvertVectorFloatToUInt(Value.r[0], 0); + BoolValue.r[1] = XMConvertVectorFloatToUInt(Value.r[1], 0); + BoolValue.r[2] = XMConvertVectorFloatToUInt(Value.r[2], 0); + BoolValue.r[3] = XMConvertVectorFloatToUInt(Value.r[3], 0); + + FXLI_StoreMatrixData(pParameter, BoolValue, pData); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_SetSampler( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __in_opt CONST IDirect3DBaseTexture9* pTexture) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + } + + DWORD ParameterIndex = FXLI_GetParameterIndex(Parameter); + + FXLI_SetSampler(ParameterIndex, pParameter, FXLI_pParameterData(pEffectPool), pEffectPool->m_DirtyFlags, pTexture); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetSampler( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __deref_out IDirect3DBaseTexture9** pTexture) +{ + FXLPARAMETERDATA* pParameter = (FXLPARAMETERDATA*)FXLEffectPoolI_GetParameterEntry(pEffectPool, Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + + FXLASSERT(pTexture != NULL); + } + + *pTexture = FXLI_GetSampler(pParameter, FXLI_pParameterData(pEffectPool)); +} + +/**************************************************************************** + * + * Public description routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetEffectDesc( + __in FXLEffect* pEffect, + __out FXLEFFECT_DESC* pDesc) +{ + FXLASSERT(pDesc); + + pDesc->pCreator = FXLI_pCreatorName(pEffect); + pDesc->Parameters = pEffect->m_ParameterHandleIndexMapSize; + pDesc->Techniques = pEffect->m_TechniqueCount; + pDesc->Functions = pEffect->m_ShaderStateCount; + pDesc->Annotations = pEffect->m_AnnotationListGlobals; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetTechniqueDesc( + __in FXLEffect* pEffect, + FXLHANDLE Technique, + __out FXLTECHNIQUE_DESC* pDesc) +{ + FXLTECHNIQUEENTRY* pTechnique = FXLEffectI_GetTechnique(pEffect, Technique); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateTechniqueHandle(pEffect, Technique); + FXLASSERT(pDesc != NULL); + } + + pDesc->pName = FXLI_pName(pTechnique); + pDesc->Passes = pTechnique->PassCount; + pDesc->Annotations = pTechnique->AnnotationCount; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetPassDesc( + __in FXLEffect* pEffect, + FXLHANDLE Pass, + __out FXLPASS_DESC* pDesc) +{ + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + FXLASSERT(pDesc != NULL); + } + + FXLRENDERSTATEENTRY* const pRenderStates = FXLI_pRenderStates (pPass); + FXLSHADERSTATEENTRY* const pShaderStates = FXLI_pShaderStates (pPass); + FXLSAMPLERSTATEENTRY* const pSamplerStates = FXLI_pSamplerStates(pPass); + FXLVERTEXSHADERENTRY* const pVertexShader = FXLI_pVertexShader (pShaderStates); + FXLPIXELSHADERENTRY* const pPixelShader = FXLI_pPixelShader (pShaderStates); + + pDesc->pName = FXLI_pName(pPass); + pDesc->Annotations = pPass->AnnotationCount; + pDesc->RenderStates = pRenderStates->DynamicFCount + + pRenderStates->DynamicICount + + pRenderStates->StaticCount; + pDesc->SamplerStates = pSamplerStates->DynamicFCount + + pSamplerStates->DynamicICount + + pSamplerStates->StaticCount; + pDesc->pVertexShaderFunction = (pVertexShader->FunctionSize > 0) ? + pVertexShader->pFunction : NULL; + pDesc->VertexShaderFunctionSize = pVertexShader->FunctionSize; + pDesc->pPixelShaderFunction = (pPixelShader->FunctionSize > 0) ? + pPixelShader->pFunction : NULL; + pDesc->PixelShaderFunctionSize = pPixelShader->FunctionSize; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetParameterDesc( + __in FXLEffect* pEffect, + FXLHANDLE Parameter, + __out FXLPARAMETER_DESC* pDesc) +{ + FXLPARAMETERENTRY* pParameterList = FXLEffectI_GetParameterList(pEffect, Parameter); + DWORD Offset = FXLI_GetParameterOffset(Parameter); + FXLPARAMETERENTRY* pParameter = pParameterList + Offset; + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateParameterHandle(pEffect, Parameter); + FXLASSERT(pDesc != NULL); + } + + DWORD* pNameMap = FXLEffectI_GetNameMap(pEffect, Parameter); + + FXLI_InitializeParameterDesc(Parameter, pParameter, pNameMap, Offset, pDesc); + + if (pEffect->m_AnnotationListEntries > 0) + { + pDesc->Annotations = FXLI_IsParameterShared(Parameter) ? FXLI_pAnnotationCountListShared(pEffect)[Offset] : pParameter->Annotations; + } + else + { + pDesc->Annotations = 0; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetAnnotationDesc( + __in FXLEffect* pEffect, + FXLHANDLE Annotation, + __out FXLANNOTATION_DESC* pDesc) +{ + FXLPARAMETERENTRY* pAnnotation = FXLEffectI_GetAnnotationEntry(pEffect, Annotation); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateAnnotationHandle(pEffect, Annotation); + FXLASSERT(pDesc != NULL); + } + + pDesc->pName = FXLI_pAnnotationNameMap(pEffect, Annotation >> FXLHANDLE_ANNOTATION_OFFSET_SHIFT); + pDesc->Content = (FXLPA_CONTENT)pAnnotation->Content; + + if (pAnnotation->Content == FXLPACONTENT_DATA) + { + if (pAnnotation->Data.Type == FXLDTYPEI_STRING) + { + pDesc->Type = FXLDTYPE_STRING; + pDesc->Class = FXLDCLASS_SCALAR; + + CHAR* pString = (CHAR*)(FXLI_pAnnotationData(pEffect) + pAnnotation->Data.DataOffset); + pDesc->Size = UINT(strlen(pString)) + 1; + } + else + { + pDesc->Type = (FXLDATA_TYPE)pAnnotation->Data.Type; + pDesc->Class = (FXLDATA_CLASS)pAnnotation->Data.Class; + pDesc->Size = pAnnotation->Size << 2; + } + pDesc->Rows = pAnnotation->Data.Rows + 1; + pDesc->Columns = pAnnotation->Data.Columns + 1; + pDesc->Elements = 0; + } + else + { + pDesc->Type = FXLDTYPE_CONTAINER; + pDesc->Class = FXLDCLASS_CONTAINER; + pDesc->Rows = 1; + pDesc->Columns = 1; + pDesc->Elements = pAnnotation->Struct.Members; // Same bit-field location as pAnnotation->Array.Elements. + pDesc->Size = pAnnotation->Size << 2; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffectPool_GetParameterDesc( + __in FXLEffectPool* pEffectPool, + FXLHANDLE Parameter, + __out FXLPARAMETER_DESC* pDesc) +{ + DWORD Offset = FXLI_GetParameterOffset(Parameter); + FXLPARAMETERENTRY* pParameter = FXLI_pParameterList(pEffectPool) + Offset; + + if (PARAMETER_CHECK) + { + FXLEffectPoolI_ValidateParameterHandle(pEffectPool, Parameter); + FXLASSERT(pDesc != NULL); + } + + FXLI_InitializeParameterDesc(Parameter, pParameter, FXLI_pParameterNameMap(pEffectPool), Offset, pDesc); + + pDesc->Annotations = 0; +} + +/**************************************************************************** + * + * Public query routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetActiveTechnique( + __in FXLEffect* pEffect) +{ + return pEffect->m_ActiveTechniqueHandle; +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLHANDLE WINAPI FXLEffect_GetActivePass( + __in FXLEffect* pEffect) +{ + return (pEffect->m_dwActivePass != 0) ? FXLI_EncodePassHandle(FXLI_pActivePass(pEffect), FXLI_pPassList(pEffect)) : 0; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetRenderStateList( + __in FXLEffect* pEffect, + FXLHANDLE Pass, + __out_ecount_opt(*pCount) FXLRENDERSTATE* pList, + __out UINT* pCount) +{ + UINT RenderStateCount; + UINT RenderStateIndex; + FLOAT* pValue; + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + + FXLASSERT(pCount != NULL); + } + + RenderStateCount = *pCount; + *pCount = 0; + + if (pPass->dwRenderStates != 0) + { + FXLRENDERSTATEDATA* pRenderState = FXLI_pRenderStates(pPass)->pStateList; + + for (RenderStateIndex = 0; RenderStateIndex < FXLI_pRenderStates(pPass)->DynamicFCount; RenderStateIndex++) + { + if ((pList != NULL) && + (*pCount < RenderStateCount)) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pRenderState->Value); + pList[*pCount].Type = (D3DRENDERSTATETYPE)pRenderState->Type; + pList[*pCount].Value = *(DWORD*)pValue; + } + + ++pRenderState; + ++(*pCount); + } + + for (RenderStateIndex = 0; RenderStateIndex < FXLI_pRenderStates(pPass)->DynamicICount; RenderStateIndex++) + { + if ((pList != NULL) && + (*pCount < RenderStateCount)) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pRenderState->Value); + pList[*pCount].Type = (D3DRENDERSTATETYPE)pRenderState->Type; + pList[*pCount].Value = (DWORD)*pValue; + } + + ++pRenderState; + ++(*pCount); + } + + for (RenderStateIndex = 0; RenderStateIndex < FXLI_pRenderStates(pPass)->StaticCount; RenderStateIndex++) + { + if ((pList != NULL) && + (*pCount < RenderStateCount)) + { + pList[*pCount].Type = (D3DRENDERSTATETYPE)pRenderState->Type; + pList[*pCount].Value = pRenderState->Value; + } + + ++pRenderState; + ++(*pCount); + } + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetSamplerStateList( + __in FXLEffect* pEffect, + FXLHANDLE Sampler, + __out_ecount_opt(*pCount) FXLSAMPLERSTATE* pList, + __out UINT* pCount) +{ + UINT SamplerOffset; + UINT SamplerStateCount; + FXLPASSPARAMETERREF* pRef; + FXLPASSPARAMETERREF* pRefEnd; + UINT64 UpdateFlags; + UINT SkipCount; + UINT CheckCount; + UINT ParameterBitGroups; + UINT PassIndex; + UINT StateIndex; + UINT Scope; + UINT Group; + UINT SamplerStateIndex; + FLOAT* pValue; + + SamplerOffset = FXLI_GetParameterOffset(Sampler); + + if (PARAMETER_CHECK) + { + FXLPARAMETERENTRY* pParameterList; + FXLPARAMETERENTRY* pParameter; + + FXLEffectI_ValidateParameterHandle(pEffect, Sampler); + FXLASSERT(pCount != NULL); + + pParameterList = FXLEffectI_GetParameterList(pEffect, Sampler); + pParameter = pParameterList + SamplerOffset; + if (pParameter->Data.Type != FXLDTYPEI_SAMPLER) + { + FXLRIP("GetSamplerStateList - The given parameter is not a sampler.\n"); + } + } + + SamplerStateCount = *pCount; + *pCount = 0; + + // Find a reference to the sampler in a shader of a pass to obtain any sampler state settings. + + for (PassIndex = 0; PassIndex < pEffect->m_PassCount; PassIndex++) + { + FXLPASSENTRY* const pPass = FXLI_pPass(pEffect, PassIndex); + FXLSHADERSTATEENTRY* const pShaderStates = FXLI_pShaderStates(pPass); + + if (FXLI_pVertexShader(pShaderStates)->FunctionSize > 0 || + FXLI_pPixelShader (pShaderStates)->FunctionSize > 0) + { + for (StateIndex = 6; StateIndex < 8; StateIndex++) + { + ParameterBitGroups = pEffect->m_ParameterBitGroupsLocal; + + for (Scope = 0; Scope < 2; Scope++) + { + for (Group = 0; Group < ParameterBitGroups; Group++) + { + pRef = (Scope == 0) ? FXLI_pReferenceListLocal (pShaderStates) : + FXLI_pReferenceListShared(pShaderStates); + pRef += (Group << 6); + + UpdateFlags = FXLI_pUsageFlags(pShaderStates, StateIndex + Scope * 8)[Group]; + + while (UpdateFlags != 0) + { + SkipCount = FXLI_CountLeadingZeros64(UpdateFlags); + UpdateFlags <<= SkipCount; + pRef += SkipCount; + + CheckCount = FXLI_CountLeadingZeros64(~UpdateFlags); + UpdateFlags <<= CheckCount; + pRefEnd = pRef + CheckCount; + + do + { + FXLPARAMETERENTRY* const pParameterEntry = FXLEffectI_GetParameterEntry(pEffect, pRef->ParameterHandle); + FXLPARAMETERENTRY* const pParameterList = FXLEffectI_GetParameterList (pEffect, pRef->ParameterHandle); + + FXLASSERT(FXLI_Is32Bits(pParameterEntry - pParameterList)); + + UINT const EntryIndex = UINT(pParameterEntry - pParameterList); + UINT const RegisterIndex = (StateIndex == 6) ? pRef->VSSRegisterIndex : pRef->PSSRegisterIndex; + + if (EntryIndex == SamplerOffset) + { + if (pPass->dwSamplerStates != 0) + { + FXLSAMPLERSTATEENTRY* const pSamplerStates = FXLI_pSamplerStates(pPass); + + FXLSAMPLERSTATEDATA* pSamplerStateData = pSamplerStates->pStateList; + + for (SamplerStateIndex = 0; SamplerStateIndex < pSamplerStates->DynamicFCount; SamplerStateIndex++) + { + if (pSamplerStateData->Index == RegisterIndex) + { + if ((pList != NULL) && + (*pCount < SamplerStateCount)) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pSamplerStateData->Value); + pList[*pCount].Type = (D3DSAMPLERSTATETYPE)pSamplerStateData->Type; + pList[*pCount].Value = *(DWORD*)pValue; + } + + ++(*pCount); + } + + ++pSamplerStateData; + } + + for (SamplerStateIndex = 0; SamplerStateIndex < pSamplerStates->DynamicICount; SamplerStateIndex++) + { + if (pSamplerStateData->Index == RegisterIndex) + { + if ((pList != NULL) && + (*pCount < SamplerStateCount)) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pSamplerStateData->Value); + pList[*pCount].Type = (D3DSAMPLERSTATETYPE)pSamplerStateData->Type; + pList[*pCount].Value = (DWORD)*pValue; + } + + ++(*pCount); + } + + ++pSamplerStateData; + } + + for (SamplerStateIndex = 0; SamplerStateIndex < pSamplerStates->StaticCount; SamplerStateIndex++) + { + if (pSamplerStateData->Index == RegisterIndex) + { + if ((pList != NULL) && + (*pCount < SamplerStateCount)) + { + pList[*pCount].Type = (D3DSAMPLERSTATETYPE)pSamplerStateData->Type; + pList[*pCount].Value = pSamplerStateData->Value; + } + + ++(*pCount); + } + + ++pSamplerStateData; + } + } + + return; + } + + ++pRef; + + } while (pRef < pRefEnd); + } + } + + ParameterBitGroups = pEffect->m_ParameterBitGroupsShared; + } + } + } + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetRenderState( + __in FXLEffect* pEffect, + FXLHANDLE Pass, + UINT StateIndex, + __out D3DRENDERSTATETYPE* pStateType, + __out DWORD* pStateValue) +{ + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + + FXLASSERT(pStateType != NULL); + FXLASSERT(pStateValue != NULL); + + if (FXLI_pRenderStates(pPass) == NULL) + { + FXLRIP("FXL: GetRenderState - The given pass does not contain any render states.\n"); + } + + if (StateIndex >= FXLI_pRenderStates(pPass)->DynamicFCount + + FXLI_pRenderStates(pPass)->DynamicICount + + FXLI_pRenderStates(pPass)->StaticCount) + { + FXLRIP("FXL: GetRenderState - The given state index exceeds the number of render states contained in the given pass.\n"); + } + } + + FXLRENDERSTATEDATA* pData = FXLI_pRenderStates(pPass)->pStateList + StateIndex; + FLOAT* pValue; + + *pStateType = (D3DRENDERSTATETYPE)pData->Type; + + if (StateIndex < FXLI_pRenderStates(pPass)->DynamicFCount) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pData->Value); + *pStateValue = *(DWORD*)pValue; + } + else if (StateIndex < FXLI_pRenderStates(pPass)->DynamicFCount + FXLI_pRenderStates(pPass)->DynamicICount) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pData->Value); + *pStateValue = (DWORD)*pValue; + } + else + { + *pStateValue = pData->Value; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetSamplerState( + __in FXLEffect* pEffect, + FXLHANDLE Pass, + UINT StateIndex, + __out UINT* pSamplerIndex, + __out D3DSAMPLERSTATETYPE* pStateType, + __out DWORD* pStateValue) +{ + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + + FXLASSERT(pStateType != NULL); + FXLASSERT(pStateValue != NULL); + + if (FXLI_pSamplerStates(pPass) == NULL) + { + FXLRIP("FXL: GetSamplerState - The given pass does not contain any sampler states.\n"); + } + + if (StateIndex >= FXLI_pSamplerStates(pPass)->DynamicFCount + + FXLI_pSamplerStates(pPass)->DynamicICount + + FXLI_pSamplerStates(pPass)->StaticCount) + { + FXLRIP("FXL: GetSamplerState - The given state index exceeds the number of sampler states contained in the given pass.\n"); + } + } + + FXLSAMPLERSTATEDATA* pData = FXLI_pSamplerStates(pPass)->pStateList + StateIndex; + FLOAT* pValue; + + *pSamplerIndex = pData->Index; + *pStateType = (D3DSAMPLERSTATETYPE)pData->Type; + + if (StateIndex < FXLI_pSamplerStates(pPass)->DynamicFCount) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pData->Value); + *pStateValue = *(DWORD*)pValue; + } + else if (StateIndex < FXLI_pSamplerStates(pPass)->DynamicFCount + FXLI_pSamplerStates(pPass)->DynamicICount) + { + pValue = FXLEffectI_GetDynamicStateValue(pEffect, pData->Value); + *pStateValue = (DWORD)*pValue; + } + else + { + *pStateValue = pData->Value; + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE FXLPARAMETER_CONTEXT WINAPI FXLEffect_GetParameterContext( + __in FXLEffect* pEffect, + FXLHANDLE Pass, + FXLHANDLE Parameter) +{ + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + DWORD Index = FXLI_GetParameterIndex(Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + + FXLPARAMETERENTRY* pEntry = FXLEffectI_GetParameterEntry(pEffect, Parameter); + if (pEntry->Content != FXLPACONTENT_DATA) + { + FXLRIP("GetParameterContext - Context information cannot be given for a struct or array parameter.\n"); + } + } + + FXLSHADERSTATEENTRY* pState = FXLI_pShaderStates(pPass); + DWORD Scope8 = (Parameter & 1) << 3; + UINT Group = (Index >> 6); + UINT Shift = 63 - (Index & 63); + + return (FXLPARAMETER_CONTEXT)((((FXLI_pUsageFlags(pState, Scope8+0)[Group] >> Shift) & 1) << 0) | + (((FXLI_pUsageFlags(pState, Scope8+1)[Group] >> Shift) & 1) << 1) | + (((FXLI_pUsageFlags(pState, Scope8+2)[Group] >> Shift) & 1) << 2) | + (((FXLI_pUsageFlags(pState, Scope8+3)[Group] >> Shift) & 1) << 3) | + (((FXLI_pUsageFlags(pState, Scope8+4)[Group] >> Shift) & 1) << 4) | + (((FXLI_pUsageFlags(pState, Scope8+5)[Group] >> Shift) & 1) << 5) | + (((FXLI_pUsageFlags(pState, Scope8+6)[Group] >> Shift) & 1) << 6) | + (((FXLI_pUsageFlags(pState, Scope8+7)[Group] >> Shift) & 1) << 7)); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_GetParameterRegister( + __in FXLEffect* pEffect, + FXLHANDLE Pass, + FXLHANDLE Parameter, + FXLPARAMETER_CONTEXT Context, + __out UINT* pRegisterIndex, + __out UINT* pRegisterCount) +{ + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + DWORD Index = FXLI_GetParameterIndex(Parameter); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + + FXLASSERT(pRegisterIndex != NULL); + FXLASSERT(pRegisterCount != NULL); + + FXLPARAMETERENTRY* pEntry = FXLEffectI_GetParameterEntry(pEffect, Parameter); + if (pEntry->Content != FXLPACONTENT_DATA) + { + FXLRIP("GetParameterRegister - Register information cannot be given for a struct or array parameter.\n"); + } + + if ((((DWORD)Context - 1) & (DWORD)Context) != 0) + { + FXLRIP("GetParameterRegister - A single context must be specified to obtain specific register information.\n"); + } + + FXLPARAMETER_CONTEXT TotalContext = FXLEffect_GetParameterContext(pEffect, Pass, Parameter); + if ((TotalContext & Context) == 0) + { + FXLRIP("GetParameterRegister - The given parameter does not possess the given context for the given pass.\n"); + } + } + + FXLSHADERSTATEENTRY* pState = FXLI_pShaderStates(pPass); + FXLPASSPARAMETERREF* pRefList = FXLI_SelectValue(Parameter, FXLI_pReferenceListLocal(pState), FXLI_pReferenceListShared(pState)); + FXLPASSPARAMETERREF* pRef = pRefList + Index; + + UINT ContextIndex = FXLI_Log2(Context); + + *pRegisterIndex = FXLI_GetPassParameterRefIndex(pRef, ContextIndex); + *pRegisterCount = FXLI_GetPassParameterRefCount(pRef, ContextIndex); +} + +/**************************************************************************** + * + * Public technique and pass routines. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_BeginTechnique( + __in FXLEffect* pEffect, + FXLHANDLE Technique, + DWORD Flags) +{ + FXLTECHNIQUEENTRY* pTechnique = FXLEffectI_GetTechnique(pEffect, Technique); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidateTechniqueHandle(pEffect, Technique); + + if (pEffect->m_dwActiveTechnique != 0) + { + FXLRIP("BeginTechnique - The nesting of techniques is unsupported.\n"); + } + + if (pEffect->m_dwDevice == 0) + { + FXLRIP("BeginTechnique - A Direct3DDevice object must be set for the effect " + "through FXLCreateEffect or FXLEffect_ChangeDevice before a technique may be begun.\n"); + } + } + + FXLI_BeginTechnique(pEffect, pTechnique, Flags); + + pEffect->m_ActiveTechniqueHandle = Technique; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_BeginTechniqueFromIndex( + __in FXLEffect* pEffect, + UINT TechniqueIndex, + DWORD Flags) +{ + if (PARAMETER_CHECK) + { + if (pEffect->m_dwActiveTechnique != 0) + { + FXLRIP("BeginTechniqueFromIndex - The nesting of techniques is unsupported.\n"); + } + + if (pEffect->m_dwDevice == 0) + { + FXLRIP("BeginTechniqueFromIndex - A Direct3DDevice object must be set for the effect " + "through FXLCreateEffect or FXLEffect_ChangeDevice before a technique may be begun.\n"); + } + + if (TechniqueIndex >= pEffect->m_TechniqueCount) + { + FXLRIP("BeginTechniqueFromIndex - The given technique index exceeds the number of techniques in the effect.\n"); + } + } + + FXLI_BeginTechnique(pEffect, FXLI_pTechnique(pEffect, TechniqueIndex), Flags); + + pEffect->m_ActiveTechniqueHandle = FXLI_EncodeTechniqueHandle(TechniqueIndex); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_EndTechnique( + __in FXLEffect* pEffect) +{ + if (PARAMETER_CHECK) + { + if (pEffect->m_dwActiveTechnique == 0) + { + FXLRIP("EndTechnique - A technique cannot be ended before it has begun.\n"); + } + } + + if (pEffect->m_TechniqueFlags & FXL_RESTORE_DEFAULT_STATE) + { + IDirect3DDevice9* pDevice = FXLI_pDevice(pEffect); + + if (pEffect->m_TechniqueFlags & FXL_RESTORE_DEFAULT_RENDER_STATE) + { + // Restore all render states altered by the passes used in the technique to D3D defaults. + + UINT Group; + UINT64 RestoreFlags; + DWORD SkipCount; + DWORD SetCount; + DWORD StateIndex; + DWORD StateLimit; + + for (Group = 0; Group < 2; Group++) + { + StateIndex = Group << 6; + + RestoreFlags = pEffect->m_RenderStateDirtyFlags[Group]; + + while (RestoreFlags != 0) + { + SkipCount = FXLI_CountLeadingZeros64(RestoreFlags); + RestoreFlags <<= SkipCount; + StateIndex += SkipCount; + + SetCount = FXLI_CountLeadingZeros64(~RestoreFlags); + RestoreFlags <<= SetCount; + StateLimit = StateIndex + SetCount; + + do + { + FXLASSERT(StateIndex < FXL_DEFAULT_RENDER_STATE_ENTRIES); + + pDevice->SetRenderState((D3DRENDERSTATETYPE)g_FXLIDefaultRenderStateList[StateIndex].Type, + g_FXLIDefaultRenderStateList[StateIndex].Value); + StateIndex++; + } while (StateIndex != StateLimit); + } + } + } + + if (pEffect->m_TechniqueFlags & FXL_RESTORE_DEFAULT_SAMPLER_STATE) + { + // Restore all sampler states altered by the passes used in the technique to D3D defaults. + + UINT Group; + UINT64 RestoreFlags; + DWORD SkipCount; + DWORD SetCount; + DWORD StateIndex; + DWORD StateLimit; + DWORD SamplerIndex; + DWORD TypeIndex; + UINT SamplerStateGroupCount = FXLI_pActiveTechnique(pEffect)->SamplerStateGroupCount; + + for (Group = 0; Group < SamplerStateGroupCount; Group += 2) + { + StateIndex = 0; + + RestoreFlags = pEffect->m_SamplerStateDirtyFlags[Group >> 1]; + + while (RestoreFlags != 0) + { + SkipCount = FXLI_CountLeadingZeros64(RestoreFlags); + RestoreFlags <<= SkipCount; + StateIndex += SkipCount; + + SetCount = FXLI_CountLeadingZeros64(~RestoreFlags); + RestoreFlags <<= SetCount; + StateLimit = StateIndex + SetCount; + + do + { + SamplerIndex = Group + (StateIndex >> 5); + TypeIndex = StateIndex & 31; + + FXLASSERT(TypeIndex < FXL_DEFAULT_SAMPLER_STATE_ENTRIES); + + pDevice->SetSamplerState(SamplerIndex, + (D3DSAMPLERSTATETYPE)g_FXLIDefaultSamplerStateList[TypeIndex].Type, + g_FXLIDefaultSamplerStateList[TypeIndex].Value); + StateIndex++; + } while (StateIndex != StateLimit); + } + } + } + } + + pEffect->m_dwActiveTechnique = 0; + pEffect->m_ActiveTechniqueHandle = 0; +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_BeginPass( + __in FXLEffect* pEffect, + FXLHANDLE Pass) +{ + FXLPASSENTRY* pPass = FXLEffectI_GetPass(pEffect, Pass); + + if (PARAMETER_CHECK) + { + FXLEffectI_ValidatePassHandle(pEffect, Pass); + + if (pEffect->m_dwActiveTechnique == 0) + { + FXLRIP("BeginPass - A technique must be started before beginning a pass.\n"); + } + + if (pEffect->m_dwActivePass != 0) + { + FXLRIP("BeginPass - The nesting of passes is unsupported.\n"); + } + + UINT PassIndex; + for (PassIndex = 0; PassIndex < FXLI_pActiveTechnique(pEffect)->PassCount; PassIndex++) + { + if (pPass == FXLI_pPass(FXLI_pActiveTechnique(pEffect), PassIndex)) + { + break; + } + } + if (PassIndex == FXLI_pActiveTechnique(pEffect)->PassCount) + { + FXLRIP("BeginPass - The given pass does not belong to the currently active technique.\n"); + } + } + + FXLI_BeginPass(pEffect, pPass); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_BeginPassFromIndex( + __in FXLEffect* pEffect, + UINT PassIndex) +{ + if (PARAMETER_CHECK) + { + if (pEffect->m_dwActiveTechnique == 0) + { + FXLRIP("BeginPassFromIndex - A technique must be started before beginning a pass.\n"); + } + + if (pEffect->m_dwActivePass != 0) + { + FXLRIP("BeginPassFromIndex - The nesting of passes is unsupported.\n"); + } + + if (PassIndex >= FXLI_pActiveTechnique(pEffect)->PassCount) + { + FXLRIP("BeginPassFromIndex - The given index exceeds the number of passes in the active technique.\n"); + } + } + + FXLI_BeginPass(pEffect, FXLI_pPass(FXLI_pActiveTechnique(pEffect), PassIndex)); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLEffect_EndPass( + __in FXLEffect* pEffect) +{ + if (PARAMETER_CHECK) + { + if (pEffect->m_dwActivePass == NULL) + { + FXLRIP("EndPass - A pass cannot be ended before it has begun.\n"); + } + } + + pEffect->m_dwPreviousPass = pEffect->m_dwActivePass; + pEffect->m_dwActivePass = 0; +} + +/**************************************************************************** + * + * Filtered commit routine. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// General Commit operations will update shader constant registers with parameter +// values (i.e. "send them to the device") under the following conditions: +// +// - Parameters will only be sent to the device if they are referenced by either +// the vertex shader or pixel shader in the current pass. +// +// - All referenced local parameters will be sent to the device (even if +// they have not been modified) on the first Commit after a BeginPass, +// unless a matching vertex and pixel shader were used on the previous +// pass. After the first Commit (or when the shaders do match), only local +// parameters which have been modified will be sent to the device. +// +// - All shared parameters will be sent to the device using the same conditions +// as local parameters unless the shared parameters are in a state of +// correlation. +// +// - If the effects system is in a state of shared parameter correlation, no +// shared parameter will be sent to the device unless it has been +// modified in value (even on the first Commit in a pass). Once modified, +// a shared parameter will be sent to the device on the next Commit, even +// if it is not referenced by either of the shaders in the associated pass. +// +// These general conditions for parameter register updates by Commit are further +// qualified for the CommitU routine to take into account the register update mode +// of individual parameters. CommitU will only send a parameter to the device +// if the parameter is set to use automatic register updates (the default). +// A parameter using manual register updates will be disregarded by CommitU +// and must be explicitly set through D3DDevice SetShaderConstant operations. + +FXLINLINE VOID WINAPI FXLEffect_CommitU( + __in FXLEffect* pEffect) +{ + XMVECTOR DirtyFlags[2]; + XMVECTOR UpdateFlags[2]; + UINT Group; + + for (Group = 0; Group < pEffect->m_ParameterBitGroupsLocal; Group += 4) + { + DirtyFlags[0] = XMLoadVector4A(&pEffect->m_DirtyFlagsLocal[Group]); + UpdateFlags[0] = XMLoadVector4A(&pEffect->m_UpdateFlagsLocal[Group]); + DirtyFlags[1] = XMLoadVector4A(&pEffect->m_DirtyFlagsLocal[Group + 2]); + UpdateFlags[1] = XMLoadVector4A(&pEffect->m_UpdateFlagsLocal[Group + 2]); + + DirtyFlags[0] = XMVectorAndInt(DirtyFlags[0], UpdateFlags[0]); + DirtyFlags[1] = XMVectorAndInt(DirtyFlags[1], UpdateFlags[1]); + + XMStoreVector4A(&pEffect->m_DirtyFlagsLocal[Group], DirtyFlags[0]); + XMStoreVector4A(&pEffect->m_DirtyFlagsLocal[Group + 2], DirtyFlags[1]); + } + + for (Group = 0; Group < pEffect->m_ParameterBitGroupsShared; Group += 4) + { + DirtyFlags[0] = XMLoadVector4A(&FXLI_pDirtyFlagsShared(pEffect)[Group]); + UpdateFlags[0] = XMLoadVector4A(&FXLI_pUpdateFlagsShared(pEffect)[Group]); + DirtyFlags[1] = XMLoadVector4A(&FXLI_pDirtyFlagsShared(pEffect)[Group + 2]); + UpdateFlags[1] = XMLoadVector4A(&FXLI_pUpdateFlagsShared(pEffect)[Group + 2]); + + DirtyFlags[0] = XMVectorAndInt(DirtyFlags[0], UpdateFlags[0]); + DirtyFlags[1] = XMVectorAndInt(DirtyFlags[1], UpdateFlags[1]); + + XMStoreVector4A(&FXLI_pDirtyFlagsShared(pEffect)[Group], DirtyFlags[0]); + XMStoreVector4A(&FXLI_pDirtyFlagsShared(pEffect)[Group + 2], DirtyFlags[1]); + } + + FXLEffect_Commit(pEffect); +} + +/**************************************************************************** + * + * Public default state management functions. + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLSetDefaultRenderState( + D3DRENDERSTATETYPE StateType, + DWORD StateValue) +{ + UINT StateIndex; + + for (StateIndex = 0; StateIndex < FXL_DEFAULT_RENDER_STATE_ENTRIES; StateIndex++) + { + if (g_FXLIDefaultRenderStateList[StateIndex].Type == (DWORD)StateType) + { + g_FXLIDefaultRenderStateList[StateIndex].Value = StateValue; + return; + } + } + + FXLRIP("FXLSetDefaultRenderState - The given state type was not found in the default render state list.\n"); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLGetDefaultRenderState( + D3DRENDERSTATETYPE StateType, + __out DWORD* pStateValue) +{ + UINT StateIndex; + + FXLASSERT(pStateValue != NULL); + + for (StateIndex = 0; StateIndex < FXL_DEFAULT_RENDER_STATE_ENTRIES; StateIndex++) + { + if (g_FXLIDefaultRenderStateList[StateIndex].Type == (DWORD)StateType) + { + *pStateValue = g_FXLIDefaultRenderStateList[StateIndex].Value; + return; + } + } + + FXLRIP("FXLGetDefaultRenderState - The given state type was not found in the default render state list.\n"); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLSetDefaultSamplerState( + D3DSAMPLERSTATETYPE StateType, + DWORD StateValue) +{ + UINT StateIndex; + + for (StateIndex = 0; StateIndex < FXL_DEFAULT_SAMPLER_STATE_ENTRIES; StateIndex++) + { + if (g_FXLIDefaultSamplerStateList[StateIndex].Type == (DWORD)StateType) + { + g_FXLIDefaultSamplerStateList[StateIndex].Value = StateValue; + return; + } + } + + FXLRIP("FXLSetDefaultSamplerState - The given state type was not found in the default sampler state list.\n"); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLGetDefaultSamplerState( + D3DSAMPLERSTATETYPE StateType, + __out DWORD* pStateValue) +{ + UINT StateIndex; + + FXLASSERT(pStateValue != NULL); + + for (StateIndex = 0; StateIndex < FXL_DEFAULT_SAMPLER_STATE_ENTRIES; StateIndex++) + { + if (g_FXLIDefaultSamplerStateList[StateIndex].Type == (DWORD)StateType) + { + *pStateValue = g_FXLIDefaultSamplerStateList[StateIndex].Value; + return; + } + } + + FXLRIP("FXLGetDefaultSamplerState - The given state type was not found in the default sampler state list.\n"); +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLApplyDefaultRenderStates( + __in IDirect3DDevice9* pDevice) +{ + UINT StateIndex; + + FXLASSERT(pDevice != NULL); + + for (StateIndex = 0; StateIndex < FXL_DEFAULT_RENDER_STATE_ENTRIES; StateIndex++) + { + D3DDevice_SetRenderState(pDevice, (D3DRENDERSTATETYPE)g_FXLIDefaultRenderStateList[StateIndex].Type, g_FXLIDefaultRenderStateList[StateIndex].Value); + } +} + +//------------------------------------------------------------------------------ + +FXLINLINE VOID WINAPI FXLApplyDefaultSamplerStates( + __in IDirect3DDevice9* pDevice) +{ + UINT SamplerIndex; + UINT StateIndex; + + FXLASSERT(pDevice != NULL); + + for (SamplerIndex = 0; SamplerIndex < D3DSAMP_MAXSAMPLERS; SamplerIndex++) + { + for (StateIndex = 0; StateIndex < FXL_DEFAULT_SAMPLER_STATE_ENTRIES; StateIndex++) + { + D3DDevice_SetSamplerState(pDevice, SamplerIndex, (D3DSAMPLERSTATETYPE)g_FXLIDefaultSamplerStateList[StateIndex].Type, g_FXLIDefaultSamplerStateList[StateIndex].Value); + } + } +} + +#ifdef __cplusplus +//}; // extern "C" +#endif + +#pragma warning(pop) + +#endif // __FXL_INL__ diff --git a/third_party/xbox_sdk/include/xbdm.h b/third_party/xbox_sdk/include/xbdm.h new file mode 100644 index 0000000..3b4cf64 --- /dev/null +++ b/third_party/xbox_sdk/include/xbdm.h @@ -0,0 +1,1497 @@ + + +/************************************************************************** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * + * Xbox Debug Monitor APIs - for use on PC + * + **************************************************************************/ +#ifndef __XBDM_H__ +#define __XBDM_H__ + +#define XBDMAPI + +#include + + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* +HPGOMODULE - used to refer to the run-time state of a PGO-instrumented +module. +*/ +DECLARE_HANDLE(HPGOMODULE); + +#define DMHRAPI XBDMAPI HRESULT __stdcall + +// Notification types +#define DM_NONE 0 +#define DM_BREAK 1 +#define DM_DEBUGSTR 2 +#define DM_EXEC 3 +#define DM_SINGLESTEP 4 +#define DM_MODLOAD 5 +#define DM_MODUNLOAD 6 +#define DM_CREATETHREAD 7 +#define DM_DESTROYTHREAD 8 +#define DM_EXCEPTION 9 +#define DM_ASSERT 12 +#define DM_DATABREAK 13 +#define DM_RIP 14 +#define DM_SECTIONLOAD 16 +#define DM_SECTIONUNLOAD 17 +#define DM_FIBER 18 +#define DM_STACKTRACE 19 +#define DM_BUGCHECK 20 +#define DM_ASSERTION_FAILURE 21 +#define DM_PGO_MODULE_STARTUP 22 +#define DM_NOTIFYMAX 22 + +#define DM_NOTIFICATIONMASK 0xffffff +#define DM_STOPTHREAD 0x80000000 + +typedef DWORD (__stdcall *PDM_NOTIFY_FUNCTION)(ULONG dwNotification, ULONG_PTR ulpParam); + + + +// Break notification structure +typedef struct _DMN_BREAK { + PVOID Address; + DWORD ThreadId; +} DMN_BREAK, *PDMN_BREAK; + +// Data breakpoint notification structure { +typedef struct _DMN_DATABREAK { + PVOID Address; + DWORD ThreadId; + DWORD BreakType; + PVOID DataAddress; +} DMN_DATABREAK, *PDMN_DATABREAK; + +// Debugstr notification structure +typedef struct _DMN_DEBUGSTR { + DWORD ThreadId; + DWORD Length; + LPCSTR String; +} DMN_DEBUGSTR, *PDMN_DEBUGSTR; + +// execution notification values +#define DMN_EXEC_STOP 0 +#define DMN_EXEC_START 1 +#define DMN_EXEC_REBOOT 2 +#define DMN_EXEC_PENDING 3 +#define DMN_EXEC_REBOOT_TITLE 4 +#define DMN_EXEC_PENDING_TITLE 5 + +// Module load notification structure +typedef struct _DMN_MODLOAD { + char Name[MAX_PATH]; + PVOID BaseAddress; + ULONG Size; + ULONG TimeStamp; + ULONG CheckSum; + ULONG Flags; + PVOID PDataAddress; + ULONG PDataSize; + DWORD ThreadId; +} DMN_MODLOAD, *PDMN_MODLOAD; + +// Module load notification structure +typedef struct _DMN_MODLOAD_EX { + ULONG SizeOfStruct; //Size of this structure + char Name[MAX_PATH]; + PVOID BaseAddress; + ULONG Size; + ULONG TimeStamp; + ULONG CheckSum; + ULONG Flags; + PVOID PDataAddress; + ULONG PDataSize; + DWORD ThreadId; + ULONG OriginalSize; +} DMN_MODLOAD_EX, *PDMN_MODLOAD_EX; + +#define DMN_MODFLAG_XBE 0x0001 +#define DMN_MODFLAG_TLS 0x0002 +#define DMN_MODFLAG_DLL 0x0004 + +// Section load/unload notification structure +typedef struct _DMN_SECTIONLOAD { + char Name[MAX_PATH]; + PVOID BaseAddress; + ULONG Size; + USHORT Index; + USHORT Flags; +} DMN_SECTIONLOAD, *PDMN_SECTIONLOAD; + +#define DMN_SECFLAG_LOADED 0x0001 +#define DMN_SECFLAG_READABLE 0x0002 +#define DMN_SECFLAG_WRITEABLE 0x0004 +#define DMN_SECFLAG_EXECUTABLE 0x0008 +#define DMN_SECFLAG_UNINITIALIZED 0x0010 + +// thread create notification structure +typedef struct _DMN_CREATETHREAD { + DWORD ThreadId; + PVOID StartAddress; + PCHAR ThreadNameAddress; +} DMN_CREATETHREAD, *PDMN_CREATETHREAD; + +// fiber create/delete notification structure +typedef struct _DMN_FIBER { + DWORD FiberId; + BOOL Create; + PVOID StartAddress; +} DMN_FIBER, *PDMN_FIBER; + + +// exception notification +typedef struct _DMN_EXCEPTION { + DWORD ThreadId; + DWORD Code; + PVOID Address; + DWORD Flags; + DWORD Information[2]; +} DMN_EXCEPTION, *PDMN_EXCEPTION; + +// bugcheck notification +typedef struct _DMN_BUGCHECK { + DWORD BugCheckData[5]; +} DMN_BUGCHECK, *PDMN_BUGCHECK; + +#define DM_EXCEPT_NONCONTINUABLE 1 +#define DM_EXCEPT_FIRSTCHANCE 2 + +// PGO module load notification +typedef struct _DMN_PGO_MODLOAD { + PCSTR pszModuleName; + HPGOMODULE hPgoModule; + DWORD ThreadId; +} DMN_PGO_MODLOAD, *PDMN_PGO_MODLOAD; + + +// Notification +#define DM_PERSISTENT 0x00000001 +#define DM_DEBUGSESSION 0x00000002 +#define DM_ASYNCSESSION 0x00000004 +typedef struct _DMN_SESSION *PDMN_SESSION; +DMHRAPI DmOpenNotificationSession(DWORD dwFlags, PDMN_SESSION *pSession); +DMHRAPI DmCloseNotificationSession(PDMN_SESSION Session); +DMHRAPI DmNotify(PDMN_SESSION Session, DWORD dwNotification, + PDM_NOTIFY_FUNCTION pfnHandler); + +// notification extensions +typedef DWORD (__stdcall *PDM_EXT_NOTIFY_FUNCTION)(LPCSTR szNotification); +DMHRAPI DmRegisterNotificationProcessor(PDMN_SESSION Session, LPCSTR szType, + PDM_EXT_NOTIFY_FUNCTION pfn); + +// protocol +#define DEBUGGER_PORT 0x2da + +// breakpoint types +#define DMBREAK_NONE 0 +#define DMBREAK_WRITE 1 +#define DMBREAK_READWRITE 2 +#define DMBREAK_EXECUTE 3 +#define DMBREAK_FIXED 4 +#define DMBREAK_READ 5 + +// breakpoint routines +DMHRAPI DmSetBreakpoint(PVOID addr); +DMHRAPI DmRemoveBreakpoint(PVOID addr); +DMHRAPI DmSetInitialBreakpoint(void); +DMHRAPI DmSetDataBreakpoint(PVOID addr, DWORD dwType, DWORD dwSize); +DMHRAPI DmIsBreakpoint(PVOID addr, LPDWORD dwType); + +// execution start and stop +DMHRAPI DmStop(void); +DMHRAPI DmGo(void); +DMHRAPI DmHaltThread(DWORD dwThreadId); +DMHRAPI DmContinueThread(DWORD dwThreadId, BOOL fException); + +// File I/O monitor +DMHRAPI DmStartFileEventCapture(); +DMHRAPI DmStopFileEventCapture(); + +// debugger +DMHRAPI DmIsDebuggerPresent(void); +DMHRAPI DmConnectDebugger(BOOL fConnect); + +// process id (fabricated) +DMHRAPI DmGetPid(LPDWORD pdwPid); + +// event stop control +#define DMSTOP_CREATETHREAD 0x00000001 +#define DMSTOP_FCE 0x00000002 +#define DMSTOP_DEBUGSTR 0x00000004 +#define DMSTOP_STACKTRACE 0x00000008 +#define DMSTOP_MODLOAD 0x00000010 +#define DMSTOP_TITLELAUNCH 0x00000020 +#define DMSTOP_PGOMODSTARTUP 0x00000040 +DMHRAPI DmStopOn(DWORD dwStopFlags, BOOL fStop); + + +// reboot +#define DMBOOT_TITLE 0 +#define DMBOOT_WAIT 1 +// WARM does not exist, it is now a cold boot. So we do not break existing tools we have left the define. +#define DMBOOT_WARM_DEPRECATED 2 +#define DMBOOT_COLD 4 +#define DMBOOT_STOP 8 + +DMHRAPI DmReboot(DWORD dwFlags); + + +DMHRAPI DmRebootEx(DWORD dwFlags, LPCSTR szImagePath, LPCSTR szMediaPath, LPCSTR szDbgCmdLine); + +//crash dump +DMHRAPI DmCrashDump(); + +// memory +DMHRAPI DmGetMemory(LPCVOID lpbAddr, DWORD cb, LPVOID lpbBuf, + LPDWORD pcbRet); + +// The checksum is computed on the Xbox, without transferring the +// memory across the network. Each block of bytes will have its own +// 32-bit CRC calculated separately. (If you just want to checksum +// the whole chunk of data, pass the same value for both cb +// and cbBlockSize.) +// Requirements: +// lpbAddr must be aligned on an 8-byte boundary. +// lpbAddr can't point to code +// cb must be a multiple of cbBlockSize +// cbBlockSize must be a multiple of 8 bytes +// lpbBuf will have sizeof(DWORD)*(cb/cbBlockSize) bytes written to it. + +DMHRAPI DmGetMemoryChecksum(LPCVOID lpbAddr, DWORD cb, + DWORD cbBlockSize, LPVOID lpbBuf, LPDWORD pcbRet); + +DMHRAPI DmSetMemory(LPVOID lpbAddr, DWORD cb, LPCVOID lpbBuf, + LPDWORD pcbRet); + +typedef struct _DM_WALK_MEMORY *PDM_WALK_MEMORY; +typedef struct _DM_MEMORY_REGION +{ + PVOID BaseAddress; + DWORD Size; + DWORD Protect; +} DM_MEMORY_REGION, *PDM_MEMORY_REGION; +DMHRAPI DmWalkCommittedMemory(PDM_WALK_MEMORY *, PDM_MEMORY_REGION); +DMHRAPI DmCloseCommittedMemory(PDM_WALK_MEMORY); + + + +// thread stopped info +typedef struct _DM_THREADSTOP { + DWORD NotifiedReason; + union { + DMN_BREAK Break; + DMN_DATABREAK DataBreak; + DMN_EXCEPTION Exception; + DMN_DEBUGSTR DebugStr; + DMN_BUGCHECK BugCheck; + } u; +} DM_THREADSTOP, *PDM_THREADSTOP; + +// thread general info +typedef struct _DM_THREADINFO { + DWORD SuspendCount; + DWORD Priority; + LPVOID TlsBase; +} DM_THREADINFO, *PDM_THREADINFO; + +typedef struct _DM_THREADINFOEX { + DWORD Size; //Size of this structure + DWORD SuspendCount; + DWORD Priority; + LPVOID TlsBase; + LPVOID StartAddress; + LPVOID StackBase; + LPVOID StackLimit; + FILETIME CreateTime; + DWORD StackSlackSpace; + PCHAR ThreadNameAddress; + DWORD ThreadNameLength; //Including NULL termination + UCHAR CurrentProcessor; + DWORD LastError; +} DM_THREADINFOEX, *PDM_THREADINFOEX; + +// thread routines +DMHRAPI DmGetThreadList(LPDWORD rgdwThreads, LPDWORD pcThreads); +DMHRAPI DmGetThreadContext(DWORD dwThreadId, PXCONTEXT pdmcr); +DMHRAPI DmSetThreadContext(DWORD dwThreadId, PXCONTEXT pdmcr); +DMHRAPI DmIsThreadStopped(DWORD dwThreadId, PDM_THREADSTOP pdmts); +DMHRAPI DmGetThreadInfoEx(DWORD dwThreadId, PDM_THREADINFOEX pdmti); +DMHRAPI DmSuspendThread(DWORD dwThreadId); +DMHRAPI DmResumeThread(DWORD dwThreadId); + + +// loaded modules and sections +typedef struct _DM_WALK_MODULES *PDM_WALK_MODULES; +DMHRAPI DmWalkLoadedModules(PDM_WALK_MODULES *, PDMN_MODLOAD); +DMHRAPI DmWalkLoadedModulesEx(PDM_WALK_MODULES *, PDMN_MODLOAD_EX); +DMHRAPI DmCloseLoadedModules(PDM_WALK_MODULES); +typedef struct _DM_WALK_MODSECT *PDM_WALK_MODSECT; +DMHRAPI DmWalkModuleSections(PDM_WALK_MODSECT *, LPCSTR, PDMN_SECTIONLOAD); +DMHRAPI DmCloseModuleSections(PDM_WALK_MODSECT); + + +DMHRAPI +DmGetXexHeaderField( + IN LPCSTR szImageName, + IN ULONG HeaderField, + OUT PUCHAR Buffer, + IN ULONG BufferLength, + IN ULONG *FieldSize + ); + +// XBE info +typedef struct _DM_XBE { + char LaunchPath[MAX_PATH+1]; + DWORD TimeStamp; + DWORD CheckSum; + DWORD StackSize; +} DM_XBE, *PDM_XBE; +DMHRAPI DmGetXbeInfo(LPCSTR szName, PDM_XBE); + +#define DM_XBEONDISKONLY 0x00000001 +DMHRAPI DmGetXbeInfoEx(LPCSTR szName, PDM_XBE, DWORD dwFlags); + + +// socket-level commands +typedef struct _DM_CONNECTION *PDM_CONNECTION; +DMHRAPI DmSetConnectionTimeout(DWORD dwConnectTimeout, DWORD dwConversationTimeout); +DMHRAPI DmOpenConnection(PDM_CONNECTION *); +DMHRAPI DmOpenSecureConnection(PDM_CONNECTION *, LPCSTR szPassword); +DMHRAPI DmCloseConnection(PDM_CONNECTION); +DMHRAPI DmSendCommand(PDM_CONNECTION, LPCSTR szCommand, LPSTR szResponse, + LPDWORD lpdwResponseSize); +DMHRAPI DmReceiveStatusResponse(PDM_CONNECTION, LPSTR szResponse, + LPDWORD lpdwResponseSize); +DMHRAPI DmReceiveSocketLine(PDM_CONNECTION, LPSTR szResponse, + LPDWORD lpdwResponseSize); +DMHRAPI DmDedicateConnection(PDM_CONNECTION, LPCSTR szHandler); +DMHRAPI DmSendBinary(PDM_CONNECTION, LPCVOID pv, DWORD cb); +DMHRAPI DmReceiveBinary(PDM_CONNECTION, LPCVOID pv, DWORD cb, LPDWORD pcbRet); +DMHRAPI DmResolveXboxName(LPDWORD lpdwAddress); +DMHRAPI DmGetNameOfXbox(LPSTR szName, LPDWORD lpdwSize, BOOL fResolvable); +DMHRAPI DmGetAltAddress(LPDWORD lpdwAddress); +DMHRAPI DmFindConsole(DWORD dwRetryCount, DWORD dwRetryDelay); + +#ifdef _MSWSOCK_ // mswsock.h is required +DMHRAPI DmTransmitFile(PDM_CONNECTION pdcon, + HANDLE hFile, + DWORD nNumberOfBytesToWrite, + DWORD nNumberOfBytesPerSend, + LPOVERLAPPED lpOverlapped, + LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, + DWORD dwReserved + ); +#endif // _MSWSOCK_ + +#ifdef _WINSOCK2API_ // winsock2.h is required +DMHRAPI DmWSAGetOverlappedResult(PDM_CONNECTION pdcon, + LPWSAOVERLAPPED lpOverlapped, + LPDWORD lpcbTransfer, + BOOL fWait, + LPDWORD lpdwFlags + ); +#endif // _WINSOCK2API_ + +// protocol commands +DMHRAPI DmUseSharedConnection(BOOL); + +// file attributes +typedef struct _DM_FILE_ATTRIBUTES { + char Name[256]; + FILETIME CreationTime; + FILETIME ChangeTime; + DWORD SizeHigh; + DWORD SizeLow; + DWORD Attributes; +} DM_FILE_ATTRIBUTES, *PDM_FILE_ATTRIBUTES; + +// filesystem +DMHRAPI DmSendFileA(LPCSTR szLocalName, LPCSTR szRemoteName); +// filesystem +DMHRAPI DmSendFileW(LPCWSTR szLocalName, LPCSTR szRemoteName); +#ifdef UNICODE +#define DmSendFile DmSendFileW +#else +#define DmSendFile DmSendFileA +#endif // !UNICODE + +DMHRAPI DmReceiveFileA(LPCSTR szLocalName, LPCSTR szRemoteName); +DMHRAPI DmReceiveFileW(LPCWSTR szLocalName, LPCSTR szRemoteName); +#ifdef UNICODE +#define DmReceiveFile DmReceiveFileW +#else +#define DmReceiveFile DmReceiveFileA +#endif // !UNICODE + +DMHRAPI DmGetFileAttributes(LPCSTR szFileName, PDM_FILE_ATTRIBUTES); +DMHRAPI DmSetFileAttributes(LPCSTR szFileName, PDM_FILE_ATTRIBUTES); +DMHRAPI DmMkdir(LPCSTR szDirectoryName); +DMHRAPI DmRenameFile(LPCSTR szOldName, LPCSTR szNewName); +DMHRAPI DmDeleteFile(LPCSTR szFileName, BOOL fIsDirectory); + +// partial file I/O +DMHRAPI DmWriteFilePartial(LPCSTR szFileName, DWORD dwFileOffset, + LPBYTE pbDataBuffer, DWORD dwDataSize, LPDWORD lpdwBytesWritten); +DMHRAPI DmReadFilePartial(LPCSTR szFileName, DWORD dwFileOffset, + LPBYTE pbDataBuffer, DWORD dwDataSize, LPDWORD lpdwBytesRead); +DMHRAPI DmSetFileSize(LPCSTR szFileName, DWORD dwFileOffset, + DWORD dwCreateDisposition); + + +// directory walking +typedef struct _DM_WALK_DIR *PDM_WALK_DIR; +DMHRAPI DmWalkDir(PDM_WALK_DIR *, LPCSTR szDir, PDM_FILE_ATTRIBUTES); +DMHRAPI DmCloseDir(PDM_WALK_DIR); + +// time +DMHRAPI DmGetSystemTime(LPSYSTEMTIME lpSysTime); + +// config functions +DMHRAPI DmSetConfigValue(ULONG ulValueIndex, ULONG ulType, PVOID pValue, ULONG cbValueLength); +DMHRAPI DmSetServerName(LPCSTR szServerName); + + +// name functions +#define DM_XBOX_NAME_MAX 21 +DMHRAPI DmGetXboxName(LPSTR, LPDWORD); +DMHRAPI DmSetXboxName(LPCSTR); +DMHRAPI DmSetXboxNameNoRegister(LPCSTR); + +// Debug settings + +// Dump mode: behavior when exception occurs (while not debugging) +#define DM_DUMPMODE_SMART 0 // Debug if xbdm can, dumps if kd required +#define DM_DUMPMODE_ENABLED 1 // Always dump +#define DM_DUMPMODE_DISABLED 2 // Always debug + +DMHRAPI DmGetDumpMode(DWORD *pdwDumpMode); +DMHRAPI DmSetDumpMode(DWORD dwDumpMode); + +// Dump reporting flags +#define DUMP_RF_REPORT_PROMPT 0 +#define DUMP_RF_REPORT_ALWAYS 0x00000001 +#define DUMP_RF_REPORT_NEVER 0x00000002 +#define DUMP_RF_REPORT_MASK 0x0000000F +#define DUMP_RF_REPORT_SHIFT 0 + +#define DUMP_RF_DESTINATION_LOCAL 0 +#define DUMP_RF_DESTINATION_REMOTE 0x00000010 +#define DUMP_RF_DESTINATION_MASK 0x000000F0 +#define DUMP_RF_DESTINATION_SHIFT 4 + +#define DUMP_RF_FORMAT_FULL 0 //Full heap +#define DUMP_RF_FORMAT_PARTIAL 0x00000100 //Partial Heap (scan memory) +#define DUMP_RF_FORMAT_NOHEAP 0x00000200 //Just Threads and Exception Info +#define DUMP_RF_FORMAT_RETAIL 0x00000300 //A retail dump - NYI +#define DUMP_RF_FORMAT_MASK 0x00000F00 +#define DUMP_RF_FORMAT_SHIFT 8 + +typedef struct _DM_DUMP_SETTINGS +{ + DWORD ReportingFlags; + char NetworkPath[MAX_PATH]; +} DM_DUMP_SETTINGS, *PDM_DUMP_SETTINGS; + +DMHRAPI DmGetDumpSettings(PDM_DUMP_SETTINGS pSettings); +DMHRAPI DmSetDumpSettings(PDM_DUMP_SETTINGS pSettings); + +// Event defer flags +#define DM_CANDEFER_EXECUTION_BREAK 1 +#define DM_CANDEFER_DEBUG_STRING 2 +#define DM_CANDEFER_SINGLE_STEP 4 +#define DM_CANDEFER_ASSERTION 8 +#define DM_CANDEFER_NT_ASSERTION 16 +#define DM_CANDEFER_DATA_BREAK 32 +#define DM_CANDEFER_RIP 64 + +DMHRAPI DmGetEventDeferFlags(DWORD *pdwEvent); +DMHRAPI DmSetEventDeferFlags(DWORD dwEvent); + +#define DMCT_DEVELOPMENT_KIT 0 +#define DMCT_TEST_KIT 1 +#define DMCT_REVIEWER_KIT 2 +DMHRAPI DmGetConsoleType(DWORD *pdwConsoleType); + +#define DMCF_DEBUGGING 1 +#define DMCF_SECONDARY_NIC 2 +#define DMCF_1GB_RAM 4 +DMHRAPI DmGetConsoleFeatures(DWORD *pdwConsoleFeatures); + + +#define DM_XBOX_HW_FLAG_HDD 0x00000020 +#define DM_XBOX_HW_FLAG_TESTKIT 0x02000000 + +typedef struct _DM_VERSION_INFO +{ + USHORT Major; + USHORT Minor; + USHORT Build; + USHORT Qfe; + +} DM_VERSION_INFO, *PDM_VERSION_INFO; + +typedef struct _DM_SYSTEM_INFO +{ + int SizeOfStruct; + + DM_VERSION_INFO BaseKernelVersion; + DM_VERSION_INFO KernelVersion; + DM_VERSION_INFO XDKVersion; + + ULONG dmSystemInfoFlags; + +} DM_SYSTEM_INFO, *PDM_SYSTEM_INFO; + + +DMHRAPI DmGetSystemInfo(PDM_SYSTEM_INFO pdmGetSystemInfo); + + +// management functions +typedef struct _DM_USER { + char UserName[256]; + DWORD AccessPrivileges; +} DM_USER, *PDM_USER; + +#define DMPL_PRIV_READ 0x0001 +#define DMPL_PRIV_WRITE 0x0002 +#define DMPL_PRIV_CONTROL 0x0004 +#define DMPL_PRIV_CONFIGURE 0x0008 +#define DMPL_PRIV_MANAGE 0x0010 + +DMHRAPI DmAddUser(LPCSTR szUserName, DWORD dwAccess); +DMHRAPI DmRemoveUser(LPCSTR szUserName); +DMHRAPI DmSetUserAccess(LPCSTR szUserName, DWORD dwAccess); +DMHRAPI DmGetUserAccess(LPCSTR szUserName, LPDWORD lpdwAccess); +typedef struct _DM_WALK_USERS *PDM_WALK_USERS; +DMHRAPI DmWalkUserList(PDM_WALK_USERS *, PDM_USER); +DMHRAPI DmCloseUserList(PDM_WALK_USERS); +DMHRAPI DmEnableSecurity(BOOL fEnable); +DMHRAPI DmIsSecurityEnabled(LPBOOL pfEnabled); +DMHRAPI DmSetAdminPassword(LPCSTR szPassword); + +// title to launch +#define DMTITLE_PERSIST 0x0001 +#define DMTITLE_UNPERSIST 0x0002 +DMHRAPI DmSetTitle(LPCSTR szDir, LPCSTR szTitle, LPCSTR szCmdLine); +DMHRAPI DmSetTitleEx(LPCSTR szDir, LPCSTR szTitle, LPCSTR szCmdLine, DWORD dwFlags); + + +// Screenshot functionality +DMHRAPI DmScreenShot(LPCSTR filename); + + + +// start / stop profile data collection +DMHRAPI DmCAPControl(LPCSTR action); + +// performance counters +#define DMCOUNT_FREQUENCY 0x000F +#define DMCOUNT_FREQ100MS 0x0001 +#define DMCOUNT_FREQ1SEC 0x000A + +#define DMCOUNT_COUNTTYPE 0x0030 +#define DMCOUNT_EVENT 0x0010 +#define DMCOUNT_VALUE 0x0000 +#define DMCOUNT_PRATIO 0x0020 +#define DMCOUNT_COUNTSUBTYPE 0x0FC0 + +// event rates +#define DMCOUNT_PERSEC 0x0040 +#define DMCOUNT_PERMSEC 0x0080 +#define DMCOUNT_PERFRAME 0x0100 +#define DMCOUNT_PERTICK 0x0200 + +// value types +#define DMCOUNT_AVERAGE 0x0040 + +typedef struct _DM_COUNTDATA { + LARGE_INTEGER CountValue; + LARGE_INTEGER RateValue; + DWORD CountType; +} DM_COUNTDATA, *PDM_COUNTDATA; + +typedef struct _DM_COUNTINFO { + char Name[256]; + DWORD Type; +} DM_COUNTINFO, *PDM_COUNTINFO; + +DMHRAPI DmQueryPerformanceCounter(LPCSTR szName, DWORD dwType, PDM_COUNTDATA); +typedef struct _DM_WALK_COUNTERS *PDM_WALK_COUNTERS; +DMHRAPI DmWalkPerformanceCounters(PDM_WALK_COUNTERS *, PDM_COUNTINFO); +DMHRAPI DmCloseCounters(PDM_WALK_COUNTERS); +DMHRAPI DmEnableGPUCounter(BOOL); + + +DMHRAPI DmGetDriveList(LPSTR rgchDrives, DWORD *pcDrives); +DMHRAPI DmGetDiskFreeSpace(char *szDrive, + PULARGE_INTEGER pnFreeBytesAvailableToCaller, + PULARGE_INTEGER pnTotalNumberOfBytes, + PULARGE_INTEGER pnTotalNumberOfFreeBytes); + + + + + +// error codes +#define FACILITY_XBDM 0x2da +#ifndef MAKE_HRESULT +#define MAKE_HRESULT(sev,fac,code) \ + ((HRESULT)(((unsigned long)sev<<31)|((unsigned long)fac<<16)|((unsigned long)code))) +#endif +#define XBDM_HRESERR(code) MAKE_HRESULT(1, FACILITY_XBDM, code) +#define XBDM_HRESSUCC(code) MAKE_HRESULT(0, FACILITY_XBDM, code) + +#define XBDM_NOERR XBDM_HRESSUCC(0) // _HRESULT_TYPEDEF_(0x02DA0000) // No error occurred. + +#define XBDM_UNDEFINED XBDM_HRESERR(0) // _HRESULT_TYPEDEF_(0x82DA0000) // An undefined error has occurred. +#define XBDM_MAXCONNECT XBDM_HRESERR(1) // _HRESULT_TYPEDEF_(0x82DA0001) // The maximum number of connections has been exceeded. +#define XBDM_NOSUCHFILE XBDM_HRESERR(2) // _HRESULT_TYPEDEF_(0x82DA0002) // No such file exists. +#define XBDM_NOMODULE XBDM_HRESERR(3) // _HRESULT_TYPEDEF_(0x82DA0003) // No such module exists. +#define XBDM_MEMUNMAPPED XBDM_HRESERR(4) // _HRESULT_TYPEDEF_(0x82DA0004) // The referenced memory has been unmapped. +#define XBDM_NOTHREAD XBDM_HRESERR(5) // _HRESULT_TYPEDEF_(0x82DA0005) // No such thread ID exists. +#define XBDM_CLOCKNOTSET XBDM_HRESERR(6) // _HRESULT_TYPEDEF_(0x82DA0006) // The console clock is not set. +#define XBDM_INVALIDCMD XBDM_HRESERR(7) // _HRESULT_TYPEDEF_(0x82DA0007) // An invalid command was specified. +#define XBDM_NOTSTOPPED XBDM_HRESERR(8) // _HRESULT_TYPEDEF_(0x82DA0008) // Thread not stopped. +#define XBDM_MUSTCOPY XBDM_HRESERR(9) // _HRESULT_TYPEDEF_(0x82DA0009) // File must be copied, not moved. +#define XBDM_ALREADYEXISTS XBDM_HRESERR(10) // _HRESULT_TYPEDEF_(0x82DA000A) // A file already exists with the same name. +#define XBDM_DIRNOTEMPTY XBDM_HRESERR(11) // _HRESULT_TYPEDEF_(0x82DA000B) // The directory is not empty. +#define XBDM_BADFILENAME XBDM_HRESERR(12) // _HRESULT_TYPEDEF_(0x82DA000C) // An invalid file name was specified. +#define XBDM_CANNOTCREATE XBDM_HRESERR(13) // _HRESULT_TYPEDEF_(0x82DA000D) // Cannot create the specified file. +#define XBDM_CANNOTACCESS XBDM_HRESERR(14) // _HRESULT_TYPEDEF_(0x82DA000E) // Cannot access the specified file. +#define XBDM_DEVICEFULL XBDM_HRESERR(15) // _HRESULT_TYPEDEF_(0x82DA000F) // The device is full. +#define XBDM_NOTDEBUGGABLE XBDM_HRESERR(16) // _HRESULT_TYPEDEF_(0x82DA0010) // This title is not debuggable. +#define XBDM_BADCOUNTTYPE XBDM_HRESERR(17) // _HRESULT_TYPEDEF_(0x82DA0011) // The counter type is invalid. +#define XBDM_COUNTUNAVAILABLE XBDM_HRESERR(18) // _HRESULT_TYPEDEF_(0x82DA0012) // Counter data is not available. +#define XBDM_NOTLOCKED XBDM_HRESERR(20) // _HRESULT_TYPEDEF_(0x82DA0014) // The console is not locked. +#define XBDM_KEYXCHG XBDM_HRESERR(21) // _HRESULT_TYPEDEF_(0x82DA0015) // Key exchange is required. +#define XBDM_MUSTBEDEDICATED XBDM_HRESERR(22) // _HRESULT_TYPEDEF_(0x82DA0016) // A dedicated connection is required. +#define XBDM_INVALIDARG XBDM_HRESERR(23) // _HRESULT_TYPEDEF_(0x82DA0017) // The argument was invalid. +#define XBDM_PROFILENOTSTARTED XBDM_HRESERR(24) // _HRESULT_TYPEDEF_(0x82DA0018) // The profile is not started. +#define XBDM_PROFILEALREADYSTARTED XBDM_HRESERR(25) // _HRESULT_TYPEDEF_(0x82DA0019) // The profile is already started. +#define XBDM_ALREADYSTOPPED XBDM_HRESERR(26) // _HRESULT_TYPEDEF_(0x82DA001A) // The console is already in DMN_EXEC_STOP. +#define XBDM_FASTCAPNOTENABLED XBDM_HRESERR(27) // _HRESULT_TYPEDEF_(0x82DA001B) // FastCAP is not enabled. +#define XBDM_NOMEMORY XBDM_HRESERR(28) // _HRESULT_TYPEDEF_(0x82DA001C) // The Debug Monitor could not allocate memory. +#define XBDM_TIMEOUT XBDM_HRESERR(29) // _HRESULT_TYPEDEF_(0x82DA001D) // Initialization through DmStartProfiling has taken longer than allowed. +#define XBDM_NOSUCHPATH XBDM_HRESERR(30) // _HRESULT_TYPEDEF_(0x82DA001E) // The path was not found. +#define XBDM_INVALID_SCREEN_INPUT_FORMAT XBDM_HRESERR(31) // _HRESULT_TYPEDEF_(0x82DA001F) // The screen input format is invalid. +#define XBDM_INVALID_SCREEN_OUTPUT_FORMAT XBDM_HRESERR(32) // _HRESULT_TYPEDEF_(0x82DA0020) // The screen output format is invalid. +#define XBDM_CALLCAPNOTENABLED XBDM_HRESERR(33) // _HRESULT_TYPEDEF_(0x82DA0021) // CallCAP is not enabled. +#define XBDM_INVALIDCAPCFG XBDM_HRESERR(34) // _HRESULT_TYPEDEF_(0x82DA0022) // Both FastCAP and CallCAP are enabled in different modules. +#define XBDM_CAPNOTENABLED XBDM_HRESERR(35) // _HRESULT_TYPEDEF_(0x82DA0023) // Neither FastCAP nor CallCAP are enabled. +#define XBDM_TOOBIGJUMP XBDM_HRESERR(36) // _HRESULT_TYPEDEF_(0x82DA0024) // A branched to a section the instrumentation code failed. +#define XBDM_FIELDNOTPRESENT XBDM_HRESERR(37) // _HRESULT_TYPEDEF_(0x82DA0025) // A necessary field is not present in the header of Xbox 360 title. +#define XBDM_OUTPUTBUFFERTOOSMALL XBDM_HRESERR(38) // _HRESULT_TYPEDEF_(0x82DA0026) // Provided data buffer for profiling is too small. +#define XBDM_PROFILEREBOOT XBDM_HRESERR(39) // _HRESULT_TYPEDEF_(0x82DA0027) // The Xbox 360 console is currently rebooting. +#define XBDM_MAXDURATIONEXCEEDED XBDM_HRESERR(41) // _HRESULT_TYPEDEF_(0x82DA0029) // The maximum duration was exceeded. +#define XBDM_INVALIDSTATE XBDM_HRESERR(42) // _HRESULT_TYPEDEF_(0x82DA002A) // The current state of game controller automation is incompatible with the requested action. +#define XBDM_MAXEXTENSIONS XBDM_HRESERR(43) // _HRESULT_TYPEDEF_(0x82DA002B) // The maximum number of extensions are already used. +#define XBDM_PMCSESSIONALREADYACTIVE XBDM_HRESERR(44) // _HRESULT_TYPEDEF_(0x82DA002C) // The Performance Monitor Counters (PMC) session is already active. +#define XBDM_PMCSESSIONNOTACTIVE XBDM_HRESERR(45) // _HRESULT_TYPEDEF_(0x82DA002D) // The Performance Monitor Counters (PMC) session is not active. +#define XBDM_LINE_TOO_LONG XBDM_HRESERR(46) // _HRESULT_TYPEDEF_(0x82DA002E) // The string passed to a debug monitor function, such as DmSendCommand, was too long. The total length of a command string, which includes its null termination and trailing CR/LF must be less than or equal too 512 characters. +#define XBDM_D3D_DEBUG_COMMAND_NOT_IMPLEMENTED XBDM_HRESERR(0x50) // _HRESULT_TYPEDEF_(0x82DA0050) // The current application has an incompatible version of D3D. +#define XBDM_D3D_INVALID_SURFACE XBDM_HRESERR(0x51) // _HRESULT_TYPEDEF_(0x82DA0051) // The D3D surface is not currently valid. +#define XBDM_CANNOTCONNECT XBDM_HRESERR(0x100) // _HRESULT_TYPEDEF_(0x82DA0100) // Cannot connect to the target system. +#define XBDM_CONNECTIONLOST XBDM_HRESERR(0x101) // _HRESULT_TYPEDEF_(0x82DA0101) // The connection to the target system has been lost. +#define XBDM_FILEERROR XBDM_HRESERR(0x103) // _HRESULT_TYPEDEF_(0x82DA0103) // An unexpected file error has occurred. +#define XBDM_ENDOFLIST XBDM_HRESERR(0x104) // _HRESULT_TYPEDEF_(0x82DA0104) // Used by the DmWalkxxx functions to signal the end of a list. +#define XBDM_BUFFER_TOO_SMALL XBDM_HRESERR(0x105) // _HRESULT_TYPEDEF_(0x82DA0105) // The buffer referenced was too small to receive the requested data. +#define XBDM_NOTXBEFILE XBDM_HRESERR(0x106) // _HRESULT_TYPEDEF_(0x82DA0106) // The file specified is not a valid XBE. +#define XBDM_MEMSETINCOMPLETE XBDM_HRESERR(0x107) // _HRESULT_TYPEDEF_(0x82DA0107) // Not all requested memory could be written. +#define XBDM_NOXBOXNAME XBDM_HRESERR(0x108) // _HRESULT_TYPEDEF_(0x82DA0108) // No target system name has been set. +#define XBDM_NOERRORSTRING XBDM_HRESERR(0x109) // _HRESULT_TYPEDEF_(0x82DA0109) // There is no string representation of this error code. +#define XBDM_INVALIDSTATUS XBDM_HRESERR(0x10A) // _HRESULT_TYPEDEF_(0x82DA010A) // The Xbox 360 console returns an formatted status string following a command. When using the custom command processor (see DmRegisterCommandProcessor), it may indicate that console and PC code are not compatible. +#define XBDM_TASK_PENDING XBDM_HRESERR(0x150) // _HRESULT_TYPEDEF_(0x82DA0150) // A previous command is still pending. + +#define XBDM_CONNECTED XBDM_HRESSUCC(1) // _HRESULT_TYPEDEF_(0x02DA0001) // A connection has been successfully established. +#define XBDM_MULTIRESPONSE XBDM_HRESSUCC(2) // _HRESULT_TYPEDEF_(0x02DA0002) // One of the three types of continued transactions supported by DmRegisterCommandProcessor. +#define XBDM_BINRESPONSE XBDM_HRESSUCC(3) // _HRESULT_TYPEDEF_(0x02DA0003) // One of the three types of continued transactions supported by DmRegisterCommandProcessor. +#define XBDM_READYFORBIN XBDM_HRESSUCC(4) // _HRESULT_TYPEDEF_(0x02DA0004) // One of the three types of continued transactions supported by DmRegisterCommandProcessor. +#define XBDM_DEDICATED XBDM_HRESSUCC(5) // _HRESULT_TYPEDEF_(0x02DA0005) // A connection has been dedicated to a specific threaded command handler. +#define XBDM_PROFILERESTARTED XBDM_HRESSUCC(6) // _HRESULT_TYPEDEF_(0x02DA0006) // The profiling session has been restarted successfully. +#define XBDM_FASTCAPENABLED XBDM_HRESSUCC(7) // _HRESULT_TYPEDEF_(0x02DA0007) // Fast call-attribute profiling is enabled. +#define XBDM_CALLCAPENABLED XBDM_HRESSUCC(8) // _HRESULT_TYPEDEF_(0x02DA0008) // Calling call-attribute profiling is enabled. +#define XBDM_RESULTCODE XBDM_HRESSUCC(9) // _HRESULT_TYPEDEF_(0x02DA0009) // A result code. + +// Call-Attributed Profiler Support Function +DMHRAPI DmStartProfiling(LPCSTR szLogFileName, DWORD dwDataBufferSize); +DMHRAPI DmStopProfiling(VOID); +DMHRAPI DmAbortProfiling(VOID); +DMHRAPI DmIsFastCAPEnabled(VOID); +DMHRAPI DmSetProfilingOptions(DWORD dwFlags); + +// Flags for DmSetProfilingOptions +// Should the extra counter be recorded by DmStartProfiling +#define DM_PROFILE_FLAG_CAPTURE_PERFCOUNTER 0x00010000L +// DM_PROFILE_FLAG_CAPTURE_L2_MISSES is obsolete--use DM_PROFILE_FLAG_CAPTURE_PERFCOUNTER +#define DM_PROFILE_FLAG_CAPTURE_L2_MISSES DM_PROFILE_FLAG_CAPTURE_PERFCOUNTER +#define DM_PROFILE_FLAG_CAPTURE_CURRENT_HW_THREAD 0x00020000L + +// Which hardware threads should be recorded +#define DM_PROFILE_FLAG_HW_THREAD0 (1<<0) +#define DM_PROFILE_FLAG_HW_THREAD1 (1<<1) +#define DM_PROFILE_FLAG_HW_THREAD2 (1<<2) +#define DM_PROFILE_FLAG_HW_THREAD3 (1<<3) +#define DM_PROFILE_FLAG_HW_THREAD4 (1<<4) +#define DM_PROFILE_FLAG_HW_THREAD5 (1<<5) + +// If the extra counter is being recorded, which counter should it be? +// These enums must be used as parameters to DM_PROFILE_FLAG_PMC to +// align them properly. +typedef enum +{ + DM_PROFILE_PMC_L2 = 0, + + DM_PROFILE_PMC_DL1, + DM_PROFILE_PMC_IL1 , + DM_PROFILE_PMC_LHS, + DM_PROFILE_PMC_DERAT, + DM_PROFILE_PMC_IERAT, + DM_PROFILE_PMC_BRANCH, + + DM_PROFILE_PMC_UCODE, + DM_PROFILE_PMC_INSTR, + + DM_PROFILE_PMC_MISALIGNED, + DM_PROFILE_PMC_STQ_FULL, + + DM_PROFILE_PMC_DIVSQRT, + DM_PROFILE_PMC_DENORM, + DM_PROFILE_PMC_FPU_NAN, + DM_PROFILE_PMC_VMX_ABNORMAL, + + + DM_PROFILE_PMC_LAST +} eDM_PROFILE_PMC_SETUP; + +#define DM_PROFILE_PMC_SHIFT 6 + +#define DM_PROFILE_PMC_MASK ((0xF) << DM_PROFILE_PMC_SHIFT) +#define DM_PROFILE_FLAG_PMC(x) (((x) << DM_PROFILE_PMC_SHIFT) & DM_PROFILE_PMC_MASK) + +// E.g. to measure instruction L1 misses on threads 0 and 2: +// DWORD flags = DM_PROFILE_FLAG_CAPTURE_PERFCOUNTER | DM_PROFILE_FLAG_HW_THREAD2 | DM_PROFILE_FLAG_PMC(DM_PROFILE_PMC_IL1); +// DmSetProfilingOptions(flags); + +// +// PMCPB Support Functions +// + +#ifndef EPMCSETUP_DECLARED +#define EPMCSETUP_DECLARED +typedef enum _ePMCSetup +{ + PMC_SETUP_FIRST = 0, + + PMC_SETUP_OVERVIEW_PB0T0 =0, + PMC_SETUP_OVERVIEW_PB0T1, + PMC_SETUP_OVERVIEW_PB1T0, + PMC_SETUP_OVERVIEW_PB1T1, + PMC_SETUP_OVERVIEW_PB2T0, + PMC_SETUP_OVERVIEW_PB2T1, + + PMC_SETUP_OVERVIEW_PB0, // 6 + PMC_SETUP_OVERVIEW_PB1, + PMC_SETUP_OVERVIEW_PB2, + + PMC_SETUP_OVERVIEW_6THREADS, // 9 + + PMC_SETUP_INSTRUCTIONMIX_PB0T0, // 10 + PMC_SETUP_INSTRUCTIONMIX_PB0T1, + PMC_SETUP_INSTRUCTIONMIX_PB1T0, + PMC_SETUP_INSTRUCTIONMIX_PB1T1, + PMC_SETUP_INSTRUCTIONMIX_PB2T0, + PMC_SETUP_INSTRUCTIONMIX_PB2T1, + + PMC_SETUP_FLUSHREASONS_PB0T0, // 16 + PMC_SETUP_FLUSHREASONS_PB0T1, + PMC_SETUP_FLUSHREASONS_PB1T0, + PMC_SETUP_FLUSHREASONS_PB1T1, + PMC_SETUP_FLUSHREASONS_PB2T0, + PMC_SETUP_FLUSHREASONS_PB2T1, + + PMC_SETUP_VMXMIX_PB0T0, // 22 + PMC_SETUP_VMXMIX_PB0T1, + PMC_SETUP_VMXMIX_PB1T0, + PMC_SETUP_VMXMIX_PB1T1, + PMC_SETUP_VMXMIX_PB2T0, + PMC_SETUP_VMXMIX_PB2T1, + + PMC_SETUP_VMXFPU_PB0T0, // 28 + PMC_SETUP_VMXFPU_PB0T1, + PMC_SETUP_VMXFPU_PB1T0, + PMC_SETUP_VMXFPU_PB1T1, + PMC_SETUP_VMXFPU_PB2T0, + PMC_SETUP_VMXFPU_PB2T1, + + PMC_SETUP_FPU_PB0T0, // 34 + PMC_SETUP_FPU_PB0T1, + PMC_SETUP_FPU_PB1T0, + PMC_SETUP_FPU_PB1T1, + PMC_SETUP_FPU_PB2T0, + PMC_SETUP_FPU_PB2T1, + + PMC_SETUP_PREFETCH, // 40 + + // + // counters dealing with events that go to main memory + // + PMC_SETUP_MEMORY_LATENCY_PB0, // 41 + PMC_SETUP_MEMORY_LATENCY_PB1, + PMC_SETUP_MEMORY_LATENCY_PB2, + + PMC_SETUP_TLBS, // 44 + + PMC_SETUP_LAST +}ePMCSetup; +#endif + +// +// PFM Status register +// +// Read returns status - 0 no overflow since last READ +// 1 overflow since last READ +// Write sets overflow interrupt enable +// 0 interrupt disabled +// 1 interrupt enabled + +#ifndef PFMSTATUS_DECLARED +#define PFMSTATUS_DECLARED +// warning C4201: nonstandard extension used : nameless struct/union +#pragma warning(push) +#pragma warning(disable: 4201) +typedef union _PFMStatus +{ + struct + { + // status and interrupt enable bits + unsigned long SI0 : 1; + unsigned long SI1 : 1; + unsigned long SI2 : 1; + unsigned long SI3 : 1; + unsigned long SI4 : 1; + unsigned long SI5 : 1; + unsigned long SI6 : 1; + unsigned long SI7 : 1; + unsigned long SI8 : 1; + unsigned long SI9 : 1; + unsigned long SI10: 1; + unsigned long SI11: 1; + unsigned long SI12: 1; + unsigned long SI13: 1; + unsigned long SI14: 1; + unsigned long SI15: 1; + unsigned long SI16: 1; // interval timer + + unsigned long _padding0:15; // 17:63 + unsigned long _padding1:32; + }; + + unsigned __int64 asQW; +}PFMStatus; +#pragma warning(pop) +#endif + +#define PMC_SIMULTANEOUS_COUNTERS 16 +// +// PMCSTATE +// +// This is the state saved from the pfm block with PMCGetCounters +// The physical counters are 32bit, but we keep 64 bits so we can +// accumulate into this structure and use the same routines to dump +// them. +// +#ifndef PMCSTATE_DECLARED +#define PMCSTATE_DECLARED +typedef struct _PMCState +{ + unsigned long long pmc[PMC_SIMULTANEOUS_COUNTERS]; // pmc values + __int64 ticks; // timebase ticks measured + double interval; // core cycles measured (only 32b). + // if it overflows we switch to converting ticks. + PFMStatus pfmstatus; // overflow status + + // + // helpful values extracted by PMCDumpCountersVerbose + // + __int64 instrCount; +}PMCState, *PPMCState; +#endif + +// +// DmPMCInstallAndStart +// +// Install a particular PMC counter setup, reset and then start +// the counters. +// +// Wraps the calls to DmPMCInstallSetup, DmPMCResetCounters, +// DmPMCSetTriggerProcessor and DmPMCStart +// +DMHRAPI DmPMCInstallAndStart(ePMCSetup whichSetup); + +// +// DmPMCStopAndReport +// +// Stop the counters, report and uninstall the current setup +// +// Wraps the calls to DmPMCStop, DmPMCGetCounters, DmPMCDumpCountersVerbose +// and DmPMCUnInstallSetup +// +DMHRAPI DmPMCStopAndReport(VOID); + +// +// DmPMCInstallSetup +// +// Acquires the performance monitor, takes a setup configuration and +// applies it to the entire CPU. +// Make sure to call DmUnInstallSetup to release the performance monitor +// for use by another application or API. +DMHRAPI DmPMCInstallSetup(ePMCSetup setup); + +// +// DmPMCUnInstallSetup +// +// Releases the performance monitor for use by another application +// +VOID DmPMCUnInstallSetup(VOID); + +// +// DmPMCResetCounters +// +// Resets the PMCs, the interval timer (including interval +// reload register). Also clears all status bits. +// +DMHRAPI DmPMCResetCounters(VOID); + +// +// DmPMCSetTriggerProcessor +// +// For simplicity's sake, we can just let one processor control the triggers +// This API selects which physical processor gets to control the triggers. +// +DMHRAPI DmPMCSetTriggerProcessor(ULONG processor); + +// +// DmPMCStart +// +// Start the counters +// +DMHRAPI DmPMCStart(VOID); + +// +// DmPMCStop +// +// Stop counters +// +DMHRAPI DmPMCStop(VOID); + +// +// DmPMCGetCounter +// +// Get single counter value +// +DMHRAPI DmPMCGetCounter(ULONG reg, ULONG *counterValue); + +// +// DmPMCGetCounters +// +// Populates the PMCState structure provided +// Assumes the counters are STOPPED with DmPMCStop +// +DMHRAPI DmPMCGetCounters(PPMCState pmcstate); + +// +// DmPMCGetCounterName +// +// Returns name of specified counter from current setup. counterNumber +// must be a number from 0 to 15. +// +const char* DmPMCGetCounterName(int counterNumber); + +// +// DmPMCDumpCounters +// +// Barebones dump of pmcstate. For friendlier output (incl. event names) +// use DmPMCDumpCountersVerbose. +// +VOID DmPMCDumpCounters(PPMCState pmcstate); + +// +// DmPMCDumpCountersVerbose +// +// Friendly dump with counter event printed. +// +#define PMC_VERBOSE_NOL2ECC 0x1 +#define PMC_VERBOSE_NOFRAMERATE 0x2 +#define PMC_VERBOSE_NOTIME 0x4 +#define PMC_VERBOSE_MIN 0xFFFFFFFF +#define PMC_VERBOSE_MAX 0x0 + +VOID DmPMCDumpCountersVerbose(PPMCState pmcstate, ULONG verbosity); + +// +// DmPMCGetCounterCostEstimate +// +// Returns an estimate for the typical cost of the specified counter +// For instance, a pipeline flush is estimated at 40 cycles, and +// an L2 cache miss is estimated at 685 cycles. These estimates are +// sometimes not very accurate and are not always meaningful, but they +// can be useful to give a rough estimate of how much time a particular +// event type is wasting. counterNumber must be a number from 0 to 15. +// +int DmPMCGetCounterCostEstimate(int counterNumber); + +// The counters in PMC setups can come from one of seven sources -- the +// six hardware threads or the L2/memory subsystem. +#ifndef PMCCOUNTERSOURCE_DECLARED +#define PMCCOUNTERSOURCE_DECLARED +typedef enum _PMCCounterSource +{ + PMC_PB0T0, + PMC_PB0T1, + PMC_PB1T0, + PMC_PB1T1, + PMC_PB2T0, + PMC_PB2T1, + PMC_PMW, + PMC_unknown, + PMC_count +} PMCCounterSource; +#endif + +// +// DmPMCGetCounterSource +// +// Returns the source unit for the specified counter. This is necessary +// in order to distinguish counters that can be measured on any +// thread/core. counterNumber must be a number from 0 to 15. +// +PMCCounterSource DmPMCGetCounterSource(int counterNumber); + +// +// DmPMCComputeFrequency +// +// Returns the core frequency, which is 3200000000 except for +// pre-release kits. +// +// Do not call this from within a DmPMCInstallSetup/DmPMCUnInstallSetup, +// since this functions can not be nested. +// +__int64 DmPMCComputeFrequency(); + +// PoGO Support Functions + +/* +DmPgo{Start|Stop}DataCollection - enables/disables PGO data collection. +This does not affect the instrumentation itself. The instrumentation will +still execute, but it will not save any results. This is intended to be used +to scope the profiling data to useful scenarios, and not to throttle +performance. This may be called in response to DM_PGO_MODULE_STARTUP to +specify that data collection should be initially disabled. + +hPgoModule - specifies module to control data collection. If NULL, controls +all loaded modules. +*/ +DMHRAPI DmPgoStartDataCollection (HPGOMODULE hPgoModule); +DMHRAPI DmPgoStopDataCollection (HPGOMODULE hPgoModule); + +/* +DmPgoSaveSnapshot - saves a snapshot of the current PGO instrumentation +data for the caller's module to a new file. A unique filename will be chosen +by appending a number to the filename. + +pszPhase - string to append to the filename. If NULL, no string is appended. + +fReset - if TRUE, resets all profiling counters + +hPgoModule - specifies module to save snapshot. If NULL, save a snapshot for +every loaded module. +*/ +DMHRAPI DmPgoSaveSnapshot ( + PCSTR pszPhase, + BOOL fReset, + HPGOMODULE hPgoModule); + +/* +DmPgoSetAllocScale - sets the buffer size multiplier. This function may +only be called in response to DM_PGO_MODULE_STARTUP. + +dwBufferAllocScale - specifies the buffer size multiplier. The actual +allocated size of the profiling data buffer is the default size times this +value. If the multiplier is 0, or if there is insufficient memory for the +computed size, the default size will be used. +*/ +DMHRAPI DmPgoSetAllocScale ( + HPGOMODULE hPgoModule, + DWORD dwBufferAllocScale); + + +#ifndef XBDM_STATIC_LIB +DMHRAPI DmTranslateErrorA(HRESULT hr, LPSTR lpBuffer, int nBufferMax); +DMHRAPI DmTranslateErrorW(HRESULT hr, LPWSTR lpBuffer, int nBufferMax); +#ifdef UNICODE +#define DmTranslateError DmTranslateErrorW +#else +#define DmTranslateError DmTranslateErrorA +#endif // !UNICODE +#endif //XBDM_STATIC_LIB + + + +// +// Allocation tracking types and definitions +// + +#define DM_TRACK_HEAP 0x0001 +#define DM_TRACK_VIRTUAL_MEMORY 0x0002 +#define DM_TRACK_CONTIGUOUS_MEMORY 0x0004 +#define DM_TRACK_SYSTEM_MEMORY 0x0008 +#define DM_TRACK_DEBUG_MEMORY 0x0010 +#define DM_TRACK_KERNEL_POOL 0x0020 +#define DM_TRACK_HANDLE 0x0040 +#define DM_TRACK_CUSTOM 0x0080 +#define DM_TRACK_TYPEMASK 0x00FF +#define DM_TRACK_ASSERT_ON_FAILURES 0x0100 +#define DM_TRACK_MASK 0x01FF + +DMHRAPI DmQueryAllocationTypeName(USHORT AllocationType, LPSTR pszName, SIZE_T nSize); + + +typedef enum _X_RUNTIME_FUNCTION_TYPE { + XFunctionTypeSaveMillicode, + XFunctionTypeNoHandler, + XFunctionTypeRestoreMillicode, + XFunctionTypeHandler, +} X_RUNTIME_FUNCTION_TYPE; + +typedef struct _X_RUNTIME_FUNCTION { + ULONG BeginAddress; + ULONG FunctionType : 2; + ULONG FunctionLength : 22; + ULONG PrologLength : 8; +} X_RUNTIME_FUNCTION, * PX_RUNTIME_FUNCTION; + +typedef struct _X_STACK_FRAME +{ + XCONTEXT FrameContext; // RegisterContext + BOOL fHasFunctionEntry; + X_RUNTIME_FUNCTION FunctionEntry; +} X_STACK_FRAME, *PX_STACK_FRAME; + + + + + +// +// Symbol APIs +// + +typedef struct _DM_PDB_SIGNATURE { + GUID Guid; + DWORD Age; + CHAR Path[MAX_PATH]; +} DM_PDB_SIGNATURE, *PDM_PDB_SIGNATURE; + +DMHRAPI +DmFindPdbSignature( + IN PVOID BaseAddress, + OUT PDM_PDB_SIGNATURE PdbSignature + ); + + +// +// Get the path of the XDK installed symbol server +// that contains system symbols. +// + +DMHRAPI +DmGetSystemSymbolServerPathA( + OUT LPSTR szSymbolServerPath, + IN OUT DWORD *pcchSymbolServerPath + ); +DMHRAPI +DmGetSystemSymbolServerPathW( + OUT LPWSTR szSymbolServerPath, + IN OUT DWORD *pcchSymbolServerPath + ); +#ifdef UNICODE +#define DmGetSystemSymbolServerPath DmGetSystemSymbolServerPathW +#else +#define DmGetSystemSymbolServerPath DmGetSystemSymbolServerPathA +#endif // !UNICODE + +// +// DmLoadSymbolsForModule and DmLoadSymbolsForModuleEx +// +// This API loads PDB symbol for the module specified by ModuleName. +// + +DMHRAPI +DmLoadSymbolsForModule( + IN CONST CHAR* ModuleName, + IN PVOID BaseAddress, + IN SIZE_T Size, + IN ULONG TimeStamp + ); + +DMHRAPI +DmLoadSymbolsForModuleEx( + IN CONST CHAR* ModuleName, + IN PVOID BaseAddress, + IN SIZE_T Size, + IN ULONG TimeStamp, + IN CONST DM_PDB_SIGNATURE* PdbSignature + ); + +// +// DmUnloadSymbolsForModule +// +// This API unloads the symbol table +// + +DMHRAPI +DmUnloadSymbolsForModule( + IN ULONG_PTR BaseAddress + ); + +// +// DmLoadSymbolsForAllLoadedModules +// +// This API enumerates all loaded modules and load symbols for each one of them +// It is equipvalent to call DmWalkLoadedModules and call DmLoadSymbolsForModule +// for each module. +// + +DMHRAPI +DmLoadSymbolsForAllLoadedModules( + VOID + ); + +// +// DmGetSymbolFromAddress +// +// This API similar to SymGetSymFromAddr64. It locates the symbol for +// specified address. +// + +DMHRAPI +DmGetSymbolFromAddress( + IN ULONG_PTR Address, + OUT CHAR* SymbolName, + IN SIZE_T BufferSize, + OUT PULONG Displacement OPTIONAL + ); + +// +// DmGetSourceLineFromAddress +// +// This API similar to SymGetLineFromAddr64. It locates the source file and line +// number for specified address. +// + +DMHRAPI +DmGetSourceLineFromAddress( + IN ULONG_PTR Address, + OUT CHAR* FileName, + IN SIZE_T BufferSize, + OUT PULONG LineNumber + ); + +// +// DmSetSymbolSearchPath +// +// This API allow user to add additional symbol search paths +// + +DMHRAPI +DmSetSymbolSearchPath( + IN LPCTSTR lpszPath + ); + +// Constants for gamepad buttons +#define DM_XINPUT_GAMEPAD_DPAD_UP 0x0001 +#define DM_XINPUT_GAMEPAD_DPAD_DOWN 0x0002 +#define DM_XINPUT_GAMEPAD_DPAD_LEFT 0x0004 +#define DM_XINPUT_GAMEPAD_DPAD_RIGHT 0x0008 +#define DM_XINPUT_GAMEPAD_START 0x0010 +#define DM_XINPUT_GAMEPAD_BACK 0x0020 +#define DM_XINPUT_GAMEPAD_LEFT_THUMB 0x0040 +#define DM_XINPUT_GAMEPAD_RIGHT_THUMB 0x0080 +#define DM_XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100 +#define DM_XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200 +#define DM_XINPUT_GAMEPAD_A 0x1000 +#define DM_XINPUT_GAMEPAD_B 0x2000 +#define DM_XINPUT_GAMEPAD_X 0x4000 +#define DM_XINPUT_GAMEPAD_Y 0x8000 + +#define DM_XINPUT_GAMEPAD_SYSTEM_BUTTON_X360 0x0400 +#define DM_XINPUT_GAMEPAD_SYSTEM_BUTTON_BIND 0x0800 + +typedef struct _DM_XINPUT_GAMEPAD +{ + WORD wButtons; + BYTE bLeftTrigger; + BYTE bRightTrigger; + SHORT sThumbLX; + SHORT sThumbLY; + SHORT sThumbRX; + SHORT sThumbRY; +} DM_XINPUT_GAMEPAD, *PDM_XINPUT_GAMEPAD; + + +// +// maximum size of a remoted controller packet. 32 would probably +// suffice, if we were limited to physical packets, but we could be +// trying to represent expanded packets or conglomerated ones (e.g., +// from multiplexed fields over multiple packets), so larger here is +// better +// +// TODO: make this completely dynamic in dmautomate.c +// +// +//#define DM_MAX_XINPUT_CONTROLLER_ENTRY_SIZE 64 + +//typedef struct _DM_XINPUT_CONTROLLER +//{ +// union +// { +// DM_XINPUT_GAMEPAD Gamepad; +// BYTE Filler[DM_MAX_XINPUT_CONTROLLER_ENTRY_SIZE]; +// }; +//} DM_XINPUT_CONTROLLER, *PDM_XINPUT_CONTROLLER; + +// +// DmAutomation Support +// +// TODO: handle device categories (DM_XUSER_MAX_COUNT times number of +// device categories, like voice, mics, etc.) +// + +#define DM_XUSER_MAX_COUNT 4 + +DMHRAPI +DmAutomationGetInputProcess ( + IN DWORD dwUserIndex, + OUT BOOL* pfSystemProcess + ); + +DMHRAPI +DmAutomationBindController( + IN DWORD dwUserIndex, + IN DWORD dwQueueLength + ); + +DMHRAPI +DmAutomationUnbindController( + IN DWORD dwUserIndex + ); + +DMHRAPI +DmAutomationConnectController( + IN DWORD dwUserIndex + ); + +//DMHRAPI +//DmAutomationConnectControllerEx( +// IN DWORD dwUserIndex, +// IN DWORD dwDeviceType, +// IN DWORD dwDeviceSubType, +// IN PVOID pDeviceTable, +// IN DWORD dwDeviceTableSize +// ); + +DMHRAPI +DmAutomationDisconnectController( + IN DWORD dwUserIndex + ); + +DMHRAPI +DmAutomationSetGamepadState( + IN DWORD dwUserIndex, + IN PDM_XINPUT_GAMEPAD pXGamepad + ); + +DMHRAPI +DmAutomationQueueGamepadState( + IN DWORD dwUserIndex, + IN PDM_XINPUT_GAMEPAD pGamepadArray, + IN PDWORD pdwTimedDurationArray OPTIONAL, + IN PDWORD pdwCountDurationArray OPTIONAL, + IN DWORD dwItemCount, + OUT PDWORD pdwItemsAddedToQueue + ); + +//DMHRAPI +//DmAutomationQueueGamepadStateEx( +// IN DWORD dwUserIndex, +// IN PVOID pInputArray, +// IN PDWORD pdwTimedDurationArray OPTIONAL, +// IN PDWORD pdwCountDurationArray OPTIONAL, +// IN DWORD dwItemCount, +// IN DWORD dwItemSize, +// OUT PDWORD pdwItemsAddedToQueue +// ); + +DMHRAPI +DmAutomationClearGamepadQueue ( + IN DWORD dwUserIndex + ); + +DMHRAPI +DmAutomationQueryGamepadQueue( + IN DWORD dwUserIndex, + OUT PDWORD pdwQueueLength OPTIONAL, + OUT PDWORD pdwItemsInQueue OPTIONAL, + OUT PDWORD pdwTimedDurationRemaining OPTIONAL, + OUT PDWORD pdwCountDurationRemaining OPTIONAL + ); + +typedef unsigned __int64 DM_XUID, *PDM_XUID; + +DMHRAPI +DmAutomationGetUserDefaultProfile( + OUT PDM_XUID pXuid + ); + +DMHRAPI +DmAutomationSetUserDefaultProfile( + DM_XUID xuid + ); + + +DMHRAPI +DmGetAdditionalTitleMemorySetting( + OUT PDWORD pdwAdditionalTitleMemory + ); + +DMHRAPI +DmGetDebugMemorySize( + OUT PDWORD pdwDebugMemorySize + ); + +#define DM_CONSOLEMEMCONFIG_NOADDITIONALMEM 0 +#define DM_CONSOLEMEMCONFIG_ADDITIONALMEMDISABLED 1 +#define DM_CONSOLEMEMCONFIG_ADDITIONALMEMENABLED 2 + +DMHRAPI +DmGetConsoleDebugMemoryStatus( + OUT PDWORD pdwConsoleMemConfig + ); + + +#ifdef __cplusplus +} +#endif + + +#endif //__XBDM_H__ diff --git a/third_party/xbox_sdk/include/xboxmath.h b/third_party/xbox_sdk/include/xboxmath.h new file mode 100644 index 0000000..bed2c2d --- /dev/null +++ b/third_party/xbox_sdk/include/xboxmath.h @@ -0,0 +1,97 @@ +/*++ + +Copyright (c) Microsoft Corporation. All rights reserved. + +Module Name: + + xboxmath.h + +Abstract: + + Xbox math general library interface to XNA Math +--*/ + +#pragma once + +#ifndef __XBOXMATH2_H__ +#define __XBOXMATH2_H__ + +#if defined(_VMX1_INTRINSICS_) || defined(_VMX32_INTRINSICS_) +#error XNA math does not support VMX1 or VMX32 +#endif + +#ifdef _NO_INTRINSICS_ +#define _XM_NO_INTRINSICS_ +#endif + +#ifdef _VMX128_INTRINSICS_ +#define _XM_VMX128_INTRINSICS_ +#endif + +#ifdef _NOALIGNMENT_ +#define XM_NO_ALIGNMENT +#endif + +#include "xnamath.h" + +/**************************************************************************** + * + * Compatibility types + * + ****************************************************************************/ + +typedef XMFLOAT2A XMFLOAT2A16; +typedef XMFLOAT3A XMFLOAT3A16; +typedef XMFLOAT4A XMFLOAT4A16; +typedef XMFLOAT4X3A XMFLOAT4X3A16; +typedef XMFLOAT4X4A XMFLOAT4X4A16; + +typedef XMVECTORU32 XMVECTORI; + +/**************************************************************************** + * + * Compatibility aliases + * + ****************************************************************************/ + +XMFINLINE XMVECTOR XMLoadScalar(CONST VOID* pSource) { return XMLoadFloat((CONST FLOAT*)pSource); } +XMFINLINE XMVECTOR XMLoadVector2(CONST VOID* pSource) { return XMLoadFloat2((CONST XMFLOAT2*)pSource); } +XMFINLINE XMVECTOR XMLoadVector2A(CONST VOID* pSource) { return XMLoadFloat2A((CONST XMFLOAT2A*)pSource); } +XMFINLINE XMVECTOR XMLoadVector3(CONST VOID* pSource) { return XMLoadFloat3((CONST XMFLOAT3*)pSource); } +XMFINLINE XMVECTOR XMLoadVector3A(CONST VOID* pSource) { return XMLoadFloat3A((CONST XMFLOAT3A*)pSource); } +XMFINLINE XMVECTOR XMLoadVector4(CONST VOID* pSource) { return XMLoadFloat4((CONST XMFLOAT4*)pSource); } +XMFINLINE XMVECTOR XMLoadVector4A(CONST VOID* pSource) { return XMLoadFloat4A((CONST XMFLOAT4A*)pSource); } + +XMFINLINE XMVECTOR XMLoadVector2A16(CONST VOID* pSource) { return XMLoadVector2A(pSource); } +XMFINLINE XMVECTOR XMLoadVector3A16(CONST VOID* pSource) { return XMLoadVector3A(pSource); } +XMFINLINE XMVECTOR XMLoadVector4A16(CONST VOID* pSource) { return XMLoadVector4A(pSource); } + +XMFINLINE XMVECTOR XMLoadFloat2A16(CONST XMFLOAT2A16* pSource) { return XMLoadFloat2A(pSource); } +XMFINLINE XMVECTOR XMLoadFloat3A16(CONST XMFLOAT3A16* pSource) { return XMLoadFloat3A(pSource); } +XMFINLINE XMVECTOR XMLoadFloat4A16(CONST XMFLOAT4A16* pSource) { return XMLoadFloat4A(pSource); } +XMFINLINE XMMATRIX XMLoadFloat4x3A16(CONST XMFLOAT4X3A16* pSource) { return XMLoadFloat4x3A(pSource); } +XMFINLINE XMMATRIX XMLoadFloat4x4A16(CONST XMFLOAT4X4A16* pSource) { return XMLoadFloat4x4A(pSource); } + +XMFINLINE VOID XMStoreScalar(VOID* pDestination, FXMVECTOR V) { XMStoreFloat((FLOAT*)pDestination, V); } +XMFINLINE VOID XMStoreVector2(VOID* pDestination, FXMVECTOR V) { XMStoreFloat2((XMFLOAT2*)pDestination, V); } +XMFINLINE VOID XMStoreVector2A(VOID* pDestination, FXMVECTOR V) { XMStoreFloat2A((XMFLOAT2A*)pDestination, V); } +XMFINLINE VOID XMStoreVector3(VOID* pDestination, FXMVECTOR V) { XMStoreFloat3((XMFLOAT3*)pDestination, V); } +XMFINLINE VOID XMStoreVector3A(VOID* pDestination, FXMVECTOR V) { XMStoreFloat3A((XMFLOAT3A*)pDestination, V); } +XMFINLINE VOID XMStoreVector4(VOID* pDestination, FXMVECTOR V) { XMStoreFloat4((XMFLOAT4*)pDestination, V); } +XMFINLINE VOID XMStoreVector4A(VOID* pDestination, FXMVECTOR V) { XMStoreFloat4A((XMFLOAT4A*)pDestination, V); } +XMFINLINE VOID XMStoreVector4NC(VOID* pDestination, FXMVECTOR V) { XMStoreFloat4NC((XMFLOAT4*)pDestination, V); } + +XMFINLINE VOID XMStoreVector2A16(VOID* pDestination, FXMVECTOR V) { XMStoreVector2A(pDestination, V); } +XMFINLINE VOID XMStoreVector3A16(VOID* pDestination, FXMVECTOR V) { XMStoreVector3A(pDestination, V); } +XMFINLINE VOID XMStoreVector4A16(VOID* pDestination, FXMVECTOR V) { XMStoreVector4A(pDestination, V); } + +XMFINLINE VOID XMStoreFloat2A16(XMFLOAT2A16* pDestination, FXMVECTOR V) { XMStoreFloat2A(pDestination, V); } +XMFINLINE VOID XMStoreFloat3A16(XMFLOAT3A16* pDestination, FXMVECTOR V) { XMStoreFloat3A(pDestination, V); } +XMFINLINE VOID XMStoreFloat4A16(XMFLOAT4A16* pDestination, FXMVECTOR V) { XMStoreFloat4A(pDestination, V); } +XMFINLINE VOID XMStoreFloat4x3A16(XMFLOAT4X3A16* pDestination, CXMMATRIX M) { XMStoreFloat4x3A(pDestination, M); } +XMFINLINE VOID XMStoreFloat4x4A16(XMFLOAT4X4A16* pDestination, CXMMATRIX M) { XMStoreFloat4x4A(pDestination, M); } + +XMFINLINE XMVECTOR XMVectorMinimize(FXMVECTOR V1, FXMVECTOR V2) { return XMVectorMin(V1, V2); } +XMFINLINE XMVECTOR XMVectorMaximize(FXMVECTOR V1, FXMVECTOR V2) { return XMVectorMax(V1, V2); } + +#endif // __XBOXMATH2_H__ diff --git a/third_party/xbox_sdk/include/xcompress.h b/third_party/xbox_sdk/include/xcompress.h new file mode 100644 index 0000000..56dc05d --- /dev/null +++ b/third_party/xbox_sdk/include/xcompress.h @@ -0,0 +1,310 @@ +/************************************************************************ +* * +* xcompress.h -- This module defines the Xbox Compression APIs * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ +#pragma once + +#ifndef _XCOMPRESS_H_ +#define _XCOMPRESS_H_ + +#include +#include + +#ifndef XBOXAPI +#define XBOXAPI +#endif + +#ifdef __cplusplus +#define XCTDEXTERN extern "C" +#else +#define XCTDEXTERN extern +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +#pragma warning(push) +#pragma warning(disable: 4200) // zero-sized array + +typedef enum _XMEMCODEC_TYPE +{ + XMEMCODEC_DEFAULT = 0, + XMEMCODEC_LZX = 1 +} XMEMCODEC_TYPE; + +/* + * Data compression flags + */ + +#define XMEMCOMPRESS_STREAM 0x00000001 + +/* + * Data compression functions + */ + +typedef VOID* XMEMCOMPRESSION_CONTEXT; + +XBOXAPI +HRESULT +WINAPI +XMemCreateCompressionContext( + __in XMEMCODEC_TYPE CodecType, + __in_opt CONST VOID* pCodecParams, + __in DWORD Flags, + __deref_out XMEMCOMPRESSION_CONTEXT* pContext + ); + +XBOXAPI +XMEMCOMPRESSION_CONTEXT +WINAPI +XMemInitializeCompressionContext( + __in XMEMCODEC_TYPE CodecType, + __in_opt CONST VOID* pCodecParams, + __in DWORD Flags, + __out_bcount(ContextSize) VOID* pContextData, + __in SIZE_T ContextSize + ); + +XBOXAPI +VOID +WINAPI +XMemDestroyCompressionContext( + __in XMEMCOMPRESSION_CONTEXT Context + ); + +XBOXAPI +SIZE_T +WINAPI +XMemGetCompressionContextSize( + __in XMEMCODEC_TYPE CodecType, + __in_opt CONST VOID* pCodecParams, + __in DWORD Flags + ); + +XBOXAPI +HRESULT +WINAPI +XMemResetCompressionContext( + __in XMEMCOMPRESSION_CONTEXT Context); + +XBOXAPI +HRESULT +WINAPI +XMemCompress( + __in XMEMCOMPRESSION_CONTEXT Context, + __out_bcount_opt( *pDestSize ) VOID* pDestination, + __inout SIZE_T* pDestSize, + __in_bcount( SrcSize ) CONST VOID* pSource, + __in SIZE_T SrcSize + ); + +XBOXAPI +HRESULT +WINAPI +XMemCompressStream( + __in XMEMCOMPRESSION_CONTEXT Context, + __out_bcount_opt( *pDestSize ) VOID* pDestination, + __inout SIZE_T* pDestSize, + __in_bcount( *pSrcSize ) CONST VOID* pSource, + __inout SIZE_T* pSrcSize + ); + +/* + * Data decompression functions + */ + +typedef VOID* XMEMDECOMPRESSION_CONTEXT; + +XBOXAPI +HRESULT +WINAPI +XMemCreateDecompressionContext( + __in XMEMCODEC_TYPE CodecType, + __in_opt CONST VOID* pCodecParams, + __in DWORD Flags, + __deref_out XMEMDECOMPRESSION_CONTEXT* pContext + ); + +XBOXAPI +XMEMDECOMPRESSION_CONTEXT +WINAPI +XMemInitializeDecompressionContext( + __in XMEMCODEC_TYPE CodecType, + __in_opt CONST VOID* pCodecParams, + __in DWORD Flags, + __out_bcount( ContextSize ) VOID* pContextData, + __in SIZE_T ContextSize + ); + +XBOXAPI +VOID +WINAPI +XMemDestroyDecompressionContext( + __in XMEMDECOMPRESSION_CONTEXT Context + ); + +XBOXAPI +SIZE_T +WINAPI +XMemGetDecompressionContextSize( + __in XMEMCODEC_TYPE CodecType, + __in_opt CONST VOID* pCodecParams, + __in DWORD Flags + ); + +XBOXAPI +HRESULT +WINAPI +XMemResetDecompressionContext( + __in XMEMDECOMPRESSION_CONTEXT Context); + +XBOXAPI +HRESULT +WINAPI +XMemDecompress( + __in XMEMDECOMPRESSION_CONTEXT Context, + __out_bcount( *pDestSize ) VOID* pDestination, + __inout SIZE_T* pDestSize, + __in_bcount( SrcSize) CONST VOID* pSource, + __in SIZE_T SrcSize + ); + +XBOXAPI +HRESULT +WINAPI +XMemDecompressStream( + __in XMEMDECOMPRESSION_CONTEXT Context, + __out_bcount( *pDestSize ) VOID* pDestination, + __inout SIZE_T* pDestSize, + __in_bcount( *pSrcSize ) CONST VOID* pSource, + __inout SIZE_T* pSrcSize + ); + +/* + * LZX codec for lossless compression + */ + +typedef struct _XMEMCODEC_PARAMETERS_LZX +{ + DWORD Flags; + DWORD WindowSize; + DWORD CompressionPartitionSize; +} XMEMCODEC_PARAMETERS_LZX; + +#define XCOMPRESS_LZX_BLOCK_SIZE (32 * 1024) +#define XCOMPRESS_LZX_BLOCK_GROWTH_SIZE_MAX 6155 + +/* + * Error codes + */ + +#define XMCDERR_MOREDATA _HRESULT_TYPEDEF_(0x81DE2001) + +/* + * Transparent decoding + */ + +#if defined(_M_PPCBE) + +typedef struct _XTDECODER_PARAMETERS +{ + XMEMCODEC_TYPE CodecType; + CONST VOID* pCodecParams; + DWORD Flags; + DWORD HardwareThread; + INT ThreadPriority; + DWORD SegmentSizeLimit; + DWORD PendingReadLimit; + DWORD OpenFileLimit; + DWORD TranslationCacheSize; +} XTDECODER_PARAMETERS; + +/* + * Transparent decoding flags + */ + +#define XTDECODER_NO_READ_ALIGNMENT_ENFORCEMENT 0x00000001 + +/* + * Transparent decoding global which, when set to TRUE before transparent + * decompression has been enabled, will force an explicit examination (read) + * of all files when created to determine their compression state (ignoring + * the presence or absence of the GDF compressed attribute bit). Use of this + * global should be done for debugging purposes only. + */ + +XCTDEXTERN BOOL XCTD__ProbeFileCompressionState; + +/* + * Transparent decoding functions + */ + +XBOXAPI +HRESULT +WINAPI +XFileEnableTransparentDecompression( + __in_opt CONST XTDECODER_PARAMETERS* pDecoderParams + ); + +XBOXAPI +VOID +WINAPI +XFileDisableTransparentDecompression(); + +#endif + +/* + * Compression file headers + */ + +#define XCOMPRESS_FILE_IDENTIFIER_LZXTDECODE 0x0FF512ED +#define XCOMPRESS_FILE_IDENTIFIER_LZXNATIVE 0x0FF512EE + +#define XCOMPRESS_SET_FILE_VERSION(Major, Minor) ((((Major) & 0xFF) << 8) | ((Minor) & 0xFF)) +#define XCOMPRESS_GET_FILE_VERSION_MAJOR(Version) (((Version) >> 8) & 0xFF) +#define XCOMPRESS_GET_FILE_VERSION_MINOR(Version) ((Version) & 0xFF) + +#define XCOMPRESS_LZXTDECODE_VERSION_MAJOR 1 +#define XCOMPRESS_LZXTDECODE_VERSION_MINOR 0 + +#define XCOMPRESS_LZXNATIVE_VERSION_MAJOR 1 +#define XCOMPRESS_LZXNATIVE_VERSION_MINOR 3 + +typedef struct _XCOMPRESS_FILE_HEADER +{ + DWORD Identifier; + WORD Version; + WORD Reserved; +} XCOMPRESS_FILE_HEADER; + +typedef struct _XCOMPRESS_FILE_HEADER_LZXNATIVE +{ + XCOMPRESS_FILE_HEADER Common; + DWORD ContextFlags; + XMEMCODEC_PARAMETERS_LZX CodecParams; + DWORD UncompressedSizeHigh; + DWORD UncompressedSizeLow; + DWORD CompressedSizeHigh; + DWORD CompressedSizeLow; + DWORD UncompressedBlockSize; + DWORD CompressedBlockSizeMax; +} XCOMPRESS_FILE_HEADER_LZXNATIVE; + +typedef struct _XCOMPRESS_BLOCK_HEADER_LZXNATIVE +{ + DWORD CompressedBlockSize; + BYTE pCompressedData[0]; +} XCOMPRESS_BLOCK_HEADER_LZXNATIVE; + +#pragma warning(pop) + +#ifdef __cplusplus +} +#endif + +#endif /* _XCOMPRESS_H_ */ diff --git a/third_party/xbox_sdk/include/xdk.h b/third_party/xbox_sdk/include/xdk.h new file mode 100644 index 0000000..f9ed203 --- /dev/null +++ b/third_party/xbox_sdk/include/xdk.h @@ -0,0 +1,21 @@ +/*++ BUILD Version: 0000 Increment this if a change has global effects + +Copyright (c) Microsoft Corporation. All rights reserved. + +Module Name: + + xdk.h + +Abstract: + + Defines the version of the XDK + +Revision History: + +--*/ +#ifndef _XDK_ +#define _XDK_ + +#define _XDK_VER 21256 + +#endif /* _XDK_ */ diff --git a/third_party/xbox_sdk/include/xectx.h b/third_party/xbox_sdk/include/xectx.h new file mode 100644 index 0000000..d95c9b9 --- /dev/null +++ b/third_party/xbox_sdk/include/xectx.h @@ -0,0 +1,408 @@ + + +/*++ + +Copyright (c) IBM Corporation. All rights reserved. +Copyright (c) Microsoft Corporation. All rights reserved. + +Module Name: + + XeCtx.h + +Abstract: + + User-mode visible PowerPC (Xenon) specific structures and constants + +--*/ + +#ifndef _XE_CTX_ +#define _XE_CTX_ +#if _MSC_VER > 1000 +#pragma once +#endif + +#ifdef __cplusplus +extern "C" { +#endif +// +// The following flags control the contents of the XCONTEXT structure. +// + +#if !defined(RC_INVOKED) + +#define XCONTEXT_CONTROL 0x00000001L +#define XCONTEXT_FLOATING_POINT 0x00000002L +#define XCONTEXT_INTEGER 0x00000004L +#define XCONTEXT_VECTOR 0x00000010L +#define XCONTEXT_FULL (XCONTEXT_CONTROL | XCONTEXT_FLOATING_POINT | XCONTEXT_INTEGER | XCONTEXT_VECTOR) + +#endif + +// +// Xenon Context Frame - this is the CONTEXT structure on Xenon +// + +typedef struct _XCONTEXT { + + // + // The flags values within this flag control the contents of + // a CONTEXT record. + // + // If the context record is used as an input parameter, then + // for each portion of the context record controlled by a flag + // whose value is set, it is assumed that that portion of the + // context record contains valid context. If the context record + // is being used to modify a thread's context, then only that + // portion of the threads context will be modified. + // + // If the context record is used as an IN OUT parameter to capture + // the context of a thread, then only those portions of the thread's + // context corresponding to set flags will be returned. + // + // The context record is never used as an OUT only parameter. + // + + ULONG ContextFlags; + + // + // This section is specified/returned if the ContextFlags word contains + // the flag CONTEXT_CONTROL. + // + + ULONG Msr; // Machine status register + ULONG Iar; // Instruction address register + ULONG Lr; // Link register + ULONGLONG Ctr; // Count register + + // + // This section is specified/returned if the ContextFlags word contains + // the flag CONTEXT_INTEGER. + // + + ULONGLONG Gpr0; // General registers 0..31 + ULONGLONG Gpr1; + ULONGLONG Gpr2; + ULONGLONG Gpr3; + ULONGLONG Gpr4; + ULONGLONG Gpr5; + ULONGLONG Gpr6; + ULONGLONG Gpr7; + ULONGLONG Gpr8; + ULONGLONG Gpr9; + ULONGLONG Gpr10; + ULONGLONG Gpr11; + ULONGLONG Gpr12; + ULONGLONG Gpr13; + ULONGLONG Gpr14; + ULONGLONG Gpr15; + ULONGLONG Gpr16; + ULONGLONG Gpr17; + ULONGLONG Gpr18; + ULONGLONG Gpr19; + ULONGLONG Gpr20; + ULONGLONG Gpr21; + ULONGLONG Gpr22; + ULONGLONG Gpr23; + ULONGLONG Gpr24; + ULONGLONG Gpr25; + ULONGLONG Gpr26; + ULONGLONG Gpr27; + ULONGLONG Gpr28; + ULONGLONG Gpr29; + ULONGLONG Gpr30; + ULONGLONG Gpr31; + + ULONG Cr; // Condition register + ULONG Xer; // Fixed point exception register + + // + // This section is specified/returned if the ContextFlags word contains + // the flag CONTEXT_FLOATING_POINT. + // + + double Fpscr; // Floating point status/control reg + double Fpr0; // Floating registers 0..31 + double Fpr1; + double Fpr2; + double Fpr3; + double Fpr4; + double Fpr5; + double Fpr6; + double Fpr7; + double Fpr8; + double Fpr9; + double Fpr10; + double Fpr11; + double Fpr12; + double Fpr13; + double Fpr14; + double Fpr15; + double Fpr16; + double Fpr17; + double Fpr18; + double Fpr19; + double Fpr20; + double Fpr21; + double Fpr22; + double Fpr23; + double Fpr24; + double Fpr25; + double Fpr26; + double Fpr27; + double Fpr28; + double Fpr29; + double Fpr30; + double Fpr31; + + ULONG UserModeControl; // User mode control state + ULONG Fill; + + // + // This section is specified/returned if the ContextFlags word contains + // the flag CONTEXT_VECTOR. + // + + float Vscr[4]; // Vector status/control register + float Vr0[4]; // Vector registers 0..127 + float Vr1[4]; + float Vr2[4]; + float Vr3[4]; + float Vr4[4]; + float Vr5[4]; + float Vr6[4]; + float Vr7[4]; + float Vr8[4]; + float Vr9[4]; + float Vr10[4]; + float Vr11[4]; + float Vr12[4]; + float Vr13[4]; + float Vr14[4]; + float Vr15[4]; + float Vr16[4]; + float Vr17[4]; + float Vr18[4]; + float Vr19[4]; + float Vr20[4]; + float Vr21[4]; + float Vr22[4]; + float Vr23[4]; + float Vr24[4]; + float Vr25[4]; + float Vr26[4]; + float Vr27[4]; + float Vr28[4]; + float Vr29[4]; + float Vr30[4]; + float Vr31[4]; + float Vr32[4]; + float Vr33[4]; + float Vr34[4]; + float Vr35[4]; + float Vr36[4]; + float Vr37[4]; + float Vr38[4]; + float Vr39[4]; + float Vr40[4]; + float Vr41[4]; + float Vr42[4]; + float Vr43[4]; + float Vr44[4]; + float Vr45[4]; + float Vr46[4]; + float Vr47[4]; + float Vr48[4]; + float Vr49[4]; + float Vr50[4]; + float Vr51[4]; + float Vr52[4]; + float Vr53[4]; + float Vr54[4]; + float Vr55[4]; + float Vr56[4]; + float Vr57[4]; + float Vr58[4]; + float Vr59[4]; + float Vr60[4]; + float Vr61[4]; + float Vr62[4]; + float Vr63[4]; + float Vr64[4]; + float Vr65[4]; + float Vr66[4]; + float Vr67[4]; + float Vr68[4]; + float Vr69[4]; + float Vr70[4]; + float Vr71[4]; + float Vr72[4]; + float Vr73[4]; + float Vr74[4]; + float Vr75[4]; + float Vr76[4]; + float Vr77[4]; + float Vr78[4]; + float Vr79[4]; + float Vr80[4]; + float Vr81[4]; + float Vr82[4]; + float Vr83[4]; + float Vr84[4]; + float Vr85[4]; + float Vr86[4]; + float Vr87[4]; + float Vr88[4]; + float Vr89[4]; + float Vr90[4]; + float Vr91[4]; + float Vr92[4]; + float Vr93[4]; + float Vr94[4]; + float Vr95[4]; + float Vr96[4]; + float Vr97[4]; + float Vr98[4]; + float Vr99[4]; + float Vr100[4]; + float Vr101[4]; + float Vr102[4]; + float Vr103[4]; + float Vr104[4]; + float Vr105[4]; + float Vr106[4]; + float Vr107[4]; + float Vr108[4]; + float Vr109[4]; + float Vr110[4]; + float Vr111[4]; + float Vr112[4]; + float Vr113[4]; + float Vr114[4]; + float Vr115[4]; + float Vr116[4]; + float Vr117[4]; + float Vr118[4]; + float Vr119[4]; + float Vr120[4]; + float Vr121[4]; + float Vr122[4]; + float Vr123[4]; + float Vr124[4]; + float Vr125[4]; + float Vr126[4]; + float Vr127[4]; + +} XCONTEXT, *PXCONTEXT; + +// +// PowerPC special-purpose registers +// + +// +// Define Machine Status Register (MSR) fields +// + +typedef struct _XMSR { + ULONG LE : 1; // 31 Little-Endian execution mode + ULONG RI : 1; // 30 Recoverable Interrupt + ULONG Rsv1 : 2; // 29..28 reserved + ULONG DR : 1; // 27 Data Relocate + ULONG IR : 1; // 26 Instruction Relocate + ULONG IP : 1; // 25 Interrupt Prefix + ULONG Rsv2 : 1; // 24 reserved + ULONG FE1 : 1; // 23 Floating point Exception mode 1 + ULONG BE : 1; // 22 Branch trace Enable + ULONG SE : 1; // 21 Single-step trace Enable + ULONG FE0 : 1; // 20 Floating point Exception mode 0 + ULONG ME : 1; // 19 Machine check Enable + ULONG FP : 1; // 18 Floating Point available + ULONG PR : 1; // 17 Problem state + ULONG EE : 1; // 16 External interrupt Enable + ULONG ILE : 1; // 15 Interrupt Little-Endian mode + ULONG IMPL : 1; // 14 Implementation dependent + ULONG POW : 1; // 13 Power management enable + ULONG Rsv3 : 13; // 12..0 reserved +} XMSR, *PXMSR; + +// +// Define Processor Version Register (PVR) fields +// + +typedef struct _XPVR { + ULONG Revision : 16; + ULONG Version : 16; +} XPVR, *PXPVR; + +// +// Define Condition Register (CR) fields +// +// We name the structure CondR rather than CR, so that a pointer +// to a condition register structure is PCondR rather than PCR. +// (PCR is an NT data structure, the Processor Control Region.) + +typedef struct _XCondR { + ULONG CR7 : 4; // Eight 4-bit fields; machine numbers + ULONG CR6 : 4; // them in Big-Endian order + ULONG CR5 : 4; + ULONG CR4 : 4; + ULONG CR3 : 4; + ULONG CR2 : 4; + ULONG CR1 : 4; + ULONG CR0 : 4; +} XCondR, *PXCondR; + +// +// Define Fixed Point Exception Register (XER) fields +// + +typedef struct _XXER { + ULONG Rsv : 29; // 31..3 Reserved + ULONG CA : 1; // 2 Carry + ULONG OV : 1; // 1 Overflow + ULONG SO : 1; // 0 Summary Overflow +} XXER, *PXXER; + +// +// Define Floating Point Status/Control Register (FPSCR) fields +// + +typedef union _XFPSCR { + struct { + ULONG RN : 2; // 31..30 Rounding control + ULONG NI : 1; // 29 Non-IEEE mode + ULONG XE : 1; // 28 Inexact exception Enable + ULONG ZE : 1; // 27 Zero divide exception Enable + ULONG UE : 1; // 26 Underflow exception Enable + ULONG OE : 1; // 25 Overflow exception Enable + ULONG VE : 1; // 24 Invalid operation exception Enable + ULONG VXCVI : 1; // 23 Invalid op exception (integer convert) + ULONG VXSQRT : 1; // 22 Invalid op exception (square root) + ULONG VXSOFT : 1; // 21 Invalid op exception (software request) + ULONG Res1 : 1; // 20 reserved + ULONG FU : 1; // 19 Result Unordered or NaN + ULONG FE : 1; // 18 Result Equal or zero + ULONG FG : 1; // 17 Result Greater than or positive + ULONG FL : 1; // 16 Result Less than or negative + ULONG C : 1; // 15 Result Class descriptor + ULONG FI : 1; // 14 Fraction Inexact + ULONG FR : 1; // 13 Fraction Rounded + ULONG VXVC : 1; // 12 Invalid op exception (compare) + ULONG VXIMZ : 1; // 11 Invalid op exception (infinity * 0) + ULONG VXZDZ : 1; // 10 Invalid op exception (0 / 0) + ULONG VXIDI : 1; // 9 Invalid op exception (infinity / infinity) + ULONG VXISI : 1; // 8 Invalid op exception (infinity - infinity) + ULONG VXSNAN : 1; // 7 Invalid op exception (signalling NaN) + ULONG XX : 1; // 6 Inexact exception + ULONG ZX : 1; // 5 Zero divide exception + ULONG UX : 1; // 4 Underflow exception + ULONG OX : 1; // 3 Overflow exception + ULONG VX : 1; // 2 Invalid operation exception summary + ULONG FEX : 1; // 1 Enabled Exception summary + ULONG FX : 1; // 0 Exception summary + } bits; + ULONG AsULONG; +} FXPSCR, *PXFPSCR; +#ifdef __cplusplus +} +#endif +#endif // _XE_CTX_ diff --git a/third_party/xbox_sdk/include/xgraphics.h b/third_party/xbox_sdk/include/xgraphics.h new file mode 100644 index 0000000..1db314b --- /dev/null +++ b/third_party/xbox_sdk/include/xgraphics.h @@ -0,0 +1,2791 @@ +/*==========================================================================; + * + * Copyright (C) Microsoft Corporation. All Rights Reserved. + * + * File: xgraphics.h + * Content: Xbox graphics helper utilities + * + ****************************************************************************/ + +#ifndef _XGRAPHICS_H_ +#define _XGRAPHICS_H_ + +#include +#if !defined(_X86_) && !defined(_AMD64_) +#include +#endif + +#define XGCONST extern CONST DECLSPEC_SELECTANY +#if !defined(_X86_) && !defined(_AMD64_) && !defined(_PREFAST_) + #define XGRESTRICT __restrict +#else + #define XGRESTRICT +#endif + +#if defined(_PREFAST_) + #define XGASSERT(cond) { __analysis_assume((cond)); } +#elif DBG // !_PREFAST_ + VOID XGRIP(PCHAR Format, ...); + + #define XGASSERT(cond) { if (!(cond)) XGRIP("Assertion failure: %s\n", #cond); } +#else // !_DBG_ + #define XGASSERT(cond) {} +#endif + +/**************************************************************************** + * + * Texture memory layout. + * + ****************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct _XGPOINT3D +{ + LONG x; + LONG y; + LONG z; +} XGPOINT3D; + +#define XGTDESC_TILED 0x0001 +#define XGTDESC_PACKED 0x0002 +#define XGTDESC_BORDERED 0x0008 + +typedef struct _XGTEXTURE_DESC +{ + D3DRESOURCETYPE ResourceType; + UINT Width; + UINT Height; + UINT Depth; + D3DFORMAT Format; + UINT RowPitch; + UINT SlicePitch; + UINT BitsPerPixel; + UINT WidthInBlocks; + UINT HeightInBlocks; + UINT DepthInBlocks; + UINT BytesPerBlock; + INT ExpBias; + DWORD Flags; + D3DMULTISAMPLE_TYPE MultiSampleType; +} XGTEXTURE_DESC; + +typedef struct _XGMIPTAIL_DESC +{ + D3DRESOURCETYPE ResourceType; + UINT Width; + UINT Height; + UINT Depth; + D3DFORMAT Format; + UINT RowPitch; + UINT SlicePitch; + UINT BitsPerPixel; + UINT WidthInBlocks; + UINT HeightInBlocks; + UINT DepthInBlocks; + UINT BytesPerBlock; + INT ExpBias; + DWORD Flags; + UINT BaseLevel; + UINT Size; +} XGMIPTAIL_DESC; + +/* + * Texture information routines. + */ + +// Returns the GPU data format of a D3DFORMAT + +__forceinline DWORD WINAPI XGGetGpuFormat( + D3DFORMAT Format) +{ + return (DWORD)((Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT); +} + +// Returns whether a texture format is tiled or not. + +__forceinline BOOL WINAPI XGIsTiledFormat( + D3DFORMAT Format + ) +{ + return (Format & D3DFORMAT_TILED_MASK) != 0; +} + +// Returns whether a texture format is compressed or not. + +__forceinline BOOL WINAPI XGIsCompressedFormat( + D3DFORMAT Format + ) +{ + switch (XGGetGpuFormat(Format)) + { + case GPUTEXTUREFORMAT_DXT1: + case GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16: + case GPUTEXTUREFORMAT_DXT2_3: + case GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16: + case GPUTEXTUREFORMAT_DXT4_5: + case GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16: + case GPUTEXTUREFORMAT_DXN: + case GPUTEXTUREFORMAT_DXT3A: + case GPUTEXTUREFORMAT_DXT5A: + case GPUTEXTUREFORMAT_CTX1: + case GPUTEXTUREFORMAT_DXT3A_AS_1_1_1_1: + case GPUTEXTUREFORMAT_Y1_Cr_Y0_Cb_REP: + case GPUTEXTUREFORMAT_Cr_Y1_Cb_Y0_REP: + case GPUTEXTUREFORMAT_32_AS_8: + case GPUTEXTUREFORMAT_32_AS_8_INTERLACED: + case GPUTEXTUREFORMAT_32_AS_8_8: + return TRUE; + } + + return FALSE; +} + +// Map of GPU data format to pixel pitch in bits + +XGCONST BYTE g_XGTextureFormatBitsPerPixel[] = +{ + 1, // GPUTEXTUREFORMAT_1_REVERSE + 1, // GPUTEXTUREFORMAT_1 + 8, // GPUTEXTUREFORMAT_8 + 16, // GPUTEXTUREFORMAT_1_5_5_5 + 16, // GPUTEXTUREFORMAT_5_6_5 + 16, // GPUTEXTUREFORMAT_6_5_5 + 32, // GPUTEXTUREFORMAT_8_8_8_8 + 32, // GPUTEXTUREFORMAT_2_10_10_10 + 8, // GPUTEXTUREFORMAT_8_A + 8, // GPUTEXTUREFORMAT_8_B + 16, // GPUTEXTUREFORMAT_8_8 + 16, // GPUTEXTUREFORMAT_Cr_Y1_Cb_Y0_REP + 16, // GPUTEXTUREFORMAT_Y1_Cr_Y0_Cb_REP + 32, // GPUTEXTUREFORMAT_16_16_EDRAM + 32, // GPUTEXTUREFORMAT_8_8_8_8_A + 16, // GPUTEXTUREFORMAT_4_4_4_4 + 32, // GPUTEXTUREFORMAT_10_11_11 + 32, // GPUTEXTUREFORMAT_11_11_10 + 4, // GPUTEXTUREFORMAT_DXT1 + 8, // GPUTEXTUREFORMAT_DXT2_3 + 8, // GPUTEXTUREFORMAT_DXT4_5 + 64, // GPUTEXTUREFORMAT_16_16_16_16_EDRAM + 32, // GPUTEXTUREFORMAT_24_8 + 32, // GPUTEXTUREFORMAT_24_8_FLOAT + 16, // GPUTEXTUREFORMAT_16 + 32, // GPUTEXTUREFORMAT_16_16 + 64, // GPUTEXTUREFORMAT_16_16_16_16 + 16, // GPUTEXTUREFORMAT_16_EXPAND + 32, // GPUTEXTUREFORMAT_16_16_EXPAND + 64, // GPUTEXTUREFORMAT_16_16_16_16_EXPAND + 16, // GPUTEXTUREFORMAT_16_FLOAT + 32, // GPUTEXTUREFORMAT_16_16_FLOAT + 64, // GPUTEXTUREFORMAT_16_16_16_16_FLOAT + 32, // GPUTEXTUREFORMAT_32 + 64, // GPUTEXTUREFORMAT_32_32 + 128, // GPUTEXTUREFORMAT_32_32_32_32 + 32, // GPUTEXTUREFORMAT_32_FLOAT + 64, // GPUTEXTUREFORMAT_32_32_FLOAT + 128, // GPUTEXTUREFORMAT_32_32_32_32_FLOAT + 8, // GPUTEXTUREFORMAT_32_AS_8 + 16, // GPUTEXTUREFORMAT_32_AS_8_8 + 16, // GPUTEXTUREFORMAT_16_MPEG + 32, // GPUTEXTUREFORMAT_16_16_MPEG + 8, // GPUTEXTUREFORMAT_8_INTERLACED + 8, // GPUTEXTUREFORMAT_32_AS_8_INTERLACED + 16, // GPUTEXTUREFORMAT_32_AS_8_8_INTERLACED + 16, // GPUTEXTUREFORMAT_16_INTERLACED + 16, // GPUTEXTUREFORMAT_16_MPEG_INTERLACED + 32, // GPUTEXTUREFORMAT_16_16_MPEG_INTERLACED + 8, // GPUTEXTUREFORMAT_DXN + 32, // GPUTEXTUREFORMAT_8_8_8_8_AS_16_16_16_16 + 4, // GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16 + 8, // GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16 + 8, // GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16 + 32, // GPUTEXTUREFORMAT_2_10_10_10_AS_16_16_16_16 + 32, // GPUTEXTUREFORMAT_10_11_11_AS_16_16_16_16 + 32, // GPUTEXTUREFORMAT_11_11_10_AS_16_16_16_16 + 96, // GPUTEXTUREFORMAT_32_32_32_FLOAT + 4, // GPUTEXTUREFORMAT_DXT3A + 4, // GPUTEXTUREFORMAT_DXT5A + 4, // GPUTEXTUREFORMAT_CTX1 + 4, // GPUTEXTUREFORMAT_DXT3A_AS_1_1_1_1 + 32, // GPUTEXTUREFORMAT_8_8_8_8_GAMMA_EDRAM + 32, // GPUTEXTUREFORMAT_2_10_10_10_FLOAT_EDRAM +}; + +// Returns the number of bits per texel of a GPU texture format. + +__inline UINT WINAPI XGBitsPerPixelFromGpuFormat( + DWORD GpuFormat + ) +{ +#if DBG + if (GpuFormat >= (sizeof(g_XGTextureFormatBitsPerPixel) / sizeof(g_XGTextureFormatBitsPerPixel[0])) || + g_XGTextureFormatBitsPerPixel[GpuFormat] == 0) + { + // Invalid format + __debugbreak(); + } +#endif + + return g_XGTextureFormatBitsPerPixel[GpuFormat]; +} + +// Returns the number of bits per texel of a format. + +__inline UINT WINAPI XGBitsPerPixelFromFormat( + D3DFORMAT Format + ) +{ + GPUTEXTUREFORMAT GpuFormat = (GPUTEXTUREFORMAT)XGGetGpuFormat(Format); + + return XGBitsPerPixelFromGpuFormat(GpuFormat); +} + +// Returns the number of bytes per texel of a format. + +__inline UINT WINAPI XGBytesPerPixelFromFormat( + D3DFORMAT Format + ) +{ + GPUTEXTUREFORMAT GpuFormat = (GPUTEXTUREFORMAT)XGGetGpuFormat(Format); + UINT BitsPerPixel = XGBitsPerPixelFromGpuFormat(GpuFormat); + + return BitsPerPixel >> 3; +} + +// Calculate the smallest multiple that is equal to or greater than the +// specified value. + +__inline UINT XGNextMultiple( + UINT Value, + UINT Multiple + ) +{ + return ((Value + Multiple - 1) / Multiple) * Multiple; +} + +// Calculate the size of the EDRAM allocation needed for the specified +// surface, in units of EDRAM tiles. + +__inline UINT WINAPI XGSurfaceSize( + UINT Width, + UINT Height, + D3DFORMAT Format, + D3DMULTISAMPLE_TYPE MultiSample + ) +{ + GPUTEXTUREFORMAT GpuFormat = (GPUTEXTUREFORMAT)XGGetGpuFormat(Format); + DWORD bytesPerFragment = 4; + DWORD sizeInBytes; + DWORD sizeInTiles; + + // Compute the surface size in fragments: + + DWORD widthInFragments = Width; + DWORD heightInFragments = Height; + + if (MultiSample >= D3DMULTISAMPLE_2_SAMPLES) + heightInFragments *= 2; + if (MultiSample == D3DMULTISAMPLE_4_SAMPLES) + widthInFragments *= 2; + + // EDRAM memory has to be allocated with a granularity that is the + // dimension of an EDRAM tile: + + widthInFragments = XGNextMultiple(widthInFragments, GPU_EDRAM_TILE_WIDTH_IN_FRAGMENTS); + heightInFragments = XGNextMultiple(heightInFragments, GPU_EDRAM_TILE_HEIGHT_IN_FRAGMENTS); + + // Determine if this is a 64-bit render target format: + + if ((GpuFormat == GPUTEXTUREFORMAT_16_16_16_16_EDRAM) || + (GpuFormat == GPUTEXTUREFORMAT_16_16_16_16_FLOAT) || + (GpuFormat == GPUTEXTUREFORMAT_32_32_FLOAT)) + { + bytesPerFragment = 8; + } + + // Compute the total size of the allocation: + + sizeInBytes = widthInFragments * heightInFragments * bytesPerFragment; + + // Note that we're guaranteed that the total size in bytes is a multiple of + // the tile size: + + sizeInTiles = sizeInBytes / GPU_EDRAM_TILE_SIZE; + + return (UINT)sizeInTiles; +} + +// Calculate the size of the hierarchical Z allocation needed for the specified +// surface, in units of hierarchical Z tiles. + +__inline UINT WINAPI XGHierarchicalZSize( + UINT Width, + UINT Height, + D3DMULTISAMPLE_TYPE MultiSample + ) +{ + // Compute the hierarchical Z size in fragments: + + DWORD widthInFragments = Width; + DWORD heightInFragments = Height; + + if (MultiSample >= D3DMULTISAMPLE_2_SAMPLES) + heightInFragments *= 2; + if (MultiSample == D3DMULTISAMPLE_4_SAMPLES) + widthInFragments *= 2; + + // Hierarchical Z memory has to be allocated with a granularity that is the + // dimension of a hierarchical Z tile: + + widthInFragments = XGNextMultiple(widthInFragments, GPU_HIERARCHICAL_Z_TILE_WIDTH_IN_FRAGMENTS); + heightInFragments = XGNextMultiple(heightInFragments, GPU_HIERARCHICAL_Z_TILE_HEIGHT_IN_FRAGMENTS); + + return widthInFragments * heightInFragments / GPU_HIERARCHICAL_Z_TILE_SIZE; +} + +// Return the description of a texture, cube texture, or volume texture. This +// description contains memory footprint and tiling information in addition to +// the information that could typically be retrieved from GetLevelDesc, LockRect, +// etc. + +VOID WINAPI XGGetTextureDesc( + __in D3DBaseTexture* pTexture, // Texture to describe + UINT Level, // Mip level to describe + __out XGTEXTURE_DESC* pDesc // Structure to be filled with texture description + ); + +// Return the description of a surface + +__inline VOID WINAPI XGGetSurfaceDesc( + __in D3DSurface* pSurface, + __out XGTEXTURE_DESC* pDesc + ) +{ + XGGetTextureDesc((D3DBaseTexture*)pSurface, 0, pDesc); +} + +// Return the description of a volume + +__inline VOID WINAPI XGGetVolumeDesc( + __in D3DVolume* pVolume, + __out XGTEXTURE_DESC* pDesc + ) +{ + XGGetTextureDesc((D3DBaseTexture*)pVolume, 0, pDesc); +} + +// Return memory layout information on a given texture + +typedef struct _XGLAYOUT_REGION +{ + UINT StartOffset; + UINT EndOffset; +} XGLAYOUT_REGION; + +VOID WINAPI XGGetTextureLayout( + __in D3DBaseTexture* pTexture, // Texture to examine + __out_opt UINT* pBaseData, // Memory address or offset to the base level data in the texture + __out_opt UINT* pBaseSize, // Allocation size of the base level data in the texture + __out_ecount_part_opt(*pBaseRegionListCount, *pBaseRegionListCount) + XGLAYOUT_REGION* pBaseRegionList, // Pointer to a list of layout regions that will be filled with a + // set of isolated memory ranges that may potentially be referenced + // by fetches into the base texture allocation + __inout_opt UINT* pBaseRegionListCount, // IN: Size of the base region list buffer in entries; OUT: Number + // of used memory regions written to the base region list + UINT BaseRegionAlignment, // Power-of-two alignment applied to the base memory regions + __out_opt UINT* pMipData, // Memory address or offset to the mip level data in the texture + __out_opt UINT* pMipSize, // Allocation size of the mip level data in the texture + __out_ecount_part_opt(*pMipRegionListCount, *pMipRegionListCount) + XGLAYOUT_REGION* pMipRegionList, // Pointer to a list of layout regions that will be filled with a + // set of isolated memory ranges that may potentially be referenced + // by fetches into the mip texture allocation + __inout_opt UINT* pMipRegionListCount, // IN: Size of the mip region list buffer in entries; OUT: Number + // of used memory regions written to the mip region list + UINT MipRegionAlignment // Power-of-two alignment applied to the mip memory regions + ); + +// Returns whether a texture packs small mip levels + +__forceinline BOOL WINAPI XGIsPackedTexture( + __in D3DBaseTexture* pTexture + ) +{ + return pTexture->Format.PackedMips != 0; +} + +// Returns whether a texture includes a border + +__forceinline BOOL WINAPI XGIsBorderTexture( + __in D3DBaseTexture* pTexture + ) +{ + return pTexture->Format.BorderSize != 0; +} + +// Return the offset in bytes to the start of the given mip level. +// This offset may be added to either the base address (for level 0 +// or in cases where the mip address is NULL) or to the mip address +// to obtain a pointer to the level data. + +UINT WINAPI XGGetMipLevelOffset( + __in D3DBaseTexture* pTexture, // Texture containing the mip level + UINT ArrayIndex, // Cubemap face or texture array index + UINT Level // Mip level index + ); + +// Return the description of a packed mip tail. + +VOID WINAPI XGGetMipTailDesc( + __in D3DBaseTexture* pTexture, // Texture containing the tail to describe + __out XGMIPTAIL_DESC* pDesc // Structure to be filled with tail description + ); + +// Return the index of the first packed level in a mip map. + +UINT WINAPI XGGetMipTailBaseLevel( + UINT Width, // Width of the texture + UINT Height, // Height of the texture + BOOL Border // TRUE if the texture has a border, FALSE if it does not + ); + +// Return the offset in bytes from the base address of the packed mip tail +// to the base address of the given mip level. If the given level is +// not packed, an offset of 0 is returned. + +UINT WINAPI XGGetMipTailLevelOffset( + UINT Width, // Width of the texture + UINT Height, // Height of the texture + UINT Depth, // Depth of the texture + UINT Level, // Mip level of the texture + DWORD GpuFormat, // Gpu format of the texture + BOOL Tiled, // TRUE if the texture is tiled, FALSE if linear + BOOL Border // TRUE if the texture has a border, FALSE if it does not + ); + +// Return the texel dimensions of a compression block in the given format. +// If the format is not compressed, the size of a block is 1 x 1 texels. + +VOID WINAPI XGGetBlockDimensions( + DWORD GpuFormat, // Gpu format of the compression block + __out UINT* pWidth, // Out: Width of a block + __out UINT* pHeight // Out: Height of a block + ); + +// Describe how to render the left eye, right eye, and blank regions for +// stereoscopic 3D. + +typedef struct _XGSTEREOREGION +{ + D3DRECT FrontBufferRect; + D3DRECT BlankRectTop; + D3DRECT BlankRectBottom; + D3DRECT ResolveSourceRect; + D3DPOINT ResolveDestPoint; + LONG ViewportYOffset; +} XGSTEREOREGION; + +typedef struct _XGSTEREOPARAMETERS +{ + UINT FrontBufferWidth; + UINT FrontBufferHeight; + UINT EyeBufferWidth; + UINT EyeBufferHeight; + XGSTEREOREGION LeftEye; + XGSTEREOREGION BlankRegion; + XGSTEREOREGION RightEye; + DWORD Reserved; +} XGSTEREOPARAMETERS; + +HRESULT WINAPI XGGetStereoParameters( + UINT Width, // Per-eye render width + UINT Height, // Per-eye render height + D3DMULTISAMPLE_TYPE MultiSampleType, + DWORD Flags, + __out XGSTEREOPARAMETERS *pStereoParameters + ); + +/* + * Address translation routines. + */ + +//------------------------------------------------------------------------ +// Calculate the log2 of a texel pitch which is less than or equal to 16 +// and a power of 2. + +__forceinline UINT WINAPI XGLog2LE16( + UINT TexelPitch) +{ + XGASSERT((TexelPitch > 0) && + (TexelPitch <= 16) && + (TexelPitch & (TexelPitch - 1)) == 0); + +#if defined(_X86_) || defined(_AMD64_) + return (TexelPitch >> 2) + ((TexelPitch >> 1) >> (TexelPitch >> 2)); +#else + return 31 - _CountLeadingZeros(TexelPitch); +#endif +} + +//------------------------------------------------------------------------ +// Translate the address of a surface texel/block from 2D array coordinates into +// a tiled memory offset measured in texels/blocks. + +__inline UINT WINAPI XGAddress2DTiledOffset( + UINT x, // x coordinate of the texel/block + UINT y, // y coordinate of the texel/block + UINT Width, // Width of the image in texels/blocks + UINT TexelPitch // Size of an image texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT LogBpp; + UINT Macro; + UINT Micro; + UINT Offset; + + XGASSERT(Width <= 8192); // Width in memory must be less than or equal to 8K texels + XGASSERT(x < Width); + + AlignedWidth = (Width + 31) & ~31; + LogBpp = XGLog2LE16(TexelPitch); + Macro = ((x >> 5) + (y >> 5) * (AlignedWidth >> 5)) << (LogBpp + 7); + Micro = (((x & 7) + ((y & 6) << 2)) << LogBpp); + Offset = Macro + ((Micro & ~15) << 1) + (Micro & 15) + ((y & 8) << (3 + LogBpp)) + ((y & 1) << 4); + + return (((Offset & ~511) << 3) + ((Offset & 448) << 2) + (Offset & 63) + + ((y & 16) << 7) + (((((y & 8) >> 2) + (x >> 3)) & 3) << 6)) >> LogBpp; +} + +//------------------------------------------------------------------------ +// Determine the amount of memory occupied by a tiled 2D surface to the +// granularity of a matte (subtile). The returned size refers to the +// largest tiled offset potentially referenced in the surface and is +// measured in texels/blocks. + +UINT WINAPI XGAddress2DTiledExtent( + UINT Width, // Width of the image in texels/blocks + UINT Height, // Height of the image in texels/blocks + UINT TexelPitch // Size of an image texel/block in bytes + ); + + +//------------------------------------------------------------------------ +// Translate the address of a volume texel/block from 3D array coordinates into +// a tiled memory offset measured in texels/blocks. + +__inline UINT WINAPI XGAddress3DTiledOffset( + UINT x, // x coordinate of the texel/block + UINT y, // y coordinate of the texel/block + UINT z, // z coordinate of the texel/block + UINT Width, // Width of a volume slice in texels/blocks + UINT Height, // Height of a volume slice in texels/blocks + UINT TexelPitch // Size of a volume texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT AlignedHeight; + UINT LogBpp; + UINT Macro; + UINT Micro; + UINT64 Offset1; + UINT64 Offset2; + + XGASSERT(Width <= 2048); // Width in memory must be less than or equal to 2K texels + XGASSERT(Height <= 2048); // Height in memory must be less than or equal to 2K texels + XGASSERT(x < Width); + XGASSERT(y < Height); + + AlignedWidth = (Width + 31) & ~31; + AlignedHeight = (Height + 31) & ~31; + LogBpp = XGLog2LE16(TexelPitch); + Macro = ((z >> 2) * (AlignedHeight >> 4) + (y >> 4)) * (AlignedWidth >> 5) + (x >> 5); + Micro = (((y & 6) << 2) + (x & 7)) << LogBpp; + Offset1 = (UINT64)(((UINT64)Macro << (8 + LogBpp)) + ((UINT64)(Micro & ~15) << 1) + (UINT64)(Micro & 15) + ((UINT64)(z & 3) << (6 + LogBpp)) + ((UINT64)(y & 1) << 4)); + Offset2 = (UINT64)(((z >> 2) + (y >> 3)) & 1); + + return (UINT)((((Offset1 & ~511ull) << 3ull) + ((Offset1 & 448ull) << 2ull) + (Offset1 & 63ull) + + (Offset2 << 11ull) + ((((Offset2 << 1ull) + (x >> 3)) & 3ull) << 6ull)) >> LogBpp); +} + +//------------------------------------------------------------------------ +// Determine the amount of memory occupied by a tiled 3D volume to the +// granularity of a matte (subtile). The returned size refers to the +// largest tiled offset potentially referenced in the volume and is +// measured in texels/blocks. + +UINT WINAPI XGAddress3DTiledExtent( + UINT Width, // Width of a volume slice in texels/blocks + UINT Height, // Height of a volume slice in texels/blocks + UINT Depth, // Depth of a volume slice in texels/blocks + UINT TexelPitch // Size of a volume texel/block in bytes + ); + +//------------------------------------------------------------------------ +// Translate the address of a surface texel/block from a tiled memory offset +// into a 2D array x coordinate measured in texels/blocks. + +__inline UINT WINAPI XGAddress2DTiledX( + UINT Offset, // Tiled memory offset in texels/blocks + UINT Width, // Width of the image in texels/blocks + UINT TexelPitch // Size of an image texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT LogBpp; + UINT OffsetB; + UINT OffsetT; + UINT OffsetM; + UINT Tile; + UINT Macro; + UINT Micro; + UINT MacroX; + + XGASSERT(Width <= 8192); // Width in memory must be less than or equal to 8K texels + + AlignedWidth = (Width + 31) & ~31; + + LogBpp = XGLog2LE16(TexelPitch); + OffsetB = Offset << LogBpp; + OffsetT = ((OffsetB & ~4095) >> 3) + ((OffsetB & 1792) >> 2) + (OffsetB & 63); + OffsetM = OffsetT >> (7 + LogBpp); + + MacroX = ((OffsetM % (AlignedWidth >> 5)) << 2); + Tile = ((((OffsetT >> (5 + LogBpp)) & 2) + (OffsetB >> 6)) & 3); + Macro = (MacroX + Tile) << 3; + Micro = ((((OffsetT >> 1) & ~15) + (OffsetT & 15)) & ((TexelPitch << 3) - 1)) >> LogBpp; + + return Macro + Micro; +} + +//------------------------------------------------------------------------ +// Translate the address of a surface texel/block from a tiled memory offset +// into a 2D array y coordinate measured in texels/blocks. + +__inline UINT WINAPI XGAddress2DTiledY( + UINT Offset, // Tiled memory offset in texels/blocks + UINT Width, // Width of the image in texels/blocks + UINT TexelPitch // Size of an image texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT LogBpp; + UINT OffsetB; + UINT OffsetT; + UINT OffsetM; + UINT Tile; + UINT Macro; + UINT Micro; + UINT MacroY; + + XGASSERT(Width <= 8192); // Width in memory must be less than or equal to 8K texels + + AlignedWidth = (Width + 31) & ~31; + + LogBpp = XGLog2LE16(TexelPitch); + OffsetB = Offset << LogBpp; + OffsetT = ((OffsetB & ~4095) >> 3) + ((OffsetB & 1792) >> 2) + (OffsetB & 63); + OffsetM = OffsetT >> (7 + LogBpp); + + MacroY = ((OffsetM / (AlignedWidth >> 5)) << 2); + Tile = ((OffsetT >> (6 + LogBpp)) & 1) + (((OffsetB & 2048) >> 10)); + Macro = (MacroY + Tile) << 3; + Micro = ((((OffsetT & (((TexelPitch << 6) - 1) & ~31)) + ((OffsetT & 15) << 1)) >> (3 + LogBpp)) & ~1); + + return Macro + Micro + ((OffsetT & 16) >> 4); +} + +//------------------------------------------------------------------------ +// Translate the address of a volume texel/block from a tiled memory offset +// into a 3D array x coordinate measured in texels/blocks. + +__inline UINT WINAPI XGAddress3DTiledX( + UINT Offset, // Tiled memory offset in texels/blocks + UINT Width, // Width of a volume slice in texels/blocks + UINT Height, // Height of a volume slice in texels/blocks + UINT TexelPitch // Size of a volume texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT LogBpp; + UINT OffsetB; + UINT OffsetT; + UINT OffsetM; + UINT Micro; + UINT Macro; + UINT Tile; + + XGASSERT(Width <= 2048); // Width in memory must be less than or equal to 2K texels +#if DBG + XGASSERT(Height <= 2048); // Height in memory must be less than or equal to 2K texels +#else + UNREFERENCED_PARAMETER(Height); +#endif + + AlignedWidth = (Width + 31) & ~31; + + LogBpp = XGLog2LE16(TexelPitch); + OffsetB = Offset << LogBpp; + OffsetM = ((Offset >> 11) & (~1 >> LogBpp)) + ((OffsetB & 1024) >> (LogBpp + 10)); + OffsetT = ((((Offset << LogBpp) & ~4095) >> 3) + (((OffsetB & 1792) >> 2) + (OffsetB & 63))) & ((TexelPitch << 6) - 1); + Micro = (((OffsetT & ~31) >> 1) + (OffsetT & 15)); + + Macro = OffsetM % (AlignedWidth >> 5); + Tile = (((OffsetB & 2048) >> 10) + (OffsetB >> 6)) & 3; + + return (((Macro << 2) + Tile) << 3) + ((Micro >> LogBpp) & 7); +} + +//------------------------------------------------------------------------ +// Translate the address of a volume texel/block from a tiled memory offset +// into a 3D array y coordinate measured in texels/blocks. + +__inline UINT WINAPI XGAddress3DTiledY( + UINT Offset, // Tiled memory offset in texels/blocks + UINT Width, // Width of a volume slice in texels/blocks + UINT Height, // Height of a volume slice in texels/blocks + UINT TexelPitch // Size of a volume texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT AlignedHeight; + UINT LogBpp; + UINT OffsetB; + UINT OffsetT; + UINT OffsetM; + UINT Micro; + UINT Macro; + UINT Tile; + UINT TileZ; + + XGASSERT(Width <= 2048); // Width in memory must be less than or equal to 2K texels + XGASSERT(Height <= 2048); // Height in memory must be less than or equal to 2K texels + + AlignedWidth = (Width + 31) & ~31; + AlignedHeight = (Height + 31) & ~31; + + LogBpp = XGLog2LE16(TexelPitch); + OffsetB = Offset << LogBpp; + OffsetM = ((Offset >> 11) & (~1 >> LogBpp)) + ((OffsetB & 1024) >> (LogBpp + 10)); + OffsetT = ((((Offset << LogBpp) & ~4095) >> 3) + (((OffsetB & 1792) >> 2) + (OffsetB & 63))) & ((TexelPitch << 6) - 1); + Micro = (((OffsetT & ~31) >> 1) + (OffsetT & 15)); + TileZ = (OffsetM << 9) / (AlignedWidth * AlignedHeight); + + Macro = (OffsetM / (AlignedWidth >> 5)) % (AlignedHeight >> 4); + Tile = (((OffsetB & 2048) >> 11) ^ TileZ) & 1; + Micro = (((Micro & 15) << 1) + (OffsetT & ~31)) >> (LogBpp + 3); + + return (((Macro << 1) + Tile) << 3) + (Micro & ~1) + ((OffsetT & 16) >> 4); +} + +//------------------------------------------------------------------------ +// Translate the address of a volume texel/block from a tiled memory offset +// into a 3D array z coordinate measured in texels/blocks. + +__inline UINT WINAPI XGAddress3DTiledZ( + UINT Offset, // Tiled memory offset in texels/blocks + UINT Width, // Width of a volume slice in texels/blocks + UINT Height, // Height of a volume slice in texels/blocks + UINT TexelPitch // Size of a volume texel/block in bytes + ) +{ + UINT AlignedWidth; + UINT AlignedHeight; + UINT LogBpp; + UINT OffsetB; + UINT OffsetM; + UINT TileZ; + + XGASSERT(Width <= 2048); // Width in memory must be less than or equal to 2K texels + XGASSERT(Height <= 2048); // Height in memory must be less than or equal to 2K texels + + AlignedWidth = (Width + 31) & ~31; + AlignedHeight = (Height + 31) & ~31; + + LogBpp = XGLog2LE16(TexelPitch); + OffsetB = Offset << LogBpp; + OffsetM = ((Offset >> 11) & (~1 >> LogBpp)) + ((OffsetB & 1024) >> (LogBpp + 10)); + TileZ = (OffsetM << 9) / (AlignedWidth * AlignedHeight); + + return (((((Offset >> 9) & (~7 >> LogBpp))) + ((OffsetB & 1792) >> (LogBpp + 8))) & 3) + (TileZ << 2); +} + +/* + * Tile conversion routines. + */ + +// Tile a subrectangle from a source image into a destination image. The +// rectangle, when offset by a given point into the destination, must be +// completely contained within the destination image (no clipping). +// If pPoint and pRect are both NULL, the source and destination images +// are assumed to have the same dimensions and the entire image is tiled. + +VOID WINAPI XGTileSurface( + __out VOID* pDestination, // Base address of the destination (tiled) image + UINT Width, // Width of the destination image + UINT Height, // Height of the destination image + __in_opt CONST POINT* pPoint, // Offset in the destination image to place the tiled rectangle + __in CONST VOID* pSource, // Base address of the source (linear) image + UINT RowPitch, // Distance in bytes between one row of the source image and the next + __in_opt CONST RECT* pRect, // Rectangle within the source image to copy + UINT TexelPitch // Size of an image texel/block in bytes + ); + +// Untile a subrectangle from a source image into a destination image. +// If pPoint and pRect are both NULL, the source and destination images +// are assumed to have the same dimensions and the entire image is untiled. + +VOID WINAPI XGUntileSurface( + __out VOID* pDestination, // Base address of the destination (linear) image + UINT RowPitch, // Distance in bytes between one row of the destination image and the next + __in_opt CONST POINT* pPoint, // Offset in the destination image to place the untiled rectangle + __in CONST VOID* pSource, // Base address of the source (tiled) image + UINT Width, // Width of the source image + UINT Height, // Height of the source image + __in_opt CONST RECT* pRect, // Rectangle within the source image to copy + UINT TexelPitch // Size of an image texel/block in bytes + ); + +// Tile a box from a source volume into a destination volume. The +// box, when offset by a given point into the destination, must be +// completely contained within the destination volume (no clipping). +// If pPoint and pBox are both NULL, the source and destination volumes +// are assumed to have the same dimensions and the entire volume is tiled. + +VOID WINAPI XGTileVolume( + __out VOID* pDestination, // Base address of the destination (tiled) volume + UINT Width, // Width of the destination volume + UINT Height, // Height of the destination volume + UINT Depth, // Depth of the destination volume + __in_opt CONST XGPOINT3D* pPoint, // Offset in the destination volume to place the tiled box + __in CONST VOID* pSource, // Base address of the source (linear) volume + UINT RowPitch, // Distance in bytes between one row of the source volume and the next + UINT SlicePitch, // Distance in bytes between one slice of the source volume and the next + __in_opt CONST D3DBOX* pBox, // Box within the source volume to copy + UINT TexelPitch // Size of a volume texel/block in bytes + ); + +// Untile a box from a source volume into a destination volume. +// If pPoint and pBox are both NULL, the source and destination volumes +// are assumed to have the same dimensions and the entire volume is untiled. + +VOID WINAPI XGUntileVolume( + __out VOID* pDestination, // Base address of the destination (linear) volume + UINT RowPitch, // Distance in bytes between one row of the destination volume and the next + UINT SlicePitch, // Distance in bytes between one slice of the destination volume and the next + __in_opt CONST XGPOINT3D* pPoint, // Offset in the destination volume to place the tiled box + __in CONST VOID* pSource, // Base address of the source (tiled) volume + UINT Width, // Width of the source volume + UINT Height, // Height of the source volume + UINT Depth, // Depth of the source volume + __in_opt CONST D3DBOX* pBox, // Box within the source volume to copy + UINT TexelPitch // Size of a volume texel/block in bytes + ); + +// Tile a subrectangle from a source image into the level of a destination texture. +// The rectangle, when offset by a given point into the destination, must be +// completely contained within the destination image (no clipping). +// If pPoint and pRect are both NULL, the source and destination images +// are assumed to have the same dimensions and the entire level is tiled. +// Unlike with the surface tiling functions, tiling directly into individual packed levels is supported. + +#define XGTILE_NONPACKED 0x1 +#define XGTILE_BORDER 0x2 + +VOID WINAPI XGTileTextureLevel( + UINT Width, // Width of the texture (base level) in texels (not blocks) + UINT Height, // Height of the texture (base level) in texels (not blocks) + UINT Level, // Mip level of the destination + DWORD GpuFormat, // Gpu format of the texture + DWORD Flags, // Tiling flags (border, non-packed, etc.) + __out VOID* pDestination, // Address of the first texel in the destination (tiled) level + __in_opt CONST POINT* pPoint, // Offset in the destination level (in texels) to place the tiled image + __in CONST VOID* pSource, // Address of the source (linear) image + UINT RowPitch, // Distance in bytes between one row of the source image and the next + __in_opt CONST RECT* pRect // Rect within the source image to copy (in texels) + ); + +// Untile a subrectangle from a source texture level into a destination image. +// If pPoint and pRect are both NULL, the source level and destination image +// are assumed to have the same dimensions and the entire level is untiled. +// Untiling directly from individual packed levels is supported. + +VOID WINAPI XGUntileTextureLevel( + UINT Width, // Width of the texture (base level) in texels (not blocks) + UINT Height, // Height of the texture (base level) in texels (not blocks) + UINT Level, // Mip level of the destination + DWORD GpuFormat, // Gpu format of the texture + DWORD Flags, // Tiling flags (border, non-packed, etc.) + __out VOID* pDestination, // Base address of the destination (linear) image + UINT RowPitch, // Distance in bytes between one row of the destination image and the next + __in_opt CONST POINT* pPoint, // Offset in the destination image (in texels) to place the untiled box + __in CONST VOID* pSource, // Address of the first texel in the source (tiled) level + __in_opt CONST RECT* pRect // Rect within the source level to copy (in texels) + ); + +// Tile a sub-box from a source volume into the level of a destination volume texture. +// The box, when offset by a given point into the destination, must be +// completely contained within the destination volume (no clipping). +// If pPoint and pBox are both NULL, the source and destination volumes +// are assumed to have the same dimensions and the entire level is tiled. +// Unlike with the volume tiling functions, tiling directly into individual packed levels is supported. + +VOID WINAPI XGTileVolumeTextureLevel( + UINT Width, // Width of the volume texture (base level) in texels (not blocks) + UINT Height, // Height of the volume texture (base level) in texels (not blocks) + UINT Depth, // Depth of the volume texture (base level) in texels + UINT Level, // Mip level of the destination + DWORD GpuFormat, // Gpu format of the volume texture + DWORD Flags, // Tiling flags (border, non-packed, etc.) + __out VOID* pDestination, // Address of the first texel in the destination (tiled) level + __in_opt CONST XGPOINT3D* pPoint, // Offset in the destination level (in texels) to place the tiled image + __in CONST VOID* pSource, // Address of the source (linear) image + UINT RowPitch, // Distance in bytes between one row of the source image and the next + UINT SlicePitch, // Distance in bytes between one slice of the source image and the next + __in_opt CONST D3DBOX* pBox // Box within the source image to copy (in texels) + ); + +// Untile a sub-box from a source volume texture level into a destination volume. +// If pPoint and pBox are both NULL, the source level and destination volume +// are assumed to have the same dimensions and the entire level is untiled. +// Untiling directly from individual packed levels is supported. + +VOID WINAPI XGUntileVolumeTextureLevel( + UINT Width, // Width of the volume texture (base level) in texels (not blocks) + UINT Height, // Height of the volume texture (base level) in texels (not blocks) + UINT Depth, // Depth of the volume texture (base level) in texels + UINT Level, // Mip level of the destination + DWORD GpuFormat, // Gpu format of the volume texture + DWORD Flags, // Tiling flags (border, non-packed, etc.) + __out VOID* pDestination, // Base address of the destination (linear) image + UINT RowPitch, // Distance in bytes between one row of the destination image and the next + UINT SlicePitch, // Distance in bytes between one slice of the destination image and the next + __in_opt CONST XGPOINT3D* pPoint, // Offset in the destination image (in texels) to place the untiled box + __in CONST VOID* pSource, // Address of the first texel in the source (tiled) level + __in_opt CONST D3DBOX* pBox // Box within the source level to copy (in texels) + ); + +/**************************************************************************** + * + * Texture compression. + * + ****************************************************************************/ + +#define XGCOMPRESS_PREMULTIPLY 0x0001 // Enable DXT2 or DXT4 +#define XGCOMPRESS_ALPHADIVIDE 0x0002 // Remove DXT2 or DXT4 premultiplication +#define XGCOMPRESS_YUV_DESTINATION 0x0004 // Store the destination in a YUV format +#define XGCOMPRESS_YUV_SOURCE 0x0008 // Load the source from a YUV format +#define XGCOMPRESS_NO_DITHERING 0x0010 // Do not dither + +// Compress a subrectangle from a source image into a destination image. The +// rectangle, when offset by a given point into the destination, must be +// completely contained within the destination image (no clipping). +// If pPoint and pRect are both NULL, the source and destination images +// are assumed to have the same dimensions and the entire image is compressed. + +HRESULT WINAPI XGCompressSurface( + __out VOID* pDestination, // Base address of the destination (compressed) image + UINT DstRowPitch, // Distance in bytes between one row of the destination image and the next + UINT Width, // Width of the destination image in texels + UINT Height, // Height of the destination image in texels + D3DFORMAT DstFormat, // Compressed format of the destination image + __in_opt CONST POINT* pPoint, // Offset in the destination image to place the compressed rectangle + __in CONST VOID* pSource, // Base address of the source (uncompressed) image + UINT SrcRowPitch, // Distance in bytes between one row of the source image and the next + D3DFORMAT SrcFormat, // Format of the source image + __in_opt CONST RECT* pRect, // Rectangle within the source image to compress + DWORD Flags, // Compression flags + FLOAT AlphaRef // Alpha threshold for DXT1 transparency + ); + +// Compress a box from a source volume into a destination volume. The +// box, when offset by a given point into the destination, must be +// completely contained within the destination volume (no clipping). +// If pPoint and pBox are both NULL, the source and destination volumes +// are assumed to have the same dimensions and the entire volume is compressed. + +HRESULT WINAPI XGCompressVolume( + __out VOID* pDestination, // Base address of the destination (compressed) volume + UINT DstRowPitch, // Distance in bytes between one row of the destination volume and the next + UINT DstSlicePitch, // Distance in bytes between one slice of the destination volume and the next + UINT Width, // Width of the destination volume in texels + UINT Height, // Height of the destination volume in texels + UINT Depth, // Depth of the destination volume in texels + D3DFORMAT DstFormat, // Compressed format of the destination volume + __in_opt CONST XGPOINT3D* pPoint, // Offset in the destination volume to place the compressed box + __in CONST VOID* pSource, // Base address of the source (uncompressed) volume + UINT SrcRowPitch, // Distance in bytes between one row of the source volume and the next + UINT SrcSlicePitch, // Distance in bytes between one slice of the source volume and the next + D3DFORMAT SrcFormat, // Format of the source volume + __in_opt CONST D3DBOX* pBox, // Box within the source volume to compress + DWORD Flags, // Compression flags + FLOAT AlphaRef // Alpha threshold for DXT1 transparency + ); + +/**************************************************************************** + * + * PTC Texture compression. + * + * PTC (Progressive Transform Codec) is a lossy image compression algorithm + * created by Microsoft Research similar to JPEG. It achieves better + * compression ratios with similar image quality. + * + ****************************************************************************/ + +// Compression parameters for use with XGPTCCompressSurfaceEx + +typedef struct _XGPTC_COMPRESSION_PARAMS +{ + INT Qs; // Quantization step, 4..10000000 [default = 100] + // Compression ratio increases for larger Qs + // Compression is lossless for Qs = 0 + INT Qa; // Quantization step for alpha, same as Qs + INT ColorSpace; // Color space of input pixels; options are: + // 0 - undefined; channels coded independently + // 1 - RGB 2 - CMY 3 - CMYK + BOOL OneBitAlpha; // Treat alpha channel as a one-bit alpha channel + INT Ec; // Entropy coding mode [default = 1] + // 0 = bit-plane coder, scalable + // 1 = adaptive run-length/Rice, nonscalable, faster + INT Eca; // Entropy coding mode for the alpha channel + INT ChunkWidth; // Encoding chunk width, in # of pixels, 32..5184 [default = 256] + INT Bd; // # of bits to preserve for lossless compression + // when the intput is 16-bits, from 8 to 16 + BOOL Npp; // Use non-overlapping transforms [not recommended]; improves + // compression and speed in lossless mode, but precludes mipmap + // decoding. + LPCSTR pMeta; // Inserts specified string into global metadata area + // of the PTC image (may be NULL) + LPCSTR pFrameMeta; // Inserts specified string into frame metadata area + // of the PTC image (may be NULL) + +} XGPTC_COMPRESSION_PARAMS; + +// Compress a subrectangle from a source image into a destination image. The +// rectangle must be completely contained within the source image (no clipping). +// If pRect is NULL, the entire source source is compressed. The memory for the +// destination image is allocated using XMemAlloc(). The Qs parameter controls +// the amount of compression. The source format must be linear - no tiling +// operations will be performed. + +HRESULT WINAPI XGPTCCompressSurface( + __deref_out_bcount(*pDstSize) + VOID** ppDestination, // Returned base address of the destination (PTC compressed) image + __out UINT* pDstSize, // Returned size of the desination (PTC compressed) image in bytes + __in CONST VOID* pSource, // Base address of the source (uncompressed) image + UINT SrcRowPitch, // Distance in bytes between one row of the source image and the next + UINT Width, // Width of the source image in texels + UINT Height, // Height of the source image in texels + D3DFORMAT SrcFormat, // Format of the source image + __in_opt CONST RECT* pRect, // Rectangle within the source image to compress + INT Qs // Quantization step, 4..10000000 [default = 100] + // Compression ratio increases for larger Qs + // Compression is lossless for Qs = 0 + ); + +// Compress a subrectangle from a source image into a destination image. The +// rectangle must be completely contained within the source image (no clipping). +// If pRect is NULL, the entire source source is compressed. The memory for the +// destination image is allocated using XMemAlloc(). The compression parameters +// control the amount and type of compression. The source format must be linear +// - no tiling operations will be performed. + +HRESULT WINAPI XGPTCCompressSurfaceEx( + __deref_out_bcount(*pDstSize) + VOID** ppDestination, // Returned base address of the destination (PTC compressed) image + __out UINT* pDstSize, // Returned size of the desination (PTC compressed) image in bytes + __in CONST VOID* pSource, // Base address of the source (uncompressed) image + UINT SrcRowPitch, // Distance in bytes between one row of the source image and the next + UINT Width, // Width of the source image in texels + UINT Height, // Height of the source image in texels + D3DFORMAT SrcFormat, // Format of the source image + __in_opt CONST RECT* pRect, // Rectangle within the source image to compress + __in CONST XGPTC_COMPRESSION_PARAMS* pParams // Compression parameters + ); + +// Free the memory allocated by XGPTCCompressSurface + +VOID WINAPI XGPTCFreeMemory( + __in VOID* pMemory // Address returned from XGPTCCompressSurface + ); + +// Decompress a source image into a subrectangle of a destination image. The +// rectangle, when offset by a given point into the destination, must be +// completely contained within the destination image. If pPoint is NULL, the +// offset is (0,0). The destination format must be linear - no tiling +// operations will be performed. For best performance the destination format +// should be the format returned by XGGetPTCImageDesc(). + +HRESULT WINAPI XGPTCDecompressSurface( + __out VOID* pDestination, // Base address of the destination (decompressed) image + INT DstRowPitch, // Distance in bytes between one row of the destination image and the next + UINT Width, // Width of the destination image in texels + UINT Height, // Height of the destination image in texels + D3DFORMAT DstFormat, // Format of the destination image + __in_opt CONST POINT* pPoint, // Offset in the destination image to place the decompressed image + __in_bcount(SrcSize) + CONST VOID* pSource, // Base address of the source (PTC compressed) image + UINT SrcSize // Size of the source (PTC compressed) image in bytes + ); + +// Decompress a subrectangle of the source image into a subrectangle of a destination +// image. The rectangle, when offset by a given point into the destination, must be +// completely contained within the destination image. If pPoint is NULL, the +// offset is (0,0). The destination format must be linear - no tiling +// operations will be performed. For best performance the destination format +// should be the format returned by XGGetPTCImageDesc(). A mip-level relative to +// the resolution of the base source image may be specified allowing lower resolution +// image to be decoded more quickly. The rectangle coordinates are in terms of the base +// mip-level. + +HRESULT WINAPI XGPTCDecompressSurfaceEx( + __out VOID* pDestination, // Base address of the destination (decompressed) image + INT DstRowPitch, // Distance in bytes between one row of the destination image and the next + UINT Width, // Width of the destination image in texels + UINT Height, // Height of the destination image in texels + D3DFORMAT DstFormat, // Format of the destination image + __in_opt CONST POINT* pPoint, // Offset in the destination image to place the decompressed image + __in_bcount(SrcSize) + CONST VOID* pSource, // Base address of the source (PTC compressed) image + UINT SrcSize, // Size of the source (PTC compressed) image in bytes + __in_opt CONST RECT* pRect, // Rectangle within the source image to compress + UINT MipLevel // Mip level of the source to decompress (0..4) + ); + +// Return the width, height, and format of a PTC compressed image. + +HRESULT WINAPI XGGetPTCImageDesc( + __in_bcount(SrcSize) + CONST VOID* pSource, // Base address of the PTC compressed image + UINT SrcSize, // Size of the PTC compressed image in bytes + __out UINT* pWidth, // Width of the PTC compressed image in texels + __out UINT* pHeight, // Height of the PTC compressed image in texels + __out D3DFORMAT* pFormat // Best format for the PTC compressed image + ); + +/**************************************************************************** + * + * MCT texture compression. + * + * MCT is a lossless and lossy image compression algorithm for DXTn, DXN, and + * CTX1 texture formats. It provides a higher level of compression than raw + * DXT storage with better decode performance relative to PTC. + * + ****************************************************************************/ + +typedef VOID* XGMCTCOMPRESSION_CONTEXT; +typedef VOID* XGMCTDECOMPRESSION_CONTEXT; + +// Flags to be used in MCT context initialization: + +#define XGMCT_BORDER 0x00000008 + +// MCT compression flags: + +#define XGCOMPRESS_MCT_CONTIGUOUS_MIP_LEVELS 0x00010000 // Compress the base and mip levels of a texture into a + // single contiguous compressed data set + +#define XGCOMPRESS_MCT_NO_ENCODER_RETRAIN 0x00020000 // Do not retrain the encoder (instead relying upon training + // from a prior texture encoding). Use of the flag will + // increase compression performance at some expense to + // resulting MCT data size. + +// Compression parameters for use with XGMCTCompressTexture and XGMCTQuantizeTexture: + +typedef struct _XGMCT_COMPRESSION_PARAMS +{ + FLOAT Quality; // Image color/normal quality control (ranges from 1.0 to 100.0, where 100.0 denotes lossless compression) + UINT LinearThreshold; // Mip levels greater in dimension than the threshold will be compressed tiled + FLOAT AlphaRef; // Alpha threshold for DXT1 transparency + INT Level; // Control for compression size vs. speed (ranges from 1 to 5: 1 to maximize speed and 5 to minimize size) + XGPOINT3D TrainingSampleSpread; // Distance between texture samples taken during training of the endoder + // (1 to 128 for x and y; 1 to 4 for z) + FLOAT AlphaQuality; // Image alpha quality control (not yet supported) +} XGMCT_COMPRESSION_PARAMS; + +// Initialize a compression context that may be used for MCT-encoding textures. + +__out XGMCTCOMPRESSION_CONTEXT WINAPI XGMCTInitializeCompressionContext( + __out_bcount(ContextSize) VOID* pContextData, + UINT ContextSize + ); + +// Destroy an MCT compression context. + +VOID WINAPI XGMCTDestroyCompressionContext( + __in XGMCTCOMPRESSION_CONTEXT Context + ); + +// Obtain the allocation size required to accomodate an MCT compression context +// capable of encoding a texture of the specified configuration. + +UINT WINAPI XGMCTGetCompressionContextSize( + D3DRESOURCETYPE ResourceType, + UINT Width, + UINT Height, + UINT Depth, + UINT LevelCount, + D3DFORMAT Format, + __in_opt CONST D3DBOX* pRegion, + DWORD Flags, + __in_opt CONST XGMCT_COMPRESSION_PARAMS* pMctParams + ); + +// Compress a region from a source texture (2d, cube, array, or volume) into +// encoded base and mip level data sets which may be subsequently decompressed +// into a destination texture constructed of equivalent attributes (dimensions, +// number of mip levels, etc.) but a DXTn, DNX, or CTX1 format. The source +// region, when offset by a given point into the destination texture must be +// completely contained within the texture (no clipping). If pRegion is NULL, +// the entire source texture is compressed. The given region dimensions will +// be tile-aligned for tiled formats. +// +// Note that an explicit range of mip levels may be selected for the compression +// by setting the minimum and maximum mip levels in the fetch constant of the +// given source texture. + +HRESULT WINAPI XGMCTCompressTexture( + __in_opt XGMCTCOMPRESSION_CONTEXT Context, // Compression context (use NULL to have a context created automatically) + __out_bcount_opt(*pDstBaseSize) + VOID* pDstBaseData, // Destination address for the compressed base level of the texture + __inout_opt UINT* pDstBaseSize, // In: Allocation size of pBaseData buffer; Out: Size of the compressed base level + __out_bcount_opt(*pDstMipSize) + VOID* pDstMipData, // Destination address for the compressed mip levels of the texture + __inout_opt UINT* pDstMipSize, // In: Allocation size of pMipData buffer; Out: Size of the compressed mip levels + D3DFORMAT DstFormat, // Format of the destination texture (DXTn, DXN, or CTX1) + __in D3DBaseTexture* pSrcTexture, // Source texture containing the data to compress + __in_opt CONST D3DBOX* pSrcRegion, // Region within the source texture to compress + DWORD Flags, // Compression flags + __in_opt CONST XGMCT_COMPRESSION_PARAMS* pParams // Compression parameters + ); + +// Quantize a region from a source texture (2d, cube, array, or volume) into +// a matching region offset within a destination texture that is constructed of equivalent +// attributes (dimensions, number of mip levels, etc.) but a DXTn, DNX, or CTX1 format. +// The source region, when offset by the given point into the destination texture must be +// completely contained within the texture (no clipping). If pRegion is NULL, +// the entire source texture is quantized. +// +// Note that the destination texture receiving the quantized region will not have any data +// outside the bounds of its individual mip levels modified (to support quantization of paired +// compressed textures). It is therefore recommended that the texture memory that will +// serve as a quantization destination be explicitly cleared on allocation for the improvement +// of any subsequent lossless compression. + +HRESULT WINAPI XGMCTQuantizeTexture( + __in_opt XGMCTCOMPRESSION_CONTEXT Context, // Compression context (use NULL to have a context created automatically) + __in D3DBaseTexture* pDstTexture, // Destination texture containing the quantized result + __in_opt CONST XGPOINT3D* pDstPoint, // Offset in the destination texture to place the quantized region + __in D3DBaseTexture* pSrcTexture, // Source texture containing the data to quantize + __in_opt CONST D3DBOX* pSrcRegion, // Region within the source texture to quantize + DWORD Flags, // Compression flags used for the quantization + __in_opt CONST XGMCT_COMPRESSION_PARAMS* pParams // Compression parameters for the quantization + ); + +// Initialize a context that may be used for decompressing MCT-encoded textures. + +__out XGMCTDECOMPRESSION_CONTEXT WINAPI XGMCTInitializeDecompressionContext( + __out_bcount(ContextSize) VOID* pContextData, + UINT ContextSize + ); + +// Destroy an MCT decompression context. + +VOID WINAPI XGMCTDestroyDecompressionContext( + __in XGMCTDECOMPRESSION_CONTEXT Context + ); + +// Obtain the allocation size required to accomodate an MCT decompression context +// capable of decoding to a texture of the specified configuration. + +UINT WINAPI XGMCTGetDecompressionContextSize( + D3DRESOURCETYPE ResourceType, + UINT Width, + UINT Height, + UINT Depth, + UINT LevelCount, + D3DFORMAT Format, + __in_opt CONST D3DBOX* pRegion, + DWORD Flags + ); + +// Decompress the region contained within the level(s) of a given data set into a +// destination texture. + +HRESULT WINAPI XGMCTDecompressTexture( + __in_opt XGMCTDECOMPRESSION_CONTEXT Context, // Decompression context (use NULL to have a context created automatically) + __in D3DBaseTexture* pDstTexture, // Destination texture + __in_opt CONST XGPOINT3D* pDstPoint, // Offset in the destination texture to place the compressed region + __in_bcount(SrcMctSize) CONST VOID* pSrcMctData, // Address of the data set containing one or more MCT-encoded levels of the texture + UINT SrcMctSize, // Size of the compressed MCT data set + DWORD Flags // Compression flags + ); + +// Obtain a description of the texture, the range of mip levels, and the region +// that was encoded to produce the given MCT data. + +VOID WINAPI XGMCTGetDesc( + __in_bcount(MctSize) + CONST VOID* pMctData, + UINT MctSize, + __out_opt XGTEXTURE_DESC* pDesc, + __out_opt UINT* pMipLevelCount, + __out_opt UINT* pMinMipLevel, + __out_opt UINT* pMaxMipLevel, + __out_opt D3DBOX* pRegion + ); + +// Initialize the header of a texture resource to a type and format compatible +// with the decompression of an MCT-encoded set of data. + +UINT WINAPI XGMCTSetBaseTextureHeader( + __in_bcount(MctSize) + CONST VOID* pMctData, + UINT MctSize, + DWORD Usage, + DWORD Flags, + UINT BaseOffset, + UINT MipOffset, + UINT Pitch, + __out_opt D3DBaseTexture* pTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +/**************************************************************************** + * + * ZTC texture compression. + * + ****************************************************************************/ + +// Compressed texture format flags + +#define ZTC_FORMAT_FLAG_16BPP (1<<0) +#define ZTC_FORMAT_FLAG_A8 (1<<1) +#define ZTC_FORMAT_FLAG_A1 (1<<2) +#define ZTC_FORMAT_FLAG_1CH (0<<3) +#define ZTC_FORMAT_FLAG_2CH (1<<3) +#define ZTC_FORMAT_FLAG_3CH (2<<3) +#define ZTC_FORMAT_FLAG_4CH (3<<3) +#define ZTC_FORMAT_FLAG_DATA (1<<5) + +#define ZTC_FORMAT_GET_CHANNELS(format) ((((format) >> 3) & 3) + 1) + + +// Compressed texture formats + +#define ZTC_FORMAT_R8G8B8 ZTC_FORMAT_FLAG_3CH // Color texture without alpha +#define ZTC_FORMAT_A8R8G8B8 (ZTC_FORMAT_FLAG_A8 | ZTC_FORMAT_FLAG_4CH) // Color texture with 8 bit alpha +#define ZTC_FORMAT_A1R8G8B8 (ZTC_FORMAT_FLAG_A1 | ZTC_FORMAT_FLAG_4CH) // Color texture with 1 bit alpha +#define ZTC_FORMAT_R5G6B5 (ZTC_FORMAT_FLAG_16BPP | ZTC_FORMAT_FLAG_3CH) // Color texture without alpha +#define ZTC_FORMAT_A8R5G6B5 (ZTC_FORMAT_FLAG_16BPP | ZTC_FORMAT_FLAG_A8 | ZTC_FORMAT_FLAG_4CH) // Color texture with 8 bit alpha +#define ZTC_FORMAT_A1R5G6B5 (ZTC_FORMAT_FLAG_16BPP | ZTC_FORMAT_FLAG_A1 | ZTC_FORMAT_FLAG_4CH) // Color texture with 1 bit alpha +#define ZTC_FORMAT_Y8 ZTC_FORMAT_FLAG_1CH // Grey scale texture +#define ZTC_FORMAT_D8 (ZTC_FORMAT_FLAG_DATA | ZTC_FORMAT_FLAG_1CH) // Data textures +#define ZTC_FORMAT_D8D8 (ZTC_FORMAT_FLAG_DATA | ZTC_FORMAT_FLAG_2CH) +#define ZTC_FORMAT_D8D8D8 (ZTC_FORMAT_FLAG_DATA | ZTC_FORMAT_FLAG_3CH) +#define ZTC_FORMAT_D8D8D8D8 (ZTC_FORMAT_FLAG_DATA | ZTC_FORMAT_FLAG_4CH) + + +typedef struct +{ + DWORD Width; // Texture width in pixels + DWORD Pitch; // Texture pitch in bytes + DWORD Height; // Texture height in pixels + DWORD Format; // One of the compression formats +} ZTCTextureInfo; + +typedef struct +{ + DWORD Quality; // Quality percentage 0..100 for color and data channels + DWORD AlphaQuality; // Quality percentage 0..100 for alpha channels + BOOL SubsampleColor; // Subsample the color (UV) channels by 2x2. This has no effect on data textures. +} ZTCQuality; + + +//----------------------------------------------------------------------------- +// Initialize ZTC compressor. This function will allocate all necessary memory +// based on the given maximum texture dimensions in pixels. +//----------------------------------------------------------------------------- +HRESULT WINAPI XGZTCInitializeCompressionContext( + __out VOID** ppCompressionContext, + DWORD MaxWidth, + DWORD MaxHeight); + + +//----------------------------------------------------------------------------- +// Compress pTexture to pCompressedTexture. dwCompressedSize is both an input +// and output parameter. pTexture must be power of two size and must be +// in the specified ZTC_FORMAT format. All 3 byte per pixel formats require a +// 4 byte per pixel buffer. Use the XGZTCGetBytesPerPixel function to allocate +// the proper buffer. +//----------------------------------------------------------------------------- +HRESULT WINAPI XGZTCCompressTexture( + __in VOID* pCompressionContext, + __out_bcount_opt(*pCompressedSize) + BYTE* pCompressedTexture, + __inout DWORD* CompressedSize, + __in_bcount(pTextureInfo->Pitch*pTextureInfo->Height) + CONST BYTE* pTexture, + __in CONST ZTCTextureInfo* pTextureInfo, + __in CONST ZTCQuality* pQuality); + + +//----------------------------------------------------------------------------- +// Free the compression context. +//----------------------------------------------------------------------------- +VOID WINAPI XGZTCDestroyCompressionContext( + __in VOID* pCompressionContext); + + +//----------------------------------------------------------------------------- +// Initialize ZTC decompressor. This function does not allocate any memory. +//----------------------------------------------------------------------------- +HRESULT WINAPI XGZTCInitializeDecompression(); + + +//----------------------------------------------------------------------------- +// Retrieve the texture information from the compressed texture data. +//----------------------------------------------------------------------------- +HRESULT WINAPI XGZTCGetTextureInfo( + __in_bcount(CompressedSize) + CONST BYTE* pCompressedTexture, + DWORD CompressedSize, + __out ZTCTextureInfo* pTextureInfo); + + +//----------------------------------------------------------------------------- +// Decompress the texture from pCompressedTexture to pTexture. All 3 byte per +// pixel formats require a 4 byte per pixel buffer. Use the +// XGZTCGetBytesPerPixel function to allocate the proper buffer. +//----------------------------------------------------------------------------- +HRESULT WINAPI XGZTCDecompressTexture( + __out_bcount(TextureSize) + BYTE* pTexture, + DWORD TextureSize, + __in_bcount(CompressedSize) + CONST BYTE* pCompressedTexture, + DWORD CompressedSize); + + +//----------------------------------------------------------------------------- +// Returns the number of bytes per pixel required for the input or output +// texture for each compression texture format. +//----------------------------------------------------------------------------- +DWORD WINAPI XGZTCGetBytesPerPixel( + DWORD Format); + + +/**************************************************************************** + * + * Texture conversion. + * + ****************************************************************************/ + +// Copy a subrectangle from a source image into a destination image, converting +// from the source format into the destination format. The rectangle, +// when offset by a given point into the destination, must be +// completely contained within the destination image (no clipping). +// If pPoint and pRect are both NULL, the source and destination images +// are assumed to have the same dimensions and the entire image is copied. +// Both source and destination formats must be linear - no tiling operations +// will be performed. Compressed formats are allowed for both source and +// destination (the XGCOMPRESS_ flags may be used to direct the compression and/or +// decompression). + +HRESULT WINAPI XGCopySurface( + __out VOID* pDestination, // Base address of the destination image + INT DstRowPitch, // Distance in bytes between one row of the destination image and the next + UINT Width, // Width of the destination image in texels + UINT Height, // Height of the destination image in texels + D3DFORMAT DstFormat, // Format of the destination image + __in_opt CONST POINT* pPoint, // Offset in the destination image to place the copied rectangle + __in CONST VOID* pSource, // Base address of the source image + INT SrcRowPitch, // Distance in bytes between one row of the source image and the next + D3DFORMAT SrcFormat, // Format of the source image + __in_opt CONST RECT* pRect, // Rectangle within the source image to copy + DWORD Flags, // Conversion flags + FLOAT Threshold); // Threshold for 1 bit components + +// Copy a box from a source volume into a destination volume, converting from +// the source format into the destination format. The box, when offset +// by a given point into the destination, must be completely contained within +// the destination volume (no clipping). If pPoint and pBox are both NULL, the +// source and destination volumes are assumed to have the same dimensions +// and the entire volume is copied. + +HRESULT WINAPI XGCopyVolume( + __out VOID* pDestination, // Base address of the destination volume + INT DstRowPitch, // Distance in bytes between one row of the destination volume and the next + INT DstSlicePitch, // Distance in bytes between one slice of the destination volume and the next + UINT Width, // Width of the destination volume in texels + UINT Height, // Height of the destination volume in texels + UINT Depth, // Depth of the destination volume in texels + D3DFORMAT DstFormat, // Format of the destination volume + __in_opt CONST XGPOINT3D* pPoint, // Offset in the destination volume to place the copied box + __in CONST VOID* pSource, // Base address of the source volume + INT SrcRowPitch, // Distance in bytes between one row of the source volume and the next + INT SrcSlicePitch, // Distance in bytes between one slice of the source volume and the next + D3DFORMAT SrcFormat, // Format of the source volume + __in_opt CONST D3DBOX* pBox, // Box within the source volume to copy + DWORD Flags, // Conversion flags + FLOAT Threshold); // Threshold for 1 bit components + +/**************************************************************************** + * + * Endian reversals. + * + ****************************************************************************/ + +// Functions to perform endian reversals on given data: These routines do not +// support endian swaps between closely overlapped source and destination memory, +// where the memory addresses are closer to one another than the data size of the +// reversal being peformed (without being equal). For instance, a reversal +// using XGENDIAN_8IN32 could be performed on source and destination memory +// addresses that are either equal (i.e. in place) or separated by at least +// 32 bits. + +// IMPORTANT NOTE: These routines are provided for resource bundling tools and +// development time conversions (secondarily, as an aid in early resource porting). +// They should not be used at runtime in a final build. + +#define XGENDIANTYPE_DATA_SIZE_MASK 0xFFFF0000 +#define XGENDIANTYPE_DATA_SIZE_SHIFT 16 + +#define XGENDIANTYPE_ELEMENT_SIZE_MASK 0x0000FFFF +#define XGENDIANTYPE_ELEMENT_SIZE_SHIFT 0 + +#define MAKE_XGENDIANTYPE(ElementSize, DataSize) (((ElementSize) << XGENDIANTYPE_ELEMENT_SIZE_SHIFT) | \ + ((DataSize) << XGENDIANTYPE_DATA_SIZE_SHIFT)) + +#define XGENDIANTYPE_SET(ElementSize, DataSize) ((XGENDIANTYPE)(MAKE_XGENDIANTYPE((ElementSize), (DataSize)))) +#define XGENDIANTYPE_GET_DATA_SIZE(Type) (((Type) & XGENDIANTYPE_DATA_SIZE_MASK) >> XGENDIANTYPE_DATA_SIZE_SHIFT) +#define XGENDIANTYPE_GET_ELEMENT_SIZE(Type) (((Type) & XGENDIANTYPE_ELEMENT_SIZE_MASK) >> XGENDIANTYPE_ELEMENT_SIZE_SHIFT) + +// Predefined endian swap types (custom types may be defined with XGENDIANTYPE_SET using power-of-two sizes). + +typedef enum +{ + XGENDIAN_NONE = MAKE_XGENDIANTYPE(0, 0), + XGENDIAN_8IN16 = MAKE_XGENDIANTYPE(1, 2), + XGENDIAN_8IN32 = MAKE_XGENDIANTYPE(1, 4), + XGENDIAN_16IN32 = MAKE_XGENDIANTYPE(2, 4), + XGENDIAN_8IN64 = MAKE_XGENDIANTYPE(1, 8), + XGENDIAN_16IN64 = MAKE_XGENDIANTYPE(2, 8), + XGENDIAN_32IN64 = MAKE_XGENDIANTYPE(4, 8), + XGENDIAN_8IN128 = MAKE_XGENDIANTYPE(1, 16), + XGENDIAN_16IN128 = MAKE_XGENDIANTYPE(2, 16), + XGENDIAN_32IN128 = MAKE_XGENDIANTYPE(4, 16), + XGENDIAN_64IN128 = MAKE_XGENDIANTYPE(8, 16), +} XGENDIANTYPE; + +// Endian reverse the elements of a single block of data. + +VOID WINAPI XGEndianSwapData( + __out VOID* pDestination, + __in CONST VOID* pSource, + XGENDIANTYPE SwapType + ); + +// Endian reverse the elements of an array of data blocks. + +VOID WINAPI XGEndianSwapMemory( + __out_bcount(abs(Stride)*Count) VOID* pDestination, + __in_bcount(abs(Stride)*Count) CONST VOID* pSource, + XGENDIANTYPE SwapType, + INT Stride, + UINT Count + ); + +// Endian reverse the elements of an array of composite data. This may be used to +// swap the elements of an array of structures composed of heterogenous data types. +// For instance a structure composed of an unsigned integer and an unsigned short +// could be endian reversed by defining a type list of two entries: XGENDIAN_8IN32 +// and XGENDIAN_8IN16. + +VOID WINAPI XGEndianSwapCompositeMemory( + __out_bcount(abs(Stride)*SwapCount) VOID* pDestination, + __in_bcount(abs(Stride)*SwapCount) CONST VOID* pSource, + __in_ecount(TypeCount) CONST XGENDIANTYPE* pTypeList, + UINT TypeCount, + INT Stride, + UINT SwapCount + ); + +// Endian reverse the texel data contained in a surface resource (based on the texel format). + +VOID WINAPI XGEndianSwapSurface( + __out VOID* pDestination, + UINT RowPitchDst, + __in CONST VOID* pSource, + UINT RowPitchSrc, + UINT Width, + UINT Height, + D3DFORMAT Format + ); + +// Endian reverse the texel data contained in a volume resource (based on the texel format). + +VOID WINAPI XGEndianSwapVolume( + __out VOID* pDestination, + UINT RowPitchDst, + UINT SlicePitchDst, + __in CONST VOID* pSource, + UINT RowPitchSrc, + UINT SlicePitchSrc, + UINT Width, + UINT Height, + UINT Depth, + D3DFORMAT Format + ); + +// Endian reverse the vertex elements in a vertex buffer resource. The vertex elements are +// identified by an array of D3DVERTEXELEMENT9 structures and referenced by a stream index. +// In this way, a single array of vertex elements defined for multiple vertex buffers (and used +// in the construction of a vertex declaration) may be used to endian reverse all of the +// vertex buffers by simply changing the stream index. + +VOID WINAPI XGEndianSwapVertexBuffer( + __out_bcount(Stride*VertexCount) VOID* pDestination, + __in_bcount(Stride*VertexCount) CONST VOID* pSource, + __in D3DVERTEXELEMENT9* pElementList, + WORD StreamIndex, + UINT Stride, + UINT VertexCount + ); + +// Endian reverse the indices within an index buffer resource. + +VOID WINAPI XGEndianSwapIndexBuffer( + __out VOID* pDestination, + __in CONST VOID* pSource, + D3DFORMAT Format, + UINT IndexCount + ); + +// Endian reverse the header of an IDirect3DSurface9 resource. + +__inline VOID WINAPI XGEndianSwapSurfaceHeader( + __inout IDirect3DSurface9* pSurface) +{ + XGEndianSwapMemory(pSurface, pSurface, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DSurface) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DTexture9 resource. + +__inline VOID WINAPI XGEndianSwapTextureHeader( + __inout IDirect3DTexture9* pTexture) +{ + XGEndianSwapMemory(pTexture, pTexture, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DTexture) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DArrayTexture9 resource. + +__inline VOID WINAPI XGEndianSwapArrayTextureHeader( + __inout IDirect3DArrayTexture9* pTexture) +{ + XGEndianSwapMemory(pTexture, pTexture, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DArrayTexture) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DCubeTexture9 resource. + +__inline VOID WINAPI XGEndianSwapCubeTextureHeader( + __inout IDirect3DCubeTexture9* pTexture) +{ + XGEndianSwapMemory(pTexture, pTexture, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DCubeTexture) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DVolumeTexture9 resource. + +__inline VOID WINAPI XGEndianSwapVolumeTextureHeader( + __inout IDirect3DVolumeTexture9* pTexture) +{ + XGEndianSwapMemory(pTexture, pTexture, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DVolumeTexture) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DLineTexture9 resource. + +__inline VOID WINAPI XGEndianSwapLineTextureHeader( + __inout IDirect3DLineTexture9* pTexture) +{ + XGEndianSwapMemory(pTexture, pTexture, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DLineTexture) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DVertexBuffer9 resource. + +__inline VOID WINAPI XGEndianSwapVertexBufferHeader( + __inout IDirect3DVertexBuffer9* pVertexBuffer) +{ + XGEndianSwapMemory(pVertexBuffer, pVertexBuffer, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DVertexBuffer) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DIndexBuffer9 resource. + +__inline VOID WINAPI XGEndianSwapIndexBufferHeader( + __inout IDirect3DIndexBuffer9* pIndexBuffer) +{ + XGEndianSwapMemory(pIndexBuffer, pIndexBuffer, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DIndexBuffer) / sizeof(DWORD)); +} + +// Endian reverse the header of an IDirect3DConstantBuffer9 resource. + +__inline VOID WINAPI XGEndianSwapConstantBufferHeader( + __inout IDirect3DConstantBuffer9* pConstantBuffer) +{ + XGEndianSwapMemory(pConstantBuffer, pConstantBuffer, XGENDIAN_8IN32, sizeof(DWORD), sizeof(D3DConstantBuffer) / sizeof(DWORD)); +} + +/**************************************************************************** + * + * Resource header initialization. + * + ****************************************************************************/ + +// For texture, cube texture, and volume texture header initialization, +// the BaseOffset and MipOffset parameters are used to provide offsets to the +// base mip level data and remaining mip level data (if any), respectively +// for the texture. These offsets are later applied to base memory addresses +// given in a subsequent call to XGOffsetResourceAddress or +// XGOffsetMipTextureAddress. However, BaseOffset and MipOffset could also +// be used to set explicit memory addresses during header initialization +// with no subsequent offset required. + +// When the MipOffset parameter is set to XGHEADER_CONTIGUOUS_MIP_OFFSET, +// the calculated size of the base mip level will be added to the value +// given in the BaseOffset parameter and the sum will be set as the offset +// for the remaining mip levels. The MipOffset parameter is ignored for +// textures with a single mip level. + +// The total memory size required to hold the texel data (including all +// mip levels) is returned from the texture initialization functions. +// The size of the highest resolution mip level is returned separately in +// the pBaseSize parameter and the size of the remaining mip levels is +// returned in pMipSize. + +#define XGHEADER_CONTIGUOUS_MIP_OFFSET 0xFFFFFFFF + +#define XGHEADEREX_NONPACKED 0x1 +#define XGHEADEREX_BORDER 0x2 + +// Initialize the header of an EDRAM surface resource and return the size of +// the EDRAM allocation required for the specified surface in units of EDRAM tiles. + +UINT WINAPI XGSetSurfaceHeader( + UINT Width, + UINT Height, + D3DFORMAT Format, + D3DMULTISAMPLE_TYPE MultiSampleType, + __in CONST D3DSURFACE_PARAMETERS* pParameters, + __out_opt IDirect3DSurface9* pSurface, + __out_opt UINT* pHierarchicalZSize + ); + +// Initialize the header of a 2D texture resource. The Pitch parameter may be +// used to set the stride for textures with a single mip level. The value +// provided must conform to the alignment restrictions for the specific +// texture to be initialized. A Pitch value of zero causes the default +// (minimum) pitch calculated for the texture to be used. + +UINT WINAPI XGSetTextureHeader( + UINT Width, + UINT Height, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + UINT BaseOffset, + UINT MipOffset, + UINT Pitch, + __out_opt IDirect3DTexture9* pTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +UINT WINAPI XGSetTextureHeaderEx( + UINT Width, + UINT Height, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + INT ExpBias, + DWORD Flags, + UINT BaseOffset, + UINT MipOffset, + UINT Pitch, + __out_opt IDirect3DTexture9* pTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize a pair of interleaved compressed 2D texture resources that +// will occupy a shared memory space in order to conserve the amount required. + +UINT WINAPI XGSetTextureHeaderPair( + UINT BaseOffset, + UINT MipOffset, + UINT Width1, + UINT Height1, + UINT Levels1, + DWORD Usage1, + D3DFORMAT Format1, + INT ExpBias1, + DWORD Flags1, + UINT Pitch1, + __out_opt IDirect3DTexture9* pTexture1, + UINT Width2, + UINT Height2, + UINT Levels2, + DWORD Usage2, + D3DFORMAT Format2, + INT ExpBias2, + DWORD Flags2, + UINT Pitch2, + __out_opt IDirect3DTexture9* pTexture2, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize the header of a line (1D) texture resource. + +UINT WINAPI XGSetLineTextureHeader( + UINT Width, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + UINT BaseOffset, + UINT MipOffset, + __out_opt IDirect3DLineTexture9* pTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +UINT WINAPI XGSetLineTextureHeaderEx( + UINT Width, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + INT ExpBias, + DWORD Flags, + UINT BaseOffset, + UINT MipOffset, + __out_opt IDirect3DLineTexture9* pTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize the header of a cube texture resource. + +UINT WINAPI XGSetCubeTextureHeader( + UINT EdgeLength, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + UINT BaseOffset, + UINT MipOffset, + __out_opt IDirect3DCubeTexture9* pCubeTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +UINT WINAPI XGSetCubeTextureHeaderEx( + UINT EdgeLength, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + INT ExpBias, + DWORD Flags, + UINT BaseOffset, + UINT MipOffset, + __out_opt IDirect3DCubeTexture9* pCubeTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize a pair of interleaved compressed cube texture resources that +// will occupy a shared memory space in order to conserve the amount required. + +UINT WINAPI XGSetCubeTextureHeaderPair( + UINT BaseOffset, + UINT MipOffset, + UINT EdgeLength1, + UINT Levels1, + DWORD Usage1, + D3DFORMAT Format1, + INT ExpBias1, + DWORD Flags1, + __out_opt IDirect3DTexture9* pCubeTexture1, + UINT EdgeLength2, + UINT Levels2, + DWORD Usage2, + D3DFORMAT Format2, + INT ExpBias2, + DWORD Flags2, + __out_opt IDirect3DTexture9* pCubeTexture2, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize the header of an array texture resource. + +UINT WINAPI XGSetArrayTextureHeader( + UINT Width, + UINT Height, + UINT ArraySize, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + UINT BaseOffset, + UINT MipOffset, + UINT Pitch, + __out_opt IDirect3DArrayTexture9* pArrayTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +UINT WINAPI XGSetArrayTextureHeaderEx( + UINT Width, + UINT Height, + UINT ArraySize, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + INT ExpBias, + DWORD Flags, + UINT BaseOffset, + UINT MipOffset, + UINT Pitch, + __out_opt IDirect3DArrayTexture9* pArrayTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize a pair of interleaved compressed array texture resources that +// will occupy a shared memory space in order to conserve the amount required. + +UINT WINAPI XGSetArrayTextureHeaderPair( + UINT BaseOffset, + UINT MipOffset, + UINT Width1, + UINT Height1, + UINT ArraySize1, + UINT Levels1, + DWORD Usage1, + D3DFORMAT Format1, + INT ExpBias1, + DWORD Flags1, + UINT Pitch1, + __out_opt IDirect3DTexture9* pArrayTexture1, + UINT Width2, + UINT Height2, + UINT ArraySize2, + UINT Levels2, + DWORD Usage2, + D3DFORMAT Format2, + INT ExpBias2, + DWORD Flags2, + UINT Pitch2, + __out_opt IDirect3DTexture9* pArrayTexture2, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize the header of a volume texture resource. + +UINT WINAPI XGSetVolumeTextureHeader( + UINT Width, + UINT Height, + UINT Depth, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + UINT BaseOffset, + UINT MipOffset, + __out_opt IDirect3DVolumeTexture9* pVolumeTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +UINT WINAPI XGSetVolumeTextureHeaderEx( + UINT Width, + UINT Height, + UINT Depth, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + INT ExpBias, + DWORD Flags, + UINT BaseOffset, + UINT MipOffset, + __out_opt IDirect3DVolumeTexture9* pVolumeTexture, + __out_opt UINT* pBaseSize, + __out_opt UINT* pMipSize + ); + +// Initialize the header of a vertex buffer resource. + +VOID WINAPI XGSetVertexBufferHeader( + UINT Length, + DWORD Usage, + D3DPOOL Pool, + UINT Offset, + __out IDirect3DVertexBuffer9* pVertexBuffer + ); + +// Initialize the header of an index buffer resource. + +VOID WINAPI XGSetIndexBufferHeader( + UINT Length, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + UINT Offset, + __out IDirect3DIndexBuffer9* pIndexBuffer + ); + +// Initialize the header of a constants resource. + +VOID WINAPI XGSetConstantBufferHeader( + UINT VectorCount, + DWORD Usage, + UINT Offset, + __out IDirect3DConstantBuffer9* pConstantBuffer + ); + +// Add the given offset(s) to the EDRAM tile offset and/or hierarchical Z offset +// stored in the surface header. + +VOID WINAPI XGOffsetSurfaceAddress( + __inout IDirect3DSurface9* pSurface, + INT SurfaceOffset, + INT HierarchicalZOffset + ); + +// Add the given memory address to the offset value stored in the resource header +// (in this way the resource header may be pointed at the resource data). + +VOID WINAPI XGOffsetResourceAddress( + __inout IDirect3DResource9* pResource, + __in_opt VOID* pBaseAddress + ); + +// Add the given memory addresses to the offsets stored in the mip map header. +// The pMipAddress parameter is ignored for textures with a single mip level. + +VOID WINAPI XGOffsetBaseTextureAddress( + __inout IDirect3DBaseTexture9* pTexture, + __in_opt VOID* pBaseAddress, + __in_opt VOID* pMipAddress + ); + +/**************************************************************************** +* +* Shader utilities +* +****************************************************************************/ + +typedef enum { + XGUCODESHADERVERSION_PIXEL = 0, + XGUCODESHADERVERSION_VERTEX = 1, +} XGUCODESHADERVERSION; + +typedef struct _XGSHADER_CONSTANT_MASKS +{ + // The MSB of the ALU constants is for constants 0-3 and the LSB is + // for constants 252-255: + + UINT64 u64BitAluConstants; + + // If the MSB is defined as bit zero, then bit 0 is for integer constant 0 + // and bit 31 is for integer constant 31. Bit 32 is for boolean constants + // 0-31 and bit 39 is for boolean constants 224-255: + + UINT64 u64BitFlowConstants; +} XGSHADER_CONSTANT_MASKS; + +VOID WINAPI XGPixelShaderGetDefinedConstantMasks( + __in D3DDevice *pDevice, + __in D3DPixelShader* pPixelShader, + __out XGSHADER_CONSTANT_MASKS* pShaderConstantMasks); + +VOID WINAPI XGVertexShaderGetDefinedConstantMasks( + __in D3DDevice *pDevice, + __in D3DVertexShader* pVertexShader, + __out XGSHADER_CONSTANT_MASKS* pShaderConstantMasks); + +VOID WINAPI XGShaderMicrocodeGetDefinedConstantMasks( + __in const DWORD* pShaderMicrocode, + XGUCODESHADERVERSION ShaderVersion, + __out XGSHADER_CONSTANT_MASKS* pShaderConstantMasks); + +typedef struct _XGSHADER_FETCHCONSTANT_MASKS +{ + // The MSB of the texture fetch constant is for constant tf0 and + // the LSB is for constant tf31 + UINT32 u32TextureFetchConstants; + + // The MSB of vertex fetch constant[0] is for constant vf0 + // and the LSB of vertex fetch constant[2] is for constant vf95 + UINT32 u32VertexFetchConstants[3]; +} XGSHADER_FETCHCONSTANT_MASKS; + +VOID WINAPI XGPixelShaderGetFetchConstantMasks( + __in D3DDevice *pDevice, + __in D3DPixelShader* pPixelShader, + __out XGSHADER_FETCHCONSTANT_MASKS* pShaderFetchConstantMasks); + +VOID WINAPI XGVertexShaderGetFetchConstantMasks( + __in D3DDevice *pDevice, + __in D3DVertexShader* pVertexShader, + __out XGSHADER_FETCHCONSTANT_MASKS* pShaderFetchConstantMasks); + +VOID WINAPI XGShaderMicrocodeGetFetchConstantMasks( + __in const DWORD* pShaderMicrocode, + XGUCODESHADERVERSION ShaderVersion, + __out XGSHADER_FETCHCONSTANT_MASKS* pShaderFetchConstantMasks); + +typedef struct _XGUCODE_PASS_DESCRIPTION +{ + GPU_PROGRAMCONTROL ProgramControl; + GPU_CONTEXTMISC ContextMisc; + DWORD PhysicalMicrocodeOffset; + DWORD PhysicalMicrocodeSize; +} XGUCODE_PASS_DESCRIPTION; + +typedef struct _XGUCODE_DESCRIPTION +{ + BOOL IsPixelShader; + DWORD PassCount; + XGUCODE_PASS_DESCRIPTION Pass[2]; +} XGUCODE_DESCRIPTION; + +VOID WINAPI XGGetMicrocodeDescription( + __in LPCVOID pShaderMicrocode, + __out XGUCODE_DESCRIPTION* pDescription); + +//------------------------------------------------------------------------------------ +// XGConvertDXTokensToMicrocode + +#define XGCUCODE_SKIPOPTIMIZATION 0x00000008 // Do not optimize the microcode + +typedef VOID (WINAPI *XGConvertDXTokensToMicrocodeErrorCallbackFunction)( + __inout_opt LPVOID pErrorCallbackContext, + BOOL isError, + DWORD errorNumber, + __in_z LPCSTR message); + +// pInput - pointer to D3D shader tokens. +// cbInputSize size of pInput, in bytes +// pOutput - pointer to buffer that will receive microcode +// cbOutputSize - size of output buffer +// pcbOutputUsed - pointer to DWORD that holds number of bytes of output buffer +// that are actually used. +// flags - use to pass flags in to control the way the shader tokens +// are converted into microcode. (If no GPU flags are specified, +// a fat shader with microcode for all GPUs will be produced.) +// pErrorCallbackContext - This argument is passed unchanged to the pErrorCallbackFunction +// pErrorCallbackFunction - this function is called when an error or warning is encountered. +// (the pErrorCallbackFunction can be NULL.) +// pConstantTable - this shader's constant table, can be NULL. +// tempRegisterLimit - the maximum number of temp registers allowed in this microcode. + + +typedef struct ID3DXConstantTable *LPD3DXCONSTANTTABLE; + +HRESULT WINAPI XGConvertDXTokensToMicrocode( + __in_bcount(cbInputSize) + const DWORD* pInput, + DWORD cbInputSize, + __out_bcount_part(cbOutputSize, *pcbOutputUsed) + DWORD* pOutput, + DWORD cbOutputSize, + __out DWORD* pcbOutputUsed, + DWORD flags, + __inout_opt LPVOID pErrorCallbackContext, + __in_opt XGConvertDXTokensToMicrocodeErrorCallbackFunction pErrorCallbackFunction, + __in_opt LPD3DXCONSTANTTABLE pConstantTable, + DWORD tempRegisterLimit); + + +// Split a microcode shader into cached and physical parts + +typedef struct _XGMICROCODESHADERPARTS { + VOID* pCachedPart; + DWORD cbCachedPartSize; // Size in bytes + VOID* pPhysicalPart; + DWORD cbPhysicalPartSize; // Size in bytes +} XGMICROCODESHADERPARTS; + +VOID WINAPI XGGetMicrocodeShaderParts( + __in LPCVOID pFunction, + __out XGMICROCODESHADERPARTS* pParts); + +// Shader physical memory must be aligned on a 32-byte boundary. + +#define D3DSHADER_ALIGNMENT 32 + +VOID WINAPI XGSetPixelShaderHeader( + __out_bcount(cbShaderSize) + IDirect3DPixelShader9* pShader, + DWORD cbShaderSize, + __in const XGMICROCODESHADERPARTS* pParts); + +VOID WINAPI XGCopyNativeToUCodePixelShaderHeader( + __in const IDirect3DPixelShader9* pShader, + __out_bcount(cbBufferSize) LPVOID pBuffer, + DWORD cbBufferSize); + +// Note: Physical pixel shader data must +// be allocated out of write-combined physical memory. + +VOID WINAPI XGRegisterPixelShader( + __inout IDirect3DPixelShader9* pShader, + __in VOID* pPhysicalPart); + +VOID WINAPI XGSetVertexShaderHeader( + __out_bcount(cbShaderSize) + IDirect3DVertexShader9* pShader, + DWORD cbShaderSize, + __in const XGMICROCODESHADERPARTS* pParts); + +VOID WINAPI XGCopyNativeToUCodeVertexShaderHeader( + __in const IDirect3DVertexShader9* pShader, + __out_bcount(cbBufferSize) LPVOID pBuffer, + DWORD cbBufferSize); + +// Note: Physical vertex shader data must +// be allocated out of cached physical memory. + +VOID WINAPI XGRegisterVertexShader( + __inout IDirect3DVertexShader9* pShader, + __in VOID* pPhysicalPart); + +#ifndef __D3DX9SHADER_H__ +struct _D3DXSHADER_CONSTANTTABLE; +typedef struct _D3DXSHADER_CONSTANTTABLE D3DXSHADER_CONSTANTTABLE; +#endif + +HRESULT WINAPI XGCreateConstantTable( + __in_bcount(ConstantTableDataSize) CONST D3DXSHADER_CONSTANTTABLE* pNativeConstantTableData, + DWORD ConstantTableDataSize, + __deref_out LPD3DXCONSTANTTABLE* ppConstantTable); + +HRESULT WINAPI XGMicrocodeGetConstantTable( + __in CONST VOID* pFunction, + __deref_out_bcount(*pConstantTableSize) CONST D3DXSHADER_CONSTANTTABLE** ppUCodeConstantTable, + __out DWORD* pConstantTableSize); + +VOID WINAPI XGCopyUCodeToNativeConstantTable( + __in_bcount(ConstantTableSize) CONST D3DXSHADER_CONSTANTTABLE* pSrcUCodeConstantTable, + __out_bcount(ConstantTableSize) D3DXSHADER_CONSTANTTABLE* pDestNativeConstantTable, + DWORD ConstantTableSize); + +HRESULT WINAPI XGMicrocodeDeleteConstantTable( + __in CONST VOID* pFunction, + __out_bcount_part(UpdatedFunctionBufferSize, *pUpdatedFunctionSize) + VOID* pUpdatedFunctionBuffer, + DWORD UpdatedFunctionBufferSize, + __out DWORD* pUpdatedFunctionSize); + + +// Literal table constant enumeration and removal + +#define XGMELCF_TYPE_IS_BOOL 0 +#define XGMELCF_TYPE_IS_FLOAT 1 +#define XGMELCF_TYPE_IS_INT 2 + +typedef HRESULT (WINAPI *XGMicrocodeEnumerateLiteralsCallbackFunction)( + __inout_opt VOID* pContext, + DWORD PassIndex, // UCODE_PASS_INDEX + DWORD Type, // XGMELCCF_TYPE + DWORD Index, + __in CONST VOID* pData); + +HRESULT WINAPI XGMicrocodeEnumerateLiterals( + __in CONST VOID* pFunction, + __inout_opt VOID* pContext, + __in XGMicrocodeEnumerateLiteralsCallbackFunction pCallbackFunction); + +#define XGMDL_DELETE_BOOL_LITERALS (1 << 0) +#define XGMDL_DELETE_FLOAT_LITERALS (1 << 1) +#define XGMDL_DELETE_INT_LITERALS (1 << 2) + +HRESULT WINAPI XGMicrocodeDeleteLiterals( + __in CONST VOID* pFunction, + DWORD Flags, // XGMDL flags. Passing zero will delete all constant types. + __out_bcount_part_opt(UpdatedFunctionBufferSize, *pUpdatedFunctionSize) + VOID* pUpdatedFunctionBuffer, + DWORD UpdatedFunctionBufferSize, + __out DWORD* pUpdatedFunctionSize); + + +// Functions for managing collections of shaders. + +#define XGMCS_IGNORE_DEBUG_INFO 0x1 + +// Returns <0, 0, or >0, depending upon whether pFunctionA is <, ==, or > pFunctionB + +INT WINAPI XGMicrocodeCompareShaders( + __in CONST VOID* pFunctionA, + __in CONST VOID* pFunctionB, + DWORD Flags); // XGMCS_* + +INT WINAPI XGMicrocodeHashShader( + __in CONST VOID* pFunction, + DWORD Flags); + +HRESULT WINAPI XGMicrocodeDeleteDebugInfo( + __in CONST VOID* pFunction, + __out_bcount_part_opt(UpdatedFunctionBufferSize, *pUpdatedFunctionSize) + VOID* pUpdatedFunctionBuffer, + DWORD UpdatedFunctionBufferSize, + __out DWORD* pUpdatedFunctionSize); + +// VertexDeclaration utilities + +UINT WINAPI XGGetVertexDeclarationSize( + __in CONST D3DVERTEXELEMENT9* pVertexElements); + +VOID WINAPI XGSetVertexDeclaration( + __in CONST D3DVERTEXELEMENT9* pVertexElements, + __out D3DVertexDeclaration* pVertexDeclaration); + +VOID WINAPI XGEndianSwapVertexDeclaration( + __inout D3DVertexDeclaration* pVertexDeclaration); + +VOID WINAPI XGRegisterVertexDeclaration( + __in D3DVertexDeclaration* pVertexDeclaration); + + +// Returns <0, 0, or >0, depending upon whether pVertexDeclarationA is <, ==, or > pVertexDeclarationB + +INT WINAPI XGCompareVertexDeclarations( + __in CONST D3DVertexDeclaration* pVertexDeclarationA, + __in CONST D3DVertexDeclaration* pVertexDeclarationB); + +INT WINAPI XGHashVertexDeclaration( + __in CONST D3DVertexDeclaration* pVertexDeclaration); + +/**************************************************************************** + * + * CPU vertex processing. + * + ****************************************************************************/ + +// Values for ProcessVertices flags: + +#define D3DPV_DONOTINVALIDATECACHE 0x1 + +// CPU shader limits. + +#define XGCPUSHADER_MAX_THREADS 14 +#define XGCPUSHADER_BRANCH_DEPTH 32 +#define XGCPUSHADER_MAX_USAGE_TYPE 14 +#define XGCPUSHADER_MAX_USAGE_INDEX 16 +#define XGCPUSHADER_MAX_PREFETCHES 8 + +typedef struct _XGCPUSHADERVERTEXSTREAM +{ + DWORD BaseAddress; + WORD VertexStride; + +} XGCPUSHADERVERTEXSTREAM; + +// Disable this benign warning because it appears when compiling to x64. +// Structures are indeed identical in Xbox 360, x86 and x64. +// It is a peculiarity of the x64 compiler, which happens +// only when the __declspec(align()) is in a member. +#pragma warning(push) +#pragma warning(disable:4324) // structure was padded due to __declspec(align()) + +typedef struct _XGCPUSHADERCONTEXT +{ + // Shader Registers + + XMVECTOR v[16][XGCPUSHADER_MAX_THREADS]; // Input register + XMVECTOR o[16][XGCPUSHADER_MAX_THREADS]; // Output register + XMVECTOR r[32][XGCPUSHADER_MAX_THREADS]; // Temporary register + XMVECTOR c[256]; // Constant float register + XMVECTOR p[XGCPUSHADER_MAX_THREADS]; // Predicate register + XMVECTOR xBranchMask; // Branch select register (1 byte per thread of execution) + XMVECTOR xBreakMask; // Break mask applied to xBranchMask when it is popped off the stack + XMVECTOR xUR0; // PPC uniform register (common for all threads) + XMVECTOR xUR1; // PPC uniform register (common for all threads) + XMVECTOR xUR2; // PPC uniform register (common for all threads) + XMVECTOR xUR3; // PPC uniform register (common for all threads) + XMVECTOR xSR0[XGCPUSHADER_MAX_THREADS]; // PPC temp register (swizzling, intermediate results, etc.) + XMVECTOR xSR1[XGCPUSHADER_MAX_THREADS]; // PPC temp register (swizzling, intermediate results, etc.) + XMVECTOR xSR2[XGCPUSHADER_MAX_THREADS]; // PPC temp register (swizzling, intermediate results, etc.) + XMVECTOR xSR3[XGCPUSHADER_MAX_THREADS]; // PPC temp register (swizzling, intermediate results, etc.) + XMVECTOR xCR0; // PPC constant register (mask, byte shift, and 1.0f generation) set to <0x00000000 0xFFFFFFFF 0x00FFFFFF 1.0f> + XMVECTOR xCR1; // PPC constant register (abs, negate, and negative abs generation) set to <0x80000000 0x7FFFFFFF dc dc> + XMVECTOR xBranchMaskStack[XGCPUSHADER_BRANCH_DEPTH]; // Branch mask stack + __declspec(align(16)) INT i[32][4]; // Constant integer register + __declspec(align(8)) SHORT a[XGCPUSHADER_MAX_THREADS][4]; // Address register + INT xLoopCounterStack[XGCPUSHADER_BRANCH_DEPTH]; // Loop counter stack + INT xLoopRepeatStack[XGCPUSHADER_BRANCH_DEPTH]; // Loop repeat stack + UINT xBranchMaskStackIndex; // Index of the top of the branch mask stack + UINT xLoopCounterStackIndex; // Index of the top of the loop counter stack + UINT xLoopRepeatStackIndex; // Index of the top of the loop repeat stack + INT l; // Loop counter register + INT xLoopRepeat; // Loop repeat register (number of times to repeat a loop) + UINT xCondition; // Condition register to hold results from uniform recording comparisons + UINT64 b; // Constant boolean register + + // Stream information + + UINT VertexCount; + UINT PrefetchCount; + BOOL InvalidateCache; + + XGCPUSHADERVERTEXSTREAM PrefetchStream[XGCPUSHADER_MAX_PREFETCHES]; + XGCPUSHADERVERTEXSTREAM InputStream[XGCPUSHADER_MAX_USAGE_INDEX][XGCPUSHADER_MAX_USAGE_TYPE]; // Map from dcl_usage to location of vertex element in the stream + XGCPUSHADERVERTEXSTREAM OutputStream[XGCPUSHADER_MAX_USAGE_INDEX][XGCPUSHADER_MAX_USAGE_TYPE]; + +} XGCPUSHADERCONTEXT; + +#pragma warning(pop) + +// CPU shader function. + +typedef VOID (__cdecl *XGCPUSHADERFUNCTION)(__inout_opt XGCPUSHADERCONTEXT* XGRESTRICT pContext); + +/* + * XGCpuVertexShader + */ + +typedef struct XGCpuVertexShader XGCpuVertexShader; + +struct XGCpuVertexShader +{ +#ifdef __cplusplus + + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + +#endif // __cplusplus + + // Private internal data: + + XGCPUSHADERFUNCTION* pShaderFunction; +}; + +/* + * XGCpuShaderDevice + */ + +typedef struct XGCpuShaderDevice XGCpuShaderDevice; + +struct XGCpuShaderDevice +{ +#ifdef __cplusplus + + ULONG WINAPI AddRef(); + ULONG WINAPI Release(); + + VOID WINAPI SetVertexShader(__in XGCpuVertexShader *pShader); + VOID WINAPI GetVertexShader(__deref_out XGCpuVertexShader **ppShader); + + VOID WINAPI SetVertexDeclaration(__in D3DVertexDeclaration *pDecl); + VOID WINAPI GetVertexDeclaration(__deref_out D3DVertexDeclaration **ppDecl); + VOID WINAPI SetVertexDeclarationDest(__in D3DVertexDeclaration *pDecl); + VOID WINAPI GetVertexDeclarationDest(__deref_out D3DVertexDeclaration **ppDecl); + VOID WINAPI SetFVF(DWORD FVF); + VOID WINAPI GetFVF(__out DWORD* pFVF); + VOID WINAPI SetFVFDest(DWORD FVF); + VOID WINAPI GetFVFDest(__out DWORD* pFVF); + + VOID WINAPI SetStreamSource(UINT StreamNumber, __in D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride); + VOID WINAPI GetStreamSource(UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride); + VOID WINAPI SetStreamDest(UINT StreamNumber, __in D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride); + VOID WINAPI GetStreamDest(UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride); + + VOID WINAPI SetVertexShaderConstantB(UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount); + VOID WINAPI SetVertexShaderConstantF(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST FLOAT *pConstantData, DWORD Vector4fCount); + VOID WINAPI SetVertexShaderConstantI(UINT StartRegister, __in_ecount(4*Vector4iCount) CONST INT *pConstantData, DWORD Vector4iCount); + VOID WINAPI GetVertexShaderConstantB(UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount); + VOID WINAPI GetVertexShaderConstantF(UINT StartRegister, __out_ecount(4*Vector4fCount) FLOAT *pConstantData, DWORD Vector4fCount); + VOID WINAPI GetVertexShaderConstantI(UINT StartRegister, __out_ecount(4*Vector4iCount) INT *pConstantData, DWORD Vector4iCount); + + VOID WINAPI ProcessVertices(UINT IndexSource, UINT IndexDest, UINT VertexCount, DWORD Flags); + +#endif // __cplusplus + + // Private internal data: + + XGCPUSHADERCONTEXT ShaderContext; +}; + +/* + * XGCpuVertexShader functions and methods. + */ + +ULONG WINAPI XGCpuVertexShader_AddRef(__inout XGCpuVertexShader* pDevice); +ULONG WINAPI XGCpuVertexShader_Release(__inout XGCpuVertexShader* pDevice); + +#ifdef __cplusplus + +__forceinline ULONG WINAPI XGCpuVertexShader::AddRef() { return XGCpuVertexShader_AddRef(this); } +__forceinline ULONG WINAPI XGCpuVertexShader::Release() { return XGCpuVertexShader_Release(this); } + +#endif // __cplusplus + +/* + * XGCpuShaderDevice functions and methods. + */ + +ULONG WINAPI XGCpuShaderDevice_AddRef(__inout XGCpuShaderDevice* pDevice); +ULONG WINAPI XGCpuShaderDevice_Release(__inout XGCpuShaderDevice* pDevice); + +VOID WINAPI XGCpuShaderDevice_SetVertexShader(__in XGCpuShaderDevice* pDevice, __in XGCpuVertexShader *pShader); +__out XGCpuVertexShader* WINAPI XGCpuShaderDevice_GetVertexShader(__in XGCpuShaderDevice* pDevice); + +VOID WINAPI XGCpuShaderDevice_SetVertexDeclaration(__in XGCpuShaderDevice* pDevice, __in D3DVertexDeclaration *pDecl); +__out D3DVertexDeclaration* WINAPI XGCpuShaderDevice_GetVertexDeclaration(__in XGCpuShaderDevice* pDevice); +VOID WINAPI XGCpuShaderDevice_SetVertexDeclarationDest(__in XGCpuShaderDevice* pDevice, __in D3DVertexDeclaration *pDecl); +__out D3DVertexDeclaration* WINAPI XGCpuShaderDevice_GetVertexDeclarationDest(__in XGCpuShaderDevice* pDevice); +VOID WINAPI XGCpuShaderDevice_SetFVF(__in XGCpuShaderDevice* pDevice, DWORD FVF); +DWORD WINAPI XGCpuShaderDevice_GetFVF(__in XGCpuShaderDevice* pDevice); +VOID WINAPI XGCpuShaderDevice_SetFVFDest(__in XGCpuShaderDevice* pDevice, DWORD FVF); +DWORD WINAPI XGCpuShaderDevice_GetFVFDest(__in XGCpuShaderDevice* pDevice); + +VOID WINAPI XGCpuShaderDevice_SetStreamSource(__in XGCpuShaderDevice* pDevice, UINT StreamNumber, __in D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride); +__out D3DVertexBuffer* WINAPI XGCpuShaderDevice_GetStreamSource(__in XGCpuShaderDevice* pDevice, UINT StreamNumber, __out UINT *pOffsetInBytes, __out UINT *pStride); +VOID WINAPI XGCpuShaderDevice_SetStreamDest(__in XGCpuShaderDevice* pDevice, UINT StreamNumber, __in D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride); +__out D3DVertexBuffer* WINAPI XGCpuShaderDevice_GetStreamDest(__in XGCpuShaderDevice* pDevice, UINT StreamNumber, __out UINT *pOffsetInBytes, __out UINT *pStride); + +VOID WINAPI XGCpuShaderDevice_SetVertexShaderConstantB(__in XGCpuShaderDevice* pDevice, UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount); +VOID WINAPI XGCpuShaderDevice_SetVertexShaderConstantF(__in XGCpuShaderDevice* pDevice, UINT StartRegister, __in_ecount(4*Vector4fCount) CONST FLOAT *pConstantData, DWORD Vector4fCount); +VOID WINAPI XGCpuShaderDevice_SetVertexShaderConstantI(__in XGCpuShaderDevice* pDevice, UINT StartRegister, __in_ecount(4*Vector4iCount) CONST INT *pConstantData, DWORD Vector4iCount); +VOID WINAPI XGCpuShaderDevice_GetVertexShaderConstantB(__in XGCpuShaderDevice* pDevice, UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount); +VOID WINAPI XGCpuShaderDevice_GetVertexShaderConstantF(__in XGCpuShaderDevice* pDevice, UINT StartRegister, __out_ecount(4*Vector4fCount) FLOAT *pConstantData, DWORD Vector4fCount); +VOID WINAPI XGCpuShaderDevice_GetVertexShaderConstantI(__in XGCpuShaderDevice* pDevice, UINT StartRegister, __out_ecount(4*Vector4iCount) INT *pConstantData, DWORD Vector4iCount); + +VOID WINAPI XGCpuShaderDevice_ProcessVertices(__in XGCpuShaderDevice* pDevice, UINT IndexSource, UINT IndexDest, UINT VertexCount, DWORD Flags); + +#ifdef __cplusplus + +__forceinline ULONG WINAPI XGCpuShaderDevice::AddRef() { return XGCpuShaderDevice_AddRef(this); } +__forceinline ULONG WINAPI XGCpuShaderDevice::Release() { return XGCpuShaderDevice_Release(this); } + +__forceinline VOID WINAPI XGCpuShaderDevice::SetVertexShader(__in XGCpuVertexShader *pShader) { return XGCpuShaderDevice_SetVertexShader(this, pShader); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetVertexShader(__deref_out XGCpuVertexShader **ppShader) { *ppShader = XGCpuShaderDevice_GetVertexShader(this); } + +__forceinline VOID WINAPI XGCpuShaderDevice::SetVertexDeclaration(__in D3DVertexDeclaration *pDecl) { return XGCpuShaderDevice_SetVertexDeclaration(this, pDecl); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetVertexDeclaration(__deref_out D3DVertexDeclaration **ppDecl) { *ppDecl = XGCpuShaderDevice_GetVertexDeclaration(this); } +__forceinline VOID WINAPI XGCpuShaderDevice::SetVertexDeclarationDest(__in D3DVertexDeclaration *pDecl) { return XGCpuShaderDevice_SetVertexDeclarationDest(this, pDecl); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetVertexDeclarationDest(__deref_out D3DVertexDeclaration **ppDecl) { *ppDecl = XGCpuShaderDevice_GetVertexDeclarationDest(this); } +__forceinline VOID WINAPI XGCpuShaderDevice::SetFVF(DWORD FVF) { return XGCpuShaderDevice_SetFVF(this, FVF); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetFVF(__out DWORD* pFVF) { *pFVF = XGCpuShaderDevice_GetFVF(this); } +__forceinline VOID WINAPI XGCpuShaderDevice::SetFVFDest(DWORD FVF) { return XGCpuShaderDevice_SetFVFDest(this, FVF); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetFVFDest(__out DWORD* pFVF) { *pFVF = XGCpuShaderDevice_GetFVFDest(this); } + +__forceinline VOID WINAPI XGCpuShaderDevice::SetStreamSource(UINT StreamNumber, __in D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride) { return XGCpuShaderDevice_SetStreamSource(this, StreamNumber, pStreamData, OffsetInBytes, Stride); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetStreamSource(UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride) { *ppStreamData = XGCpuShaderDevice_GetStreamSource(this, StreamNumber, pOffsetInBytes, pStride); } +__forceinline VOID WINAPI XGCpuShaderDevice::SetStreamDest(UINT StreamNumber, __in D3DVertexBuffer *pStreamData, UINT OffsetInBytes, UINT Stride) { return XGCpuShaderDevice_SetStreamDest(this, StreamNumber, pStreamData, OffsetInBytes, Stride); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetStreamDest(UINT StreamNumber, __deref_out D3DVertexBuffer **ppStreamData, __out UINT *pOffsetInBytes, __out UINT *pStride) { *ppStreamData = XGCpuShaderDevice_GetStreamDest(this, StreamNumber, pOffsetInBytes, pStride); } + +__forceinline VOID WINAPI XGCpuShaderDevice::SetVertexShaderConstantB(UINT StartRegister, __in_ecount(BoolCount) CONST BOOL *pConstantData, UINT BoolCount) { return XGCpuShaderDevice_SetVertexShaderConstantB(this, StartRegister, pConstantData, BoolCount); } +__forceinline VOID WINAPI XGCpuShaderDevice::SetVertexShaderConstantF(UINT StartRegister, __in_ecount(4*Vector4fCount) CONST FLOAT *pConstantData, DWORD Vector4fCount) { return XGCpuShaderDevice_SetVertexShaderConstantF(this, StartRegister, pConstantData, Vector4fCount); } +__forceinline VOID WINAPI XGCpuShaderDevice::SetVertexShaderConstantI(UINT StartRegister, __in_ecount(4*Vector4iCount) CONST INT *pConstantData, DWORD Vector4iCount) { return XGCpuShaderDevice_SetVertexShaderConstantI(this, StartRegister, pConstantData, Vector4iCount); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetVertexShaderConstantB(UINT StartRegister, __out_ecount(BoolCount) BOOL *pConstantData, DWORD BoolCount) { return XGCpuShaderDevice_GetVertexShaderConstantB(this, StartRegister, pConstantData, BoolCount); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetVertexShaderConstantF(UINT StartRegister, __out_ecount(4*Vector4fCount) FLOAT *pConstantData, DWORD Vector4fCount) { return XGCpuShaderDevice_GetVertexShaderConstantF(this, StartRegister, pConstantData, Vector4fCount); } +__forceinline VOID WINAPI XGCpuShaderDevice::GetVertexShaderConstantI(UINT StartRegister, __out_ecount(4*Vector4iCount) INT *pConstantData, DWORD Vector4iCount) { return XGCpuShaderDevice_GetVertexShaderConstantI(this, StartRegister, pConstantData, Vector4iCount); } + +__forceinline VOID WINAPI XGCpuShaderDevice::ProcessVertices(UINT IndexSource, UINT IndexDest, UINT VertexCount, DWORD Flags) { return XGCpuShaderDevice_ProcessVertices(this, IndexSource, IndexDest, VertexCount, Flags); } + +#endif // __cplusplus + +/* + * Create functions. + */ + +HRESULT WINAPI XGCreateCpuShaderDevice( + __deref_out XGCpuShaderDevice** pCpuShaderDevice + ); + +HRESULT WINAPI XGCreateCpuVertexShader( + __in XGCPUSHADERFUNCTION* pFunction, + __in D3DVertexDeclaration* pDeclSource, + __in D3DVertexDeclaration* pDeclDest, + __deref_out XGCpuVertexShader** pCpuVertexShader + ); + +HRESULT WINAPI XGCreateCpuVertexShaderFromDLL( + __in_z CONST CHAR* pDLLName, + __in_z CONST CHAR* pFunction, + __in D3DVertexDeclaration* pDeclSource, + __in D3DVertexDeclaration* pDeclDest, + __deref_out XGCpuVertexShader** pCpuVertexShader + ); + +typedef struct _XGIDEALSHADERCOST +{ + float MinAlu; + float MaxAlu; + float Interpolator; + float MinTexture; + float MaxTexture; + float MinVertex; + float MaxVertex; + float Sequencer; + float MinOverall; + float MaxOverall; + BOOL bHasHitUnknownControlFlow; + BOOL bHasHitChangeableControlFlow; + BOOL bHasHitPredicatedJump; + BOOL bHasHitPredicatedEndloop; + BOOL bHasHitUnknownFetchConstant; + BOOL bHasHitUnpatchedVfetch; + int MaxTempReg; + float AvgTcInstructions; + float AvgTcAndTcCfInstructions; + float AvgVcInstructions; + float AvgVcAndVcCfInstructions; +} XGIDEALSHADERCOST; + + +HRESULT WINAPI XGCalculateIdealShaderCost ( + BOOL VertexShader, + GPU_PROGRAMCONTROL ProgramControl, + GPU_CONTEXTMISC ContextMisc, + __in_bcount(ShaderSizeInBytes) const DWORD* pShaderCode, + DWORD ShaderSizeInBytes, + __in_opt const DWORD* pBooleanConstants, + __in_opt const DWORD* pIntegerConstants, + __in_opt const GPUFETCH_CONSTANT* pFetchConstants, + BOOL bLittleEndianShader, + __out XGIDEALSHADERCOST* pShaderCost); + + +HRESULT WINAPI XGEstimateIdealShaderCost ( + __in const VOID* pFunction, + DWORD pass, + __out XGIDEALSHADERCOST* pShaderCost +); + +/* + * SetSamplerState on textures + */ + +VOID WINAPI XGSetSamplerStateParameterCheck(IDirect3DBaseTexture9* pTexture, D3DSAMPLERSTATETYPE Type, DWORD Value); + +VOID WINAPI XGSetSamplerState(__in D3DBaseTexture* pTexture, D3DSAMPLERSTATETYPE Type, DWORD Value); + +__inline VOID WINAPI XGSetSamplerAddressStates(__in D3DBaseTexture* pTexture, DWORD AddressU, DWORD AddressV, DWORD AddressW) +{ +#if defined(_DEBUG) + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_ADDRESSU, AddressU); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_ADDRESSV, AddressV); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_ADDRESSW, AddressW); +#endif + + pTexture->Format.ClampX = (GPUCLAMP)AddressU; + pTexture->Format.ClampY = (GPUCLAMP)AddressV; + pTexture->Format.ClampZ = (GPUCLAMP)AddressW; +} + +__inline VOID WINAPI XGSetSamplerBorderStates(__in D3DBaseTexture* pTexture, DWORD BorderColor, DWORD WhiteBorderColorW, DWORD PointBorderEnable) +{ +#if defined(_DEBUG) + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_BORDERCOLOR, BorderColor); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_WHITEBORDERCOLORW, WhiteBorderColorW); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_POINTBORDERENABLE, PointBorderEnable); +#endif + + pTexture->Format.BorderColor = (BorderColor == 0) ? GPUBORDERCOLOR_ABGR_BLACK : GPUBORDERCOLOR_ABGR_WHITE; + pTexture->Format.ForceBCWToMax = WhiteBorderColorW; + pTexture->Format.ClampPolicy = (GPUCLAMPPOLICY)!PointBorderEnable; +} + +__inline VOID WINAPI XGSetSamplerSeparateZFilterStates(__in D3DBaseTexture* pTexture, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MinFilterZ, DWORD MagFilterZ, DWORD MaxAnisotropy) +{ + static CONST GPUANISOFILTER anisoFilterMap[] = + { + GPUANISOFILTER_DISABLED, // 0 + GPUANISOFILTER_DISABLED, // 1 + GPUANISOFILTER_MAX2TO1, // 2 + GPUANISOFILTER_MAX2TO1, // 3 + GPUANISOFILTER_MAX4TO1, // 4 + GPUANISOFILTER_MAX4TO1, // 5 + GPUANISOFILTER_MAX4TO1, // 6 + GPUANISOFILTER_MAX8TO1, // 7 + GPUANISOFILTER_MAX8TO1, // 8 + GPUANISOFILTER_MAX8TO1, // 9 + GPUANISOFILTER_MAX8TO1, // 10 + GPUANISOFILTER_MAX8TO1, // 11 + GPUANISOFILTER_MAX8TO1, // 12 + GPUANISOFILTER_MAX16TO1, // 13 + GPUANISOFILTER_MAX16TO1, // 14 + GPUANISOFILTER_MAX16TO1, // 15 + GPUANISOFILTER_MAX16TO1, // 16 + }; + +#if defined(_DEBUG) + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_MINFILTER, MinFilter); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_MAGFILTER, MagFilter); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_MIPFILTER, MipFilter); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_MINFILTERZ, MinFilterZ); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_MAGFILTERZ, MagFilterZ); + XGSetSamplerStateParameterCheck(pTexture, D3DSAMP_MAXANISOTROPY, MaxAnisotropy); +#endif + + pTexture->Format.MinFilter = (MinFilter == D3DTEXF_ANISOTROPIC) ? D3DTEXF_LINEAR : MinFilter; + pTexture->Format.MagFilter = (MagFilter == D3DTEXF_ANISOTROPIC)? D3DTEXF_LINEAR : MagFilter; + pTexture->Format.MipFilter = MipFilter; + pTexture->Format.VolMinFilter = MinFilterZ; + pTexture->Format.VolMagFilter = MagFilterZ; + pTexture->Format.MinAnisoWalk = (MinFilter == D3DTEXF_ANISOTROPIC); + pTexture->Format.MagAnisoWalk = (MagFilter == D3DTEXF_ANISOTROPIC); + pTexture->Format.AnisoFilter = (MinFilter == D3DTEXF_ANISOTROPIC || MagFilter == D3DTEXF_ANISOTROPIC) ? anisoFilterMap[MaxAnisotropy] : GPUANISOFILTER_DISABLED; +} + +__inline VOID WINAPI XGSetSamplerFilterStates(__in D3DBaseTexture* pTexture, DWORD MinFilter, DWORD MagFilter, DWORD MipFilter, DWORD MaxAnisotropy) +{ + DWORD minFilterZ = (MinFilter == D3DTEXF_ANISOTROPIC) ? D3DTEXF_LINEAR : MinFilter; + DWORD magFilterZ = (MagFilter == D3DTEXF_ANISOTROPIC) ? D3DTEXF_LINEAR : MagFilter; + + XGSetSamplerSeparateZFilterStates(pTexture, MinFilter, MagFilter, MipFilter, minFilterZ, magFilterZ, MaxAnisotropy); +} + +__inline VOID XGBindSamplerStatesToTexture(__in D3DBaseTexture* pTexture, __in D3DDevice* pDevice, DWORD Sampler) +{ + #if defined(_DEBUG) + D3DDevice_SetSamplerState_ParameterCheck(pDevice, Sampler, D3DSAMP_MINFILTER, D3DTEXF_POINT); + #endif + + Sampler = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Sampler); + pTexture->Format.ClampX = pDevice->m_Constants.TextureFetch[Sampler].ClampX; + pTexture->Format.ClampY = pDevice->m_Constants.TextureFetch[Sampler].ClampY; + pTexture->Format.ClampZ = pDevice->m_Constants.TextureFetch[Sampler].ClampZ; + pTexture->Format.ClampPolicy = pDevice->m_Constants.TextureFetch[Sampler].ClampPolicy; + pTexture->Format.MagFilter = pDevice->m_Constants.TextureFetch[Sampler].MagFilter; + pTexture->Format.MinFilter = pDevice->m_Constants.TextureFetch[Sampler].MinFilter; + pTexture->Format.MipFilter = pDevice->m_Constants.TextureFetch[Sampler].MipFilter; + pTexture->Format.AnisoFilter = pDevice->m_Constants.TextureFetch[Sampler].AnisoFilter; + pTexture->Format.VolMagFilter = pDevice->m_Constants.TextureFetch[Sampler].VolMagFilter; + pTexture->Format.VolMinFilter = pDevice->m_Constants.TextureFetch[Sampler].VolMinFilter; + pTexture->Format.MagAnisoWalk = pDevice->m_Constants.TextureFetch[Sampler].MagAnisoWalk; + pTexture->Format.MinAnisoWalk = pDevice->m_Constants.TextureFetch[Sampler].MinAnisoWalk; + pTexture->Format.LODBias = pDevice->m_Constants.TextureFetch[Sampler].LODBias; + pTexture->Format.GradExpAdjustH = pDevice->m_Constants.TextureFetch[Sampler].GradExpAdjustH; + pTexture->Format.GradExpAdjustV = pDevice->m_Constants.TextureFetch[Sampler].GradExpAdjustV; + pTexture->Format.BorderColor = pDevice->m_Constants.TextureFetch[Sampler].BorderColor; + pTexture->Format.ForceBCWToMax = pDevice->m_Constants.TextureFetch[Sampler].ForceBCWToMax; + pTexture->Format.TriClamp = pDevice->m_Constants.TextureFetch[Sampler].TriClamp; + pTexture->Format.AnisoBias = pDevice->m_Constants.TextureFetch[Sampler].AnisoBias; + + // Note: MinMipLevel and MaxMipLevel are not copied + // since their default values depend on texture dimension. +} + +#ifdef __cplusplus +} +#endif + +#endif /* _XGRAPHICS_H_ */ diff --git a/third_party/xbox_sdk/include/xma2defs.h b/third_party/xbox_sdk/include/xma2defs.h new file mode 100644 index 0000000..13a4306 --- /dev/null +++ b/third_party/xbox_sdk/include/xma2defs.h @@ -0,0 +1,718 @@ +/*************************************************************************** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * + * File: xma2defs.h + * Content: Constants, data types and functions for XMA2 compressed audio. + * + ***************************************************************************/ + +#ifndef __XMA2DEFS_INCLUDED__ +#define __XMA2DEFS_INCLUDED__ + +#include // Markers for documenting API semantics +#include // For S_OK, E_FAIL +#include // Basic data types and constants for audio work + + +/*************************************************************************** + * Overview + ***************************************************************************/ + +// A typical XMA2 file contains these RIFF chunks: +// +// 'fmt' or 'XMA2' chunk (or both): A description of the XMA data's structure +// and characteristics (length, channels, sample rate, loops, block size, etc). +// +// 'seek' chunk: A seek table to help navigate the XMA data. +// +// 'data' chunk: The encoded XMA2 data. +// +// The encoded XMA2 data is structured as a set of BLOCKS, which contain PACKETS, +// which contain FRAMES, which contain SUBFRAMES (roughly speaking). The frames +// in a file may also be divided into several subsets, called STREAMS. +// +// FRAME: A variable-sized segment of XMA data that decodes to exactly 512 mono +// or stereo PCM samples. This is the smallest unit of XMA data that can +// be decoded in isolation. Frames are an arbitrary number of bits in +// length, and need not be byte-aligned. See "XMA frame structure" below. +// +// SUBFRAME: A region of bits in an XMA frame that decodes to 128 mono or stereo +// samples. The XMA decoder cannot decode a subframe in isolation; it needs +// a whole frame to work with. However, it can begin emitting the frame's +// decoded samples at any one of the four subframe boundaries. Subframes +// can be addressed for seeking and looping purposes. +// +// PACKET: A 2Kb region containing a 32-bit header and some XMA frames. Frames +// can (and usually do) span packets. A packet's header includes the offset +// in bits of the first frame that begins within that packet. All of the +// frames that begin in a given packet belong to the same "stream" (see the +// Multichannel Audio section below). +// +// STREAM: A set of packets within an XMA file that all contain data for the +// same mono or stereo component of a PCM file with more than two channels. +// The packets comprising a given stream may be interleaved with each other +// more or less arbitrarily; see Multichannel Audio. +// +// BLOCK: An array of XMA packets; or, to break it down differently, a series of +// consecutive XMA frames, padded at the end with reserved data. A block +// must contain at least one 2Kb packet per stream, and it can hold up to +// 4095 packets (8190Kb), but its size is typically in the 32Kb-128Kb range. +// (The size chosen involves a trade-off between memory use and efficiency +// of reading from permanent storage.) +// +// XMA frames do not span blocks, so a block is guaranteed to begin with a +// set of complete frames, one per stream. Also, a block in a multi-stream +// XMA2 file always contains the same number of samples for each stream; +// see Multichannel Audio. +// +// The 'data' chunk in an XMA2 file is an array of XMA2WAVEFORMAT.BlockCount XMA +// blocks, all the same size (as specified in XMA2WAVEFORMAT.BlockSizeInBytes) +// except for the last one, which may be shorter. + + +// MULTICHANNEL AUDIO: the XMA decoder can only decode raw XMA data into either +// mono or stereo PCM data. In order to encode a 6-channel file (say), the file +// must be deinterleaved into 3 stereo streams that are encoded independently, +// producing 3 encoded XMA data streams. Then the packets in these 3 streams +// are interleaved to produce a single XMA2 file, and some information is added +// to the file so that the original 6-channel audio can be reconstructed at +// decode time. This works using the concept of an XMA stream (see above). +// +// The frames for all the streams in an XMA file are interleaved in an arbitrary +// order. To locate a frame that belongs to a given stream in a given XMA block, +// you must examine the first few packets in the block. Here (and only here) the +// packets are guaranteed to be presented in stream order, so that all frames +// beginning in packet 0 belong to stream 0 (the first stereo pair), etc. +// +// (This means that when decoding multi-stream XMA files, only entire XMA blocks +// should be submitted to the decoder; otherwise it cannot know which frames +// belong to which stream.) +// +// Once you have one frame that belongs to a given stream, you can find the next +// one by looking at the frame's 'NextFrameOffsetBits' value (which is stored in +// its first 15 bits; see XMAFRAME below). The GetXmaFrameBitPosition function +// uses this technique. + + +// SEEKING IN XMA2 FILES: Here is some pseudocode to find the byte position and +// subframe in an XMA2 file which will contain sample S when decoded. +// +// 1. Traverse the seek table to find the XMA2 block containing sample S. The +// seek table is an array of big-endian DWORDs, one per block in the file. +// The Nth DWORD is the total number of PCM samples that would be obtained +// by decoding the entire XMA file up to the end of block N. Hence, the +// block we want is the first one whose seek table entry is greater than S. +// (See the GetXmaBlockContainingSample helper function.) +// +// 2. Calculate which frame F within the block found above contains sample S. +// Since each frame decodes to 512 samples, this is straightforward. The +// first frame in the block produces samples X to X + 512, where X is the +// seek table entry for the prior block. So F is (S - X) / 512. +// +// 3. Find the bit offset within the block where frame F starts. Since frames +// are variable-sized, this can only be done by traversing all the frames in +// the block until we reach frame F. (See GetXmaFrameBitPosition.) +// +// 4. Frame F has four 128-sample subframes. To find the subframe containing S, +// we can use the formula (S % 512) / 128. +// +// In the case of multi-stream XMA files, sample S is a multichannel sample with +// parts coming from several frames, one per stream. To find all these frames, +// steps 2-4 need to be repeated for each stream N, using the knowledge that the +// first packets in a block are presented in stream order. The frame traversal +// in step 3 must be started at the first frame in the Nth packet of the block, +// which will be the first frame for stream N. (And the packet header will tell +// you the first frame's start position within the packet.) +// +// Step 1 can be performed using the GetXmaBlockContainingSample function below, +// and steps 2-4 by calling GetXmaDecodePositionForSample once for each stream. + + + +/*************************************************************************** + * XMA constants + ***************************************************************************/ + +// Size of the PCM samples produced by the XMA decoder +#define XMA_OUTPUT_SAMPLE_BYTES 2u +#define XMA_OUTPUT_SAMPLE_BITS (XMA_OUTPUT_SAMPLE_BYTES * 8u) + +// Size of an XMA packet +#define XMA_BYTES_PER_PACKET 2048u +#define XMA_BITS_PER_PACKET (XMA_BYTES_PER_PACKET * 8u) + +// Size of an XMA packet header +#define XMA_PACKET_HEADER_BYTES 4u +#define XMA_PACKET_HEADER_BITS (XMA_PACKET_HEADER_BYTES * 8u) + +// Sample blocks in a decoded XMA frame +#define XMA_SAMPLES_PER_FRAME 512u + +// Sample blocks in a decoded XMA subframe +#define XMA_SAMPLES_PER_SUBFRAME 128u + +// Maximum encoded data that can be submitted to the XMA decoder at a time +#define XMA_READBUFFER_MAX_PACKETS 4095u +#define XMA_READBUFFER_MAX_BYTES (XMA_READBUFFER_MAX_PACKETS * XMA_BYTES_PER_PACKET) + +// Maximum size allowed for the XMA decoder's output buffers +#define XMA_WRITEBUFFER_MAX_BYTES (31u * 256u) + +// Required byte alignment of the XMA decoder's output buffers +#define XMA_WRITEBUFFER_BYTE_ALIGNMENT 256u + +// Decode chunk sizes for the XMA_PLAYBACK_INIT.subframesToDecode field +#define XMA_MIN_SUBFRAMES_TO_DECODE 1u +#define XMA_MAX_SUBFRAMES_TO_DECODE 8u +#define XMA_OPTIMAL_SUBFRAMES_TO_DECODE 4u + +// LoopCount<255 means finite repetitions; LoopCount=255 means infinite looping +#define XMA_MAX_LOOPCOUNT 254u +#define XMA_INFINITE_LOOP 255u + + + +/*************************************************************************** + * XMA format structures + ***************************************************************************/ + +// The currently recommended way to express format information for XMA2 files +// is the XMA2WAVEFORMATEX structure. This structure is fully compliant with +// the WAVEFORMATEX standard and contains all the information needed to parse +// and manage XMA2 files in a compact way. + +#define WAVE_FORMAT_XMA2 0x166 + +typedef struct XMA2WAVEFORMATEX +{ + WAVEFORMATEX wfx; + // Meaning of the WAVEFORMATEX fields here: + // wFormatTag; // Audio format type; always WAVE_FORMAT_XMA2 + // nChannels; // Channel count of the decoded audio + // nSamplesPerSec; // Sample rate of the decoded audio + // nAvgBytesPerSec; // Used internally by the XMA encoder + // nBlockAlign; // Decoded sample size; channels * wBitsPerSample / 8 + // wBitsPerSample; // Bits per decoded mono sample; always 16 for XMA + // cbSize; // Size in bytes of the rest of this structure (34) + + WORD NumStreams; // Number of audio streams (1 or 2 channels each) + DWORD ChannelMask; // Spatial positions of the channels in this file, + // stored as SPEAKER_xxx values (see audiodefs.h) + DWORD SamplesEncoded; // Total number of PCM samples the file decodes to + DWORD BytesPerBlock; // XMA block size (but the last one may be shorter) + DWORD PlayBegin; // First valid sample in the decoded audio + DWORD PlayLength; // Length of the valid part of the decoded audio + DWORD LoopBegin; // Beginning of the loop region in decoded sample terms + DWORD LoopLength; // Length of the loop region in decoded sample terms + BYTE LoopCount; // Number of loop repetitions; 255 = infinite + BYTE EncoderVersion; // Version of XMA encoder that generated the file + WORD BlockCount; // XMA blocks in file (and entries in its seek table) +} XMA2WAVEFORMATEX, *PXMA2WAVEFORMATEX; + + +// The legacy XMA format structures are described here for reference, but they +// should not be used in new content. XMAWAVEFORMAT was the structure used in +// XMA version 1 files. XMA2WAVEFORMAT was used in early XMA2 files; it is not +// placed in the usual 'fmt' RIFF chunk but in its own 'XMA2' chunk. + +#ifndef WAVE_FORMAT_XMA +#define WAVE_FORMAT_XMA 0x0165 + +// Values used in the ChannelMask fields below. Similar to the SPEAKER_xxx +// values defined in audiodefs.h, but modified to fit in a single byte. +#ifndef XMA_SPEAKER_LEFT + #define XMA_SPEAKER_LEFT 0x01 + #define XMA_SPEAKER_RIGHT 0x02 + #define XMA_SPEAKER_CENTER 0x04 + #define XMA_SPEAKER_LFE 0x08 + #define XMA_SPEAKER_LEFT_SURROUND 0x10 + #define XMA_SPEAKER_RIGHT_SURROUND 0x20 + #define XMA_SPEAKER_LEFT_BACK 0x40 + #define XMA_SPEAKER_RIGHT_BACK 0x80 +#endif + + +// Used in XMAWAVEFORMAT for per-stream data +typedef struct XMASTREAMFORMAT +{ + DWORD PsuedoBytesPerSec; // Used by the XMA encoder (typo preserved for legacy reasons) + DWORD SampleRate; // The stream's decoded sample rate (in XMA2 files, + // this is the same for all streams in the file). + DWORD LoopStart; // Bit offset of the frame containing the loop start + // point, relative to the beginning of the stream. + DWORD LoopEnd; // Bit offset of the frame containing the loop end. + BYTE SubframeData; // Two 4-bit numbers specifying the exact location of + // the loop points within the frames that contain them. + // SubframeEnd: Subframe of the loop end frame where + // the loop ends. Ranges from 0 to 3. + // SubframeSkip: Subframes to skip in the start frame to + // reach the loop. Ranges from 0 to 4. + BYTE Channels; // Number of channels in the stream (1 or 2) + WORD ChannelMask; // Spatial positions of the channels in the stream +} XMASTREAMFORMAT; + +// Legacy XMA1 format structure +typedef struct XMAWAVEFORMAT +{ + WORD FormatTag; // Audio format type (always WAVE_FORMAT_XMA) + WORD BitsPerSample; // Bit depth (currently required to be 16) + WORD EncodeOptions; // Options for XMA encoder/decoder + WORD LargestSkip; // Largest skip used in interleaving streams + WORD NumStreams; // Number of interleaved audio streams + BYTE LoopCount; // Number of loop repetitions; 255 = infinite + BYTE Version; // XMA encoder version that generated the file. + // Always 3 or higher for XMA2 files. + XMASTREAMFORMAT XmaStreams[1]; // Per-stream format information; the actual + // array length is in the NumStreams field. +} XMAWAVEFORMAT; + + +// Used in XMA2WAVEFORMAT for per-stream data +typedef struct XMA2STREAMFORMAT +{ + BYTE Channels; // Number of channels in the stream (1 or 2) + BYTE RESERVED; // Reserved for future use + WORD ChannelMask; // Spatial positions of the channels in the stream +} XMA2STREAMFORMAT; + +// Legacy XMA2 format structure (big-endian byte ordering) +typedef struct XMA2WAVEFORMAT +{ + BYTE Version; // XMA encoder version that generated the file. + // Always 3 or higher for XMA2 files. + BYTE NumStreams; // Number of interleaved audio streams + BYTE RESERVED; // Reserved for future use + BYTE LoopCount; // Number of loop repetitions; 255 = infinite + DWORD LoopBegin; // Loop begin point, in samples + DWORD LoopEnd; // Loop end point, in samples + DWORD SampleRate; // The file's decoded sample rate + DWORD EncodeOptions; // Options for the XMA encoder/decoder + DWORD PsuedoBytesPerSec; // Used internally by the XMA encoder + DWORD BlockSizeInBytes; // Size in bytes of this file's XMA blocks (except + // possibly the last one). Always a multiple of + // 2Kb, since XMA blocks are arrays of 2Kb packets. + DWORD SamplesEncoded; // Total number of PCM samples encoded in this file + DWORD SamplesInSource; // Actual number of PCM samples in the source + // material used to generate this file + DWORD BlockCount; // Number of XMA blocks in this file (and hence + // also the number of entries in its seek table) + XMA2STREAMFORMAT Streams[1]; // Per-stream format information; the actual + // array length is in the NumStreams field. +} XMA2WAVEFORMAT; + +#endif // #ifndef WAVE_FORMAT_XMA + + + +/*************************************************************************** + * XMA packet structure (in big-endian form) + ***************************************************************************/ + +typedef struct XMA2PACKET +{ + int FrameCount : 6; // Number of XMA frames that begin in this packet + int FrameOffsetInBits : 15; // Bit of XmaData where the first complete frame begins + int PacketMetaData : 3; // Metadata stored in the packet (always 1 for XMA2) + int PacketSkipCount : 8; // How many packets belonging to other streams must be + // skipped to find the next packet belonging to this one + BYTE XmaData[XMA_BYTES_PER_PACKET - sizeof(DWORD)]; // XMA encoded data +} XMA2PACKET; + +// E.g. if the first DWORD of a packet is 0x30107902: +// +// 001100 000001000001111 001 00000010 +// | | | |____ Skip 2 packets to find the next one for this stream +// | | |___________ XMA2 signature (always 001) +// | |_____________________ First frame starts 527 bits into packet +// |________________________________ Packet contains 12 frames + + +// Helper functions to extract the fields above from an XMA packet. (Note that +// the bitfields cannot be read directly on little-endian architectures such as +// the Intel x86, as they are laid out in big-endian form.) + +__inline DWORD GetXmaPacketFrameCount(__in_bcount(1) const BYTE* pPacket) +{ + return (DWORD)(pPacket[0] >> 2); +} + +__inline DWORD GetXmaPacketFirstFrameOffsetInBits(__in_bcount(3) const BYTE* pPacket) +{ + return ((DWORD)(pPacket[0] & 0x3) << 13) | + ((DWORD)(pPacket[1]) << 5) | + ((DWORD)(pPacket[2]) >> 3); +} + +__inline DWORD GetXmaPacketMetadata(__in_bcount(3) const BYTE* pPacket) +{ + return (DWORD)(pPacket[2] & 0x7); +} + +__inline DWORD GetXmaPacketSkipCount(__in_bcount(4) const BYTE* pPacket) +{ + return (DWORD)(pPacket[3]); +} + + + +/*************************************************************************** + * XMA frame structure + ***************************************************************************/ + +// There is no way to represent the XMA frame as a C struct, since it is a +// variable-sized string of bits that need not be stored at a byte-aligned +// position in memory. This is the layout: +// +// XMAFRAME +// { +// LengthInBits: A 15-bit number representing the length of this frame. +// XmaData: Encoded XMA data; its size in bits is (LengthInBits - 15). +// } + +// Size in bits of the frame's initial LengthInBits field +#define XMA_BITS_IN_FRAME_LENGTH_FIELD 15 + +// Special LengthInBits value that marks an invalid final frame +#define XMA_FINAL_FRAME_MARKER 0x7FFF + + + +/*************************************************************************** + * XMA helper functions + ***************************************************************************/ + +// We define a local ASSERT macro to equal the global one if it exists. +// You can define XMA2DEFS_ASSERT in advance to override this default. +#ifndef XMA2DEFS_ASSERT + #ifdef ASSERT + #define XMA2DEFS_ASSERT ASSERT + #else + #define XMA2DEFS_ASSERT(a) /* No-op by default */ + #endif +#endif + + +// GetXmaBlockContainingSample: Use a given seek table to find the XMA block +// containing a given decoded sample. Note that the seek table entries in an +// XMA file are stored in big-endian form and may need to be converted prior +// to calling this function. + +__inline HRESULT GetXmaBlockContainingSample +( + DWORD nBlockCount, // Blocks in the file (= seek table entries) + __in_ecount(nBlockCount) const DWORD* pSeekTable, // Pointer to the seek table data + DWORD nDesiredSample, // Decoded sample to locate + __out DWORD* pnBlockContainingSample, // Index of the block containing the sample + __out DWORD* pnSampleOffsetWithinBlock // Position of the sample in this block +) +{ + DWORD nPreviousTotalSamples = 0; + DWORD nBlock; + DWORD nTotalSamplesSoFar; + + XMA2DEFS_ASSERT(pSeekTable); + XMA2DEFS_ASSERT(pnBlockContainingSample); + XMA2DEFS_ASSERT(pnSampleOffsetWithinBlock); + + for (nBlock = 0; nBlock < nBlockCount; ++nBlock) + { + nTotalSamplesSoFar = pSeekTable[nBlock]; + if (nTotalSamplesSoFar > nDesiredSample) + { + *pnBlockContainingSample = nBlock; + *pnSampleOffsetWithinBlock = nDesiredSample - nPreviousTotalSamples; + return S_OK; + } + nPreviousTotalSamples = nTotalSamplesSoFar; + } + + return E_FAIL; +} + + +// GetXmaFrameLengthInBits: Reads a given frame's LengthInBits field. + +__inline DWORD GetXmaFrameLengthInBits +( + __in_bcount(nBitPosition / 8 + 3) + __in const BYTE* pPacket, // Pointer to XMA packet[s] containing the frame + DWORD nBitPosition // Bit offset of the frame within this packet +) +{ + DWORD nRegion; + DWORD nBytePosition = nBitPosition / 8; + DWORD nBitOffset = nBitPosition % 8; + + if (nBitOffset < 2) // Only need to read 2 bytes (and might not be safe to read more) + { + nRegion = (DWORD)(pPacket[nBytePosition+0]) << 8 | + (DWORD)(pPacket[nBytePosition+1]); + return (nRegion >> (1 - nBitOffset)) & 0x7FFF; // Last 15 bits + } + else // Need to read 3 bytes + { + nRegion = (DWORD)(pPacket[nBytePosition+0]) << 16 | + (DWORD)(pPacket[nBytePosition+1]) << 8 | + (DWORD)(pPacket[nBytePosition+2]); + return (nRegion >> (9 - nBitOffset)) & 0x7FFF; // Last 15 bits + } +} + + +// GetXmaFrameBitPosition: Calculates the bit offset of a given frame within +// an XMA block or set of blocks. Returns 0 on failure. + +__inline DWORD GetXmaFrameBitPosition +( + __in_bcount(nXmaDataBytes) const BYTE* pXmaData, // Pointer to XMA block[s] + DWORD nXmaDataBytes, // Size of pXmaData in bytes + DWORD nStreamIndex, // Stream within which to seek + DWORD nDesiredFrame // Frame sought +) +{ + const BYTE* pCurrentPacket; + DWORD nPacketsExamined = 0; + DWORD nFrameCountSoFar = 0; + DWORD nFramesToSkip; + DWORD nFrameBitOffset; + + XMA2DEFS_ASSERT(pXmaData); + XMA2DEFS_ASSERT(nXmaDataBytes % XMA_BYTES_PER_PACKET == 0); + + // Get the first XMA packet belonging to the desired stream, relying on the + // fact that the first packets for each stream are in consecutive order at + // the beginning of an XMA block. + + pCurrentPacket = pXmaData + nStreamIndex * XMA_BYTES_PER_PACKET; + for (;;) + { + // If we have exceeded the size of the XMA data, return failure + if (pCurrentPacket + XMA_BYTES_PER_PACKET > pXmaData + nXmaDataBytes) + { + return 0; + } + + // If the current packet contains the frame we are looking for... + if (nFrameCountSoFar + GetXmaPacketFrameCount(pCurrentPacket) > nDesiredFrame) + { + // See how many frames in this packet we need to skip to get to it + XMA2DEFS_ASSERT(nDesiredFrame >= nFrameCountSoFar); + nFramesToSkip = nDesiredFrame - nFrameCountSoFar; + + // Get the bit offset of the first frame in this packet + nFrameBitOffset = XMA_PACKET_HEADER_BITS + GetXmaPacketFirstFrameOffsetInBits(pCurrentPacket); + + // Advance nFrameBitOffset to the frame of interest + while (nFramesToSkip--) + { + nFrameBitOffset += GetXmaFrameLengthInBits(pCurrentPacket, nFrameBitOffset); + } + + // The bit offset to return is the number of bits from pXmaData to + // pCurrentPacket plus the bit offset of the frame of interest + return (DWORD)(pCurrentPacket - pXmaData) * 8 + nFrameBitOffset; + } + + // If we haven't found the right packet yet, advance our counters + ++nPacketsExamined; + nFrameCountSoFar += GetXmaPacketFrameCount(pCurrentPacket); + + // And skip to the next packet belonging to the same stream + pCurrentPacket += XMA_BYTES_PER_PACKET * (GetXmaPacketSkipCount(pCurrentPacket) + 1); + } +} + + +// GetLastXmaFrameBitPosition: Calculates the bit offset of the last complete +// frame in an XMA block or set of blocks. + +__inline DWORD GetLastXmaFrameBitPosition +( + __in_bcount(nXmaDataBytes) const BYTE* pXmaData, // Pointer to XMA block[s] + DWORD nXmaDataBytes, // Size of pXmaData in bytes + DWORD nStreamIndex // Stream within which to seek +) +{ + const BYTE* pLastPacket; + DWORD nBytesToNextPacket; + DWORD nFrameBitOffset; + DWORD nFramesInLastPacket; + + XMA2DEFS_ASSERT(pXmaData); + XMA2DEFS_ASSERT(nXmaDataBytes % XMA_BYTES_PER_PACKET == 0); + XMA2DEFS_ASSERT(nXmaDataBytes >= XMA_BYTES_PER_PACKET * (nStreamIndex + 1)); + + // Get the first XMA packet belonging to the desired stream, relying on the + // fact that the first packets for each stream are in consecutive order at + // the beginning of an XMA block. + pLastPacket = pXmaData + nStreamIndex * XMA_BYTES_PER_PACKET; + + // Search for the last packet belonging to the desired stream + for (;;) + { + nBytesToNextPacket = XMA_BYTES_PER_PACKET * (GetXmaPacketSkipCount(pLastPacket) + 1); + XMA2DEFS_ASSERT(nBytesToNextPacket); + if (pLastPacket + nBytesToNextPacket + XMA_BYTES_PER_PACKET > pXmaData + nXmaDataBytes) + { + break; // The next packet would extend beyond the end of pXmaData + } + pLastPacket += nBytesToNextPacket; + } + + // The last packet can sometimes have no seekable frames, in which case we + // have to use the previous one + if (GetXmaPacketFrameCount(pLastPacket) == 0) + { + pLastPacket -= nBytesToNextPacket; + } + + // Found the last packet. Get the bit offset of its first frame. + nFrameBitOffset = XMA_PACKET_HEADER_BITS + GetXmaPacketFirstFrameOffsetInBits(pLastPacket); + + // Traverse frames until we reach the last one + nFramesInLastPacket = GetXmaPacketFrameCount(pLastPacket); + while (--nFramesInLastPacket) + { + nFrameBitOffset += GetXmaFrameLengthInBits(pLastPacket, nFrameBitOffset); + } + + // The bit offset to return is the number of bits from pXmaData to + // pLastPacket plus the offset of the last frame in this packet. + return (DWORD)(pLastPacket - pXmaData) * 8 + nFrameBitOffset; +} + + +// GetXmaDecodePositionForSample: Obtains the information needed to make the +// decoder generate audio starting at a given sample position relative to the +// beginning of the given XMA block: the bit offset of the appropriate frame, +// and the right subframe within that frame. This data can be passed directly +// to the XMAPlaybackSetDecodePosition function. + +__inline HRESULT GetXmaDecodePositionForSample +( + __in_bcount(nXmaDataBytes) const BYTE* pXmaData, // Pointer to XMA block[s] + DWORD nXmaDataBytes, // Size of pXmaData in bytes + DWORD nStreamIndex, // Stream within which to seek + DWORD nDesiredSample, // Sample sought + __out DWORD* pnBitOffset, // Returns the bit offset within pXmaData of + // the frame containing the sample sought + __out DWORD* pnSubFrame // Returns the subframe containing the sample +) +{ + DWORD nDesiredFrame = nDesiredSample / XMA_SAMPLES_PER_FRAME; + DWORD nSubFrame = (nDesiredSample % XMA_SAMPLES_PER_FRAME) / XMA_SAMPLES_PER_SUBFRAME; + DWORD nBitOffset = GetXmaFrameBitPosition(pXmaData, nXmaDataBytes, nStreamIndex, nDesiredFrame); + + XMA2DEFS_ASSERT(pnBitOffset); + XMA2DEFS_ASSERT(pnSubFrame); + + if (nBitOffset) + { + *pnBitOffset = nBitOffset; + *pnSubFrame = nSubFrame; + return S_OK; + } + else + { + return E_FAIL; + } +} + + +// GetXmaSampleRate: Obtains the legal XMA sample rate (24, 32, 44.1 or 48Khz) +// corresponding to a generic sample rate. + +__inline DWORD GetXmaSampleRate(DWORD dwGeneralRate) +{ + DWORD dwXmaRate = 48000; // Default XMA rate for all rates above 44100Hz + + if (dwGeneralRate <= 24000) dwXmaRate = 24000; + else if (dwGeneralRate <= 32000) dwXmaRate = 32000; + else if (dwGeneralRate <= 44100) dwXmaRate = 44100; + + return dwXmaRate; +} + + +// Functions to convert between WAVEFORMATEXTENSIBLE channel masks (combinations +// of the SPEAKER_xxx flags defined in audiodefs.h) and XMA channel masks (which +// are limited to eight possible speaker positions: left, right, center, low +// frequency, side left, side right, back left and back right). + +__inline DWORD GetStandardChannelMaskFromXmaMask(BYTE bXmaMask) +{ + DWORD dwStandardMask = 0; + + if (bXmaMask & XMA_SPEAKER_LEFT) dwStandardMask |= SPEAKER_FRONT_LEFT; + if (bXmaMask & XMA_SPEAKER_RIGHT) dwStandardMask |= SPEAKER_FRONT_RIGHT; + if (bXmaMask & XMA_SPEAKER_CENTER) dwStandardMask |= SPEAKER_FRONT_CENTER; + if (bXmaMask & XMA_SPEAKER_LFE) dwStandardMask |= SPEAKER_LOW_FREQUENCY; + if (bXmaMask & XMA_SPEAKER_LEFT_SURROUND) dwStandardMask |= SPEAKER_SIDE_LEFT; + if (bXmaMask & XMA_SPEAKER_RIGHT_SURROUND) dwStandardMask |= SPEAKER_SIDE_RIGHT; + if (bXmaMask & XMA_SPEAKER_LEFT_BACK) dwStandardMask |= SPEAKER_BACK_LEFT; + if (bXmaMask & XMA_SPEAKER_RIGHT_BACK) dwStandardMask |= SPEAKER_BACK_RIGHT; + + return dwStandardMask; +} + +__inline BYTE GetXmaChannelMaskFromStandardMask(DWORD dwStandardMask) +{ + BYTE bXmaMask = 0; + + if (dwStandardMask & SPEAKER_FRONT_LEFT) bXmaMask |= XMA_SPEAKER_LEFT; + if (dwStandardMask & SPEAKER_FRONT_RIGHT) bXmaMask |= XMA_SPEAKER_RIGHT; + if (dwStandardMask & SPEAKER_FRONT_CENTER) bXmaMask |= XMA_SPEAKER_CENTER; + if (dwStandardMask & SPEAKER_LOW_FREQUENCY) bXmaMask |= XMA_SPEAKER_LFE; + if (dwStandardMask & SPEAKER_SIDE_LEFT) bXmaMask |= XMA_SPEAKER_LEFT_SURROUND; + if (dwStandardMask & SPEAKER_SIDE_RIGHT) bXmaMask |= XMA_SPEAKER_RIGHT_SURROUND; + if (dwStandardMask & SPEAKER_BACK_LEFT) bXmaMask |= XMA_SPEAKER_LEFT_BACK; + if (dwStandardMask & SPEAKER_BACK_RIGHT) bXmaMask |= XMA_SPEAKER_RIGHT_BACK; + + return bXmaMask; +} + + +// LocalizeXma2Format: Modifies a XMA2WAVEFORMATEX structure in place to comply +// with the current platform's byte-ordering rules (little- or big-endian). + +__inline HRESULT LocalizeXma2Format(__inout XMA2WAVEFORMATEX* pXma2Format) +{ + #define XMASWAP2BYTES(n) ((WORD)(((n) >> 8) | (((n) & 0xff) << 8))) + #define XMASWAP4BYTES(n) ((DWORD)((n) >> 24 | (n) << 24 | ((n) & 0xff00) << 8 | ((n) & 0xff0000) >> 8)) + + if (pXma2Format->wfx.wFormatTag == WAVE_FORMAT_XMA2) + { + return S_OK; + } + else if (XMASWAP2BYTES(pXma2Format->wfx.wFormatTag) == WAVE_FORMAT_XMA2) + { + pXma2Format->wfx.wFormatTag = XMASWAP2BYTES(pXma2Format->wfx.wFormatTag); + pXma2Format->wfx.nChannels = XMASWAP2BYTES(pXma2Format->wfx.nChannels); + pXma2Format->wfx.nSamplesPerSec = XMASWAP4BYTES(pXma2Format->wfx.nSamplesPerSec); + pXma2Format->wfx.nAvgBytesPerSec = XMASWAP4BYTES(pXma2Format->wfx.nAvgBytesPerSec); + pXma2Format->wfx.nBlockAlign = XMASWAP2BYTES(pXma2Format->wfx.nBlockAlign); + pXma2Format->wfx.wBitsPerSample = XMASWAP2BYTES(pXma2Format->wfx.wBitsPerSample); + pXma2Format->wfx.cbSize = XMASWAP2BYTES(pXma2Format->wfx.cbSize); + pXma2Format->NumStreams = XMASWAP2BYTES(pXma2Format->NumStreams); + pXma2Format->ChannelMask = XMASWAP4BYTES(pXma2Format->ChannelMask); + pXma2Format->SamplesEncoded = XMASWAP4BYTES(pXma2Format->SamplesEncoded); + pXma2Format->BytesPerBlock = XMASWAP4BYTES(pXma2Format->BytesPerBlock); + pXma2Format->PlayBegin = XMASWAP4BYTES(pXma2Format->PlayBegin); + pXma2Format->PlayLength = XMASWAP4BYTES(pXma2Format->PlayLength); + pXma2Format->LoopBegin = XMASWAP4BYTES(pXma2Format->LoopBegin); + pXma2Format->LoopLength = XMASWAP4BYTES(pXma2Format->LoopLength); + pXma2Format->BlockCount = XMASWAP2BYTES(pXma2Format->BlockCount); + return S_OK; + } + else + { + return E_FAIL; // Not a recognizable XMA2 format + } + + #undef XMASWAP2BYTES + #undef XMASWAP4BYTES +} + + +#endif // #ifndef __XMA2DEFS_INCLUDED__ diff --git a/third_party/xbox_sdk/include/xmaencoder.h b/third_party/xbox_sdk/include/xmaencoder.h new file mode 100644 index 0000000..cf12dce --- /dev/null +++ b/third_party/xbox_sdk/include/xmaencoder.h @@ -0,0 +1,252 @@ +/************************************************************************** + * + * Copyright (C) Microsoft Corporation. All rights reserved. + * + * Module Name: + * + * XMAEncoder.h + * + * Abstract: + * + * XMA encoder public interfaces, functions and data types + * + **************************************************************************/ + +#ifndef _XMAENCODER_H_ +#define _XMAENCODER_H_ + +#if defined (_MSC_VER) && (_MSC_VER >= 1020) + #pragma once +#endif // #if defined (_MSC_VER) && (_MSC_VER >= 1020) + +//------------------------------------------------------------------------------ +// The XMA1 and old-style XMA2 formats are no longer supported +//------------------------------------------------------------------------------ + +#ifndef XMA_ENABLE_OLD_FORMATS + + #pragma deprecated(XMAInMemoryEncoder, XMA2InMemoryEncoder) + +#endif // XMA_ENABLE_OLD_FORMATS + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include // For COM interface macros +#include // For IUnknown +#include // For WAVEFORMATEXTENSIBLE +#include // For standard error codes +#include "XMA2Defs.h" // For the new XMA2WAVEFORMATEX structure + +//------------------------------------------------------------------------------ +// Flags +//------------------------------------------------------------------------------ + +#define XMAENCODER_LOOP 0x00000001 +#define XMAENCODER_NOFILTER 0x00000002 +#define XMAENCODER_DECODEFROMXMA 0x00000004 // Not supported for in-memory encoder +#define XMAENCODER_VERBOSE 0x00000008 // Enable debug output +#define XMAENCODER_PACKSTREAMS 0x00000010 // Pack channels into fewest streams possible + +#define XMAENCODER_MASK 0x0000001F + +//------------------------------------------------------------------------------ +// Speaker assignments +//------------------------------------------------------------------------------ + +#define XMA_SPEAKER_LEFT 0x01 +#define XMA_SPEAKER_RIGHT 0x02 +#define XMA_SPEAKER_CENTER 0x04 +#define XMA_SPEAKER_LFE 0x08 +#define XMA_SPEAKER_LEFT_SURROUND 0x10 +#define XMA_SPEAKER_RIGHT_SURROUND 0x20 +#define XMA_SPEAKER_LEFT_BACK 0x40 +#define XMA_SPEAKER_RIGHT_BACK 0x80 + +//------------------------------------------------------------------------------ +// Other defines +//------------------------------------------------------------------------------ + +#define XMA_MAXINPUTCHANNELCOUNT 2 + +#define XMA_MAXLOOPCOUNT 255 +#define XMA_INFINITELOOPCOUNT XMA_MAXLOOPCOUNT + +#define XMA_LOOP_ALIGN_SAMPLES 0x00000080 + + +#ifndef WAVE_FORMAT_XMA +#define WAVE_FORMAT_XMA 0x0165 + +typedef struct XMASTREAMFORMAT +{ + DWORD PsuedoBytesPerSec; // Used by encoder + DWORD SampleRate; // Sample rate for the stream. + DWORD LoopStart; // Loop start offset (in bits). + DWORD LoopEnd; // Loop end offset (in bits). + + // Format for SubframeData: eeee ssss. + // e: Subframe number of loop end point [0,3]. + // s: Number of subframes to skip before decoding and outputting at the loop start point [1,4]. + + BYTE SubframeData; // Data for decoding subframes. See above. + BYTE Channels; // Number of channels in the stream (1 or 2). + WORD ChannelMask; // Channel assignments for the channels in the stream (same as + // lower 16 bits of dwChannelMask in WAVEFORMATEXTENSIBLE). +} XMASTREAMFORMAT, *PXMASTREAMFORMAT, *NPXMASTREAMFORMAT, *LPXMASTREAMFORMAT; +typedef const XMASTREAMFORMAT *LPCXMASTREAMFORMAT; + +typedef struct XMAWAVEFORMAT +{ + WORD FormatTag; // Audio format type (always WAVE_FORMAT_XMA). + WORD BitsPerSample; // Bit depth (currently required to be 16). + WORD EncodeOptions; // Options for XMA encoder/decoder. + WORD LargestSkip; // Largest skip used in interleaving streams. + WORD NumStreams; // Number of interleaved audio streams. + BYTE LoopCount; // Number of loop repetitions (255 == infinite). + BYTE Version; // Version of the encoder that generated this. + XMASTREAMFORMAT XmaStreams[1]; // Format info for each stream (can grow based on wNumStreams). +} XMAWAVEFORMAT, *PXMAWAVEFORMAT, *NPXMAWAVEFORMAT, *LPXMAWAVEFORMAT; +typedef XMAWAVEFORMAT *LPCXMAWAVEFORMAT; + +// Additional information for file versions 3 and above: + +typedef struct XMA2STREAMFORMAT +{ + BYTE Channels; // Number of channels in the stream (1 or 2) + BYTE RESERVED; + WORD ChannelMask; // Channel assignments for the channels in the stream (same as + // lower 16 bits of dwChannelMask in WAVEFORMATEXTENSIBLE). + // Stored with big-endian byte ordering. +} XMA2STREAMFORMAT, *LPXMA2STREAMFORMAT; +typedef const XMA2STREAMFORMAT * LPCXMA2STREAMFORMAT; + +// RIFF chunk ID is "XMA2" +// Data values are stored with big-endian byte ordering +typedef struct XMA2WAVEFORMAT +{ + BYTE Version; + BYTE NumStreams; + BYTE RESERVED; + + BYTE LoopCount; // Loop count, 255 == infinite + DWORD LoopBegin; // Loop begin point, in samples + DWORD LoopEnd; // Loop end point, in samples + + DWORD SampleRate; + + DWORD EncodeOptions; // Options for XMA encoder/decoder. + DWORD PsuedoBytesPerSec; // Used by encoder + + DWORD BlockSizeInBytes; // Size of the blocks that were encoded. + DWORD SamplesEncoded; // Total number of samples in the XMA file. + DWORD SamplesInSource; // The number of samples in the file used to generate the XMA + DWORD BlockCount; // The number of encoded blocks in the file (also the number of elements in the seek table) + + XMA2STREAMFORMAT Streams[1]; // Format info for each stream (can grow based on NumStreams) + +} XMA2WAVEFORMAT, *LPXMA2WAVEFORMAT; +typedef const XMA2WAVEFORMAT *LPCXMA2WAVEFORMAT; + +#endif // #ifndef WAVE_FORMAT_XMA + + +//------------------------------------------------------------------------------ +// Encoder parameters +//------------------------------------------------------------------------------ + +typedef struct XMAENCODERSTREAM +{ + WAVEFORMATEXTENSIBLE Format; + LPCVOID pBuffer; + DWORD BufferSize; + DWORD LoopStart; + DWORD LoopLength; + BYTE SpeakerAssignment[XMA_MAXINPUTCHANNELCOUNT]; +} XMAENCODERSTREAM, *LPXMAENCODERSTREAM; +typedef const XMAENCODERSTREAM* LPCXMAENCODERSTREAM; + +//------------------------------------------------------------------------------ +// XMA Encoder Functions +//------------------------------------------------------------------------------ + + +// The XMAInMemoryEncoder() and XMA2InMemoryEncoder() functions are no longer +// supported and should not be used in new code. Their declarations are only +// available if XMA_ENABLE_OLD_FORMATS is defined prior to including this header. + +#ifdef XMA_ENABLE_OLD_FORMATS + +// This function encodes to the original, unsupported XMA1 format +STDAPI XMAInMemoryEncoder +( + DWORD InputStreamCount, + __in_ecount(InputStreamCount) const XMAENCODERSTREAM* pStreams, + DWORD Compression, + DWORD Flags, + __deref_out_bcount(*pEncodedBufferSize) VOID** ppEncodedBuffer, + __out DWORD* pEncodedBufferSize, + __deref_out_bcount(*pEncodedBufferFormatSize) XMAWAVEFORMAT** ppEncodedBufferFormat, + __out DWORD* pEncodedBufferFormatSize, + __deref_out_bcount(*pSeekTableSize) DWORD** ppSeekTable, + __out DWORD* pSeekTableSize +); + +// This function encodes to the old, unsupported version of the XMA2 format +STDAPI XMA2InMemoryEncoder +( + DWORD InputStreamCount, + __in_ecount(InputStreamCount) const XMAENCODERSTREAM* pStreams, + DWORD Compression, + DWORD Flags, + DWORD BlockSizeInKbytes, // Cannot be zero + __deref_out_bcount(*pEncodedBufferSize) VOID** ppEncodedBuffer, + __out DWORD* pEncodedBufferSize, + __deref_out_bcount(*pEncodedBufferFormatSize) XMA2WAVEFORMAT** ppEncodedBufferFormat, + __out DWORD* pEncodedBufferFormatSize, + __deref_out_bcount(*pSeekTableSize) DWORD** ppSeekTable, + __out DWORD* pSeekTableSize +); + +#endif // #ifdef XMA_ENABLE_OLD_FORMATS + +// This function encodes to the new, approved version of the XMA2 format, +// which is the only format usable in XAudio2. +STDAPI XAudio2XMAEncoder +( + DWORD InputStreamCount, + __in_ecount(InputStreamCount) const XMAENCODERSTREAM* pStreams, + DWORD Compression, + DWORD Flags, + DWORD BlockSizeInKbytes, // Cannot be zero + __deref_out_bcount(*pEncodedBufferSize) VOID** ppEncodedBuffer, + __out DWORD* pEncodedBufferSize, + __deref_out_bcount(*pEncodedBufferFormatSize) XMA2WAVEFORMATEX** ppEncodedBufferFormat, + __out DWORD* pEncodedBufferFormatSize, + __deref_out_bcount(*pSeekTableSize) DWORD** ppSeekTable, + __out DWORD* pSeekTableSize +); + +//------------------------------------------------------------------------------ +// Encoder error codes +//------------------------------------------------------------------------------ + +#define FACILITY_XMACodec 0x889 +#define XMAENCODERERROR(n) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_XMACodec, n) + +#define XMAENCODER_E_OUTOFMEMORY E_OUTOFMEMORY // Out of memory +#define XMAENCODER_E_INVALIDARG E_INVALIDARG // Invalid arg +#define XMAENCODER_E_NOTIMPL E_NOTIMPL // Not implemented +#define XMAENCODER_E_FAIL E_FAIL // Unknown error + +#define XMAENCODER_E_INVALIDLOOP XMAENCODERERROR(0x001) // The loop points are invalid. +#define XMAENCODER_E_UNSUPPORTEDFORMAT XMAENCODERERROR(0x002) // Format is invalid. +#define XMAENCODER_E_OUTOFRANGE XMAENCODERERROR(0x003) // Parameter is out of valid range. +#define XMAENCODER_E_READFAILED XMAENCODERERROR(0x004) // Read operation failed. +#define XMAENCODER_E_INVALIDFRAME XMAENCODERERROR(0x005) // Invalid XMA frame. +#define XMAENCODER_E_INCOMPLETEFRAME XMAENCODERERROR(0x006) // Incomplete XMA frame. +#define XMAENCODER_E_ZEROSTUFFINGBIT XMAENCODERERROR(0x007) // Stuffing bit is zero +#define XMAENCODER_E_GETDATAFAILED XMAENCODERERROR(0x008) // Data fetch failed. + +#endif // #ifndef _XMAENCODER_H_ diff --git a/third_party/xbox_sdk/include/xmcore.h b/third_party/xbox_sdk/include/xmcore.h new file mode 100644 index 0000000..2b9a05e --- /dev/null +++ b/third_party/xbox_sdk/include/xmcore.h @@ -0,0 +1,952 @@ +/************************************************************************ +* * +* XMCore.h -- This module defines the Xbox multicore APIs * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/////////////////////////////// +// LOCK FREE DECLARATIONS // +/////////////////////////////// + +typedef DWORD_PTR XLOCKFREE_HANDLE; +typedef DWORD_PTR XLOCKFREE_LOG; + +///////////////////////////////////////////////////////////////////////////// +// Wait function prototype called when a lock-free data structure needs // +// to block before it can add an element or must wait to remove an // +// element. Routine must return WAIT_OBJECT_0 if event is signaled. // +///////////////////////////////////////////////////////////////////////////// +typedef DWORD (CALLBACK *XLockFreeWait)(__in_opt PVOID context, // Developer supplied context for the wait. + __in HANDLE event, // Event the xmcore library wants to wait on. + __in DWORD dwMilliSeconds, // Expected wait time. + __in BOOL fAlertable); // Should the wait allow APC's + +/////////////////////////////////////////////////////////////////////////////// +// Function prototypes if allocators are to be replace. Memory call backs // +// are specific to one data structure. If all allocations need to be // +// replaced then XMemAlloc can be overridden. // +/////////////////////////////////////////////////////////////////////////////// +typedef PVOID (CALLBACK *XLockFreeMemoryAllocate)(__in_opt PVOID context, __in DWORD dwSize); +typedef void (CALLBACK *XLockFreeMemoryFree)(__in_opt PVOID context, __in PVOID pAddress); + + +//////////////////////////////////////////////////////////////////////////////////////////////// +// Function prototype for dump callbacks. Context is user specified in the // +// dump call, entry is the data stored in the structure and node is the system data. // +// Dump functions are NOT thread safe and should only be used when threads are NOT // +// accessing the data structures. // +//////////////////////////////////////////////////////////////////////////////////////////////// +typedef HRESULT (CALLBACK *XLockFreeUnsafeDump)(__in_opt PVOID context, __in PVOID entry, __in PVOID node); + +////////////////////////////////////////////////////////////////////////////// +// Default Allocation routines used by the lock free library. Allocation // +// is done through XMemAlloc using allocator ID // +// eXALLOCAllocatorID_XMCORE. // +////////////////////////////////////////////////////////////////////////////// +PVOID APIENTRY XLFAllocate(__in DWORD_PTR dwSize); +void APIENTRY XLFFree(__in_opt PVOID pAddress); + +///////////////////////////// +// Lock free attributes // +///////////////////////////// +#define XLOCKFREE_NO_ATTRIBUTES 0x000 +#define XLOCKFREE_ATTRIBUTE_FLAG 0x001 // Reservered for internal use +#define XLOCKFREE_RESERVED_FLAG 0x002 +#define XLOCKFREE_ADD_WAIT 0x004 // Wait until there is room in the queue/stack to add an element. +#define XLOCKFREE_REMOVE_WAIT 0x008 // Wait until there is an entry to remove from the queue/stack. +#define XLOCKFREE_SPIN_ON_ADD 0x010 // If we need to wait do we spin first before adding an entry +#define XLOCKFREE_SPIN_ON_REMOVE 0x020 // If we need to wait do we spin first before removing an entry +#define XLOCKFREE_ALERTABLE_ADD 0x040 // If we wait while adding an entry, is the wait altertable +#define XLOCKFREE_ALERTABLE_REMOVE 0x080 // If we wait while removing an entry, is the wait altertable +#define XLOCKFREE_SINGLE_KEY_ENTRY 0x100 // Allow a single key value (PRIORITY QUEUE and HASH TABLE only) + +///////////////////////////////////////////////////////////////////////////// +// The XLOCKFREE_CREATE structure is used to initialize the data // +// structures. All entries in the structure are optional. The structure // +// can be used to create data structures that have customized wait // +// characteristics and memory allocations. // +///////////////////////////////////////////////////////////////////////////// +typedef struct _XLOCKFREE_CREATE +{ + DWORD attributes; // See attributes defined above (OPTIONAL) + PVOID addWaitContext; // User data passed when in when an add would wait (OPTIONAL) + PVOID removeWaitContext; // User data passed when in when a remove would wait (OPTIONAL) + DWORD addWaitTime; // Amount of time to wait before a timeout happens when adding an element (OPTIONAL) + DWORD removeWaitTime; // Amount of time to wait before a timeout happens when deleting an element (OPTIONAL) + XLockFreeWait addWait; // Custom wait function used if an element cannot be added to the data structure (OPTIONAL) + XLockFreeWait removeWait; // Custom wait function used if there is no element to removed from the data structure (OPTIONAL) + + // All information after here is used only during creation + DWORD structureSize; // Must be set to sizeof(XLOCKFREE_CREATE)!. + DWORD allocationLength; // Number of elements to allocate when the data structure needs to allocate more nodes (OPTIONAL) + DWORD maximumLength; // Total number of entries allowed in the data structure. -1 or 0 means unlimited (OPTIONAL) + XLockFreeMemoryAllocate allocate; // Custom Allocator (OPTIONAL) + XLockFreeMemoryFree free; // Matching release for custom Allocator (OPTIONAL) + PVOID memoryContext; // Memory context if required. +} XLOCKFREE_CREATE, *PXLOCKFREE_CREATE; + +//////////////////////////////////////////////////////////////////////////// +// The 'C' API for the queue data structure provides the ability to // +// create, destroy, add elements and remove elements from a FIFO // +// queue. The queue is an opaque handle that must be passed into every // +// function. // +//////////////////////////////////////////////////////////////////////////// +HRESULT WINAPI XLFQueueAdd(__in XLOCKFREE_HANDLE queue, __in void* data); +HRESULT WINAPI XLFQueueAllocated(__in XLOCKFREE_HANDLE queue, __out DWORD* size); +HRESULT WINAPI XLFQueueCreate(__in_opt PXLOCKFREE_CREATE info, __out XLOCKFREE_HANDLE* queue); +void WINAPI XLFQueueDestroy(__in XLOCKFREE_HANDLE queue); +HRESULT WINAPI XLFQueueGetEntryCount(__in XLOCKFREE_HANDLE queue, __out LONG* entries); +BOOL WINAPI XLFQueueIsEmpty(__in XLOCKFREE_HANDLE queue); +HRESULT WINAPI XLFQueueRemove(__in XLOCKFREE_HANDLE queue, __deref_out void** data); +HRESULT WINAPI XLFQueueUnsafeDump(__in XLOCKFREE_HANDLE queue, __in_opt PVOID context, __in XLockFreeUnsafeDump callback); + +////////////////////////////////////////////////// +// The 'C' API for the stack data structure. // +////////////////////////////////////////////////// +HRESULT WINAPI XLFStackAllocated(__in XLOCKFREE_HANDLE stack, __out DWORD* size); +HRESULT WINAPI XLFStackCreate(__in_opt PXLOCKFREE_CREATE info, __out XLOCKFREE_HANDLE* stack); +void WINAPI XLFStackDestroy(__in XLOCKFREE_HANDLE stack); +HRESULT WINAPI XLFStackGetEntryCount(__in XLOCKFREE_HANDLE stack, __out LONG* entries); +BOOL WINAPI XLFStackIsEmpty(__in XLOCKFREE_HANDLE stack); +HRESULT WINAPI XLFStackPop(__in XLOCKFREE_HANDLE stack, __deref_out void** data); +HRESULT WINAPI XLFStackPush(__in XLOCKFREE_HANDLE stack, __in void* data); +HRESULT WINAPI XLFStackUnsafeDump(__in XLOCKFREE_HANDLE stack, __in_opt PVOID context, __in XLockFreeUnsafeDump callback); + + +/////////////////////////////////////////////////////////////////////////////// +// Compare functions to compare and hash keys used in Priority Queues and // +// Hash Tables. Call back functions can be used in the Priority Queue and // +// Hash Table to customize how entries are added and removed from the // +// data structures. // +/////////////////////////////////////////////////////////////////////////////// +typedef int (CALLBACK *XLockFreeCompareKeys)(int key1, int key2); +typedef unsigned int (CALLBACK *XLockFreeHashKey)(DWORD key, DWORD size); + +typedef struct _XLOCKFREE_FUNCTIONS +{ + XLockFreeCompareKeys compare; // Function to compare to keys (OPTIONAL) + XLockFreeHashKey hash; // Function that calculates the bucket [hashtable only] (OPTIONAL) + DWORD structureSize; // Must be set to the sizeof(XLOCKFREE_FUNCTIONS). +} XLOCKFREE_FUNCTIONS, *PXLOCKFREE_FUNCTIONS; + +/////////////////////////////////////////////////////////// +// The 'C' API for the priority queue data structure. // +/////////////////////////////////////////////////////////// +HRESULT WINAPI XLFPriorityQueueAdd(__in XLOCKFREE_HANDLE queue, __in DWORD key, __in PVOID data); +HRESULT WINAPI XLFPriorityQueueAllocated(__in XLOCKFREE_HANDLE queue, __out DWORD* size); +HRESULT WINAPI XLFPriorityQueueCreate(__in_opt PXLOCKFREE_CREATE info, __in PXLOCKFREE_FUNCTIONS functions, __out XLOCKFREE_HANDLE* queue); +void WINAPI XLFPriorityQueueDestroy(__in XLOCKFREE_HANDLE queue); +HRESULT WINAPI XLFPriorityQueueGetEntryCount(__in XLOCKFREE_HANDLE queue, __out LONG* entries); +BOOL WINAPI XLFPriorityQueueIsEmpty(__in XLOCKFREE_HANDLE queue); +HRESULT WINAPI XLFPriorityQueueRemoveFirst(__in XLOCKFREE_HANDLE queue, __out PVOID* data); +HRESULT WINAPI XLFPriorityQueueRemove(__in XLOCKFREE_HANDLE queue, __in DWORD key, __out PVOID* data); +HRESULT WINAPI XLFPriorityQueueUnsafeDump(__in XLOCKFREE_HANDLE queue, __in_opt PVOID context, __in XLockFreeUnsafeDump callback); + +/////////////////////////////////////////////////////// +// The 'C' API for the hash table data structure. // +/////////////////////////////////////////////////////// +HRESULT WINAPI XLFHashTableAdd(__in XLOCKFREE_HANDLE hashTable, __in DWORD key, __in PVOID data); +HRESULT WINAPI XLFHashTableAllocated(__in XLOCKFREE_HANDLE hashTable, __out DWORD* size); +HRESULT WINAPI XLFHashTableCreate(__in_opt PXLOCKFREE_CREATE info, __in PXLOCKFREE_FUNCTIONS functions, __in DWORD buckets, __out XLOCKFREE_HANDLE* hashTable); +void WINAPI XLFHashTableDestroy(__in XLOCKFREE_HANDLE hashTable); +HRESULT WINAPI XLFHashTableGetEntryCount(__in XLOCKFREE_HANDLE hashTable, __out LONG* entries); +BOOL WINAPI XLFHashTableIsEmpty(__in XLOCKFREE_HANDLE hashTable); +HRESULT WINAPI XLFHashTableRemoveFirst(__in XLOCKFREE_HANDLE hashTable, __out PVOID* data); +HRESULT WINAPI XLFHashTableRemove(__in XLOCKFREE_HANDLE hashTable, __in DWORD key, __out PVOID* data); +HRESULT WINAPI XLFHashTableUnsafeDump(__in XLOCKFREE_HANDLE hashTable, __in_opt PVOID context, __in XLockFreeUnsafeDump callback); + + +////////////////// +// LOCK POOL // +////////////////// +#define XLOCKFREE_POOL_ALLOW_RECURSION 0x1 // Allow recursive calls to locks (see warnings below) +#define XLOCKFREE_POOL_WATCH_THREAD 0x2 // Fail if another thread tries to destroy a lock +#define XLOCKFREE_POOL_ACQUIRE_WAIT 0x4 // Wait until the lock can be acquired +#define XLOCKFREE_POOL_SPIN_ON_WAIT 0x10 // If we need to wait do we spin first +#define XLOCKFREE_POOL_ALERTABLE_WAIT 0x20 // If we wait, the wait is altertable + + +// Recursion warnings: +// 1) A thread that has shared access to a lock will become blocked if it recursively tries to acquire shared +// access to the same lock when another thread is requesting exclusive access. When a thread requests exclusive +// access to a lock it will block all threads trying to acquire shared access. This includes threads that have +// already been granted shared access. +// +// 2) Threads that hold exclusive access will block if they ask for shared access. +// + + +typedef enum _TWO_WAY_LOCK_ACTIONS +{ + XLF_LOCK_SHARED, // acquire shared lock (may require waiting); + XLF_LOCK_EXCLUSIVE, // acquire exclusive lock (may require waiting); + XLF_LOCK_DOWNGRADE, // downgrade exclusive lock to shared (non-blocking request); + XLF_LOCK_UPGRADE_SAFELY, // upgrade shared lock to exclusive in order (may require waiting); + XLF_LOCK_UPGRADE_IGNORE // upgrade shared +} TWO_WAY_LOCK_ACTIONS; + +typedef struct _TWO_WAY_LOCK +{ + __int64 data[2]; +} TWO_WAY_LOCK, *PTWO_WAY_LOCK; + +typedef struct _XLOCKFREE_POOL +{ + DWORD attributes; // See attributes defined above (OPTIONAL) + DWORD allocationLength; // Number of elements to allocate when the data + // structure needs to allocate more nodes (OPTIONAL) + PVOID waitContext; // User data passed into the wait function associated + // with the data structure (OPTIONAL) + DWORD acquireWaitTime; // Amount of time to wait before a timeout happens when acquiring a lock + XLockFreeWait acquireWait; // Custom wait function used if an element cannot be + // added to the data structure (OPTIONAL) + DWORD structureSize; // Must be set to sizeof(XLOCKFREE_POOL). +} XLOCKFREE_POOL, *PXLOCKFREE_POOL; + + +HRESULT WINAPI XLFPoolAcquireLock(__in XLOCKFREE_HANDLE pool, __in TWO_WAY_LOCK_ACTIONS action, __in TWO_WAY_LOCK* lock); +HRESULT WINAPI XLFPoolAllocated(__in XLOCKFREE_HANDLE pool, __out DWORD* size); +HRESULT WINAPI XLFPoolCreate(__in_opt XLOCKFREE_POOL* info, __out XLOCKFREE_HANDLE* pool); +HRESULT WINAPI XLFPoolCreateLock(__in XLOCKFREE_HANDLE pool, __out PTWO_WAY_LOCK* lock); +void WINAPI XLFPoolDestroy(__in XLOCKFREE_HANDLE pool); +HRESULT WINAPI XLFPoolDestroyLock(__in XLOCKFREE_HANDLE pool, __in TWO_WAY_LOCK* lock); +HRESULT WINAPI XLFPoolIncreaseEvents(__in XLOCKFREE_HANDLE pool, __in DWORD number); +HRESULT WINAPI XLFPoolIncreaseLocks(__in XLOCKFREE_HANDLE pool, __in DWORD number); +HRESULT WINAPI XLFPoolInitializeLock(__in XLOCKFREE_HANDLE pool, __in TWO_WAY_LOCK* lock); +HRESULT WINAPI XLFPoolNumberOfEvents(__in XLOCKFREE_HANDLE pool, __out DWORD* number); +HRESULT WINAPI XLFPoolNumberOfLocks(__in XLOCKFREE_HANDLE pool, __out DWORD* number); +HRESULT WINAPI XLFPoolReleaseLock(__in XLOCKFREE_HANDLE pool, __in TWO_WAY_LOCK_ACTIONS action, __in TWO_WAY_LOCK* lock); + +//////////////////// +// Error codes // +//////////////////// +#define FACILITY_XLOCKFREE 0x31 +#define XLOCKFREE_STRUCTURE_FULL ((HRESULT)0x80310001L) +#define XLOCKFREE_STRUCTURE_EMPTY ((HRESULT)0x80310002L) +#define XLOCKFREE_INVALID_ACTION ((HRESULT)0x80310003L) // When releasing a lock the action must be XLF_LOCK_SHARED or XLF_LOCK_EXCLUSIVE +#define XLOCKFREE_INVALID_UNLOCK ((HRESULT)0x80310004L) +#define XLOCKFREE_PENDING_UPGRADE ((HRESULT)0x80310005L) +#define XLOCKFREE_PENDING_EXCLUSIVE_LOCK ((HRESULT)0x80310006L) +#define XLOCKFREE_PENDING_RECURSIVE_LOCK ((HRESULT)0x80310007L) + + +//////////////////////////////// +// The 'C' API for the log // +//////////////////////////////// +typedef HRESULT (CALLBACK *XLFLogMessage)(__in_opt PVOID messageContext, __in_bcount(length) PBYTE buffer, __in DWORD length); +HRESULT WINAPI XLFStartLog(__in int requestedCore, // Run the logging facility on this core + __in_z LPCSTR logFile, // Log messages to this file + __in int messageLength, // Maximum message length + __in int numberOfMessages, // Maximum number of messages allowed to be queued up + __in BOOL blockOnWrite, // Block if queue is at is maximum + __out XLOCKFREE_LOG* log); // Handle to the log is returned + +HRESULT WINAPI XLFStartUserLog(__in int requestedCore, // Run the logging facility on this core + __in_opt PVOID messageContext, // Context passed to the callback + __in XLFLogMessage callback, // Callback processes message + __in int messageLength, // Maximum message length + __in int numberOfMessages, // Maximum number of messages allowed to be queued up + __in BOOL blockOnWrite, // Block if queue is at is maximum + __out XLOCKFREE_LOG* log); // Handle to the log is returned + +void WINAPI XLFEndLog(__in XLOCKFREE_LOG log); +void WINAPI XLFLogPrint(__in XLOCKFREE_LOG log, __in_z const char* format, ...); +void WINAPI XLFLogPrintV(__in XLOCKFREE_LOG log, __in_z const char* format, va_list argptr); +void WINAPI XLFLogBuffer(__in XLOCKFREE_LOG log, __in_bcount(length) PBYTE buffer, __in DWORD length); +void WINAPI XLFLogMessageStats(__in XLOCKFREE_LOG log, __in DWORD* droppedMessages, DWORD* missedMessages); + + +/////////////////////////////////////////////////////////////////////////// +// XLockFree library will RIP in debug mode unless a error handler is // +// supplied and it returns S_OK after being passed an error message. // +/////////////////////////////////////////////////////////////////////////// +typedef HRESULT (CALLBACK *XLockFreeErrorHandler)(__in_z const char* msg); +XLockFreeErrorHandler APIENTRY XLockFreeGetErrorHandler(void); +XLockFreeErrorHandler APIENTRY XLockFreeSetErrorHandler(__in_opt XLockFreeErrorHandler func); + + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus + +/////////////////////////////////////////////////////////////////////////////////////////// +// Elements added to the lock free data structures do not need to // +// inherit a link structure. These algorithm allocate external link // +// structures because it is very difficult to know when the link structures // +// can be released or changed. The link structure can be referenced on // +// multiple threads at the same and failure can occur if the link structure is updated // +// outside the data structure. // +// // +// User data cannot be delete when it is added to a list. After the data // +// is removed from a list it can be safely deleted at any time. // +// Only one thread will have a reference to the user data after it is // +// removed from a list. // +/////////////////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////////////////// +// XLockFreeStack // +// -------------- // +// Creates a stack structure that can accept T objects. The stack stores pointers // +// to T, it does not copy the contents of T. If the object T is deleted while the // +// stack holds a reference results can be unpredictable. // +// // +// Care needs to be taken when creating a stack structure that will be visible to // +// multiple threads. The stack should either be constructed before threads are // +// started, passed as a parameter to the thread procedure, or have global references // +// updated using an interlocked function. // +/////////////////////////////////////////////////////////////////////////////////////////// + +template class XLockFreeStack +{ + public: + XLockFreeStack(); // Creates a stack structure. + ~XLockFreeStack(); // Releases all the stack resources. + + /////////////////////////////////////////////////////////////////////////// + // Manually release all the stack resources. // + /////////////////////////////////////////////////////////////////////////// + void Destroy(); + + /////////////////////////////////////////////////////////////////////////// + // Returns the amount of memory allocated for the stack. // + /////////////////////////////////////////////////////////////////////////// + DWORD GetAllocated() const; + + /////////////////////////////////////////////////////////////////////////// + // Returns the number of entries in the stack (is a snapshot in time). // + /////////////////////////////////////////////////////////////////////////// + DWORD GetEntryCount() const; + + /////////////////////////////////////////////////////////////////////////// + // Creates a Stack structure that will allocate nodes as required and // + // will not block on Pushes and Pops. // + /////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(); + + //////////////////////////////////////////////////////////////////////////// + // Creates a queue structure where the maximum number of elements, the // + // number of allocations and whether calls will block can be // + // specified. If waiting is specified in the attributes then an // + // optional custom Wait functions can be also added. // + //////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(__in_opt PXLOCKFREE_CREATE info); + + // Returns TRUE if there are no items in the stack. + BOOL IsEmpty() const; + + ////////////////////////////////////////////////////////////////////////////// + // Returns the top data type in the stack. Returns NULL if no entry is // + // available. Because the stack can be used in a multithreaded // + // environment it is very possible that a call to IsEmpty() will return // + // FALSE and the Pop() will return NULL. By the time the Pop() has // + // executed another thread may have taken all the available entries. The // + // program must always test for a NULL. // + ////////////////////////////////////////////////////////////////////////////// + _T* Pop(); + + /////////////////////////////////////////////////////////////////////////// + // Returns the top data type in the stack. Returns // + // XLOCKFREE_STRUCTURE_EMPTY if no entry is available. If there is a // + // wait function added to the stack the error code from that function // + // would be returned in the case of a failure. // + /////////////////////////////////////////////////////////////////////////// + HRESULT Pop(__deref_out _T** ref); + + ///////////////////////////////////////////////////////////////////////////// + // Adds a data type to the stack. Returns XLOCKFREE_STRUCTURE_FULL if // + // the stack was full. If there is a wait function added to the stack // + // the error code from that function would be returned in the case of a // + // failure. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Push(__in _T* entry); + + PVOID operator new( __in size_t size); + void operator delete(__in_opt PVOID p); + PVOID operator new[]( __in size_t size); + void operator delete[](__in_opt PVOID p); + + ///////////////////////////////////////////////////////////////////////////////// + // Dump the stack. Context is user defined and passed into the dump function // + // along with every entry in the stack. This routine is NOT thread safe. // + ///////////////////////////////////////////////////////////////////////////////// + HRESULT UnsafeDump(__in_opt PVOID context, __in XLockFreeUnsafeDump function); + + private: + XLOCKFREE_HANDLE stack; + XLockFreeStack(__in const XLockFreeStack& s) {} // Copy constructor not allowed +}; + + +/////////////////////////////////////////////////////////////////////////////// +// XLockFreeQueue // +// -------------- // +// // +// Creates an queue structure that can accept T objects. The queue stores // +// pointers to T, it does not copy the contents of T. If the object T is // +// deleted while the queue holds a reference results can be // +// unpredictable. // +// // +// Creates a queue structure. Care needs to be taken when creating a // +// queue structure that will be visible to multiple threads. The queue // +// should be constructed before threads are started, should be passed as // +// a parameter to the thread procedure, or should have the global // +// reference updated using an interlocked function. // +/////////////////////////////////////////////////////////////////////////////// + +template class XLockFreeQueue +{ +public: + XLockFreeQueue(); + ~XLockFreeQueue(); + + ///////////////////////////////////////////////////////////////////////////// + // Adds an entry to the queue, returns S_OK if element successfully // + // added. Returns XLOCKFREE_STRUCTURE_FULL if a free node was not // + // available to link in the data. If there is a wait function added to // + // the stack the error code from that function would be returned in the // + // case of a failure. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Add(__in _T* entry); + + /////////////////////////////////////////////////////////////////////////// + // Manually releases all the resources associated with the queue. The // + // queue should not be used after this method has been called. // + /////////////////////////////////////////////////////////////////////////// + void Destroy(); + + ////////////////////////////////////////////////////////////// + // Returns the amount of memory allocated for the Queue. // + ////////////////////////////////////////////////////////////// + DWORD GetAllocated() const; + + /////////////////////////////////////////////////////////////////////////// + // Returns the number of entries in the Queue (is a snapshot in time). // + /////////////////////////////////////////////////////////////////////////// + DWORD GetEntryCount() const; + + /////////////////////////////////////////////////////////////////////////////// + // Creates a queue structure that will grow as necessary and will not // + // block on when adding or removing elements. An Initialize() method must // + // be called before the queue can be used. // + /////////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(); + + //////////////////////////////////////////////////////////////////////////// + // Creates a queue structure where the maximum number of elements, the // + // number of allocations and whether calls will block can be // + // specified. If waiting is specified in the attributes then an // + // optional custom Wait functions can be also added. // + //////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(__in_opt PXLOCKFREE_CREATE info); + + ////////////////////////////////////////////////////////////// + // Returns TRUE if there currently no items in the queue // + ////////////////////////////////////////////////////////////// + BOOL IsEmpty() const; + + ////////////////////////////////////////////////////////////////////////////// + // Returns the last entry in the queue. Returns NULL if no entry is // + // available. Because the queue can be used in a multithreaded // + // environment it is very possible that a call to IsEmpty() will return // + // FALSE and Remove() will return NULL. By the time the Remove() has // + // executed another thread may have taken all the available entries. The // + // program must always test for a NULL. // + ////////////////////////////////////////////////////////////////////////////// + _T* Remove(); + + /////////////////////////////////////////////////////////////////////////////// + // Returns the last entry in the queue. Return XLOCKFREE_STRUCTURE_EMPTY // + // if no entry is available. If there is a wait function added to the // + // queue the error code from that function would be returned in the case // + // of a failure. // + /////////////////////////////////////////////////////////////////////////////// + HRESULT Remove(__deref_out _T** ref); + + PVOID operator new( __in size_t size ); + void operator delete(__in_opt PVOID p); + PVOID operator new[]( __in size_t size ); + void operator delete[](__in_opt PVOID p); + + ///////////////////////////////////////////////////////////////////////////////// + // Dump the queue. Context is user defined and passed into the dump function // + // along with every entry in the queue. This routine is NOT thread safe. // + ///////////////////////////////////////////////////////////////////////////////// + HRESULT UnsafeDump(__in PVOID context, __in XLockFreeUnsafeDump function); + + +private: + XLockFreeQueue(__in const XLockFreeQueue& q) {} // Copy constructor not allowed + XLOCKFREE_HANDLE queue; +}; + + +class XLockFreeCustom +{ +public: + static int WINAPI compare(__in int p1, __in int p2); + static unsigned int WINAPI hash(__in unsigned int key, __in unsigned int buckets); + static unsigned int WINAPI bucketSize(__in unsigned int buckets); +}; + +template +class XLockFreeFunctions +{ +public: + XLockFreeFunctions() {} + XLockFreeFunctions(__in _Functions c) : _func(c) {} +protected: + _Functions _func; +}; + +///////////////////////////////////////////////////////////////////////////// +// XLockFreePriorityQueue // +// ---------------------- // +// // +// Creates a queue structure that can accept T objects. The default // +// implementation supplies functions for comparing keys and for hashing // +// the key. // +// // +// Creates a priority queue structure. Care needs to be taken when // +// creating a priority queue structure that will be visible to multiple // +// threads. The queue should be constructed before threads are started, // +// should be passed as a parameter to the thread procedure, or should // +// have the global reference updated using an interlocked function. // +///////////////////////////////////////////////////////////////////////////// + +template > +class XLockFreePriorityQueue : _XFunctions +{ +public: + XLockFreePriorityQueue(); + ~XLockFreePriorityQueue(); + + //////////////////////////////////////////////////////////////////////////////// + // Adds and entry to the priority queue. Returns // + // XLOCKFREE_STRUCTURE_FULL if there is no space to add the entry // + // // + // Returns XLOCKFREE_STRUCTURE_FULL if there is no space to add the // + // entry or the key exists in the queue and the queue was initialized // + // with XLOCKFREE_SINGLE_KEY_ENTRY // + // // + // If there is a wait function added to the queue the error code from that // + // function would be returned in the case of a failure // + //////////////////////////////////////////////////////////////////////////////// + HRESULT Add(__in DWORD key, __in _T* entry); + + /////////////////////////////////////////////////////////////////////////////// + // Manually release all the priority queue resources. The priority queue // + // should not be used after this method has been called. // + /////////////////////////////////////////////////////////////////////////////// + void Destroy(); + + /////////////////////////////////////////////////////////////////////// + // Returns the amount of memory allocated for the priority queue. // + /////////////////////////////////////////////////////////////////////// + DWORD GetAllocated() const; + + ////////////////////////////////////////////////////////////////////////////////// + // Returns the number of entries in the priority queue (is a snapshot in time). // + ////////////////////////////////////////////////////////////////////////////////// + DWORD GetEntryCount() const; + + /////////////////////////////////////////////////////////////////////////////// + // Creates a priority queue structure that will allocate nodes as // + // required to add new entries and will not block when adding or removing // + // entries. // + /////////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(); + + ///////////////////////////////////////////////////////////////////////////// + // Creates a priority queue structure where the maximum number of // + // elements, the number of allocations and whether calls will block can // + // be specified. If waiting is specified in the attributes then an // + // optional custom Wait functions can be also added. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(__in_opt PXLOCKFREE_CREATE info); + + //////////////////////////////////////////////////////////////////////////// + // Returns TRUE if there are currently no items in the priority queue // + //////////////////////////////////////////////////////////////////////////// + BOOL IsEmpty() const; + + ///////////////////////////////////////////////////////////////////////////// + // Returns the first entry in the priority queue (the entry with the // + // lowest key). Returns NULL if no entry is available. Because the // + // queue can be used in a multithreaded environment it is very possible // + // that a call to Search() will return TRUE and Remove() will return // + // NULL. By the time the Remove() has executed another thread may have // + // taken entries. The program must always test for a NULL. // + ///////////////////////////////////////////////////////////////////////////// + _T* RemoveFirst(); + + ////////////////////////////////////////////////////////////////////////////// + // Returns the first entry in the queue (the entry with the lowest key). // + // Returns XLOCKFREE_STRUCTURE_EMPTY if no entry is available. If there // + // is a wait function added to the queue the error code from that // + // function would be returned in the case of a failure. // + ////////////////////////////////////////////////////////////////////////////// + HRESULT RemoveFirst(__deref_out _T** ref); + + /////////////////////////////////////////////////////////////////////////////// + // Returns the entry in the queue identified by 'key'. Returns NULL if no // + // entry is available. Because the queue can be used in a multithreaded // + // environment it is very possible that a call to Search() will return // + // TRUE and Remove() will return NULL. By the time the Remove() has // + // executed another thread may have taken entries. The program must // + // always test for a NULL. // + /////////////////////////////////////////////////////////////////////////////// + _T* Remove(__in DWORD key); + + /////////////////////////////////////////////////////////////////////////// + // Returns the entry in the queue identified by 'key'. Returns // + // XLOCKFREE_STRUCTURE_EMPTY if no entry is available. If there is a // + // wait function added to the queue the error code from that function // + // would be returned in the case of a failure. // + /////////////////////////////////////////////////////////////////////////// + HRESULT Remove(__in DWORD key, __deref_out _T** ref); + + PVOID operator new( __in size_t size ); + void operator delete(__in_opt PVOID p); + PVOID operator new[]( __in size_t size ); + void operator delete[](__in_opt PVOID p); + + ///////////////////////////////////////////////////////////////////////////////// + // Dump the priority queue. Context is user defined and passed into the // + // dump function along with every entry in the priority queue. This routine is // + // NOT thread safe. // + ///////////////////////////////////////////////////////////////////////////////// + HRESULT UnsafeDump(__in PVOID context, __in XLockFreeUnsafeDump function); + + +private: + XLockFreePriorityQueue(__in const XLockFreePriorityQueue& q) {} // Copy constructor not allowed. + XLOCKFREE_HANDLE queue; +}; + + + +///////////////////////////////////////////////////////////////////////////////// +// XLockFreeHashTable // +// ------------------ // +// // +// Creates a hash table that can accept T objects. The default // +// implementation supplies functions for comparing keys and for hashing // +// the key // +// // +// Creates a hash table structure. Care needs to be taken when // +// creating a hash table structure that will be visible to multiple // +// threads. The hash table should be constructed before threads are started // +// should be passed as a parameter to the thread procedure, or should // +// have the global reference updated using an interlocked function // +///////////////////////////////////////////////////////////////////////////////// + +template > +class XLockFreeHashTable : _XFunctions +{ +public: + XLockFreeHashTable(); + ~XLockFreeHashTable(); + + ///////////////////////////////////////////////////////////////////////////// + // Adds an entry to the hash table. The entries are added in the // + // numerical order of the keys. // + // // + // Returns XLOCKFREE_STRUCTURE_FULL if there is no space to add the entry // + // or the entry exists in the table and the table was initialized with // + // XLOCKFREE_SINGLE_KEY_ENTRY. // + // // + // If there is a wait function added to the queue the error code from // + // that function would be returned in the case of a failure // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Add(__in DWORD key, __in _T* entry); + + ///////////////////////////////////////////////////////////////////////////// + // Manually release all the hash table resources. The hash table should // + // not be used after this method is called. // + ///////////////////////////////////////////////////////////////////////////// + void Destroy(); + + ///////////////////////////////////////////////////////////////////////////// + // Returns the amount of memory currently allocated for the hash table. // + ///////////////////////////////////////////////////////////////////////////// + DWORD GetAllocated() const; + + ////////////////////////////////////////////////////////////////////////////// + // Returns the number of entries in the hash table (is a snapshot in time). // + ////////////////////////////////////////////////////////////////////////////// + DWORD GetEntryCount() const; + + ///////////////////////////////////////////////////////////////////////////// + // Creates a hash table that will allocate nodes as required to add new // + // entries and will not block when adding or removing entries. // + // // + // There hash table will be created with a fixed number of buckets. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(__in DWORD buckets); + + ///////////////////////////////////////////////////////////////////////////// + // Creates a hash table structure where the maximum number of elements, // + // the number of allocations and whether calls will block can be // + // specified. If the maximum number of elements is specified then // + // optional custom Wait functions can be also added. // + // // + // There hash table will be created with a fixed number of buckets. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(__in_opt PXLOCKFREE_CREATE info, __in DWORD buckets); + + ///////////////////////////////////////////////////////////////////////////// + // Returns TRUE if there are currently no items in the hash table // + ///////////////////////////////////////////////////////////////////////////// + BOOL IsEmpty() const; + + ///////////////////////////////////////////////////////////////////////////// + // Returns the first entry in the hash table (the entry with the lowest // + // key). // + // // + // Returns NULL if no entry is available. // + ///////////////////////////////////////////////////////////////////////////// + _T* RemoveFirst(); + + //////////////////////////////////////////////////////////////////////////// + // Returns the first entry in the hash table queue (the entry with the // + // lowest key). // + // // + // Returns XLOCKFREE_STRUCTURE_EMPTY if no entry is available. // + //////////////////////////////////////////////////////////////////////////// + HRESULT RemoveFirst(__deref_out _T** ref); + + /////////////////////////////////////////////////////////////////////////////// + // Returns the entry in the table identified by 'key'. Returns NULL if no // + // entry is available. Because the table can be used in a multithreaded // + // environment it is very possible that a call to Remove() will return // + // NULL. The program must always test for a NULL. // + /////////////////////////////////////////////////////////////////////////////// + _T* Remove(__in DWORD key); + + /////////////////////////////////////////////////////////////////////////// + // Returns the entry in the queue identified by 'key'. // + // // + // Returns XLOCKFREE_STRUCTURE_EMPTY if no entry is available. // + // // + // If there is a wait function added to the queue the error code from // + // that function would be returned in the case of a failure. // + /////////////////////////////////////////////////////////////////////////// + HRESULT Remove(__in DWORD key, __deref_out _T** ref); + + PVOID operator new( __in size_t size ); + void operator delete(__in_opt PVOID p); + PVOID operator new[]( __in size_t size ); + void operator delete[](__in_opt PVOID p); + + ///////////////////////////////////////////////////////////////////////////// + // Dump the hashtable. Context is user defined and passed into the dump // + // function along with every entry in the hash table. This routine is not // + // thread safe. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT UnsafeDump(__in PVOID context, __in XLockFreeUnsafeDump function); + + +private: + XLOCKFREE_HANDLE hashTable; + XLockFreeHashTable(__in const XLockFreeHashTable& h) {} +}; + + +///////////////////////////////////////////////////////////////////////////////// +// Often the number of lockable objects is huge. For example, an // +// implementation of a thread-safe hash table requires one lock per hash // +// chain (using one lock per hash table considerably reduces // +// performance). In such situations the number of two-way locks (and thus // +// event handles and size of memory required) grows proportionally to the // +// number of lockable objects. // +// // +// This class implements a pool of fast two locks. A fast two lock provides // +// exclusive or shared access where requests for exclusive lock will be // +// satisfied ahead of any requests for shared locks (it does not matter // +// of timing (traditional implementations process lock requests on "first // +// came first served" basis). // +// // +// In this implementation the number of event/semaphore pairs that are // +// actually required never exceeds the max number of threads running // +// simultaneousely (this limit may be reached on complete deadlock), and // +// since this number of threads that process may simultaneousely create is // +// very limited and the use of too many threads (more than few dozens) // +// considerably reduces performance, the total amount of required // +// synchonization events is limited and does not depend on number of // +// lockable objects. // +///////////////////////////////////////////////////////////////////////////////// + +class XLockFreeLockPool +{ + public: + XLockFreeLockPool(); + ~XLockFreeLockPool(); + + // + // Pool functions + // + ///////////////////////////////////////////////////////////////////////////// + // Releases all resources associated with the pool The pool cannot be // + // used after calling this function. // + ///////////////////////////////////////////////////////////////////////////// + void Destroy(); + + ///////////////////////////////////////////////////////////////////////////// + // Returns the amount of memory allocated for the Pool. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT GetAllocated(__out DWORD* allocated); + + ///////////////////////////////////////////////////////////////////////////// + // Sets up the lock pool. This must be done prior to any other methods // + // calls on the Pool are attempted. If multiple threads will be accessing // + // the Pool it must be finished initializing before any other thread uses // + // the object. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(); + + ///////////////////////////////////////////////////////////////////////////// + // Initializes the pool with custom information. The amount of memory // + // that is allocated, whether a thread should wait or not when accessing // + // the pool, and what the custom wait function should be. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Initialize(__in_opt XLOCKFREE_POOL* info); + + // + // Lock functions + // + ///////////////////////////////////////////////////////////////////////////// + // Acquire a lock. The lock can either be shared (multiple readers) or // + // exclusive (one writer). The writers are queued up in order of // + // requests. The only exception to this is when a shared lock is // + // upgraded. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Acquire(__in TWO_WAY_LOCK_ACTIONS action, __in TWO_WAY_LOCK* lock); + + ///////////////////////////////////////////////////////////////////////////// + // Returns the number of locks allocated for the pool (does not include // + // locks that were created using external memory - see SetupExternal()) // + ///////////////////////////////////////////////////////////////////////////// + DWORD GetCount() const; + + ///////////////////////////////////////////////////////////////////////////// + // Increases the number of locks created in the Pool. Useful when the // + // total number of locks is known. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Increase(__in DWORD number); + + ///////////////////////////////////////////////////////////////////////////// + // Creates a lock that can be used to protect data or synchronize // + // execution. The lock is created using the Pool's memory routines. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Obtain(__deref_out TWO_WAY_LOCK** lock); + + ///////////////////////////////////////////////////////////////////////////// + // Releases a lock that has been acquired (see Acquire()). The action // + // must be identical to the action used when acquiring the lock. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Release(__in TWO_WAY_LOCK_ACTIONS action, __in TWO_WAY_LOCK* lock); + + ///////////////////////////////////////////////////////////////////////////// + // Returns the lock to pool so it can be reused. Only locks that were // + // created with Obtain() can be returned to the pool. Locks that are // + // created using SetupExternal() are not returned. // + ///////////////////////////////////////////////////////////////////////////// + HRESULT Return(__in TWO_WAY_LOCK* lock); + + ///////////////////////////////////////////////////////////////////////////// + // Initializes a lock using memory supplied by the caller. The memory // + // must by 4 byte aligned. Memory management of the lock is the // + // responsibility of the caller. This lock can not be returned to the // + // pool (see Return()). // + ///////////////////////////////////////////////////////////////////////////// + HRESULT SetupExternal(__in TWO_WAY_LOCK* lock); + + // + // System resource functions + // + /////////////////////////////////////////////////////////////////////////////// + // Returns the number of event/semaphore pairs used by the Pool. The // + // number will not exceed 32767. An event/semaphore pair is only required // + // when there is contention between locks. Pairs are shared between locks // + // because the maximum number required at any given point during // + // execution is determined by the number of simultaneously executing // + // threads. // + /////////////////////////////////////////////////////////////////////////////// + DWORD GetEventCount() const; + + /////////////////////////////////////////////////////////////////////////////// + // Increase the number of events/semaphore pairs available to the // + // Pool. (Maximum 32767). This function is useful when the maximum number // + // concurrently running threads is known in advance. // + /////////////////////////////////////////////////////////////////////////////// + HRESULT IncreaseEvents(__in DWORD number); + + private: + XLOCKFREE_HANDLE pool; +}; + +//////////////////////////////////////////////////////////////////////////// +// LOGGING FACILITY // +// // +// Create a log file that does the physical writes to the file on the // +// requested core. The log allocates a fixed number of messages of a // +// specified length. The can log can either be blocking or // +// non-blocking. If the log is non-blocking it will drop messages. The // +// number of dropped messages is reported when the log is shut down. // +// // +// N.B. Log created with InitializeUser writes to the debugger only // +// when _DEBUG is defined. The default behavior can be changed by // +// overriding LogMessage(PBYTE buffer, DWORD length). // +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////// +// Logs directly to file or output // +//////////////////////////////////////// +class XLockFreeLog +{ + public: + XLockFreeLog(); + virtual ~XLockFreeLog(); + + HRESULT Initialize( __in int requestedCore, // Run the logging facility on this core + __in_z LPCSTR logFile, // Log messages to this file + __in int messageLength, // Maximum message length + __in int numberOfMessages, // Maximum number of messages allowed to be queued up + __in BOOL blockOnWrite); // Block if queue is at is maximum + + HRESULT InitializeUser(__in int requestedCore, // Run the logging facility on this core + __in int messageLength, // Maximum message length + __in int numberOfMessages, // Maximum number of messages allowed to be queued up + __in BOOL blockOnWrite); // Block if queue is at is maximum + + void Destroy(); + void LogPrint(__in_z const char* format, ...); + void LogBuffer(__in_bcount(length) PBYTE buffer, __in DWORD length); + + protected: + virtual HRESULT CALLBACK LogMessage(__in_bcount(length) PBYTE buffer, __in DWORD length); + private: + static HRESULT CALLBACK LogMessageCallback(__in PVOID context, __in_bcount(length) PBYTE buffer, __in DWORD length); // XLFLogMessage callback + XLockFreeLog(const XLockFreeLog&){} // Copy constructor not allowed. + XLOCKFREE_LOG log; +}; + +#include "xmcore.inl" + +#endif /* __cplusplus */ diff --git a/third_party/xbox_sdk/include/xmcore.inl b/third_party/xbox_sdk/include/xmcore.inl new file mode 100644 index 0000000..3d8b575 --- /dev/null +++ b/third_party/xbox_sdk/include/xmcore.inl @@ -0,0 +1,771 @@ +/************************************************************************** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * + * File: xmcore.inl + * Content: XMCore inline functions + * + **************************************************************************/ +#pragma once + +// XLockFreeStack +template inline XLockFreeStack<_T>::XLockFreeStack() +{ + stack = NULL; +} + +template inline XLockFreeStack<_T>::~XLockFreeStack() +{ + Destroy(); +} + +template inline void XLockFreeStack<_T>::Destroy() +{ + if(stack != NULL) + { + XLFStackDestroy(stack); + stack = NULL; + } +} + +template inline HRESULT XLockFreeStack<_T>::Initialize() +{ + return XLFStackCreate(NULL, &stack); +} + +template inline HRESULT XLockFreeStack<_T>::Initialize(PXLOCKFREE_CREATE info) +{ + if(info != NULL) + { + info->structureSize = sizeof(XLOCKFREE_CREATE); + } + return XLFStackCreate(info, &stack); +} + +template inline BOOL XLockFreeStack<_T>::IsEmpty() const +{ + if(stack != NULL) + return XLFStackIsEmpty(stack); + else + return TRUE; +} + +template inline DWORD XLockFreeStack<_T>::GetAllocated() const +{ + DWORD allocated; + if(SUCCEEDED(XLFStackAllocated(stack, &allocated))) + { + return allocated; + } + else + { + return 0; + } +} + +template inline DWORD XLockFreeStack<_T>::GetEntryCount() const +{ + LONG entries; + if(SUCCEEDED(XLFStackGetEntryCount(stack, &entries))) + { + return entries; + } + else + { + return 0; + } +} + +template inline _T* XLockFreeStack<_T>::Pop() +{ + PVOID data = NULL; + HRESULT hr = XLFStackPop(stack, &data); + if(SUCCEEDED(hr)) + return (_T*) data; + else + return NULL; +} + +template inline HRESULT XLockFreeStack<_T>::Pop(_T** ref) +{ + PVOID data = NULL; + HRESULT hr = XLFStackPop(stack, &data); + if(SUCCEEDED(hr) && ref != NULL) *ref = (_T*) data; + return hr; +} + +template inline HRESULT XLockFreeStack<_T>::Push(_T* entry) +{ + return XLFStackPush(stack, entry); +} + +template inline +PVOID XLockFreeStack<_T>::operator new( size_t size) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreeStack<_T>::operator delete(PVOID p) +{ + XLFFree(p); +} + +template inline +PVOID XLockFreeStack<_T>::operator new[]( size_t size) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreeStack<_T>::operator delete[](PVOID p) +{ + XLFFree(p); +} + +template inline +HRESULT XLockFreeStack<_T>::UnsafeDump(PVOID context, XLockFreeUnsafeDump func) +{ + return XLFStackUnsafeDump(stack, context, func); +} + +// XLockFree Queue +template inline XLockFreeQueue<_T>::XLockFreeQueue() +{ + queue = NULL; +} + +template inline XLockFreeQueue<_T>::~XLockFreeQueue() +{ + Destroy(); +} + +template inline HRESULT XLockFreeQueue<_T>::Add(_T* entry) +{ + return XLFQueueAdd(queue, entry); +} + +template inline void XLockFreeQueue<_T>::Destroy() +{ + if(queue != NULL) + { + XLFQueueDestroy(queue); + queue = NULL; + } +} + +template inline HRESULT XLockFreeQueue<_T>::Initialize() +{ + return XLFQueueCreate(NULL, &queue); +} + +template inline HRESULT XLockFreeQueue<_T>::Initialize(PXLOCKFREE_CREATE info) +{ + if(info != NULL) + { + info->structureSize = sizeof(XLOCKFREE_CREATE); + } + return XLFQueueCreate(info, &queue); +} + +template inline BOOL XLockFreeQueue<_T>::IsEmpty() const +{ + if(queue != NULL) + return XLFQueueIsEmpty(queue); + else + return TRUE; +} + +template inline DWORD XLockFreeQueue<_T>::GetAllocated() const +{ + DWORD allocated = 0; + if(SUCCEEDED(XLFQueueAllocated(queue, &allocated))) + { + return allocated; + } + else + { + return 0; + } +} + +template inline DWORD XLockFreeQueue<_T>::GetEntryCount() const +{ + LONG entries = 0; + if(SUCCEEDED(XLFQueueGetEntryCount(queue, &entries))) + { + return entries; + } + else + { + return 0; + } +} + +template inline _T* XLockFreeQueue<_T>::Remove() +{ + PVOID data = NULL; + HRESULT hr = XLFQueueRemove(queue, &data); + + if(SUCCEEDED(hr)) + return (_T*) data; + else + return NULL; +} + +template inline HRESULT XLockFreeQueue<_T>::Remove(_T** ref) +{ + PVOID data = NULL; + HRESULT hr = XLFQueueRemove(queue, &data); + if(SUCCEEDED(hr) && ref != NULL) *ref = (_T*) data; + return hr; +} + +template inline +PVOID XLockFreeQueue<_T>::operator new( size_t size ) +{ + return XLFAllocate( size ); +} + +template inline +void XLockFreeQueue<_T>::operator delete(PVOID p) +{ + XLFFree(p); +} + +template inline +PVOID XLockFreeQueue<_T>::operator new[]( size_t size ) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreeQueue<_T>::operator delete[](PVOID p) +{ + XLFFree(p); +} + +template inline +HRESULT XLockFreeQueue<_T>::UnsafeDump(PVOID context, XLockFreeUnsafeDump func) +{ + return XLFQueueUnsafeDump(queue, context, func); +} + +// XLockFreeCustom + +inline +int XLockFreeCustom::compare(int p1, int p2) +{ + ULONG left = (ULONG) p1; + ULONG right = (ULONG) p2; + + if(left < right) + return -1; + else if(left > right) + return 1; + else + return 0; +} + +inline +unsigned int XLockFreeCustom::hash(unsigned int key, unsigned int buckets) +{ + unsigned int mask = buckets - 1; + unsigned __int64 spot = (unsigned __int64)key * 0xfaf57cee85433e40 + + 0xfc2d7230d92f2eac; + unsigned int index = ((unsigned int) (spot >> 32)) & mask; + return index; +} + +inline +unsigned int XLockFreeCustom::bucketSize(unsigned int buckets) +{ + buckets = buckets & ~0x80000000; + unsigned int log2 = 1; + while(log2 < buckets) log2 = log2 << 1; + return log2; +} + +// XLockFreePriorityQueue +template inline XLockFreePriorityQueue<_T,_XFunctions>::XLockFreePriorityQueue() +{ + queue = NULL; +} + +template inline XLockFreePriorityQueue<_T,_XFunctions>::~XLockFreePriorityQueue() +{ + Destroy(); +} + +template inline HRESULT XLockFreePriorityQueue<_T,_XFunctions>::Add(DWORD key, _T* entry) +{ + return XLFPriorityQueueAdd(queue, key, entry); +} + +template inline void XLockFreePriorityQueue<_T,_XFunctions>::Destroy() +{ + if(queue != NULL) + { + XLFPriorityQueueDestroy(queue); + queue = NULL; + } +} + +template inline HRESULT XLockFreePriorityQueue<_T,_XFunctions>::Initialize() +{ + return Initialize(NULL); +} + +template inline HRESULT XLockFreePriorityQueue<_T,_XFunctions>::Initialize(PXLOCKFREE_CREATE info) +{ + HRESULT hr = S_OK; + XLOCKFREE_FUNCTIONS functions; + functions.structureSize = sizeof(XLOCKFREE_FUNCTIONS); + functions.compare = (XLockFreeCompareKeys) _func.compare; + functions.hash = (XLockFreeHashKey) _func.hash; + + if(info != NULL) + { + info->structureSize = sizeof(XLOCKFREE_CREATE); + } + hr = XLFPriorityQueueCreate(info, &functions, &queue); + return hr; +} + +template inline BOOL XLockFreePriorityQueue<_T,_XFunctions>::IsEmpty() const +{ + if(queue != NULL) + return XLFPriorityQueueIsEmpty(queue); + else + return TRUE; +} + +template inline DWORD XLockFreePriorityQueue<_T,_XFunctions>::GetAllocated() const +{ + DWORD allocated = 0; + if(SUCCEEDED(XLFPriorityQueueAllocated(queue, &allocated))) + { + return allocated; + } + else + { + return 0; + } +} + +template inline DWORD XLockFreePriorityQueue<_T,_XFunctions>::GetEntryCount() const +{ + LONG entries = 0; + if(SUCCEEDED(XLFPriorityQueueGetEntryCount(queue, &entries))) + { + return entries; + } + else + { + return 0; + } +} + +template inline _T* XLockFreePriorityQueue<_T,_XFunctions>::RemoveFirst() +{ + PVOID data = NULL; + HRESULT hr = XLFPriorityQueueRemoveFirst(queue, &data); + if(SUCCEEDED(hr)) + return (_T*) data; + else + return NULL; +} + +template inline HRESULT XLockFreePriorityQueue<_T,_XFunctions>::RemoveFirst(_T** ref) +{ + PVOID data = NULL; + HRESULT hr = XLFPriorityQueueRemoveFirst(queue, &data); + if(SUCCEEDED(hr) && ref != NULL) *ref = (_T*) data; + return hr; +} + +template inline _T* XLockFreePriorityQueue<_T,_XFunctions>::Remove(DWORD key) +{ + PVOID data = NULL; + HRESULT hr = XLFPriorityQueueRemove(queue, key, &data); + if(SUCCEEDED(hr)) + return (_T*) data; + else + return NULL; +} + +template inline HRESULT XLockFreePriorityQueue<_T,_XFunctions>::Remove(DWORD key, _T** ref) +{ + PVOID data = NULL; + HRESULT hr = XLFPriorityQueueRemove(queue, key, &data); + if(SUCCEEDED(hr) && ref != NULL) *ref = (_T*) data; + return hr; +} + +template inline +PVOID XLockFreePriorityQueue<_T,_XFunctions>::operator new( size_t size ) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreePriorityQueue<_T,_XFunctions>::operator delete(PVOID p) +{ + XLFFree(p); +} + +template inline +PVOID XLockFreePriorityQueue<_T,_XFunctions>::operator new[]( size_t size ) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreePriorityQueue<_T,_XFunctions>::operator delete[](PVOID p) +{ + XLFFree(p); +} + +template inline +HRESULT XLockFreePriorityQueue<_T,_XFunctions>::UnsafeDump(PVOID context, XLockFreeUnsafeDump func) +{ + return XLFPriorityQueueUnsafeDump(queue, context, func); +} + +// XLockFreeHashTable +template inline +XLockFreeHashTable<_T,_XFunctions>::XLockFreeHashTable() +{ + hashTable = NULL; +} + +template inline +XLockFreeHashTable<_T,_XFunctions>::~XLockFreeHashTable() +{ + Destroy(); +} + +template inline +HRESULT XLockFreeHashTable<_T,_XFunctions>::Add(DWORD key, _T* entry) +{ + return XLFHashTableAdd(hashTable, key, entry); +} + +template inline +void XLockFreeHashTable<_T,_XFunctions>::Destroy() +{ + if(hashTable != NULL) + { + XLFHashTableDestroy(hashTable); + hashTable = NULL; + } +} + +template inline +HRESULT XLockFreeHashTable<_T,_XFunctions>::Initialize(DWORD buckets) +{ + return Initialize(NULL, buckets); +} + +template inline +HRESULT XLockFreeHashTable<_T,_XFunctions>::Initialize(PXLOCKFREE_CREATE info, DWORD buckets) +{ + HRESULT hr = S_OK; + XLOCKFREE_FUNCTIONS functions; + if(buckets == 0 || ((buckets & 0x80000000) != 0)) + { + return E_INVALIDARG; + } + + functions.structureSize = sizeof(XLOCKFREE_FUNCTIONS); + functions.compare = (XLockFreeCompareKeys) _func.compare; + functions.hash = (XLockFreeHashKey) _func.hash; + buckets = _func.bucketSize(buckets); + + if(info != NULL) + { + info->structureSize = sizeof(XLOCKFREE_CREATE); + } + hr = XLFHashTableCreate(info, &functions, buckets, &hashTable); + return hr; +} + +template inline +BOOL XLockFreeHashTable<_T,_XFunctions>::IsEmpty() const +{ + if(hashTable != NULL) + return XLFHashTableIsEmpty(hashTable); + else + return TRUE; +} + +template inline +DWORD XLockFreeHashTable<_T,_XFunctions>::GetAllocated() const +{ + DWORD allocated = 0; + if(SUCCEEDED(XLFHashTableAllocated(hashTable, &allocated))) + { + return allocated; + } + else + { + return 0; + } +} + +template inline +DWORD XLockFreeHashTable<_T,_XFunctions>::GetEntryCount() const +{ + LONG entries = 0; + if(SUCCEEDED(XLFHashTableGetEntryCount(hashTable, &entries))) + { + return entries; + } + else + { + return 0; + } +} + +template inline +_T* XLockFreeHashTable<_T,_XFunctions>::RemoveFirst() +{ + PVOID data = NULL; + HRESULT hr = XLFHashTableRemoveFirst(hashTable, &data); + if(SUCCEEDED(hr)) + return (_T*) data; + else + return NULL; +} + +template inline +HRESULT XLockFreeHashTable<_T,_XFunctions>::RemoveFirst(_T** ref) +{ + PVOID data = NULL; + HRESULT hr = XLFHashTableRemoveFirst(hashTable, &data); + if(SUCCEEDED(hr) && ref != NULL) *ref = (_T*) data; + return hr; +} + +template inline +_T* XLockFreeHashTable<_T,_XFunctions>::Remove(DWORD key) +{ + PVOID data = NULL; + HRESULT hr = XLFHashTableRemove(hashTable, key, &data); + if(SUCCEEDED(hr)) + return (_T*) data; + else + return NULL; +} + +template inline +HRESULT XLockFreeHashTable<_T,_XFunctions>::Remove(DWORD key, _T** ref) +{ + PVOID data = NULL; + HRESULT hr = XLFHashTableRemove(hashTable, key, &data); + if(SUCCEEDED(hr) && ref != NULL) *ref = (_T*) data; + return hr; +} + +template inline +PVOID XLockFreeHashTable<_T,_XFunctions>::operator new( size_t size ) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreeHashTable<_T,_XFunctions>::operator delete(PVOID p) +{ + XLFFree(p); +} + +template inline +PVOID XLockFreeHashTable<_T,_XFunctions>::operator new[]( size_t size ) +{ + return XLFAllocate(size); +} + +template inline +void XLockFreeHashTable<_T,_XFunctions>::operator delete[](PVOID p) +{ + XLFFree(p); +} + +template inline +HRESULT XLockFreeHashTable<_T,_XFunctions>::UnsafeDump(PVOID context, XLockFreeUnsafeDump func) +{ + return XLFHashTableUnsafeDump(hashTable, context, func); +} + + +// XLockFreeLockPool +inline XLockFreeLockPool::XLockFreeLockPool() +{ + pool = NULL; +} + +inline XLockFreeLockPool::~XLockFreeLockPool() +{ + Destroy(); +} + +inline HRESULT XLockFreeLockPool::Acquire(TWO_WAY_LOCK_ACTIONS action, TWO_WAY_LOCK* lock) +{ + return XLFPoolAcquireLock(pool, action, lock); +} + +inline void XLockFreeLockPool::Destroy() +{ + if(pool != NULL) + { + XLFPoolDestroy(pool); + pool = NULL; + } +} + +inline HRESULT XLockFreeLockPool::Initialize() +{ + return XLFPoolCreate(NULL, &pool); +} + +inline HRESULT XLockFreeLockPool::Initialize(XLOCKFREE_POOL* info) +{ + if(info != NULL) + { + info->structureSize = sizeof(XLOCKFREE_POOL); + } + return XLFPoolCreate(info, &pool); +} + +inline HRESULT XLockFreeLockPool::GetAllocated(DWORD* allocated) +{ + return XLFPoolAllocated(pool, allocated); +} + +inline HRESULT XLockFreeLockPool::Obtain(TWO_WAY_LOCK** lock) +{ + return XLFPoolCreateLock(pool, lock); +} + +inline HRESULT XLockFreeLockPool::Return(TWO_WAY_LOCK* lock) +{ + return XLFPoolDestroyLock(pool, lock); +} + +inline HRESULT XLockFreeLockPool::IncreaseEvents(DWORD number) +{ + return XLFPoolIncreaseEvents(pool, number); +} + +inline HRESULT XLockFreeLockPool::Increase(DWORD number) +{ + return XLFPoolIncreaseLocks(pool, number); +} + +inline HRESULT XLockFreeLockPool::SetupExternal(TWO_WAY_LOCK* lock) +{ + return XLFPoolInitializeLock(pool, lock); +} + +inline DWORD XLockFreeLockPool::GetEventCount() const +{ + DWORD count = 0; + if(SUCCEEDED(XLFPoolNumberOfEvents(pool, &count))) + { + return count; + } + else + { + return 0; + } +} + +inline DWORD XLockFreeLockPool::GetCount() const +{ + DWORD count = 0; + if(SUCCEEDED(XLFPoolNumberOfLocks(pool, &count))) + { + return count; + } + else + { + return 0; + } +} + +inline HRESULT XLockFreeLockPool::Release(TWO_WAY_LOCK_ACTIONS action, TWO_WAY_LOCK* lock) +{ + return XLFPoolReleaseLock(pool, action, lock); +} + +// XLockFreeLog +inline XLockFreeLog::XLockFreeLog() +{ + log = NULL; +} + +inline XLockFreeLog::~XLockFreeLog() +{ + // + // N.B. If deriving from the XLockFreeLog class, we recommend that you implement a + // virtual destructor that calls Destroy(). + // + + Destroy(); +} + +inline void XLockFreeLog::Destroy() +{ + if (log != NULL) + { + XLFEndLog(log); + log = NULL; + } +} + +inline void XLockFreeLog::LogPrint(const char* format, ...) +{ + va_list args; + va_start(args, format); + XLFLogPrintV(log, format, args); + va_end(args); +} + +inline void XLockFreeLog::LogBuffer(PBYTE buffer, DWORD length) +{ + XLFLogBuffer(log, buffer, length); +} + +inline HRESULT XLockFreeLog::Initialize(int requestedCore, LPCSTR logFile, int messageLength, int numberOfMessages, BOOL blockOnWrite) +{ + if (log != NULL) + return E_UNEXPECTED; + + return XLFStartLog(requestedCore, logFile, messageLength, numberOfMessages, blockOnWrite, &log); +} + +inline HRESULT XLockFreeLog::InitializeUser(int requestedCore, int messageLength, int numberOfMessages, BOOL blockOnWrite) +{ + if (log != NULL) + return E_UNEXPECTED; + + return XLFStartUserLog(requestedCore, this, &XLockFreeLog::LogMessageCallback, messageLength, numberOfMessages, blockOnWrite, &log); +} + +inline HRESULT CALLBACK XLockFreeLog::LogMessageCallback(PVOID context, PBYTE buffer, DWORD length) +{ + XLockFreeLog* inst = (XLockFreeLog*) context; + return inst->LogMessage(buffer, length); +} + +inline HRESULT CALLBACK XLockFreeLog::LogMessage(PBYTE buffer, DWORD length) +{ + UNREFERENCED_PARAMETER(length); +#ifndef _DEBUG + UNREFERENCED_PARAMETER(buffer); +#else + OutputDebugStringA((LPCSTR)buffer); +#endif + + return S_OK; +} diff --git a/third_party/xbox_sdk/include/xnamath.h b/third_party/xbox_sdk/include/xnamath.h new file mode 100644 index 0000000..941af11 --- /dev/null +++ b/third_party/xbox_sdk/include/xnamath.h @@ -0,0 +1,3397 @@ +/************************************************************************ +* * +* XNAMath.h -- SIMD C++ Math library for Windows and Xbox 360 * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ + +#if defined(_MSC_VER) && (_MSC_VER > 1000) +#pragma once +#endif + +#ifndef __XNAMATH_H__ +#define __XNAMATH_H__ + +#ifdef __XBOXMATH_H__ +#error XNAMATH and XBOXMATH are incompatible in the same compilation module. Use one or the other. +#endif + +#define XNAMATH_VERSION 205 + +#if !defined(_XM_X64_) && !defined(_XM_X86_) +#if defined(_M_AMD64) || defined(_AMD64_) +#define _XM_X64_ +#elif defined(_M_IX86) || defined(_X86_) +#define _XM_X86_ +#endif +#endif + + +#if !defined(_XM_BIGENDIAN_) && !defined(_XM_LITTLEENDIAN_) +#if defined(_XM_X64_) || defined(_XM_X86_) +#define _XM_LITTLEENDIAN_ +#elif defined(_XBOX_VER) +#define _XM_BIGENDIAN_ +#else +#error xnamath.h does not support this target +#endif +#endif + +#if defined(_XM_X86_) || defined(_XM_X64_) +#define _XM_SSE_INTRINSICS_ +#if !defined(__cplusplus) && !defined(_XM_NO_INTRINSICS_) +#error xnamath.h only supports C compliation for Xbox 360 targets and no intrinsics cases for x86/x64 +#endif +#elif defined(_XBOX_VER) +#if !defined(__VMX128_SUPPORTED) && !defined(_XM_NO_INTRINSICS_) +#error xnamath.h requires VMX128 compiler support for XBOX 360 +#endif // !__VMX128_SUPPORTED && !_XM_NO_INTRINSICS_ +#define _XM_VMX128_INTRINSICS_ +#elif !defined(_XM_NO_INTRINSICS_) +#error xnamath.h does not support this target +#endif + + +#if defined(_XM_SSE_INTRINSICS_) +#ifndef _XM_NO_INTRINSICS_ +#include +#include +#endif +#elif defined(_XM_VMX128_INTRINSICS_) +#error This version of xnamath.h does not support Xbox 360 +#endif + +#if defined(_XM_SSE_INTRINSICS_) +#pragma warning(push) +#pragma warning(disable:4985) +#endif +#include +#if defined(_XM_SSE_INTRINSICS_) +#pragma warning(pop) +#endif + + +#include + + +#if !defined(XMINLINE) +#if !defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#define XMINLINE __inline +#else +#define XMINLINE __forceinline +#endif +#endif + +#if !defined(XMFINLINE) +#define XMFINLINE __forceinline +#endif + +#if !defined(XMDEBUG) +#if defined(_DEBUG) +#define XMDEBUG +#endif +#endif // !XMDEBUG + +#if !defined(XMASSERT) +#if defined(_PREFAST_) +#define XMASSERT(Expression) __analysis_assume((Expression)) +#elif defined(XMDEBUG) // !_PREFAST_ +#define XMASSERT(Expression) ((VOID)((Expression) || (XMAssert(#Expression, __FILE__, __LINE__), 0))) +#else // !XMDEBUG +#define XMASSERT(Expression) ((VOID)0) +#endif // !XMDEBUG +#endif // !XMASSERT + +#if !defined(XM_NO_ALIGNMENT) +#define _DECLSPEC_ALIGN_16_ __declspec(align(16)) +#else +#define _DECLSPEC_ALIGN_16_ +#endif + + +#if defined(_MSC_VER) && (_MSC_VER<1500) && (_MSC_VER>=1400) +#define _XM_ISVS2005_ +#endif + +/**************************************************************************** + * + * Constant definitions + * + ****************************************************************************/ + +#define XM_PI 3.141592654f +#define XM_2PI 6.283185307f +#define XM_1DIVPI 0.318309886f +#define XM_1DIV2PI 0.159154943f +#define XM_PIDIV2 1.570796327f +#define XM_PIDIV4 0.785398163f + +#define XM_SELECT_0 0x00000000 +#define XM_SELECT_1 0xFFFFFFFF + +#define XM_PERMUTE_0X 0x00010203 +#define XM_PERMUTE_0Y 0x04050607 +#define XM_PERMUTE_0Z 0x08090A0B +#define XM_PERMUTE_0W 0x0C0D0E0F +#define XM_PERMUTE_1X 0x10111213 +#define XM_PERMUTE_1Y 0x14151617 +#define XM_PERMUTE_1Z 0x18191A1B +#define XM_PERMUTE_1W 0x1C1D1E1F + +#define XM_CRMASK_CR6 0x000000F0 +#define XM_CRMASK_CR6TRUE 0x00000080 +#define XM_CRMASK_CR6FALSE 0x00000020 +#define XM_CRMASK_CR6BOUNDS XM_CRMASK_CR6FALSE + + +#define XM_CACHE_LINE_SIZE 64 + +/**************************************************************************** + * + * Macros + * + ****************************************************************************/ + +// Unit conversion + +XMFINLINE FLOAT XMConvertToRadians(FLOAT fDegrees) { return fDegrees * (XM_PI / 180.0f); } +XMFINLINE FLOAT XMConvertToDegrees(FLOAT fRadians) { return fRadians * (180.0f / XM_PI); } + +// Condition register evaluation proceeding a recording (Rc) comparison + +#define XMComparisonAllTrue(CR) (((CR) & XM_CRMASK_CR6TRUE) == XM_CRMASK_CR6TRUE) +#define XMComparisonAnyTrue(CR) (((CR) & XM_CRMASK_CR6FALSE) != XM_CRMASK_CR6FALSE) +#define XMComparisonAllFalse(CR) (((CR) & XM_CRMASK_CR6FALSE) == XM_CRMASK_CR6FALSE) +#define XMComparisonAnyFalse(CR) (((CR) & XM_CRMASK_CR6TRUE) != XM_CRMASK_CR6TRUE) +#define XMComparisonMixed(CR) (((CR) & XM_CRMASK_CR6) == 0) +#define XMComparisonAllInBounds(CR) (((CR) & XM_CRMASK_CR6BOUNDS) == XM_CRMASK_CR6BOUNDS) +#define XMComparisonAnyOutOfBounds(CR) (((CR) & XM_CRMASK_CR6BOUNDS) != XM_CRMASK_CR6BOUNDS) + + +#define XMMin(a, b) (((a) < (b)) ? (a) : (b)) +#define XMMax(a, b) (((a) > (b)) ? (a) : (b)) + +/**************************************************************************** + * + * Data types + * + ****************************************************************************/ + +#pragma warning(push) +#pragma warning(disable:4201 4365 4324) + +#ifdef _XM_BIGENDIAN_ +#pragma bitfield_order(push) +#pragma bitfield_order(lsb_to_msb) +#endif + +//------------------------------------------------------------------------------ +#if defined(_XM_NO_INTRINSICS_) && !defined(_XBOX_VER) +// The __vector4 structure is an intrinsic on Xbox but must be separately defined +// for x86/x64 +typedef struct __vector4 +{ + union + { + float vector4_f32[4]; + unsigned int vector4_u32[4]; +#ifndef XM_STRICT_VECTOR4 + struct + { + FLOAT x; + FLOAT y; + FLOAT z; + FLOAT w; + }; + FLOAT v[4]; + UINT u[4]; +#endif // !XM_STRICT_VECTOR4 + }; +} __vector4; +#endif // _XM_NO_INTRINSICS_ + +//------------------------------------------------------------------------------ +#if (defined (_XM_X86_) || defined(_XM_X64_)) && defined(_XM_NO_INTRINSICS_) +typedef UINT __vector4i[4]; +#else +typedef __declspec(align(16)) UINT __vector4i[4]; +#endif + +//------------------------------------------------------------------------------ +// Vector intrinsic: Four 32 bit floating point components aligned on a 16 byte +// boundary and mapped to hardware vector registers +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +typedef __m128 XMVECTOR; +#else +typedef __vector4 XMVECTOR; +#endif + +// Fix-up for (1st-3rd) XMVECTOR parameters that are pass-in-register for x86 and Xbox 360, but not for other targets +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +typedef const XMVECTOR FXMVECTOR; +#elif defined(_XM_X86_) && !defined(_XM_NO_INTRINSICS_) +typedef const XMVECTOR FXMVECTOR; +#elif defined(__cplusplus) +typedef const XMVECTOR& FXMVECTOR; +#else +typedef const XMVECTOR FXMVECTOR; +#endif + +// Fix-up for (4th+) XMVECTOR parameters to pass in-register for Xbox 360 and by reference otherwise +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +typedef const XMVECTOR CXMVECTOR; +#elif defined(__cplusplus) +typedef const XMVECTOR& CXMVECTOR; +#else +typedef const XMVECTOR CXMVECTOR; +#endif + +//------------------------------------------------------------------------------ +// Conversion types for constants +typedef _DECLSPEC_ALIGN_16_ struct XMVECTORF32 { + union { + float f[4]; + XMVECTOR v; + }; + +#if defined(__cplusplus) + inline operator XMVECTOR() const { return v; } + inline operator const float*() const { return f; } +#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_) + inline operator __m128i() const { return reinterpret_cast(&v)[0]; } + inline operator __m128d() const { return reinterpret_cast(&v)[0]; } +#endif +#endif // __cplusplus +} XMVECTORF32; + +typedef _DECLSPEC_ALIGN_16_ struct XMVECTORI32 { + union { + INT i[4]; + XMVECTOR v; + }; +#if defined(__cplusplus) + inline operator XMVECTOR() const { return v; } +#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_) + inline operator __m128i() const { return reinterpret_cast(&v)[0]; } + inline operator __m128d() const { return reinterpret_cast(&v)[0]; } +#endif +#endif // __cplusplus +} XMVECTORI32; + +typedef _DECLSPEC_ALIGN_16_ struct XMVECTORU8 { + union { + BYTE u[16]; + XMVECTOR v; + }; +#if defined(__cplusplus) + inline operator XMVECTOR() const { return v; } +#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_) + inline operator __m128i() const { return reinterpret_cast(&v)[0]; } + inline operator __m128d() const { return reinterpret_cast(&v)[0]; } +#endif +#endif // __cplusplus +} XMVECTORU8; + +typedef _DECLSPEC_ALIGN_16_ struct XMVECTORU32 { + union { + UINT u[4]; + XMVECTOR v; + }; +#if defined(__cplusplus) + inline operator XMVECTOR() const { return v; } +#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_) + inline operator __m128i() const { return reinterpret_cast(&v)[0]; } + inline operator __m128d() const { return reinterpret_cast(&v)[0]; } +#endif +#endif // __cplusplus +} XMVECTORU32; + +//------------------------------------------------------------------------------ +// Vector operators +#if defined(__cplusplus) && !defined(XM_NO_OPERATOR_OVERLOADS) + +XMVECTOR operator+ (FXMVECTOR V); +XMVECTOR operator- (FXMVECTOR V); + +XMVECTOR& operator+= (XMVECTOR& V1, FXMVECTOR V2); +XMVECTOR& operator-= (XMVECTOR& V1, FXMVECTOR V2); +XMVECTOR& operator*= (XMVECTOR& V1, FXMVECTOR V2); +XMVECTOR& operator/= (XMVECTOR& V1, FXMVECTOR V2); +XMVECTOR& operator*= (XMVECTOR& V, FLOAT S); +XMVECTOR& operator/= (XMVECTOR& V, FLOAT S); + +XMVECTOR operator+ (FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR operator- (FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR operator* (FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR operator/ (FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR operator* (FXMVECTOR V, FLOAT S); +XMVECTOR operator* (FLOAT S, FXMVECTOR V); +XMVECTOR operator/ (FXMVECTOR V, FLOAT S); + +#endif // __cplusplus && !XM_NO_OPERATOR_OVERLOADS + +//------------------------------------------------------------------------------ +// Matrix type: Sixteen 32 bit floating point components aligned on a +// 16 byte boundary and mapped to four hardware vector registers +#if (defined(_XM_X86_) || defined(_XM_X64_)) && defined(_XM_NO_INTRINSICS_) +typedef struct _XMMATRIX +#else +typedef _DECLSPEC_ALIGN_16_ struct _XMMATRIX +#endif +{ +#if defined(_XM_NO_INTRINSICS_) || !defined(XM_STRICT_MATRIX) + union + { + XMVECTOR r[4]; + struct + { + FLOAT _11, _12, _13, _14; + FLOAT _21, _22, _23, _24; + FLOAT _31, _32, _33, _34; + FLOAT _41, _42, _43, _44; + }; + FLOAT m[4][4]; + }; +#else + XMVECTOR r[4]; +#endif + +#ifdef __cplusplus + + _XMMATRIX() {}; + _XMMATRIX(FXMVECTOR R0, FXMVECTOR R1, FXMVECTOR R2, CXMVECTOR R3); + _XMMATRIX(FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33); + explicit _XMMATRIX(_In_count_c_(16) CONST FLOAT *pArray); + +#if defined(_XM_NO_INTRINSICS_) || !defined(XM_STRICT_MATRIX) + FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } + FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } +#endif + + _XMMATRIX& operator= (CONST _XMMATRIX& M); + +#ifndef XM_NO_OPERATOR_OVERLOADS + _XMMATRIX& operator*= (CONST _XMMATRIX& M); + _XMMATRIX operator* (CONST _XMMATRIX& M) CONST; +#endif // !XM_NO_OPERATOR_OVERLOADS + +#endif // __cplusplus + +} XMMATRIX; + +// Fix-up for XMMATRIX parameters to pass in-register on Xbox 360, by reference otherwise +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +typedef const XMMATRIX CXMMATRIX; +#elif defined(__cplusplus) +typedef const XMMATRIX& CXMMATRIX; +#else +typedef const XMMATRIX CXMMATRIX; +#endif + +//------------------------------------------------------------------------------ +// 16 bit floating point number consisting of a sign bit, a 5 bit biased +// exponent, and a 10 bit mantissa +typedef USHORT HALF; + +//------------------------------------------------------------------------------ +// 2D Vector; 32 bit floating point components +typedef struct _XMFLOAT2 +{ + FLOAT x; + FLOAT y; + +#ifdef __cplusplus + + _XMFLOAT2() {}; + _XMFLOAT2(FLOAT _x, FLOAT _y) : x(_x), y(_y) {}; + _XMFLOAT2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMFLOAT2& operator= (CONST _XMFLOAT2& Float2); + +#endif // __cplusplus + +} XMFLOAT2; + +// 2D Vector; 32 bit floating point components aligned on a 16 byte boundary +#ifdef __cplusplus +__declspec(align(16)) struct XMFLOAT2A : public XMFLOAT2 +{ + XMFLOAT2A() : XMFLOAT2() {}; + XMFLOAT2A(FLOAT _x, FLOAT _y) : XMFLOAT2(_x, _y) {}; + XMFLOAT2A(_In_count_c_(2) CONST FLOAT *pArray) : XMFLOAT2(pArray) {}; + + XMFLOAT2A& operator= (CONST XMFLOAT2A& Float2); +}; +#else +typedef __declspec(align(16)) XMFLOAT2 XMFLOAT2A; +#endif // __cplusplus + +//------------------------------------------------------------------------------ +// 2D Vector; 32 bit signed integer components +typedef struct _XMINT2 +{ + INT x; + INT y; + +#ifdef __cplusplus + + _XMINT2() {}; + _XMINT2(INT _x, INT _y) : x(_x), y(_y) {}; + explicit _XMINT2(_In_count_c_(2) CONST INT *pArray); + + _XMINT2& operator= (CONST _XMINT2& Int2); + +#endif // __cplusplus + +} XMINT2; + +// 2D Vector; 32 bit unsigned integer components +typedef struct _XMUINT2 +{ + UINT x; + UINT y; + +#ifdef __cplusplus + + _XMUINT2() {}; + _XMUINT2(UINT _x, UINT _y) : x(_x), y(_y) {}; + explicit _XMUINT2(_In_count_c_(2) CONST UINT *pArray); + + _XMUINT2& operator= (CONST _XMUINT2& UInt2); + +#endif // __cplusplus + +} XMUINT2; + +//------------------------------------------------------------------------------ +// 2D Vector; 16 bit floating point components +typedef struct _XMHALF2 +{ + HALF x; + HALF y; + +#ifdef __cplusplus + + _XMHALF2() {}; + _XMHALF2(HALF _x, HALF _y) : x(_x), y(_y) {}; + explicit _XMHALF2(_In_count_c_(2) CONST HALF *pArray); + _XMHALF2(FLOAT _x, FLOAT _y); + explicit _XMHALF2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMHALF2& operator= (CONST _XMHALF2& Half2); + +#endif // __cplusplus + +} XMHALF2; + +//------------------------------------------------------------------------------ +// 2D Vector; 16 bit signed normalized integer components +typedef struct _XMSHORTN2 +{ + SHORT x; + SHORT y; + +#ifdef __cplusplus + + _XMSHORTN2() {}; + _XMSHORTN2(SHORT _x, SHORT _y) : x(_x), y(_y) {}; + explicit _XMSHORTN2(_In_count_c_(2) CONST SHORT *pArray); + _XMSHORTN2(FLOAT _x, FLOAT _y); + explicit _XMSHORTN2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMSHORTN2& operator= (CONST _XMSHORTN2& ShortN2); + +#endif // __cplusplus + +} XMSHORTN2; + +// 2D Vector; 16 bit signed integer components +typedef struct _XMSHORT2 +{ + SHORT x; + SHORT y; + +#ifdef __cplusplus + + _XMSHORT2() {}; + _XMSHORT2(SHORT _x, SHORT _y) : x(_x), y(_y) {}; + explicit _XMSHORT2(_In_count_c_(2) CONST SHORT *pArray); + _XMSHORT2(FLOAT _x, FLOAT _y); + explicit _XMSHORT2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMSHORT2& operator= (CONST _XMSHORT2& Short2); + +#endif // __cplusplus + +} XMSHORT2; + +// 2D Vector; 16 bit unsigned normalized integer components +typedef struct _XMUSHORTN2 +{ + USHORT x; + USHORT y; + +#ifdef __cplusplus + + _XMUSHORTN2() {}; + _XMUSHORTN2(USHORT _x, USHORT _y) : x(_x), y(_y) {}; + explicit _XMUSHORTN2(_In_count_c_(2) CONST USHORT *pArray); + _XMUSHORTN2(FLOAT _x, FLOAT _y); + explicit _XMUSHORTN2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMUSHORTN2& operator= (CONST _XMUSHORTN2& UShortN2); + +#endif // __cplusplus + +} XMUSHORTN2; + +// 2D Vector; 16 bit unsigned integer components +typedef struct _XMUSHORT2 +{ + USHORT x; + USHORT y; + +#ifdef __cplusplus + + _XMUSHORT2() {}; + _XMUSHORT2(USHORT _x, USHORT _y) : x(_x), y(_y) {}; + explicit _XMUSHORT2(_In_count_c_(2) CONST USHORT *pArray); + _XMUSHORT2(FLOAT _x, FLOAT _y); + explicit _XMUSHORT2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMUSHORT2& operator= (CONST _XMUSHORT2& UShort2); + +#endif // __cplusplus + +} XMUSHORT2; + +//------------------------------------------------------------------------------ +// 2D Vector; 8 bit signed normalized integer components +typedef struct _XMBYTEN2 +{ + CHAR x; + CHAR y; + +#ifdef __cplusplus + + _XMBYTEN2() {}; + _XMBYTEN2(CHAR _x, CHAR _y) : x(_x), y(_y) {}; + explicit _XMBYTEN2(_In_count_c_(2) CONST CHAR *pArray); + _XMBYTEN2(FLOAT _x, FLOAT _y); + explicit _XMBYTEN2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMBYTEN2& operator= (CONST _XMBYTEN2& ByteN2); + +#endif // __cplusplus + +} XMBYTEN2; + +// 2D Vector; 8 bit signed integer components +typedef struct _XMBYTE2 +{ + CHAR x; + CHAR y; + +#ifdef __cplusplus + + _XMBYTE2() {}; + _XMBYTE2(CHAR _x, CHAR _y) : x(_x), y(_y) {}; + explicit _XMBYTE2(_In_count_c_(2) CONST CHAR *pArray); + _XMBYTE2(FLOAT _x, FLOAT _y); + explicit _XMBYTE2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMBYTE2& operator= (CONST _XMBYTE2& Byte2); + +#endif // __cplusplus + +} XMBYTE2; + +// 2D Vector; 8 bit unsigned normalized integer components +typedef struct _XMUBYTEN2 +{ + BYTE x; + BYTE y; + +#ifdef __cplusplus + + _XMUBYTEN2() {}; + _XMUBYTEN2(BYTE _x, BYTE _y) : x(_x), y(_y) {}; + explicit _XMUBYTEN2(_In_count_c_(2) CONST BYTE *pArray); + _XMUBYTEN2(FLOAT _x, FLOAT _y); + explicit _XMUBYTEN2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMUBYTEN2& operator= (CONST _XMUBYTEN2& UByteN2); + +#endif // __cplusplus + +} XMUBYTEN2; + + +// 2D Vector; 8 bit unsigned integer components +typedef struct _XMUBYTE2 +{ + BYTE x; + BYTE y; + +#ifdef __cplusplus + + _XMUBYTE2() {}; + _XMUBYTE2(BYTE _x, BYTE _y) : x(_x), y(_y) {}; + explicit _XMUBYTE2(_In_count_c_(2) CONST BYTE *pArray); + _XMUBYTE2(FLOAT _x, FLOAT _y); + explicit _XMUBYTE2(_In_count_c_(2) CONST FLOAT *pArray); + + _XMUBYTE2& operator= (CONST _XMUBYTE2& UByte2); + +#endif // __cplusplus + +} XMUBYTE2; + +//------------------------------------------------------------------------------ +// 3D Vector; 32 bit floating point components +typedef struct _XMFLOAT3 +{ + FLOAT x; + FLOAT y; + FLOAT z; + +#ifdef __cplusplus + + _XMFLOAT3() {}; + _XMFLOAT3(FLOAT _x, FLOAT _y, FLOAT _z) : x(_x), y(_y), z(_z) {}; + _XMFLOAT3(_In_count_c_(3) CONST FLOAT *pArray); + + _XMFLOAT3& operator= (CONST _XMFLOAT3& Float3); + +#endif // __cplusplus + +} XMFLOAT3; + +// 3D Vector; 32 bit floating point components aligned on a 16 byte boundary +#ifdef __cplusplus +__declspec(align(16)) struct XMFLOAT3A : public XMFLOAT3 +{ + XMFLOAT3A() : XMFLOAT3() {}; + XMFLOAT3A(FLOAT _x, FLOAT _y, FLOAT _z) : XMFLOAT3(_x, _y, _z) {}; + XMFLOAT3A(_In_count_c_(3) CONST FLOAT *pArray) : XMFLOAT3(pArray) {}; + + XMFLOAT3A& operator= (CONST XMFLOAT3A& Float3); +}; +#else +typedef __declspec(align(16)) XMFLOAT3 XMFLOAT3A; +#endif // __cplusplus + +//------------------------------------------------------------------------------ +// 3D Vector; 32 bit signed integer components +typedef struct _XMINT3 +{ + INT x; + INT y; + INT z; + +#ifdef __cplusplus + + _XMINT3() {}; + _XMINT3(INT _x, INT _y, INT _z) : x(_x), y(_y), z(_z) {}; + explicit _XMINT3(_In_count_c_(3) CONST INT *pArray); + + _XMINT3& operator= (CONST _XMINT3& Int3); + +#endif // __cplusplus + +} XMINT3; + +// 3D Vector; 32 bit unsigned integer components +typedef struct _XMUINT3 +{ + UINT x; + UINT y; + UINT z; + +#ifdef __cplusplus + + _XMUINT3() {}; + _XMUINT3(UINT _x, UINT _y, UINT _z) : x(_x), y(_y), z(_z) {}; + explicit _XMUINT3(_In_count_c_(3) CONST UINT *pArray); + + _XMUINT3& operator= (CONST _XMUINT3& UInt3); + +#endif // __cplusplus + +} XMUINT3; + +//------------------------------------------------------------------------------ +// 3D Vector; 11-11-10 bit normalized components packed into a 32 bit integer +// The normalized 3D Vector is packed into 32 bits as follows: a 10 bit signed, +// normalized integer for the z component and 11 bit signed, normalized +// integers for the x and y components. The z component is stored in the +// most significant bits and the x component in the least significant bits +// (Z10Y11X11): [32] zzzzzzzz zzyyyyyy yyyyyxxx xxxxxxxx [0] +typedef struct _XMHENDN3 +{ + union + { + struct + { + INT x : 11; // -1023/1023 to 1023/1023 + INT y : 11; // -1023/1023 to 1023/1023 + INT z : 10; // -511/511 to 511/511 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMHENDN3() {}; + explicit _XMHENDN3(UINT Packed) : v(Packed) {}; + _XMHENDN3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMHENDN3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMHENDN3& operator= (CONST _XMHENDN3& HenDN3); + _XMHENDN3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMHENDN3; + +// 3D Vector; 11-11-10 bit components packed into a 32 bit integer +// The 3D Vector is packed into 32 bits as follows: a 10 bit signed, +// integer for the z component and 11 bit signed integers for the +// x and y components. The z component is stored in the +// most significant bits and the x component in the least significant bits +// (Z10Y11X11): [32] zzzzzzzz zzyyyyyy yyyyyxxx xxxxxxxx [0] +typedef struct _XMHEND3 +{ + union + { + struct + { + INT x : 11; // -1023 to 1023 + INT y : 11; // -1023 to 1023 + INT z : 10; // -511 to 511 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMHEND3() {}; + explicit _XMHEND3(UINT Packed) : v(Packed) {}; + _XMHEND3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMHEND3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMHEND3& operator= (CONST _XMHEND3& HenD3); + _XMHEND3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMHEND3; + +// 3D Vector; 11-11-10 bit normalized components packed into a 32 bit integer +// The normalized 3D Vector is packed into 32 bits as follows: a 10 bit unsigned, +// normalized integer for the z component and 11 bit unsigned, normalized +// integers for the x and y components. The z component is stored in the +// most significant bits and the x component in the least significant bits +// (Z10Y11X11): [32] zzzzzzzz zzyyyyyy yyyyyxxx xxxxxxxx [0] +typedef struct _XMUHENDN3 +{ + union + { + struct + { + UINT x : 11; // 0/2047 to 2047/2047 + UINT y : 11; // 0/2047 to 2047/2047 + UINT z : 10; // 0/1023 to 1023/1023 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUHENDN3() {}; + explicit _XMUHENDN3(UINT Packed) : v(Packed) {}; + _XMUHENDN3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMUHENDN3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMUHENDN3& operator= (CONST _XMUHENDN3& UHenDN3); + _XMUHENDN3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMUHENDN3; + +// 3D Vector; 11-11-10 bit components packed into a 32 bit integer +// The 3D Vector is packed into 32 bits as follows: a 10 bit unsigned +// integer for the z component and 11 bit unsigned integers +// for the x and y components. The z component is stored in the +// most significant bits and the x component in the least significant bits +// (Z10Y11X11): [32] zzzzzzzz zzyyyyyy yyyyyxxx xxxxxxxx [0] +typedef struct _XMUHEND3 +{ + union + { + struct + { + UINT x : 11; // 0 to 2047 + UINT y : 11; // 0 to 2047 + UINT z : 10; // 0 to 1023 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUHEND3() {}; + explicit _XMUHEND3(UINT Packed) : v(Packed) {}; + _XMUHEND3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMUHEND3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMUHEND3& operator= (CONST _XMUHEND3& UHenD3); + _XMUHEND3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMUHEND3; + +// 3D Vector; 10-11-11 bit normalized components packed into a 32 bit integer +// The normalized 3D Vector is packed into 32 bits as follows: a 10 bit signed, +// normalized integer for the x component and 11 bit signed, normalized +// integers for the y and z components. The z component is stored in the +// most significant bits and the x component in the least significant bits +// (Z11Y11X10): [32] zzzzzzzz zzzyyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMDHENN3 +{ + union + { + struct + { + INT x : 10; // -511/511 to 511/511 + INT y : 11; // -1023/1023 to 1023/1023 + INT z : 11; // -1023/1023 to 1023/1023 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMDHENN3() {}; + explicit _XMDHENN3(UINT Packed) : v(Packed) {}; + _XMDHENN3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMDHENN3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMDHENN3& operator= (CONST _XMDHENN3& DHenN3); + _XMDHENN3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMDHENN3; + +// 3D Vector; 10-11-11 bit components packed into a 32 bit integer +// The 3D Vector is packed into 32 bits as follows: a 10 bit signed, +// integer for the x component and 11 bit signed integers for the +// y and z components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (Z11Y11X10): [32] zzzzzzzz zzzyyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMDHEN3 +{ + union + { + struct + { + INT x : 10; // -511 to 511 + INT y : 11; // -1023 to 1023 + INT z : 11; // -1023 to 1023 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMDHEN3() {}; + explicit _XMDHEN3(UINT Packed) : v(Packed) {}; + _XMDHEN3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMDHEN3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMDHEN3& operator= (CONST _XMDHEN3& DHen3); + _XMDHEN3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMDHEN3; + +// 3D Vector; 10-11-11 bit normalized components packed into a 32 bit integer +// The normalized 3D Vector is packed into 32 bits as follows: a 10 bit unsigned, +// normalized integer for the x component and 11 bit unsigned, normalized +// integers for the y and z components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (Z11Y11X10): [32] zzzzzzzz zzzyyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMUDHENN3 +{ + union + { + struct + { + UINT x : 10; // 0/1023 to 1023/1023 + UINT y : 11; // 0/2047 to 2047/2047 + UINT z : 11; // 0/2047 to 2047/2047 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUDHENN3() {}; + explicit _XMUDHENN3(UINT Packed) : v(Packed) {}; + _XMUDHENN3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMUDHENN3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMUDHENN3& operator= (CONST _XMUDHENN3& UDHenN3); + _XMUDHENN3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMUDHENN3; + +// 3D Vector; 10-11-11 bit components packed into a 32 bit integer +// The 3D Vector is packed into 32 bits as follows: a 10 bit unsigned, +// integer for the x component and 11 bit unsigned integers +// for the y and z components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (Z11Y11X10): [32] zzzzzzzz zzzyyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMUDHEN3 +{ + union + { + struct + { + UINT x : 10; // 0 to 1023 + UINT y : 11; // 0 to 2047 + UINT z : 11; // 0 to 2047 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUDHEN3() {}; + explicit _XMUDHEN3(UINT Packed) : v(Packed) {}; + _XMUDHEN3(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMUDHEN3(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMUDHEN3& operator= (CONST _XMUDHEN3& UDHen3); + _XMUDHEN3& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMUDHEN3; + +//------------------------------------------------------------------------------ +// 3D vector: 5/6/5 unsigned integer components +typedef struct _XMU565 +{ + union + { + struct + { + USHORT x : 5; + USHORT y : 6; + USHORT z : 5; + }; + USHORT v; + }; + +#ifdef __cplusplus + + _XMU565() {}; + explicit _XMU565(USHORT Packed) : v(Packed) {}; + _XMU565(CHAR _x, CHAR _y, CHAR _z) : x(_x), y(_y), z(_z) {}; + explicit _XMU565(_In_count_c_(3) CONST CHAR *pArray); + _XMU565(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMU565(_In_count_c_(3) CONST FLOAT *pArray); + + operator USHORT () const { return v; } + + _XMU565& operator= (CONST _XMU565& U565); + _XMU565& operator= (CONST USHORT Packed); + +#endif // __cplusplus + +} XMU565; + +//------------------------------------------------------------------------------ +// 3D vector: 11/11/10 floating-point components +// The 3D vector is packed into 32 bits as follows: a 5-bit biased exponent +// and 6-bit mantissa for x component, a 5-bit biased exponent and +// 6-bit mantissa for y component, a 5-bit biased exponent and a 5-bit +// mantissa for z. The z component is stored in the most significant bits +// and the x component in the least significant bits. No sign bits so +// all partial-precision numbers are positive. +// (Z10Y11X11): [32] ZZZZZzzz zzzYYYYY yyyyyyXX XXXxxxxx [0] +typedef struct _XMFLOAT3PK +{ + union + { + struct + { + UINT xm : 6; + UINT xe : 5; + UINT ym : 6; + UINT ye : 5; + UINT zm : 5; + UINT ze : 5; + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMFLOAT3PK() {}; + explicit _XMFLOAT3PK(UINT Packed) : v(Packed) {}; + _XMFLOAT3PK(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMFLOAT3PK(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMFLOAT3PK& operator= (CONST _XMFLOAT3PK& float3pk); + _XMFLOAT3PK& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMFLOAT3PK; + +//------------------------------------------------------------------------------ +// 3D vector: 9/9/9 floating-point components with shared 5-bit exponent +// The 3D vector is packed into 32 bits as follows: a 5-bit biased exponent +// with 9-bit mantissa for the x, y, and z component. The shared exponent +// is stored in the most significant bits and the x component mantissa is in +// the least significant bits. No sign bits so all partial-precision numbers +// are positive. +// (E5Z9Y9X9): [32] EEEEEzzz zzzzzzyy yyyyyyyx xxxxxxxx [0] +typedef struct _XMFLOAT3SE +{ + union + { + struct + { + UINT xm : 9; + UINT ym : 9; + UINT zm : 9; + UINT e : 5; + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMFLOAT3SE() {}; + explicit _XMFLOAT3SE(UINT Packed) : v(Packed) {}; + _XMFLOAT3SE(FLOAT _x, FLOAT _y, FLOAT _z); + explicit _XMFLOAT3SE(_In_count_c_(3) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMFLOAT3SE& operator= (CONST _XMFLOAT3SE& float3se); + _XMFLOAT3SE& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMFLOAT3SE; + +//------------------------------------------------------------------------------ +// 4D Vector; 32 bit floating point components +typedef struct _XMFLOAT4 +{ + FLOAT x; + FLOAT y; + FLOAT z; + FLOAT w; + +#ifdef __cplusplus + + _XMFLOAT4() {}; + _XMFLOAT4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}; + _XMFLOAT4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMFLOAT4& operator= (CONST _XMFLOAT4& Float4); + +#endif // __cplusplus + +} XMFLOAT4; + +// 4D Vector; 32 bit floating point components aligned on a 16 byte boundary +#ifdef __cplusplus +__declspec(align(16)) struct XMFLOAT4A : public XMFLOAT4 +{ + XMFLOAT4A() : XMFLOAT4() {}; + XMFLOAT4A(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w) : XMFLOAT4(_x, _y, _z, _w) {}; + XMFLOAT4A(_In_count_c_(4) CONST FLOAT *pArray) : XMFLOAT4(pArray) {}; + + XMFLOAT4A& operator= (CONST XMFLOAT4A& Float4); +}; +#else +typedef __declspec(align(16)) XMFLOAT4 XMFLOAT4A; +#endif // __cplusplus + +//------------------------------------------------------------------------------ +// 4D Vector; 32 bit signed integer components +typedef struct _XMINT4 +{ + INT x; + INT y; + INT z; + INT w; + +#ifdef __cplusplus + + _XMINT4() {}; + _XMINT4(INT _x, INT _y, INT _z, INT _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMINT4(_In_count_c_(4) CONST INT *pArray); + + _XMINT4& operator= (CONST _XMINT4& Int4); + +#endif // __cplusplus + +} XMINT4; + +// 4D Vector; 32 bit unsigned integer components +typedef struct _XMUINT4 +{ + UINT x; + UINT y; + UINT z; + UINT w; + +#ifdef __cplusplus + + _XMUINT4() {}; + _XMUINT4(UINT _x, UINT _y, UINT _z, UINT _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMUINT4(_In_count_c_(4) CONST UINT *pArray); + + _XMUINT4& operator= (CONST _XMUINT4& UInt4); + +#endif // __cplusplus + +} XMUINT4; + +//------------------------------------------------------------------------------ +// 4D Vector; 16 bit floating point components +typedef struct _XMHALF4 +{ + HALF x; + HALF y; + HALF z; + HALF w; + +#ifdef __cplusplus + + _XMHALF4() {}; + _XMHALF4(HALF _x, HALF _y, HALF _z, HALF _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMHALF4(_In_count_c_(4) CONST HALF *pArray); + _XMHALF4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMHALF4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMHALF4& operator= (CONST _XMHALF4& Half4); + +#endif // __cplusplus + +} XMHALF4; + +//------------------------------------------------------------------------------ +// 4D Vector; 16 bit signed normalized integer components +typedef struct _XMSHORTN4 +{ + SHORT x; + SHORT y; + SHORT z; + SHORT w; + +#ifdef __cplusplus + + _XMSHORTN4() {}; + _XMSHORTN4(SHORT _x, SHORT _y, SHORT _z, SHORT _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMSHORTN4(_In_count_c_(4) CONST SHORT *pArray); + _XMSHORTN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMSHORTN4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMSHORTN4& operator= (CONST _XMSHORTN4& ShortN4); + +#endif // __cplusplus + +} XMSHORTN4; + +// 4D Vector; 16 bit signed integer components +typedef struct _XMSHORT4 +{ + SHORT x; + SHORT y; + SHORT z; + SHORT w; + +#ifdef __cplusplus + + _XMSHORT4() {}; + _XMSHORT4(SHORT _x, SHORT _y, SHORT _z, SHORT _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMSHORT4(_In_count_c_(4) CONST SHORT *pArray); + _XMSHORT4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMSHORT4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMSHORT4& operator= (CONST _XMSHORT4& Short4); + +#endif // __cplusplus + +} XMSHORT4; + +// 4D Vector; 16 bit unsigned normalized integer components +typedef struct _XMUSHORTN4 +{ + USHORT x; + USHORT y; + USHORT z; + USHORT w; + +#ifdef __cplusplus + + _XMUSHORTN4() {}; + _XMUSHORTN4(USHORT _x, USHORT _y, USHORT _z, USHORT _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMUSHORTN4(_In_count_c_(4) CONST USHORT *pArray); + _XMUSHORTN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUSHORTN4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMUSHORTN4& operator= (CONST _XMUSHORTN4& UShortN4); + +#endif // __cplusplus + +} XMUSHORTN4; + +// 4D Vector; 16 bit unsigned integer components +typedef struct _XMUSHORT4 +{ + USHORT x; + USHORT y; + USHORT z; + USHORT w; + +#ifdef __cplusplus + + _XMUSHORT4() {}; + _XMUSHORT4(USHORT _x, USHORT _y, USHORT _z, USHORT _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMUSHORT4(_In_count_c_(4) CONST USHORT *pArray); + _XMUSHORT4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUSHORT4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMUSHORT4& operator= (CONST _XMUSHORT4& UShort4); + +#endif // __cplusplus + +} XMUSHORT4; + +//------------------------------------------------------------------------------ +// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer +// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned, +// normalized integer for the w component and 10 bit signed, normalized +// integers for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMXDECN4 +{ + union + { + struct + { + INT x : 10; // -511/511 to 511/511 + INT y : 10; // -511/511 to 511/511 + INT z : 10; // -511/511 to 511/511 + UINT w : 2; // 0/3 to 3/3 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMXDECN4() {}; + explicit _XMXDECN4(UINT Packed) : v(Packed) {}; + _XMXDECN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMXDECN4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMXDECN4& operator= (CONST _XMXDECN4& XDecN4); + _XMXDECN4& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMXDECN4; + +// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer +// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned +// integer for the w component and 10 bit signed integers for the +// z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMXDEC4 +{ + union + { + struct + { + INT x : 10; // -511 to 511 + INT y : 10; // -511 to 511 + INT z : 10; // -511 to 511 + UINT w : 2; // 0 to 3 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMXDEC4() {}; + explicit _XMXDEC4(UINT Packed) : v(Packed) {}; + _XMXDEC4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMXDEC4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMXDEC4& operator= (CONST _XMXDEC4& XDec4); + _XMXDEC4& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMXDEC4; + +// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer +// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit signed, +// normalized integer for the w component and 10 bit signed, normalized +// integers for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMDECN4 +{ + union + { + struct + { + INT x : 10; // -511/511 to 511/511 + INT y : 10; // -511/511 to 511/511 + INT z : 10; // -511/511 to 511/511 + INT w : 2; // -1/1 to 1/1 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMDECN4() {}; + explicit _XMDECN4(UINT Packed) : v(Packed) {}; + _XMDECN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMDECN4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMDECN4& operator= (CONST _XMDECN4& DecN4); + _XMDECN4& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMDECN4; + +// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer +// The 4D Vector is packed into 32 bits as follows: a 2 bit signed, +// integer for the w component and 10 bit signed integers for the +// z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMDEC4 +{ + union + { + struct + { + INT x : 10; // -511 to 511 + INT y : 10; // -511 to 511 + INT z : 10; // -511 to 511 + INT w : 2; // -1 to 1 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMDEC4() {}; + explicit _XMDEC4(UINT Packed) : v(Packed) {}; + _XMDEC4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMDEC4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMDEC4& operator= (CONST _XMDEC4& Dec4); + _XMDEC4& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMDEC4; + +// 4D Vector; 10-10-10-2 bit normalized components packed into a 32 bit integer +// The normalized 4D Vector is packed into 32 bits as follows: a 2 bit unsigned, +// normalized integer for the w component and 10 bit unsigned, normalized +// integers for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMUDECN4 +{ + union + { + struct + { + UINT x : 10; // 0/1023 to 1023/1023 + UINT y : 10; // 0/1023 to 1023/1023 + UINT z : 10; // 0/1023 to 1023/1023 + UINT w : 2; // 0/3 to 3/3 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUDECN4() {}; + explicit _XMUDECN4(UINT Packed) : v(Packed) {}; + _XMUDECN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUDECN4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMUDECN4& operator= (CONST _XMUDECN4& UDecN4); + _XMUDECN4& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMUDECN4; + +// 4D Vector; 10-10-10-2 bit components packed into a 32 bit integer +// The 4D Vector is packed into 32 bits as follows: a 2 bit unsigned, +// integer for the w component and 10 bit unsigned integers +// for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W2Z10Y10X10): [32] wwzzzzzz zzzzyyyy yyyyyyxx xxxxxxxx [0] +typedef struct _XMUDEC4 +{ + union + { + struct + { + UINT x : 10; // 0 to 1023 + UINT y : 10; // 0 to 1023 + UINT z : 10; // 0 to 1023 + UINT w : 2; // 0 to 3 + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUDEC4() {}; + explicit _XMUDEC4(UINT Packed) : v(Packed) {}; + _XMUDEC4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUDEC4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return v; } + + _XMUDEC4& operator= (CONST _XMUDEC4& UDec4); + _XMUDEC4& operator= (CONST UINT Packed); + +#endif // __cplusplus + +} XMUDEC4; + +//------------------------------------------------------------------------------ +// 4D Vector; 20-20-20-4 bit normalized components packed into a 64 bit integer +// The normalized 4D Vector is packed into 64 bits as follows: a 4 bit unsigned, +// normalized integer for the w component and 20 bit signed, normalized +// integers for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W4Z20Y20X20): [64] wwwwzzzz zzzzzzzz zzzzzzzz yyyyyyyy yyyyyyyy yyyyxxxx xxxxxxxx xxxxxxxx [0] +typedef struct _XMXICON4 +{ + union + { + struct + { + INT64 x : 20; // -524287/524287 to 524287/524287 + INT64 y : 20; // -524287/524287 to 524287/524287 + INT64 z : 20; // -524287/524287 to 524287/524287 + UINT64 w : 4; // 0/15 to 15/15 + }; + UINT64 v; + }; + +#ifdef __cplusplus + + _XMXICON4() {}; + explicit _XMXICON4(UINT64 Packed) : v(Packed) {}; + _XMXICON4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMXICON4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT64 () const { return v; } + + _XMXICON4& operator= (CONST _XMXICON4& XIcoN4); + _XMXICON4& operator= (CONST UINT64 Packed); + +#endif // __cplusplus + +} XMXICON4; + +// 4D Vector; 20-20-20-4 bit components packed into a 64 bit integer +// The 4D Vector is packed into 64 bits as follows: a 4 bit unsigned +// integer for the w component and 20 bit signed integers for the +// z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W4Z20Y20X20): [64] wwwwzzzz zzzzzzzz zzzzzzzz yyyyyyyy yyyyyyyy yyyyxxxx xxxxxxxx xxxxxxxx [0] +typedef struct _XMXICO4 +{ + union + { + struct + { + INT64 x : 20; // -524287 to 524287 + INT64 y : 20; // -524287 to 524287 + INT64 z : 20; // -524287 to 524287 + UINT64 w : 4; // 0 to 15 + }; + UINT64 v; + }; + +#ifdef __cplusplus + + _XMXICO4() {}; + explicit _XMXICO4(UINT64 Packed) : v(Packed) {}; + _XMXICO4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMXICO4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT64 () const { return v; } + + _XMXICO4& operator= (CONST _XMXICO4& XIco4); + _XMXICO4& operator= (CONST UINT64 Packed); + +#endif // __cplusplus + +} XMXICO4; + +// 4D Vector; 20-20-20-4 bit normalized components packed into a 64 bit integer +// The normalized 4D Vector is packed into 64 bits as follows: a 4 bit signed, +// normalized integer for the w component and 20 bit signed, normalized +// integers for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W4Z20Y20X20): [64] wwwwzzzz zzzzzzzz zzzzzzzz yyyyyyyy yyyyyyyy yyyyxxxx xxxxxxxx xxxxxxxx [0] +typedef struct _XMICON4 +{ + union + { + struct + { + INT64 x : 20; // -524287/524287 to 524287/524287 + INT64 y : 20; // -524287/524287 to 524287/524287 + INT64 z : 20; // -524287/524287 to 524287/524287 + INT64 w : 4; // -7/7 to 7/7 + }; + UINT64 v; + }; + +#ifdef __cplusplus + + _XMICON4() {}; + explicit _XMICON4(UINT64 Packed) : v(Packed) {}; + _XMICON4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMICON4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT64 () const { return v; } + + _XMICON4& operator= (CONST _XMICON4& IcoN4); + _XMICON4& operator= (CONST UINT64 Packed); + +#endif // __cplusplus + +} XMICON4; + +// 4D Vector; 20-20-20-4 bit components packed into a 64 bit integer +// The 4D Vector is packed into 64 bits as follows: a 4 bit signed, +// integer for the w component and 20 bit signed integers for the +// z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W4Z20Y20X20): [64] wwwwzzzz zzzzzzzz zzzzzzzz yyyyyyyy yyyyyyyy yyyyxxxx xxxxxxxx xxxxxxxx [0] +typedef struct _XMICO4 +{ + union + { + struct + { + INT64 x : 20; // -524287 to 524287 + INT64 y : 20; // -524287 to 524287 + INT64 z : 20; // -524287 to 524287 + INT64 w : 4; // -7 to 7 + }; + UINT64 v; + }; + +#ifdef __cplusplus + + _XMICO4() {}; + explicit _XMICO4(UINT64 Packed) : v(Packed) {}; + _XMICO4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMICO4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT64 () const { return v; } + + _XMICO4& operator= (CONST _XMICO4& Ico4); + _XMICO4& operator= (CONST UINT64 Packed); + +#endif // __cplusplus + +} XMICO4; + +// 4D Vector; 20-20-20-4 bit normalized components packed into a 64 bit integer +// The normalized 4D Vector is packed into 64 bits as follows: a 4 bit unsigned, +// normalized integer for the w component and 20 bit unsigned, normalized +// integers for the z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W4Z20Y20X20): [64] wwwwzzzz zzzzzzzz zzzzzzzz yyyyyyyy yyyyyyyy yyyyxxxx xxxxxxxx xxxxxxxx [0] +typedef struct _XMUICON4 +{ + union + { + struct + { + UINT64 x : 20; // 0/1048575 to 1048575/1048575 + UINT64 y : 20; // 0/1048575 to 1048575/1048575 + UINT64 z : 20; // 0/1048575 to 1048575/1048575 + UINT64 w : 4; // 0/15 to 15/15 + }; + UINT64 v; + }; + +#ifdef __cplusplus + + _XMUICON4() {}; + explicit _XMUICON4(UINT64 Packed) : v(Packed) {}; + _XMUICON4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUICON4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT64 () const { return v; } + + _XMUICON4& operator= (CONST _XMUICON4& UIcoN4); + _XMUICON4& operator= (CONST UINT64 Packed); + +#endif // __cplusplus + +} XMUICON4; + +// 4D Vector; 20-20-20-4 bit components packed into a 64 bit integer +// The 4D Vector is packed into 64 bits as follows: a 4 bit unsigned +// integer for the w component and 20 bit unsigned integers for the +// z, y, and x components. The w component is stored in the +// most significant bits and the x component in the least significant bits +// (W4Z20Y20X20): [64] wwwwzzzz zzzzzzzz zzzzzzzz yyyyyyyy yyyyyyyy yyyyxxxx xxxxxxxx xxxxxxxx [0] +typedef struct _XMUICO4 +{ + union + { + struct + { + UINT64 x : 20; // 0 to 1048575 + UINT64 y : 20; // 0 to 1048575 + UINT64 z : 20; // 0 to 1048575 + UINT64 w : 4; // 0 to 15 + }; + UINT64 v; + }; + +#ifdef __cplusplus + + _XMUICO4() {}; + explicit _XMUICO4(UINT64 Packed) : v(Packed) {}; + _XMUICO4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUICO4(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT64 () const { return v; } + + _XMUICO4& operator= (CONST _XMUICO4& UIco4); + _XMUICO4& operator= (CONST UINT64 Packed); + +#endif // __cplusplus + +} XMUICO4; + +//------------------------------------------------------------------------------ +// ARGB Color; 8-8-8-8 bit unsigned normalized integer components packed into +// a 32 bit integer. The normalized color is packed into 32 bits using 8 bit +// unsigned, normalized integers for the alpha, red, green, and blue components. +// The alpha component is stored in the most significant bits and the blue +// component in the least significant bits (A8R8G8B8): +// [32] aaaaaaaa rrrrrrrr gggggggg bbbbbbbb [0] +typedef struct _XMCOLOR +{ + union + { + struct + { + UINT b : 8; // Blue: 0/255 to 255/255 + UINT g : 8; // Green: 0/255 to 255/255 + UINT r : 8; // Red: 0/255 to 255/255 + UINT a : 8; // Alpha: 0/255 to 255/255 + }; + UINT c; + }; + +#ifdef __cplusplus + + _XMCOLOR() {}; + _XMCOLOR(UINT Color) : c(Color) {}; + _XMCOLOR(FLOAT _r, FLOAT _g, FLOAT _b, FLOAT _a); + explicit _XMCOLOR(_In_count_c_(4) CONST FLOAT *pArray); + + operator UINT () const { return c; } + + _XMCOLOR& operator= (CONST _XMCOLOR& Color); + _XMCOLOR& operator= (CONST UINT Color); + +#endif // __cplusplus + +} XMCOLOR; + +//------------------------------------------------------------------------------ +// 4D Vector; 8 bit signed normalized integer components +typedef struct _XMBYTEN4 +{ + union + { + struct + { + CHAR x; + CHAR y; + CHAR z; + CHAR w; + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMBYTEN4() {}; + _XMBYTEN4(CHAR _x, CHAR _y, CHAR _z, CHAR _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMBYTEN4(UINT Packed) : v(Packed) {}; + explicit _XMBYTEN4(_In_count_c_(4) CONST CHAR *pArray); + _XMBYTEN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMBYTEN4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMBYTEN4& operator= (CONST _XMBYTEN4& ByteN4); + _XMBYTEN4& operator= (UINT Packed) { v = Packed; return *this; } + +#endif // __cplusplus + +} XMBYTEN4; + +// 4D Vector; 8 bit signed integer components +typedef struct _XMBYTE4 +{ + union + { + struct + { + CHAR x; + CHAR y; + CHAR z; + CHAR w; + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMBYTE4() {}; + _XMBYTE4(CHAR _x, CHAR _y, CHAR _z, CHAR _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMBYTE4(UINT Packed) : v(Packed) {}; + explicit _XMBYTE4(_In_count_c_(4) CONST CHAR *pArray); + _XMBYTE4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMBYTE4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMBYTE4& operator= (CONST _XMBYTE4& Byte4); + _XMBYTE4& operator= (UINT Packed) { v = Packed; return *this; } + +#endif // __cplusplus + +} XMBYTE4; + +// 4D Vector; 8 bit unsigned normalized integer components +typedef struct _XMUBYTEN4 +{ + union + { + struct + { + BYTE x; + BYTE y; + BYTE z; + BYTE w; + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUBYTEN4() {}; + _XMUBYTEN4(BYTE _x, BYTE _y, BYTE _z, BYTE _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMUBYTEN4(UINT Packed) : v(Packed) {}; + explicit _XMUBYTEN4(_In_count_c_(4) CONST BYTE *pArray); + _XMUBYTEN4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUBYTEN4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMUBYTEN4& operator= (CONST _XMUBYTEN4& UByteN4); + _XMUBYTEN4& operator= (UINT Packed) { v = Packed; return *this; } + +#endif // __cplusplus + +} XMUBYTEN4; + +// 4D Vector; 8 bit unsigned integer components +typedef struct _XMUBYTE4 +{ + union + { + struct + { + BYTE x; + BYTE y; + BYTE z; + BYTE w; + }; + UINT v; + }; + +#ifdef __cplusplus + + _XMUBYTE4() {}; + _XMUBYTE4(BYTE _x, BYTE _y, BYTE _z, BYTE _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMUBYTE4(UINT Packed) : v(Packed) {}; + explicit _XMUBYTE4(_In_count_c_(4) CONST BYTE *pArray); + _XMUBYTE4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUBYTE4(_In_count_c_(4) CONST FLOAT *pArray); + + _XMUBYTE4& operator= (CONST _XMUBYTE4& UByte4); + _XMUBYTE4& operator= (UINT Packed) { v = Packed; return *this; } + +#endif // __cplusplus + +} XMUBYTE4; + +//------------------------------------------------------------------------------ +// 4D vector; 4 bit unsigned integer components +typedef struct _XMUNIBBLE4 +{ + union + { + struct + { + USHORT x : 4; + USHORT y : 4; + USHORT z : 4; + USHORT w : 4; + }; + USHORT v; + }; + +#ifdef __cplusplus + + _XMUNIBBLE4() {}; + explicit _XMUNIBBLE4(USHORT Packed) : v(Packed) {}; + _XMUNIBBLE4(CHAR _x, CHAR _y, CHAR _z, CHAR _w) : x(_x), y(_y), z(_z), w(_w) {}; + explicit _XMUNIBBLE4(_In_count_c_(4) CONST CHAR *pArray); + _XMUNIBBLE4(FLOAT _x, FLOAT _y, FLOAT _z, FLOAT _w); + explicit _XMUNIBBLE4(_In_count_c_(4) CONST FLOAT *pArray); + + operator USHORT () const { return v; } + + _XMUNIBBLE4& operator= (CONST _XMUNIBBLE4& UNibble4); + _XMUNIBBLE4& operator= (CONST USHORT Packed); + +#endif // __cplusplus + +} XMUNIBBLE4; + +//------------------------------------------------------------------------------ +// 4D vector: 5/5/5/1 unsigned integer components +typedef struct _XMU555 +{ + union + { + struct + { + USHORT x : 5; + USHORT y : 5; + USHORT z : 5; + USHORT w : 1; + }; + USHORT v; + }; + +#ifdef __cplusplus + + _XMU555() {}; + explicit _XMU555(USHORT Packed) : v(Packed) {}; + _XMU555(CHAR _x, CHAR _y, CHAR _z, BOOL _w) : x(_x), y(_y), z(_z), w(_w ? 0x1 : 0) {}; + _XMU555(_In_count_c_(3) CONST CHAR *pArray, BOOL _w); + _XMU555(FLOAT _x, FLOAT _y, FLOAT _z, BOOL _w); + _XMU555(_In_count_c_(3) CONST FLOAT *pArray, BOOL _w); + + operator USHORT () const { return v; } + + _XMU555& operator= (CONST _XMU555& U555); + _XMU555& operator= (CONST USHORT Packed); + +#endif // __cplusplus + +} XMU555; + +//------------------------------------------------------------------------------ +// 3x3 Matrix: 32 bit floating point components +typedef struct _XMFLOAT3X3 +{ + union + { + struct + { + FLOAT _11, _12, _13; + FLOAT _21, _22, _23; + FLOAT _31, _32, _33; + }; + FLOAT m[3][3]; + }; + +#ifdef __cplusplus + + _XMFLOAT3X3() {}; + _XMFLOAT3X3(FLOAT m00, FLOAT m01, FLOAT m02, + FLOAT m10, FLOAT m11, FLOAT m12, + FLOAT m20, FLOAT m21, FLOAT m22); + explicit _XMFLOAT3X3(_In_count_c_(9) CONST FLOAT *pArray); + + FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } + FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } + + _XMFLOAT3X3& operator= (CONST _XMFLOAT3X3& Float3x3); + +#endif // __cplusplus + +} XMFLOAT3X3; + +//------------------------------------------------------------------------------ +// 4x3 Matrix: 32 bit floating point components +typedef struct _XMFLOAT4X3 +{ + union + { + struct + { + FLOAT _11, _12, _13; + FLOAT _21, _22, _23; + FLOAT _31, _32, _33; + FLOAT _41, _42, _43; + }; + FLOAT m[4][3]; + }; + +#ifdef __cplusplus + + _XMFLOAT4X3() {}; + _XMFLOAT4X3(FLOAT m00, FLOAT m01, FLOAT m02, + FLOAT m10, FLOAT m11, FLOAT m12, + FLOAT m20, FLOAT m21, FLOAT m22, + FLOAT m30, FLOAT m31, FLOAT m32); + explicit _XMFLOAT4X3(_In_count_c_(12) CONST FLOAT *pArray); + + FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } + FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } + + _XMFLOAT4X3& operator= (CONST _XMFLOAT4X3& Float4x3); + +#endif // __cplusplus + +} XMFLOAT4X3; + +// 4x3 Matrix: 32 bit floating point components aligned on a 16 byte boundary +#ifdef __cplusplus +__declspec(align(16)) struct XMFLOAT4X3A : public XMFLOAT4X3 +{ + XMFLOAT4X3A() : XMFLOAT4X3() {}; + XMFLOAT4X3A(FLOAT m00, FLOAT m01, FLOAT m02, + FLOAT m10, FLOAT m11, FLOAT m12, + FLOAT m20, FLOAT m21, FLOAT m22, + FLOAT m30, FLOAT m31, FLOAT m32) : + XMFLOAT4X3(m00,m01,m02,m10,m11,m12,m20,m21,m22,m30,m31,m32) {}; + explicit XMFLOAT4X3A(_In_count_c_(12) CONST FLOAT *pArray) : XMFLOAT4X3(pArray) {} + + FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } + FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } + + XMFLOAT4X3A& operator= (CONST XMFLOAT4X3A& Float4x3); +}; +#else +typedef __declspec(align(16)) XMFLOAT4X3 XMFLOAT4X3A; +#endif // __cplusplus + +//------------------------------------------------------------------------------ +// 4x4 Matrix: 32 bit floating point components +typedef struct _XMFLOAT4X4 +{ + union + { + struct + { + FLOAT _11, _12, _13, _14; + FLOAT _21, _22, _23, _24; + FLOAT _31, _32, _33, _34; + FLOAT _41, _42, _43, _44; + }; + FLOAT m[4][4]; + }; + +#ifdef __cplusplus + + _XMFLOAT4X4() {}; + _XMFLOAT4X4(FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33); + explicit _XMFLOAT4X4(_In_count_c_(16) CONST FLOAT *pArray); + + FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } + FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } + + _XMFLOAT4X4& operator= (CONST _XMFLOAT4X4& Float4x4); + +#endif // __cplusplus + +} XMFLOAT4X4; + +// 4x4 Matrix: 32 bit floating point components aligned on a 16 byte boundary +#ifdef __cplusplus +__declspec(align(16)) struct XMFLOAT4X4A : public XMFLOAT4X4 +{ + XMFLOAT4X4A() : XMFLOAT4X4() {}; + XMFLOAT4X4A(FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33) + : XMFLOAT4X4(m00,m01,m02,m03,m10,m11,m12,m13,m20,m21,m22,m23,m30,m31,m32,m33) {}; + explicit XMFLOAT4X4A(_In_count_c_(16) CONST FLOAT *pArray) : XMFLOAT4X4(pArray) {} + + FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } + FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } + + XMFLOAT4X4A& operator= (CONST XMFLOAT4X4A& Float4x4); +}; +#else +typedef __declspec(align(16)) XMFLOAT4X4 XMFLOAT4X4A; +#endif // __cplusplus + + +#ifdef _XM_BIGENDIAN_ +#pragma bitfield_order(pop) +#endif + +#pragma warning(pop) + +/**************************************************************************** + * + * Data conversion operations + * + ****************************************************************************/ + +#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_VMX128_INTRINSICS_) +#else +XMVECTOR XMConvertVectorIntToFloat(FXMVECTOR VInt, UINT DivExponent); +XMVECTOR XMConvertVectorFloatToInt(FXMVECTOR VFloat, UINT MulExponent); +XMVECTOR XMConvertVectorUIntToFloat(FXMVECTOR VUInt, UINT DivExponent); +XMVECTOR XMConvertVectorFloatToUInt(FXMVECTOR VFloat, UINT MulExponent); +#endif + +FLOAT XMConvertHalfToFloat(HALF Value); +FLOAT* XMConvertHalfToFloatStream(_Out_bytecap_x_(sizeof(FLOAT)+OutputStride*(HalfCount-1)) FLOAT* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(HALF)+InputStride*(HalfCount-1)) CONST HALF* pInputStream, + _In_ size_t InputStride, _In_ size_t HalfCount); +HALF XMConvertFloatToHalf(FLOAT Value); +HALF* XMConvertFloatToHalfStream(_Out_bytecap_x_(sizeof(HALF)+OutputStride*(FloatCount-1)) HALF* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(FLOAT)+InputStride*(FloatCount-1)) CONST FLOAT* pInputStream, + _In_ size_t InputStride, _In_ size_t FloatCount); + +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) +XMVECTOR XMVectorSetBinaryConstant(UINT C0, UINT C1, UINT C2, UINT C3); +XMVECTOR XMVectorSplatConstant(INT IntConstant, UINT DivExponent); +XMVECTOR XMVectorSplatConstantInt(INT IntConstant); + +// VMX128 versions defined below as macros +#endif + +/**************************************************************************** + * + * Load operations + * + ****************************************************************************/ + +XMVECTOR XMLoadInt(_In_ CONST UINT* pSource); +XMVECTOR XMLoadFloat(_In_ CONST FLOAT* pSource); + +XMVECTOR XMLoadInt2(_In_count_c_(2) CONST UINT* pSource); +XMVECTOR XMLoadInt2A(_In_count_c_(2) CONST UINT* PSource); +XMVECTOR XMLoadFloat2(_In_ CONST XMFLOAT2* pSource); +XMVECTOR XMLoadFloat2A(_In_ CONST XMFLOAT2A* pSource); +XMVECTOR XMLoadSInt2(_In_ CONST XMINT2* pSource); +XMVECTOR XMLoadUInt2(_In_ CONST XMUINT2* pSource); +XMVECTOR XMLoadHalf2(_In_ CONST XMHALF2* pSource); +XMVECTOR XMLoadShortN2(_In_ CONST XMSHORTN2* pSource); +XMVECTOR XMLoadShort2(_In_ CONST XMSHORT2* pSource); +XMVECTOR XMLoadUShortN2(_In_ CONST XMUSHORTN2* pSource); +XMVECTOR XMLoadUShort2(_In_ CONST XMUSHORT2* pSource); +XMVECTOR XMLoadByteN2(_In_ CONST XMBYTEN2* pSource); +XMVECTOR XMLoadByte2(_In_ CONST XMBYTE2* pSource); +XMVECTOR XMLoadUByteN2(_In_ CONST XMUBYTEN2* pSource); +XMVECTOR XMLoadUByte2(_In_ CONST XMUBYTE2* pSource); + +XMVECTOR XMLoadInt3(_In_count_c_(3) CONST UINT* pSource); +XMVECTOR XMLoadInt3A(_In_count_c_(3) CONST UINT* pSource); +XMVECTOR XMLoadFloat3(_In_ CONST XMFLOAT3* pSource); +XMVECTOR XMLoadFloat3A(_In_ CONST XMFLOAT3A* pSource); +XMVECTOR XMLoadSInt3(_In_ CONST XMINT3* pSource); +XMVECTOR XMLoadUInt3(_In_ CONST XMUINT3* pSource); +XMVECTOR XMLoadHenDN3(_In_ CONST XMHENDN3* pSource); +XMVECTOR XMLoadHenD3(_In_ CONST XMHEND3* pSource); +XMVECTOR XMLoadUHenDN3(_In_ CONST XMUHENDN3* pSource); +XMVECTOR XMLoadUHenD3(_In_ CONST XMUHEND3* pSource); +XMVECTOR XMLoadDHenN3(_In_ CONST XMDHENN3* pSource); +XMVECTOR XMLoadDHen3(_In_ CONST XMDHEN3* pSource); +XMVECTOR XMLoadUDHenN3(_In_ CONST XMUDHENN3* pSource); +XMVECTOR XMLoadUDHen3(_In_ CONST XMUDHEN3* pSource); +XMVECTOR XMLoadU565(_In_ CONST XMU565* pSource); +XMVECTOR XMLoadFloat3PK(_In_ CONST XMFLOAT3PK* pSource); +XMVECTOR XMLoadFloat3SE(_In_ CONST XMFLOAT3SE* pSource); + +XMVECTOR XMLoadInt4(_In_count_c_(4) CONST UINT* pSource); +XMVECTOR XMLoadInt4A(_In_count_c_(4) CONST UINT* pSource); +XMVECTOR XMLoadFloat4(_In_ CONST XMFLOAT4* pSource); +XMVECTOR XMLoadFloat4A(_In_ CONST XMFLOAT4A* pSource); +XMVECTOR XMLoadSInt4(_In_ CONST XMINT4* pSource); +XMVECTOR XMLoadUInt4(_In_ CONST XMUINT4* pSource); +XMVECTOR XMLoadHalf4(_In_ CONST XMHALF4* pSource); +XMVECTOR XMLoadShortN4(_In_ CONST XMSHORTN4* pSource); +XMVECTOR XMLoadShort4(_In_ CONST XMSHORT4* pSource); +XMVECTOR XMLoadUShortN4(_In_ CONST XMUSHORTN4* pSource); +XMVECTOR XMLoadUShort4(_In_ CONST XMUSHORT4* pSource); +XMVECTOR XMLoadXIcoN4(_In_ CONST XMXICON4* pSource); +XMVECTOR XMLoadXIco4(_In_ CONST XMXICO4* pSource); +XMVECTOR XMLoadIcoN4(_In_ CONST XMICON4* pSource); +XMVECTOR XMLoadIco4(_In_ CONST XMICO4* pSource); +XMVECTOR XMLoadUIcoN4(_In_ CONST XMUICON4* pSource); +XMVECTOR XMLoadUIco4(_In_ CONST XMUICO4* pSource); +XMVECTOR XMLoadXDecN4(_In_ CONST XMXDECN4* pSource); +XMVECTOR XMLoadXDec4(_In_ CONST XMXDEC4* pSource); +XMVECTOR XMLoadDecN4(_In_ CONST XMDECN4* pSource); +XMVECTOR XMLoadDec4(_In_ CONST XMDEC4* pSource); +XMVECTOR XMLoadUDecN4(_In_ CONST XMUDECN4* pSource); +XMVECTOR XMLoadUDec4(_In_ CONST XMUDEC4* pSource); +XMVECTOR XMLoadByteN4(_In_ CONST XMBYTEN4* pSource); +XMVECTOR XMLoadByte4(_In_ CONST XMBYTE4* pSource); +XMVECTOR XMLoadUByteN4(_In_ CONST XMUBYTEN4* pSource); +XMVECTOR XMLoadUByte4(_In_ CONST XMUBYTE4* pSource); +XMVECTOR XMLoadUNibble4(_In_ CONST XMUNIBBLE4* pSource); +XMVECTOR XMLoadU555(_In_ CONST XMU555* pSource); +XMVECTOR XMLoadColor(_In_ CONST XMCOLOR* pSource); + +XMMATRIX XMLoadFloat3x3(_In_ CONST XMFLOAT3X3* pSource); +XMMATRIX XMLoadFloat4x3(_In_ CONST XMFLOAT4X3* pSource); +XMMATRIX XMLoadFloat4x3A(_In_ CONST XMFLOAT4X3A* pSource); +XMMATRIX XMLoadFloat4x4(_In_ CONST XMFLOAT4X4* pSource); +XMMATRIX XMLoadFloat4x4A(_In_ CONST XMFLOAT4X4A* pSource); + +/**************************************************************************** + * + * Store operations + * + ****************************************************************************/ + +VOID XMStoreInt(_Out_ UINT* pDestination, FXMVECTOR V); +VOID XMStoreFloat(_Out_ FLOAT* pDestination, FXMVECTOR V); + +VOID XMStoreInt2(_Out_cap_c_(2) UINT* pDestination, FXMVECTOR V); +VOID XMStoreInt2A(_Out_cap_c_(2) UINT* pDestination, FXMVECTOR V); +VOID XMStoreFloat2(_Out_ XMFLOAT2* pDestination, FXMVECTOR V); +VOID XMStoreFloat2A(_Out_ XMFLOAT2A* pDestination, FXMVECTOR V); +VOID XMStoreSInt2(_Out_ XMINT2* pDestination, FXMVECTOR V); +VOID XMStoreUInt2(_Out_ XMUINT2* pDestination, FXMVECTOR V); +VOID XMStoreHalf2(_Out_ XMHALF2* pDestination, FXMVECTOR V); +VOID XMStoreShortN2(_Out_ XMSHORTN2* pDestination, FXMVECTOR V); +VOID XMStoreShort2(_Out_ XMSHORT2* pDestination, FXMVECTOR V); +VOID XMStoreUShortN2(_Out_ XMUSHORTN2* pDestination, FXMVECTOR V); +VOID XMStoreUShort2(_Out_ XMUSHORT2* pDestination, FXMVECTOR V); +VOID XMStoreByteN2(_Out_ XMBYTEN2* pDestination, FXMVECTOR V); +VOID XMStoreByte2(_Out_ XMBYTE2* pDestination, FXMVECTOR V); +VOID XMStoreUByteN2(_Out_ XMUBYTEN2* pDestination, FXMVECTOR V); +VOID XMStoreUByte2(_Out_ XMUBYTE2* pDestination, FXMVECTOR V); + +VOID XMStoreInt3(_Out_cap_c_(3) UINT* pDestination, FXMVECTOR V); +VOID XMStoreInt3A(_Out_cap_c_(3) UINT* pDestination, FXMVECTOR V); +VOID XMStoreFloat3(_Out_ XMFLOAT3* pDestination, FXMVECTOR V); +VOID XMStoreFloat3A(_Out_ XMFLOAT3A* pDestination, FXMVECTOR V); +VOID XMStoreSInt3(_Out_ XMINT3* pDestination, FXMVECTOR V); +VOID XMStoreUInt3(_Out_ XMUINT3* pDestination, FXMVECTOR V); +VOID XMStoreHenDN3(_Out_ XMHENDN3* pDestination, FXMVECTOR V); +VOID XMStoreHenD3(_Out_ XMHEND3* pDestination, FXMVECTOR V); +VOID XMStoreUHenDN3(_Out_ XMUHENDN3* pDestination, FXMVECTOR V); +VOID XMStoreUHenD3(_Out_ XMUHEND3* pDestination, FXMVECTOR V); +VOID XMStoreDHenN3(_Out_ XMDHENN3* pDestination, FXMVECTOR V); +VOID XMStoreDHen3(_Out_ XMDHEN3* pDestination, FXMVECTOR V); +VOID XMStoreUDHenN3(_Out_ XMUDHENN3* pDestination, FXMVECTOR V); +VOID XMStoreUDHen3(_Out_ XMUDHEN3* pDestination, FXMVECTOR V); +VOID XMStoreU565(_Out_ XMU565* pDestination, FXMVECTOR V); +VOID XMStoreFloat3PK(_Out_ XMFLOAT3PK* pDestination, FXMVECTOR V); +VOID XMStoreFloat3SE(_Out_ XMFLOAT3SE* pDestination, FXMVECTOR V); + +VOID XMStoreInt4(_Out_cap_c_(4) UINT* pDestination, FXMVECTOR V); +VOID XMStoreInt4A(_Out_cap_c_(4) UINT* pDestination, FXMVECTOR V); +VOID XMStoreInt4NC(_Out_cap_c_(4) UINT* pDestination, FXMVECTOR V); +VOID XMStoreFloat4(_Out_ XMFLOAT4* pDestination, FXMVECTOR V); +VOID XMStoreFloat4A(_Out_ XMFLOAT4A* pDestination, FXMVECTOR V); +VOID XMStoreFloat4NC(_Out_ XMFLOAT4* pDestination, FXMVECTOR V); +VOID XMStoreSInt4(_Out_ XMINT4* pDestination, FXMVECTOR V); +VOID XMStoreUInt4(_Out_ XMUINT4* pDestination, FXMVECTOR V); +VOID XMStoreHalf4(_Out_ XMHALF4* pDestination, FXMVECTOR V); +VOID XMStoreShortN4(_Out_ XMSHORTN4* pDestination, FXMVECTOR V); +VOID XMStoreShort4(_Out_ XMSHORT4* pDestination, FXMVECTOR V); +VOID XMStoreUShortN4(_Out_ XMUSHORTN4* pDestination, FXMVECTOR V); +VOID XMStoreUShort4(_Out_ XMUSHORT4* pDestination, FXMVECTOR V); +VOID XMStoreXIcoN4(_Out_ XMXICON4* pDestination, FXMVECTOR V); +VOID XMStoreXIco4(_Out_ XMXICO4* pDestination, FXMVECTOR V); +VOID XMStoreIcoN4(_Out_ XMICON4* pDestination, FXMVECTOR V); +VOID XMStoreIco4(_Out_ XMICO4* pDestination, FXMVECTOR V); +VOID XMStoreUIcoN4(_Out_ XMUICON4* pDestination, FXMVECTOR V); +VOID XMStoreUIco4(_Out_ XMUICO4* pDestination, FXMVECTOR V); +VOID XMStoreXDecN4(_Out_ XMXDECN4* pDestination, FXMVECTOR V); +VOID XMStoreXDec4(_Out_ XMXDEC4* pDestination, FXMVECTOR V); +VOID XMStoreDecN4(_Out_ XMDECN4* pDestination, FXMVECTOR V); +VOID XMStoreDec4(_Out_ XMDEC4* pDestination, FXMVECTOR V); +VOID XMStoreUDecN4(_Out_ XMUDECN4* pDestination, FXMVECTOR V); +VOID XMStoreUDec4(_Out_ XMUDEC4* pDestination, FXMVECTOR V); +VOID XMStoreByteN4(_Out_ XMBYTEN4* pDestination, FXMVECTOR V); +VOID XMStoreByte4(_Out_ XMBYTE4* pDestination, FXMVECTOR V); +VOID XMStoreUByteN4(_Out_ XMUBYTEN4* pDestination, FXMVECTOR V); +VOID XMStoreUByte4(_Out_ XMUBYTE4* pDestination, FXMVECTOR V); +VOID XMStoreUNibble4(_Out_ XMUNIBBLE4* pDestination, FXMVECTOR V); +VOID XMStoreU555(_Out_ XMU555* pDestination, FXMVECTOR V); +VOID XMStoreColor(_Out_ XMCOLOR* pDestination, FXMVECTOR V); + +VOID XMStoreFloat3x3(_Out_ XMFLOAT3X3* pDestination, CXMMATRIX M); +VOID XMStoreFloat3x3NC(_Out_ XMFLOAT3X3* pDestination, CXMMATRIX M); +VOID XMStoreFloat4x3(_Out_ XMFLOAT4X3* pDestination, CXMMATRIX M); +VOID XMStoreFloat4x3A(_Out_ XMFLOAT4X3A* pDestination, CXMMATRIX M); +VOID XMStoreFloat4x3NC(_Out_ XMFLOAT4X3* pDestination, CXMMATRIX M); +VOID XMStoreFloat4x4(_Out_ XMFLOAT4X4* pDestination, CXMMATRIX M); +VOID XMStoreFloat4x4A(_Out_ XMFLOAT4X4A* pDestination, CXMMATRIX M); +VOID XMStoreFloat4x4NC(_Out_ XMFLOAT4X4* pDestination, CXMMATRIX M); + +/**************************************************************************** + * + * General vector operations + * + ****************************************************************************/ + +XMVECTOR XMVectorZero(); +XMVECTOR XMVectorSet(FLOAT x, FLOAT y, FLOAT z, FLOAT w); +XMVECTOR XMVectorSetInt(UINT x, UINT y, UINT z, UINT w); +XMVECTOR XMVectorReplicate(FLOAT Value); +XMVECTOR XMVectorReplicatePtr(_In_ CONST FLOAT *pValue); +XMVECTOR XMVectorReplicateInt(UINT Value); +XMVECTOR XMVectorReplicateIntPtr(_In_ CONST UINT *pValue); +XMVECTOR XMVectorTrueInt(); +XMVECTOR XMVectorFalseInt(); +XMVECTOR XMVectorSplatX(FXMVECTOR V); +XMVECTOR XMVectorSplatY(FXMVECTOR V); +XMVECTOR XMVectorSplatZ(FXMVECTOR V); +XMVECTOR XMVectorSplatW(FXMVECTOR V); +XMVECTOR XMVectorSplatOne(); +XMVECTOR XMVectorSplatInfinity(); +XMVECTOR XMVectorSplatQNaN(); +XMVECTOR XMVectorSplatEpsilon(); +XMVECTOR XMVectorSplatSignMask(); + +FLOAT XMVectorGetByIndex(FXMVECTOR V,UINT i); +FLOAT XMVectorGetX(FXMVECTOR V); +FLOAT XMVectorGetY(FXMVECTOR V); +FLOAT XMVectorGetZ(FXMVECTOR V); +FLOAT XMVectorGetW(FXMVECTOR V); + +VOID XMVectorGetByIndexPtr(_Out_ FLOAT *f, FXMVECTOR V, UINT i); +VOID XMVectorGetXPtr(_Out_ FLOAT *x, FXMVECTOR V); +VOID XMVectorGetYPtr(_Out_ FLOAT *y, FXMVECTOR V); +VOID XMVectorGetZPtr(_Out_ FLOAT *z, FXMVECTOR V); +VOID XMVectorGetWPtr(_Out_ FLOAT *w, FXMVECTOR V); + +UINT XMVectorGetIntByIndex(FXMVECTOR V,UINT i); +UINT XMVectorGetIntX(FXMVECTOR V); +UINT XMVectorGetIntY(FXMVECTOR V); +UINT XMVectorGetIntZ(FXMVECTOR V); +UINT XMVectorGetIntW(FXMVECTOR V); + +VOID XMVectorGetIntByIndexPtr(_Out_ UINT *x,FXMVECTOR V, UINT i); +VOID XMVectorGetIntXPtr(_Out_ UINT *x, FXMVECTOR V); +VOID XMVectorGetIntYPtr(_Out_ UINT *y, FXMVECTOR V); +VOID XMVectorGetIntZPtr(_Out_ UINT *z, FXMVECTOR V); +VOID XMVectorGetIntWPtr(_Out_ UINT *w, FXMVECTOR V); + +XMVECTOR XMVectorSetByIndex(FXMVECTOR V,FLOAT f,UINT i); +XMVECTOR XMVectorSetX(FXMVECTOR V, FLOAT x); +XMVECTOR XMVectorSetY(FXMVECTOR V, FLOAT y); +XMVECTOR XMVectorSetZ(FXMVECTOR V, FLOAT z); +XMVECTOR XMVectorSetW(FXMVECTOR V, FLOAT w); + +XMVECTOR XMVectorSetByIndexPtr(FXMVECTOR V, _In_ CONST FLOAT *f, UINT i); +XMVECTOR XMVectorSetXPtr(FXMVECTOR V, _In_ CONST FLOAT *x); +XMVECTOR XMVectorSetYPtr(FXMVECTOR V, _In_ CONST FLOAT *y); +XMVECTOR XMVectorSetZPtr(FXMVECTOR V, _In_ CONST FLOAT *z); +XMVECTOR XMVectorSetWPtr(FXMVECTOR V, _In_ CONST FLOAT *w); + +XMVECTOR XMVectorSetIntByIndex(FXMVECTOR V, UINT x,UINT i); +XMVECTOR XMVectorSetIntX(FXMVECTOR V, UINT x); +XMVECTOR XMVectorSetIntY(FXMVECTOR V, UINT y); +XMVECTOR XMVectorSetIntZ(FXMVECTOR V, UINT z); +XMVECTOR XMVectorSetIntW(FXMVECTOR V, UINT w); + +XMVECTOR XMVectorSetIntByIndexPtr(FXMVECTOR V, _In_ CONST UINT *x, UINT i); +XMVECTOR XMVectorSetIntXPtr(FXMVECTOR V, _In_ CONST UINT *x); +XMVECTOR XMVectorSetIntYPtr(FXMVECTOR V, _In_ CONST UINT *y); +XMVECTOR XMVectorSetIntZPtr(FXMVECTOR V, _In_ CONST UINT *z); +XMVECTOR XMVectorSetIntWPtr(FXMVECTOR V, _In_ CONST UINT *w); + +XMVECTOR XMVectorPermuteControl(UINT ElementIndex0, UINT ElementIndex1, UINT ElementIndex2, UINT ElementIndex3); +XMVECTOR XMVectorPermute(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR Control); +XMVECTOR XMVectorSelectControl(UINT VectorIndex0, UINT VectorIndex1, UINT VectorIndex2, UINT VectorIndex3); +XMVECTOR XMVectorSelect(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR Control); +XMVECTOR XMVectorMergeXY(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorMergeZW(FXMVECTOR V1, FXMVECTOR V2); + +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) +XMVECTOR XMVectorShiftLeft(FXMVECTOR V1, FXMVECTOR V2, UINT Elements); +XMVECTOR XMVectorRotateLeft(FXMVECTOR V, UINT Elements); +XMVECTOR XMVectorRotateRight(FXMVECTOR V, UINT Elements); +XMVECTOR XMVectorSwizzle(FXMVECTOR V, UINT E0, UINT E1, UINT E2, UINT E3); +XMVECTOR XMVectorInsert(FXMVECTOR VD, FXMVECTOR VS, UINT VSLeftRotateElements, + UINT Select0, UINT Select1, UINT Select2, UINT Select3); + +// VMX128 versions defined below as macros +#endif + +XMVECTOR XMVectorEqual(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorEqualR(_Out_ UINT* pCR, FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorEqualInt(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorEqualIntR(_Out_ UINT* pCR, FXMVECTOR V, FXMVECTOR V2); +XMVECTOR XMVectorNearEqual(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR Epsilon); +XMVECTOR XMVectorNotEqual(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorNotEqualInt(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorGreater(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorGreaterR(_Out_ UINT* pCR, FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorGreaterOrEqual(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorGreaterOrEqualR(_Out_ UINT* pCR, FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorLess(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorLessOrEqual(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorInBounds(FXMVECTOR V, FXMVECTOR Bounds); +XMVECTOR XMVectorInBoundsR(_Out_ UINT* pCR, FXMVECTOR V, FXMVECTOR Bounds); + +XMVECTOR XMVectorIsNaN(FXMVECTOR V); +XMVECTOR XMVectorIsInfinite(FXMVECTOR V); + +XMVECTOR XMVectorMin(FXMVECTOR V1,FXMVECTOR V2); +XMVECTOR XMVectorMax(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorRound(FXMVECTOR V); +XMVECTOR XMVectorTruncate(FXMVECTOR V); +XMVECTOR XMVectorFloor(FXMVECTOR V); +XMVECTOR XMVectorCeiling(FXMVECTOR V); +XMVECTOR XMVectorClamp(FXMVECTOR V, FXMVECTOR Min, FXMVECTOR Max); +XMVECTOR XMVectorSaturate(FXMVECTOR V); + +XMVECTOR XMVectorAndInt(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorAndCInt(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorOrInt(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorNorInt(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorXorInt(FXMVECTOR V1, FXMVECTOR V2); + +XMVECTOR XMVectorNegate(FXMVECTOR V); +XMVECTOR XMVectorAdd(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorAddAngles(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorSubtract(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorSubtractAngles(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorMultiply(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorMultiplyAdd(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR V3); +XMVECTOR XMVectorDivide(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorNegativeMultiplySubtract(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR V3); +XMVECTOR XMVectorScale(FXMVECTOR V, FLOAT ScaleFactor); +XMVECTOR XMVectorReciprocalEst(FXMVECTOR V); +XMVECTOR XMVectorReciprocal(FXMVECTOR V); +XMVECTOR XMVectorSqrtEst(FXMVECTOR V); +XMVECTOR XMVectorSqrt(FXMVECTOR V); +XMVECTOR XMVectorReciprocalSqrtEst(FXMVECTOR V); +XMVECTOR XMVectorReciprocalSqrt(FXMVECTOR V); +XMVECTOR XMVectorExpEst(FXMVECTOR V); +XMVECTOR XMVectorExp(FXMVECTOR V); +XMVECTOR XMVectorLogEst(FXMVECTOR V); +XMVECTOR XMVectorLog(FXMVECTOR V); +XMVECTOR XMVectorPowEst(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorPow(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorAbs(FXMVECTOR V); +XMVECTOR XMVectorMod(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVectorModAngles(FXMVECTOR Angles); +XMVECTOR XMVectorSin(FXMVECTOR V); +XMVECTOR XMVectorSinEst(FXMVECTOR V); +XMVECTOR XMVectorCos(FXMVECTOR V); +XMVECTOR XMVectorCosEst(FXMVECTOR V); +VOID XMVectorSinCos(_Out_ XMVECTOR* pSin, _Out_ XMVECTOR* pCos, FXMVECTOR V); +VOID XMVectorSinCosEst(_Out_ XMVECTOR* pSin, _Out_ XMVECTOR* pCos, FXMVECTOR V); +XMVECTOR XMVectorTan(FXMVECTOR V); +XMVECTOR XMVectorTanEst(FXMVECTOR V); +XMVECTOR XMVectorSinH(FXMVECTOR V); +XMVECTOR XMVectorSinHEst(FXMVECTOR V); +XMVECTOR XMVectorCosH(FXMVECTOR V); +XMVECTOR XMVectorCosHEst(FXMVECTOR V); +XMVECTOR XMVectorTanH(FXMVECTOR V); +XMVECTOR XMVectorTanHEst(FXMVECTOR V); +XMVECTOR XMVectorASin(FXMVECTOR V); +XMVECTOR XMVectorASinEst(FXMVECTOR V); +XMVECTOR XMVectorACos(FXMVECTOR V); +XMVECTOR XMVectorACosEst(FXMVECTOR V); +XMVECTOR XMVectorATan(FXMVECTOR V); +XMVECTOR XMVectorATanEst(FXMVECTOR V); +XMVECTOR XMVectorATan2(FXMVECTOR Y, FXMVECTOR X); +XMVECTOR XMVectorATan2Est(FXMVECTOR Y, FXMVECTOR X); +XMVECTOR XMVectorLerp(FXMVECTOR V0, FXMVECTOR V1, FLOAT t); +XMVECTOR XMVectorLerpV(FXMVECTOR V0, FXMVECTOR V1, FXMVECTOR T); +XMVECTOR XMVectorHermite(FXMVECTOR Position0, FXMVECTOR Tangent0, FXMVECTOR Position1, CXMVECTOR Tangent1, FLOAT t); +XMVECTOR XMVectorHermiteV(FXMVECTOR Position0, FXMVECTOR Tangent0, FXMVECTOR Position1, CXMVECTOR Tangent1, CXMVECTOR T); +XMVECTOR XMVectorCatmullRom(FXMVECTOR Position0, FXMVECTOR Position1, FXMVECTOR Position2, CXMVECTOR Position3, FLOAT t); +XMVECTOR XMVectorCatmullRomV(FXMVECTOR Position0, FXMVECTOR Position1, FXMVECTOR Position2, CXMVECTOR Position3, CXMVECTOR T); +XMVECTOR XMVectorBaryCentric(FXMVECTOR Position0, FXMVECTOR Position1, FXMVECTOR Position2, FLOAT f, FLOAT g); +XMVECTOR XMVectorBaryCentricV(FXMVECTOR Position0, FXMVECTOR Position1, FXMVECTOR Position2, CXMVECTOR F, CXMVECTOR G); + +/**************************************************************************** + * + * 2D vector operations + * + ****************************************************************************/ + + +BOOL XMVector2Equal(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector2EqualR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2EqualInt(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector2EqualIntR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2NearEqual(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR Epsilon); +BOOL XMVector2NotEqual(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2NotEqualInt(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2Greater(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector2GreaterR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2GreaterOrEqual(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector2GreaterOrEqualR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2Less(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2LessOrEqual(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector2InBounds(FXMVECTOR V, FXMVECTOR Bounds); +UINT XMVector2InBoundsR(FXMVECTOR V, FXMVECTOR Bounds); + +BOOL XMVector2IsNaN(FXMVECTOR V); +BOOL XMVector2IsInfinite(FXMVECTOR V); + +XMVECTOR XMVector2Dot(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector2Cross(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector2LengthSq(FXMVECTOR V); +XMVECTOR XMVector2ReciprocalLengthEst(FXMVECTOR V); +XMVECTOR XMVector2ReciprocalLength(FXMVECTOR V); +XMVECTOR XMVector2LengthEst(FXMVECTOR V); +XMVECTOR XMVector2Length(FXMVECTOR V); +XMVECTOR XMVector2NormalizeEst(FXMVECTOR V); +XMVECTOR XMVector2Normalize(FXMVECTOR V); +XMVECTOR XMVector2ClampLength(FXMVECTOR V, FLOAT LengthMin, FLOAT LengthMax); +XMVECTOR XMVector2ClampLengthV(FXMVECTOR V, FXMVECTOR LengthMin, FXMVECTOR LengthMax); +XMVECTOR XMVector2Reflect(FXMVECTOR Incident, FXMVECTOR Normal); +XMVECTOR XMVector2Refract(FXMVECTOR Incident, FXMVECTOR Normal, FLOAT RefractionIndex); +XMVECTOR XMVector2RefractV(FXMVECTOR Incident, FXMVECTOR Normal, FXMVECTOR RefractionIndex); +XMVECTOR XMVector2Orthogonal(FXMVECTOR V); +XMVECTOR XMVector2AngleBetweenNormalsEst(FXMVECTOR N1, FXMVECTOR N2); +XMVECTOR XMVector2AngleBetweenNormals(FXMVECTOR N1, FXMVECTOR N2); +XMVECTOR XMVector2AngleBetweenVectors(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector2LinePointDistance(FXMVECTOR LinePoint1, FXMVECTOR LinePoint2, FXMVECTOR Point); +XMVECTOR XMVector2IntersectLine(FXMVECTOR Line1Point1, FXMVECTOR Line1Point2, FXMVECTOR Line2Point1, CXMVECTOR Line2Point2); +XMVECTOR XMVector2Transform(FXMVECTOR V, CXMMATRIX M); +XMFLOAT4* XMVector2TransformStream(_Out_bytecap_x_(sizeof(XMFLOAT4)+OutputStride*(VectorCount-1)) XMFLOAT4* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT2)+InputStride*(VectorCount-1)) CONST XMFLOAT2* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMFLOAT4* XMVector2TransformStreamNC(_Out_bytecap_x_(sizeof(XMFLOAT4)+OutputStride*(VectorCount-1)) XMFLOAT4* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT2)+InputStride*(VectorCount-1)) CONST XMFLOAT2* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMVECTOR XMVector2TransformCoord(FXMVECTOR V, CXMMATRIX M); +XMFLOAT2* XMVector2TransformCoordStream(_Out_bytecap_x_(sizeof(XMFLOAT2)+OutputStride*(VectorCount-1)) XMFLOAT2* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT2)+InputStride*(VectorCount-1)) CONST XMFLOAT2* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMVECTOR XMVector2TransformNormal(FXMVECTOR V, CXMMATRIX M); +XMFLOAT2* XMVector2TransformNormalStream(_Out_bytecap_x_(sizeof(XMFLOAT2)+OutputStride*(VectorCount-1)) XMFLOAT2* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT2)+InputStride*(VectorCount-1)) CONST XMFLOAT2* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); + +/**************************************************************************** + * + * 3D vector operations + * + ****************************************************************************/ + + +BOOL XMVector3Equal(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector3EqualR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3EqualInt(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector3EqualIntR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3NearEqual(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR Epsilon); +BOOL XMVector3NotEqual(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3NotEqualInt(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3Greater(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector3GreaterR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3GreaterOrEqual(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector3GreaterOrEqualR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3Less(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3LessOrEqual(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector3InBounds(FXMVECTOR V, FXMVECTOR Bounds); +UINT XMVector3InBoundsR(FXMVECTOR V, FXMVECTOR Bounds); + +BOOL XMVector3IsNaN(FXMVECTOR V); +BOOL XMVector3IsInfinite(FXMVECTOR V); + +XMVECTOR XMVector3Dot(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector3Cross(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector3LengthSq(FXMVECTOR V); +XMVECTOR XMVector3ReciprocalLengthEst(FXMVECTOR V); +XMVECTOR XMVector3ReciprocalLength(FXMVECTOR V); +XMVECTOR XMVector3LengthEst(FXMVECTOR V); +XMVECTOR XMVector3Length(FXMVECTOR V); +XMVECTOR XMVector3NormalizeEst(FXMVECTOR V); +XMVECTOR XMVector3Normalize(FXMVECTOR V); +XMVECTOR XMVector3ClampLength(FXMVECTOR V, FLOAT LengthMin, FLOAT LengthMax); +XMVECTOR XMVector3ClampLengthV(FXMVECTOR V, FXMVECTOR LengthMin, FXMVECTOR LengthMax); +XMVECTOR XMVector3Reflect(FXMVECTOR Incident, FXMVECTOR Normal); +XMVECTOR XMVector3Refract(FXMVECTOR Incident, FXMVECTOR Normal, FLOAT RefractionIndex); +XMVECTOR XMVector3RefractV(FXMVECTOR Incident, FXMVECTOR Normal, FXMVECTOR RefractionIndex); +XMVECTOR XMVector3Orthogonal(FXMVECTOR V); +XMVECTOR XMVector3AngleBetweenNormalsEst(FXMVECTOR N1, FXMVECTOR N2); +XMVECTOR XMVector3AngleBetweenNormals(FXMVECTOR N1, FXMVECTOR N2); +XMVECTOR XMVector3AngleBetweenVectors(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector3LinePointDistance(FXMVECTOR LinePoint1, FXMVECTOR LinePoint2, FXMVECTOR Point); +VOID XMVector3ComponentsFromNormal(_Out_ XMVECTOR* pParallel, _Out_ XMVECTOR* pPerpendicular, FXMVECTOR V, FXMVECTOR Normal); +XMVECTOR XMVector3Rotate(FXMVECTOR V, FXMVECTOR RotationQuaternion); +XMVECTOR XMVector3InverseRotate(FXMVECTOR V, FXMVECTOR RotationQuaternion); +XMVECTOR XMVector3Transform(FXMVECTOR V, CXMMATRIX M); +XMFLOAT4* XMVector3TransformStream(_Out_bytecap_x_(sizeof(XMFLOAT4)+OutputStride*(VectorCount-1)) XMFLOAT4* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT3)+InputStride*(VectorCount-1)) CONST XMFLOAT3* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMFLOAT4* XMVector3TransformStreamNC(_Out_bytecap_x_(sizeof(XMFLOAT4)+OutputStride*(VectorCount-1)) XMFLOAT4* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT3)+InputStride*(VectorCount-1)) CONST XMFLOAT3* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMVECTOR XMVector3TransformCoord(FXMVECTOR V, CXMMATRIX M); +XMFLOAT3* XMVector3TransformCoordStream(_Out_bytecap_x_(sizeof(XMFLOAT3)+OutputStride*(VectorCount-1)) XMFLOAT3* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT3)+InputStride*(VectorCount-1)) CONST XMFLOAT3* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMVECTOR XMVector3TransformNormal(FXMVECTOR V, CXMMATRIX M); +XMFLOAT3* XMVector3TransformNormalStream(_Out_bytecap_x_(sizeof(XMFLOAT3)+OutputStride*(VectorCount-1)) XMFLOAT3* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT3)+InputStride*(VectorCount-1)) CONST XMFLOAT3* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); +XMVECTOR XMVector3Project(FXMVECTOR V, FLOAT ViewportX, FLOAT ViewportY, FLOAT ViewportWidth, FLOAT ViewportHeight, FLOAT ViewportMinZ, FLOAT ViewportMaxZ, + CXMMATRIX Projection, CXMMATRIX View, CXMMATRIX World); +XMFLOAT3* XMVector3ProjectStream(_Out_bytecap_x_(sizeof(XMFLOAT3)+OutputStride*(VectorCount-1)) XMFLOAT3* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT3)+InputStride*(VectorCount-1)) CONST XMFLOAT3* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, + FLOAT ViewportX, FLOAT ViewportY, FLOAT ViewportWidth, FLOAT ViewportHeight, FLOAT ViewportMinZ, FLOAT ViewportMaxZ, + CXMMATRIX Projection, CXMMATRIX View, CXMMATRIX World); +XMVECTOR XMVector3Unproject(FXMVECTOR V, FLOAT ViewportX, FLOAT ViewportY, FLOAT ViewportWidth, FLOAT ViewportHeight, FLOAT ViewportMinZ, FLOAT ViewportMaxZ, + CXMMATRIX Projection, CXMMATRIX View, CXMMATRIX World); +XMFLOAT3* XMVector3UnprojectStream(_Out_bytecap_x_(sizeof(XMFLOAT3)+OutputStride*(VectorCount-1)) XMFLOAT3* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT3)+InputStride*(VectorCount-1)) CONST XMFLOAT3* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, + FLOAT ViewportX, FLOAT ViewportY, FLOAT ViewportWidth, FLOAT ViewportHeight, FLOAT ViewportMinZ, FLOAT ViewportMaxZ, + CXMMATRIX Projection, CXMMATRIX View, CXMMATRIX World); + +/**************************************************************************** + * + * 4D vector operations + * + ****************************************************************************/ + +BOOL XMVector4Equal(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector4EqualR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4EqualInt(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector4EqualIntR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4NearEqual(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR Epsilon); +BOOL XMVector4NotEqual(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4NotEqualInt(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4Greater(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector4GreaterR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4GreaterOrEqual(FXMVECTOR V1, FXMVECTOR V2); +UINT XMVector4GreaterOrEqualR(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4Less(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4LessOrEqual(FXMVECTOR V1, FXMVECTOR V2); +BOOL XMVector4InBounds(FXMVECTOR V, FXMVECTOR Bounds); +UINT XMVector4InBoundsR(FXMVECTOR V, FXMVECTOR Bounds); + +BOOL XMVector4IsNaN(FXMVECTOR V); +BOOL XMVector4IsInfinite(FXMVECTOR V); + +XMVECTOR XMVector4Dot(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector4Cross(FXMVECTOR V1, FXMVECTOR V2, FXMVECTOR V3); +XMVECTOR XMVector4LengthSq(FXMVECTOR V); +XMVECTOR XMVector4ReciprocalLengthEst(FXMVECTOR V); +XMVECTOR XMVector4ReciprocalLength(FXMVECTOR V); +XMVECTOR XMVector4LengthEst(FXMVECTOR V); +XMVECTOR XMVector4Length(FXMVECTOR V); +XMVECTOR XMVector4NormalizeEst(FXMVECTOR V); +XMVECTOR XMVector4Normalize(FXMVECTOR V); +XMVECTOR XMVector4ClampLength(FXMVECTOR V, FLOAT LengthMin, FLOAT LengthMax); +XMVECTOR XMVector4ClampLengthV(FXMVECTOR V, FXMVECTOR LengthMin, FXMVECTOR LengthMax); +XMVECTOR XMVector4Reflect(FXMVECTOR Incident, FXMVECTOR Normal); +XMVECTOR XMVector4Refract(FXMVECTOR Incident, FXMVECTOR Normal, FLOAT RefractionIndex); +XMVECTOR XMVector4RefractV(FXMVECTOR Incident, FXMVECTOR Normal, FXMVECTOR RefractionIndex); +XMVECTOR XMVector4Orthogonal(FXMVECTOR V); +XMVECTOR XMVector4AngleBetweenNormalsEst(FXMVECTOR N1, FXMVECTOR N2); +XMVECTOR XMVector4AngleBetweenNormals(FXMVECTOR N1, FXMVECTOR N2); +XMVECTOR XMVector4AngleBetweenVectors(FXMVECTOR V1, FXMVECTOR V2); +XMVECTOR XMVector4Transform(FXMVECTOR V, CXMMATRIX M); +XMFLOAT4* XMVector4TransformStream(_Out_bytecap_x_(sizeof(XMFLOAT4)+OutputStride*(VectorCount-1)) XMFLOAT4* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT4)+InputStride*(VectorCount-1)) CONST XMFLOAT4* pInputStream, + _In_ size_t InputStride, _In_ size_t VectorCount, CXMMATRIX M); + +/**************************************************************************** + * + * Matrix operations + * + ****************************************************************************/ + +BOOL XMMatrixIsNaN(CXMMATRIX M); +BOOL XMMatrixIsInfinite(CXMMATRIX M); +BOOL XMMatrixIsIdentity(CXMMATRIX M); + +XMMATRIX XMMatrixMultiply(CXMMATRIX M1, CXMMATRIX M2); +XMMATRIX XMMatrixMultiplyTranspose(CXMMATRIX M1, CXMMATRIX M2); +XMMATRIX XMMatrixTranspose(CXMMATRIX M); +XMMATRIX XMMatrixInverse(_Out_opt_ XMVECTOR* pDeterminant, CXMMATRIX M); +XMVECTOR XMMatrixDeterminant(CXMMATRIX M); +BOOL XMMatrixDecompose(_Out_ XMVECTOR *outScale, _Out_ XMVECTOR *outRotQuat, _Out_ XMVECTOR *outTrans, CXMMATRIX M); + +XMMATRIX XMMatrixIdentity(); +XMMATRIX XMMatrixSet(FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33); +XMMATRIX XMMatrixTranslation(FLOAT OffsetX, FLOAT OffsetY, FLOAT OffsetZ); +XMMATRIX XMMatrixTranslationFromVector(FXMVECTOR Offset); +XMMATRIX XMMatrixScaling(FLOAT ScaleX, FLOAT ScaleY, FLOAT ScaleZ); +XMMATRIX XMMatrixScalingFromVector(FXMVECTOR Scale); +XMMATRIX XMMatrixRotationX(FLOAT Angle); +XMMATRIX XMMatrixRotationY(FLOAT Angle); +XMMATRIX XMMatrixRotationZ(FLOAT Angle); +XMMATRIX XMMatrixRotationRollPitchYaw(FLOAT Pitch, FLOAT Yaw, FLOAT Roll); +XMMATRIX XMMatrixRotationRollPitchYawFromVector(FXMVECTOR Angles); +XMMATRIX XMMatrixRotationNormal(FXMVECTOR NormalAxis, FLOAT Angle); +XMMATRIX XMMatrixRotationAxis(FXMVECTOR Axis, FLOAT Angle); +XMMATRIX XMMatrixRotationQuaternion(FXMVECTOR Quaternion); +XMMATRIX XMMatrixTransformation2D(FXMVECTOR ScalingOrigin, FLOAT ScalingOrientation, FXMVECTOR Scaling, + FXMVECTOR RotationOrigin, FLOAT Rotation, CXMVECTOR Translation); +XMMATRIX XMMatrixTransformation(FXMVECTOR ScalingOrigin, FXMVECTOR ScalingOrientationQuaternion, FXMVECTOR Scaling, + CXMVECTOR RotationOrigin, CXMVECTOR RotationQuaternion, CXMVECTOR Translation); +XMMATRIX XMMatrixAffineTransformation2D(FXMVECTOR Scaling, FXMVECTOR RotationOrigin, FLOAT Rotation, FXMVECTOR Translation); +XMMATRIX XMMatrixAffineTransformation(FXMVECTOR Scaling, FXMVECTOR RotationOrigin, FXMVECTOR RotationQuaternion, CXMVECTOR Translation); +XMMATRIX XMMatrixReflect(FXMVECTOR ReflectionPlane); +XMMATRIX XMMatrixShadow(FXMVECTOR ShadowPlane, FXMVECTOR LightPosition); + +XMMATRIX XMMatrixLookAtLH(FXMVECTOR EyePosition, FXMVECTOR FocusPosition, FXMVECTOR UpDirection); +XMMATRIX XMMatrixLookAtRH(FXMVECTOR EyePosition, FXMVECTOR FocusPosition, FXMVECTOR UpDirection); +XMMATRIX XMMatrixLookToLH(FXMVECTOR EyePosition, FXMVECTOR EyeDirection, FXMVECTOR UpDirection); +XMMATRIX XMMatrixLookToRH(FXMVECTOR EyePosition, FXMVECTOR EyeDirection, FXMVECTOR UpDirection); +XMMATRIX XMMatrixPerspectiveLH(FLOAT ViewWidth, FLOAT ViewHeight, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixPerspectiveRH(FLOAT ViewWidth, FLOAT ViewHeight, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixPerspectiveFovLH(FLOAT FovAngleY, FLOAT AspectHByW, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixPerspectiveFovRH(FLOAT FovAngleY, FLOAT AspectHByW, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixPerspectiveOffCenterLH(FLOAT ViewLeft, FLOAT ViewRight, FLOAT ViewBottom, FLOAT ViewTop, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixPerspectiveOffCenterRH(FLOAT ViewLeft, FLOAT ViewRight, FLOAT ViewBottom, FLOAT ViewTop, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixOrthographicLH(FLOAT ViewWidth, FLOAT ViewHeight, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixOrthographicRH(FLOAT ViewWidth, FLOAT ViewHeight, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixOrthographicOffCenterLH(FLOAT ViewLeft, FLOAT ViewRight, FLOAT ViewBottom, FLOAT ViewTop, FLOAT NearZ, FLOAT FarZ); +XMMATRIX XMMatrixOrthographicOffCenterRH(FLOAT ViewLeft, FLOAT ViewRight, FLOAT ViewBottom, FLOAT ViewTop, FLOAT NearZ, FLOAT FarZ); + + +/**************************************************************************** + * + * Quaternion operations + * + ****************************************************************************/ + +BOOL XMQuaternionEqual(FXMVECTOR Q1, FXMVECTOR Q2); +BOOL XMQuaternionNotEqual(FXMVECTOR Q1, FXMVECTOR Q2); + +BOOL XMQuaternionIsNaN(FXMVECTOR Q); +BOOL XMQuaternionIsInfinite(FXMVECTOR Q); +BOOL XMQuaternionIsIdentity(FXMVECTOR Q); + +XMVECTOR XMQuaternionDot(FXMVECTOR Q1, FXMVECTOR Q2); +XMVECTOR XMQuaternionMultiply(FXMVECTOR Q1, FXMVECTOR Q2); +XMVECTOR XMQuaternionLengthSq(FXMVECTOR Q); +XMVECTOR XMQuaternionReciprocalLength(FXMVECTOR Q); +XMVECTOR XMQuaternionLength(FXMVECTOR Q); +XMVECTOR XMQuaternionNormalizeEst(FXMVECTOR Q); +XMVECTOR XMQuaternionNormalize(FXMVECTOR Q); +XMVECTOR XMQuaternionConjugate(FXMVECTOR Q); +XMVECTOR XMQuaternionInverse(FXMVECTOR Q); +XMVECTOR XMQuaternionLn(FXMVECTOR Q); +XMVECTOR XMQuaternionExp(FXMVECTOR Q); +XMVECTOR XMQuaternionSlerp(FXMVECTOR Q0, FXMVECTOR Q1, FLOAT t); +XMVECTOR XMQuaternionSlerpV(FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR T); +XMVECTOR XMQuaternionSquad(FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR Q2, CXMVECTOR Q3, FLOAT t); +XMVECTOR XMQuaternionSquadV(FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR Q2, CXMVECTOR Q3, CXMVECTOR T); +VOID XMQuaternionSquadSetup(_Out_ XMVECTOR* pA, _Out_ XMVECTOR* pB, _Out_ XMVECTOR* pC, FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR Q2, CXMVECTOR Q3); +XMVECTOR XMQuaternionBaryCentric(FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR Q2, FLOAT f, FLOAT g); +XMVECTOR XMQuaternionBaryCentricV(FXMVECTOR Q0, FXMVECTOR Q1, FXMVECTOR Q2, CXMVECTOR F, CXMVECTOR G); + +XMVECTOR XMQuaternionIdentity(); +XMVECTOR XMQuaternionRotationRollPitchYaw(FLOAT Pitch, FLOAT Yaw, FLOAT Roll); +XMVECTOR XMQuaternionRotationRollPitchYawFromVector(FXMVECTOR Angles); +XMVECTOR XMQuaternionRotationNormal(FXMVECTOR NormalAxis, FLOAT Angle); +XMVECTOR XMQuaternionRotationAxis(FXMVECTOR Axis, FLOAT Angle); +XMVECTOR XMQuaternionRotationMatrix(CXMMATRIX M); + +VOID XMQuaternionToAxisAngle(_Out_ XMVECTOR* pAxis, _Out_ FLOAT* pAngle, FXMVECTOR Q); + +/**************************************************************************** + * + * Plane operations + * + ****************************************************************************/ + +BOOL XMPlaneEqual(FXMVECTOR P1, FXMVECTOR P2); +BOOL XMPlaneNearEqual(FXMVECTOR P1, FXMVECTOR P2, FXMVECTOR Epsilon); +BOOL XMPlaneNotEqual(FXMVECTOR P1, FXMVECTOR P2); + +BOOL XMPlaneIsNaN(FXMVECTOR P); +BOOL XMPlaneIsInfinite(FXMVECTOR P); + +XMVECTOR XMPlaneDot(FXMVECTOR P, FXMVECTOR V); +XMVECTOR XMPlaneDotCoord(FXMVECTOR P, FXMVECTOR V); +XMVECTOR XMPlaneDotNormal(FXMVECTOR P, FXMVECTOR V); +XMVECTOR XMPlaneNormalizeEst(FXMVECTOR P); +XMVECTOR XMPlaneNormalize(FXMVECTOR P); +XMVECTOR XMPlaneIntersectLine(FXMVECTOR P, FXMVECTOR LinePoint1, FXMVECTOR LinePoint2); +VOID XMPlaneIntersectPlane(_Out_ XMVECTOR* pLinePoint1, _Out_ XMVECTOR* pLinePoint2, FXMVECTOR P1, FXMVECTOR P2); +XMVECTOR XMPlaneTransform(FXMVECTOR P, CXMMATRIX M); +XMFLOAT4* XMPlaneTransformStream(_Out_bytecap_x_(sizeof(XMFLOAT4)+OutputStride*(PlaneCount-1)) XMFLOAT4* pOutputStream, + _In_ size_t OutputStride, + _In_bytecount_x_(sizeof(XMFLOAT4)+InputStride*(PlaneCount-1)) CONST XMFLOAT4* pInputStream, + _In_ size_t InputStride, _In_ size_t PlaneCount, CXMMATRIX M); + +XMVECTOR XMPlaneFromPointNormal(FXMVECTOR Point, FXMVECTOR Normal); +XMVECTOR XMPlaneFromPoints(FXMVECTOR Point1, FXMVECTOR Point2, FXMVECTOR Point3); + +/**************************************************************************** + * + * Color operations + * + ****************************************************************************/ + +BOOL XMColorEqual(FXMVECTOR C1, FXMVECTOR C2); +BOOL XMColorNotEqual(FXMVECTOR C1, FXMVECTOR C2); +BOOL XMColorGreater(FXMVECTOR C1, FXMVECTOR C2); +BOOL XMColorGreaterOrEqual(FXMVECTOR C1, FXMVECTOR C2); +BOOL XMColorLess(FXMVECTOR C1, FXMVECTOR C2); +BOOL XMColorLessOrEqual(FXMVECTOR C1, FXMVECTOR C2); + +BOOL XMColorIsNaN(FXMVECTOR C); +BOOL XMColorIsInfinite(FXMVECTOR C); + +XMVECTOR XMColorNegative(FXMVECTOR C); +XMVECTOR XMColorModulate(FXMVECTOR C1, FXMVECTOR C2); +XMVECTOR XMColorAdjustSaturation(FXMVECTOR C, FLOAT Saturation); +XMVECTOR XMColorAdjustContrast(FXMVECTOR C, FLOAT Contrast); + +/**************************************************************************** + * + * Miscellaneous operations + * + ****************************************************************************/ + +BOOL XMVerifyCPUSupport(); + +VOID XMAssert(_In_z_ CONST CHAR* pExpression, _In_z_ CONST CHAR* pFileName, UINT LineNumber); + +XMVECTOR XMFresnelTerm(FXMVECTOR CosIncidentAngle, FXMVECTOR RefractionIndex); + +BOOL XMScalarNearEqual(FLOAT S1, FLOAT S2, FLOAT Epsilon); +FLOAT XMScalarModAngle(FLOAT Value); +FLOAT XMScalarSin(FLOAT Value); +FLOAT XMScalarCos(FLOAT Value); +VOID XMScalarSinCos(_Out_ FLOAT* pSin, _Out_ FLOAT* pCos, FLOAT Value); +FLOAT XMScalarASin(FLOAT Value); +FLOAT XMScalarACos(FLOAT Value); +FLOAT XMScalarSinEst(FLOAT Value); +FLOAT XMScalarCosEst(FLOAT Value); +VOID XMScalarSinCosEst(_Out_ FLOAT* pSin, _Out_ FLOAT* pCos, FLOAT Value); +FLOAT XMScalarASinEst(FLOAT Value); +FLOAT XMScalarACosEst(FLOAT Value); + +/**************************************************************************** + * + * Templates + * + ****************************************************************************/ + +#if defined(__cplusplus) + +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + +// PermuteHelper internal template (SSE only) +namespace XNAMathInternal +{ + // Slow path fallback for permutes that do not map to a single SSE shuffle opcode. + template struct PermuteHelper + { + static XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR v2) + { + static const XMVECTORU32 selectMask = + { + WhichX ? 0xFFFFFFFF : 0, + WhichY ? 0xFFFFFFFF : 0, + WhichZ ? 0xFFFFFFFF : 0, + WhichW ? 0xFFFFFFFF : 0, + }; + + XMVECTOR shuffled1 = _mm_shuffle_ps(v1, v1, Shuffle); + XMVECTOR shuffled2 = _mm_shuffle_ps(v2, v2, Shuffle); + + XMVECTOR masked1 = _mm_andnot_ps(selectMask, shuffled1); + XMVECTOR masked2 = _mm_and_ps(selectMask, shuffled2); + + return _mm_or_ps(masked1, masked2); + } + }; + + // Fast path for permutes that only read from the first vector. + template struct PermuteHelper + { + static XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR v2) { (v2); return _mm_shuffle_ps(v1, v1, Shuffle); } + }; + + // Fast path for permutes that only read from the second vector. + template struct PermuteHelper + { + static XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR v2){ (v1); return _mm_shuffle_ps(v2, v2, Shuffle); } + }; + + // Fast path for permutes that read XY from the first vector, ZW from the second. + template struct PermuteHelper + { + static XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR v2) { return _mm_shuffle_ps(v1, v2, Shuffle); } + }; + + // Fast path for permutes that read XY from the second vector, ZW from the first. + template struct PermuteHelper + { + static XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR v2) { return _mm_shuffle_ps(v2, v1, Shuffle); } + }; +}; + +#endif // _XM_SSE_INTRINSICS_ && !_XM_NO_INTRINSICS_ + +// General permute template +template + inline XMVECTOR XMVectorPermute(FXMVECTOR V1, FXMVECTOR V2) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1600) + static_assert(PermuteX <= 7, "PermuteX template parameter out of range"); + static_assert(PermuteY <= 7, "PermuteY template parameter out of range"); + static_assert(PermuteZ <= 7, "PermuteZ template parameter out of range"); + static_assert(PermuteW <= 7, "PermuteW template parameter out of range"); +#else + XMASSERT(PermuteX <= 7); + XMASSERT(PermuteY <= 7); + XMASSERT(PermuteZ <= 7); + XMASSERT(PermuteW <= 7); +#endif + +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + const UINT Shuffle = _MM_SHUFFLE(PermuteW & 3, PermuteZ & 3, PermuteY & 3, PermuteX & 3); + + const bool WhichX = PermuteX > 3; + const bool WhichY = PermuteY > 3; + const bool WhichZ = PermuteZ > 3; + const bool WhichW = PermuteW > 3; + + return XNAMathInternal::PermuteHelper::Permute(V1, V2); +#else + + XMVECTOR c = XMVectorPermuteControl( PermuteX, PermuteY, PermuteZ, PermuteW ); + return XMVectorPermute( V1, V2, c ); + +#endif +} + +// Special-case permute templates +template<> inline XMVECTOR XMVectorPermute<0,1,2,3>(FXMVECTOR V1, FXMVECTOR V2) { (V2); return V1; } +template<> inline XMVECTOR XMVectorPermute<4,5,6,7>(FXMVECTOR V1, FXMVECTOR V2) { (V1); return V2; } + +//------------------------------------------------------------------------------ + +// General swizzle template +template + inline XMVECTOR XMVectorSwizzle(FXMVECTOR V) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1600) + static_assert(SwizzleX <= 3, "SwizzleX template parameter out of range"); + static_assert(SwizzleY <= 3, "SwizzleY template parameter out of range"); + static_assert(SwizzleZ <= 3, "SwizzleZ template parameter out of range"); + static_assert(SwizzleW <= 3, "SwizzleW template parameter out of range"); +#else + XMASSERT(SwizzleX <= 3); + XMASSERT(SwizzleY <= 3); + XMASSERT(SwizzleZ <= 3); + XMASSERT(SwizzleW <= 3); +#endif + +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + return _mm_shuffle_ps( V, V, _MM_SHUFFLE( SwizzleW, SwizzleZ, SwizzleY, SwizzleX ) ); +#elif defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + return __vpermwi(V, ((SwizzleX & 3) << 6) | ((SwizzleY & 3) << 4) | ((SwizzleZ & 3) << 2) | (SwizzleW & 3) ); +#else + + return XMVectorSwizzle( V, SwizzleX, SwizzleY, SwizzleZ, SwizzleW ); + +#endif +} + +// Specialized swizzles +template<> inline XMVECTOR XMVectorSwizzle<0,1,2,3>(FXMVECTOR V) { return V; } + +//------------------------------------------------------------------------------ + +template + inline XMVECTOR XMVectorShiftLeft(FXMVECTOR V1, FXMVECTOR V2) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1600) + static_assert( Elements < 4, "Elements template parameter out of range" ); +#else + XMASSERT( Elements < 4 ); +#endif + +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +#else + return XMVectorPermute(V1, V2); +#endif +} + +template + inline XMVECTOR XMVectorRotateLeft(FXMVECTOR V) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1600) + static_assert( Elements < 4, "Elements template parameter out of range" ); +#else + XMASSERT( Elements < 4 ); +#endif + +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +#else + return XMVectorSwizzle(V); +#endif +} + +template + inline XMVECTOR XMVectorRotateRight(FXMVECTOR V) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1600) + static_assert( Elements < 4, "Elements template parameter out of range" ); +#else + XMASSERT( Elements < 4 ); +#endif + +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +#else + return XMVectorSwizzle<(4 - Elements) & 3, (5 - Elements) & 3, (6 - Elements) & 3, (7 - Elements) & 3>(V); +#endif +} + +template + inline XMVECTOR XMVectorInsert(FXMVECTOR VD, FXMVECTOR VS) +{ +#if defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) +#else + XMVECTOR Control = XMVectorSelectControl(Select0&1, Select1&1, Select2&1, Select3&1); + return XMVectorSelect( VD, XMVectorRotateLeft(VS), Control ); +#endif +} + +#endif // __cplusplus + +/**************************************************************************** + * + * Globals + * + ****************************************************************************/ + +// The purpose of the following global constants is to prevent redundant +// reloading of the constants when they are referenced by more than one +// separate inline math routine called within the same function. Declaring +// a constant locally within a routine is sufficient to prevent redundant +// reloads of that constant when that single routine is called multiple +// times in a function, but if the constant is used (and declared) in a +// separate math routine it would be reloaded. + +#define XMGLOBALCONST extern CONST __declspec(selectany) + +XMGLOBALCONST XMVECTORF32 g_XMSinCoefficients0 = {1.0f, -0.166666667f, 8.333333333e-3f, -1.984126984e-4f}; +XMGLOBALCONST XMVECTORF32 g_XMSinCoefficients1 = {2.755731922e-6f, -2.505210839e-8f, 1.605904384e-10f, -7.647163732e-13f}; +XMGLOBALCONST XMVECTORF32 g_XMSinCoefficients2 = {2.811457254e-15f, -8.220635247e-18f, 1.957294106e-20f, -3.868170171e-23f}; +XMGLOBALCONST XMVECTORF32 g_XMCosCoefficients0 = {1.0f, -0.5f, 4.166666667e-2f, -1.388888889e-3f}; +XMGLOBALCONST XMVECTORF32 g_XMCosCoefficients1 = {2.480158730e-5f, -2.755731922e-7f, 2.087675699e-9f, -1.147074560e-11f}; +XMGLOBALCONST XMVECTORF32 g_XMCosCoefficients2 = {4.779477332e-14f, -1.561920697e-16f, 4.110317623e-19f, -8.896791392e-22f}; +XMGLOBALCONST XMVECTORF32 g_XMTanCoefficients0 = {1.0f, 0.333333333f, 0.133333333f, 5.396825397e-2f}; +XMGLOBALCONST XMVECTORF32 g_XMTanCoefficients1 = {2.186948854e-2f, 8.863235530e-3f, 3.592128167e-3f, 1.455834485e-3f}; +XMGLOBALCONST XMVECTORF32 g_XMTanCoefficients2 = {5.900274264e-4f, 2.391290764e-4f, 9.691537707e-5f, 3.927832950e-5f}; +XMGLOBALCONST XMVECTORF32 g_XMASinCoefficients0 = {-0.05806367563904f, -0.41861972469416f, 0.22480114791621f, 2.17337241360606f}; +XMGLOBALCONST XMVECTORF32 g_XMASinCoefficients1 = {0.61657275907170f, 4.29696498283455f, -1.18942822255452f, -6.53784832094831f}; +XMGLOBALCONST XMVECTORF32 g_XMASinCoefficients2 = {-1.36926553863413f, -4.48179294237210f, 1.41810672941833f, 5.48179257935713f}; +XMGLOBALCONST XMVECTORF32 g_XMATanCoefficients0 = {1.0f, 0.333333334f, 0.2f, 0.142857143f}; +XMGLOBALCONST XMVECTORF32 g_XMATanCoefficients1 = {1.111111111e-1f, 9.090909091e-2f, 7.692307692e-2f, 6.666666667e-2f}; +XMGLOBALCONST XMVECTORF32 g_XMATanCoefficients2 = {5.882352941e-2f, 5.263157895e-2f, 4.761904762e-2f, 4.347826087e-2f}; +XMGLOBALCONST XMVECTORF32 g_XMSinEstCoefficients = {1.0f, -1.66521856991541e-1f, 8.199913018755e-3f, -1.61475937228e-4f}; +XMGLOBALCONST XMVECTORF32 g_XMCosEstCoefficients = {1.0f, -4.95348008918096e-1f, 3.878259962881e-2f, -9.24587976263e-4f}; +XMGLOBALCONST XMVECTORF32 g_XMTanEstCoefficients = {2.484f, -1.954923183e-1f, 2.467401101f, XM_1DIVPI}; +XMGLOBALCONST XMVECTORF32 g_XMATanEstCoefficients = {7.689891418951e-1f, 1.104742493348f, 8.661844266006e-1f, XM_PIDIV2}; +XMGLOBALCONST XMVECTORF32 g_XMASinEstCoefficients = {-1.36178272886711f, 2.37949493464538f, -8.08228565650486e-1f, 2.78440142746736e-1f}; +XMGLOBALCONST XMVECTORF32 g_XMASinEstConstants = {1.00000011921f, XM_PIDIV2, 0.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMPiConstants0 = {XM_PI, XM_2PI, XM_1DIVPI, XM_1DIV2PI}; +XMGLOBALCONST XMVECTORF32 g_XMIdentityR0 = {1.0f, 0.0f, 0.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMIdentityR1 = {0.0f, 1.0f, 0.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMIdentityR2 = {0.0f, 0.0f, 1.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMIdentityR3 = {0.0f, 0.0f, 0.0f, 1.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegIdentityR0 = {-1.0f,0.0f, 0.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegIdentityR1 = {0.0f,-1.0f, 0.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegIdentityR2 = {0.0f, 0.0f,-1.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegIdentityR3 = {0.0f, 0.0f, 0.0f,-1.0f}; +XMGLOBALCONST XMVECTORI32 g_XMNegativeZero = {0x80000000, 0x80000000, 0x80000000, 0x80000000}; +XMGLOBALCONST XMVECTORI32 g_XMNegate3 = {0x80000000, 0x80000000, 0x80000000, 0x00000000}; +XMGLOBALCONST XMVECTORI32 g_XMMask3 = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000}; +XMGLOBALCONST XMVECTORI32 g_XMMaskX = {0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000}; +XMGLOBALCONST XMVECTORI32 g_XMMaskY = {0x00000000, 0xFFFFFFFF, 0x00000000, 0x00000000}; +XMGLOBALCONST XMVECTORI32 g_XMMaskZ = {0x00000000, 0x00000000, 0xFFFFFFFF, 0x00000000}; +XMGLOBALCONST XMVECTORI32 g_XMMaskW = {0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF}; +XMGLOBALCONST XMVECTORF32 g_XMOne = { 1.0f, 1.0f, 1.0f, 1.0f}; +XMGLOBALCONST XMVECTORF32 g_XMOne3 = { 1.0f, 1.0f, 1.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMZero = { 0.0f, 0.0f, 0.0f, 0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegativeOne = {-1.0f,-1.0f,-1.0f,-1.0f}; +XMGLOBALCONST XMVECTORF32 g_XMOneHalf = { 0.5f, 0.5f, 0.5f, 0.5f}; +XMGLOBALCONST XMVECTORF32 g_XMNegativeOneHalf = {-0.5f,-0.5f,-0.5f,-0.5f}; +XMGLOBALCONST XMVECTORF32 g_XMNegativeTwoPi = {-XM_2PI, -XM_2PI, -XM_2PI, -XM_2PI}; +XMGLOBALCONST XMVECTORF32 g_XMNegativePi = {-XM_PI, -XM_PI, -XM_PI, -XM_PI}; +XMGLOBALCONST XMVECTORF32 g_XMHalfPi = {XM_PIDIV2, XM_PIDIV2, XM_PIDIV2, XM_PIDIV2}; +XMGLOBALCONST XMVECTORF32 g_XMPi = {XM_PI, XM_PI, XM_PI, XM_PI}; +XMGLOBALCONST XMVECTORF32 g_XMReciprocalPi = {XM_1DIVPI, XM_1DIVPI, XM_1DIVPI, XM_1DIVPI}; +XMGLOBALCONST XMVECTORF32 g_XMTwoPi = {XM_2PI, XM_2PI, XM_2PI, XM_2PI}; +XMGLOBALCONST XMVECTORF32 g_XMReciprocalTwoPi = {XM_1DIV2PI, XM_1DIV2PI, XM_1DIV2PI, XM_1DIV2PI}; +XMGLOBALCONST XMVECTORF32 g_XMEpsilon = {1.192092896e-7f, 1.192092896e-7f, 1.192092896e-7f, 1.192092896e-7f}; +XMGLOBALCONST XMVECTORI32 g_XMInfinity = {0x7F800000, 0x7F800000, 0x7F800000, 0x7F800000}; +XMGLOBALCONST XMVECTORI32 g_XMQNaN = {0x7FC00000, 0x7FC00000, 0x7FC00000, 0x7FC00000}; +XMGLOBALCONST XMVECTORI32 g_XMQNaNTest = {0x007FFFFF, 0x007FFFFF, 0x007FFFFF, 0x007FFFFF}; +XMGLOBALCONST XMVECTORI32 g_XMAbsMask = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; +XMGLOBALCONST XMVECTORI32 g_XMFltMin = {0x00800000, 0x00800000, 0x00800000, 0x00800000}; +XMGLOBALCONST XMVECTORI32 g_XMFltMax = {0x7F7FFFFF, 0x7F7FFFFF, 0x7F7FFFFF, 0x7F7FFFFF}; +XMGLOBALCONST XMVECTORI32 g_XMNegOneMask = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; +XMGLOBALCONST XMVECTORI32 g_XMMaskA8R8G8B8 = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}; +XMGLOBALCONST XMVECTORI32 g_XMFlipA8R8G8B8 = {0x00000000, 0x00000000, 0x00000000, 0x80000000}; +XMGLOBALCONST XMVECTORF32 g_XMFixAA8R8G8B8 = {0.0f,0.0f,0.0f,(float)(0x80000000U)}; +XMGLOBALCONST XMVECTORF32 g_XMNormalizeA8R8G8B8 = {1.0f/(255.0f*(float)(0x10000)),1.0f/(255.0f*(float)(0x100)),1.0f/255.0f,1.0f/(255.0f*(float)(0x1000000))}; +XMGLOBALCONST XMVECTORI32 g_XMMaskA2B10G10R10 = {0x000003FF, 0x000FFC00, 0x3FF00000, 0xC0000000}; +XMGLOBALCONST XMVECTORI32 g_XMFlipA2B10G10R10 = {0x00000200, 0x00080000, 0x20000000, 0x80000000}; +XMGLOBALCONST XMVECTORF32 g_XMFixAA2B10G10R10 = {-512.0f,-512.0f*(float)(0x400),-512.0f*(float)(0x100000),(float)(0x80000000U)}; +XMGLOBALCONST XMVECTORF32 g_XMNormalizeA2B10G10R10 = {1.0f/511.0f,1.0f/(511.0f*(float)(0x400)),1.0f/(511.0f*(float)(0x100000)),1.0f/(3.0f*(float)(0x40000000))}; +XMGLOBALCONST XMVECTORI32 g_XMMaskX16Y16 = {0x0000FFFF, 0xFFFF0000, 0x00000000, 0x00000000}; +XMGLOBALCONST XMVECTORI32 g_XMFlipX16Y16 = {0x00008000, 0x00000000, 0x00000000, 0x00000000}; +XMGLOBALCONST XMVECTORF32 g_XMFixX16Y16 = {-32768.0f,0.0f,0.0f,0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNormalizeX16Y16 = {1.0f/32767.0f,1.0f/(32767.0f*65536.0f),0.0f,0.0f}; +XMGLOBALCONST XMVECTORI32 g_XMMaskX16Y16Z16W16 = {0x0000FFFF, 0x0000FFFF, 0xFFFF0000, 0xFFFF0000}; +XMGLOBALCONST XMVECTORI32 g_XMFlipX16Y16Z16W16 = {0x00008000, 0x00008000, 0x00000000, 0x00000000}; +XMGLOBALCONST XMVECTORF32 g_XMFixX16Y16Z16W16 = {-32768.0f,-32768.0f,0.0f,0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNormalizeX16Y16Z16W16 = {1.0f/32767.0f,1.0f/32767.0f,1.0f/(32767.0f*65536.0f),1.0f/(32767.0f*65536.0f)}; +XMGLOBALCONST XMVECTORF32 g_XMNoFraction = {8388608.0f,8388608.0f,8388608.0f,8388608.0f}; +XMGLOBALCONST XMVECTORI32 g_XMMaskByte = {0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF}; +XMGLOBALCONST XMVECTORF32 g_XMNegateX = {-1.0f, 1.0f, 1.0f, 1.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegateY = { 1.0f,-1.0f, 1.0f, 1.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegateZ = { 1.0f, 1.0f,-1.0f, 1.0f}; +XMGLOBALCONST XMVECTORF32 g_XMNegateW = { 1.0f, 1.0f, 1.0f,-1.0f}; +XMGLOBALCONST XMVECTORI32 g_XMSelect0101 = {XM_SELECT_0, XM_SELECT_1, XM_SELECT_0, XM_SELECT_1}; +XMGLOBALCONST XMVECTORI32 g_XMSelect1010 = {XM_SELECT_1, XM_SELECT_0, XM_SELECT_1, XM_SELECT_0}; +XMGLOBALCONST XMVECTORI32 g_XMOneHalfMinusEpsilon = { 0x3EFFFFFD, 0x3EFFFFFD, 0x3EFFFFFD, 0x3EFFFFFD}; +XMGLOBALCONST XMVECTORI32 g_XMSelect1000 = {XM_SELECT_1, XM_SELECT_0, XM_SELECT_0, XM_SELECT_0}; +XMGLOBALCONST XMVECTORI32 g_XMSelect1100 = {XM_SELECT_1, XM_SELECT_1, XM_SELECT_0, XM_SELECT_0}; +XMGLOBALCONST XMVECTORI32 g_XMSelect1110 = {XM_SELECT_1, XM_SELECT_1, XM_SELECT_1, XM_SELECT_0}; +XMGLOBALCONST XMVECTORI32 g_XMSwizzleXYXY = {XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0X, XM_PERMUTE_0Y}; +XMGLOBALCONST XMVECTORI32 g_XMSwizzleXYZX = {XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0X}; +XMGLOBALCONST XMVECTORI32 g_XMSwizzleYXZW = {XM_PERMUTE_0Y, XM_PERMUTE_0X, XM_PERMUTE_0Z, XM_PERMUTE_0W}; +XMGLOBALCONST XMVECTORI32 g_XMSwizzleYZXW = {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0W}; +XMGLOBALCONST XMVECTORI32 g_XMSwizzleZXYW = {XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0W}; +XMGLOBALCONST XMVECTORI32 g_XMPermute0X0Y1X1Y = {XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_1X, XM_PERMUTE_1Y}; +XMGLOBALCONST XMVECTORI32 g_XMPermute0Z0W1Z1W = {XM_PERMUTE_0Z, XM_PERMUTE_0W, XM_PERMUTE_1Z, XM_PERMUTE_1W}; +XMGLOBALCONST XMVECTORF32 g_XMFixupY16 = {1.0f,1.0f/65536.0f,0.0f,0.0f}; +XMGLOBALCONST XMVECTORF32 g_XMFixupY16W16 = {1.0f,1.0f,1.0f/65536.0f,1.0f/65536.0f}; +XMGLOBALCONST XMVECTORI32 g_XMFlipY = {0,0x80000000,0,0}; +XMGLOBALCONST XMVECTORI32 g_XMFlipZ = {0,0,0x80000000,0}; +XMGLOBALCONST XMVECTORI32 g_XMFlipW = {0,0,0,0x80000000}; +XMGLOBALCONST XMVECTORI32 g_XMFlipYZ = {0,0x80000000,0x80000000,0}; +XMGLOBALCONST XMVECTORI32 g_XMFlipZW = {0,0,0x80000000,0x80000000}; +XMGLOBALCONST XMVECTORI32 g_XMFlipYW = {0,0x80000000,0,0x80000000}; +XMGLOBALCONST XMVECTORI32 g_XMMaskHenD3 = {0x7FF,0x7ff<<11,0x3FF<<22,0}; +XMGLOBALCONST XMVECTORI32 g_XMMaskDHen3 = {0x3FF,0x7ff<<10,0x7FF<<21,0}; +XMGLOBALCONST XMVECTORF32 g_XMAddUHenD3 = {0,0,32768.0f*65536.0f,0}; +XMGLOBALCONST XMVECTORF32 g_XMAddHenD3 = {-1024.0f,-1024.0f*2048.0f,0,0}; +XMGLOBALCONST XMVECTORF32 g_XMAddDHen3 = {-512.0f,-1024.0f*1024.0f,0,0}; +XMGLOBALCONST XMVECTORF32 g_XMMulHenD3 = {1.0f,1.0f/2048.0f,1.0f/(2048.0f*2048.0f),0}; +XMGLOBALCONST XMVECTORF32 g_XMMulDHen3 = {1.0f,1.0f/1024.0f,1.0f/(1024.0f*2048.0f),0}; +XMGLOBALCONST XMVECTORI32 g_XMXorHenD3 = {0x400,0x400<<11,0,0}; +XMGLOBALCONST XMVECTORI32 g_XMXorDHen3 = {0x200,0x400<<10,0,0}; +XMGLOBALCONST XMVECTORI32 g_XMMaskIco4 = {0xFFFFF,0xFFFFF000,0xFFFFF,0xF0000000}; +XMGLOBALCONST XMVECTORI32 g_XMXorXIco4 = {0x80000,0,0x80000,0x80000000}; +XMGLOBALCONST XMVECTORI32 g_XMXorIco4 = {0x80000,0,0x80000,0}; +XMGLOBALCONST XMVECTORF32 g_XMAddXIco4 = {-8.0f*65536.0f,0,-8.0f*65536.0f,32768.0f*65536.0f}; +XMGLOBALCONST XMVECTORF32 g_XMAddUIco4 = {0,32768.0f*65536.0f,0,32768.0f*65536.0f}; +XMGLOBALCONST XMVECTORF32 g_XMAddIco4 = {-8.0f*65536.0f,0,-8.0f*65536.0f,0}; +XMGLOBALCONST XMVECTORF32 g_XMMulIco4 = {1.0f,1.0f/4096.0f,1.0f,1.0f/(4096.0f*65536.0f)}; +XMGLOBALCONST XMVECTORI32 g_XMMaskDec4 = {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<30}; +XMGLOBALCONST XMVECTORI32 g_XMXorDec4 = {0x200,0x200<<10,0x200<<20,0}; +XMGLOBALCONST XMVECTORF32 g_XMAddUDec4 = {0,0,0,32768.0f*65536.0f}; +XMGLOBALCONST XMVECTORF32 g_XMAddDec4 = {-512.0f,-512.0f*1024.0f,-512.0f*1024.0f*1024.0f,0}; +XMGLOBALCONST XMVECTORF32 g_XMMulDec4 = {1.0f,1.0f/1024.0f,1.0f/(1024.0f*1024.0f),1.0f/(1024.0f*1024.0f*1024.0f)}; +XMGLOBALCONST XMVECTORI32 g_XMMaskByte4 = {0xFF,0xFF00,0xFF0000,0xFF000000}; +XMGLOBALCONST XMVECTORI32 g_XMXorByte4 = {0x80,0x8000,0x800000,0x00000000}; +XMGLOBALCONST XMVECTORF32 g_XMAddByte4 = {-128.0f,-128.0f*256.0f,-128.0f*65536.0f,0}; +XMGLOBALCONST XMVECTORF32 g_XMFixUnsigned = {32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f}; +XMGLOBALCONST XMVECTORF32 g_XMMaxInt = {65536.0f*32768.0f-128.0f,65536.0f*32768.0f-128.0f,65536.0f*32768.0f-128.0f,65536.0f*32768.0f-128.0f}; +XMGLOBALCONST XMVECTORF32 g_XMMaxUInt = {65536.0f*65536.0f-256.0f,65536.0f*65536.0f-256.0f,65536.0f*65536.0f-256.0f,65536.0f*65536.0f-256.0f}; +XMGLOBALCONST XMVECTORF32 g_XMUnsignedFix = {32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f,32768.0f*65536.0f}; + + +/**************************************************************************** + * + * Implementation + * + ****************************************************************************/ + +#pragma warning(push) +#pragma warning(disable:4068 4214 4204 4365 4616 6001) + +#pragma prefast(push) +#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes") + +#if !defined(__cplusplus) && !defined(_XBOX) && defined(_XM_ISVS2005_) + +/* Work around VC 2005 bug where math.h defines logf with a semicolon at the end. + * Note this is fixed as of Visual Studio 2005 Service Pack 1 + */ + +#undef logf +#define logf(x) ((float)log((double)(x))) + +#endif // !defined(__cplusplus) && !defined(_XBOX) && defined(_XM_ISVS2005_) + + +//------------------------------------------------------------------------------ + +#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_VMX128_INTRINSICS_) +#else + +XMFINLINE XMVECTOR XMVectorSetBinaryConstant(UINT C0, UINT C1, UINT C2, UINT C3) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTORU32 vResult; + vResult.u[0] = (0-(C0&1)) & 0x3F800000; + vResult.u[1] = (0-(C1&1)) & 0x3F800000; + vResult.u[2] = (0-(C2&1)) & 0x3F800000; + vResult.u[3] = (0-(C3&1)) & 0x3F800000; + return vResult.v; +#else // XM_SSE_INTRINSICS_ + static const XMVECTORU32 g_vMask1 = {1,1,1,1}; + // Move the parms to a vector + __m128i vTemp = _mm_set_epi32(C3,C2,C1,C0); + // Mask off the low bits + vTemp = _mm_and_si128(vTemp,g_vMask1); + // 0xFFFFFFFF on true bits + vTemp = _mm_cmpeq_epi32(vTemp,g_vMask1); + // 0xFFFFFFFF -> 1.0f, 0x00000000 -> 0.0f + vTemp = _mm_and_si128(vTemp,g_XMOne); + return reinterpret_cast(&vTemp)[0]; +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSplatConstant(INT IntConstant, UINT DivExponent) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT( IntConstant >= -16 && IntConstant <= 15 ); + XMASSERT(DivExponent<32); + { + XMVECTORI32 V = { IntConstant, IntConstant, IntConstant, IntConstant }; + return XMConvertVectorIntToFloat( V.v, DivExponent); + } +#else // XM_SSE_INTRINSICS_ + XMASSERT( IntConstant >= -16 && IntConstant <= 15 ); + XMASSERT(DivExponent<32); + // Splat the int + __m128i vScale = _mm_set1_epi32(IntConstant); + // Convert to a float + XMVECTOR vResult = _mm_cvtepi32_ps(vScale); + // Convert DivExponent into 1.0f/(1<(&vScale)[0]); + return vResult; +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSplatConstantInt(INT IntConstant) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT( IntConstant >= -16 && IntConstant <= 15 ); + { + XMVECTORI32 V = { IntConstant, IntConstant, IntConstant, IntConstant }; + return V.v; + } +#else // XM_SSE_INTRINSICS_ + XMASSERT( IntConstant >= -16 && IntConstant <= 15 ); + __m128i V = _mm_set1_epi32( IntConstant ); + return reinterpret_cast<__m128 *>(&V)[0]; +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorShiftLeft(FXMVECTOR V1, FXMVECTOR V2, UINT Elements) +{ + return XMVectorPermute(V1, V2, XMVectorPermuteControl((Elements), ((Elements) + 1), ((Elements) + 2), ((Elements) + 3))); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorRotateLeft(FXMVECTOR V, UINT Elements) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT( Elements < 4 ); + { + XMVECTORF32 vResult = { V.vector4_f32[Elements & 3], V.vector4_f32[(Elements + 1) & 3], + V.vector4_f32[(Elements + 2) & 3], V.vector4_f32[(Elements + 3) & 3] }; + return vResult.v; + } +#else // XM_SSE_INTRINSICS_ + FLOAT fx = XMVectorGetByIndex(V,(Elements) & 3); + FLOAT fy = XMVectorGetByIndex(V,((Elements) + 1) & 3); + FLOAT fz = XMVectorGetByIndex(V,((Elements) + 2) & 3); + FLOAT fw = XMVectorGetByIndex(V,((Elements) + 3) & 3); + return _mm_set_ps( fw, fz, fy, fx ); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorRotateRight(FXMVECTOR V, UINT Elements) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT( Elements < 4 ); + { + XMVECTORF32 vResult = { V.vector4_f32[(4 - (Elements)) & 3], V.vector4_f32[(5 - (Elements)) & 3], + V.vector4_f32[(6 - (Elements)) & 3], V.vector4_f32[(7 - (Elements)) & 3] }; + return vResult.v; + } +#else // XM_SSE_INTRINSICS_ + FLOAT fx = XMVectorGetByIndex(V,(4 - (Elements)) & 3); + FLOAT fy = XMVectorGetByIndex(V,(5 - (Elements)) & 3); + FLOAT fz = XMVectorGetByIndex(V,(6 - (Elements)) & 3); + FLOAT fw = XMVectorGetByIndex(V,(7 - (Elements)) & 3); + return _mm_set_ps( fw, fz, fy, fx ); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSwizzle(FXMVECTOR V, UINT E0, UINT E1, UINT E2, UINT E3) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT( (E0 < 4) && (E1 < 4) && (E2 < 4) && (E3 < 4) ); + { + XMVECTORF32 vResult = { V.vector4_f32[E0], V.vector4_f32[E1], V.vector4_f32[E2], V.vector4_f32[E3] }; + return vResult.v; + } +#else // XM_SSE_INTRINSICS_ + FLOAT fx = XMVectorGetByIndex(V,E0); + FLOAT fy = XMVectorGetByIndex(V,E1); + FLOAT fz = XMVectorGetByIndex(V,E2); + FLOAT fw = XMVectorGetByIndex(V,E3); + return _mm_set_ps( fw, fz, fy, fx ); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorInsert(FXMVECTOR VD, FXMVECTOR VS, UINT VSLeftRotateElements, + UINT Select0, UINT Select1, UINT Select2, UINT Select3) +{ + XMVECTOR Control = XMVectorSelectControl(Select0&1, Select1&1, Select2&1, Select3&1); + return XMVectorSelect( VD, XMVectorRotateLeft(VS, VSLeftRotateElements), Control ); +} + +#endif + +//------------------------------------------------------------------------------ + +#include "xnamathconvert.inl" +#include "xnamathvector.inl" +#include "xnamathmatrix.inl" +#include "xnamathmisc.inl" + +#pragma prefast(pop) +#pragma warning(pop) + +#endif // __XNAMATH_H__ + diff --git a/third_party/xbox_sdk/include/xnamathconvert.inl b/third_party/xbox_sdk/include/xnamathconvert.inl new file mode 100644 index 0000000..63ed20d --- /dev/null +++ b/third_party/xbox_sdk/include/xnamathconvert.inl @@ -0,0 +1,6383 @@ +/************************************************************************ +* * +* xnamathconvert.inl -- SIMD C++ Math library for Windows and Xbox 360 * +* Conversion, loading, and storing functions * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ + +#if defined(_MSC_VER) && (_MSC_VER > 1000) +#pragma once +#endif + +#ifndef __XNAMATHCONVERT_INL__ +#define __XNAMATHCONVERT_INL__ + +#define XM_PACK_FACTOR (FLOAT)(1 << 22) +#define XM_UNPACK_FACTOR_UNSIGNED (FLOAT)(1 << 23) +#define XM_UNPACK_FACTOR_SIGNED XM_PACK_FACTOR + +#define XM_UNPACK_UNSIGNEDN_OFFSET(BitsX, BitsY, BitsZ, BitsW) \ + {-XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsX)) - 1), \ + -XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsY)) - 1), \ + -XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsZ)) - 1), \ + -XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsW)) - 1)} + +#define XM_UNPACK_UNSIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \ + {XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsX)) - 1), \ + XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsY)) - 1), \ + XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsZ)) - 1), \ + XM_UNPACK_FACTOR_UNSIGNED / (FLOAT)((1 << (BitsW)) - 1)} + +#define XM_UNPACK_SIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \ + {-XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsX) - 1)) - 1), \ + -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsY) - 1)) - 1), \ + -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsZ) - 1)) - 1), \ + -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsW) - 1)) - 1)} + +//#define XM_UNPACK_SIGNEDN_OFFSET(BitsX, BitsY, BitsZ, BitsW) \ +// {-XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsX) - 1)) - 1) * 3.0f, \ +// -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsY) - 1)) - 1) * 3.0f, \ +// -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsZ) - 1)) - 1) * 3.0f, \ +// -XM_UNPACK_FACTOR_SIGNED / (FLOAT)((1 << ((BitsW) - 1)) - 1) * 3.0f} + +#define XM_PACK_UNSIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \ + {-(FLOAT)((1 << (BitsX)) - 1) / XM_PACK_FACTOR, \ + -(FLOAT)((1 << (BitsY)) - 1) / XM_PACK_FACTOR, \ + -(FLOAT)((1 << (BitsZ)) - 1) / XM_PACK_FACTOR, \ + -(FLOAT)((1 << (BitsW)) - 1) / XM_PACK_FACTOR} + +#define XM_PACK_SIGNEDN_SCALE(BitsX, BitsY, BitsZ, BitsW) \ + {-(FLOAT)((1 << ((BitsX) - 1)) - 1) / XM_PACK_FACTOR, \ + -(FLOAT)((1 << ((BitsY) - 1)) - 1) / XM_PACK_FACTOR, \ + -(FLOAT)((1 << ((BitsZ) - 1)) - 1) / XM_PACK_FACTOR, \ + -(FLOAT)((1 << ((BitsW) - 1)) - 1) / XM_PACK_FACTOR} + +#define XM_PACK_OFFSET XMVectorSplatConstant(3, 0) +//#define XM_UNPACK_OFFSET XM_PACK_OFFSET + +/**************************************************************************** + * + * Data conversion + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE FLOAT XMConvertHalfToFloat +( + HALF Value +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + + UINT Mantissa; + UINT Exponent; + UINT Result; + + Mantissa = (UINT)(Value & 0x03FF); + + if ((Value & 0x7C00) != 0) // The value is normalized + { + Exponent = (UINT)((Value >> 10) & 0x1F); + } + else if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x0400) == 0); + + Mantissa &= 0x03FF; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result = ((Value & 0x8000) << 16) | // Sign + ((Exponent + 112) << 23) | // Exponent + (Mantissa << 13); // Mantissa + + return *(FLOAT*)&Result; + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif +} + +//------------------------------------------------------------------------------ + +XMINLINE FLOAT* XMConvertHalfToFloatStream +( + FLOAT* pOutputStream, + size_t OutputStride, + CONST HALF* pInputStream, + size_t InputStride, + size_t HalfCount +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + + size_t i; + CONST BYTE* pHalf = (CONST BYTE*)pInputStream; + BYTE* pFloat = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < HalfCount; i++) + { + *(FLOAT*)pFloat = XMConvertHalfToFloat(*(const HALF*)pHalf); + pHalf += InputStride; + pFloat += OutputStride; + } + + return pOutputStream; + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE HALF XMConvertFloatToHalf +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + UINT Result; + + UINT IValue = ((UINT *)(&Value))[0]; + UINT Sign = (IValue & 0x80000000U) >> 16U; + IValue = IValue & 0x7FFFFFFFU; // Hack off the sign + + if (IValue > 0x47FFEFFFU) + { + // The number is too large to be represented as a half. Saturate to infinity. + Result = 0x7FFFU; + } + else + { + if (IValue < 0x38800000U) + { + // The number is too small to be represented as a normalized half. + // Convert it to a denormalized value. + UINT Shift = 113U - (IValue >> 23U); + IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift; + } + else + { + // Rebias the exponent to represent the value as a normalized half. + IValue += 0xC8000000U; + } + + Result = ((IValue + 0x0FFFU + ((IValue >> 13U) & 1U)) >> 13U)&0x7FFFU; + } + return (HALF)(Result|Sign); + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif +} + +//------------------------------------------------------------------------------ + +XMINLINE HALF* XMConvertFloatToHalfStream +( + HALF* pOutputStream, + size_t OutputStride, + CONST FLOAT* pInputStream, + size_t InputStride, + size_t FloatCount +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + + size_t i; + BYTE* pFloat = (BYTE*)pInputStream; + BYTE* pHalf = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < FloatCount; i++) + { + *(HALF*)pHalf = XMConvertFloatToHalf(*(FLOAT*)pFloat); + pFloat += InputStride; + pHalf += OutputStride; + } + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) +// For VMX128, these routines are all defines in the main header + +#pragma warning(push) +#pragma warning(disable:4701) // Prevent warnings about 'Result' potentially being used without having been initialized + +XMINLINE XMVECTOR XMConvertVectorIntToFloat +( + FXMVECTOR VInt, + UINT DivExponent +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ElementIndex; + FLOAT fScale; + XMVECTOR Result; + XMASSERT(DivExponent<32); + fScale = 1.0f / (FLOAT)(1U << DivExponent); + ElementIndex = 0; + do { + INT iTemp = (INT)VInt.vector4_u32[ElementIndex]; + Result.vector4_f32[ElementIndex] = ((FLOAT)iTemp) * fScale; + } while (++ElementIndex<4); + return Result; +#else // _XM_SSE_INTRINSICS_ + XMASSERT(DivExponent<32); + // Convert to floats + XMVECTOR vResult = _mm_cvtepi32_ps(reinterpret_cast(&VInt)[0]); + // Convert DivExponent into 1.0f/(1<(&vScale)[0]); + return vResult; +#endif +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMConvertVectorFloatToInt +( + FXMVECTOR VFloat, + UINT MulExponent +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ElementIndex; + XMVECTOR Result; + FLOAT fScale; + XMASSERT(MulExponent<32); + // Get the scalar factor. + fScale = (FLOAT)(1U << MulExponent); + ElementIndex = 0; + do { + INT iResult; + FLOAT fTemp = VFloat.vector4_f32[ElementIndex]*fScale; + if (fTemp <= -(65536.0f*32768.0f)) { + iResult = (-0x7FFFFFFF)-1; + } else if (fTemp > (65536.0f*32768.0f)-128.0f) { + iResult = 0x7FFFFFFF; + } else { + iResult = (INT)fTemp; + } + Result.vector4_u32[ElementIndex] = (UINT)iResult; + } while (++ElementIndex<4); + return Result; +#else // _XM_SSE_INTRINSICS_ + XMASSERT(MulExponent<32); + XMVECTOR vResult = _mm_set_ps1((FLOAT)(1U << MulExponent)); + vResult = _mm_mul_ps(vResult,VFloat); + // In case of positive overflow, detect it + XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,g_XMMaxInt); + // Float to int conversion + __m128i vResulti = _mm_cvttps_epi32(vResult); + // If there was positive overflow, set to 0x7FFFFFFF + vResult = _mm_and_ps(vOverflow,g_XMAbsMask); + vOverflow = _mm_andnot_ps(vOverflow,reinterpret_cast(&vResulti)[0]); + vOverflow = _mm_or_ps(vOverflow,vResult); + return vOverflow; +#endif +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMConvertVectorUIntToFloat +( + FXMVECTOR VUInt, + UINT DivExponent +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ElementIndex; + FLOAT fScale; + XMVECTOR Result; + XMASSERT(DivExponent<32); + fScale = 1.0f / (FLOAT)(1U << DivExponent); + ElementIndex = 0; + do { + Result.vector4_f32[ElementIndex] = (FLOAT)VUInt.vector4_u32[ElementIndex] * fScale; + } while (++ElementIndex<4); + return Result; +#else // _XM_SSE_INTRINSICS_ + XMASSERT(DivExponent<32); + // For the values that are higher than 0x7FFFFFFF, a fixup is needed + // Determine which ones need the fix. + XMVECTOR vMask = _mm_and_ps(VUInt,g_XMNegativeZero); + // Force all values positive + XMVECTOR vResult = _mm_xor_ps(VUInt,vMask); + // Convert to floats + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert 0x80000000 -> 0xFFFFFFFF + __m128i iMask = _mm_srai_epi32(reinterpret_cast(&vMask)[0],31); + // For only the ones that are too big, add the fixup + vMask = _mm_and_ps(reinterpret_cast(&iMask)[0],g_XMFixUnsigned); + vResult = _mm_add_ps(vResult,vMask); + // Convert DivExponent into 1.0f/(1<(&iMask)[0]); + return vResult; +#endif +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMConvertVectorFloatToUInt +( + FXMVECTOR VFloat, + UINT MulExponent +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ElementIndex; + XMVECTOR Result; + FLOAT fScale; + XMASSERT(MulExponent<32); + // Get the scalar factor. + fScale = (FLOAT)(1U << MulExponent); + ElementIndex = 0; + do { + UINT uResult; + FLOAT fTemp = VFloat.vector4_f32[ElementIndex]*fScale; + if (fTemp <= 0.0f) { + uResult = 0; + } else if (fTemp >= (65536.0f*65536.0f)) { + uResult = 0xFFFFFFFFU; + } else { + uResult = (UINT)fTemp; + } + Result.vector4_u32[ElementIndex] = uResult; + } while (++ElementIndex<4); + return Result; +#else // _XM_SSE_INTRINSICS_ + XMASSERT(MulExponent<32); + XMVECTOR vResult = _mm_set_ps1(static_cast(1U << MulExponent)); + vResult = _mm_mul_ps(vResult,VFloat); + // Clamp to >=0 + vResult = _mm_max_ps(vResult,g_XMZero); + // Any numbers that are too big, set to 0xFFFFFFFFU + XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,g_XMMaxUInt); + XMVECTOR vValue = g_XMUnsignedFix; + // Too large for a signed integer? + XMVECTOR vMask = _mm_cmpge_ps(vResult,vValue); + // Zero for number's lower than 0x80000000, 32768.0f*65536.0f otherwise + vValue = _mm_and_ps(vValue,vMask); + // Perform fixup only on numbers too large (Keeps low bit precision) + vResult = _mm_sub_ps(vResult,vValue); + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Convert from signed to unsigned pnly if greater than 0x80000000 + vMask = _mm_and_ps(vMask,g_XMNegativeZero); + vResult = _mm_xor_ps(reinterpret_cast(&vResulti)[0],vMask); + // On those that are too large, set to 0xFFFFFFFF + vResult = _mm_or_ps(vResult,vOverflow); + return vResult; +#endif +} + +#pragma warning(pop) + +#endif // _XM_NO_INTRINSICS_ || _XM_SSE_INTRINSICS_ + +/**************************************************************************** + * + * Vector and matrix load operations + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt(CONST UINT* pSource) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 3) == 0); + + V.vector4_u32[0] = *pSource; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 3) == 0); + + return _mm_load_ss( (const float*)pSource ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat(CONST FLOAT* pSource) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 3) == 0); + + V.vector4_f32[0] = *pSource; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 3) == 0); + + return _mm_load_ss( pSource ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt2 +( + CONST UINT* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_u32[0] = pSource[0]; + V.vector4_u32[1] = pSource[1]; + + return V; +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pSource); + + __m128 x = _mm_load_ss( (const float*)pSource ); + __m128 y = _mm_load_ss( (const float*)(pSource+1) ); + return _mm_unpacklo_ps( x, y ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadSInt2 +( + CONST XMINT2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + V.vector4_f32[0] = (float)pSource->x; + V.vector4_f32[1] = (float)pSource->y; + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + + __m128 x = _mm_load_ss( (const float*)&pSource->x ); + __m128 y = _mm_load_ss( (const float*)&pSource->y ); + __m128 V = _mm_unpacklo_ps( x, y ); + return _mm_cvtepi32_ps(reinterpret_cast(&V)[0]); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUInt2 +( + CONST XMUINT2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + V.vector4_f32[0] = (float)pSource->x; + V.vector4_f32[1] = (float)pSource->y; + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + + __m128 x = _mm_load_ss( (const float*)&pSource->x ); + __m128 y = _mm_load_ss( (const float*)&pSource->y ); + __m128 V = _mm_unpacklo_ps( x, y ); + // For the values that are higher than 0x7FFFFFFF, a fixup is needed + // Determine which ones need the fix. + XMVECTOR vMask = _mm_and_ps(V,g_XMNegativeZero); + // Force all values positive + XMVECTOR vResult = _mm_xor_ps(V,vMask); + // Convert to floats + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert 0x80000000 -> 0xFFFFFFFF + __m128i iMask = _mm_srai_epi32(reinterpret_cast(&vMask)[0],31); + // For only the ones that are too big, add the fixup + vMask = _mm_and_ps(reinterpret_cast(&iMask)[0],g_XMFixUnsigned); + vResult = _mm_add_ps(vResult,vMask); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt2A +( + CONST UINT* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + V.vector4_u32[0] = pSource[0]; + V.vector4_u32[1] = pSource[1]; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + __m128i V = _mm_loadl_epi64( (const __m128i*)pSource ); + return reinterpret_cast<__m128 *>(&V)[0]; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat2 +( + CONST XMFLOAT2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + ((UINT *)(&V.vector4_f32[0]))[0] = ((const UINT *)(&pSource->x))[0]; + ((UINT *)(&V.vector4_f32[1]))[0] = ((const UINT *)(&pSource->y))[0]; + return V; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + + __m128 x = _mm_load_ss( &pSource->x ); + __m128 y = _mm_load_ss( &pSource->y ); + return _mm_unpacklo_ps( x, y ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat2A +( + CONST XMFLOAT2A* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + V.vector4_f32[0] = pSource->x; + V.vector4_f32[1] = pSource->y; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + __m128i V = _mm_loadl_epi64( (const __m128i*)pSource ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadHalf2 +( + CONST XMHALF2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT(pSource); + { + XMVECTOR vResult = { + XMConvertHalfToFloat(pSource->x), + XMConvertHalfToFloat(pSource->y), + 0.0f, + 0.0f + }; + return vResult; + } +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMVECTOR vResult = { + XMConvertHalfToFloat(pSource->x), + XMConvertHalfToFloat(pSource->y), + 0.0f, + 0.0f + }; + return vResult; + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadShortN2 +( + CONST XMSHORTN2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT(pSource); + { + XMVECTOR vResult = { + (pSource->x == -32768) ? -1.f : ((FLOAT)pSource->x * (1.0f/32767.0f)), + (pSource->y == -32768) ? -1.f : ((FLOAT)pSource->y * (1.0f/32767.0f)), + 0.0f, + 0.0f + }; + return vResult; + } + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the two shorts in all four entries (WORD alignment okay, + // DWORD alignment preferred) + __m128 vTemp = _mm_load_ps1(reinterpret_cast(&pSource->x)); + // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0 + vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16); + // x needs to be sign extended + vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x - 0x8000 to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16); + // Convert -1.0f - 1.0f + vTemp = _mm_mul_ps(vTemp,g_XMNormalizeX16Y16); + // Clamp result (for case of -32768) + return _mm_max_ps( vTemp, g_XMNegativeOne ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadShort2 +( + CONST XMSHORT2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x; + V.vector4_f32[1] = (FLOAT)pSource->y; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the two shorts in all four entries (WORD alignment okay, + // DWORD alignment preferred) + __m128 vTemp = _mm_load_ps1(reinterpret_cast(&pSource->x)); + // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0 + vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16); + // x needs to be sign extended + vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x - 0x8000 to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16); + // Y is 65536 too large + return _mm_mul_ps(vTemp,g_XMFixupY16); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUShortN2 +( + CONST XMUSHORTN2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x / 65535.0f; + V.vector4_f32[1] = (FLOAT)pSource->y / 65535.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 FixupY16 = {1.0f/65535.0f,1.0f/(65535.0f*65536.0f),0.0f,0.0f}; + static const XMVECTORF32 FixaddY16 = {0,32768.0f*65536.0f,0,0}; + XMASSERT(pSource); + // Splat the two shorts in all four entries (WORD alignment okay, + // DWORD alignment preferred) + __m128 vTemp = _mm_load_ps1(reinterpret_cast(&pSource->x)); + // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0 + vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16); + // y needs to be sign flipped + vTemp = _mm_xor_ps(vTemp,g_XMFlipY); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // y + 0x8000 to undo the signed order. + vTemp = _mm_add_ps(vTemp,FixaddY16); + // Y is 65536 times too large + vTemp = _mm_mul_ps(vTemp,FixupY16); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUShort2 +( + CONST XMUSHORT2* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x; + V.vector4_f32[1] = (FLOAT)pSource->y; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 FixaddY16 = {0,32768.0f,0,0}; + XMASSERT(pSource); + // Splat the two shorts in all four entries (WORD alignment okay, + // DWORD alignment preferred) + __m128 vTemp = _mm_load_ps1(reinterpret_cast(&pSource->x)); + // Mask x&0xFFFF, y&0xFFFF0000,z&0,w&0 + vTemp = _mm_and_ps(vTemp,g_XMMaskX16Y16); + // y needs to be sign flipped + vTemp = _mm_xor_ps(vTemp,g_XMFlipY); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // Y is 65536 times too large + vTemp = _mm_mul_ps(vTemp,g_XMFixupY16); + // y + 0x8000 to undo the signed order. + vTemp = _mm_add_ps(vTemp,FixaddY16); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadByteN2 +( + CONST XMBYTEN2* pSource +) +{ + XMASSERT(pSource); + { + XMVECTOR vResult = { + (pSource->x == -128) ? -1.f : ((FLOAT)pSource->x * (1.0f/127.0f)), + (pSource->y == -128) ? -1.f : ((FLOAT)pSource->y * (1.0f/127.0f)), + 0.0f, + 0.0f + }; + return vResult; + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadByte2 +( + CONST XMBYTE2* pSource +) +{ + XMASSERT(pSource); + { + XMVECTOR vResult = { + (FLOAT)pSource->x, + (FLOAT)pSource->y, + 0.0f, + 0.0f + }; + return vResult; + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUByteN2 +( + CONST XMUBYTEN2* pSource +) +{ + XMASSERT(pSource); + { + XMVECTOR vResult = { + (FLOAT)pSource->x * (1.0f/255.0f), + (FLOAT)pSource->y * (1.0f/255.0f), + 0.0f, + 0.0f + }; + return vResult; + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUByte2 +( + CONST XMUBYTE2* pSource +) +{ + XMASSERT(pSource); + { + XMVECTOR vResult = { + (FLOAT)pSource->x, + (FLOAT)pSource->y, + 0.0f, + 0.0f + }; + return vResult; + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt3 +( + CONST UINT* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_u32[0] = pSource[0]; + V.vector4_u32[1] = pSource[1]; + V.vector4_u32[2] = pSource[2]; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + +#ifdef _XM_ISVS2005_ + __m128i V = _mm_set_epi32( 0, *(pSource+2), *(pSource+1), *pSource ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else + __m128 x = _mm_load_ss( (const float*)pSource ); + __m128 y = _mm_load_ss( (const float*)(pSource+1) ); + __m128 z = _mm_load_ss( (const float*)(pSource+2) ); + __m128 xy = _mm_unpacklo_ps( x, y ); + return _mm_movelh_ps( xy, z ); +#endif // !_XM_ISVS2005_ +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadSInt3 +( + CONST XMINT3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + +#ifdef _XBOX_VER + V = XMLoadInt3( (const UINT*)pSource ); + return XMConvertVectorIntToFloat( V, 0 ); +#else + V.vector4_f32[0] = (float)pSource->x; + V.vector4_f32[1] = (float)pSource->y; + V.vector4_f32[2] = (float)pSource->z; + return V; +#endif + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + +#ifdef _XM_ISVS2005_ + __m128i V = _mm_set_epi32( 0, pSource->z, pSource->y, pSource->x ); + return _mm_cvtepi32_ps(V); +#else + __m128 x = _mm_load_ss( (const float*)&pSource->x ); + __m128 y = _mm_load_ss( (const float*)&pSource->y ); + __m128 z = _mm_load_ss( (const float*)&pSource->z ); + __m128 xy = _mm_unpacklo_ps( x, y ); + __m128 V = _mm_movelh_ps( xy, z ); + return _mm_cvtepi32_ps(reinterpret_cast(&V)[0]); +#endif // !_XM_ISVS2005_ +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUInt3 +( + CONST XMUINT3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + V.vector4_f32[0] = (float)pSource->x; + V.vector4_f32[1] = (float)pSource->y; + V.vector4_f32[2] = (float)pSource->z; + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + +#ifdef _XM_ISVS2005_ + __m128i V = _mm_set_epi32( 0, pSource->z, pSource->y, pSource->x ); + // For the values that are higher than 0x7FFFFFFF, a fixup is needed + // Determine which ones need the fix. + XMVECTOR vMask = _mm_and_ps(reinterpret_cast(&V)[0],g_XMNegativeZero); + // Force all values positive + XMVECTOR vResult = _mm_xor_ps(reinterpret_cast(&V)[0],vMask); +#else + __m128 x = _mm_load_ss( (const float*)&pSource->x ); + __m128 y = _mm_load_ss( (const float*)&pSource->y ); + __m128 z = _mm_load_ss( (const float*)&pSource->z ); + __m128 xy = _mm_unpacklo_ps( x, y ); + __m128 V = _mm_movelh_ps( xy, z ); + // For the values that are higher than 0x7FFFFFFF, a fixup is needed + // Determine which ones need the fix. + XMVECTOR vMask = _mm_and_ps(V,g_XMNegativeZero); + // Force all values positive + XMVECTOR vResult = _mm_xor_ps(V,vMask); +#endif // !_XM_ISVS2005_ + // Convert to floats + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert 0x80000000 -> 0xFFFFFFFF + __m128i iMask = _mm_srai_epi32(reinterpret_cast(&vMask)[0],31); + // For only the ones that are too big, add the fixup + vMask = _mm_and_ps(reinterpret_cast(&iMask)[0],g_XMFixUnsigned); + vResult = _mm_add_ps(vResult,vMask); + return vResult; + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt3A +( + CONST UINT* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + V.vector4_u32[0] = pSource[0]; + V.vector4_u32[1] = pSource[1]; + V.vector4_u32[2] = pSource[2]; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + + // Reads an extra integer that is 'undefined' + + __m128i V = _mm_load_si128( (const __m128i*)pSource ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat3 +( + CONST XMFLOAT3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + ((UINT *)(&V.vector4_f32[0]))[0] = ((const UINT *)(&pSource->x))[0]; + ((UINT *)(&V.vector4_f32[1]))[0] = ((const UINT *)(&pSource->y))[0]; + ((UINT *)(&V.vector4_f32[2]))[0] = ((const UINT *)(&pSource->z))[0]; + return V; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + +#ifdef _XM_ISVS2005_ + // This reads 1 floats past the memory that should be ignored. + // Need to continue to do this for VS 2005 due to compiler issue but prefer new method + // to avoid triggering issues with memory debug tools (like AV) + return _mm_loadu_ps( &pSource->x ); +#else + __m128 x = _mm_load_ss( &pSource->x ); + __m128 y = _mm_load_ss( &pSource->y ); + __m128 z = _mm_load_ss( &pSource->z ); + __m128 xy = _mm_unpacklo_ps( x, y ); + return _mm_movelh_ps( xy, z ); +#endif // !_XM_ISVS2005_ +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat3A +( + CONST XMFLOAT3A* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + V.vector4_f32[0] = pSource->x; + V.vector4_f32[1] = pSource->y; + V.vector4_f32[2] = pSource->z; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + // This reads 1 floats past the memory that should be ignored. + return _mm_load_ps( &pSource->x ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUHenDN3 +( + CONST XMUHENDN3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x7FF; + V.vector4_f32[0] = (FLOAT)Element / 2047.0f; + Element = (pSource->v >> 11) & 0x7FF; + V.vector4_f32[1] = (FLOAT)Element / 2047.0f; + Element = (pSource->v >> 22) & 0x3FF; + V.vector4_f32[2] = (FLOAT)Element / 1023.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 UHenDN3Mul = {1.0f/2047.0f,1.0f/(2047.0f*2048.0f),1.0f/(1023.0f*2048.0f*2048.0f),0}; + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskHenD3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMFlipZ); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddUHenD3); + // Normalize x,y and z to -1.0f-1.0f + vResult = _mm_mul_ps(vResult,UHenDN3Mul); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUHenD3 +( + CONST XMUHEND3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x7FF; + V.vector4_f32[0] = (FLOAT)Element; + Element = (pSource->v >> 11) & 0x7FF; + V.vector4_f32[1] = (FLOAT)Element; + Element = (pSource->v >> 22) & 0x3FF; + V.vector4_f32[2] = (FLOAT)Element; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskHenD3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMFlipZ); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddUHenD3); + // Normalize x and y to -1024-1023.0f and z to -512-511.0f + vResult = _mm_mul_ps(vResult,g_XMMulHenD3); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadHenDN3 +( + CONST XMHENDN3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtendXY[] = {0x00000000, 0xFFFFF800}; + static CONST UINT SignExtendZ[] = {0x00000000, 0xFFFFFC00}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200); + + Element = pSource->v & 0x7FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]) / 1023.0f; + Element = (pSource->v >> 11) & 0x7FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]) / 1023.0f; + Element = (pSource->v >> 22) & 0x3FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendZ[Element >> 9]) / 511.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 HenDN3Mul = {1.0f/1023.0f,1.0f/(1023.0f*2048.0f),1.0f/(511.0f*2048.0f*2048.0f),0}; + XMASSERT(pSource); + XMASSERT((pSource->v & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskHenD3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMXorHenD3); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddHenD3); + // Normalize x,y and z to -1.0f-1.0f + vResult = _mm_mul_ps(vResult,HenDN3Mul); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadHenD3 +( + CONST XMHEND3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtendXY[] = {0x00000000, 0xFFFFF800}; + static CONST UINT SignExtendZ[] = {0x00000000, 0xFFFFFC00}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200); + + Element = pSource->v & 0x7FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]); + Element = (pSource->v >> 11) & 0x7FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendXY[Element >> 10]); + Element = (pSource->v >> 22) & 0x3FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendZ[Element >> 9]); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT((pSource->v & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 11) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 22) & 0x3FF) != 0x200); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskHenD3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMXorHenD3); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddHenD3); + // Normalize x and y to -1024-1023.0f and z to -512-511.0f + vResult = _mm_mul_ps(vResult,g_XMMulHenD3); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUDHenN3 +( + CONST XMUDHENN3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)Element / 1023.0f; + Element = (pSource->v >> 10) & 0x7FF; + V.vector4_f32[1] = (FLOAT)Element / 2047.0f; + Element = (pSource->v >> 21) & 0x7FF; + V.vector4_f32[2] = (FLOAT)Element / 2047.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 UDHenN3Mul = {1.0f/1023.0f,1.0f/(2047.0f*1024.0f),1.0f/(2047.0f*1024.0f*2048.0f),0}; + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskDHen3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMFlipZ); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddUHenD3); + // Normalize x,y and z to -1.0f-1.0f + vResult = _mm_mul_ps(vResult,UDHenN3Mul); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUDHen3 +( + CONST XMUDHEN3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)Element; + Element = (pSource->v >> 10) & 0x7FF; + V.vector4_f32[1] = (FLOAT)Element; + Element = (pSource->v >> 21) & 0x7FF; + V.vector4_f32[2] = (FLOAT)Element; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskDHen3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMFlipZ); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddUHenD3); + // Normalize x to 0-1023.0f and y and z to 0-2047.0f + vResult = _mm_mul_ps(vResult,g_XMMulDHen3); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadDHenN3 +( + CONST XMDHENN3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtendX[] = {0x00000000, 0xFFFFFC00}; + static CONST UINT SignExtendYZ[] = {0x00000000, 0xFFFFF800}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendX[Element >> 9]) / 511.0f; + Element = (pSource->v >> 10) & 0x7FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]) / 1023.0f; + Element = (pSource->v >> 21) & 0x7FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]) / 1023.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 DHenN3Mul = {1.0f/511.0f,1.0f/(1023.0f*1024.0f),1.0f/(1023.0f*1024.0f*2048.0f),0}; + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskDHen3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMXorDHen3); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddDHen3); + // Normalize x,y and z to -1.0f-1.0f + vResult = _mm_mul_ps(vResult,DHenN3Mul); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadDHen3 +( + CONST XMDHEN3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtendX[] = {0x00000000, 0xFFFFFC00}; + static CONST UINT SignExtendYZ[] = {0x00000000, 0xFFFFF800}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtendX[Element >> 9]); + Element = (pSource->v >> 10) & 0x7FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]); + Element = (pSource->v >> 21) & 0x7FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtendYZ[Element >> 10]); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x7FF) != 0x400); + XMASSERT(((pSource->v >> 21) & 0x7FF) != 0x400); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,g_XMMaskDHen3); + // Convert x and y to unsigned + vResult = _mm_xor_ps(vResult,g_XMXorDHen3); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert x and y back to signed + vResult = _mm_add_ps(vResult,g_XMAddDHen3); + // Normalize x to -210-511.0f and y and z to -1024-1023.0f + vResult = _mm_mul_ps(vResult,g_XMMulDHen3); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadU565 +( + CONST XMU565* pSource +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + static const XMVECTORI32 U565And = {0x1F,0x3F<<5,0x1F<<11,0}; + static const XMVECTORF32 U565Mul = {1.0f,1.0f/32.0f,1.0f/2048.f,0}; + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,U565And); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Normalize x, y, and z + vResult = _mm_mul_ps(vResult,U565Mul); + return vResult; +#else + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x1F; + V.vector4_f32[0] = (FLOAT)Element; + Element = (pSource->v >> 5) & 0x3F; + V.vector4_f32[1] = (FLOAT)Element; + Element = (pSource->v >> 11) & 0x1F; + V.vector4_f32[2] = (FLOAT)Element; + + return V; +#endif // !_XM_SSE_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat3PK +( + CONST XMFLOAT3PK* pSource +) +{ + _DECLSPEC_ALIGN_16_ UINT Result[4]; + UINT Mantissa; + UINT Exponent; + + XMASSERT(pSource); + + // X Channel (6-bit mantissa) + Mantissa = pSource->xm; + + if ( pSource->xe == 0x1f ) // INF or NAN + { + Result[0] = 0x7f800000 | (pSource->xm << 17); + } + else + { + if ( pSource->xe != 0 ) // The value is normalized + { + Exponent = pSource->xe; + } + else if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x40) == 0); + + Mantissa &= 0x3F; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result[0] = ((Exponent + 112) << 23) | (Mantissa << 17); + } + + // Y Channel (6-bit mantissa) + Mantissa = pSource->ym; + + if ( pSource->ye == 0x1f ) // INF or NAN + { + Result[1] = 0x7f800000 | (pSource->ym << 17); + } + else + { + if ( pSource->ye != 0 ) // The value is normalized + { + Exponent = pSource->ye; + } + else if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x40) == 0); + + Mantissa &= 0x3F; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result[1] = ((Exponent + 112) << 23) | (Mantissa << 17); + } + + // Z Channel (5-bit mantissa) + Mantissa = pSource->zm; + + if ( pSource->ze == 0x1f ) // INF or NAN + { + Result[2] = 0x7f800000 | (pSource->zm << 17); + } + else + { + if ( pSource->ze != 0 ) // The value is normalized + { + Exponent = pSource->ze; + } + else if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x20) == 0); + + Mantissa &= 0x1F; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result[2] = ((Exponent + 112) << 23) | (Mantissa << 18); + } + + return XMLoadFloat3A( (const XMFLOAT3A*)&Result ); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat3SE +( + CONST XMFLOAT3SE* pSource +) +{ + _DECLSPEC_ALIGN_16_ UINT Result[4]; + UINT Mantissa; + UINT Exponent, ExpBits; + + XMASSERT(pSource); + + if ( pSource->e == 0x1f ) // INF or NAN + { + Result[0] = 0x7f800000 | (pSource->xm << 14); + Result[1] = 0x7f800000 | (pSource->ym << 14); + Result[2] = 0x7f800000 | (pSource->zm << 14); + } + else if ( pSource->e != 0 ) // The values are all normalized + { + Exponent = pSource->e; + + ExpBits = (Exponent + 112) << 23; + + Mantissa = pSource->xm; + Result[0] = ExpBits | (Mantissa << 14); + + Mantissa = pSource->ym; + Result[1] = ExpBits | (Mantissa << 14); + + Mantissa = pSource->zm; + Result[2] = ExpBits | (Mantissa << 14); + } + else + { + // X Channel + Mantissa = pSource->xm; + + if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x200) == 0); + + Mantissa &= 0x1FF; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result[0] = ((Exponent + 112) << 23) | (Mantissa << 14); + + // Y Channel + Mantissa = pSource->ym; + + if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x200) == 0); + + Mantissa &= 0x1FF; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result[1] = ((Exponent + 112) << 23) | (Mantissa << 14); + + // Z Channel + Mantissa = pSource->zm; + + if (Mantissa != 0) // The value is denormalized + { + // Normalize the value in the resulting float + Exponent = 1; + + do + { + Exponent--; + Mantissa <<= 1; + } while ((Mantissa & 0x200) == 0); + + Mantissa &= 0x1FF; + } + else // The value is zero + { + Exponent = (UINT)-112; + } + + Result[2] = ((Exponent + 112) << 23) | (Mantissa << 14); + } + + return XMLoadFloat3A( (const XMFLOAT3A*)&Result ); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt4 +( + CONST UINT* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_u32[0] = pSource[0]; + V.vector4_u32[1] = pSource[1]; + V.vector4_u32[2] = pSource[2]; + V.vector4_u32[3] = pSource[3]; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pSource); + + __m128i V = _mm_loadu_si128( (const __m128i*)pSource ); + return reinterpret_cast<__m128 *>(&V)[0]; + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadSInt4 +( + CONST XMINT4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + +#ifdef _XBOX_VER + V = XMLoadInt4( (const UINT*)pSource ); + return XMConvertVectorIntToFloat( V, 0 ); +#else + V.vector4_f32[0] = (float)pSource->x; + V.vector4_f32[1] = (float)pSource->y; + V.vector4_f32[2] = (float)pSource->z; + V.vector4_f32[3] = (float)pSource->w; + return V; +#endif + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + __m128i V = _mm_loadu_si128( (const __m128i*)pSource ); + return _mm_cvtepi32_ps(V); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUInt4 +( + CONST XMUINT4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + V.vector4_f32[0] = (float)pSource->x; + V.vector4_f32[1] = (float)pSource->y; + V.vector4_f32[2] = (float)pSource->z; + V.vector4_f32[3] = (float)pSource->w; + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + __m128i V = _mm_loadu_si128( (const __m128i*)pSource ); + // For the values that are higher than 0x7FFFFFFF, a fixup is needed + // Determine which ones need the fix. + XMVECTOR vMask = _mm_and_ps(reinterpret_cast(&V)[0],g_XMNegativeZero); + // Force all values positive + XMVECTOR vResult = _mm_xor_ps(reinterpret_cast(&V)[0],vMask); + // Convert to floats + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Convert 0x80000000 -> 0xFFFFFFFF + __m128i iMask = _mm_srai_epi32(reinterpret_cast(&vMask)[0],31); + // For only the ones that are too big, add the fixup + vMask = _mm_and_ps(reinterpret_cast(&iMask)[0],g_XMFixUnsigned); + vResult = _mm_add_ps(vResult,vMask); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadInt4A +( + CONST UINT* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + V.vector4_u32[0] = pSource[0]; + V.vector4_u32[1] = pSource[1]; + V.vector4_u32[2] = pSource[2]; + V.vector4_u32[3] = pSource[3]; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + __m128i V = _mm_load_si128( (const __m128i*)pSource ); + return reinterpret_cast<__m128 *>(&V)[0]; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat4 +( + CONST XMFLOAT4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + XMASSERT(pSource); + + ((UINT *)(&V.vector4_f32[0]))[0] = ((const UINT *)(&pSource->x))[0]; + ((UINT *)(&V.vector4_f32[1]))[0] = ((const UINT *)(&pSource->y))[0]; + ((UINT *)(&V.vector4_f32[2]))[0] = ((const UINT *)(&pSource->z))[0]; + ((UINT *)(&V.vector4_f32[3]))[0] = ((const UINT *)(&pSource->w))[0]; + return V; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + + return _mm_loadu_ps( &pSource->x ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadFloat4A +( + CONST XMFLOAT4A* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + V.vector4_f32[0] = pSource->x; + V.vector4_f32[1] = pSource->y; + V.vector4_f32[2] = pSource->z; + V.vector4_f32[3] = pSource->w; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + return _mm_load_ps( &pSource->x ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadHalf4 +( + CONST XMHALF4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT(pSource); + { + XMVECTOR vResult = { + XMConvertHalfToFloat(pSource->x), + XMConvertHalfToFloat(pSource->y), + XMConvertHalfToFloat(pSource->z), + XMConvertHalfToFloat(pSource->w) + }; + return vResult; + } +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMVECTOR vResult = { + XMConvertHalfToFloat(pSource->x), + XMConvertHalfToFloat(pSource->y), + XMConvertHalfToFloat(pSource->z), + XMConvertHalfToFloat(pSource->w) + }; + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadShortN4 +( + CONST XMSHORTN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT(pSource); + { + XMVECTOR vResult = { + (pSource->x == -32768) ? -1.f : ((FLOAT)pSource->x * (1.0f/32767.0f)), + (pSource->y == -32768) ? -1.f : ((FLOAT)pSource->y * (1.0f/32767.0f)), + (pSource->z == -32768) ? -1.f : ((FLOAT)pSource->z * (1.0f/32767.0f)), + (pSource->w == -32768) ? -1.f : ((FLOAT)pSource->w * (1.0f/32767.0f)) + }; + return vResult; + } +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + __m128d vIntd = _mm_load1_pd(reinterpret_cast(&pSource->x)); + // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000 + __m128 vTemp = _mm_and_ps(reinterpret_cast(&vIntd)[0],g_XMMaskX16Y16Z16W16); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16Z16W16); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x8000 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16Z16W16); + // Convert to -1.0f - 1.0f + vTemp = _mm_mul_ps(vTemp,g_XMNormalizeX16Y16Z16W16); + // Very important! The entries are x,z,y,w, flip it to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0)); + // Clamp result (for case of -32768) + return _mm_max_ps( vTemp, g_XMNegativeOne ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadShort4 +( + CONST XMSHORT4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x; + V.vector4_f32[1] = (FLOAT)pSource->y; + V.vector4_f32[2] = (FLOAT)pSource->z; + V.vector4_f32[3] = (FLOAT)pSource->w; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + __m128d vIntd = _mm_load1_pd(reinterpret_cast(&pSource->x)); + // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000 + __m128 vTemp = _mm_and_ps(reinterpret_cast(&vIntd)[0],g_XMMaskX16Y16Z16W16); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipX16Y16Z16W16); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x8000 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMFixX16Y16Z16W16); + // Fix y and w because they are 65536 too large + vTemp = _mm_mul_ps(vTemp,g_XMFixupY16W16); + // Very important! The entries are x,z,y,w, flip it to x,y,z,w + return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0)); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUShortN4 +( + CONST XMUSHORTN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x / 65535.0f; + V.vector4_f32[1] = (FLOAT)pSource->y / 65535.0f; + V.vector4_f32[2] = (FLOAT)pSource->z / 65535.0f; + V.vector4_f32[3] = (FLOAT)pSource->w / 65535.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + static const XMVECTORF32 FixupY16W16 = {1.0f/65535.0f,1.0f/65535.0f,1.0f/(65535.0f*65536.0f),1.0f/(65535.0f*65536.0f)}; + static const XMVECTORF32 FixaddY16W16 = {0,0,32768.0f*65536.0f,32768.0f*65536.0f}; + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + __m128d vIntd = _mm_load1_pd(reinterpret_cast(&pSource->x)); + // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000 + __m128 vTemp = _mm_and_ps(reinterpret_cast(&vIntd)[0],g_XMMaskX16Y16Z16W16); + // y and w are signed! Flip the bits to convert the order to unsigned + vTemp = _mm_xor_ps(vTemp,g_XMFlipZW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // y and w + 0x8000 to complete the conversion + vTemp = _mm_add_ps(vTemp,FixaddY16W16); + // Fix y and w because they are 65536 too large + vTemp = _mm_mul_ps(vTemp,FixupY16W16); + // Very important! The entries are x,z,y,w, flip it to x,y,z,w + return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0)); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUShort4 +( + CONST XMUSHORT4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x; + V.vector4_f32[1] = (FLOAT)pSource->y; + V.vector4_f32[2] = (FLOAT)pSource->z; + V.vector4_f32[3] = (FLOAT)pSource->w; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + static const XMVECTORF32 FixaddY16W16 = {0,0,32768.0f,32768.0f}; + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + __m128d vIntd = _mm_load1_pd(reinterpret_cast(&pSource->x)); + // Shift x&0ffff,z&0xffff,y&0xffff0000,w&0xffff0000 + __m128 vTemp = _mm_and_ps(reinterpret_cast(&vIntd)[0],g_XMMaskX16Y16Z16W16); + // y and w are signed! Flip the bits to convert the order to unsigned + vTemp = _mm_xor_ps(vTemp,g_XMFlipZW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // Fix y and w because they are 65536 too large + vTemp = _mm_mul_ps(vTemp,g_XMFixupY16W16); + // y and w + 0x8000 to complete the conversion + vTemp = _mm_add_ps(vTemp,FixaddY16W16); + // Very important! The entries are x,z,y,w, flip it to x,y,z,w + return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(3,1,2,0)); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadXIcoN4 +( + CONST XMXICON4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull); + + Element = (UINT)(pSource->v & 0xFFFFF); + V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f; + Element = (UINT)((pSource->v >> 20) & 0xFFFFF); + V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f; + Element = (UINT)((pSource->v >> 40) & 0xFFFFF); + V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f; + V.vector4_f32[3] = (FLOAT)(pSource->v >> 60) / 15.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull); + static const XMVECTORF32 LoadXIcoN4Mul = {1.0f/524287.0f,1.0f/(524287.0f*4096.0f),1.0f/524287.0f,1.0f/(15.0f*4096.0f*65536.0f)}; + XMASSERT(pSource); + // Grab the 64 bit structure + __m128d vResultd = _mm_load_sd(reinterpret_cast(&pSource->v)); + // By shifting down 8 bits, y and z are in seperate 32 bit elements + __m128i vResulti = _mm_srli_si128(reinterpret_cast(&vResultd)[0],8/8); + // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z + XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast(&vResultd)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(1,0,1,0)); + // Fix the entries to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0)); + // Mask x,y,z and w + vTemp = _mm_and_ps(vTemp,g_XMMaskIco4); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorXIco4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddXIco4); + // Fix y and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadXIcoN4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadXIco4 +( + CONST XMXICO4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull); + + Element = (UINT)(pSource->v & 0xFFFFF); + V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]); + Element = (UINT)((pSource->v >> 20) & 0xFFFFF); + V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]); + Element = (UINT)((pSource->v >> 40) & 0xFFFFF); + V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]); + V.vector4_f32[3] = (FLOAT)(pSource->v >> 60); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT((pSource->v & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 20) & 0xFFFFFull) != 0x80000ull); + XMASSERT(((pSource->v >> 40) & 0xFFFFFull) != 0x80000ull); + XMASSERT(pSource); + // Grab the 64 bit structure + __m128d vResultd = _mm_load_sd(reinterpret_cast(&pSource->v)); + // By shifting down 8 bits, y and z are in seperate 32 bit elements + __m128i vResulti = _mm_srli_si128(reinterpret_cast(&vResultd)[0],8/8); + // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z + XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast(&vResultd)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(1,0,1,0)); + // Fix the entries to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0)); + // Mask x,y,z and w + vTemp = _mm_and_ps(vTemp,g_XMMaskIco4); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorXIco4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddXIco4); + // Fix y and w because they are too large + vTemp = _mm_mul_ps(vTemp,g_XMMulIco4); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUIcoN4 +( + CONST XMUICON4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)(pSource->v & 0xFFFFF) / 1048575.0f; + V.vector4_f32[1] = (FLOAT)((pSource->v >> 20) & 0xFFFFF) / 1048575.0f; + V.vector4_f32[2] = (FLOAT)((pSource->v >> 40) & 0xFFFFF) / 1048575.0f; + V.vector4_f32[3] = (FLOAT)(pSource->v >> 60) / 15.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 LoadUIcoN4Mul = {1.0f/1048575.0f,1.0f/(1048575.0f*4096.0f),1.0f/1048575.0f,1.0f/(15.0f*4096.0f*65536.0f)}; + XMASSERT(pSource); + // Grab the 64 bit structure + __m128d vResultd = _mm_load_sd(reinterpret_cast(&pSource->v)); + // By shifting down 8 bits, y and z are in seperate 32 bit elements + __m128i vResulti = _mm_srli_si128(reinterpret_cast(&vResultd)[0],8/8); + // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z + XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast(&vResultd)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(1,0,1,0)); + // Fix the entries to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0)); + // Mask x,y,z and w + vTemp = _mm_and_ps(vTemp,g_XMMaskIco4); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipYW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddUIco4); + // Fix y and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadUIcoN4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUIco4 +( + CONST XMUICO4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)(pSource->v & 0xFFFFF); + V.vector4_f32[1] = (FLOAT)((pSource->v >> 20) & 0xFFFFF); + V.vector4_f32[2] = (FLOAT)((pSource->v >> 40) & 0xFFFFF); + V.vector4_f32[3] = (FLOAT)(pSource->v >> 60); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Grab the 64 bit structure + __m128d vResultd = _mm_load_sd(reinterpret_cast(&pSource->v)); + // By shifting down 8 bits, y and z are in seperate 32 bit elements + __m128i vResulti = _mm_srli_si128(reinterpret_cast(&vResultd)[0],8/8); + // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z + XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast(&vResultd)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(1,0,1,0)); + // Fix the entries to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0)); + // Mask x,y,z and w + vTemp = _mm_and_ps(vTemp,g_XMMaskIco4); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipYW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddUIco4); + // Fix y and w because they are too large + vTemp = _mm_mul_ps(vTemp,g_XMMulIco4); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadIcoN4 +( + CONST XMICON4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000}; + static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFF0}; + + XMASSERT(pSource); + + Element = (UINT)(pSource->v & 0xFFFFF); + V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f; + Element = (UINT)((pSource->v >> 20) & 0xFFFFF); + V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f; + Element = (UINT)((pSource->v >> 40) & 0xFFFFF); + V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]) / 524287.0f; + Element = (UINT)(pSource->v >> 60); + V.vector4_f32[3] = (FLOAT)(INT)(Element | SignExtendW[Element >> 3]) / 7.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 LoadIcoN4Mul = {1.0f/524287.0f,1.0f/(524287.0f*4096.0f),1.0f/524287.0f,1.0f/(7.0f*4096.0f*65536.0f)}; + XMASSERT(pSource); + // Grab the 64 bit structure + __m128d vResultd = _mm_load_sd(reinterpret_cast(&pSource->v)); + // By shifting down 8 bits, y and z are in seperate 32 bit elements + __m128i vResulti = _mm_srli_si128(reinterpret_cast(&vResultd)[0],8/8); + // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z + XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast(&vResultd)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(1,0,1,0)); + // Fix the entries to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0)); + // Mask x,y,z and w + vTemp = _mm_and_ps(vTemp,g_XMMaskIco4); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorIco4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddIco4); + // Fix y and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadIcoN4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadIco4 +( + CONST XMICO4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFF00000}; + static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFF0}; + + XMASSERT(pSource); + + Element = (UINT)(pSource->v & 0xFFFFF); + V.vector4_f32[0] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]); + Element = (UINT)((pSource->v >> 20) & 0xFFFFF); + V.vector4_f32[1] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]); + Element = (UINT)((pSource->v >> 40) & 0xFFFFF); + V.vector4_f32[2] = (FLOAT)(INT)(Element | SignExtend[Element >> 19]); + Element = (UINT)(pSource->v >> 60); + V.vector4_f32[3] = (FLOAT)(INT)(Element | SignExtendW[Element >> 3]); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Grab the 64 bit structure + __m128d vResultd = _mm_load_sd(reinterpret_cast(&pSource->v)); + // By shifting down 8 bits, y and z are in seperate 32 bit elements + __m128i vResulti = _mm_srli_si128(reinterpret_cast(&vResultd)[0],8/8); + // vResultd has x and w, vResulti has y and z, merge into one as x,w,y,z + XMVECTOR vTemp = _mm_shuffle_ps(reinterpret_cast(&vResultd)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(1,0,1,0)); + // Fix the entries to x,y,z,w + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,3,2,0)); + // Mask x,y,z and w + vTemp = _mm_and_ps(vTemp,g_XMMaskIco4); + // x and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorIco4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddIco4); + // Fix y and w because they are too large + vTemp = _mm_mul_ps(vTemp,g_XMMulIco4); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadXDecN4 +( + CONST XMXDECN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f; + Element = (pSource->v >> 10) & 0x3FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f; + Element = (pSource->v >> 20) & 0x3FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f; + V.vector4_f32[3] = (FLOAT)(pSource->v >> 30) / 3.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the color in all four entries + __m128 vTemp = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskA2B10G10R10); + // a is unsigned! Flip the bit to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipA2B10G10R10); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMFixAA2B10G10R10); + // Convert 0-255 to 0.0f-1.0f + return _mm_mul_ps(vTemp,g_XMNormalizeA2B10G10R10); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadXDec4 +( + CONST XMXDEC4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]); + Element = (pSource->v >> 10) & 0x3FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]); + Element = (pSource->v >> 20) & 0x3FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]); + V.vector4_f32[3] = (FLOAT)(pSource->v >> 30); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + static const XMVECTORI32 XDec4Xor = {0x200, 0x200<<10, 0x200<<20, 0x80000000}; + static const XMVECTORF32 XDec4Add = {-512.0f,-512.0f*1024.0f,-512.0f*1024.0f*1024.0f,32768*65536.0f}; + XMASSERT(pSource); + // Splat the color in all four entries + XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskDec4); + // a is unsigned! Flip the bit to convert the order to signed + vTemp = _mm_xor_ps(vTemp,XDec4Xor); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,XDec4Add); + // Convert 0-255 to 0.0f-1.0f + vTemp = _mm_mul_ps(vTemp,g_XMMulDec4); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUDecN4 +( + CONST XMUDECN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)Element / 1023.0f; + Element = (pSource->v >> 10) & 0x3FF; + V.vector4_f32[1] = (FLOAT)Element / 1023.0f; + Element = (pSource->v >> 20) & 0x3FF; + V.vector4_f32[2] = (FLOAT)Element / 1023.0f; + V.vector4_f32[3] = (FLOAT)(pSource->v >> 30) / 3.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + static const XMVECTORF32 UDecN4Mul = {1.0f/1023.0f,1.0f/(1023.0f*1024.0f),1.0f/(1023.0f*1024.0f*1024.0f),1.0f/(3.0f*1024.0f*1024.0f*1024.0f)}; + // Splat the color in all four entries + XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskDec4); + // a is unsigned! Flip the bit to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMAddUDec4); + // Convert 0-255 to 0.0f-1.0f + vTemp = _mm_mul_ps(vTemp,UDecN4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUDec4 +( + CONST XMUDEC4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)Element; + Element = (pSource->v >> 10) & 0x3FF; + V.vector4_f32[1] = (FLOAT)Element; + Element = (pSource->v >> 20) & 0x3FF; + V.vector4_f32[2] = (FLOAT)Element; + V.vector4_f32[3] = (FLOAT)(pSource->v >> 30); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the color in all four entries + XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskDec4); + // a is unsigned! Flip the bit to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMFlipW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMAddUDec4); + // Convert 0-255 to 0.0f-1.0f + vTemp = _mm_mul_ps(vTemp,g_XMMulDec4); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadDecN4 +( + CONST XMDECN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00}; + static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFFC}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 30) & 0x3) != 0x2); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f; + Element = (pSource->v >> 10) & 0x3FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f; + Element = (pSource->v >> 20) & 0x3FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]) / 511.0f; + Element = pSource->v >> 30; + V.vector4_f32[3] = (FLOAT)(SHORT)(Element | SignExtendW[Element >> 1]); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 30) & 0x3) != 0x2); + static const XMVECTORF32 DecN4Mul = {1.0f/511.0f,1.0f/(511.0f*1024.0f),1.0f/(511.0f*1024.0f*1024.0f),1.0f/(1024.0f*1024.0f*1024.0f)}; + // Splat the color in all four entries + XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskDec4); + // a is unsigned! Flip the bit to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorDec4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMAddDec4); + // Convert 0-255 to 0.0f-1.0f + vTemp = _mm_mul_ps(vTemp,DecN4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadDec4 +( + CONST XMDEC4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + UINT Element; + static CONST UINT SignExtend[] = {0x00000000, 0xFFFFFC00}; + static CONST UINT SignExtendW[] = {0x00000000, 0xFFFFFFFC}; + + XMASSERT(pSource); + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 30) & 0x3) != 0x2); + + Element = pSource->v & 0x3FF; + V.vector4_f32[0] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]); + Element = (pSource->v >> 10) & 0x3FF; + V.vector4_f32[1] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]); + Element = (pSource->v >> 20) & 0x3FF; + V.vector4_f32[2] = (FLOAT)(SHORT)(Element | SignExtend[Element >> 9]); + Element = pSource->v >> 30; + V.vector4_f32[3] = (FLOAT)(SHORT)(Element | SignExtendW[Element >> 1]); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT((pSource->v & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 10) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 20) & 0x3FF) != 0x200); + XMASSERT(((pSource->v >> 30) & 0x3) != 0x2); + XMASSERT(pSource); + // Splat the color in all four entries + XMVECTOR vTemp = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskDec4); + // a is unsigned! Flip the bit to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorDec4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMAddDec4); + // Convert 0-255 to 0.0f-1.0f + vTemp = _mm_mul_ps(vTemp,g_XMMulDec4); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUByteN4 +( + CONST XMUBYTEN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x / 255.0f; + V.vector4_f32[1] = (FLOAT)pSource->y / 255.0f; + V.vector4_f32[2] = (FLOAT)pSource->z / 255.0f; + V.vector4_f32[3] = (FLOAT)pSource->w / 255.0f; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 LoadUByteN4Mul = {1.0f/255.0f,1.0f/(255.0f*256.0f),1.0f/(255.0f*65536.0f),1.0f/(255.0f*65536.0f*256.0f)}; + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast(&pSource->x)); + // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskByte4); + // w is signed! Flip the bits to convert the order to unsigned + vTemp = _mm_xor_ps(vTemp,g_XMFlipW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // w + 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddUDec4); + // Fix y, z and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadUByteN4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUByte4 +( + CONST XMUBYTE4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x; + V.vector4_f32[1] = (FLOAT)pSource->y; + V.vector4_f32[2] = (FLOAT)pSource->z; + V.vector4_f32[3] = (FLOAT)pSource->w; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 LoadUByte4Mul = {1.0f,1.0f/256.0f,1.0f/65536.0f,1.0f/(65536.0f*256.0f)}; + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast(&pSource->x)); + // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskByte4); + // w is signed! Flip the bits to convert the order to unsigned + vTemp = _mm_xor_ps(vTemp,g_XMFlipW); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // w + 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddUDec4); + // Fix y, z and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadUByte4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadByteN4 +( + CONST XMBYTEN4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (pSource->x == -128) ? -1.f : ((FLOAT)pSource->x / 127.0f); + V.vector4_f32[1] = (pSource->y == -128) ? -1.f : ((FLOAT)pSource->y / 127.0f); + V.vector4_f32[2] = (pSource->z == -128) ? -1.f : ((FLOAT)pSource->z / 127.0f); + V.vector4_f32[3] = (pSource->w == -128) ? -1.f : ((FLOAT)pSource->w / 127.0f); + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 LoadByteN4Mul = {1.0f/127.0f,1.0f/(127.0f*256.0f),1.0f/(127.0f*65536.0f),1.0f/(127.0f*65536.0f*256.0f)}; + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast(&pSource->x)); + // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskByte4); + // x,y and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorByte4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x, y and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddByte4); + // Fix y, z and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadByteN4Mul); + // Clamp result (for case of -128) + return _mm_max_ps( vTemp, g_XMNegativeOne ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadByte4 +( + CONST XMBYTE4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + + XMASSERT(pSource); + + V.vector4_f32[0] = (FLOAT)pSource->x; + V.vector4_f32[1] = (FLOAT)pSource->y; + V.vector4_f32[2] = (FLOAT)pSource->z; + V.vector4_f32[3] = (FLOAT)pSource->w; + + return V; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 LoadByte4Mul = {1.0f,1.0f/256.0f,1.0f/65536.0f,1.0f/(65536.0f*256.0f)}; + XMASSERT(pSource); + // Splat the color in all four entries (x,z,y,w) + XMVECTOR vTemp = _mm_load1_ps(reinterpret_cast(&pSource->x)); + // Mask x&0ff,y&0xff00,z&0xff0000,w&0xff000000 + vTemp = _mm_and_ps(vTemp,g_XMMaskByte4); + // x,y and z are unsigned! Flip the bits to convert the order to signed + vTemp = _mm_xor_ps(vTemp,g_XMXorByte4); + // Convert to floating point numbers + vTemp = _mm_cvtepi32_ps(reinterpret_cast(&vTemp)[0]); + // x, y and z - 0x80 to complete the conversion + vTemp = _mm_add_ps(vTemp,g_XMAddByte4); + // Fix y, z and w because they are too large + vTemp = _mm_mul_ps(vTemp,LoadByte4Mul); + return vTemp; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadUNibble4 +( + CONST XMUNIBBLE4* pSource +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + static const XMVECTORI32 UNibble4And = {0xF,0xF0,0xF00,0xF000}; + static const XMVECTORF32 UNibble4Mul = {1.0f,1.0f/16.f,1.0f/256.f,1.0f/4096.f}; + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,UNibble4And); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Normalize x, y, and z + vResult = _mm_mul_ps(vResult,UNibble4Mul); + return vResult; +#else + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0xF; + V.vector4_f32[0] = (FLOAT)Element; + Element = (pSource->v >> 4) & 0xF; + V.vector4_f32[1] = (FLOAT)Element; + Element = (pSource->v >> 8) & 0xF; + V.vector4_f32[2] = (FLOAT)Element; + Element = (pSource->v >> 12) & 0xF; + V.vector4_f32[3] = (FLOAT)Element; + + return V; +#endif // !_XM_SSE_INTRISICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadU555 +( + CONST XMU555* pSource +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + static const XMVECTORI32 U555And = {0x1F,0x1F<<5,0x1F<<10,0x8000}; + static const XMVECTORF32 U555Mul = {1.0f,1.0f/32.f,1.0f/1024.f,1.0f/32768.f}; + XMASSERT(pSource); + // Get the 32 bit value and splat it + XMVECTOR vResult = _mm_load_ps1(reinterpret_cast(&pSource->v)); + // Mask off x, y and z + vResult = _mm_and_ps(vResult,U555And); + // Convert to float + vResult = _mm_cvtepi32_ps(reinterpret_cast(&vResult)[0]); + // Normalize x, y, and z + vResult = _mm_mul_ps(vResult,U555Mul); + return vResult; +#else + XMVECTOR V; + UINT Element; + + XMASSERT(pSource); + + Element = pSource->v & 0x1F; + V.vector4_f32[0] = (FLOAT)Element; + Element = (pSource->v >> 5) & 0x1F; + V.vector4_f32[1] = (FLOAT)Element; + Element = (pSource->v >> 10) & 0x1F; + V.vector4_f32[2] = (FLOAT)Element; + Element = (pSource->v >> 15) & 0x1; + V.vector4_f32[3] = (FLOAT)Element; + + return V; +#endif // !_XM_SSE_INTRISICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMLoadColor +( + CONST XMCOLOR* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMASSERT(pSource); + { + // INT -> Float conversions are done in one instruction. + // UINT -> Float calls a runtime function. Keep in INT + INT iColor = (INT)(pSource->c); + XMVECTOR vColor = { + (FLOAT)((iColor >> 16) & 0xFF) * (1.0f/255.0f), + (FLOAT)((iColor >> 8) & 0xFF) * (1.0f/255.0f), + (FLOAT)(iColor & 0xFF) * (1.0f/255.0f), + (FLOAT)((iColor >> 24) & 0xFF) * (1.0f/255.0f) + }; + return vColor; + } +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Splat the color in all four entries + __m128i vInt = _mm_set1_epi32(pSource->c); + // Shift R&0xFF0000, G&0xFF00, B&0xFF, A&0xFF000000 + vInt = _mm_and_si128(vInt,g_XMMaskA8R8G8B8); + // a is unsigned! Flip the bit to convert the order to signed + vInt = _mm_xor_si128(vInt,g_XMFlipA8R8G8B8); + // Convert to floating point numbers + XMVECTOR vTemp = _mm_cvtepi32_ps(vInt); + // RGB + 0, A + 0x80000000.f to undo the signed order. + vTemp = _mm_add_ps(vTemp,g_XMFixAA8R8G8B8); + // Convert 0-255 to 0.0f-1.0f + return _mm_mul_ps(vTemp,g_XMNormalizeA8R8G8B8); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMLoadFloat3x3 +( + CONST XMFLOAT3X3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + + XMASSERT(pSource); + + M.r[0].vector4_f32[0] = pSource->m[0][0]; + M.r[0].vector4_f32[1] = pSource->m[0][1]; + M.r[0].vector4_f32[2] = pSource->m[0][2]; + M.r[0].vector4_f32[3] = 0.0f; + + M.r[1].vector4_f32[0] = pSource->m[1][0]; + M.r[1].vector4_f32[1] = pSource->m[1][1]; + M.r[1].vector4_f32[2] = pSource->m[1][2]; + M.r[1].vector4_f32[3] = 0.0f; + + M.r[2].vector4_f32[0] = pSource->m[2][0]; + M.r[2].vector4_f32[1] = pSource->m[2][1]; + M.r[2].vector4_f32[2] = pSource->m[2][2]; + M.r[2].vector4_f32[3] = 0.0f; + + M.r[3].vector4_f32[0] = 0.0f; + M.r[3].vector4_f32[1] = 0.0f; + M.r[3].vector4_f32[2] = 0.0f; + M.r[3].vector4_f32[3] = 1.0f; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMVECTOR V1, V2, V3, Z, T1, T2, T3, T4, T5; + + Z = _mm_setzero_ps(); + + XMASSERT(pSource); + + V1 = _mm_loadu_ps( &pSource->m[0][0] ); + V2 = _mm_loadu_ps( &pSource->m[1][1] ); + V3 = _mm_load_ss( &pSource->m[2][2] ); + + T1 = _mm_unpackhi_ps( V1, Z ); + T2 = _mm_unpacklo_ps( V2, Z ); + T3 = _mm_shuffle_ps( V3, T2, _MM_SHUFFLE( 0, 1, 0, 0 ) ); + T4 = _mm_movehl_ps( T2, T3 ); + T5 = _mm_movehl_ps( Z, T1 ); + + M.r[0] = _mm_movelh_ps( V1, T1 ); + M.r[1] = _mm_add_ps( T4, T5 ); + M.r[2] = _mm_shuffle_ps( V2, V3, _MM_SHUFFLE(1, 0, 3, 2) ); + M.r[3] = g_XMIdentityR3; + + return M; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMLoadFloat4x3 +( + CONST XMFLOAT4X3* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + XMASSERT(pSource); + + ((UINT *)(&M.r[0].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[0][0]))[0]; + ((UINT *)(&M.r[0].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[0][1]))[0]; + ((UINT *)(&M.r[0].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[0][2]))[0]; + M.r[0].vector4_f32[3] = 0.0f; + + ((UINT *)(&M.r[1].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[1][0]))[0]; + ((UINT *)(&M.r[1].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[1][1]))[0]; + ((UINT *)(&M.r[1].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[1][2]))[0]; + M.r[1].vector4_f32[3] = 0.0f; + + ((UINT *)(&M.r[2].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[2][0]))[0]; + ((UINT *)(&M.r[2].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[2][1]))[0]; + ((UINT *)(&M.r[2].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[2][2]))[0]; + M.r[2].vector4_f32[3] = 0.0f; + + ((UINT *)(&M.r[3].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[3][0]))[0]; + ((UINT *)(&M.r[3].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[3][1]))[0]; + ((UINT *)(&M.r[3].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[3][2]))[0]; + M.r[3].vector4_f32[3] = 1.0f; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Use unaligned load instructions to + // load the 12 floats + // vTemp1 = x1,y1,z1,x2 + XMVECTOR vTemp1 = _mm_loadu_ps(&pSource->m[0][0]); + // vTemp2 = y2,z2,x3,y3 + XMVECTOR vTemp2 = _mm_loadu_ps(&pSource->m[1][1]); + // vTemp4 = z3,x4,y4,z4 + XMVECTOR vTemp4 = _mm_loadu_ps(&pSource->m[2][2]); + // vTemp3 = x3,y3,z3,z3 + XMVECTOR vTemp3 = _mm_shuffle_ps(vTemp2,vTemp4,_MM_SHUFFLE(0,0,3,2)); + // vTemp2 = y2,z2,x2,x2 + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp1,_MM_SHUFFLE(3,3,1,0)); + // vTemp2 = x2,y2,z2,z2 + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(1,1,0,2)); + // vTemp1 = x1,y1,z1,0 + vTemp1 = _mm_and_ps(vTemp1,g_XMMask3); + // vTemp2 = x2,y2,z2,0 + vTemp2 = _mm_and_ps(vTemp2,g_XMMask3); + // vTemp3 = x3,y3,z3,0 + vTemp3 = _mm_and_ps(vTemp3,g_XMMask3); + // vTemp4i = x4,y4,z4,0 + __m128i vTemp4i = _mm_srli_si128(reinterpret_cast(&vTemp4)[0],32/8); + // vTemp4i = x4,y4,z4,1.0f + vTemp4i = _mm_or_si128(vTemp4i,g_XMIdentityR3); + XMMATRIX M(vTemp1, + vTemp2, + vTemp3, + reinterpret_cast(&vTemp4i)[0]); + return M; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMLoadFloat4x3A +( + CONST XMFLOAT4X3A* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + M.r[0].vector4_f32[0] = pSource->m[0][0]; + M.r[0].vector4_f32[1] = pSource->m[0][1]; + M.r[0].vector4_f32[2] = pSource->m[0][2]; + M.r[0].vector4_f32[3] = 0.0f; + + M.r[1].vector4_f32[0] = pSource->m[1][0]; + M.r[1].vector4_f32[1] = pSource->m[1][1]; + M.r[1].vector4_f32[2] = pSource->m[1][2]; + M.r[1].vector4_f32[3] = 0.0f; + + M.r[2].vector4_f32[0] = pSource->m[2][0]; + M.r[2].vector4_f32[1] = pSource->m[2][1]; + M.r[2].vector4_f32[2] = pSource->m[2][2]; + M.r[2].vector4_f32[3] = 0.0f; + + M.r[3].vector4_f32[0] = pSource->m[3][0]; + M.r[3].vector4_f32[1] = pSource->m[3][1]; + M.r[3].vector4_f32[2] = pSource->m[3][2]; + M.r[3].vector4_f32[3] = 1.0f; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + // Use aligned load instructions to + // load the 12 floats + // vTemp1 = x1,y1,z1,x2 + XMVECTOR vTemp1 = _mm_load_ps(&pSource->m[0][0]); + // vTemp2 = y2,z2,x3,y3 + XMVECTOR vTemp2 = _mm_load_ps(&pSource->m[1][1]); + // vTemp4 = z3,x4,y4,z4 + XMVECTOR vTemp4 = _mm_load_ps(&pSource->m[2][2]); + // vTemp3 = x3,y3,z3,z3 + XMVECTOR vTemp3 = _mm_shuffle_ps(vTemp2,vTemp4,_MM_SHUFFLE(0,0,3,2)); + // vTemp2 = y2,z2,x2,x2 + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp1,_MM_SHUFFLE(3,3,1,0)); + // vTemp2 = x2,y2,z2,z2 + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(1,1,0,2)); + // vTemp1 = x1,y1,z1,0 + vTemp1 = _mm_and_ps(vTemp1,g_XMMask3); + // vTemp2 = x2,y2,z2,0 + vTemp2 = _mm_and_ps(vTemp2,g_XMMask3); + // vTemp3 = x3,y3,z3,0 + vTemp3 = _mm_and_ps(vTemp3,g_XMMask3); + // vTemp4i = x4,y4,z4,0 + __m128i vTemp4i = _mm_srli_si128(reinterpret_cast(&vTemp4)[0],32/8); + // vTemp4i = x4,y4,z4,1.0f + vTemp4i = _mm_or_si128(vTemp4i,g_XMIdentityR3); + XMMATRIX M(vTemp1, + vTemp2, + vTemp3, + reinterpret_cast(&vTemp4i)[0]); + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMLoadFloat4x4 +( + CONST XMFLOAT4X4* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + XMASSERT(pSource); + + ((UINT *)(&M.r[0].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[0][0]))[0]; + ((UINT *)(&M.r[0].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[0][1]))[0]; + ((UINT *)(&M.r[0].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[0][2]))[0]; + ((UINT *)(&M.r[0].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[0][3]))[0]; + + ((UINT *)(&M.r[1].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[1][0]))[0]; + ((UINT *)(&M.r[1].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[1][1]))[0]; + ((UINT *)(&M.r[1].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[1][2]))[0]; + ((UINT *)(&M.r[1].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[1][3]))[0]; + + ((UINT *)(&M.r[2].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[2][0]))[0]; + ((UINT *)(&M.r[2].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[2][1]))[0]; + ((UINT *)(&M.r[2].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[2][2]))[0]; + ((UINT *)(&M.r[2].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[2][3]))[0]; + + ((UINT *)(&M.r[3].vector4_f32[0]))[0] = ((const UINT *)(&pSource->m[3][0]))[0]; + ((UINT *)(&M.r[3].vector4_f32[1]))[0] = ((const UINT *)(&pSource->m[3][1]))[0]; + ((UINT *)(&M.r[3].vector4_f32[2]))[0] = ((const UINT *)(&pSource->m[3][2]))[0]; + ((UINT *)(&M.r[3].vector4_f32[3]))[0] = ((const UINT *)(&pSource->m[3][3]))[0]; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSource); + XMMATRIX M; + + M.r[0] = _mm_loadu_ps( &pSource->_11 ); + M.r[1] = _mm_loadu_ps( &pSource->_21 ); + M.r[2] = _mm_loadu_ps( &pSource->_31 ); + M.r[3] = _mm_loadu_ps( &pSource->_41 ); + + return M; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMLoadFloat4x4A +( + CONST XMFLOAT4X4A* pSource +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + + XMASSERT(pSource); + XMASSERT(((UINT_PTR)pSource & 0xF) == 0); + + M.r[0].vector4_f32[0] = pSource->m[0][0]; + M.r[0].vector4_f32[1] = pSource->m[0][1]; + M.r[0].vector4_f32[2] = pSource->m[0][2]; + M.r[0].vector4_f32[3] = pSource->m[0][3]; + + M.r[1].vector4_f32[0] = pSource->m[1][0]; + M.r[1].vector4_f32[1] = pSource->m[1][1]; + M.r[1].vector4_f32[2] = pSource->m[1][2]; + M.r[1].vector4_f32[3] = pSource->m[1][3]; + + M.r[2].vector4_f32[0] = pSource->m[2][0]; + M.r[2].vector4_f32[1] = pSource->m[2][1]; + M.r[2].vector4_f32[2] = pSource->m[2][2]; + M.r[2].vector4_f32[3] = pSource->m[2][3]; + + M.r[3].vector4_f32[0] = pSource->m[3][0]; + M.r[3].vector4_f32[1] = pSource->m[3][1]; + M.r[3].vector4_f32[2] = pSource->m[3][2]; + M.r[3].vector4_f32[3] = pSource->m[3][3]; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + + XMASSERT(pSource); + + M.r[0] = _mm_load_ps( &pSource->_11 ); + M.r[1] = _mm_load_ps( &pSource->_21 ); + M.r[2] = _mm_load_ps( &pSource->_31 ); + M.r[3] = _mm_load_ps( &pSource->_41 ); + + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +/**************************************************************************** + * + * Vector and matrix store operations + * + ****************************************************************************/ + +XMFINLINE VOID XMStoreInt +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + *pDestination = XMVectorGetIntX( V ); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + _mm_store_ss( (float*)pDestination, V ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat +( + FLOAT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + *pDestination = XMVectorGetX( V ); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + _mm_store_ss( pDestination, V ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt2 +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + XMVECTOR T = _mm_shuffle_ps( V, V, _MM_SHUFFLE( 1, 1, 1, 1 ) ); + _mm_store_ss( (float*)&pDestination[0], V ); + _mm_store_ss( (float*)&pDestination[1], T ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreSInt2 +( + XMINT2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = (INT)V.vector4_f32[0]; + pDestination->y = (INT)V.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + // In case of positive overflow, detect it + XMVECTOR vOverflow = _mm_cmpgt_ps(V,g_XMMaxInt); + // Float to int conversion + __m128i vResulti = _mm_cvttps_epi32(V); + // If there was positive overflow, set to 0x7FFFFFFF + XMVECTOR vResult = _mm_and_ps(vOverflow,g_XMAbsMask); + vOverflow = _mm_andnot_ps(vOverflow,reinterpret_cast(&vResulti)[0]); + vOverflow = _mm_or_ps(vOverflow,vResult); + // Write two ints + XMVECTOR T = _mm_shuffle_ps( vOverflow, vOverflow, _MM_SHUFFLE( 1, 1, 1, 1 ) ); + _mm_store_ss( (float*)&pDestination->x, vOverflow ); + _mm_store_ss( (float*)&pDestination->y, T ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUInt2 +( + XMUINT2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = (UINT)V.vector4_f32[0]; + pDestination->y = (UINT)V.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + // Clamp to >=0 + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + // Any numbers that are too big, set to 0xFFFFFFFFU + XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,g_XMMaxUInt); + XMVECTOR vValue = g_XMUnsignedFix; + // Too large for a signed integer? + XMVECTOR vMask = _mm_cmpge_ps(vResult,vValue); + // Zero for number's lower than 0x80000000, 32768.0f*65536.0f otherwise + vValue = _mm_and_ps(vValue,vMask); + // Perform fixup only on numbers too large (Keeps low bit precision) + vResult = _mm_sub_ps(vResult,vValue); + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Convert from signed to unsigned pnly if greater than 0x80000000 + vMask = _mm_and_ps(vMask,g_XMNegativeZero); + vResult = _mm_xor_ps(reinterpret_cast(&vResulti)[0],vMask); + // On those that are too large, set to 0xFFFFFFFF + vResult = _mm_or_ps(vResult,vOverflow); + // Write two uints + XMVECTOR T = _mm_shuffle_ps( vResult, vResult, _MM_SHUFFLE( 1, 1, 1, 1 ) ); + _mm_store_ss( (float*)&pDestination->x, vResult ); + _mm_store_ss( (float*)&pDestination->y, T ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt2A +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat2 +( + XMFLOAT2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + XMVECTOR T = _mm_shuffle_ps( V, V, _MM_SHUFFLE( 1, 1, 1, 1 ) ); + _mm_store_ss( &pDestination->x, V ); + _mm_store_ss( &pDestination->y, T ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat2A +( + XMFLOAT2A* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreHalf2 +( + XMHALF2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->x = XMConvertFloatToHalf(V.vector4_f32[0]); + pDestination->y = XMConvertFloatToHalf(V.vector4_f32[1]); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + pDestination->x = XMConvertFloatToHalf(XMVectorGetX(V)); + pDestination->y = XMConvertFloatToHalf(XMVectorGetY(V)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreShortN2 +( + XMSHORTN2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + + XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + vResult = _mm_mul_ps(vResult,Scale); + __m128i vResulti = _mm_cvtps_epi32(vResult); + vResulti = _mm_packs_epi32(vResulti,vResulti); + _mm_store_ss(reinterpret_cast(&pDestination->x),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreShort2 +( + XMSHORT2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f}; + static CONST XMVECTOR Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + N = XMVectorRound(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f}; + static CONST XMVECTORF32 Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,Min); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // Pack the ints into shorts + vInt = _mm_packs_epi32(vInt,vInt); + _mm_store_ss(reinterpret_cast(&pDestination->x),reinterpret_cast(&vInt)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUShortN2 +( + XMUSHORTN2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v); + N = XMVectorTruncate(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + vResult = _mm_mul_ps(vResult,Scale); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // Since the SSE pack instruction clamps using signed rules, + // manually extract the values to store them to memory + pDestination->x = static_cast(_mm_extract_epi16(vInt,0)); + pDestination->y = static_cast(_mm_extract_epi16(vInt,2)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUShort2 +( + XMUSHORT2* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + N = XMVectorRound(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // Since the SSE pack instruction clamps using signed rules, + // manually extract the values to store them to memory + pDestination->x = static_cast(_mm_extract_epi16(vInt,0)); + pDestination->y = static_cast(_mm_extract_epi16(vInt,2)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreByteN2 +( + XMBYTEN2* pDestination, + FXMVECTOR V +) +{ + XMVECTOR N; + XMFLOAT4A tmp; + static CONST XMVECTORF32 Scale = {127.0f, 127.0f, 127.0f, 127.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + XMStoreFloat4A( &tmp, N ); + + pDestination->x = (CHAR)tmp.x; + pDestination->y = (CHAR)tmp.y; +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreByte2 +( + XMBYTE2* pDestination, + FXMVECTOR V +) +{ + XMVECTOR N; + XMFLOAT4A tmp; + static CONST XMVECTOR Min = {-127.0f, -127.0f, -127.0f, -127.0f}; + static CONST XMVECTOR Max = {127.0f, 127.0f, 127.0f, 127.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + N = XMVectorRound(N); + + XMStoreFloat4A( &tmp, N ); + + pDestination->x = (CHAR)tmp.x; + pDestination->y = (CHAR)tmp.y; +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUByteN2 +( + XMUBYTEN2* pDestination, + FXMVECTOR V +) +{ + XMVECTOR N; + XMFLOAT4A tmp; + static CONST XMVECTORF32 Scale = {255.0f, 255.0f, 255.0f, 255.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v); + N = XMVectorTruncate(N); + + XMStoreFloat4A( &tmp, N ); + + pDestination->x = (BYTE)tmp.x; + pDestination->y = (BYTE)tmp.y; +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUByte2 +( + XMUBYTE2* pDestination, + FXMVECTOR V +) +{ + XMVECTOR N; + static CONST XMVECTOR Max = {255.0f, 255.0f, 255.0f, 255.0f}; + XMFLOAT4A tmp; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + N = XMVectorRound(N); + + XMStoreFloat4A( &tmp, N ); + + pDestination->x = (BYTE)tmp.x; + pDestination->y = (BYTE)tmp.y; +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt3 +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + pDestination[2] = V.vector4_u32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + XMVECTOR T1 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR T2 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss( (float*)pDestination, V ); + _mm_store_ss( (float*)&pDestination[1], T1 ); + _mm_store_ss( (float*)&pDestination[2], T2 ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreSInt3 +( + XMINT3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = (INT)V.vector4_f32[0]; + pDestination->y = (INT)V.vector4_f32[1]; + pDestination->z = (INT)V.vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + // In case of positive overflow, detect it + XMVECTOR vOverflow = _mm_cmpgt_ps(V,g_XMMaxInt); + // Float to int conversion + __m128i vResulti = _mm_cvttps_epi32(V); + // If there was positive overflow, set to 0x7FFFFFFF + XMVECTOR vResult = _mm_and_ps(vOverflow,g_XMAbsMask); + vOverflow = _mm_andnot_ps(vOverflow,reinterpret_cast(&vResulti)[0]); + vOverflow = _mm_or_ps(vOverflow,vResult); + // Write 3 uints + XMVECTOR T1 = _mm_shuffle_ps(vOverflow,vOverflow,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR T2 = _mm_shuffle_ps(vOverflow,vOverflow,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss( (float*)&pDestination->x, vOverflow ); + _mm_store_ss( (float*)&pDestination->y, T1 ); + _mm_store_ss( (float*)&pDestination->z, T2 ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUInt3 +( + XMUINT3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = (UINT)V.vector4_f32[0]; + pDestination->y = (UINT)V.vector4_f32[1]; + pDestination->z = (UINT)V.vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + // Clamp to >=0 + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + // Any numbers that are too big, set to 0xFFFFFFFFU + XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,g_XMMaxUInt); + XMVECTOR vValue = g_XMUnsignedFix; + // Too large for a signed integer? + XMVECTOR vMask = _mm_cmpge_ps(vResult,vValue); + // Zero for number's lower than 0x80000000, 32768.0f*65536.0f otherwise + vValue = _mm_and_ps(vValue,vMask); + // Perform fixup only on numbers too large (Keeps low bit precision) + vResult = _mm_sub_ps(vResult,vValue); + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Convert from signed to unsigned pnly if greater than 0x80000000 + vMask = _mm_and_ps(vMask,g_XMNegativeZero); + vResult = _mm_xor_ps(reinterpret_cast(&vResulti)[0],vMask); + // On those that are too large, set to 0xFFFFFFFF + vResult = _mm_or_ps(vResult,vOverflow); + // Write 3 uints + XMVECTOR T1 = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR T2 = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss( (float*)&pDestination->x, vResult ); + _mm_store_ss( (float*)&pDestination->y, T1 ); + _mm_store_ss( (float*)&pDestination->z, T2 ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt3A +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + pDestination[2] = V.vector4_u32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + XMVECTOR T = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + _mm_store_ss( (float*)&pDestination[2], T ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat3 +( + XMFLOAT3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + pDestination->z = V.vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + XMVECTOR T1 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR T2 = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss( &pDestination->x, V ); + _mm_store_ss( &pDestination->y, T1 ); + _mm_store_ss( &pDestination->z, T2 ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat3A +( + XMFLOAT3A* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + pDestination->z = V.vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + XMVECTOR T = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + _mm_storel_epi64( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + _mm_store_ss( &pDestination->z, T ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUHenDN3 +( + XMUHENDN3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {2047.0f, 2047.0f, 1023.0f, 0.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiply(N, Scale.v); + + pDestination->v = (((UINT)N.vector4_f32[2] & 0x3FF) << 22) | + (((UINT)N.vector4_f32[1] & 0x7FF) << 11) | + (((UINT)N.vector4_f32[0] & 0x7FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleUHenDN3 = {2047.0f, 2047.0f*2048.0f,1023.0f*(2048.0f*2048.0f)/2.0f,1.0f}; + static const XMVECTORI32 MaskUHenDN3 = {0x7FF,0x7FF<<11,0x3FF<<(22-1),0}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUHenDN3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUHenDN3); + // Do a horizontal or of 3 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1)); + // i = x|y + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1)); + // Add Z to itself to perform a single bit left shift + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUHenD3 +( + XMUHEND3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {2047.0f, 2047.0f, 1023.0f, 0.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + + pDestination->v = (((UINT)N.vector4_f32[2] & 0x3FF) << 22) | + (((UINT)N.vector4_f32[1] & 0x7FF) << 11) | + (((UINT)N.vector4_f32[0] & 0x7FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MaxUHenD3 = { 2047.0f, 2047.0f, 1023.0f, 1.0f}; + static const XMVECTORF32 ScaleUHenD3 = {1.0f, 2048.0f,(2048.0f*2048.0f)/2.0f,1.0f}; + static const XMVECTORI32 MaskUHenD3 = {0x7FF,0x7FF<<11,0x3FF<<(22-1),0}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,MaxUHenD3); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUHenD3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUHenD3); + // Do a horizontal or of 3 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1)); + // i = x|y + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1)); + // Add Z to itself to perform a single bit left shift + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreHenDN3 +( + XMHENDN3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {1023.0f, 1023.0f, 511.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + + pDestination->v = (((INT)N.vector4_f32[2] & 0x3FF) << 22) | + (((INT)N.vector4_f32[1] & 0x7FF) << 11) | + (((INT)N.vector4_f32[0] & 0x7FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleHenDN3 = {1023.0f, 1023.0f*2048.0f,511.0f*(2048.0f*2048.0f),1.0f}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleHenDN3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,g_XMMaskHenD3); + // Do a horizontal or of all 4 entries + vResult = _mm_shuffle_ps(reinterpret_cast(&vResulti)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreHenD3 +( + XMHEND3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-1023.0f, -1023.0f, -511.0f, -1.0f}; + static CONST XMVECTOR Max = {1023.0f, 1023.0f, 511.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + + pDestination->v = (((INT)N.vector4_f32[2] & 0x3FF) << 22) | + (((INT)N.vector4_f32[1] & 0x7FF) << 11) | + (((INT)N.vector4_f32[0] & 0x7FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MinHenD3 = {-1023.0f,-1023.0f,-511.0f,-1.0f}; + static const XMVECTORF32 MaxHenD3 = { 1023.0f, 1023.0f, 511.0f, 1.0f}; + static const XMVECTORF32 ScaleHenD3 = {1.0f, 2048.0f,(2048.0f*2048.0f),1.0f}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,MinHenD3); + vResult = _mm_min_ps(vResult,MaxHenD3); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleHenD3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,g_XMMaskHenD3); + // Do a horizontal or of all 4 entries + vResult = _mm_shuffle_ps(reinterpret_cast(&vResulti)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUDHenN3 +( + XMUDHENN3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {1023.0f, 2047.0f, 2047.0f, 0.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiply(N, Scale.v); + + pDestination->v = (((UINT)N.vector4_f32[2] & 0x7FF) << 21) | + (((UINT)N.vector4_f32[1] & 0x7FF) << 10) | + (((UINT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleUDHenN3 = {1023.0f,2047.0f*1024.0f,2047.0f*(1024.0f*2048.0f)/2.0f,1.0f}; + static const XMVECTORI32 MaskUDHenN3 = {0x3FF,0x7FF<<10,0x7FF<<(21-1),0}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUDHenN3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUDHenN3); + // Do a horizontal or of 3 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1)); + // i = x|y + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1)); + // Add Z to itself to perform a single bit left shift + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUDHen3 +( + XMUDHEN3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {1023.0f, 2047.0f, 2047.0f, 0.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + + pDestination->v = (((UINT)N.vector4_f32[2] & 0x7FF) << 21) | + (((UINT)N.vector4_f32[1] & 0x7FF) << 10) | + (((UINT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MaxUDHen3 = { 1023.0f, 2047.0f, 2047.0f, 1.0f}; + static const XMVECTORF32 ScaleUDHen3 = {1.0f, 1024.0f,(1024.0f*2048.0f)/2.0f,1.0f}; + static const XMVECTORI32 MaskUDHen3 = {0x3FF,0x7FF<<10,0x7FF<<(21-1),0}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,MaxUDHen3); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUDHen3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUDHen3); + // Do a horizontal or of 3 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(0,3,2,1)); + // i = x|y + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti2,_MM_SHUFFLE(0,3,2,1)); + // Add Z to itself to perform a single bit left shift + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreDHenN3 +( + XMDHENN3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {511.0f, 1023.0f, 1023.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + + pDestination->v = (((INT)N.vector4_f32[2] & 0x7FF) << 21) | + (((INT)N.vector4_f32[1] & 0x7FF) << 10) | + (((INT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleDHenN3 = {511.0f, 1023.0f*1024.0f,1023.0f*(1024.0f*2048.0f),1.0f}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleDHenN3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,g_XMMaskDHen3); + // Do a horizontal or of all 4 entries + vResult = _mm_shuffle_ps(reinterpret_cast(&vResulti)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreDHen3 +( + XMDHEN3* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-511.0f, -1023.0f, -1023.0f, -1.0f}; + static CONST XMVECTOR Max = {511.0f, 1023.0f, 1023.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + + pDestination->v = (((INT)N.vector4_f32[2] & 0x7FF) << 21) | + (((INT)N.vector4_f32[1] & 0x7FF) << 10) | + (((INT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MinDHen3 = {-511.0f,-1023.0f,-1023.0f,-1.0f}; + static const XMVECTORF32 MaxDHen3 = { 511.0f, 1023.0f, 1023.0f, 1.0f}; + static const XMVECTORF32 ScaleDHen3 = {1.0f, 1024.0f,(1024.0f*2048.0f),1.0f}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,MinDHen3); + vResult = _mm_min_ps(vResult,MaxDHen3); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleDHen3); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,g_XMMaskDHen3); + // Do a horizontal or of all 4 entries + vResult = _mm_shuffle_ps(reinterpret_cast(&vResulti)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreU565 +( + XMU565* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Max = {31.0f, 63.0f, 31.0f, 0.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // No SSE operations will write to 16-bit values, so we have to extract them manually + USHORT x = static_cast(_mm_extract_epi16(vInt,0)); + USHORT y = static_cast(_mm_extract_epi16(vInt,2)); + USHORT z = static_cast(_mm_extract_epi16(vInt,4)); + pDestination->v = ((z & 0x1F) << 11) | + ((y & 0x3F) << 5) | + ((x & 0x1F)); +#else + XMVECTOR N; + static CONST XMVECTORF32 Max = {31.0f, 63.0f, 31.0f, 0.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max.v); + N = XMVectorRound(N); + + pDestination->v = (((USHORT)N.vector4_f32[2] & 0x1F) << 11) | + (((USHORT)N.vector4_f32[1] & 0x3F) << 5) | + (((USHORT)N.vector4_f32[0] & 0x1F)); +#endif !_XM_SSE_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat3PK +( + XMFLOAT3PK* pDestination, + FXMVECTOR V +) +{ + _DECLSPEC_ALIGN_16_ UINT IValue[4]; + UINT I, Sign, j; + UINT Result[3]; + + XMASSERT(pDestination); + + XMStoreFloat3A( (XMFLOAT3A*)&IValue, V ); + + // X & Y Channels (5-bit exponent, 6-bit mantissa) + for(j=0; j < 2; ++j) + { + Sign = IValue[j] & 0x80000000; + I = IValue[j] & 0x7FFFFFFF; + + if ((I & 0x7F800000) == 0x7F800000) + { + // INF or NAN + Result[j] = 0x7c0; + if (( I & 0x7FFFFF ) != 0) + { + Result[j] = 0x7c0 | (((I>>17)|(I>11)|(I>>6)|(I))&0x3f); + } + else if ( Sign ) + { + // -INF is clamped to 0 since 3PK is positive only + Result[j] = 0; + } + } + else if ( Sign ) + { + // 3PK is positive only, so clamp to zero + Result[j] = 0; + } + else if (I > 0x477E0000U) + { + // The number is too large to be represented as a float11, set to max + Result[j] = 0x7BF; + } + else + { + if (I < 0x38800000U) + { + // The number is too small to be represented as a normalized float11 + // Convert it to a denormalized value. + UINT Shift = 113U - (I >> 23U); + I = (0x800000U | (I & 0x7FFFFFU)) >> Shift; + } + else + { + // Rebias the exponent to represent the value as a normalized float11 + I += 0xC8000000U; + } + + Result[j] = ((I + 0xFFFFU + ((I >> 17U) & 1U)) >> 17U)&0x7ffU; + } + } + + // Z Channel (5-bit exponent, 5-bit mantissa) + Sign = IValue[2] & 0x80000000; + I = IValue[2] & 0x7FFFFFFF; + + if ((I & 0x7F800000) == 0x7F800000) + { + // INF or NAN + Result[2] = 0x3e0; + if ( I & 0x7FFFFF ) + { + Result[2] = 0x3e0 | (((I>>18)|(I>13)|(I>>3)|(I))&0x1f); + } + else if ( Sign ) + { + // -INF is clamped to 0 since 3PK is positive only + Result[2] = 0; + } + } + else if ( Sign ) + { + // 3PK is positive only, so clamp to zero + Result[2] = 0; + } + else if (I > 0x477C0000U) + { + // The number is too large to be represented as a float10, set to max + Result[2] = 0x3df; + } + else + { + if (I < 0x38800000U) + { + // The number is too small to be represented as a normalized float10 + // Convert it to a denormalized value. + UINT Shift = 113U - (I >> 23U); + I = (0x800000U | (I & 0x7FFFFFU)) >> Shift; + } + else + { + // Rebias the exponent to represent the value as a normalized float10 + I += 0xC8000000U; + } + + Result[2] = ((I + 0x1FFFFU + ((I >> 18U) & 1U)) >> 18U)&0x3ffU; + } + + // Pack Result into memory + pDestination->v = (Result[0] & 0x7ff) + | ( (Result[1] & 0x7ff) << 11 ) + | ( (Result[2] & 0x3ff) << 22 ); +} + + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat3SE +( + XMFLOAT3SE* pDestination, + FXMVECTOR V +) +{ + _DECLSPEC_ALIGN_16_ UINT IValue[4]; + UINT I, Sign, j, T; + UINT Frac[3]; + UINT Exp[3]; + + + XMASSERT(pDestination); + + XMStoreFloat3A( (XMFLOAT3A*)&IValue, V ); + + // X, Y, Z Channels (5-bit exponent, 9-bit mantissa) + for(j=0; j < 3; ++j) + { + Sign = IValue[j] & 0x80000000; + I = IValue[j] & 0x7FFFFFFF; + + if ((I & 0x7F800000) == 0x7F800000) + { + // INF or NAN + Exp[j] = 0x1f; + if (( I & 0x7FFFFF ) != 0) + { + Frac[j] = ((I>>14)|(I>5)|(I))&0x1ff; + } + else if ( Sign ) + { + // -INF is clamped to 0 since 3SE is positive only + Exp[j] = Frac[j] = 0; + } + } + else if ( Sign ) + { + // 3SE is positive only, so clamp to zero + Exp[j] = Frac[j] = 0; + } + else if (I > 0x477FC000U) + { + // The number is too large, set to max + Exp[j] = 0x1e; + Frac[j] = 0x1ff; + } + else + { + if (I < 0x38800000U) + { + // The number is too small to be represented as a normalized float11 + // Convert it to a denormalized value. + UINT Shift = 113U - (I >> 23U); + I = (0x800000U | (I & 0x7FFFFFU)) >> Shift; + } + else + { + // Rebias the exponent to represent the value as a normalized float11 + I += 0xC8000000U; + } + + T = ((I + 0x1FFFU + ((I >> 14U) & 1U)) >> 14U)&0x3fffU; + + Exp[j] = (T & 0x3E00) >> 9; + Frac[j] = T & 0x1ff; + } + } + + // Adjust to a shared exponent + T = XMMax( Exp[0], XMMax( Exp[1], Exp[2] ) ); + + Frac[0] = Frac[0] >> (T - Exp[0]); + Frac[1] = Frac[1] >> (T - Exp[1]); + Frac[2] = Frac[2] >> (T - Exp[2]); + + // Store packed into memory + pDestination->xm = Frac[0]; + pDestination->ym = Frac[1]; + pDestination->zm = Frac[2]; + pDestination->e = T; +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt4 +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + pDestination[2] = V.vector4_u32[2]; + pDestination[3] = V.vector4_u32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + + _mm_storeu_si128( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt4A +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + pDestination[2] = V.vector4_u32[2]; + pDestination[3] = V.vector4_u32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + _mm_store_si128( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreSInt4 +( + XMINT4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->x = (INT)V.vector4_f32[0]; + pDestination->y = (INT)V.vector4_f32[1]; + pDestination->z = (INT)V.vector4_f32[2]; + pDestination->w = (INT)V.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + + // In case of positive overflow, detect it + XMVECTOR vOverflow = _mm_cmpgt_ps(V,g_XMMaxInt); + // Float to int conversion + __m128i vResulti = _mm_cvttps_epi32(V); + // If there was positive overflow, set to 0x7FFFFFFF + XMVECTOR vResult = _mm_and_ps(vOverflow,g_XMAbsMask); + vOverflow = _mm_andnot_ps(vOverflow,reinterpret_cast(&vResulti)[0]); + vOverflow = _mm_or_ps(vOverflow,vResult); + _mm_storeu_si128( (__m128i*)pDestination, reinterpret_cast(&vOverflow)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUInt4 +( + XMUINT4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->x = (UINT)V.vector4_f32[0]; + pDestination->y = (UINT)V.vector4_f32[1]; + pDestination->z = (UINT)V.vector4_f32[2]; + pDestination->w = (UINT)V.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + + // Clamp to >=0 + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + // Any numbers that are too big, set to 0xFFFFFFFFU + XMVECTOR vOverflow = _mm_cmpgt_ps(vResult,g_XMMaxUInt); + XMVECTOR vValue = g_XMUnsignedFix; + // Too large for a signed integer? + XMVECTOR vMask = _mm_cmpge_ps(vResult,vValue); + // Zero for number's lower than 0x80000000, 32768.0f*65536.0f otherwise + vValue = _mm_and_ps(vValue,vMask); + // Perform fixup only on numbers too large (Keeps low bit precision) + vResult = _mm_sub_ps(vResult,vValue); + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Convert from signed to unsigned pnly if greater than 0x80000000 + vMask = _mm_and_ps(vMask,g_XMNegativeZero); + vResult = _mm_xor_ps(reinterpret_cast(&vResulti)[0],vMask); + // On those that are too large, set to 0xFFFFFFFF + vResult = _mm_or_ps(vResult,vOverflow); + _mm_storeu_si128( (__m128i*)pDestination, reinterpret_cast(&vResult)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreInt4NC +( + UINT* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination[0] = V.vector4_u32[0]; + pDestination[1] = V.vector4_u32[1]; + pDestination[2] = V.vector4_u32[2]; + pDestination[3] = V.vector4_u32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + _mm_storeu_si128( (__m128i*)pDestination, reinterpret_cast(&V)[0] ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4 +( + XMFLOAT4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + pDestination->z = V.vector4_f32[2]; + pDestination->w = V.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + + _mm_storeu_ps( &pDestination->x, V ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4A +( + XMFLOAT4A* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + pDestination->z = V.vector4_f32[2]; + pDestination->w = V.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + _mm_store_ps( &pDestination->x, V ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4NC +( + XMFLOAT4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + pDestination->x = V.vector4_f32[0]; + pDestination->y = V.vector4_f32[1]; + pDestination->z = V.vector4_f32[2]; + pDestination->w = V.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 3) == 0); + + _mm_storeu_ps( &pDestination->x, V ); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreHalf4 +( + XMHALF4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->x = XMConvertFloatToHalf(V.vector4_f32[0]); + pDestination->y = XMConvertFloatToHalf(V.vector4_f32[1]); + pDestination->z = XMConvertFloatToHalf(V.vector4_f32[2]); + pDestination->w = XMConvertFloatToHalf(V.vector4_f32[3]); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + pDestination->x = XMConvertFloatToHalf(XMVectorGetX(V)); + pDestination->y = XMConvertFloatToHalf(XMVectorGetY(V)); + pDestination->z = XMConvertFloatToHalf(XMVectorGetZ(V)); + pDestination->w = XMConvertFloatToHalf(XMVectorGetW(V)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreShortN4 +( + XMSHORTN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + pDestination->z = (SHORT)N.vector4_f32[2]; + pDestination->w = (SHORT)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Scale = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + + XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + vResult = _mm_mul_ps(vResult,Scale); + __m128i vResulti = _mm_cvtps_epi32(vResult); + vResulti = _mm_packs_epi32(vResulti,vResulti); + _mm_store_sd(reinterpret_cast(&pDestination->x),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreShort4 +( + XMSHORT4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f}; + static CONST XMVECTOR Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + N = XMVectorRound(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + pDestination->z = (SHORT)N.vector4_f32[2]; + pDestination->w = (SHORT)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Min = {-32767.0f, -32767.0f, -32767.0f, -32767.0f}; + static CONST XMVECTORF32 Max = {32767.0f, 32767.0f, 32767.0f, 32767.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,Min); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // Pack the ints into shorts + vInt = _mm_packs_epi32(vInt,vInt); + _mm_store_sd(reinterpret_cast(&pDestination->x),reinterpret_cast(&vInt)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUShortN4 +( + XMUSHORTN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v); + N = XMVectorTruncate(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + pDestination->z = (SHORT)N.vector4_f32[2]; + pDestination->w = (SHORT)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Scale = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + vResult = _mm_mul_ps(vResult,Scale); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // Since the SSE pack instruction clamps using signed rules, + // manually extract the values to store them to memory + pDestination->x = static_cast(_mm_extract_epi16(vInt,0)); + pDestination->y = static_cast(_mm_extract_epi16(vInt,2)); + pDestination->z = static_cast(_mm_extract_epi16(vInt,4)); + pDestination->w = static_cast(_mm_extract_epi16(vInt,6)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUShort4 +( + XMUSHORT4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + N = XMVectorRound(N); + + pDestination->x = (SHORT)N.vector4_f32[0]; + pDestination->y = (SHORT)N.vector4_f32[1]; + pDestination->z = (SHORT)N.vector4_f32[2]; + pDestination->w = (SHORT)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Max = {65535.0f, 65535.0f, 65535.0f, 65535.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // Since the SSE pack instruction clamps using signed rules, + // manually extract the values to store them to memory + pDestination->x = static_cast(_mm_extract_epi16(vInt,0)); + pDestination->y = static_cast(_mm_extract_epi16(vInt,2)); + pDestination->z = static_cast(_mm_extract_epi16(vInt,4)); + pDestination->w = static_cast(_mm_extract_epi16(vInt,6)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreXIcoN4 +( + XMXICON4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Min = {-1.0f, -1.0f, -1.0f, 0.0f}; + static CONST XMVECTORF32 Scale = {524287.0f, 524287.0f, 524287.0f, 15.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + pDestination->v = ((UINT64)N.vector4_f32[3] << 60) | + (((INT64)N.vector4_f32[2] & 0xFFFFF) << 40) | + (((INT64)N.vector4_f32[1] & 0xFFFFF) << 20) | + (((INT64)N.vector4_f32[0] & 0xFFFFF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + // Note: Masks are x,w,y and z + static const XMVECTORF32 MinXIcoN4 = {-1.0f, 0.0f,-1.0f,-1.0f}; + static const XMVECTORF32 ScaleXIcoN4 = {524287.0f,15.0f*4096.0f*65536.0f*0.5f,524287.0f*4096.0f,524287.0f}; + static const XMVECTORI32 MaskXIcoN4 = {0xFFFFF,0xF<<((60-32)-1),0xFFFFF000,0xFFFFF}; + + // Clamp to bounds + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0)); + vResult = _mm_max_ps(vResult,MinXIcoN4); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleXIcoN4); + // Convert to integer (w is unsigned) + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off unused bits + vResulti = _mm_and_si128(vResulti,MaskXIcoN4); + // Isolate Y + __m128i vResulti2 = _mm_and_si128(vResulti,g_XMMaskY); + // Double Y (Really W) to fixup for unsigned conversion + vResulti = _mm_add_epi32(vResulti,vResulti2); + // Shift y and z to straddle the 32-bit boundary + vResulti2 = _mm_srli_si128(vResulti,(64+12)/8); + // Shift it into place + vResulti2 = _mm_slli_si128(vResulti2,20/8); + // i = x|y<<20|z<<40|w<<60 + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_sd(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreXIco4 +( + XMXICO4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Min = {-524287.0f, -524287.0f, -524287.0f, 0.0f}; + static CONST XMVECTORF32 Max = {524287.0f, 524287.0f, 524287.0f, 15.0f}; + + XMASSERT(pDestination); + N = XMVectorClamp(V, Min.v, Max.v); + pDestination->v = ((UINT64)N.vector4_f32[3] << 60) | + (((INT64)N.vector4_f32[2] & 0xFFFFF) << 40) | + (((INT64)N.vector4_f32[1] & 0xFFFFF) << 20) | + (((INT64)N.vector4_f32[0] & 0xFFFFF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + // Note: Masks are x,w,y and z + static const XMVECTORF32 MinXIco4 = {-524287.0f, 0.0f,-524287.0f,-524287.0f}; + static const XMVECTORF32 MaxXIco4 = { 524287.0f,15.0f, 524287.0f, 524287.0f}; + static const XMVECTORF32 ScaleXIco4 = {1.0f,4096.0f*65536.0f*0.5f,4096.0f,1.0f}; + static const XMVECTORI32 MaskXIco4 = {0xFFFFF,0xF<<((60-1)-32),0xFFFFF000,0xFFFFF}; + // Clamp to bounds + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0)); + vResult = _mm_max_ps(vResult,MinXIco4); + vResult = _mm_min_ps(vResult,MaxXIco4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleXIco4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskXIco4); + // Isolate Y + __m128i vResulti2 = _mm_and_si128(vResulti,g_XMMaskY); + // Double Y (Really W) to fixup for unsigned conversion + vResulti = _mm_add_epi32(vResulti,vResulti2); + // Shift y and z to straddle the 32-bit boundary + vResulti2 = _mm_srli_si128(vResulti,(64+12)/8); + // Shift it into place + vResulti2 = _mm_slli_si128(vResulti2,20/8); + // i = x|y<<20|z<<40|w<<60 + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_sd(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUIcoN4 +( + XMUICON4* pDestination, + FXMVECTOR V +) +{ + #define XM_URange ((FLOAT)(1 << 20)) + #define XM_URangeDiv2 ((FLOAT)(1 << 19)) + #define XM_UMaxXYZ ((FLOAT)((1 << 20) - 1)) + #define XM_UMaxW ((FLOAT)((1 << 4) - 1)) + #define XM_ScaleXYZ (-(FLOAT)((1 << 20) - 1) / XM_PACK_FACTOR) + #define XM_ScaleW (-(FLOAT)((1 << 4) - 1) / XM_PACK_FACTOR) + #define XM_Scale (-1.0f / XM_PACK_FACTOR) + #define XM_Offset (3.0f) + +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {1048575.0f, 1048575.0f, 1048575.0f, 15.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiplyAdd(N, Scale.v, g_XMOneHalf.v); + + pDestination->v = ((UINT64)N.vector4_f32[3] << 60) | + (((UINT64)N.vector4_f32[2] & 0xFFFFF) << 40) | + (((UINT64)N.vector4_f32[1] & 0xFFFFF) << 20) | + (((UINT64)N.vector4_f32[0] & 0xFFFFF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + // Note: Masks are x,w,y and z + static const XMVECTORF32 ScaleUIcoN4 = {1048575.0f,15.0f*4096.0f*65536.0f,1048575.0f*4096.0f,1048575.0f}; + static const XMVECTORI32 MaskUIcoN4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF}; + static const XMVECTORF32 AddUIcoN4 = {0.0f,-32768.0f*65536.0f,-32768.0f*65536.0f,0.0f}; + // Clamp to bounds + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0)); + vResult = _mm_max_ps(vResult,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUIcoN4); + // Adjust for unsigned entries + vResult = _mm_add_ps(vResult,AddUIcoN4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Fix the signs on the unsigned entries + vResulti = _mm_xor_si128(vResulti,g_XMFlipYZ); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUIcoN4); + // Shift y and z to straddle the 32-bit boundary + __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8); + // Shift it into place + vResulti2 = _mm_slli_si128(vResulti2,20/8); + // i = x|y<<20|z<<40|w<<60 + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_sd(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ + + #undef XM_URange + #undef XM_URangeDiv2 + #undef XM_UMaxXYZ + #undef XM_UMaxW + #undef XM_ScaleXYZ + #undef XM_ScaleW + #undef XM_Scale + #undef XM_Offset +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUIco4 +( + XMUICO4* pDestination, + FXMVECTOR V +) +{ + #define XM_Scale (-1.0f / XM_PACK_FACTOR) + #define XM_URange ((FLOAT)(1 << 20)) + #define XM_URangeDiv2 ((FLOAT)(1 << 19)) + +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {1048575.0f, 1048575.0f, 1048575.0f, 15.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + N = XMVectorRound(N); + + pDestination->v = ((UINT64)N.vector4_f32[3] << 60) | + (((UINT64)N.vector4_f32[2] & 0xFFFFF) << 40) | + (((UINT64)N.vector4_f32[1] & 0xFFFFF) << 20) | + (((UINT64)N.vector4_f32[0] & 0xFFFFF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + // Note: Masks are x,w,y and z + static const XMVECTORF32 MaxUIco4 = { 1048575.0f, 15.0f, 1048575.0f, 1048575.0f}; + static const XMVECTORF32 ScaleUIco4 = {1.0f,4096.0f*65536.0f,4096.0f,1.0f}; + static const XMVECTORI32 MaskUIco4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF}; + static const XMVECTORF32 AddUIco4 = {0.0f,-32768.0f*65536.0f,-32768.0f*65536.0f,0.0f}; + // Clamp to bounds + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0)); + vResult = _mm_max_ps(vResult,g_XMZero); + vResult = _mm_min_ps(vResult,MaxUIco4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUIco4); + vResult = _mm_add_ps(vResult,AddUIco4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + vResulti = _mm_xor_si128(vResulti,g_XMFlipYZ); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUIco4); + // Shift y and z to straddle the 32-bit boundary + __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8); + // Shift it into place + vResulti2 = _mm_slli_si128(vResulti2,20/8); + // i = x|y<<20|z<<40|w<<60 + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_sd(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ + + #undef XM_Scale + #undef XM_URange + #undef XM_URangeDiv2 +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreIcoN4 +( + XMICON4* pDestination, + FXMVECTOR V +) +{ + #define XM_Scale (-1.0f / XM_PACK_FACTOR) + #define XM_URange ((FLOAT)(1 << 4)) + #define XM_Offset (3.0f) + #define XM_UMaxXYZ ((FLOAT)((1 << (20 - 1)) - 1)) + #define XM_UMaxW ((FLOAT)((1 << (4 - 1)) - 1)) + +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {524287.0f, 524287.0f, 524287.0f, 7.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiplyAdd(N, Scale.v, g_XMNegativeZero.v); + N = XMVectorRound(N); + + pDestination->v = ((UINT64)N.vector4_f32[3] << 60) | + (((UINT64)N.vector4_f32[2] & 0xFFFFF) << 40) | + (((UINT64)N.vector4_f32[1] & 0xFFFFF) << 20) | + (((UINT64)N.vector4_f32[0] & 0xFFFFF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + // Note: Masks are x,w,y and z + static const XMVECTORF32 ScaleIcoN4 = {524287.0f,7.0f*4096.0f*65536.0f,524287.0f*4096.0f,524287.0f}; + static const XMVECTORI32 MaskIcoN4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF}; + // Clamp to bounds + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0)); + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleIcoN4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskIcoN4); + // Shift y and z to straddle the 32-bit boundary + __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8); + // Shift it into place + vResulti2 = _mm_slli_si128(vResulti2,20/8); + // i = x|y<<20|z<<40|w<<60 + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_sd(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ + + #undef XM_Scale + #undef XM_URange + #undef XM_Offset + #undef XM_UMaxXYZ + #undef XM_UMaxW +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreIco4 +( + XMICO4* pDestination, + FXMVECTOR V +) +{ + #define XM_Scale (-1.0f / XM_PACK_FACTOR) + #define XM_URange ((FLOAT)(1 << 4)) + #define XM_Offset (3.0f) + +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-524287.0f, -524287.0f, -524287.0f, -7.0f}; + static CONST XMVECTOR Max = {524287.0f, 524287.0f, 524287.0f, 7.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + N = XMVectorRound(N); + + pDestination->v = ((INT64)N.vector4_f32[3] << 60) | + (((INT64)N.vector4_f32[2] & 0xFFFFF) << 40) | + (((INT64)N.vector4_f32[1] & 0xFFFFF) << 20) | + (((INT64)N.vector4_f32[0] & 0xFFFFF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + // Note: Masks are x,w,y and z + static const XMVECTORF32 MinIco4 = {-524287.0f,-7.0f,-524287.0f,-524287.0f}; + static const XMVECTORF32 MaxIco4 = { 524287.0f, 7.0f, 524287.0f, 524287.0f}; + static const XMVECTORF32 ScaleIco4 = {1.0f,4096.0f*65536.0f,4096.0f,1.0f}; + static const XMVECTORI32 MaskIco4 = {0xFFFFF,0xF<<(60-32),0xFFFFF000,0xFFFFF}; + // Clamp to bounds + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,1,3,0)); + vResult = _mm_max_ps(vResult,MinIco4); + vResult = _mm_min_ps(vResult,MaxIco4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleIco4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskIco4); + // Shift y and z to straddle the 32-bit boundary + __m128i vResulti2 = _mm_srli_si128(vResulti,(64+12)/8); + // Shift it into place + vResulti2 = _mm_slli_si128(vResulti2,20/8); + // i = x|y<<20|z<<40|w<<60 + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_sd(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ + + #undef XM_Scale + #undef XM_URange + #undef XM_Offset +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreXDecN4 +( + XMXDECN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Min = {-1.0f, -1.0f, -1.0f, 0.0f}; + static CONST XMVECTORF32 Scale = {511.0f, 511.0f, 511.0f, 3.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + pDestination->v = ((UINT)N.vector4_f32[3] << 30) | + (((INT)N.vector4_f32[2] & 0x3FF) << 20) | + (((INT)N.vector4_f32[1] & 0x3FF) << 10) | + (((INT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 Min = {-1.0f, -1.0f, -1.0f, 0.0f}; + static const XMVECTORF32 Scale = {511.0f, 511.0f*1024.0f, 511.0f*1048576.0f,3.0f*536870912.0f}; + static const XMVECTORI32 ScaleMask = {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<29}; + XMASSERT(pDestination); + XMVECTOR vResult = _mm_max_ps(V,Min); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,Scale); + // Convert to int (W is unsigned) + __m128i vResulti = _mm_cvtps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,ScaleMask); + // To fix W, add itself to shift it up to <<30 instead of <<29 + __m128i vResultw = _mm_and_si128(vResulti,g_XMMaskW); + vResulti = _mm_add_epi32(vResulti,vResultw); + // Do a horizontal or of all 4 entries + vResult = _mm_shuffle_ps(reinterpret_cast(&vResulti)[0],reinterpret_cast(&vResulti)[0],_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + vResulti = _mm_or_si128(vResulti,reinterpret_cast(&vResult)[0]); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreXDec4 +( + XMXDEC4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-511.0f, -511.0f, -511.0f, 0.0f}; + static CONST XMVECTOR Max = {511.0f, 511.0f, 511.0f, 3.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + + pDestination->v = ((UINT)N.vector4_f32[3] << 30) | + (((INT)N.vector4_f32[2] & 0x3FF) << 20) | + (((INT)N.vector4_f32[1] & 0x3FF) << 10) | + (((INT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MinXDec4 = {-511.0f,-511.0f,-511.0f, 0.0f}; + static const XMVECTORF32 MaxXDec4 = { 511.0f, 511.0f, 511.0f, 3.0f}; + static const XMVECTORF32 ScaleXDec4 = {1.0f,1024.0f/2.0f,1024.0f*1024.0f,1024.0f*1024.0f*1024.0f/2.0f}; + static const XMVECTORI32 MaskXDec4= {0x3FF,0x3FF<<(10-1),0x3FF<<20,0x3<<(30-1)}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,MinXDec4); + vResult = _mm_min_ps(vResult,MaxXDec4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleXDec4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskXDec4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // Perform a single bit left shift on y|w + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUDecN4 +( + XMUDECN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {1023.0f, 1023.0f, 1023.0f, 3.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiply(N, Scale.v); + + pDestination->v = ((UINT)N.vector4_f32[3] << 30) | + (((UINT)N.vector4_f32[2] & 0x3FF) << 20) | + (((UINT)N.vector4_f32[1] & 0x3FF) << 10) | + (((UINT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleUDecN4 = {1023.0f,1023.0f*1024.0f*0.5f,1023.0f*1024.0f*1024.0f,3.0f*1024.0f*1024.0f*1024.0f*0.5f}; + static const XMVECTORI32 MaskUDecN4= {0x3FF,0x3FF<<(10-1),0x3FF<<20,0x3<<(30-1)}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUDecN4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUDecN4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // Perform a left shift by one bit on y|w + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUDec4 +( + XMUDEC4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {1023.0f, 1023.0f, 1023.0f, 3.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + + pDestination->v = ((UINT)N.vector4_f32[3] << 30) | + (((UINT)N.vector4_f32[2] & 0x3FF) << 20) | + (((UINT)N.vector4_f32[1] & 0x3FF) << 10) | + (((UINT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MaxUDec4 = { 1023.0f, 1023.0f, 1023.0f, 3.0f}; + static const XMVECTORF32 ScaleUDec4 = {1.0f,1024.0f/2.0f,1024.0f*1024.0f,1024.0f*1024.0f*1024.0f/2.0f}; + static const XMVECTORI32 MaskUDec4= {0x3FF,0x3FF<<(10-1),0x3FF<<20,0x3<<(30-1)}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,MaxUDec4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUDec4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUDec4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // Perform a left shift by one bit on y|w + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreDecN4 +( + XMDECN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {511.0f, 511.0f, 511.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(N, Scale.v); + + pDestination->v = ((INT)N.vector4_f32[3] << 30) | + (((INT)N.vector4_f32[2] & 0x3FF) << 20) | + (((INT)N.vector4_f32[1] & 0x3FF) << 10) | + (((INT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleDecN4 = {511.0f,511.0f*1024.0f,511.0f*1024.0f*1024.0f,1.0f*1024.0f*1024.0f*1024.0f}; + static const XMVECTORI32 MaskDecN4= {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<30}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleDecN4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskDecN4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreDec4 +( + XMDEC4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-511.0f, -511.0f, -511.0f, -1.0f}; + static CONST XMVECTOR Max = {511.0f, 511.0f, 511.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + + pDestination->v = ((INT)N.vector4_f32[3] << 30) | + (((INT)N.vector4_f32[2] & 0x3FF) << 20) | + (((INT)N.vector4_f32[1] & 0x3FF) << 10) | + (((INT)N.vector4_f32[0] & 0x3FF)); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MinDec4 = {-511.0f,-511.0f,-511.0f,-1.0f}; + static const XMVECTORF32 MaxDec4 = { 511.0f, 511.0f, 511.0f, 1.0f}; + static const XMVECTORF32 ScaleDec4 = {1.0f,1024.0f,1024.0f*1024.0f,1024.0f*1024.0f*1024.0f}; + static const XMVECTORI32 MaskDec4= {0x3FF,0x3FF<<10,0x3FF<<20,0x3<<30}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,MinDec4); + vResult = _mm_min_ps(vResult,MaxDec4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleDec4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskDec4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUByteN4 +( + XMUBYTEN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {255.0f, 255.0f, 255.0f, 255.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + pDestination->x = (BYTE)N.vector4_f32[0]; + pDestination->y = (BYTE)N.vector4_f32[1]; + pDestination->z = (BYTE)N.vector4_f32[2]; + pDestination->w = (BYTE)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleUByteN4 = {255.0f,255.0f*256.0f*0.5f,255.0f*256.0f*256.0f,255.0f*256.0f*256.0f*256.0f*0.5f}; + static const XMVECTORI32 MaskUByteN4 = {0xFF,0xFF<<(8-1),0xFF<<16,0xFF<<(24-1)}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUByteN4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUByteN4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // Perform a single bit left shift to fix y|w + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUByte4 +( + XMUBYTE4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Max = {255.0f, 255.0f, 255.0f, 255.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max); + N = XMVectorRound(N); + + pDestination->x = (BYTE)N.vector4_f32[0]; + pDestination->y = (BYTE)N.vector4_f32[1]; + pDestination->z = (BYTE)N.vector4_f32[2]; + pDestination->w = (BYTE)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MaxUByte4 = { 255.0f, 255.0f, 255.0f, 255.0f}; + static const XMVECTORF32 ScaleUByte4 = {1.0f,256.0f*0.5f,256.0f*256.0f,256.0f*256.0f*256.0f*0.5f}; + static const XMVECTORI32 MaskUByte4 = {0xFF,0xFF<<(8-1),0xFF<<16,0xFF<<(24-1)}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,MaxUByte4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleUByte4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskUByte4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // Perform a single bit left shift to fix y|w + vResulti2 = _mm_add_epi32(vResulti2,vResulti2); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreByteN4 +( + XMBYTEN4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {127.0f, 127.0f, 127.0f, 127.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v); + N = XMVectorMultiply(V, Scale.v); + N = XMVectorRound(N); + + pDestination->x = (CHAR)N.vector4_f32[0]; + pDestination->y = (CHAR)N.vector4_f32[1]; + pDestination->z = (CHAR)N.vector4_f32[2]; + pDestination->w = (CHAR)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 ScaleByteN4 = {127.0f,127.0f*256.0f,127.0f*256.0f*256.0f,127.0f*256.0f*256.0f*256.0f}; + static const XMVECTORI32 MaskByteN4 = {0xFF,0xFF<<8,0xFF<<16,0xFF<<24}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleByteN4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskByteN4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreByte4 +( + XMBYTE4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTOR Min = {-127.0f, -127.0f, -127.0f, -127.0f}; + static CONST XMVECTOR Max = {127.0f, 127.0f, 127.0f, 127.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, Min, Max); + N = XMVectorRound(N); + + pDestination->x = (CHAR)N.vector4_f32[0]; + pDestination->y = (CHAR)N.vector4_f32[1]; + pDestination->z = (CHAR)N.vector4_f32[2]; + pDestination->w = (CHAR)N.vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static const XMVECTORF32 MinByte4 = {-127.0f,-127.0f,-127.0f,-127.0f}; + static const XMVECTORF32 MaxByte4 = { 127.0f, 127.0f, 127.0f, 127.0f}; + static const XMVECTORF32 ScaleByte4 = {1.0f,256.0f,256.0f*256.0f,256.0f*256.0f*256.0f}; + static const XMVECTORI32 MaskByte4 = {0xFF,0xFF<<8,0xFF<<16,0xFF<<24}; + // Clamp to bounds + XMVECTOR vResult = _mm_max_ps(V,MinByte4); + vResult = _mm_min_ps(vResult,MaxByte4); + // Scale by multiplication + vResult = _mm_mul_ps(vResult,ScaleByte4); + // Convert to int + __m128i vResulti = _mm_cvttps_epi32(vResult); + // Mask off any fraction + vResulti = _mm_and_si128(vResulti,MaskByte4); + // Do a horizontal or of 4 entries + __m128i vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(3,2,3,2)); + // x = x|z, y = y|w + vResulti = _mm_or_si128(vResulti,vResulti2); + // Move Z to the x position + vResulti2 = _mm_shuffle_epi32(vResulti,_MM_SHUFFLE(1,1,1,1)); + // i = x|y|z|w + vResulti = _mm_or_si128(vResulti,vResulti2); + _mm_store_ss(reinterpret_cast(&pDestination->v),reinterpret_cast(&vResulti)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreUNibble4 +( + XMUNIBBLE4* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Max = {15.0f,15.0f,15.0f,15.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // No SSE operations will write to 16-bit values, so we have to extract them manually + USHORT x = static_cast(_mm_extract_epi16(vInt,0)); + USHORT y = static_cast(_mm_extract_epi16(vInt,2)); + USHORT z = static_cast(_mm_extract_epi16(vInt,4)); + USHORT w = static_cast(_mm_extract_epi16(vInt,6)); + pDestination->v = ((w & 0xF) << 12) | + ((z & 0xF) << 8) | + ((y & 0xF) << 4) | + ((x & 0xF)); +#else + XMVECTOR N; + static CONST XMVECTORF32 Max = {15.0f,15.0f,15.0f,15.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max.v); + N = XMVectorRound(N); + + pDestination->v = (((USHORT)N.vector4_f32[3] & 0xF) << 12) | + (((USHORT)N.vector4_f32[2] & 0xF) << 8) | + (((USHORT)N.vector4_f32[1] & 0xF) << 4) | + (((USHORT)N.vector4_f32[0] & 0xF)); +#endif !_XM_SSE_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreU555( + XMU555* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Max = {31.0f, 31.0f, 31.0f, 1.0f}; + // Bounds check + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + vResult = _mm_min_ps(vResult,Max); + // Convert to int with rounding + __m128i vInt = _mm_cvtps_epi32(vResult); + // No SSE operations will write to 16-bit values, so we have to extract them manually + USHORT x = static_cast(_mm_extract_epi16(vInt,0)); + USHORT y = static_cast(_mm_extract_epi16(vInt,2)); + USHORT z = static_cast(_mm_extract_epi16(vInt,4)); + USHORT w = static_cast(_mm_extract_epi16(vInt,6)); + pDestination->v = ((w) ? 0x8000 : 0) | + ((z & 0x1F) << 10) | + ((y & 0x1F) << 5) | + ((x & 0x1F)); +#else + XMVECTOR N; + static CONST XMVECTORF32 Max = {31.0f, 31.0f, 31.0f, 1.0f}; + + XMASSERT(pDestination); + + N = XMVectorClamp(V, XMVectorZero(), Max.v); + N = XMVectorRound(N); + + pDestination->v = ((N.vector4_f32[3] > 0.f) ? 0x8000 : 0) | + (((USHORT)N.vector4_f32[2] & 0x1F) << 10) | + (((USHORT)N.vector4_f32[1] & 0x1F) << 5) | + (((USHORT)N.vector4_f32[0] & 0x1F)); +#endif !_XM_SSE_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreColor +( + XMCOLOR* pDestination, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + static CONST XMVECTORF32 Scale = {255.0f, 255.0f, 255.0f, 255.0f}; + + XMASSERT(pDestination); + + N = XMVectorSaturate(V); + N = XMVectorMultiply(N, Scale.v); + N = XMVectorRound(N); + + pDestination->c = ((UINT)N.vector4_f32[3] << 24) | + ((UINT)N.vector4_f32[0] << 16) | + ((UINT)N.vector4_f32[1] << 8) | + ((UINT)N.vector4_f32[2]); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + static CONST XMVECTORF32 Scale = {255.0f,255.0f,255.0f,255.0f}; + // Set <0 to 0 + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + // Set>1 to 1 + vResult = _mm_min_ps(vResult,g_XMOne); + // Convert to 0-255 + vResult = _mm_mul_ps(vResult,Scale); + // Shuffle RGBA to ARGB + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,0,1,2)); + // Convert to int + __m128i vInt = _mm_cvtps_epi32(vResult); + // Mash to shorts + vInt = _mm_packs_epi32(vInt,vInt); + // Mash to bytes + vInt = _mm_packus_epi16(vInt,vInt); + // Store the color + _mm_store_ss(reinterpret_cast(&pDestination->c),reinterpret_cast<__m128 *>(&vInt)[0]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat3x3 +( + XMFLOAT3X3* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) || defined(_XM_SSE_INTRINSICS_) + + XMStoreFloat3x3NC(pDestination, M); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat3x3NC +( + XMFLOAT3X3* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->m[0][0] = M.r[0].vector4_f32[0]; + pDestination->m[0][1] = M.r[0].vector4_f32[1]; + pDestination->m[0][2] = M.r[0].vector4_f32[2]; + + pDestination->m[1][0] = M.r[1].vector4_f32[0]; + pDestination->m[1][1] = M.r[1].vector4_f32[1]; + pDestination->m[1][2] = M.r[1].vector4_f32[2]; + + pDestination->m[2][0] = M.r[2].vector4_f32[0]; + pDestination->m[2][1] = M.r[2].vector4_f32[1]; + pDestination->m[2][2] = M.r[2].vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMVECTOR vTemp1 = M.r[0]; + XMVECTOR vTemp2 = M.r[1]; + XMVECTOR vTemp3 = M.r[2]; + XMVECTOR vWork = _mm_shuffle_ps(vTemp1,vTemp2,_MM_SHUFFLE(0,0,2,2)); + vTemp1 = _mm_shuffle_ps(vTemp1,vWork,_MM_SHUFFLE(2,0,1,0)); + _mm_storeu_ps(&pDestination->m[0][0],vTemp1); + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp3,_MM_SHUFFLE(1,0,2,1)); + _mm_storeu_ps(&pDestination->m[1][1],vTemp2); + vTemp3 = _mm_shuffle_ps(vTemp3,vTemp3,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss(&pDestination->m[2][2],vTemp3); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4x3 +( + XMFLOAT4X3* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) || defined(_XM_SSE_INTRINSICS_) + + XMStoreFloat4x3NC(pDestination, M); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4x3A +( + XMFLOAT4X3A* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination->m[0][0] = M.r[0].vector4_f32[0]; + pDestination->m[0][1] = M.r[0].vector4_f32[1]; + pDestination->m[0][2] = M.r[0].vector4_f32[2]; + + pDestination->m[1][0] = M.r[1].vector4_f32[0]; + pDestination->m[1][1] = M.r[1].vector4_f32[1]; + pDestination->m[1][2] = M.r[1].vector4_f32[2]; + + pDestination->m[2][0] = M.r[2].vector4_f32[0]; + pDestination->m[2][1] = M.r[2].vector4_f32[1]; + pDestination->m[2][2] = M.r[2].vector4_f32[2]; + + pDestination->m[3][0] = M.r[3].vector4_f32[0]; + pDestination->m[3][1] = M.r[3].vector4_f32[1]; + pDestination->m[3][2] = M.r[3].vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + // x1,y1,z1,w1 + XMVECTOR vTemp1 = M.r[0]; + // x2,y2,z2,w2 + XMVECTOR vTemp2 = M.r[1]; + // x3,y3,z3,w3 + XMVECTOR vTemp3 = M.r[2]; + // x4,y4,z4,w4 + XMVECTOR vTemp4 = M.r[3]; + // z1,z1,x2,y2 + XMVECTOR vTemp = _mm_shuffle_ps(vTemp1,vTemp2,_MM_SHUFFLE(1,0,2,2)); + // y2,z2,x3,y3 (Final) + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp3,_MM_SHUFFLE(1,0,2,1)); + // x1,y1,z1,x2 (Final) + vTemp1 = _mm_shuffle_ps(vTemp1,vTemp,_MM_SHUFFLE(2,0,1,0)); + // z3,z3,x4,x4 + vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(0,0,2,2)); + // z3,x4,y4,z4 (Final) + vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(2,1,2,0)); + // Store in 3 operations + _mm_store_ps(&pDestination->m[0][0],vTemp1); + _mm_store_ps(&pDestination->m[1][1],vTemp2); + _mm_store_ps(&pDestination->m[2][2],vTemp3); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4x3NC +( + XMFLOAT4X3* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->m[0][0] = M.r[0].vector4_f32[0]; + pDestination->m[0][1] = M.r[0].vector4_f32[1]; + pDestination->m[0][2] = M.r[0].vector4_f32[2]; + + pDestination->m[1][0] = M.r[1].vector4_f32[0]; + pDestination->m[1][1] = M.r[1].vector4_f32[1]; + pDestination->m[1][2] = M.r[1].vector4_f32[2]; + + pDestination->m[2][0] = M.r[2].vector4_f32[0]; + pDestination->m[2][1] = M.r[2].vector4_f32[1]; + pDestination->m[2][2] = M.r[2].vector4_f32[2]; + + pDestination->m[3][0] = M.r[3].vector4_f32[0]; + pDestination->m[3][1] = M.r[3].vector4_f32[1]; + pDestination->m[3][2] = M.r[3].vector4_f32[2]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + XMVECTOR vTemp1 = M.r[0]; + XMVECTOR vTemp2 = M.r[1]; + XMVECTOR vTemp3 = M.r[2]; + XMVECTOR vTemp4 = M.r[3]; + XMVECTOR vTemp2x = _mm_shuffle_ps(vTemp2,vTemp3,_MM_SHUFFLE(1,0,2,1)); + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp1,_MM_SHUFFLE(2,2,0,0)); + vTemp1 = _mm_shuffle_ps(vTemp1,vTemp2,_MM_SHUFFLE(0,2,1,0)); + vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(0,0,2,2)); + vTemp3 = _mm_shuffle_ps(vTemp3,vTemp4,_MM_SHUFFLE(2,1,2,0)); + _mm_storeu_ps(&pDestination->m[0][0],vTemp1); + _mm_storeu_ps(&pDestination->m[1][1],vTemp2x); + _mm_storeu_ps(&pDestination->m[2][2],vTemp3); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4x4 +( + XMFLOAT4X4* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) + + XMStoreFloat4x4NC(pDestination, M); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + + _mm_storeu_ps( &pDestination->_11, M.r[0] ); + _mm_storeu_ps( &pDestination->_21, M.r[1] ); + _mm_storeu_ps( &pDestination->_31, M.r[2] ); + _mm_storeu_ps( &pDestination->_41, M.r[3] ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4x4A +( + XMFLOAT4X4A* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + XMASSERT(((UINT_PTR)pDestination & 0xF) == 0); + + pDestination->m[0][0] = M.r[0].vector4_f32[0]; + pDestination->m[0][1] = M.r[0].vector4_f32[1]; + pDestination->m[0][2] = M.r[0].vector4_f32[2]; + pDestination->m[0][3] = M.r[0].vector4_f32[3]; + + pDestination->m[1][0] = M.r[1].vector4_f32[0]; + pDestination->m[1][1] = M.r[1].vector4_f32[1]; + pDestination->m[1][2] = M.r[1].vector4_f32[2]; + pDestination->m[1][3] = M.r[1].vector4_f32[3]; + + pDestination->m[2][0] = M.r[2].vector4_f32[0]; + pDestination->m[2][1] = M.r[2].vector4_f32[1]; + pDestination->m[2][2] = M.r[2].vector4_f32[2]; + pDestination->m[2][3] = M.r[2].vector4_f32[3]; + + pDestination->m[3][0] = M.r[3].vector4_f32[0]; + pDestination->m[3][1] = M.r[3].vector4_f32[1]; + pDestination->m[3][2] = M.r[3].vector4_f32[2]; + pDestination->m[3][3] = M.r[3].vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + + _mm_store_ps( &pDestination->_11, M.r[0] ); + _mm_store_ps( &pDestination->_21, M.r[1] ); + _mm_store_ps( &pDestination->_31, M.r[2] ); + _mm_store_ps( &pDestination->_41, M.r[3] ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMStoreFloat4x4NC +( + XMFLOAT4X4* pDestination, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMASSERT(pDestination); + + pDestination->m[0][0] = M.r[0].vector4_f32[0]; + pDestination->m[0][1] = M.r[0].vector4_f32[1]; + pDestination->m[0][2] = M.r[0].vector4_f32[2]; + pDestination->m[0][3] = M.r[0].vector4_f32[3]; + + pDestination->m[1][0] = M.r[1].vector4_f32[0]; + pDestination->m[1][1] = M.r[1].vector4_f32[1]; + pDestination->m[1][2] = M.r[1].vector4_f32[2]; + pDestination->m[1][3] = M.r[1].vector4_f32[3]; + + pDestination->m[2][0] = M.r[2].vector4_f32[0]; + pDestination->m[2][1] = M.r[2].vector4_f32[1]; + pDestination->m[2][2] = M.r[2].vector4_f32[2]; + pDestination->m[2][3] = M.r[2].vector4_f32[3]; + + pDestination->m[3][0] = M.r[3].vector4_f32[0]; + pDestination->m[3][1] = M.r[3].vector4_f32[1]; + pDestination->m[3][2] = M.r[3].vector4_f32[2]; + pDestination->m[3][3] = M.r[3].vector4_f32[3]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pDestination); + _mm_storeu_ps(&pDestination->m[0][0],M.r[0]); + _mm_storeu_ps(&pDestination->m[1][0],M.r[1]); + _mm_storeu_ps(&pDestination->m[2][0],M.r[2]); + _mm_storeu_ps(&pDestination->m[3][0],M.r[3]); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +#endif // __XNAMATHCONVERT_INL__ + diff --git a/third_party/xbox_sdk/include/xnamathmatrix.inl b/third_party/xbox_sdk/include/xnamathmatrix.inl new file mode 100644 index 0000000..eb9f164 --- /dev/null +++ b/third_party/xbox_sdk/include/xnamathmatrix.inl @@ -0,0 +1,3293 @@ +/************************************************************************ +* * +* xnamathmatrix.inl -- SIMD C++ Math library for Windows and Xbox 360 * +* Matrix functions * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ + +#if defined(_MSC_VER) && (_MSC_VER > 1000) +#pragma once +#endif + +#ifndef __XNAMATHMATRIX_INL__ +#define __XNAMATHMATRIX_INL__ + +/**************************************************************************** + * + * Matrix + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +// Return TRUE if any entry in the matrix is NaN +XMFINLINE BOOL XMMatrixIsNaN +( + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT i, uTest; + const UINT *pWork; + + i = 16; + pWork = (const UINT *)(&M.m[0][0]); + do { + // Fetch value into integer unit + uTest = pWork[0]; + // Remove sign + uTest &= 0x7FFFFFFFU; + // NaN is 0x7F800001 through 0x7FFFFFFF inclusive + uTest -= 0x7F800001U; + if (uTest<0x007FFFFFU) { + break; // NaN found + } + ++pWork; // Next entry + } while (--i); + return (i!=0); // i == 0 if nothing matched +#elif defined(_XM_SSE_INTRINSICS_) + // Load in registers + XMVECTOR vX = M.r[0]; + XMVECTOR vY = M.r[1]; + XMVECTOR vZ = M.r[2]; + XMVECTOR vW = M.r[3]; + // Test themselves to check for NaN + vX = _mm_cmpneq_ps(vX,vX); + vY = _mm_cmpneq_ps(vY,vY); + vZ = _mm_cmpneq_ps(vZ,vZ); + vW = _mm_cmpneq_ps(vW,vW); + // Or all the results + vX = _mm_or_ps(vX,vZ); + vY = _mm_or_ps(vY,vW); + vX = _mm_or_ps(vX,vY); + // If any tested true, return true + return (_mm_movemask_ps(vX)!=0); +#else +#endif +} + +//------------------------------------------------------------------------------ + +// Return TRUE if any entry in the matrix is +/-INF +XMFINLINE BOOL XMMatrixIsInfinite +( + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT i, uTest; + const UINT *pWork; + + i = 16; + pWork = (const UINT *)(&M.m[0][0]); + do { + // Fetch value into integer unit + uTest = pWork[0]; + // Remove sign + uTest &= 0x7FFFFFFFU; + // INF is 0x7F800000 + if (uTest==0x7F800000U) { + break; // INF found + } + ++pWork; // Next entry + } while (--i); + return (i!=0); // i == 0 if nothing matched +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the sign bits + XMVECTOR vTemp1 = _mm_and_ps(M.r[0],g_XMAbsMask); + XMVECTOR vTemp2 = _mm_and_ps(M.r[1],g_XMAbsMask); + XMVECTOR vTemp3 = _mm_and_ps(M.r[2],g_XMAbsMask); + XMVECTOR vTemp4 = _mm_and_ps(M.r[3],g_XMAbsMask); + // Compare to infinity + vTemp1 = _mm_cmpeq_ps(vTemp1,g_XMInfinity); + vTemp2 = _mm_cmpeq_ps(vTemp2,g_XMInfinity); + vTemp3 = _mm_cmpeq_ps(vTemp3,g_XMInfinity); + vTemp4 = _mm_cmpeq_ps(vTemp4,g_XMInfinity); + // Or the answers together + vTemp1 = _mm_or_ps(vTemp1,vTemp2); + vTemp3 = _mm_or_ps(vTemp3,vTemp4); + vTemp1 = _mm_or_ps(vTemp1,vTemp3); + // If any are infinity, the signs are true. + return (_mm_movemask_ps(vTemp1)!=0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Return TRUE if the XMMatrix is equal to identity +XMFINLINE BOOL XMMatrixIsIdentity +( + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + unsigned int uOne, uZero; + const unsigned int *pWork; + + // Use the integer pipeline to reduce branching to a minimum + pWork = (const unsigned int*)(&M.m[0][0]); + // Convert 1.0f to zero and or them together + uOne = pWork[0]^0x3F800000U; + // Or all the 0.0f entries together + uZero = pWork[1]; + uZero |= pWork[2]; + uZero |= pWork[3]; + // 2nd row + uZero |= pWork[4]; + uOne |= pWork[5]^0x3F800000U; + uZero |= pWork[6]; + uZero |= pWork[7]; + // 3rd row + uZero |= pWork[8]; + uZero |= pWork[9]; + uOne |= pWork[10]^0x3F800000U; + uZero |= pWork[11]; + // 4th row + uZero |= pWork[12]; + uZero |= pWork[13]; + uZero |= pWork[14]; + uOne |= pWork[15]^0x3F800000U; + // If all zero entries are zero, the uZero==0 + uZero &= 0x7FFFFFFF; // Allow -0.0f + // If all 1.0f entries are 1.0f, then uOne==0 + uOne |= uZero; + return (uOne==0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp1 = _mm_cmpeq_ps(M.r[0],g_XMIdentityR0); + XMVECTOR vTemp2 = _mm_cmpeq_ps(M.r[1],g_XMIdentityR1); + XMVECTOR vTemp3 = _mm_cmpeq_ps(M.r[2],g_XMIdentityR2); + XMVECTOR vTemp4 = _mm_cmpeq_ps(M.r[3],g_XMIdentityR3); + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + vTemp3 = _mm_and_ps(vTemp3,vTemp4); + vTemp1 = _mm_and_ps(vTemp1,vTemp3); + return (_mm_movemask_ps(vTemp1)==0x0f); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Perform a 4x4 matrix multiply by a 4x4 matrix +XMFINLINE XMMATRIX XMMatrixMultiply +( + CXMMATRIX M1, + CXMMATRIX M2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX mResult; + // Cache the invariants in registers + float x = M1.m[0][0]; + float y = M1.m[0][1]; + float z = M1.m[0][2]; + float w = M1.m[0][3]; + // Perform the operation on the first row + mResult.m[0][0] = (M2.m[0][0]*x)+(M2.m[1][0]*y)+(M2.m[2][0]*z)+(M2.m[3][0]*w); + mResult.m[0][1] = (M2.m[0][1]*x)+(M2.m[1][1]*y)+(M2.m[2][1]*z)+(M2.m[3][1]*w); + mResult.m[0][2] = (M2.m[0][2]*x)+(M2.m[1][2]*y)+(M2.m[2][2]*z)+(M2.m[3][2]*w); + mResult.m[0][3] = (M2.m[0][3]*x)+(M2.m[1][3]*y)+(M2.m[2][3]*z)+(M2.m[3][3]*w); + // Repeat for all the other rows + x = M1.m[1][0]; + y = M1.m[1][1]; + z = M1.m[1][2]; + w = M1.m[1][3]; + mResult.m[1][0] = (M2.m[0][0]*x)+(M2.m[1][0]*y)+(M2.m[2][0]*z)+(M2.m[3][0]*w); + mResult.m[1][1] = (M2.m[0][1]*x)+(M2.m[1][1]*y)+(M2.m[2][1]*z)+(M2.m[3][1]*w); + mResult.m[1][2] = (M2.m[0][2]*x)+(M2.m[1][2]*y)+(M2.m[2][2]*z)+(M2.m[3][2]*w); + mResult.m[1][3] = (M2.m[0][3]*x)+(M2.m[1][3]*y)+(M2.m[2][3]*z)+(M2.m[3][3]*w); + x = M1.m[2][0]; + y = M1.m[2][1]; + z = M1.m[2][2]; + w = M1.m[2][3]; + mResult.m[2][0] = (M2.m[0][0]*x)+(M2.m[1][0]*y)+(M2.m[2][0]*z)+(M2.m[3][0]*w); + mResult.m[2][1] = (M2.m[0][1]*x)+(M2.m[1][1]*y)+(M2.m[2][1]*z)+(M2.m[3][1]*w); + mResult.m[2][2] = (M2.m[0][2]*x)+(M2.m[1][2]*y)+(M2.m[2][2]*z)+(M2.m[3][2]*w); + mResult.m[2][3] = (M2.m[0][3]*x)+(M2.m[1][3]*y)+(M2.m[2][3]*z)+(M2.m[3][3]*w); + x = M1.m[3][0]; + y = M1.m[3][1]; + z = M1.m[3][2]; + w = M1.m[3][3]; + mResult.m[3][0] = (M2.m[0][0]*x)+(M2.m[1][0]*y)+(M2.m[2][0]*z)+(M2.m[3][0]*w); + mResult.m[3][1] = (M2.m[0][1]*x)+(M2.m[1][1]*y)+(M2.m[2][1]*z)+(M2.m[3][1]*w); + mResult.m[3][2] = (M2.m[0][2]*x)+(M2.m[1][2]*y)+(M2.m[2][2]*z)+(M2.m[3][2]*w); + mResult.m[3][3] = (M2.m[0][3]*x)+(M2.m[1][3]*y)+(M2.m[2][3]*z)+(M2.m[3][3]*w); + return mResult; +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX mResult; + // Use vW to hold the original row + XMVECTOR vW = M1.r[0]; + // Splat the component X,Y,Z then W + XMVECTOR vX = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(0,0,0,0)); + XMVECTOR vY = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR vZ = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(2,2,2,2)); + vW = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(3,3,3,3)); + // Perform the opertion on the first row + vX = _mm_mul_ps(vX,M2.r[0]); + vY = _mm_mul_ps(vY,M2.r[1]); + vZ = _mm_mul_ps(vZ,M2.r[2]); + vW = _mm_mul_ps(vW,M2.r[3]); + // Perform a binary add to reduce cumulative errors + vX = _mm_add_ps(vX,vZ); + vY = _mm_add_ps(vY,vW); + vX = _mm_add_ps(vX,vY); + mResult.r[0] = vX; + // Repeat for the other 3 rows + vW = M1.r[1]; + vX = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(0,0,0,0)); + vY = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(1,1,1,1)); + vZ = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(2,2,2,2)); + vW = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(3,3,3,3)); + vX = _mm_mul_ps(vX,M2.r[0]); + vY = _mm_mul_ps(vY,M2.r[1]); + vZ = _mm_mul_ps(vZ,M2.r[2]); + vW = _mm_mul_ps(vW,M2.r[3]); + vX = _mm_add_ps(vX,vZ); + vY = _mm_add_ps(vY,vW); + vX = _mm_add_ps(vX,vY); + mResult.r[1] = vX; + vW = M1.r[2]; + vX = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(0,0,0,0)); + vY = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(1,1,1,1)); + vZ = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(2,2,2,2)); + vW = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(3,3,3,3)); + vX = _mm_mul_ps(vX,M2.r[0]); + vY = _mm_mul_ps(vY,M2.r[1]); + vZ = _mm_mul_ps(vZ,M2.r[2]); + vW = _mm_mul_ps(vW,M2.r[3]); + vX = _mm_add_ps(vX,vZ); + vY = _mm_add_ps(vY,vW); + vX = _mm_add_ps(vX,vY); + mResult.r[2] = vX; + vW = M1.r[3]; + vX = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(0,0,0,0)); + vY = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(1,1,1,1)); + vZ = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(2,2,2,2)); + vW = _mm_shuffle_ps(vW,vW,_MM_SHUFFLE(3,3,3,3)); + vX = _mm_mul_ps(vX,M2.r[0]); + vY = _mm_mul_ps(vY,M2.r[1]); + vZ = _mm_mul_ps(vZ,M2.r[2]); + vW = _mm_mul_ps(vW,M2.r[3]); + vX = _mm_add_ps(vX,vZ); + vY = _mm_add_ps(vY,vW); + vX = _mm_add_ps(vX,vY); + mResult.r[3] = vX; + return mResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixMultiplyTranspose +( + CXMMATRIX M1, + CXMMATRIX M2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX mResult; + // Cache the invariants in registers + float x = M2.m[0][0]; + float y = M2.m[1][0]; + float z = M2.m[2][0]; + float w = M2.m[3][0]; + // Perform the operation on the first row + mResult.m[0][0] = (M1.m[0][0]*x)+(M1.m[0][1]*y)+(M1.m[0][2]*z)+(M1.m[0][3]*w); + mResult.m[0][1] = (M1.m[1][0]*x)+(M1.m[1][1]*y)+(M1.m[1][2]*z)+(M1.m[1][3]*w); + mResult.m[0][2] = (M1.m[2][0]*x)+(M1.m[2][1]*y)+(M1.m[2][2]*z)+(M1.m[2][3]*w); + mResult.m[0][3] = (M1.m[3][0]*x)+(M1.m[3][1]*y)+(M1.m[3][2]*z)+(M1.m[3][3]*w); + // Repeat for all the other rows + x = M2.m[0][1]; + y = M2.m[1][1]; + z = M2.m[2][1]; + w = M2.m[3][1]; + mResult.m[1][0] = (M1.m[0][0]*x)+(M1.m[0][1]*y)+(M1.m[0][2]*z)+(M1.m[0][3]*w); + mResult.m[1][1] = (M1.m[1][0]*x)+(M1.m[1][1]*y)+(M1.m[1][2]*z)+(M1.m[1][3]*w); + mResult.m[1][2] = (M1.m[2][0]*x)+(M1.m[2][1]*y)+(M1.m[2][2]*z)+(M1.m[2][3]*w); + mResult.m[1][3] = (M1.m[3][0]*x)+(M1.m[3][1]*y)+(M1.m[3][2]*z)+(M1.m[3][3]*w); + x = M2.m[0][2]; + y = M2.m[1][2]; + z = M2.m[2][2]; + w = M2.m[3][2]; + mResult.m[2][0] = (M1.m[0][0]*x)+(M1.m[0][1]*y)+(M1.m[0][2]*z)+(M1.m[0][3]*w); + mResult.m[2][1] = (M1.m[1][0]*x)+(M1.m[1][1]*y)+(M1.m[1][2]*z)+(M1.m[1][3]*w); + mResult.m[2][2] = (M1.m[2][0]*x)+(M1.m[2][1]*y)+(M1.m[2][2]*z)+(M1.m[2][3]*w); + mResult.m[2][3] = (M1.m[3][0]*x)+(M1.m[3][1]*y)+(M1.m[3][2]*z)+(M1.m[3][3]*w); + x = M2.m[0][3]; + y = M2.m[1][3]; + z = M2.m[2][3]; + w = M2.m[3][3]; + mResult.m[3][0] = (M1.m[0][0]*x)+(M1.m[0][1]*y)+(M1.m[0][2]*z)+(M1.m[0][3]*w); + mResult.m[3][1] = (M1.m[1][0]*x)+(M1.m[1][1]*y)+(M1.m[1][2]*z)+(M1.m[1][3]*w); + mResult.m[3][2] = (M1.m[2][0]*x)+(M1.m[2][1]*y)+(M1.m[2][2]*z)+(M1.m[2][3]*w); + mResult.m[3][3] = (M1.m[3][0]*x)+(M1.m[3][1]*y)+(M1.m[3][2]*z)+(M1.m[3][3]*w); + return mResult; +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX Product; + XMMATRIX Result; + Product = XMMatrixMultiply(M1, M2); + Result = XMMatrixTranspose(Product); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixTranspose +( + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX P; + XMMATRIX MT; + + // Original matrix: + // + // m00m01m02m03 + // m10m11m12m13 + // m20m21m22m23 + // m30m31m32m33 + + P.r[0] = XMVectorMergeXY(M.r[0], M.r[2]); // m00m20m01m21 + P.r[1] = XMVectorMergeXY(M.r[1], M.r[3]); // m10m30m11m31 + P.r[2] = XMVectorMergeZW(M.r[0], M.r[2]); // m02m22m03m23 + P.r[3] = XMVectorMergeZW(M.r[1], M.r[3]); // m12m32m13m33 + + MT.r[0] = XMVectorMergeXY(P.r[0], P.r[1]); // m00m10m20m30 + MT.r[1] = XMVectorMergeZW(P.r[0], P.r[1]); // m01m11m21m31 + MT.r[2] = XMVectorMergeXY(P.r[2], P.r[3]); // m02m12m22m32 + MT.r[3] = XMVectorMergeZW(P.r[2], P.r[3]); // m03m13m23m33 + + return MT; + +#elif defined(_XM_SSE_INTRINSICS_) + // x.x,x.y,y.x,y.y + XMVECTOR vTemp1 = _mm_shuffle_ps(M.r[0],M.r[1],_MM_SHUFFLE(1,0,1,0)); + // x.z,x.w,y.z,y.w + XMVECTOR vTemp3 = _mm_shuffle_ps(M.r[0],M.r[1],_MM_SHUFFLE(3,2,3,2)); + // z.x,z.y,w.x,w.y + XMVECTOR vTemp2 = _mm_shuffle_ps(M.r[2],M.r[3],_MM_SHUFFLE(1,0,1,0)); + // z.z,z.w,w.z,w.w + XMVECTOR vTemp4 = _mm_shuffle_ps(M.r[2],M.r[3],_MM_SHUFFLE(3,2,3,2)); + XMMATRIX mResult; + + // x.x,y.x,z.x,w.x + mResult.r[0] = _mm_shuffle_ps(vTemp1, vTemp2,_MM_SHUFFLE(2,0,2,0)); + // x.y,y.y,z.y,w.y + mResult.r[1] = _mm_shuffle_ps(vTemp1, vTemp2,_MM_SHUFFLE(3,1,3,1)); + // x.z,y.z,z.z,w.z + mResult.r[2] = _mm_shuffle_ps(vTemp3, vTemp4,_MM_SHUFFLE(2,0,2,0)); + // x.w,y.w,z.w,w.w + mResult.r[3] = _mm_shuffle_ps(vTemp3, vTemp4,_MM_SHUFFLE(3,1,3,1)); + return mResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return the inverse and the determinant of a 4x4 matrix +XMINLINE XMMATRIX XMMatrixInverse +( + XMVECTOR* pDeterminant, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX R; + XMMATRIX MT; + XMVECTOR D0, D1, D2; + XMVECTOR C0, C1, C2, C3, C4, C5, C6, C7; + XMVECTOR V0[4], V1[4]; + XMVECTOR Determinant; + XMVECTOR Reciprocal; + XMMATRIX Result; + static CONST XMVECTORU32 SwizzleXXYY = {XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0Y}; + static CONST XMVECTORU32 SwizzleZWZW = {XM_PERMUTE_0Z, XM_PERMUTE_0W, XM_PERMUTE_0Z, XM_PERMUTE_0W}; + static CONST XMVECTORU32 SwizzleYZXY = {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0Y}; + static CONST XMVECTORU32 SwizzleZWYZ = {XM_PERMUTE_0Z, XM_PERMUTE_0W, XM_PERMUTE_0Y, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 SwizzleWXWX = {XM_PERMUTE_0W, XM_PERMUTE_0X, XM_PERMUTE_0W, XM_PERMUTE_0X}; + static CONST XMVECTORU32 SwizzleZXYX = {XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0X}; + static CONST XMVECTORU32 SwizzleYWXZ = {XM_PERMUTE_0Y, XM_PERMUTE_0W, XM_PERMUTE_0X, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 SwizzleWZWY = {XM_PERMUTE_0W, XM_PERMUTE_0Z, XM_PERMUTE_0W, XM_PERMUTE_0Y}; + static CONST XMVECTORU32 Permute0X0Z1X1Z = {XM_PERMUTE_0X, XM_PERMUTE_0Z, XM_PERMUTE_1X, XM_PERMUTE_1Z}; + static CONST XMVECTORU32 Permute0Y0W1Y1W = {XM_PERMUTE_0Y, XM_PERMUTE_0W, XM_PERMUTE_1Y, XM_PERMUTE_1W}; + static CONST XMVECTORU32 Permute1Y0Y0W0X = {XM_PERMUTE_1Y, XM_PERMUTE_0Y, XM_PERMUTE_0W, XM_PERMUTE_0X}; + static CONST XMVECTORU32 Permute0W0X0Y1X = {XM_PERMUTE_0W, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_1X}; + static CONST XMVECTORU32 Permute0Z1Y1X0Z = {XM_PERMUTE_0Z, XM_PERMUTE_1Y, XM_PERMUTE_1X, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 Permute0W1Y0Y0Z = {XM_PERMUTE_0W, XM_PERMUTE_1Y, XM_PERMUTE_0Y, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 Permute0Z0Y1X0X = {XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_1X, XM_PERMUTE_0X}; + static CONST XMVECTORU32 Permute1Y0X0W1X = {XM_PERMUTE_1Y, XM_PERMUTE_0X, XM_PERMUTE_0W, XM_PERMUTE_1X}; + static CONST XMVECTORU32 Permute1W0Y0W0X = {XM_PERMUTE_1W, XM_PERMUTE_0Y, XM_PERMUTE_0W, XM_PERMUTE_0X}; + static CONST XMVECTORU32 Permute0W0X0Y1Z = {XM_PERMUTE_0W, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_1Z}; + static CONST XMVECTORU32 Permute0Z1W1Z0Z = {XM_PERMUTE_0Z, XM_PERMUTE_1W, XM_PERMUTE_1Z, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 Permute0W1W0Y0Z = {XM_PERMUTE_0W, XM_PERMUTE_1W, XM_PERMUTE_0Y, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 Permute0Z0Y1Z0X = {XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_1Z, XM_PERMUTE_0X}; + static CONST XMVECTORU32 Permute1W0X0W1Z = {XM_PERMUTE_1W, XM_PERMUTE_0X, XM_PERMUTE_0W, XM_PERMUTE_1Z}; + + MT = XMMatrixTranspose(M); + + V0[0] = XMVectorPermute(MT.r[2], MT.r[2], SwizzleXXYY.v); + V1[0] = XMVectorPermute(MT.r[3], MT.r[3], SwizzleZWZW.v); + V0[1] = XMVectorPermute(MT.r[0], MT.r[0], SwizzleXXYY.v); + V1[1] = XMVectorPermute(MT.r[1], MT.r[1], SwizzleZWZW.v); + V0[2] = XMVectorPermute(MT.r[2], MT.r[0], Permute0X0Z1X1Z.v); + V1[2] = XMVectorPermute(MT.r[3], MT.r[1], Permute0Y0W1Y1W.v); + + D0 = XMVectorMultiply(V0[0], V1[0]); + D1 = XMVectorMultiply(V0[1], V1[1]); + D2 = XMVectorMultiply(V0[2], V1[2]); + + V0[0] = XMVectorPermute(MT.r[2], MT.r[2], SwizzleZWZW.v); + V1[0] = XMVectorPermute(MT.r[3], MT.r[3], SwizzleXXYY.v); + V0[1] = XMVectorPermute(MT.r[0], MT.r[0], SwizzleZWZW.v); + V1[1] = XMVectorPermute(MT.r[1], MT.r[1], SwizzleXXYY.v); + V0[2] = XMVectorPermute(MT.r[2], MT.r[0], Permute0Y0W1Y1W.v); + V1[2] = XMVectorPermute(MT.r[3], MT.r[1], Permute0X0Z1X1Z.v); + + D0 = XMVectorNegativeMultiplySubtract(V0[0], V1[0], D0); + D1 = XMVectorNegativeMultiplySubtract(V0[1], V1[1], D1); + D2 = XMVectorNegativeMultiplySubtract(V0[2], V1[2], D2); + + V0[0] = XMVectorPermute(MT.r[1], MT.r[1], SwizzleYZXY.v); + V1[0] = XMVectorPermute(D0, D2, Permute1Y0Y0W0X.v); + V0[1] = XMVectorPermute(MT.r[0], MT.r[0], SwizzleZXYX.v); + V1[1] = XMVectorPermute(D0, D2, Permute0W1Y0Y0Z.v); + V0[2] = XMVectorPermute(MT.r[3], MT.r[3], SwizzleYZXY.v); + V1[2] = XMVectorPermute(D1, D2, Permute1W0Y0W0X.v); + V0[3] = XMVectorPermute(MT.r[2], MT.r[2], SwizzleZXYX.v); + V1[3] = XMVectorPermute(D1, D2, Permute0W1W0Y0Z.v); + + C0 = XMVectorMultiply(V0[0], V1[0]); + C2 = XMVectorMultiply(V0[1], V1[1]); + C4 = XMVectorMultiply(V0[2], V1[2]); + C6 = XMVectorMultiply(V0[3], V1[3]); + + V0[0] = XMVectorPermute(MT.r[1], MT.r[1], SwizzleZWYZ.v); + V1[0] = XMVectorPermute(D0, D2, Permute0W0X0Y1X.v); + V0[1] = XMVectorPermute(MT.r[0], MT.r[0], SwizzleWZWY.v); + V1[1] = XMVectorPermute(D0, D2, Permute0Z0Y1X0X.v); + V0[2] = XMVectorPermute(MT.r[3], MT.r[3], SwizzleZWYZ.v); + V1[2] = XMVectorPermute(D1, D2, Permute0W0X0Y1Z.v); + V0[3] = XMVectorPermute(MT.r[2], MT.r[2], SwizzleWZWY.v); + V1[3] = XMVectorPermute(D1, D2, Permute0Z0Y1Z0X.v); + + C0 = XMVectorNegativeMultiplySubtract(V0[0], V1[0], C0); + C2 = XMVectorNegativeMultiplySubtract(V0[1], V1[1], C2); + C4 = XMVectorNegativeMultiplySubtract(V0[2], V1[2], C4); + C6 = XMVectorNegativeMultiplySubtract(V0[3], V1[3], C6); + + V0[0] = XMVectorPermute(MT.r[1], MT.r[1], SwizzleWXWX.v); + V1[0] = XMVectorPermute(D0, D2, Permute0Z1Y1X0Z.v); + V0[1] = XMVectorPermute(MT.r[0], MT.r[0], SwizzleYWXZ.v); + V1[1] = XMVectorPermute(D0, D2, Permute1Y0X0W1X.v); + V0[2] = XMVectorPermute(MT.r[3], MT.r[3], SwizzleWXWX.v); + V1[2] = XMVectorPermute(D1, D2, Permute0Z1W1Z0Z.v); + V0[3] = XMVectorPermute(MT.r[2], MT.r[2], SwizzleYWXZ.v); + V1[3] = XMVectorPermute(D1, D2, Permute1W0X0W1Z.v); + + C1 = XMVectorNegativeMultiplySubtract(V0[0], V1[0], C0); + C0 = XMVectorMultiplyAdd(V0[0], V1[0], C0); + C3 = XMVectorMultiplyAdd(V0[1], V1[1], C2); + C2 = XMVectorNegativeMultiplySubtract(V0[1], V1[1], C2); + C5 = XMVectorNegativeMultiplySubtract(V0[2], V1[2], C4); + C4 = XMVectorMultiplyAdd(V0[2], V1[2], C4); + C7 = XMVectorMultiplyAdd(V0[3], V1[3], C6); + C6 = XMVectorNegativeMultiplySubtract(V0[3], V1[3], C6); + + R.r[0] = XMVectorSelect(C0, C1, g_XMSelect0101.v); + R.r[1] = XMVectorSelect(C2, C3, g_XMSelect0101.v); + R.r[2] = XMVectorSelect(C4, C5, g_XMSelect0101.v); + R.r[3] = XMVectorSelect(C6, C7, g_XMSelect0101.v); + + Determinant = XMVector4Dot(R.r[0], MT.r[0]); + + if (pDeterminant) + *pDeterminant = Determinant; + + Reciprocal = XMVectorReciprocal(Determinant); + + Result.r[0] = XMVectorMultiply(R.r[0], Reciprocal); + Result.r[1] = XMVectorMultiply(R.r[1], Reciprocal); + Result.r[2] = XMVectorMultiply(R.r[2], Reciprocal); + Result.r[3] = XMVectorMultiply(R.r[3], Reciprocal); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX MT = XMMatrixTranspose(M); + XMVECTOR V00 = _mm_shuffle_ps(MT.r[2], MT.r[2],_MM_SHUFFLE(1,1,0,0)); + XMVECTOR V10 = _mm_shuffle_ps(MT.r[3], MT.r[3],_MM_SHUFFLE(3,2,3,2)); + XMVECTOR V01 = _mm_shuffle_ps(MT.r[0], MT.r[0],_MM_SHUFFLE(1,1,0,0)); + XMVECTOR V11 = _mm_shuffle_ps(MT.r[1], MT.r[1],_MM_SHUFFLE(3,2,3,2)); + XMVECTOR V02 = _mm_shuffle_ps(MT.r[2], MT.r[0],_MM_SHUFFLE(2,0,2,0)); + XMVECTOR V12 = _mm_shuffle_ps(MT.r[3], MT.r[1],_MM_SHUFFLE(3,1,3,1)); + + XMVECTOR D0 = _mm_mul_ps(V00,V10); + XMVECTOR D1 = _mm_mul_ps(V01,V11); + XMVECTOR D2 = _mm_mul_ps(V02,V12); + + V00 = _mm_shuffle_ps(MT.r[2],MT.r[2],_MM_SHUFFLE(3,2,3,2)); + V10 = _mm_shuffle_ps(MT.r[3],MT.r[3],_MM_SHUFFLE(1,1,0,0)); + V01 = _mm_shuffle_ps(MT.r[0],MT.r[0],_MM_SHUFFLE(3,2,3,2)); + V11 = _mm_shuffle_ps(MT.r[1],MT.r[1],_MM_SHUFFLE(1,1,0,0)); + V02 = _mm_shuffle_ps(MT.r[2],MT.r[0],_MM_SHUFFLE(3,1,3,1)); + V12 = _mm_shuffle_ps(MT.r[3],MT.r[1],_MM_SHUFFLE(2,0,2,0)); + + V00 = _mm_mul_ps(V00,V10); + V01 = _mm_mul_ps(V01,V11); + V02 = _mm_mul_ps(V02,V12); + D0 = _mm_sub_ps(D0,V00); + D1 = _mm_sub_ps(D1,V01); + D2 = _mm_sub_ps(D2,V02); + // V11 = D0Y,D0W,D2Y,D2Y + V11 = _mm_shuffle_ps(D0,D2,_MM_SHUFFLE(1,1,3,1)); + V00 = _mm_shuffle_ps(MT.r[1], MT.r[1],_MM_SHUFFLE(1,0,2,1)); + V10 = _mm_shuffle_ps(V11,D0,_MM_SHUFFLE(0,3,0,2)); + V01 = _mm_shuffle_ps(MT.r[0], MT.r[0],_MM_SHUFFLE(0,1,0,2)); + V11 = _mm_shuffle_ps(V11,D0,_MM_SHUFFLE(2,1,2,1)); + // V13 = D1Y,D1W,D2W,D2W + XMVECTOR V13 = _mm_shuffle_ps(D1,D2,_MM_SHUFFLE(3,3,3,1)); + V02 = _mm_shuffle_ps(MT.r[3], MT.r[3],_MM_SHUFFLE(1,0,2,1)); + V12 = _mm_shuffle_ps(V13,D1,_MM_SHUFFLE(0,3,0,2)); + XMVECTOR V03 = _mm_shuffle_ps(MT.r[2], MT.r[2],_MM_SHUFFLE(0,1,0,2)); + V13 = _mm_shuffle_ps(V13,D1,_MM_SHUFFLE(2,1,2,1)); + + XMVECTOR C0 = _mm_mul_ps(V00,V10); + XMVECTOR C2 = _mm_mul_ps(V01,V11); + XMVECTOR C4 = _mm_mul_ps(V02,V12); + XMVECTOR C6 = _mm_mul_ps(V03,V13); + + // V11 = D0X,D0Y,D2X,D2X + V11 = _mm_shuffle_ps(D0,D2,_MM_SHUFFLE(0,0,1,0)); + V00 = _mm_shuffle_ps(MT.r[1], MT.r[1],_MM_SHUFFLE(2,1,3,2)); + V10 = _mm_shuffle_ps(D0,V11,_MM_SHUFFLE(2,1,0,3)); + V01 = _mm_shuffle_ps(MT.r[0], MT.r[0],_MM_SHUFFLE(1,3,2,3)); + V11 = _mm_shuffle_ps(D0,V11,_MM_SHUFFLE(0,2,1,2)); + // V13 = D1X,D1Y,D2Z,D2Z + V13 = _mm_shuffle_ps(D1,D2,_MM_SHUFFLE(2,2,1,0)); + V02 = _mm_shuffle_ps(MT.r[3], MT.r[3],_MM_SHUFFLE(2,1,3,2)); + V12 = _mm_shuffle_ps(D1,V13,_MM_SHUFFLE(2,1,0,3)); + V03 = _mm_shuffle_ps(MT.r[2], MT.r[2],_MM_SHUFFLE(1,3,2,3)); + V13 = _mm_shuffle_ps(D1,V13,_MM_SHUFFLE(0,2,1,2)); + + V00 = _mm_mul_ps(V00,V10); + V01 = _mm_mul_ps(V01,V11); + V02 = _mm_mul_ps(V02,V12); + V03 = _mm_mul_ps(V03,V13); + C0 = _mm_sub_ps(C0,V00); + C2 = _mm_sub_ps(C2,V01); + C4 = _mm_sub_ps(C4,V02); + C6 = _mm_sub_ps(C6,V03); + + V00 = _mm_shuffle_ps(MT.r[1],MT.r[1],_MM_SHUFFLE(0,3,0,3)); + // V10 = D0Z,D0Z,D2X,D2Y + V10 = _mm_shuffle_ps(D0,D2,_MM_SHUFFLE(1,0,2,2)); + V10 = _mm_shuffle_ps(V10,V10,_MM_SHUFFLE(0,2,3,0)); + V01 = _mm_shuffle_ps(MT.r[0],MT.r[0],_MM_SHUFFLE(2,0,3,1)); + // V11 = D0X,D0W,D2X,D2Y + V11 = _mm_shuffle_ps(D0,D2,_MM_SHUFFLE(1,0,3,0)); + V11 = _mm_shuffle_ps(V11,V11,_MM_SHUFFLE(2,1,0,3)); + V02 = _mm_shuffle_ps(MT.r[3],MT.r[3],_MM_SHUFFLE(0,3,0,3)); + // V12 = D1Z,D1Z,D2Z,D2W + V12 = _mm_shuffle_ps(D1,D2,_MM_SHUFFLE(3,2,2,2)); + V12 = _mm_shuffle_ps(V12,V12,_MM_SHUFFLE(0,2,3,0)); + V03 = _mm_shuffle_ps(MT.r[2],MT.r[2],_MM_SHUFFLE(2,0,3,1)); + // V13 = D1X,D1W,D2Z,D2W + V13 = _mm_shuffle_ps(D1,D2,_MM_SHUFFLE(3,2,3,0)); + V13 = _mm_shuffle_ps(V13,V13,_MM_SHUFFLE(2,1,0,3)); + + V00 = _mm_mul_ps(V00,V10); + V01 = _mm_mul_ps(V01,V11); + V02 = _mm_mul_ps(V02,V12); + V03 = _mm_mul_ps(V03,V13); + XMVECTOR C1 = _mm_sub_ps(C0,V00); + C0 = _mm_add_ps(C0,V00); + XMVECTOR C3 = _mm_add_ps(C2,V01); + C2 = _mm_sub_ps(C2,V01); + XMVECTOR C5 = _mm_sub_ps(C4,V02); + C4 = _mm_add_ps(C4,V02); + XMVECTOR C7 = _mm_add_ps(C6,V03); + C6 = _mm_sub_ps(C6,V03); + + C0 = _mm_shuffle_ps(C0,C1,_MM_SHUFFLE(3,1,2,0)); + C2 = _mm_shuffle_ps(C2,C3,_MM_SHUFFLE(3,1,2,0)); + C4 = _mm_shuffle_ps(C4,C5,_MM_SHUFFLE(3,1,2,0)); + C6 = _mm_shuffle_ps(C6,C7,_MM_SHUFFLE(3,1,2,0)); + C0 = _mm_shuffle_ps(C0,C0,_MM_SHUFFLE(3,1,2,0)); + C2 = _mm_shuffle_ps(C2,C2,_MM_SHUFFLE(3,1,2,0)); + C4 = _mm_shuffle_ps(C4,C4,_MM_SHUFFLE(3,1,2,0)); + C6 = _mm_shuffle_ps(C6,C6,_MM_SHUFFLE(3,1,2,0)); + // Get the determinate + XMVECTOR vTemp = XMVector4Dot(C0,MT.r[0]); + if (pDeterminant) + *pDeterminant = vTemp; + vTemp = _mm_div_ps(g_XMOne,vTemp); + XMMATRIX mResult; + mResult.r[0] = _mm_mul_ps(C0,vTemp); + mResult.r[1] = _mm_mul_ps(C2,vTemp); + mResult.r[2] = _mm_mul_ps(C4,vTemp); + mResult.r[3] = _mm_mul_ps(C6,vTemp); + return mResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMMatrixDeterminant +( + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V0, V1, V2, V3, V4, V5; + XMVECTOR P0, P1, P2, R, S; + XMVECTOR Result; + static CONST XMVECTORU32 SwizzleYXXX = {XM_PERMUTE_0Y, XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0X}; + static CONST XMVECTORU32 SwizzleZZYY = {XM_PERMUTE_0Z, XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_0Y}; + static CONST XMVECTORU32 SwizzleWWWZ = {XM_PERMUTE_0W, XM_PERMUTE_0W, XM_PERMUTE_0W, XM_PERMUTE_0Z}; + static CONST XMVECTOR Sign = {1.0f, -1.0f, 1.0f, -1.0f}; + + V0 = XMVectorPermute(M.r[2], M.r[2], SwizzleYXXX.v); + V1 = XMVectorPermute(M.r[3], M.r[3], SwizzleZZYY.v); + V2 = XMVectorPermute(M.r[2], M.r[2], SwizzleYXXX.v); + V3 = XMVectorPermute(M.r[3], M.r[3], SwizzleWWWZ.v); + V4 = XMVectorPermute(M.r[2], M.r[2], SwizzleZZYY.v); + V5 = XMVectorPermute(M.r[3], M.r[3], SwizzleWWWZ.v); + + P0 = XMVectorMultiply(V0, V1); + P1 = XMVectorMultiply(V2, V3); + P2 = XMVectorMultiply(V4, V5); + + V0 = XMVectorPermute(M.r[2], M.r[2], SwizzleZZYY.v); + V1 = XMVectorPermute(M.r[3], M.r[3], SwizzleYXXX.v); + V2 = XMVectorPermute(M.r[2], M.r[2], SwizzleWWWZ.v); + V3 = XMVectorPermute(M.r[3], M.r[3], SwizzleYXXX.v); + V4 = XMVectorPermute(M.r[2], M.r[2], SwizzleWWWZ.v); + V5 = XMVectorPermute(M.r[3], M.r[3], SwizzleZZYY.v); + + P0 = XMVectorNegativeMultiplySubtract(V0, V1, P0); + P1 = XMVectorNegativeMultiplySubtract(V2, V3, P1); + P2 = XMVectorNegativeMultiplySubtract(V4, V5, P2); + + V0 = XMVectorPermute(M.r[1], M.r[1], SwizzleWWWZ.v); + V1 = XMVectorPermute(M.r[1], M.r[1], SwizzleZZYY.v); + V2 = XMVectorPermute(M.r[1], M.r[1], SwizzleYXXX.v); + + S = XMVectorMultiply(M.r[0], Sign); + R = XMVectorMultiply(V0, P0); + R = XMVectorNegativeMultiplySubtract(V1, P1, R); + R = XMVectorMultiplyAdd(V2, P2, R); + + Result = XMVector4Dot(S, R); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V0, V1, V2, V3, V4, V5; + XMVECTOR P0, P1, P2, R, S; + XMVECTOR Result; + static CONST XMVECTORU32 SwizzleYXXX = {XM_PERMUTE_0Y, XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0X}; + static CONST XMVECTORU32 SwizzleZZYY = {XM_PERMUTE_0Z, XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_0Y}; + static CONST XMVECTORU32 SwizzleWWWZ = {XM_PERMUTE_0W, XM_PERMUTE_0W, XM_PERMUTE_0W, XM_PERMUTE_0Z}; + static CONST XMVECTORF32 Sign = {1.0f, -1.0f, 1.0f, -1.0f}; + + V0 = XMVectorPermute(M.r[2], M.r[2], SwizzleYXXX); + V1 = XMVectorPermute(M.r[3], M.r[3], SwizzleZZYY); + V2 = XMVectorPermute(M.r[2], M.r[2], SwizzleYXXX); + V3 = XMVectorPermute(M.r[3], M.r[3], SwizzleWWWZ); + V4 = XMVectorPermute(M.r[2], M.r[2], SwizzleZZYY); + V5 = XMVectorPermute(M.r[3], M.r[3], SwizzleWWWZ); + + P0 = _mm_mul_ps(V0, V1); + P1 = _mm_mul_ps(V2, V3); + P2 = _mm_mul_ps(V4, V5); + + V0 = XMVectorPermute(M.r[2], M.r[2], SwizzleZZYY); + V1 = XMVectorPermute(M.r[3], M.r[3], SwizzleYXXX); + V2 = XMVectorPermute(M.r[2], M.r[2], SwizzleWWWZ); + V3 = XMVectorPermute(M.r[3], M.r[3], SwizzleYXXX); + V4 = XMVectorPermute(M.r[2], M.r[2], SwizzleWWWZ); + V5 = XMVectorPermute(M.r[3], M.r[3], SwizzleZZYY); + + P0 = XMVectorNegativeMultiplySubtract(V0, V1, P0); + P1 = XMVectorNegativeMultiplySubtract(V2, V3, P1); + P2 = XMVectorNegativeMultiplySubtract(V4, V5, P2); + + V0 = XMVectorPermute(M.r[1], M.r[1], SwizzleWWWZ); + V1 = XMVectorPermute(M.r[1], M.r[1], SwizzleZZYY); + V2 = XMVectorPermute(M.r[1], M.r[1], SwizzleYXXX); + + S = _mm_mul_ps(M.r[0], Sign); + R = _mm_mul_ps(V0, P0); + R = XMVectorNegativeMultiplySubtract(V1, P1, R); + R = XMVectorMultiplyAdd(V2, P2, R); + + Result = XMVector4Dot(S, R); + + return Result; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +#undef XMRANKDECOMPOSE +#undef XM_DECOMP_EPSILON + +#define XMRANKDECOMPOSE(a, b, c, x, y, z) \ + if((x) < (y)) \ + { \ + if((y) < (z)) \ + { \ + (a) = 2; \ + (b) = 1; \ + (c) = 0; \ + } \ + else \ + { \ + (a) = 1; \ + \ + if((x) < (z)) \ + { \ + (b) = 2; \ + (c) = 0; \ + } \ + else \ + { \ + (b) = 0; \ + (c) = 2; \ + } \ + } \ + } \ + else \ + { \ + if((x) < (z)) \ + { \ + (a) = 2; \ + (b) = 0; \ + (c) = 1; \ + } \ + else \ + { \ + (a) = 0; \ + \ + if((y) < (z)) \ + { \ + (b) = 2; \ + (c) = 1; \ + } \ + else \ + { \ + (b) = 1; \ + (c) = 2; \ + } \ + } \ + } + +#define XM_DECOMP_EPSILON 0.0001f + +XMINLINE BOOL XMMatrixDecompose +( + XMVECTOR *outScale, + XMVECTOR *outRotQuat, + XMVECTOR *outTrans, + CXMMATRIX M +) +{ + FLOAT fDet; + FLOAT *pfScales; + XMVECTOR *ppvBasis[3]; + XMMATRIX matTemp; + UINT a, b, c; + static const XMVECTOR *pvCanonicalBasis[3] = { + &g_XMIdentityR0.v, + &g_XMIdentityR1.v, + &g_XMIdentityR2.v + }; + + XMASSERT( outScale != NULL ); + XMASSERT( outRotQuat != NULL ); + XMASSERT( outTrans != NULL ); + + // Get the translation + outTrans[0] = M.r[3]; + + ppvBasis[0] = &matTemp.r[0]; + ppvBasis[1] = &matTemp.r[1]; + ppvBasis[2] = &matTemp.r[2]; + + matTemp.r[0] = M.r[0]; + matTemp.r[1] = M.r[1]; + matTemp.r[2] = M.r[2]; + matTemp.r[3] = g_XMIdentityR3.v; + + pfScales = (FLOAT *)outScale; + + XMVectorGetXPtr(&pfScales[0],XMVector3Length(ppvBasis[0][0])); + XMVectorGetXPtr(&pfScales[1],XMVector3Length(ppvBasis[1][0])); + XMVectorGetXPtr(&pfScales[2],XMVector3Length(ppvBasis[2][0])); + pfScales[3] = 0.f; + + XMRANKDECOMPOSE(a, b, c, pfScales[0], pfScales[1], pfScales[2]) + + if(pfScales[a] < XM_DECOMP_EPSILON) + { + ppvBasis[a][0] = pvCanonicalBasis[a][0]; + } + ppvBasis[a][0] = XMVector3Normalize(ppvBasis[a][0]); + + if(pfScales[b] < XM_DECOMP_EPSILON) + { + UINT aa, bb, cc; + FLOAT fAbsX, fAbsY, fAbsZ; + + fAbsX = fabsf(XMVectorGetX(ppvBasis[a][0])); + fAbsY = fabsf(XMVectorGetY(ppvBasis[a][0])); + fAbsZ = fabsf(XMVectorGetZ(ppvBasis[a][0])); + + XMRANKDECOMPOSE(aa, bb, cc, fAbsX, fAbsY, fAbsZ) + + ppvBasis[b][0] = XMVector3Cross(ppvBasis[a][0],pvCanonicalBasis[cc][0]); + } + + ppvBasis[b][0] = XMVector3Normalize(ppvBasis[b][0]); + + if(pfScales[c] < XM_DECOMP_EPSILON) + { + ppvBasis[c][0] = XMVector3Cross(ppvBasis[a][0],ppvBasis[b][0]); + } + + ppvBasis[c][0] = XMVector3Normalize(ppvBasis[c][0]); + + fDet = XMVectorGetX(XMMatrixDeterminant(matTemp)); + + // use Kramer's rule to check for handedness of coordinate system + if(fDet < 0.0f) + { + // switch coordinate system by negating the scale and inverting the basis vector on the x-axis + pfScales[a] = -pfScales[a]; + ppvBasis[a][0] = XMVectorNegate(ppvBasis[a][0]); + + fDet = -fDet; + } + + fDet -= 1.0f; + fDet *= fDet; + + if(XM_DECOMP_EPSILON < fDet) + { + // Non-SRT matrix encountered + return FALSE; + } + + // generate the quaternion from the matrix + outRotQuat[0] = XMQuaternionRotationMatrix(matTemp); + return TRUE; +} + +#undef XMRANKDECOMPOSE +#undef XM_DECOMP_EPSILON + +//------------------------------------------------------------------------------ +// Transformation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixIdentity() +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + M.r[0] = g_XMIdentityR0.v; + M.r[1] = g_XMIdentityR1.v; + M.r[2] = g_XMIdentityR2.v; + M.r[3] = g_XMIdentityR3.v; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + M.r[0] = g_XMIdentityR0; + M.r[1] = g_XMIdentityR1; + M.r[2] = g_XMIdentityR2; + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixSet +( + FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33 +) +{ + XMMATRIX M; + + M.r[0] = XMVectorSet(m00, m01, m02, m03); + M.r[1] = XMVectorSet(m10, m11, m12, m13); + M.r[2] = XMVectorSet(m20, m21, m22, m23); + M.r[3] = XMVectorSet(m30, m31, m32, m33); + + return M; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixTranslation +( + FLOAT OffsetX, + FLOAT OffsetY, + FLOAT OffsetZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + + M.m[0][0] = 1.0f; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = 1.0f; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = 0.0f; + M.m[2][2] = 1.0f; + M.m[2][3] = 0.0f; + + M.m[3][0] = OffsetX; + M.m[3][1] = OffsetY; + M.m[3][2] = OffsetZ; + M.m[3][3] = 1.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + M.r[0] = g_XMIdentityR0; + M.r[1] = g_XMIdentityR1; + M.r[2] = g_XMIdentityR2; + M.r[3] = _mm_set_ps(1.0f,OffsetZ,OffsetY,OffsetX); + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixTranslationFromVector +( + FXMVECTOR Offset +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + M.m[0][0] = 1.0f; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = 1.0f; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = 0.0f; + M.m[2][2] = 1.0f; + M.m[2][3] = 0.0f; + + M.m[3][0] = Offset.vector4_f32[0]; + M.m[3][1] = Offset.vector4_f32[1]; + M.m[3][2] = Offset.vector4_f32[2]; + M.m[3][3] = 1.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_and_ps(Offset,g_XMMask3); + vTemp = _mm_or_ps(vTemp,g_XMIdentityR3); + XMMATRIX M; + M.r[0] = g_XMIdentityR0; + M.r[1] = g_XMIdentityR1; + M.r[2] = g_XMIdentityR2; + M.r[3] = vTemp; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixScaling +( + FLOAT ScaleX, + FLOAT ScaleY, + FLOAT ScaleZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + + M.r[0] = XMVectorSet(ScaleX, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, ScaleY, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, ScaleZ, 0.0f); + + M.r[3] = g_XMIdentityR3.v; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + M.r[0] = _mm_set_ps( 0, 0, 0, ScaleX ); + M.r[1] = _mm_set_ps( 0, 0, ScaleY, 0 ); + M.r[2] = _mm_set_ps( 0, ScaleZ, 0, 0 ); + M.r[3] = g_XMIdentityR3; + return M; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixScalingFromVector +( + FXMVECTOR Scale +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + M.m[0][0] = Scale.vector4_f32[0]; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = Scale.vector4_f32[1]; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = 0.0f; + M.m[2][2] = Scale.vector4_f32[2]; + M.m[2][3] = 0.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = 0.0f; + M.m[3][3] = 1.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + M.r[0] = _mm_and_ps(Scale,g_XMMaskX); + M.r[1] = _mm_and_ps(Scale,g_XMMaskY); + M.r[2] = _mm_and_ps(Scale,g_XMMaskZ); + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationX +( + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + + FLOAT fSinAngle = sinf(Angle); + FLOAT fCosAngle = cosf(Angle); + + M.m[0][0] = 1.0f; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = fCosAngle; + M.m[1][2] = fSinAngle; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = -fSinAngle; + M.m[2][2] = fCosAngle; + M.m[2][3] = 0.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = 0.0f; + M.m[3][3] = 1.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + FLOAT SinAngle = sinf(Angle); + FLOAT CosAngle = cosf(Angle); + + XMVECTOR vSin = _mm_set_ss(SinAngle); + XMVECTOR vCos = _mm_set_ss(CosAngle); + // x = 0,y = cos,z = sin, w = 0 + vCos = _mm_shuffle_ps(vCos,vSin,_MM_SHUFFLE(3,0,0,3)); + XMMATRIX M; + M.r[0] = g_XMIdentityR0; + M.r[1] = vCos; + // x = 0,y = sin,z = cos, w = 0 + vCos = _mm_shuffle_ps(vCos,vCos,_MM_SHUFFLE(3,1,2,0)); + // x = 0,y = -sin,z = cos, w = 0 + vCos = _mm_mul_ps(vCos,g_XMNegateY); + M.r[2] = vCos; + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationY +( + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + + FLOAT fSinAngle = sinf(Angle); + FLOAT fCosAngle = cosf(Angle); + + M.m[0][0] = fCosAngle; + M.m[0][1] = 0.0f; + M.m[0][2] = -fSinAngle; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = 1.0f; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = fSinAngle; + M.m[2][1] = 0.0f; + M.m[2][2] = fCosAngle; + M.m[2][3] = 0.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = 0.0f; + M.m[3][3] = 1.0f; + return M; +#elif defined(_XM_SSE_INTRINSICS_) + FLOAT SinAngle = sinf(Angle); + FLOAT CosAngle = cosf(Angle); + + XMVECTOR vSin = _mm_set_ss(SinAngle); + XMVECTOR vCos = _mm_set_ss(CosAngle); + // x = sin,y = 0,z = cos, w = 0 + vSin = _mm_shuffle_ps(vSin,vCos,_MM_SHUFFLE(3,0,3,0)); + XMMATRIX M; + M.r[2] = vSin; + M.r[1] = g_XMIdentityR1; + // x = cos,y = 0,z = sin, w = 0 + vSin = _mm_shuffle_ps(vSin,vSin,_MM_SHUFFLE(3,0,1,2)); + // x = cos,y = 0,z = -sin, w = 0 + vSin = _mm_mul_ps(vSin,g_XMNegateZ); + M.r[0] = vSin; + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationZ +( + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMMATRIX M; + + FLOAT fSinAngle = sinf(Angle); + FLOAT fCosAngle = cosf(Angle); + + M.m[0][0] = fCosAngle; + M.m[0][1] = fSinAngle; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = -fSinAngle; + M.m[1][1] = fCosAngle; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = 0.0f; + M.m[2][2] = 1.0f; + M.m[2][3] = 0.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = 0.0f; + M.m[3][3] = 1.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + FLOAT SinAngle = sinf(Angle); + FLOAT CosAngle = cosf(Angle); + + XMVECTOR vSin = _mm_set_ss(SinAngle); + XMVECTOR vCos = _mm_set_ss(CosAngle); + // x = cos,y = sin,z = 0, w = 0 + vCos = _mm_unpacklo_ps(vCos,vSin); + XMMATRIX M; + M.r[0] = vCos; + // x = sin,y = cos,z = 0, w = 0 + vCos = _mm_shuffle_ps(vCos,vCos,_MM_SHUFFLE(3,2,0,1)); + // x = cos,y = -sin,z = 0, w = 0 + vCos = _mm_mul_ps(vCos,g_XMNegateX); + M.r[1] = vCos; + M.r[2] = g_XMIdentityR2; + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationRollPitchYaw +( + FLOAT Pitch, + FLOAT Yaw, + FLOAT Roll +) +{ + XMVECTOR Angles; + XMMATRIX M; + + Angles = XMVectorSet(Pitch, Yaw, Roll, 0.0f); + M = XMMatrixRotationRollPitchYawFromVector(Angles); + + return M; +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationRollPitchYawFromVector +( + FXMVECTOR Angles // +) +{ + XMVECTOR Q; + XMMATRIX M; + + Q = XMQuaternionRotationRollPitchYawFromVector(Angles); + M = XMMatrixRotationQuaternion(Q); + + return M; +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationNormal +( + FXMVECTOR NormalAxis, + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR A; + XMVECTOR N0, N1; + XMVECTOR V0, V1, V2; + XMVECTOR R0, R1, R2; + XMVECTOR C0, C1, C2; + XMMATRIX M; + static CONST XMVECTORU32 SwizzleYZXW = {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0W}; + static CONST XMVECTORU32 SwizzleZXYW = {XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute0Z1Y1Z0X = {XM_PERMUTE_0Z, XM_PERMUTE_1Y, XM_PERMUTE_1Z, XM_PERMUTE_0X}; + static CONST XMVECTORU32 Permute0Y1X0Y1X = {XM_PERMUTE_0Y, XM_PERMUTE_1X, XM_PERMUTE_0Y, XM_PERMUTE_1X}; + static CONST XMVECTORU32 Permute0X1X1Y0W = {XM_PERMUTE_0X, XM_PERMUTE_1X, XM_PERMUTE_1Y, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute1Z0Y1W0W = {XM_PERMUTE_1Z, XM_PERMUTE_0Y, XM_PERMUTE_1W, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute1X1Y0Z0W = {XM_PERMUTE_1X, XM_PERMUTE_1Y, XM_PERMUTE_0Z, XM_PERMUTE_0W}; + + FLOAT fSinAngle = sinf(Angle); + FLOAT fCosAngle = cosf(Angle); + + A = XMVectorSet(fSinAngle, fCosAngle, 1.0f - fCosAngle, 0.0f); + + C2 = XMVectorSplatZ(A); + C1 = XMVectorSplatY(A); + C0 = XMVectorSplatX(A); + + N0 = XMVectorPermute(NormalAxis, NormalAxis, SwizzleYZXW.v); + N1 = XMVectorPermute(NormalAxis, NormalAxis, SwizzleZXYW.v); + + V0 = XMVectorMultiply(C2, N0); + V0 = XMVectorMultiply(V0, N1); + + R0 = XMVectorMultiply(C2, NormalAxis); + R0 = XMVectorMultiplyAdd(R0, NormalAxis, C1); + + R1 = XMVectorMultiplyAdd(C0, NormalAxis, V0); + R2 = XMVectorNegativeMultiplySubtract(C0, NormalAxis, V0); + + V0 = XMVectorSelect(A, R0, g_XMSelect1110.v); + V1 = XMVectorPermute(R1, R2, Permute0Z1Y1Z0X.v); + V2 = XMVectorPermute(R1, R2, Permute0Y1X0Y1X.v); + + M.r[0] = XMVectorPermute(V0, V1, Permute0X1X1Y0W.v); + M.r[1] = XMVectorPermute(V0, V1, Permute1Z0Y1W0W.v); + M.r[2] = XMVectorPermute(V0, V2, Permute1X1Y0Z0W.v); + M.r[3] = g_XMIdentityR3.v; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR N0, N1; + XMVECTOR V0, V1, V2; + XMVECTOR R0, R1, R2; + XMVECTOR C0, C1, C2; + XMMATRIX M; + + FLOAT fSinAngle = sinf(Angle); + FLOAT fCosAngle = cosf(Angle); + + C2 = _mm_set_ps1(1.0f - fCosAngle); + C1 = _mm_set_ps1(fCosAngle); + C0 = _mm_set_ps1(fSinAngle); + + N0 = _mm_shuffle_ps(NormalAxis,NormalAxis,_MM_SHUFFLE(3,0,2,1)); +// N0 = XMVectorPermute(NormalAxis, NormalAxis, SwizzleYZXW); + N1 = _mm_shuffle_ps(NormalAxis,NormalAxis,_MM_SHUFFLE(3,1,0,2)); +// N1 = XMVectorPermute(NormalAxis, NormalAxis, SwizzleZXYW); + + V0 = _mm_mul_ps(C2, N0); + V0 = _mm_mul_ps(V0, N1); + + R0 = _mm_mul_ps(C2, NormalAxis); + R0 = _mm_mul_ps(R0, NormalAxis); + R0 = _mm_add_ps(R0, C1); + + R1 = _mm_mul_ps(C0, NormalAxis); + R1 = _mm_add_ps(R1, V0); + R2 = _mm_mul_ps(C0, NormalAxis); + R2 = _mm_sub_ps(V0,R2); + + V0 = _mm_and_ps(R0,g_XMMask3); +// V0 = XMVectorSelect(A, R0, g_XMSelect1110); + V1 = _mm_shuffle_ps(R1,R2,_MM_SHUFFLE(2,1,2,0)); + V1 = _mm_shuffle_ps(V1,V1,_MM_SHUFFLE(0,3,2,1)); +// V1 = XMVectorPermute(R1, R2, Permute0Z1Y1Z0X); + V2 = _mm_shuffle_ps(R1,R2,_MM_SHUFFLE(0,0,1,1)); + V2 = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(2,0,2,0)); +// V2 = XMVectorPermute(R1, R2, Permute0Y1X0Y1X); + + R2 = _mm_shuffle_ps(V0,V1,_MM_SHUFFLE(1,0,3,0)); + R2 = _mm_shuffle_ps(R2,R2,_MM_SHUFFLE(1,3,2,0)); + M.r[0] = R2; +// M.r[0] = XMVectorPermute(V0, V1, Permute0X1X1Y0W); + R2 = _mm_shuffle_ps(V0,V1,_MM_SHUFFLE(3,2,3,1)); + R2 = _mm_shuffle_ps(R2,R2,_MM_SHUFFLE(1,3,0,2)); + M.r[1] = R2; +// M.r[1] = XMVectorPermute(V0, V1, Permute1Z0Y1W0W); + V2 = _mm_shuffle_ps(V2,V0,_MM_SHUFFLE(3,2,1,0)); +// R2 = _mm_shuffle_ps(R2,R2,_MM_SHUFFLE(3,2,1,0)); + M.r[2] = V2; +// M.r[2] = XMVectorPermute(V0, V2, Permute1X1Y0Z0W); + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixRotationAxis +( + FXMVECTOR Axis, + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Normal; + XMMATRIX M; + + XMASSERT(!XMVector3Equal(Axis, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(Axis)); + + Normal = XMVector3Normalize(Axis); + M = XMMatrixRotationNormal(Normal, Angle); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMVector3Equal(Axis, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(Axis)); + XMVECTOR Normal = XMVector3Normalize(Axis); + XMMATRIX M = XMMatrixRotationNormal(Normal, Angle); + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixRotationQuaternion +( + FXMVECTOR Quaternion +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + XMVECTOR Q0, Q1; + XMVECTOR V0, V1, V2; + XMVECTOR R0, R1, R2; + static CONST XMVECTOR Constant1110 = {1.0f, 1.0f, 1.0f, 0.0f}; + static CONST XMVECTORU32 SwizzleXXYW = {XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0W}; + static CONST XMVECTORU32 SwizzleZYZW = {XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0W}; + static CONST XMVECTORU32 SwizzleYZXW = {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0X, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute0Y0X0X1W = {XM_PERMUTE_0Y, XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_1W}; + static CONST XMVECTORU32 Permute0Z0Z0Y1W = {XM_PERMUTE_0Z, XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_1W}; + static CONST XMVECTORU32 Permute0Y1X1Y0Z = {XM_PERMUTE_0Y, XM_PERMUTE_1X, XM_PERMUTE_1Y, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 Permute0X1Z0X1Z = {XM_PERMUTE_0X, XM_PERMUTE_1Z, XM_PERMUTE_0X, XM_PERMUTE_1Z}; + static CONST XMVECTORU32 Permute0X1X1Y0W = {XM_PERMUTE_0X, XM_PERMUTE_1X, XM_PERMUTE_1Y, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute1Z0Y1W0W = {XM_PERMUTE_1Z, XM_PERMUTE_0Y, XM_PERMUTE_1W, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute1X1Y0Z0W = {XM_PERMUTE_1X, XM_PERMUTE_1Y, XM_PERMUTE_0Z, XM_PERMUTE_0W}; + + Q0 = XMVectorAdd(Quaternion, Quaternion); + Q1 = XMVectorMultiply(Quaternion, Q0); + + V0 = XMVectorPermute(Q1, Constant1110, Permute0Y0X0X1W.v); + V1 = XMVectorPermute(Q1, Constant1110, Permute0Z0Z0Y1W.v); + R0 = XMVectorSubtract(Constant1110, V0); + R0 = XMVectorSubtract(R0, V1); + + V0 = XMVectorPermute(Quaternion, Quaternion, SwizzleXXYW.v); + V1 = XMVectorPermute(Q0, Q0, SwizzleZYZW.v); + V0 = XMVectorMultiply(V0, V1); + + V1 = XMVectorSplatW(Quaternion); + V2 = XMVectorPermute(Q0, Q0, SwizzleYZXW.v); + V1 = XMVectorMultiply(V1, V2); + + R1 = XMVectorAdd(V0, V1); + R2 = XMVectorSubtract(V0, V1); + + V0 = XMVectorPermute(R1, R2, Permute0Y1X1Y0Z.v); + V1 = XMVectorPermute(R1, R2, Permute0X1Z0X1Z.v); + + M.r[0] = XMVectorPermute(R0, V0, Permute0X1X1Y0W.v); + M.r[1] = XMVectorPermute(R0, V0, Permute1Z0Y1W0W.v); + M.r[2] = XMVectorPermute(R0, V1, Permute1X1Y0Z0W.v); + M.r[3] = g_XMIdentityR3.v; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMVECTOR Q0, Q1; + XMVECTOR V0, V1, V2; + XMVECTOR R0, R1, R2; + static CONST XMVECTORF32 Constant1110 = {1.0f, 1.0f, 1.0f, 0.0f}; + + Q0 = _mm_add_ps(Quaternion,Quaternion); + Q1 = _mm_mul_ps(Quaternion,Q0); + + V0 = _mm_shuffle_ps(Q1,Q1,_MM_SHUFFLE(3,0,0,1)); + V0 = _mm_and_ps(V0,g_XMMask3); +// V0 = XMVectorPermute(Q1, Constant1110,Permute0Y0X0X1W); + V1 = _mm_shuffle_ps(Q1,Q1,_MM_SHUFFLE(3,1,2,2)); + V1 = _mm_and_ps(V1,g_XMMask3); +// V1 = XMVectorPermute(Q1, Constant1110,Permute0Z0Z0Y1W); + R0 = _mm_sub_ps(Constant1110,V0); + R0 = _mm_sub_ps(R0, V1); + + V0 = _mm_shuffle_ps(Quaternion,Quaternion,_MM_SHUFFLE(3,1,0,0)); +// V0 = XMVectorPermute(Quaternion, Quaternion,SwizzleXXYW); + V1 = _mm_shuffle_ps(Q0,Q0,_MM_SHUFFLE(3,2,1,2)); +// V1 = XMVectorPermute(Q0, Q0,SwizzleZYZW); + V0 = _mm_mul_ps(V0, V1); + + V1 = _mm_shuffle_ps(Quaternion,Quaternion,_MM_SHUFFLE(3,3,3,3)); +// V1 = XMVectorSplatW(Quaternion); + V2 = _mm_shuffle_ps(Q0,Q0,_MM_SHUFFLE(3,0,2,1)); +// V2 = XMVectorPermute(Q0, Q0,SwizzleYZXW); + V1 = _mm_mul_ps(V1, V2); + + R1 = _mm_add_ps(V0, V1); + R2 = _mm_sub_ps(V0, V1); + + V0 = _mm_shuffle_ps(R1,R2,_MM_SHUFFLE(1,0,2,1)); + V0 = _mm_shuffle_ps(V0,V0,_MM_SHUFFLE(1,3,2,0)); +// V0 = XMVectorPermute(R1, R2,Permute0Y1X1Y0Z); + V1 = _mm_shuffle_ps(R1,R2,_MM_SHUFFLE(2,2,0,0)); + V1 = _mm_shuffle_ps(V1,V1,_MM_SHUFFLE(2,0,2,0)); +// V1 = XMVectorPermute(R1, R2,Permute0X1Z0X1Z); + + Q1 = _mm_shuffle_ps(R0,V0,_MM_SHUFFLE(1,0,3,0)); + Q1 = _mm_shuffle_ps(Q1,Q1,_MM_SHUFFLE(1,3,2,0)); + M.r[0] = Q1; +// M.r[0] = XMVectorPermute(R0, V0,Permute0X1X1Y0W); + Q1 = _mm_shuffle_ps(R0,V0,_MM_SHUFFLE(3,2,3,1)); + Q1 = _mm_shuffle_ps(Q1,Q1,_MM_SHUFFLE(1,3,0,2)); + M.r[1] = Q1; +// M.r[1] = XMVectorPermute(R0, V0,Permute1Z0Y1W0W); + Q1 = _mm_shuffle_ps(V1,R0,_MM_SHUFFLE(3,2,1,0)); + M.r[2] = Q1; +// M.r[2] = XMVectorPermute(R0, V1,Permute1X1Y0Z0W); + M.r[3] = g_XMIdentityR3; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixTransformation2D +( + FXMVECTOR ScalingOrigin, + FLOAT ScalingOrientation, + FXMVECTOR Scaling, + FXMVECTOR RotationOrigin, + FLOAT Rotation, + CXMVECTOR Translation +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + XMVECTOR VScaling; + XMVECTOR NegScalingOrigin; + XMVECTOR VScalingOrigin; + XMMATRIX MScalingOriginI; + XMMATRIX MScalingOrientation; + XMMATRIX MScalingOrientationT; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = Inverse(MScalingOrigin) * Transpose(MScalingOrientation) * MScaling * MScalingOrientation * + // MScalingOrigin * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + VScalingOrigin = XMVectorSelect(g_XMSelect1100.v, ScalingOrigin, g_XMSelect1100.v); + NegScalingOrigin = XMVectorNegate(VScalingOrigin); + + MScalingOriginI = XMMatrixTranslationFromVector(NegScalingOrigin); + MScalingOrientation = XMMatrixRotationZ(ScalingOrientation); + MScalingOrientationT = XMMatrixTranspose(MScalingOrientation); + VScaling = XMVectorSelect(g_XMOne.v, Scaling, g_XMSelect1100.v); + MScaling = XMMatrixScalingFromVector(VScaling); + VRotationOrigin = XMVectorSelect(g_XMSelect1100.v, RotationOrigin, g_XMSelect1100.v); + MRotation = XMMatrixRotationZ(Rotation); + VTranslation = XMVectorSelect(g_XMSelect1100.v, Translation,g_XMSelect1100.v); + + M = XMMatrixMultiply(MScalingOriginI, MScalingOrientationT); + M = XMMatrixMultiply(M, MScaling); + M = XMMatrixMultiply(M, MScalingOrientation); + M.r[3] = XMVectorAdd(M.r[3], VScalingOrigin); + M.r[3] = XMVectorSubtract(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = XMVectorAdd(M.r[3], VRotationOrigin); + M.r[3] = XMVectorAdd(M.r[3], VTranslation); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMVECTOR VScaling; + XMVECTOR NegScalingOrigin; + XMVECTOR VScalingOrigin; + XMMATRIX MScalingOriginI; + XMMATRIX MScalingOrientation; + XMMATRIX MScalingOrientationT; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = Inverse(MScalingOrigin) * Transpose(MScalingOrientation) * MScaling * MScalingOrientation * + // MScalingOrigin * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + static const XMVECTORU32 Mask2 = {0xFFFFFFFF,0xFFFFFFFF,0,0}; + static const XMVECTORF32 ZWOne = {0,0,1.0f,1.0f}; + + VScalingOrigin = _mm_and_ps(ScalingOrigin, Mask2); + NegScalingOrigin = XMVectorNegate(VScalingOrigin); + + MScalingOriginI = XMMatrixTranslationFromVector(NegScalingOrigin); + MScalingOrientation = XMMatrixRotationZ(ScalingOrientation); + MScalingOrientationT = XMMatrixTranspose(MScalingOrientation); + VScaling = _mm_and_ps(Scaling, Mask2); + VScaling = _mm_or_ps(VScaling,ZWOne); + MScaling = XMMatrixScalingFromVector(VScaling); + VRotationOrigin = _mm_and_ps(RotationOrigin, Mask2); + MRotation = XMMatrixRotationZ(Rotation); + VTranslation = _mm_and_ps(Translation, Mask2); + + M = XMMatrixMultiply(MScalingOriginI, MScalingOrientationT); + M = XMMatrixMultiply(M, MScaling); + M = XMMatrixMultiply(M, MScalingOrientation); + M.r[3] = XMVectorAdd(M.r[3], VScalingOrigin); + M.r[3] = XMVectorSubtract(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = XMVectorAdd(M.r[3], VRotationOrigin); + M.r[3] = XMVectorAdd(M.r[3], VTranslation); + + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixTransformation +( + FXMVECTOR ScalingOrigin, + FXMVECTOR ScalingOrientationQuaternion, + FXMVECTOR Scaling, + CXMVECTOR RotationOrigin, + CXMVECTOR RotationQuaternion, + CXMVECTOR Translation +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + XMVECTOR NegScalingOrigin; + XMVECTOR VScalingOrigin; + XMMATRIX MScalingOriginI; + XMMATRIX MScalingOrientation; + XMMATRIX MScalingOrientationT; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = Inverse(MScalingOrigin) * Transpose(MScalingOrientation) * MScaling * MScalingOrientation * + // MScalingOrigin * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + VScalingOrigin = XMVectorSelect(g_XMSelect1110.v, ScalingOrigin, g_XMSelect1110.v); + NegScalingOrigin = XMVectorNegate(ScalingOrigin); + + MScalingOriginI = XMMatrixTranslationFromVector(NegScalingOrigin); + MScalingOrientation = XMMatrixRotationQuaternion(ScalingOrientationQuaternion); + MScalingOrientationT = XMMatrixTranspose(MScalingOrientation); + MScaling = XMMatrixScalingFromVector(Scaling); + VRotationOrigin = XMVectorSelect(g_XMSelect1110.v, RotationOrigin, g_XMSelect1110.v); + MRotation = XMMatrixRotationQuaternion(RotationQuaternion); + VTranslation = XMVectorSelect(g_XMSelect1110.v, Translation, g_XMSelect1110.v); + + M = XMMatrixMultiply(MScalingOriginI, MScalingOrientationT); + M = XMMatrixMultiply(M, MScaling); + M = XMMatrixMultiply(M, MScalingOrientation); + M.r[3] = XMVectorAdd(M.r[3], VScalingOrigin); + M.r[3] = XMVectorSubtract(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = XMVectorAdd(M.r[3], VRotationOrigin); + M.r[3] = XMVectorAdd(M.r[3], VTranslation); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMVECTOR NegScalingOrigin; + XMVECTOR VScalingOrigin; + XMMATRIX MScalingOriginI; + XMMATRIX MScalingOrientation; + XMMATRIX MScalingOrientationT; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = Inverse(MScalingOrigin) * Transpose(MScalingOrientation) * MScaling * MScalingOrientation * + // MScalingOrigin * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + VScalingOrigin = _mm_and_ps(ScalingOrigin,g_XMMask3); + NegScalingOrigin = XMVectorNegate(ScalingOrigin); + + MScalingOriginI = XMMatrixTranslationFromVector(NegScalingOrigin); + MScalingOrientation = XMMatrixRotationQuaternion(ScalingOrientationQuaternion); + MScalingOrientationT = XMMatrixTranspose(MScalingOrientation); + MScaling = XMMatrixScalingFromVector(Scaling); + VRotationOrigin = _mm_and_ps(RotationOrigin,g_XMMask3); + MRotation = XMMatrixRotationQuaternion(RotationQuaternion); + VTranslation = _mm_and_ps(Translation,g_XMMask3); + + M = XMMatrixMultiply(MScalingOriginI, MScalingOrientationT); + M = XMMatrixMultiply(M, MScaling); + M = XMMatrixMultiply(M, MScalingOrientation); + M.r[3] = XMVectorAdd(M.r[3], VScalingOrigin); + M.r[3] = XMVectorSubtract(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = XMVectorAdd(M.r[3], VRotationOrigin); + M.r[3] = XMVectorAdd(M.r[3], VTranslation); + + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixAffineTransformation2D +( + FXMVECTOR Scaling, + FXMVECTOR RotationOrigin, + FLOAT Rotation, + FXMVECTOR Translation +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + XMVECTOR VScaling; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = MScaling * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + VScaling = XMVectorSelect(g_XMOne.v, Scaling, g_XMSelect1100.v); + MScaling = XMMatrixScalingFromVector(VScaling); + VRotationOrigin = XMVectorSelect(g_XMSelect1100.v, RotationOrigin, g_XMSelect1100.v); + MRotation = XMMatrixRotationZ(Rotation); + VTranslation = XMVectorSelect(g_XMSelect1100.v, Translation,g_XMSelect1100.v); + + M = MScaling; + M.r[3] = XMVectorSubtract(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = XMVectorAdd(M.r[3], VRotationOrigin); + M.r[3] = XMVectorAdd(M.r[3], VTranslation); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMVECTOR VScaling; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + static const XMVECTORU32 Mask2 = {0xFFFFFFFFU,0xFFFFFFFFU,0,0}; + static const XMVECTORF32 ZW1 = {0,0,1.0f,1.0f}; + + // M = MScaling * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + VScaling = _mm_and_ps(Scaling, Mask2); + VScaling = _mm_or_ps(VScaling, ZW1); + MScaling = XMMatrixScalingFromVector(VScaling); + VRotationOrigin = _mm_and_ps(RotationOrigin, Mask2); + MRotation = XMMatrixRotationZ(Rotation); + VTranslation = _mm_and_ps(Translation, Mask2); + + M = MScaling; + M.r[3] = _mm_sub_ps(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = _mm_add_ps(M.r[3], VRotationOrigin); + M.r[3] = _mm_add_ps(M.r[3], VTranslation); + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixAffineTransformation +( + FXMVECTOR Scaling, + FXMVECTOR RotationOrigin, + FXMVECTOR RotationQuaternion, + CXMVECTOR Translation +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = MScaling * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + MScaling = XMMatrixScalingFromVector(Scaling); + VRotationOrigin = XMVectorSelect(g_XMSelect1110.v, RotationOrigin,g_XMSelect1110.v); + MRotation = XMMatrixRotationQuaternion(RotationQuaternion); + VTranslation = XMVectorSelect(g_XMSelect1110.v, Translation,g_XMSelect1110.v); + + M = MScaling; + M.r[3] = XMVectorSubtract(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = XMVectorAdd(M.r[3], VRotationOrigin); + M.r[3] = XMVectorAdd(M.r[3], VTranslation); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMMATRIX MScaling; + XMVECTOR VRotationOrigin; + XMMATRIX MRotation; + XMVECTOR VTranslation; + + // M = MScaling * Inverse(MRotationOrigin) * MRotation * MRotationOrigin * MTranslation; + + MScaling = XMMatrixScalingFromVector(Scaling); + VRotationOrigin = _mm_and_ps(RotationOrigin,g_XMMask3); + MRotation = XMMatrixRotationQuaternion(RotationQuaternion); + VTranslation = _mm_and_ps(Translation,g_XMMask3); + + M = MScaling; + M.r[3] = _mm_sub_ps(M.r[3], VRotationOrigin); + M = XMMatrixMultiply(M, MRotation); + M.r[3] = _mm_add_ps(M.r[3], VRotationOrigin); + M.r[3] = _mm_add_ps(M.r[3], VTranslation); + + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixReflect +( + FXMVECTOR ReflectionPlane +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR P; + XMVECTOR S; + XMVECTOR A, B, C, D; + XMMATRIX M; + static CONST XMVECTOR NegativeTwo = {-2.0f, -2.0f, -2.0f, 0.0f}; + + XMASSERT(!XMVector3Equal(ReflectionPlane, XMVectorZero())); + XMASSERT(!XMPlaneIsInfinite(ReflectionPlane)); + + P = XMPlaneNormalize(ReflectionPlane); + S = XMVectorMultiply(P, NegativeTwo); + + A = XMVectorSplatX(P); + B = XMVectorSplatY(P); + C = XMVectorSplatZ(P); + D = XMVectorSplatW(P); + + M.r[0] = XMVectorMultiplyAdd(A, S, g_XMIdentityR0.v); + M.r[1] = XMVectorMultiplyAdd(B, S, g_XMIdentityR1.v); + M.r[2] = XMVectorMultiplyAdd(C, S, g_XMIdentityR2.v); + M.r[3] = XMVectorMultiplyAdd(D, S, g_XMIdentityR3.v); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + static CONST XMVECTORF32 NegativeTwo = {-2.0f, -2.0f, -2.0f, 0.0f}; + + XMASSERT(!XMVector3Equal(ReflectionPlane, XMVectorZero())); + XMASSERT(!XMPlaneIsInfinite(ReflectionPlane)); + + XMVECTOR P = XMPlaneNormalize(ReflectionPlane); + XMVECTOR S = _mm_mul_ps(P,NegativeTwo); + XMVECTOR X = _mm_shuffle_ps(P,P,_MM_SHUFFLE(0,0,0,0)); + XMVECTOR Y = _mm_shuffle_ps(P,P,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR Z = _mm_shuffle_ps(P,P,_MM_SHUFFLE(2,2,2,2)); + P = _mm_shuffle_ps(P,P,_MM_SHUFFLE(3,3,3,3)); + X = _mm_mul_ps(X,S); + Y = _mm_mul_ps(Y,S); + Z = _mm_mul_ps(Z,S); + P = _mm_mul_ps(P,S); + X = _mm_add_ps(X,g_XMIdentityR0); + Y = _mm_add_ps(Y,g_XMIdentityR1); + Z = _mm_add_ps(Z,g_XMIdentityR2); + P = _mm_add_ps(P,g_XMIdentityR3); + M.r[0] = X; + M.r[1] = Y; + M.r[2] = Z; + M.r[3] = P; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixShadow +( + FXMVECTOR ShadowPlane, + FXMVECTOR LightPosition +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR P; + XMVECTOR Dot; + XMVECTOR A, B, C, D; + XMMATRIX M; + static CONST XMVECTORU32 Select0001 = {XM_SELECT_0, XM_SELECT_0, XM_SELECT_0, XM_SELECT_1}; + + XMASSERT(!XMVector3Equal(ShadowPlane, XMVectorZero())); + XMASSERT(!XMPlaneIsInfinite(ShadowPlane)); + + P = XMPlaneNormalize(ShadowPlane); + Dot = XMPlaneDot(P, LightPosition); + P = XMVectorNegate(P); + D = XMVectorSplatW(P); + C = XMVectorSplatZ(P); + B = XMVectorSplatY(P); + A = XMVectorSplatX(P); + Dot = XMVectorSelect(Select0001.v, Dot, Select0001.v); + M.r[3] = XMVectorMultiplyAdd(D, LightPosition, Dot); + Dot = XMVectorRotateLeft(Dot, 1); + M.r[2] = XMVectorMultiplyAdd(C, LightPosition, Dot); + Dot = XMVectorRotateLeft(Dot, 1); + M.r[1] = XMVectorMultiplyAdd(B, LightPosition, Dot); + Dot = XMVectorRotateLeft(Dot, 1); + M.r[0] = XMVectorMultiplyAdd(A, LightPosition, Dot); + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + XMASSERT(!XMVector3Equal(ShadowPlane, XMVectorZero())); + XMASSERT(!XMPlaneIsInfinite(ShadowPlane)); + XMVECTOR P = XMPlaneNormalize(ShadowPlane); + XMVECTOR Dot = XMPlaneDot(P,LightPosition); + // Negate + P = _mm_mul_ps(P,g_XMNegativeOne); + XMVECTOR X = _mm_shuffle_ps(P,P,_MM_SHUFFLE(0,0,0,0)); + XMVECTOR Y = _mm_shuffle_ps(P,P,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR Z = _mm_shuffle_ps(P,P,_MM_SHUFFLE(2,2,2,2)); + P = _mm_shuffle_ps(P,P,_MM_SHUFFLE(3,3,3,3)); + Dot = _mm_and_ps(Dot,g_XMMaskW); + X = _mm_mul_ps(X,LightPosition); + Y = _mm_mul_ps(Y,LightPosition); + Z = _mm_mul_ps(Z,LightPosition); + P = _mm_mul_ps(P,LightPosition); + P = _mm_add_ps(P,Dot); + Dot = _mm_shuffle_ps(Dot,Dot,_MM_SHUFFLE(0,3,2,1)); + Z = _mm_add_ps(Z,Dot); + Dot = _mm_shuffle_ps(Dot,Dot,_MM_SHUFFLE(0,3,2,1)); + Y = _mm_add_ps(Y,Dot); + Dot = _mm_shuffle_ps(Dot,Dot,_MM_SHUFFLE(0,3,2,1)); + X = _mm_add_ps(X,Dot); + // Store the resulting matrix + M.r[0] = X; + M.r[1] = Y; + M.r[2] = Z; + M.r[3] = P; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// View and projection initialization operations +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixLookAtLH +( + FXMVECTOR EyePosition, + FXMVECTOR FocusPosition, + FXMVECTOR UpDirection +) +{ + XMVECTOR EyeDirection; + XMMATRIX M; + + EyeDirection = XMVectorSubtract(FocusPosition, EyePosition); + M = XMMatrixLookToLH(EyePosition, EyeDirection, UpDirection); + + return M; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixLookAtRH +( + FXMVECTOR EyePosition, + FXMVECTOR FocusPosition, + FXMVECTOR UpDirection +) +{ + XMVECTOR NegEyeDirection; + XMMATRIX M; + + NegEyeDirection = XMVectorSubtract(EyePosition, FocusPosition); + M = XMMatrixLookToLH(EyePosition, NegEyeDirection, UpDirection); + + return M; +} + +//------------------------------------------------------------------------------ + +XMINLINE XMMATRIX XMMatrixLookToLH +( + FXMVECTOR EyePosition, + FXMVECTOR EyeDirection, + FXMVECTOR UpDirection +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegEyePosition; + XMVECTOR D0, D1, D2; + XMVECTOR R0, R1, R2; + XMMATRIX M; + + XMASSERT(!XMVector3Equal(EyeDirection, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(EyeDirection)); + XMASSERT(!XMVector3Equal(UpDirection, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(UpDirection)); + + R2 = XMVector3Normalize(EyeDirection); + + R0 = XMVector3Cross(UpDirection, R2); + R0 = XMVector3Normalize(R0); + + R1 = XMVector3Cross(R2, R0); + + NegEyePosition = XMVectorNegate(EyePosition); + + D0 = XMVector3Dot(R0, NegEyePosition); + D1 = XMVector3Dot(R1, NegEyePosition); + D2 = XMVector3Dot(R2, NegEyePosition); + + M.r[0] = XMVectorSelect(D0, R0, g_XMSelect1110.v); + M.r[1] = XMVectorSelect(D1, R1, g_XMSelect1110.v); + M.r[2] = XMVectorSelect(D2, R2, g_XMSelect1110.v); + M.r[3] = g_XMIdentityR3.v; + + M = XMMatrixTranspose(M); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + + XMASSERT(!XMVector3Equal(EyeDirection, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(EyeDirection)); + XMASSERT(!XMVector3Equal(UpDirection, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(UpDirection)); + + XMVECTOR R2 = XMVector3Normalize(EyeDirection); + XMVECTOR R0 = XMVector3Cross(UpDirection, R2); + R0 = XMVector3Normalize(R0); + XMVECTOR R1 = XMVector3Cross(R2,R0); + XMVECTOR NegEyePosition = _mm_mul_ps(EyePosition,g_XMNegativeOne); + XMVECTOR D0 = XMVector3Dot(R0,NegEyePosition); + XMVECTOR D1 = XMVector3Dot(R1,NegEyePosition); + XMVECTOR D2 = XMVector3Dot(R2,NegEyePosition); + R0 = _mm_and_ps(R0,g_XMMask3); + R1 = _mm_and_ps(R1,g_XMMask3); + R2 = _mm_and_ps(R2,g_XMMask3); + D0 = _mm_and_ps(D0,g_XMMaskW); + D1 = _mm_and_ps(D1,g_XMMaskW); + D2 = _mm_and_ps(D2,g_XMMaskW); + D0 = _mm_or_ps(D0,R0); + D1 = _mm_or_ps(D1,R1); + D2 = _mm_or_ps(D2,R2); + M.r[0] = D0; + M.r[1] = D1; + M.r[2] = D2; + M.r[3] = g_XMIdentityR3; + M = XMMatrixTranspose(M); + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixLookToRH +( + FXMVECTOR EyePosition, + FXMVECTOR EyeDirection, + FXMVECTOR UpDirection +) +{ + XMVECTOR NegEyeDirection; + XMMATRIX M; + + NegEyeDirection = XMVectorNegate(EyeDirection); + M = XMMatrixLookToLH(EyePosition, NegEyeDirection, UpDirection); + + return M; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixPerspectiveLH +( + FLOAT ViewWidth, + FLOAT ViewHeight, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT TwoNearZ, fRange; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + TwoNearZ = NearZ + NearZ; + fRange = FarZ / (FarZ - NearZ); + M.m[0][0] = TwoNearZ / ViewWidth; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = TwoNearZ / ViewHeight; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = 0.0f; + M.m[2][2] = fRange; + M.m[2][3] = 1.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = -fRange * NearZ; + M.m[3][3] = 0.0f; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + XMMATRIX M; + FLOAT TwoNearZ = NearZ + NearZ; + FLOAT fRange = FarZ / (FarZ - NearZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + TwoNearZ / ViewWidth, + TwoNearZ / ViewHeight, + fRange, + -fRange * NearZ + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // TwoNearZ / ViewWidth,0,0,0 + M.r[0] = vTemp; + // 0,TwoNearZ / ViewHeight,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // x=fRange,y=-fRange * NearZ,0,1.0f + vValues = _mm_shuffle_ps(vValues,g_XMIdentityR3,_MM_SHUFFLE(3,2,3,2)); + // 0,0,fRange,1.0f + vTemp = _mm_setzero_ps(); + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(3,0,0,0)); + M.r[2] = vTemp; + // 0,0,-fRange * NearZ,0 + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(2,1,0,0)); + M.r[3] = vTemp; + + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixPerspectiveRH +( + FLOAT ViewWidth, + FLOAT ViewHeight, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT TwoNearZ, fRange; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + TwoNearZ = NearZ + NearZ; + fRange = FarZ / (NearZ - FarZ); + M.m[0][0] = TwoNearZ / ViewWidth; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = TwoNearZ / ViewHeight; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = 0.0f; + M.m[2][1] = 0.0f; + M.m[2][2] = fRange; + M.m[2][3] = -1.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = fRange * NearZ; + M.m[3][3] = 0.0f; + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + XMMATRIX M; + FLOAT TwoNearZ = NearZ + NearZ; + FLOAT fRange = FarZ / (NearZ-FarZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + TwoNearZ / ViewWidth, + TwoNearZ / ViewHeight, + fRange, + fRange * NearZ + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // TwoNearZ / ViewWidth,0,0,0 + M.r[0] = vTemp; + // 0,TwoNearZ / ViewHeight,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // x=fRange,y=-fRange * NearZ,0,-1.0f + vValues = _mm_shuffle_ps(vValues,g_XMNegIdentityR3,_MM_SHUFFLE(3,2,3,2)); + // 0,0,fRange,-1.0f + vTemp = _mm_setzero_ps(); + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(3,0,0,0)); + M.r[2] = vTemp; + // 0,0,-fRange * NearZ,0 + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(2,1,0,0)); + M.r[3] = vTemp; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixPerspectiveFovLH +( + FLOAT FovAngleY, + FLOAT AspectHByW, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT SinFov; + FLOAT CosFov; + FLOAT Height; + FLOAT Width; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(FovAngleY, 0.0f, 0.00001f * 2.0f)); + XMASSERT(!XMScalarNearEqual(AspectHByW, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + XMScalarSinCos(&SinFov, &CosFov, 0.5f * FovAngleY); + + Height = CosFov / SinFov; + Width = Height / AspectHByW; + + M.r[0] = XMVectorSet(Width, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, Height, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, FarZ / (FarZ - NearZ), 1.0f); + M.r[3] = XMVectorSet(0.0f, 0.0f, -M.r[2].vector4_f32[2] * NearZ, 0.0f); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(FovAngleY, 0.0f, 0.00001f * 2.0f)); + XMASSERT(!XMScalarNearEqual(AspectHByW, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + XMMATRIX M; + FLOAT SinFov; + FLOAT CosFov; + XMScalarSinCos(&SinFov, &CosFov, 0.5f * FovAngleY); + FLOAT fRange = FarZ / (FarZ-NearZ); + // Note: This is recorded on the stack + FLOAT Height = CosFov / SinFov; + XMVECTOR rMem = { + Height / AspectHByW, + Height, + fRange, + -fRange * NearZ + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // CosFov / SinFov,0,0,0 + M.r[0] = vTemp; + // 0,Height / AspectHByW,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // x=fRange,y=-fRange * NearZ,0,1.0f + vTemp = _mm_setzero_ps(); + vValues = _mm_shuffle_ps(vValues,g_XMIdentityR3,_MM_SHUFFLE(3,2,3,2)); + // 0,0,fRange,1.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(3,0,0,0)); + M.r[2] = vTemp; + // 0,0,-fRange * NearZ,0.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(2,1,0,0)); + M.r[3] = vTemp; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixPerspectiveFovRH +( + FLOAT FovAngleY, + FLOAT AspectHByW, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT SinFov; + FLOAT CosFov; + FLOAT Height; + FLOAT Width; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(FovAngleY, 0.0f, 0.00001f * 2.0f)); + XMASSERT(!XMScalarNearEqual(AspectHByW, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + XMScalarSinCos(&SinFov, &CosFov, 0.5f * FovAngleY); + + Height = CosFov / SinFov; + Width = Height / AspectHByW; + + M.r[0] = XMVectorSet(Width, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, Height, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, FarZ / (NearZ - FarZ), -1.0f); + M.r[3] = XMVectorSet(0.0f, 0.0f, M.r[2].vector4_f32[2] * NearZ, 0.0f); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(FovAngleY, 0.0f, 0.00001f * 2.0f)); + XMASSERT(!XMScalarNearEqual(AspectHByW, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + XMMATRIX M; + FLOAT SinFov; + FLOAT CosFov; + XMScalarSinCos(&SinFov, &CosFov, 0.5f * FovAngleY); + FLOAT fRange = FarZ / (NearZ-FarZ); + // Note: This is recorded on the stack + FLOAT Height = CosFov / SinFov; + XMVECTOR rMem = { + Height / AspectHByW, + Height, + fRange, + fRange * NearZ + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // CosFov / SinFov,0,0,0 + M.r[0] = vTemp; + // 0,Height / AspectHByW,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // x=fRange,y=-fRange * NearZ,0,-1.0f + vTemp = _mm_setzero_ps(); + vValues = _mm_shuffle_ps(vValues,g_XMNegIdentityR3,_MM_SHUFFLE(3,2,3,2)); + // 0,0,fRange,-1.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(3,0,0,0)); + M.r[2] = vTemp; + // 0,0,fRange * NearZ,0.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(2,1,0,0)); + M.r[3] = vTemp; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixPerspectiveOffCenterLH +( + FLOAT ViewLeft, + FLOAT ViewRight, + FLOAT ViewBottom, + FLOAT ViewTop, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT TwoNearZ; + FLOAT ReciprocalWidth; + FLOAT ReciprocalHeight; + FLOAT fRange; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewRight, ViewLeft, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewTop, ViewBottom, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + TwoNearZ = NearZ + NearZ; + ReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + ReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + fRange = FarZ / (FarZ-NearZ); + + M.m[0][0] = TwoNearZ * ReciprocalWidth; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = TwoNearZ * ReciprocalHeight; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = -(ViewLeft + ViewRight) * ReciprocalWidth; + M.m[2][1] = -(ViewTop + ViewBottom) * ReciprocalHeight; + M.m[2][2] = fRange; + M.m[2][3] = 1.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = -fRange * NearZ; + M.m[3][3] = 0.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(ViewRight, ViewLeft, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewTop, ViewBottom, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + XMMATRIX M; + FLOAT TwoNearZ = NearZ+NearZ; + FLOAT ReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + FLOAT ReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + FLOAT fRange = FarZ / (FarZ-NearZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + TwoNearZ*ReciprocalWidth, + TwoNearZ*ReciprocalHeight, + -fRange * NearZ, + 0 + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // TwoNearZ*ReciprocalWidth,0,0,0 + M.r[0] = vTemp; + // 0,TwoNearZ*ReciprocalHeight,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // 0,0,fRange,1.0f + M.r[2] = XMVectorSet( -(ViewLeft + ViewRight) * ReciprocalWidth, + -(ViewTop + ViewBottom) * ReciprocalHeight, + fRange, + 1.0f ); + // 0,0,-fRange * NearZ,0.0f + vValues = _mm_and_ps(vValues,g_XMMaskZ); + M.r[3] = vValues; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixPerspectiveOffCenterRH +( + FLOAT ViewLeft, + FLOAT ViewRight, + FLOAT ViewBottom, + FLOAT ViewTop, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT TwoNearZ; + FLOAT ReciprocalWidth; + FLOAT ReciprocalHeight; + FLOAT fRange; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewRight, ViewLeft, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewTop, ViewBottom, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + TwoNearZ = NearZ + NearZ; + ReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + ReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + fRange = FarZ / (NearZ-FarZ); + + M.m[0][0] = TwoNearZ * ReciprocalWidth; + M.m[0][1] = 0.0f; + M.m[0][2] = 0.0f; + M.m[0][3] = 0.0f; + + M.m[1][0] = 0.0f; + M.m[1][1] = TwoNearZ * ReciprocalHeight; + M.m[1][2] = 0.0f; + M.m[1][3] = 0.0f; + + M.m[2][0] = (ViewLeft + ViewRight) * ReciprocalWidth; + M.m[2][1] = (ViewTop + ViewBottom) * ReciprocalHeight; + M.m[2][2] = fRange; + M.m[2][3] = -1.0f; + + M.m[3][0] = 0.0f; + M.m[3][1] = 0.0f; + M.m[3][2] = fRange * NearZ; + M.m[3][3] = 0.0f; + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(ViewRight, ViewLeft, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewTop, ViewBottom, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + XMMATRIX M; + FLOAT TwoNearZ = NearZ+NearZ; + FLOAT ReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + FLOAT ReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + FLOAT fRange = FarZ / (NearZ-FarZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + TwoNearZ*ReciprocalWidth, + TwoNearZ*ReciprocalHeight, + fRange * NearZ, + 0 + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // TwoNearZ*ReciprocalWidth,0,0,0 + M.r[0] = vTemp; + // 0,TwoNearZ*ReciprocalHeight,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // 0,0,fRange,1.0f + M.r[2] = XMVectorSet((ViewLeft + ViewRight) * ReciprocalWidth, + (ViewTop + ViewBottom) * ReciprocalHeight, + fRange, + -1.0f); + // 0,0,-fRange * NearZ,0.0f + vValues = _mm_and_ps(vValues,g_XMMaskZ); + M.r[3] = vValues; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixOrthographicLH +( + FLOAT ViewWidth, + FLOAT ViewHeight, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT fRange; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + fRange = 1.0f / (FarZ-NearZ); + M.r[0] = XMVectorSet(2.0f / ViewWidth, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, 2.0f / ViewHeight, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, fRange, 0.0f); + M.r[3] = XMVectorSet(0.0f, 0.0f, -fRange * NearZ, 1.0f); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + XMMATRIX M; + FLOAT fRange = 1.0f / (FarZ-NearZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + 2.0f / ViewWidth, + 2.0f / ViewHeight, + fRange, + -fRange * NearZ + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // 2.0f / ViewWidth,0,0,0 + M.r[0] = vTemp; + // 0,2.0f / ViewHeight,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // x=fRange,y=-fRange * NearZ,0,1.0f + vTemp = _mm_setzero_ps(); + vValues = _mm_shuffle_ps(vValues,g_XMIdentityR3,_MM_SHUFFLE(3,2,3,2)); + // 0,0,fRange,0.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(2,0,0,0)); + M.r[2] = vTemp; + // 0,0,-fRange * NearZ,1.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(3,1,0,0)); + M.r[3] = vTemp; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixOrthographicRH +( + FLOAT ViewWidth, + FLOAT ViewHeight, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + M.r[0] = XMVectorSet(2.0f / ViewWidth, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, 2.0f / ViewHeight, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, 1.0f / (NearZ - FarZ), 0.0f); + M.r[3] = XMVectorSet(0.0f, 0.0f, M.r[2].vector4_f32[2] * NearZ, 1.0f); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(!XMScalarNearEqual(ViewWidth, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewHeight, 0.0f, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + XMMATRIX M; + FLOAT fRange = 1.0f / (NearZ-FarZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + 2.0f / ViewWidth, + 2.0f / ViewHeight, + fRange, + fRange * NearZ + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // 2.0f / ViewWidth,0,0,0 + M.r[0] = vTemp; + // 0,2.0f / ViewHeight,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + M.r[1] = vTemp; + // x=fRange,y=fRange * NearZ,0,1.0f + vTemp = _mm_setzero_ps(); + vValues = _mm_shuffle_ps(vValues,g_XMIdentityR3,_MM_SHUFFLE(3,2,3,2)); + // 0,0,fRange,0.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(2,0,0,0)); + M.r[2] = vTemp; + // 0,0,fRange * NearZ,1.0f + vTemp = _mm_shuffle_ps(vTemp,vValues,_MM_SHUFFLE(3,1,0,0)); + M.r[3] = vTemp; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixOrthographicOffCenterLH +( + FLOAT ViewLeft, + FLOAT ViewRight, + FLOAT ViewBottom, + FLOAT ViewTop, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ReciprocalWidth; + FLOAT ReciprocalHeight; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewRight, ViewLeft, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewTop, ViewBottom, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + ReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + ReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + + M.r[0] = XMVectorSet(ReciprocalWidth + ReciprocalWidth, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, ReciprocalHeight + ReciprocalHeight, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, 1.0f / (FarZ - NearZ), 0.0f); + M.r[3] = XMVectorSet(-(ViewLeft + ViewRight) * ReciprocalWidth, + -(ViewTop + ViewBottom) * ReciprocalHeight, + -M.r[2].vector4_f32[2] * NearZ, + 1.0f); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + FLOAT fReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + FLOAT fReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + FLOAT fRange = 1.0f / (FarZ-NearZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + fReciprocalWidth, + fReciprocalHeight, + fRange, + 1.0f + }; + XMVECTOR rMem2 = { + -(ViewLeft + ViewRight), + -(ViewTop + ViewBottom), + -NearZ, + 1.0f + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // fReciprocalWidth*2,0,0,0 + vTemp = _mm_add_ss(vTemp,vTemp); + M.r[0] = vTemp; + // 0,fReciprocalHeight*2,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + vTemp = _mm_add_ps(vTemp,vTemp); + M.r[1] = vTemp; + // 0,0,fRange,0.0f + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskZ); + M.r[2] = vTemp; + // -(ViewLeft + ViewRight)*fReciprocalWidth,-(ViewTop + ViewBottom)*fReciprocalHeight,fRange*-NearZ,1.0f + vValues = _mm_mul_ps(vValues,rMem2); + M.r[3] = vValues; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMMATRIX XMMatrixOrthographicOffCenterRH +( + FLOAT ViewLeft, + FLOAT ViewRight, + FLOAT ViewBottom, + FLOAT ViewTop, + FLOAT NearZ, + FLOAT FarZ +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ReciprocalWidth; + FLOAT ReciprocalHeight; + XMMATRIX M; + + XMASSERT(!XMScalarNearEqual(ViewRight, ViewLeft, 0.00001f)); + XMASSERT(!XMScalarNearEqual(ViewTop, ViewBottom, 0.00001f)); + XMASSERT(!XMScalarNearEqual(FarZ, NearZ, 0.00001f)); + + ReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + ReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + + M.r[0] = XMVectorSet(ReciprocalWidth + ReciprocalWidth, 0.0f, 0.0f, 0.0f); + M.r[1] = XMVectorSet(0.0f, ReciprocalHeight + ReciprocalHeight, 0.0f, 0.0f); + M.r[2] = XMVectorSet(0.0f, 0.0f, 1.0f / (NearZ - FarZ), 0.0f); + M.r[3] = XMVectorSet(-(ViewLeft + ViewRight) * ReciprocalWidth, + -(ViewTop + ViewBottom) * ReciprocalHeight, + M.r[2].vector4_f32[2] * NearZ, + 1.0f); + + return M; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX M; + FLOAT fReciprocalWidth = 1.0f / (ViewRight - ViewLeft); + FLOAT fReciprocalHeight = 1.0f / (ViewTop - ViewBottom); + FLOAT fRange = 1.0f / (NearZ-FarZ); + // Note: This is recorded on the stack + XMVECTOR rMem = { + fReciprocalWidth, + fReciprocalHeight, + fRange, + 1.0f + }; + XMVECTOR rMem2 = { + -(ViewLeft + ViewRight), + -(ViewTop + ViewBottom), + NearZ, + 1.0f + }; + // Copy from memory to SSE register + XMVECTOR vValues = rMem; + XMVECTOR vTemp = _mm_setzero_ps(); + // Copy x only + vTemp = _mm_move_ss(vTemp,vValues); + // fReciprocalWidth*2,0,0,0 + vTemp = _mm_add_ss(vTemp,vTemp); + M.r[0] = vTemp; + // 0,fReciprocalHeight*2,0,0 + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskY); + vTemp = _mm_add_ps(vTemp,vTemp); + M.r[1] = vTemp; + // 0,0,fRange,0.0f + vTemp = vValues; + vTemp = _mm_and_ps(vTemp,g_XMMaskZ); + M.r[2] = vTemp; + // -(ViewLeft + ViewRight)*fReciprocalWidth,-(ViewTop + ViewBottom)*fReciprocalHeight,fRange*-NearZ,1.0f + vValues = _mm_mul_ps(vValues,rMem2); + M.r[3] = vValues; + return M; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + + +#ifdef __cplusplus + +/**************************************************************************** + * + * XMMATRIX operators and methods + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMMATRIX::_XMMATRIX +( + FXMVECTOR R0, + FXMVECTOR R1, + FXMVECTOR R2, + CXMVECTOR R3 +) +{ + r[0] = R0; + r[1] = R1; + r[2] = R2; + r[3] = R3; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMMATRIX::_XMMATRIX +( + FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33 +) +{ + r[0] = XMVectorSet(m00, m01, m02, m03); + r[1] = XMVectorSet(m10, m11, m12, m13); + r[2] = XMVectorSet(m20, m21, m22, m23); + r[3] = XMVectorSet(m30, m31, m32, m33); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMMATRIX::_XMMATRIX +( + CONST FLOAT* pArray +) +{ + r[0] = XMLoadFloat4((const XMFLOAT4*)pArray); + r[1] = XMLoadFloat4((const XMFLOAT4*)(pArray + 4)); + r[2] = XMLoadFloat4((const XMFLOAT4*)(pArray + 8)); + r[3] = XMLoadFloat4((const XMFLOAT4*)(pArray + 12)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMMATRIX& _XMMATRIX::operator= +( + CONST _XMMATRIX& M +) +{ + r[0] = M.r[0]; + r[1] = M.r[1]; + r[2] = M.r[2]; + r[3] = M.r[3]; + return *this; +} + +//------------------------------------------------------------------------------ + +#ifndef XM_NO_OPERATOR_OVERLOADS + +#if !defined(_XBOX_VER) && defined(_XM_ISVS2005_) && defined(_XM_X64_) +#pragma warning(push) +#pragma warning(disable : 4328) +#endif + +XMFINLINE _XMMATRIX& _XMMATRIX::operator*= +( + CONST _XMMATRIX& M +) +{ + *this = XMMatrixMultiply(*this, M); + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMMATRIX _XMMATRIX::operator* +( + CONST _XMMATRIX& M +) CONST +{ + return XMMatrixMultiply(*this, M); +} + +#if !defined(_XBOX_VER) && defined(_XM_ISVS2005_) && defined(_XM_X64_) +#pragma warning(pop) +#endif + +#endif // !XM_NO_OPERATOR_OVERLOADS + +/**************************************************************************** + * + * XMFLOAT3X3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT3X3::_XMFLOAT3X3 +( + FLOAT m00, FLOAT m01, FLOAT m02, + FLOAT m10, FLOAT m11, FLOAT m12, + FLOAT m20, FLOAT m21, FLOAT m22 +) +{ + m[0][0] = m00; + m[0][1] = m01; + m[0][2] = m02; + + m[1][0] = m10; + m[1][1] = m11; + m[1][2] = m12; + + m[2][0] = m20; + m[2][1] = m21; + m[2][2] = m22; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT3X3::_XMFLOAT3X3 +( + CONST FLOAT* pArray +) +{ + UINT Row; + UINT Column; + + for (Row = 0; Row < 3; Row++) + { + for (Column = 0; Column < 3; Column++) + { + m[Row][Column] = pArray[Row * 3 + Column]; + } + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT3X3& _XMFLOAT3X3::operator= +( + CONST _XMFLOAT3X3& Float3x3 +) +{ + _11 = Float3x3._11; + _12 = Float3x3._12; + _13 = Float3x3._13; + _21 = Float3x3._21; + _22 = Float3x3._22; + _23 = Float3x3._23; + _31 = Float3x3._31; + _32 = Float3x3._32; + _33 = Float3x3._33; + + return *this; +} + +/**************************************************************************** + * + * XMFLOAT4X3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4X3::_XMFLOAT4X3 +( + FLOAT m00, FLOAT m01, FLOAT m02, + FLOAT m10, FLOAT m11, FLOAT m12, + FLOAT m20, FLOAT m21, FLOAT m22, + FLOAT m30, FLOAT m31, FLOAT m32 +) +{ + m[0][0] = m00; + m[0][1] = m01; + m[0][2] = m02; + + m[1][0] = m10; + m[1][1] = m11; + m[1][2] = m12; + + m[2][0] = m20; + m[2][1] = m21; + m[2][2] = m22; + + m[3][0] = m30; + m[3][1] = m31; + m[3][2] = m32; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4X3::_XMFLOAT4X3 +( + CONST FLOAT* pArray +) +{ + UINT Row; + UINT Column; + + for (Row = 0; Row < 4; Row++) + { + for (Column = 0; Column < 3; Column++) + { + m[Row][Column] = pArray[Row * 3 + Column]; + } + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4X3& _XMFLOAT4X3::operator= +( + CONST _XMFLOAT4X3& Float4x3 +) +{ + XMVECTOR V1 = XMLoadFloat4((const XMFLOAT4*)&Float4x3._11); + XMVECTOR V2 = XMLoadFloat4((const XMFLOAT4*)&Float4x3._22); + XMVECTOR V3 = XMLoadFloat4((const XMFLOAT4*)&Float4x3._33); + + XMStoreFloat4((XMFLOAT4*)&_11, V1); + XMStoreFloat4((XMFLOAT4*)&_22, V2); + XMStoreFloat4((XMFLOAT4*)&_33, V3); + + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMFLOAT4X3A& XMFLOAT4X3A::operator= +( + CONST XMFLOAT4X3A& Float4x3 +) +{ + XMVECTOR V1 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x3._11); + XMVECTOR V2 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x3._22); + XMVECTOR V3 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x3._33); + + XMStoreFloat4A((XMFLOAT4A*)&_11, V1); + XMStoreFloat4A((XMFLOAT4A*)&_22, V2); + XMStoreFloat4A((XMFLOAT4A*)&_33, V3); + + return *this; +} + +/**************************************************************************** + * + * XMFLOAT4X4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4X4::_XMFLOAT4X4 +( + FLOAT m00, FLOAT m01, FLOAT m02, FLOAT m03, + FLOAT m10, FLOAT m11, FLOAT m12, FLOAT m13, + FLOAT m20, FLOAT m21, FLOAT m22, FLOAT m23, + FLOAT m30, FLOAT m31, FLOAT m32, FLOAT m33 +) +{ + m[0][0] = m00; + m[0][1] = m01; + m[0][2] = m02; + m[0][3] = m03; + + m[1][0] = m10; + m[1][1] = m11; + m[1][2] = m12; + m[1][3] = m13; + + m[2][0] = m20; + m[2][1] = m21; + m[2][2] = m22; + m[2][3] = m23; + + m[3][0] = m30; + m[3][1] = m31; + m[3][2] = m32; + m[3][3] = m33; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4X4::_XMFLOAT4X4 +( + CONST FLOAT* pArray +) +{ + UINT Row; + UINT Column; + + for (Row = 0; Row < 4; Row++) + { + for (Column = 0; Column < 4; Column++) + { + m[Row][Column] = pArray[Row * 4 + Column]; + } + } +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4X4& _XMFLOAT4X4::operator= +( + CONST _XMFLOAT4X4& Float4x4 +) +{ + XMVECTOR V1 = XMLoadFloat4((const XMFLOAT4*)&Float4x4._11); + XMVECTOR V2 = XMLoadFloat4((const XMFLOAT4*)&Float4x4._21); + XMVECTOR V3 = XMLoadFloat4((const XMFLOAT4*)&Float4x4._31); + XMVECTOR V4 = XMLoadFloat4((const XMFLOAT4*)&Float4x4._41); + + XMStoreFloat4((XMFLOAT4*)&_11, V1); + XMStoreFloat4((XMFLOAT4*)&_21, V2); + XMStoreFloat4((XMFLOAT4*)&_31, V3); + XMStoreFloat4((XMFLOAT4*)&_41, V4); + + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMFLOAT4X4A& XMFLOAT4X4A::operator= +( + CONST XMFLOAT4X4A& Float4x4 +) +{ + XMVECTOR V1 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x4._11); + XMVECTOR V2 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x4._21); + XMVECTOR V3 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x4._31); + XMVECTOR V4 = XMLoadFloat4A((const XMFLOAT4A*)&Float4x4._41); + + XMStoreFloat4A((XMFLOAT4A*)&_11, V1); + XMStoreFloat4A((XMFLOAT4A*)&_21, V2); + XMStoreFloat4A((XMFLOAT4A*)&_31, V3); + XMStoreFloat4A((XMFLOAT4A*)&_41, V4); + + return *this; +} + +#endif // __cplusplus + +#endif // __XNAMATHMATRIX_INL__ + diff --git a/third_party/xbox_sdk/include/xnamathmisc.inl b/third_party/xbox_sdk/include/xnamathmisc.inl new file mode 100644 index 0000000..d4d4ef2 --- /dev/null +++ b/third_party/xbox_sdk/include/xnamathmisc.inl @@ -0,0 +1,2460 @@ +/************************************************************************ +* * +* xnamathmisc.inl -- SIMD C++ Math library for Windows and Xbox 360 * +* Quaternion, plane, and color functions * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ + +#if defined(_MSC_VER) && (_MSC_VER > 1000) +#pragma once +#endif + +#ifndef __XNAMATHMISC_INL__ +#define __XNAMATHMISC_INL__ + +/**************************************************************************** + * + * Quaternion + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMQuaternionEqual +( + FXMVECTOR Q1, + FXMVECTOR Q2 +) +{ + return XMVector4Equal(Q1, Q2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMQuaternionNotEqual +( + FXMVECTOR Q1, + FXMVECTOR Q2 +) +{ + return XMVector4NotEqual(Q1, Q2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMQuaternionIsNaN +( + FXMVECTOR Q +) +{ + return XMVector4IsNaN(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMQuaternionIsInfinite +( + FXMVECTOR Q +) +{ + return XMVector4IsInfinite(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMQuaternionIsIdentity +( + FXMVECTOR Q +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return XMVector4Equal(Q, g_XMIdentityR3.v); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(Q,g_XMIdentityR3); + return (_mm_movemask_ps(vTemp)==0x0f); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionDot +( + FXMVECTOR Q1, + FXMVECTOR Q2 +) +{ + return XMVector4Dot(Q1, Q2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionMultiply +( + FXMVECTOR Q1, + FXMVECTOR Q2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegativeQ1; + XMVECTOR Q2X; + XMVECTOR Q2Y; + XMVECTOR Q2Z; + XMVECTOR Q2W; + XMVECTOR Q1WZYX; + XMVECTOR Q1ZWXY; + XMVECTOR Q1YXWZ; + XMVECTOR Result; + CONST XMVECTORU32 ControlWZYX = {XM_PERMUTE_0W, XM_PERMUTE_1Z, XM_PERMUTE_0Y, XM_PERMUTE_1X}; + CONST XMVECTORU32 ControlZWXY = {XM_PERMUTE_0Z, XM_PERMUTE_0W, XM_PERMUTE_1X, XM_PERMUTE_1Y}; + CONST XMVECTORU32 ControlYXWZ = {XM_PERMUTE_1Y, XM_PERMUTE_0X, XM_PERMUTE_0W, XM_PERMUTE_1Z}; + + NegativeQ1 = XMVectorNegate(Q1); + + Q2W = XMVectorSplatW(Q2); + Q2X = XMVectorSplatX(Q2); + Q2Y = XMVectorSplatY(Q2); + Q2Z = XMVectorSplatZ(Q2); + + Q1WZYX = XMVectorPermute(Q1, NegativeQ1, ControlWZYX.v); + Q1ZWXY = XMVectorPermute(Q1, NegativeQ1, ControlZWXY.v); + Q1YXWZ = XMVectorPermute(Q1, NegativeQ1, ControlYXWZ.v); + + Result = XMVectorMultiply(Q1, Q2W); + Result = XMVectorMultiplyAdd(Q1WZYX, Q2X, Result); + Result = XMVectorMultiplyAdd(Q1ZWXY, Q2Y, Result); + Result = XMVectorMultiplyAdd(Q1YXWZ, Q2Z, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 ControlWZYX = { 1.0f,-1.0f, 1.0f,-1.0f}; + static CONST XMVECTORF32 ControlZWXY = { 1.0f, 1.0f,-1.0f,-1.0f}; + static CONST XMVECTORF32 ControlYXWZ = {-1.0f, 1.0f, 1.0f,-1.0f}; + // Copy to SSE registers and use as few as possible for x86 + XMVECTOR Q2X = Q2; + XMVECTOR Q2Y = Q2; + XMVECTOR Q2Z = Q2; + XMVECTOR vResult = Q2; + // Splat with one instruction + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,3,3,3)); + Q2X = _mm_shuffle_ps(Q2X,Q2X,_MM_SHUFFLE(0,0,0,0)); + Q2Y = _mm_shuffle_ps(Q2Y,Q2Y,_MM_SHUFFLE(1,1,1,1)); + Q2Z = _mm_shuffle_ps(Q2Z,Q2Z,_MM_SHUFFLE(2,2,2,2)); + // Retire Q1 and perform Q1*Q2W + vResult = _mm_mul_ps(vResult,Q1); + XMVECTOR Q1Shuffle = Q1; + // Shuffle the copies of Q1 + Q1Shuffle = _mm_shuffle_ps(Q1Shuffle,Q1Shuffle,_MM_SHUFFLE(0,1,2,3)); + // Mul by Q1WZYX + Q2X = _mm_mul_ps(Q2X,Q1Shuffle); + Q1Shuffle = _mm_shuffle_ps(Q1Shuffle,Q1Shuffle,_MM_SHUFFLE(2,3,0,1)); + // Flip the signs on y and z + Q2X = _mm_mul_ps(Q2X,ControlWZYX); + // Mul by Q1ZWXY + Q2Y = _mm_mul_ps(Q2Y,Q1Shuffle); + Q1Shuffle = _mm_shuffle_ps(Q1Shuffle,Q1Shuffle,_MM_SHUFFLE(0,1,2,3)); + // Flip the signs on z and w + Q2Y = _mm_mul_ps(Q2Y,ControlZWXY); + // Mul by Q1YXWZ + Q2Z = _mm_mul_ps(Q2Z,Q1Shuffle); + vResult = _mm_add_ps(vResult,Q2X); + // Flip the signs on x and w + Q2Z = _mm_mul_ps(Q2Z,ControlYXWZ); + Q2Y = _mm_add_ps(Q2Y,Q2Z); + vResult = _mm_add_ps(vResult,Q2Y); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionLengthSq +( + FXMVECTOR Q +) +{ + return XMVector4LengthSq(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionReciprocalLength +( + FXMVECTOR Q +) +{ + return XMVector4ReciprocalLength(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionLength +( + FXMVECTOR Q +) +{ + return XMVector4Length(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionNormalizeEst +( + FXMVECTOR Q +) +{ + return XMVector4NormalizeEst(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionNormalize +( + FXMVECTOR Q +) +{ + return XMVector4Normalize(Q); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionConjugate +( + FXMVECTOR Q +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result = { + -Q.vector4_f32[0], + -Q.vector4_f32[1], + -Q.vector4_f32[2], + Q.vector4_f32[3] + }; + return Result; +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 NegativeOne3 = {-1.0f,-1.0f,-1.0f,1.0f}; + XMVECTOR Result = _mm_mul_ps(Q,NegativeOne3); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionInverse +( + FXMVECTOR Q +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Conjugate; + XMVECTOR L; + XMVECTOR Control; + XMVECTOR Result; + CONST XMVECTOR Zero = XMVectorZero(); + + L = XMVector4LengthSq(Q); + Conjugate = XMQuaternionConjugate(Q); + + Control = XMVectorLessOrEqual(L, g_XMEpsilon.v); + + L = XMVectorReciprocal(L); + Result = XMVectorMultiply(Conjugate, L); + + Result = XMVectorSelect(Result, Zero, Control); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Conjugate; + XMVECTOR L; + XMVECTOR Control; + XMVECTOR Result; + XMVECTOR Zero = XMVectorZero(); + + L = XMVector4LengthSq(Q); + Conjugate = XMQuaternionConjugate(Q); + Control = XMVectorLessOrEqual(L, g_XMEpsilon); + Result = _mm_div_ps(Conjugate,L); + Result = XMVectorSelect(Result, Zero, Control); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionLn +( + FXMVECTOR Q +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Q0; + XMVECTOR QW; + XMVECTOR Theta; + XMVECTOR SinTheta; + XMVECTOR S; + XMVECTOR ControlW; + XMVECTOR Result; + static CONST XMVECTOR OneMinusEpsilon = {1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f}; + + QW = XMVectorSplatW(Q); + Q0 = XMVectorSelect(g_XMSelect1110.v, Q, g_XMSelect1110.v); + + ControlW = XMVectorInBounds(QW, OneMinusEpsilon); + + Theta = XMVectorACos(QW); + SinTheta = XMVectorSin(Theta); + + S = XMVectorReciprocal(SinTheta); + S = XMVectorMultiply(Theta, S); + + Result = XMVectorMultiply(Q0, S); + + Result = XMVectorSelect(Q0, Result, ControlW); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 OneMinusEpsilon = {1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f}; + static CONST XMVECTORF32 NegOneMinusEpsilon = {-(1.0f - 0.00001f), -(1.0f - 0.00001f),-(1.0f - 0.00001f),-(1.0f - 0.00001f)}; + // Get W only + XMVECTOR QW = _mm_shuffle_ps(Q,Q,_MM_SHUFFLE(3,3,3,3)); + // W = 0 + XMVECTOR Q0 = _mm_and_ps(Q,g_XMMask3); + // Use W if within bounds + XMVECTOR ControlW = _mm_cmple_ps(QW,OneMinusEpsilon); + XMVECTOR vTemp2 = _mm_cmpge_ps(QW,NegOneMinusEpsilon); + ControlW = _mm_and_ps(ControlW,vTemp2); + // Get theta + XMVECTOR vTheta = XMVectorACos(QW); + // Get Sine of theta + vTemp2 = XMVectorSin(vTheta); + // theta/sine of theta + vTheta = _mm_div_ps(vTheta,vTemp2); + // Here's the answer + vTheta = _mm_mul_ps(vTheta,Q0); + // Was W in bounds? If not, return input as is + vTheta = XMVectorSelect(Q0,vTheta,ControlW); + return vTheta; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionExp +( + FXMVECTOR Q +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Theta; + XMVECTOR SinTheta; + XMVECTOR CosTheta; + XMVECTOR S; + XMVECTOR Control; + XMVECTOR Zero; + XMVECTOR Result; + + Theta = XMVector3Length(Q); + XMVectorSinCos(&SinTheta, &CosTheta, Theta); + + S = XMVectorReciprocal(Theta); + S = XMVectorMultiply(SinTheta, S); + + Result = XMVectorMultiply(Q, S); + + Zero = XMVectorZero(); + Control = XMVectorNearEqual(Theta, Zero, g_XMEpsilon.v); + Result = XMVectorSelect(Result, Q, Control); + + Result = XMVectorSelect(CosTheta, Result, g_XMSelect1110.v); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Theta; + XMVECTOR SinTheta; + XMVECTOR CosTheta; + XMVECTOR S; + XMVECTOR Control; + XMVECTOR Zero; + XMVECTOR Result; + Theta = XMVector3Length(Q); + XMVectorSinCos(&SinTheta, &CosTheta, Theta); + S = _mm_div_ps(SinTheta,Theta); + Result = _mm_mul_ps(Q, S); + Zero = XMVectorZero(); + Control = XMVectorNearEqual(Theta, Zero, g_XMEpsilon); + Result = XMVectorSelect(Result,Q,Control); + Result = _mm_and_ps(Result,g_XMMask3); + CosTheta = _mm_and_ps(CosTheta,g_XMMaskW); + Result = _mm_or_ps(Result,CosTheta); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMQuaternionSlerp +( + FXMVECTOR Q0, + FXMVECTOR Q1, + FLOAT t +) +{ + XMVECTOR T = XMVectorReplicate(t); + return XMQuaternionSlerpV(Q0, Q1, T); +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMQuaternionSlerpV +( + FXMVECTOR Q0, + FXMVECTOR Q1, + FXMVECTOR T +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // Result = Q0 * sin((1.0 - t) * Omega) / sin(Omega) + Q1 * sin(t * Omega) / sin(Omega) + XMVECTOR Omega; + XMVECTOR CosOmega; + XMVECTOR SinOmega; + XMVECTOR InvSinOmega; + XMVECTOR V01; + XMVECTOR C1000; + XMVECTOR SignMask; + XMVECTOR S0; + XMVECTOR S1; + XMVECTOR Sign; + XMVECTOR Control; + XMVECTOR Result; + XMVECTOR Zero; + CONST XMVECTOR OneMinusEpsilon = {1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f}; + + XMASSERT((T.vector4_f32[1] == T.vector4_f32[0]) && (T.vector4_f32[2] == T.vector4_f32[0]) && (T.vector4_f32[3] == T.vector4_f32[0])); + + CosOmega = XMQuaternionDot(Q0, Q1); + + Zero = XMVectorZero(); + Control = XMVectorLess(CosOmega, Zero); + Sign = XMVectorSelect(g_XMOne.v, g_XMNegativeOne.v, Control); + + CosOmega = XMVectorMultiply(CosOmega, Sign); + + Control = XMVectorLess(CosOmega, OneMinusEpsilon); + + SinOmega = XMVectorNegativeMultiplySubtract(CosOmega, CosOmega, g_XMOne.v); + SinOmega = XMVectorSqrt(SinOmega); + + Omega = XMVectorATan2(SinOmega, CosOmega); + + SignMask = XMVectorSplatSignMask(); + C1000 = XMVectorSetBinaryConstant(1, 0, 0, 0); + V01 = XMVectorShiftLeft(T, Zero, 2); + SignMask = XMVectorShiftLeft(SignMask, Zero, 3); + V01 = XMVectorXorInt(V01, SignMask); + V01 = XMVectorAdd(C1000, V01); + + InvSinOmega = XMVectorReciprocal(SinOmega); + + S0 = XMVectorMultiply(V01, Omega); + S0 = XMVectorSin(S0); + S0 = XMVectorMultiply(S0, InvSinOmega); + + S0 = XMVectorSelect(V01, S0, Control); + + S1 = XMVectorSplatY(S0); + S0 = XMVectorSplatX(S0); + + S1 = XMVectorMultiply(S1, Sign); + + Result = XMVectorMultiply(Q0, S0); + Result = XMVectorMultiplyAdd(Q1, S1, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = Q0 * sin((1.0 - t) * Omega) / sin(Omega) + Q1 * sin(t * Omega) / sin(Omega) + XMVECTOR Omega; + XMVECTOR CosOmega; + XMVECTOR SinOmega; + XMVECTOR V01; + XMVECTOR S0; + XMVECTOR S1; + XMVECTOR Sign; + XMVECTOR Control; + XMVECTOR Result; + XMVECTOR Zero; + static const XMVECTORF32 OneMinusEpsilon = {1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f, 1.0f - 0.00001f}; + static const XMVECTORI32 SignMask2 = {0x80000000,0x00000000,0x00000000,0x00000000}; + static const XMVECTORI32 MaskXY = {0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000}; + + XMASSERT((XMVectorGetY(T) == XMVectorGetX(T)) && (XMVectorGetZ(T) == XMVectorGetX(T)) && (XMVectorGetW(T) == XMVectorGetX(T))); + + CosOmega = XMQuaternionDot(Q0, Q1); + + Zero = XMVectorZero(); + Control = XMVectorLess(CosOmega, Zero); + Sign = XMVectorSelect(g_XMOne, g_XMNegativeOne, Control); + + CosOmega = _mm_mul_ps(CosOmega, Sign); + + Control = XMVectorLess(CosOmega, OneMinusEpsilon); + + SinOmega = _mm_mul_ps(CosOmega,CosOmega); + SinOmega = _mm_sub_ps(g_XMOne,SinOmega); + SinOmega = _mm_sqrt_ps(SinOmega); + + Omega = XMVectorATan2(SinOmega, CosOmega); + + V01 = _mm_shuffle_ps(T,T,_MM_SHUFFLE(2,3,0,1)); + V01 = _mm_and_ps(V01,MaskXY); + V01 = _mm_xor_ps(V01,SignMask2); + V01 = _mm_add_ps(g_XMIdentityR0, V01); + + S0 = _mm_mul_ps(V01, Omega); + S0 = XMVectorSin(S0); + S0 = _mm_div_ps(S0, SinOmega); + + S0 = XMVectorSelect(V01, S0, Control); + + S1 = XMVectorSplatY(S0); + S0 = XMVectorSplatX(S0); + + S1 = _mm_mul_ps(S1, Sign); + Result = _mm_mul_ps(Q0, S0); + S1 = _mm_mul_ps(S1, Q1); + Result = _mm_add_ps(Result,S1); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionSquad +( + FXMVECTOR Q0, + FXMVECTOR Q1, + FXMVECTOR Q2, + CXMVECTOR Q3, + FLOAT t +) +{ + XMVECTOR T = XMVectorReplicate(t); + return XMQuaternionSquadV(Q0, Q1, Q2, Q3, T); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionSquadV +( + FXMVECTOR Q0, + FXMVECTOR Q1, + FXMVECTOR Q2, + CXMVECTOR Q3, + CXMVECTOR T +) +{ + XMVECTOR Q03; + XMVECTOR Q12; + XMVECTOR TP; + XMVECTOR Two; + XMVECTOR Result; + + XMASSERT( (XMVectorGetY(T) == XMVectorGetX(T)) && (XMVectorGetZ(T) == XMVectorGetX(T)) && (XMVectorGetW(T) == XMVectorGetX(T)) ); + + TP = T; + Two = XMVectorSplatConstant(2, 0); + + Q03 = XMQuaternionSlerpV(Q0, Q3, T); + Q12 = XMQuaternionSlerpV(Q1, Q2, T); + + TP = XMVectorNegativeMultiplySubtract(TP, TP, TP); + TP = XMVectorMultiply(TP, Two); + + Result = XMQuaternionSlerpV(Q03, Q12, TP); + + return Result; + +} + +//------------------------------------------------------------------------------ + +XMINLINE VOID XMQuaternionSquadSetup +( + XMVECTOR* pA, + XMVECTOR* pB, + XMVECTOR* pC, + FXMVECTOR Q0, + FXMVECTOR Q1, + FXMVECTOR Q2, + CXMVECTOR Q3 +) +{ + XMVECTOR SQ0, SQ2, SQ3; + XMVECTOR InvQ1, InvQ2; + XMVECTOR LnQ0, LnQ1, LnQ2, LnQ3; + XMVECTOR ExpQ02, ExpQ13; + XMVECTOR LS01, LS12, LS23; + XMVECTOR LD01, LD12, LD23; + XMVECTOR Control0, Control1, Control2; + XMVECTOR NegativeOneQuarter; + + XMASSERT(pA); + XMASSERT(pB); + XMASSERT(pC); + + LS12 = XMQuaternionLengthSq(XMVectorAdd(Q1, Q2)); + LD12 = XMQuaternionLengthSq(XMVectorSubtract(Q1, Q2)); + SQ2 = XMVectorNegate(Q2); + + Control1 = XMVectorLess(LS12, LD12); + SQ2 = XMVectorSelect(Q2, SQ2, Control1); + + LS01 = XMQuaternionLengthSq(XMVectorAdd(Q0, Q1)); + LD01 = XMQuaternionLengthSq(XMVectorSubtract(Q0, Q1)); + SQ0 = XMVectorNegate(Q0); + + LS23 = XMQuaternionLengthSq(XMVectorAdd(SQ2, Q3)); + LD23 = XMQuaternionLengthSq(XMVectorSubtract(SQ2, Q3)); + SQ3 = XMVectorNegate(Q3); + + Control0 = XMVectorLess(LS01, LD01); + Control2 = XMVectorLess(LS23, LD23); + + SQ0 = XMVectorSelect(Q0, SQ0, Control0); + SQ3 = XMVectorSelect(Q3, SQ3, Control2); + + InvQ1 = XMQuaternionInverse(Q1); + InvQ2 = XMQuaternionInverse(SQ2); + + LnQ0 = XMQuaternionLn(XMQuaternionMultiply(InvQ1, SQ0)); + LnQ2 = XMQuaternionLn(XMQuaternionMultiply(InvQ1, SQ2)); + LnQ1 = XMQuaternionLn(XMQuaternionMultiply(InvQ2, Q1)); + LnQ3 = XMQuaternionLn(XMQuaternionMultiply(InvQ2, SQ3)); + + NegativeOneQuarter = XMVectorSplatConstant(-1, 2); + + ExpQ02 = XMVectorMultiply(XMVectorAdd(LnQ0, LnQ2), NegativeOneQuarter); + ExpQ13 = XMVectorMultiply(XMVectorAdd(LnQ1, LnQ3), NegativeOneQuarter); + ExpQ02 = XMQuaternionExp(ExpQ02); + ExpQ13 = XMQuaternionExp(ExpQ13); + + *pA = XMQuaternionMultiply(Q1, ExpQ02); + *pB = XMQuaternionMultiply(SQ2, ExpQ13); + *pC = SQ2; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionBaryCentric +( + FXMVECTOR Q0, + FXMVECTOR Q1, + FXMVECTOR Q2, + FLOAT f, + FLOAT g +) +{ + XMVECTOR Q01; + XMVECTOR Q02; + FLOAT s; + XMVECTOR Result; + + s = f + g; + + if ((s < 0.00001f) && (s > -0.00001f)) + { + Result = Q0; + } + else + { + Q01 = XMQuaternionSlerp(Q0, Q1, s); + Q02 = XMQuaternionSlerp(Q0, Q2, s); + + Result = XMQuaternionSlerp(Q01, Q02, g / s); + } + + return Result; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionBaryCentricV +( + FXMVECTOR Q0, + FXMVECTOR Q1, + FXMVECTOR Q2, + CXMVECTOR F, + CXMVECTOR G +) +{ + XMVECTOR Q01; + XMVECTOR Q02; + XMVECTOR S, GS; + XMVECTOR Epsilon; + XMVECTOR Result; + + XMASSERT( (XMVectorGetY(F) == XMVectorGetX(F)) && (XMVectorGetZ(F) == XMVectorGetX(F)) && (XMVectorGetW(F) == XMVectorGetX(F)) ); + XMASSERT( (XMVectorGetY(G) == XMVectorGetX(G)) && (XMVectorGetZ(G) == XMVectorGetX(G)) && (XMVectorGetW(G) == XMVectorGetX(G)) ); + + Epsilon = XMVectorSplatConstant(1, 16); + + S = XMVectorAdd(F, G); + + if (XMVector4InBounds(S, Epsilon)) + { + Result = Q0; + } + else + { + Q01 = XMQuaternionSlerpV(Q0, Q1, S); + Q02 = XMQuaternionSlerpV(Q0, Q2, S); + GS = XMVectorReciprocal(S); + GS = XMVectorMultiply(G, GS); + + Result = XMQuaternionSlerpV(Q01, Q02, GS); + } + + return Result; +} + +//------------------------------------------------------------------------------ +// Transformation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionIdentity() +{ +#if defined(_XM_NO_INTRINSICS_) + return g_XMIdentityR3.v; +#elif defined(_XM_SSE_INTRINSICS_) + return g_XMIdentityR3; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionRotationRollPitchYaw +( + FLOAT Pitch, + FLOAT Yaw, + FLOAT Roll +) +{ + XMVECTOR Angles; + XMVECTOR Q; + + Angles = XMVectorSet(Pitch, Yaw, Roll, 0.0f); + Q = XMQuaternionRotationRollPitchYawFromVector(Angles); + + return Q; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionRotationRollPitchYawFromVector +( + FXMVECTOR Angles // +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Q, Q0, Q1; + XMVECTOR P0, P1, Y0, Y1, R0, R1; + XMVECTOR HalfAngles; + XMVECTOR SinAngles, CosAngles; + static CONST XMVECTORU32 ControlPitch = {XM_PERMUTE_0X, XM_PERMUTE_1X, XM_PERMUTE_1X, XM_PERMUTE_1X}; + static CONST XMVECTORU32 ControlYaw = {XM_PERMUTE_1Y, XM_PERMUTE_0Y, XM_PERMUTE_1Y, XM_PERMUTE_1Y}; + static CONST XMVECTORU32 ControlRoll = {XM_PERMUTE_1Z, XM_PERMUTE_1Z, XM_PERMUTE_0Z, XM_PERMUTE_1Z}; + static CONST XMVECTOR Sign = {1.0f, -1.0f, -1.0f, 1.0f}; + + HalfAngles = XMVectorMultiply(Angles, g_XMOneHalf.v); + XMVectorSinCos(&SinAngles, &CosAngles, HalfAngles); + + P0 = XMVectorPermute(SinAngles, CosAngles, ControlPitch.v); + Y0 = XMVectorPermute(SinAngles, CosAngles, ControlYaw.v); + R0 = XMVectorPermute(SinAngles, CosAngles, ControlRoll.v); + P1 = XMVectorPermute(CosAngles, SinAngles, ControlPitch.v); + Y1 = XMVectorPermute(CosAngles, SinAngles, ControlYaw.v); + R1 = XMVectorPermute(CosAngles, SinAngles, ControlRoll.v); + + Q1 = XMVectorMultiply(P1, Sign); + Q0 = XMVectorMultiply(P0, Y0); + Q1 = XMVectorMultiply(Q1, Y1); + Q0 = XMVectorMultiply(Q0, R0); + Q = XMVectorMultiplyAdd(Q1, R1, Q0); + + return Q; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Q, Q0, Q1; + XMVECTOR P0, P1, Y0, Y1, R0, R1; + XMVECTOR HalfAngles; + XMVECTOR SinAngles, CosAngles; + static CONST XMVECTORI32 ControlPitch = {XM_PERMUTE_0X, XM_PERMUTE_1X, XM_PERMUTE_1X, XM_PERMUTE_1X}; + static CONST XMVECTORI32 ControlYaw = {XM_PERMUTE_1Y, XM_PERMUTE_0Y, XM_PERMUTE_1Y, XM_PERMUTE_1Y}; + static CONST XMVECTORI32 ControlRoll = {XM_PERMUTE_1Z, XM_PERMUTE_1Z, XM_PERMUTE_0Z, XM_PERMUTE_1Z}; + static CONST XMVECTORF32 Sign = {1.0f, -1.0f, -1.0f, 1.0f}; + + HalfAngles = _mm_mul_ps(Angles, g_XMOneHalf); + XMVectorSinCos(&SinAngles, &CosAngles, HalfAngles); + + P0 = XMVectorPermute(SinAngles, CosAngles, ControlPitch); + Y0 = XMVectorPermute(SinAngles, CosAngles, ControlYaw); + R0 = XMVectorPermute(SinAngles, CosAngles, ControlRoll); + P1 = XMVectorPermute(CosAngles, SinAngles, ControlPitch); + Y1 = XMVectorPermute(CosAngles, SinAngles, ControlYaw); + R1 = XMVectorPermute(CosAngles, SinAngles, ControlRoll); + + Q1 = _mm_mul_ps(P1, Sign); + Q0 = _mm_mul_ps(P0, Y0); + Q1 = _mm_mul_ps(Q1, Y1); + Q0 = _mm_mul_ps(Q0, R0); + Q = _mm_mul_ps(Q1, R1); + Q = _mm_add_ps(Q,Q0); + return Q; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionRotationNormal +( + FXMVECTOR NormalAxis, + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Q; + XMVECTOR N; + XMVECTOR Scale; + + N = XMVectorSelect(g_XMOne.v, NormalAxis, g_XMSelect1110.v); + + XMScalarSinCos(&Scale.vector4_f32[2], &Scale.vector4_f32[3], 0.5f * Angle); + + Scale.vector4_f32[0] = Scale.vector4_f32[1] = Scale.vector4_f32[2]; + + Q = XMVectorMultiply(N, Scale); + + return Q; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR N = _mm_and_ps(NormalAxis,g_XMMask3); + N = _mm_or_ps(N,g_XMIdentityR3); + XMVECTOR Scale = _mm_set_ps1(0.5f * Angle); + XMVECTOR vSine; + XMVECTOR vCosine; + XMVectorSinCos(&vSine,&vCosine,Scale); + Scale = _mm_and_ps(vSine,g_XMMask3); + vCosine = _mm_and_ps(vCosine,g_XMMaskW); + Scale = _mm_or_ps(Scale,vCosine); + N = _mm_mul_ps(N,Scale); + return N; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMQuaternionRotationAxis +( + FXMVECTOR Axis, + FLOAT Angle +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Normal; + XMVECTOR Q; + + XMASSERT(!XMVector3Equal(Axis, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(Axis)); + + Normal = XMVector3Normalize(Axis); + Q = XMQuaternionRotationNormal(Normal, Angle); + + return Q; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Normal; + XMVECTOR Q; + + XMASSERT(!XMVector3Equal(Axis, XMVectorZero())); + XMASSERT(!XMVector3IsInfinite(Axis)); + + Normal = XMVector3Normalize(Axis); + Q = XMQuaternionRotationNormal(Normal, Angle); + return Q; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMQuaternionRotationMatrix +( + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + + XMVECTOR Q0, Q1, Q2; + XMVECTOR M00, M11, M22; + XMVECTOR CQ0, CQ1, C; + XMVECTOR CX, CY, CZ, CW; + XMVECTOR SQ1, Scale; + XMVECTOR Rsq, Sqrt, VEqualsNaN; + XMVECTOR A, B, P; + XMVECTOR PermuteSplat, PermuteSplatT; + XMVECTOR SignB, SignBT; + XMVECTOR PermuteControl, PermuteControlT; + XMVECTOR Result; + static CONST XMVECTORF32 OneQuarter = {0.25f, 0.25f, 0.25f, 0.25f}; + static CONST XMVECTORF32 SignPNNP = {1.0f, -1.0f, -1.0f, 1.0f}; + static CONST XMVECTORF32 SignNPNP = {-1.0f, 1.0f, -1.0f, 1.0f}; + static CONST XMVECTORF32 SignNNPP = {-1.0f, -1.0f, 1.0f, 1.0f}; + static CONST XMVECTORF32 SignPNPP = {1.0f, -1.0f, 1.0f, 1.0f}; + static CONST XMVECTORF32 SignPPNP = {1.0f, 1.0f, -1.0f, 1.0f}; + static CONST XMVECTORF32 SignNPPP = {-1.0f, 1.0f, 1.0f, 1.0f}; + static CONST XMVECTORU32 Permute0X0X0Y0W = {XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0Y, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute0Y0Z0Z1W = {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0Z, XM_PERMUTE_1W}; + static CONST XMVECTORU32 SplatX = {XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0X}; + static CONST XMVECTORU32 SplatY = {XM_PERMUTE_0Y, XM_PERMUTE_0Y, XM_PERMUTE_0Y, XM_PERMUTE_0Y}; + static CONST XMVECTORU32 SplatZ = {XM_PERMUTE_0Z, XM_PERMUTE_0Z, XM_PERMUTE_0Z, XM_PERMUTE_0Z}; + static CONST XMVECTORU32 SplatW = {XM_PERMUTE_0W, XM_PERMUTE_0W, XM_PERMUTE_0W, XM_PERMUTE_0W}; + static CONST XMVECTORU32 PermuteC = {XM_PERMUTE_0X, XM_PERMUTE_0Z, XM_PERMUTE_1X, XM_PERMUTE_1Y}; + static CONST XMVECTORU32 PermuteA = {XM_PERMUTE_0Y, XM_PERMUTE_1Y, XM_PERMUTE_1Z, XM_PERMUTE_0W}; + static CONST XMVECTORU32 PermuteB = {XM_PERMUTE_1X, XM_PERMUTE_1W, XM_PERMUTE_0Z, XM_PERMUTE_0W}; + static CONST XMVECTORU32 Permute0 = {XM_PERMUTE_0X, XM_PERMUTE_1X, XM_PERMUTE_1Z, XM_PERMUTE_1Y}; + static CONST XMVECTORU32 Permute1 = {XM_PERMUTE_1X, XM_PERMUTE_0Y, XM_PERMUTE_1Y, XM_PERMUTE_1Z}; + static CONST XMVECTORU32 Permute2 = {XM_PERMUTE_1Z, XM_PERMUTE_1Y, XM_PERMUTE_0Z, XM_PERMUTE_1X}; + static CONST XMVECTORU32 Permute3 = {XM_PERMUTE_1Y, XM_PERMUTE_1Z, XM_PERMUTE_1X, XM_PERMUTE_0W}; + + M00 = XMVectorSplatX(M.r[0]); + M11 = XMVectorSplatY(M.r[1]); + M22 = XMVectorSplatZ(M.r[2]); + + Q0 = XMVectorMultiply(SignPNNP.v, M00); + Q0 = XMVectorMultiplyAdd(SignNPNP.v, M11, Q0); + Q0 = XMVectorMultiplyAdd(SignNNPP.v, M22, Q0); + + Q1 = XMVectorAdd(Q0, g_XMOne.v); + + Rsq = XMVectorReciprocalSqrt(Q1); + VEqualsNaN = XMVectorIsNaN(Rsq); + Sqrt = XMVectorMultiply(Q1, Rsq); + Q1 = XMVectorSelect(Sqrt, Q1, VEqualsNaN); + + Q1 = XMVectorMultiply(Q1, g_XMOneHalf.v); + + SQ1 = XMVectorMultiply(Rsq, g_XMOneHalf.v); + + CQ0 = XMVectorPermute(Q0, Q0, Permute0X0X0Y0W.v); + CQ1 = XMVectorPermute(Q0, g_XMEpsilon.v, Permute0Y0Z0Z1W.v); + C = XMVectorGreaterOrEqual(CQ0, CQ1); + + CX = XMVectorSplatX(C); + CY = XMVectorSplatY(C); + CZ = XMVectorSplatZ(C); + CW = XMVectorSplatW(C); + + PermuteSplat = XMVectorSelect(SplatZ.v, SplatY.v, CZ); + SignB = XMVectorSelect(SignNPPP.v, SignPPNP.v, CZ); + PermuteControl = XMVectorSelect(Permute2.v, Permute1.v, CZ); + + PermuteSplat = XMVectorSelect(PermuteSplat, SplatZ.v, CX); + SignB = XMVectorSelect(SignB, SignNPPP.v, CX); + PermuteControl = XMVectorSelect(PermuteControl, Permute2.v, CX); + + PermuteSplatT = XMVectorSelect(PermuteSplat,SplatX.v, CY); + SignBT = XMVectorSelect(SignB, SignPNPP.v, CY); + PermuteControlT = XMVectorSelect(PermuteControl,Permute0.v, CY); + + PermuteSplat = XMVectorSelect(PermuteSplat, PermuteSplatT, CX); + SignB = XMVectorSelect(SignB, SignBT, CX); + PermuteControl = XMVectorSelect(PermuteControl, PermuteControlT, CX); + + PermuteSplat = XMVectorSelect(PermuteSplat,SplatW.v, CW); + SignB = XMVectorSelect(SignB, g_XMNegativeOne.v, CW); + PermuteControl = XMVectorSelect(PermuteControl,Permute3.v, CW); + + Scale = XMVectorPermute(SQ1, SQ1, PermuteSplat); + + P = XMVectorPermute(M.r[1], M.r[2],PermuteC.v); // {M10, M12, M20, M21} + A = XMVectorPermute(M.r[0], P, PermuteA.v); // {M01, M12, M20, M03} + B = XMVectorPermute(M.r[0], P, PermuteB.v); // {M10, M21, M02, M03} + + Q2 = XMVectorMultiplyAdd(SignB, B, A); + Q2 = XMVectorMultiply(Q2, Scale); + + Result = XMVectorPermute(Q1, Q2, PermuteControl); + + return Result; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Conversion operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMQuaternionToAxisAngle +( + XMVECTOR* pAxis, + FLOAT* pAngle, + FXMVECTOR Q +) +{ + XMASSERT(pAxis); + XMASSERT(pAngle); + + *pAxis = Q; + +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + *pAngle = 2.0f * acosf(XMVectorGetW(Q)); +#else + *pAngle = 2.0f * XMScalarACos(XMVectorGetW(Q)); +#endif +} + +/**************************************************************************** + * + * Plane + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMPlaneEqual +( + FXMVECTOR P1, + FXMVECTOR P2 +) +{ + return XMVector4Equal(P1, P2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMPlaneNearEqual +( + FXMVECTOR P1, + FXMVECTOR P2, + FXMVECTOR Epsilon +) +{ + XMVECTOR NP1 = XMPlaneNormalize(P1); + XMVECTOR NP2 = XMPlaneNormalize(P2); + return XMVector4NearEqual(NP1, NP2, Epsilon); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMPlaneNotEqual +( + FXMVECTOR P1, + FXMVECTOR P2 +) +{ + return XMVector4NotEqual(P1, P2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMPlaneIsNaN +( + FXMVECTOR P +) +{ + return XMVector4IsNaN(P); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMPlaneIsInfinite +( + FXMVECTOR P +) +{ + return XMVector4IsInfinite(P); +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneDot +( + FXMVECTOR P, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return XMVector4Dot(P, V); + +#elif defined(_XM_SSE_INTRINSICS_) + __m128 vTemp2 = V; + __m128 vTemp = _mm_mul_ps(P,vTemp2); + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp,_MM_SHUFFLE(1,0,0,0)); // Copy X to the Z position and Y to the W position + vTemp2 = _mm_add_ps(vTemp2,vTemp); // Add Z = X+Z; W = Y+W; + vTemp = _mm_shuffle_ps(vTemp,vTemp2,_MM_SHUFFLE(0,3,0,0)); // Copy W to the Z position + vTemp = _mm_add_ps(vTemp,vTemp2); // Add Z and W together + return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(2,2,2,2)); // Splat Z and return +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneDotCoord +( + FXMVECTOR P, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V3; + XMVECTOR Result; + + // Result = P[0] * V[0] + P[1] * V[1] + P[2] * V[2] + P[3] + V3 = XMVectorSelect(g_XMOne.v, V, g_XMSelect1110.v); + Result = XMVector4Dot(P, V3); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp2 = _mm_and_ps(V,g_XMMask3); + vTemp2 = _mm_or_ps(vTemp2,g_XMIdentityR3); + XMVECTOR vTemp = _mm_mul_ps(P,vTemp2); + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp,_MM_SHUFFLE(1,0,0,0)); // Copy X to the Z position and Y to the W position + vTemp2 = _mm_add_ps(vTemp2,vTemp); // Add Z = X+Z; W = Y+W; + vTemp = _mm_shuffle_ps(vTemp,vTemp2,_MM_SHUFFLE(0,3,0,0)); // Copy W to the Z position + vTemp = _mm_add_ps(vTemp,vTemp2); // Add Z and W together + return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(2,2,2,2)); // Splat Z and return +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneDotNormal +( + FXMVECTOR P, + FXMVECTOR V +) +{ + return XMVector3Dot(P, V); +} + +//------------------------------------------------------------------------------ +// XMPlaneNormalizeEst uses a reciprocal estimate and +// returns QNaN on zero and infinite vectors. + +XMFINLINE XMVECTOR XMPlaneNormalizeEst +( + FXMVECTOR P +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result = XMVector3ReciprocalLength(P); + Result = XMVectorMultiply(P, Result); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product + XMVECTOR vDot = _mm_mul_ps(P,P); + // x=Dot.y, y=Dot.z + XMVECTOR vTemp = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(2,1,2,1)); + // Result.x = x+y + vDot = _mm_add_ss(vDot,vTemp); + // x=Dot.z + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // Result.x = (x+y)+z + vDot = _mm_add_ss(vDot,vTemp); + // Splat x + vDot = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(0,0,0,0)); + // Get the reciprocal + vDot = _mm_rsqrt_ps(vDot); + // Get the reciprocal + vDot = _mm_mul_ps(vDot,P); + return vDot; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneNormalize +( + FXMVECTOR P +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fLengthSq = sqrtf((P.vector4_f32[0]*P.vector4_f32[0])+(P.vector4_f32[1]*P.vector4_f32[1])+(P.vector4_f32[2]*P.vector4_f32[2])); + // Prevent divide by zero + if (fLengthSq) { + fLengthSq = 1.0f/fLengthSq; + } + { + XMVECTOR vResult = { + P.vector4_f32[0]*fLengthSq, + P.vector4_f32[1]*fLengthSq, + P.vector4_f32[2]*fLengthSq, + P.vector4_f32[3]*fLengthSq + }; + return vResult; + } +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y and z only + XMVECTOR vLengthSq = _mm_mul_ps(P,P); + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,1,2,1)); + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + // Prepare for the division + XMVECTOR vResult = _mm_sqrt_ps(vLengthSq); + // Failsafe on zero (Or epsilon) length planes + // If the length is infinity, set the elements to zero + vLengthSq = _mm_cmpneq_ps(vLengthSq,g_XMInfinity); + // Reciprocal mul to perform the normalization + vResult = _mm_div_ps(P,vResult); + // Any that are infinity, set to zero + vResult = _mm_and_ps(vResult,vLengthSq); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneIntersectLine +( + FXMVECTOR P, + FXMVECTOR LinePoint1, + FXMVECTOR LinePoint2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1; + XMVECTOR V2; + XMVECTOR D; + XMVECTOR ReciprocalD; + XMVECTOR VT; + XMVECTOR Point; + XMVECTOR Zero; + XMVECTOR Control; + XMVECTOR Result; + + V1 = XMVector3Dot(P, LinePoint1); + V2 = XMVector3Dot(P, LinePoint2); + D = XMVectorSubtract(V1, V2); + + ReciprocalD = XMVectorReciprocal(D); + VT = XMPlaneDotCoord(P, LinePoint1); + VT = XMVectorMultiply(VT, ReciprocalD); + + Point = XMVectorSubtract(LinePoint2, LinePoint1); + Point = XMVectorMultiplyAdd(Point, VT, LinePoint1); + + Zero = XMVectorZero(); + Control = XMVectorNearEqual(D, Zero, g_XMEpsilon.v); + + Result = XMVectorSelect(Point, g_XMQNaN.v, Control); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1; + XMVECTOR V2; + XMVECTOR D; + XMVECTOR VT; + XMVECTOR Point; + XMVECTOR Zero; + XMVECTOR Control; + XMVECTOR Result; + + V1 = XMVector3Dot(P, LinePoint1); + V2 = XMVector3Dot(P, LinePoint2); + D = _mm_sub_ps(V1, V2); + + VT = XMPlaneDotCoord(P, LinePoint1); + VT = _mm_div_ps(VT, D); + + Point = _mm_sub_ps(LinePoint2, LinePoint1); + Point = _mm_mul_ps(Point,VT); + Point = _mm_add_ps(Point,LinePoint1); + Zero = XMVectorZero(); + Control = XMVectorNearEqual(D, Zero, g_XMEpsilon); + Result = XMVectorSelect(Point, g_XMQNaN, Control); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE VOID XMPlaneIntersectPlane +( + XMVECTOR* pLinePoint1, + XMVECTOR* pLinePoint2, + FXMVECTOR P1, + FXMVECTOR P2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1; + XMVECTOR V2; + XMVECTOR V3; + XMVECTOR LengthSq; + XMVECTOR RcpLengthSq; + XMVECTOR Point; + XMVECTOR P1W; + XMVECTOR P2W; + XMVECTOR Control; + XMVECTOR LinePoint1; + XMVECTOR LinePoint2; + + XMASSERT(pLinePoint1); + XMASSERT(pLinePoint2); + + V1 = XMVector3Cross(P2, P1); + + LengthSq = XMVector3LengthSq(V1); + + V2 = XMVector3Cross(P2, V1); + + P1W = XMVectorSplatW(P1); + Point = XMVectorMultiply(V2, P1W); + + V3 = XMVector3Cross(V1, P1); + + P2W = XMVectorSplatW(P2); + Point = XMVectorMultiplyAdd(V3, P2W, Point); + + RcpLengthSq = XMVectorReciprocal(LengthSq); + LinePoint1 = XMVectorMultiply(Point, RcpLengthSq); + + LinePoint2 = XMVectorAdd(LinePoint1, V1); + + Control = XMVectorLessOrEqual(LengthSq, g_XMEpsilon.v); + *pLinePoint1 = XMVectorSelect(LinePoint1,g_XMQNaN.v, Control); + *pLinePoint2 = XMVectorSelect(LinePoint2,g_XMQNaN.v, Control); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pLinePoint1); + XMASSERT(pLinePoint2); + XMVECTOR V1; + XMVECTOR V2; + XMVECTOR V3; + XMVECTOR LengthSq; + XMVECTOR Point; + XMVECTOR P1W; + XMVECTOR P2W; + XMVECTOR Control; + XMVECTOR LinePoint1; + XMVECTOR LinePoint2; + + V1 = XMVector3Cross(P2, P1); + + LengthSq = XMVector3LengthSq(V1); + + V2 = XMVector3Cross(P2, V1); + + P1W = _mm_shuffle_ps(P1,P1,_MM_SHUFFLE(3,3,3,3)); + Point = _mm_mul_ps(V2, P1W); + + V3 = XMVector3Cross(V1, P1); + + P2W = _mm_shuffle_ps(P2,P2,_MM_SHUFFLE(3,3,3,3)); + V3 = _mm_mul_ps(V3,P2W); + Point = _mm_add_ps(Point,V3); + LinePoint1 = _mm_div_ps(Point,LengthSq); + + LinePoint2 = _mm_add_ps(LinePoint1, V1); + + Control = XMVectorLessOrEqual(LengthSq, g_XMEpsilon); + *pLinePoint1 = XMVectorSelect(LinePoint1,g_XMQNaN, Control); + *pLinePoint2 = XMVectorSelect(LinePoint2,g_XMQNaN, Control); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneTransform +( + FXMVECTOR P, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR W; + XMVECTOR Result; + + W = XMVectorSplatW(P); + Z = XMVectorSplatZ(P); + Y = XMVectorSplatY(P); + X = XMVectorSplatX(P); + + Result = XMVectorMultiply(W, M.r[3]); + Result = XMVectorMultiplyAdd(Z, M.r[2], Result); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR X = _mm_shuffle_ps(P,P,_MM_SHUFFLE(0,0,0,0)); + XMVECTOR Y = _mm_shuffle_ps(P,P,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR Z = _mm_shuffle_ps(P,P,_MM_SHUFFLE(2,2,2,2)); + XMVECTOR W = _mm_shuffle_ps(P,P,_MM_SHUFFLE(3,3,3,3)); + X = _mm_mul_ps(X, M.r[0]); + Y = _mm_mul_ps(Y, M.r[1]); + Z = _mm_mul_ps(Z, M.r[2]); + W = _mm_mul_ps(W, M.r[3]); + X = _mm_add_ps(X,Z); + Y = _mm_add_ps(Y,W); + X = _mm_add_ps(X,Y); + return X; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMFLOAT4* XMPlaneTransformStream +( + XMFLOAT4* pOutputStream, + size_t OutputStride, + CONST XMFLOAT4* pInputStream, + size_t InputStride, + size_t PlaneCount, + CXMMATRIX M +) +{ + return XMVector4TransformStream(pOutputStream, + OutputStride, + pInputStream, + InputStride, + PlaneCount, + M); +} + +//------------------------------------------------------------------------------ +// Conversion operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneFromPointNormal +( + FXMVECTOR Point, + FXMVECTOR Normal +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR W; + XMVECTOR Result; + + W = XMVector3Dot(Point, Normal); + W = XMVectorNegate(W); + Result = XMVectorSelect(W, Normal, g_XMSelect1110.v); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR W; + XMVECTOR Result; + W = XMVector3Dot(Point,Normal); + W = _mm_mul_ps(W,g_XMNegativeOne); + Result = _mm_and_ps(Normal,g_XMMask3); + W = _mm_and_ps(W,g_XMMaskW); + Result = _mm_or_ps(Result,W); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMPlaneFromPoints +( + FXMVECTOR Point1, + FXMVECTOR Point2, + FXMVECTOR Point3 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR N; + XMVECTOR D; + XMVECTOR V21; + XMVECTOR V31; + XMVECTOR Result; + + V21 = XMVectorSubtract(Point1, Point2); + V31 = XMVectorSubtract(Point1, Point3); + + N = XMVector3Cross(V21, V31); + N = XMVector3Normalize(N); + + D = XMPlaneDotNormal(N, Point1); + D = XMVectorNegate(D); + + Result = XMVectorSelect(D, N, g_XMSelect1110.v); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR N; + XMVECTOR D; + XMVECTOR V21; + XMVECTOR V31; + XMVECTOR Result; + + V21 = _mm_sub_ps(Point1, Point2); + V31 = _mm_sub_ps(Point1, Point3); + + N = XMVector3Cross(V21, V31); + N = XMVector3Normalize(N); + + D = XMPlaneDotNormal(N, Point1); + D = _mm_mul_ps(D,g_XMNegativeOne); + N = _mm_and_ps(N,g_XMMask3); + D = _mm_and_ps(D,g_XMMaskW); + Result = _mm_or_ps(D,N); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +/**************************************************************************** + * + * Color + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorEqual +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVector4Equal(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorNotEqual +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVector4NotEqual(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorGreater +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVector4Greater(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorGreaterOrEqual +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVector4GreaterOrEqual(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorLess +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVector4Less(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorLessOrEqual +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVector4LessOrEqual(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorIsNaN +( + FXMVECTOR C +) +{ + return XMVector4IsNaN(C); +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMColorIsInfinite +( + FXMVECTOR C +) +{ + return XMVector4IsInfinite(C); +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMColorNegative +( + FXMVECTOR vColor +) +{ +#if defined(_XM_NO_INTRINSICS_) +// XMASSERT(XMVector4GreaterOrEqual(C, XMVectorReplicate(0.0f))); +// XMASSERT(XMVector4LessOrEqual(C, XMVectorReplicate(1.0f))); + XMVECTOR vResult = { + 1.0f - vColor.vector4_f32[0], + 1.0f - vColor.vector4_f32[1], + 1.0f - vColor.vector4_f32[2], + vColor.vector4_f32[3] + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // Negate only x,y and z. + XMVECTOR vTemp = _mm_xor_ps(vColor,g_XMNegate3); + // Add 1,1,1,0 to -x,-y,-z,w + return _mm_add_ps(vTemp,g_XMOne3); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMColorModulate +( + FXMVECTOR C1, + FXMVECTOR C2 +) +{ + return XMVectorMultiply(C1, C2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMColorAdjustSaturation +( + FXMVECTOR vColor, + FLOAT fSaturation +) +{ +#if defined(_XM_NO_INTRINSICS_) + CONST XMVECTOR gvLuminance = {0.2125f, 0.7154f, 0.0721f, 0.0f}; + + // Luminance = 0.2125f * C[0] + 0.7154f * C[1] + 0.0721f * C[2]; + // Result = (C - Luminance) * Saturation + Luminance; + + FLOAT fLuminance = (vColor.vector4_f32[0]*gvLuminance.vector4_f32[0])+(vColor.vector4_f32[1]*gvLuminance.vector4_f32[1])+(vColor.vector4_f32[2]*gvLuminance.vector4_f32[2]); + XMVECTOR vResult = { + ((vColor.vector4_f32[0] - fLuminance)*fSaturation)+fLuminance, + ((vColor.vector4_f32[1] - fLuminance)*fSaturation)+fLuminance, + ((vColor.vector4_f32[2] - fLuminance)*fSaturation)+fLuminance, + vColor.vector4_f32[3]}; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 gvLuminance = {0.2125f, 0.7154f, 0.0721f, 0.0f}; +// Mul RGB by intensity constants + XMVECTOR vLuminance = _mm_mul_ps(vColor,gvLuminance); +// vResult.x = vLuminance.y, vResult.y = vLuminance.y, +// vResult.z = vLuminance.z, vResult.w = vLuminance.z + XMVECTOR vResult = vLuminance; + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(2,2,1,1)); +// vLuminance.x += vLuminance.y + vLuminance = _mm_add_ss(vLuminance,vResult); +// Splat vLuminance.z + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(2,2,2,2)); +// vLuminance.x += vLuminance.z (Dot product) + vLuminance = _mm_add_ss(vLuminance,vResult); +// Splat vLuminance + vLuminance = _mm_shuffle_ps(vLuminance,vLuminance,_MM_SHUFFLE(0,0,0,0)); +// Splat fSaturation + XMVECTOR vSaturation = _mm_set_ps1(fSaturation); +// vResult = ((vColor-vLuminance)*vSaturation)+vLuminance; + vResult = _mm_sub_ps(vColor,vLuminance); + vResult = _mm_mul_ps(vResult,vSaturation); + vResult = _mm_add_ps(vResult,vLuminance); +// Retain w from the source color + vLuminance = _mm_shuffle_ps(vResult,vColor,_MM_SHUFFLE(3,2,2,2)); // x = vResult.z,y = vResult.z,z = vColor.z,w=vColor.w + vResult = _mm_shuffle_ps(vResult,vLuminance,_MM_SHUFFLE(3,0,1,0)); // x = vResult.x,y = vResult.y,z = vResult.z,w=vColor.w + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMColorAdjustContrast +( + FXMVECTOR vColor, + FLOAT fContrast +) +{ +#if defined(_XM_NO_INTRINSICS_) + // Result = (vColor - 0.5f) * fContrast + 0.5f; + XMVECTOR vResult = { + ((vColor.vector4_f32[0]-0.5f) * fContrast) + 0.5f, + ((vColor.vector4_f32[1]-0.5f) * fContrast) + 0.5f, + ((vColor.vector4_f32[2]-0.5f) * fContrast) + 0.5f, + vColor.vector4_f32[3] // Leave W untouched + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vScale = _mm_set_ps1(fContrast); // Splat the scale + XMVECTOR vResult = _mm_sub_ps(vColor,g_XMOneHalf); // Subtract 0.5f from the source (Saving source) + vResult = _mm_mul_ps(vResult,vScale); // Mul by scale + vResult = _mm_add_ps(vResult,g_XMOneHalf); // Add 0.5f +// Retain w from the source color + vScale = _mm_shuffle_ps(vResult,vColor,_MM_SHUFFLE(3,2,2,2)); // x = vResult.z,y = vResult.z,z = vColor.z,w=vColor.w + vResult = _mm_shuffle_ps(vResult,vScale,_MM_SHUFFLE(3,0,1,0)); // x = vResult.x,y = vResult.y,z = vResult.z,w=vColor.w + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +/**************************************************************************** + * + * Miscellaneous + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMINLINE BOOL XMVerifyCPUSupport() +{ +#if defined(_XM_NO_INTRINSICS_) || !defined(_XM_SSE_INTRINSICS_) + return TRUE; +#else // _XM_SSE_INTRINSICS_ + // Note that on Windows 2000 or older, SSE2 detection is not supported so this will always fail + // Detecting SSE2 on older versions of Windows would require using cpuid directly + return ( IsProcessorFeaturePresent( PF_XMMI_INSTRUCTIONS_AVAILABLE ) && IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE ) ); +#endif +} + + +//------------------------------------------------------------------------------ + +#define XMASSERT_LINE_STRING_SIZE 16 + +XMINLINE VOID XMAssert +( + CONST CHAR* pExpression, + CONST CHAR* pFileName, + UINT LineNumber +) +{ + CHAR aLineString[XMASSERT_LINE_STRING_SIZE]; + CHAR* pLineString; + UINT Line; + + aLineString[XMASSERT_LINE_STRING_SIZE - 2] = '0'; + aLineString[XMASSERT_LINE_STRING_SIZE - 1] = '\0'; + for (Line = LineNumber, pLineString = aLineString + XMASSERT_LINE_STRING_SIZE - 2; + Line != 0 && pLineString >= aLineString; + Line /= 10, pLineString--) + { + *pLineString = (CHAR)('0' + (Line % 10)); + } + +#ifndef NO_OUTPUT_DEBUG_STRING + OutputDebugStringA("Assertion failed: "); + OutputDebugStringA(pExpression); + OutputDebugStringA(", file "); + OutputDebugStringA(pFileName); + OutputDebugStringA(", line "); + OutputDebugStringA(pLineString + 1); + OutputDebugStringA("\r\n"); +#else + DbgPrint("Assertion failed: %s, file %s, line %d\r\n", pExpression, pFileName, LineNumber); +#endif + + __debugbreak(); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMFresnelTerm +( + FXMVECTOR CosIncidentAngle, + FXMVECTOR RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR G; + XMVECTOR D, S; + XMVECTOR V0, V1, V2, V3; + XMVECTOR Result; + + // Result = 0.5f * (g - c)^2 / (g + c)^2 * ((c * (g + c) - 1)^2 / (c * (g - c) + 1)^2 + 1) where + // c = CosIncidentAngle + // g = sqrt(c^2 + RefractionIndex^2 - 1) + + XMASSERT(!XMVector4IsInfinite(CosIncidentAngle)); + + G = XMVectorMultiplyAdd(RefractionIndex, RefractionIndex, g_XMNegativeOne.v); + G = XMVectorMultiplyAdd(CosIncidentAngle, CosIncidentAngle, G); + G = XMVectorAbs(G); + G = XMVectorSqrt(G); + + S = XMVectorAdd(G, CosIncidentAngle); + D = XMVectorSubtract(G, CosIncidentAngle); + + V0 = XMVectorMultiply(D, D); + V1 = XMVectorMultiply(S, S); + V1 = XMVectorReciprocal(V1); + V0 = XMVectorMultiply(g_XMOneHalf.v, V0); + V0 = XMVectorMultiply(V0, V1); + + V2 = XMVectorMultiplyAdd(CosIncidentAngle, S, g_XMNegativeOne.v); + V3 = XMVectorMultiplyAdd(CosIncidentAngle, D, g_XMOne.v); + V2 = XMVectorMultiply(V2, V2); + V3 = XMVectorMultiply(V3, V3); + V3 = XMVectorReciprocal(V3); + V2 = XMVectorMultiplyAdd(V2, V3, g_XMOne.v); + + Result = XMVectorMultiply(V0, V2); + + Result = XMVectorSaturate(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = 0.5f * (g - c)^2 / (g + c)^2 * ((c * (g + c) - 1)^2 / (c * (g - c) + 1)^2 + 1) where + // c = CosIncidentAngle + // g = sqrt(c^2 + RefractionIndex^2 - 1) + + XMASSERT(!XMVector4IsInfinite(CosIncidentAngle)); + + // G = sqrt(abs((RefractionIndex^2-1) + CosIncidentAngle^2)) + XMVECTOR G = _mm_mul_ps(RefractionIndex,RefractionIndex); + XMVECTOR vTemp = _mm_mul_ps(CosIncidentAngle,CosIncidentAngle); + G = _mm_sub_ps(G,g_XMOne); + vTemp = _mm_add_ps(vTemp,G); + // max((0-vTemp),vTemp) == abs(vTemp) + // The abs is needed to deal with refraction and cosine being zero + G = _mm_setzero_ps(); + G = _mm_sub_ps(G,vTemp); + G = _mm_max_ps(G,vTemp); + // Last operation, the sqrt() + G = _mm_sqrt_ps(G); + + // Calc G-C and G+C + XMVECTOR GAddC = _mm_add_ps(G,CosIncidentAngle); + XMVECTOR GSubC = _mm_sub_ps(G,CosIncidentAngle); + // Perform the term (0.5f *(g - c)^2) / (g + c)^2 + XMVECTOR vResult = _mm_mul_ps(GSubC,GSubC); + vTemp = _mm_mul_ps(GAddC,GAddC); + vResult = _mm_mul_ps(vResult,g_XMOneHalf); + vResult = _mm_div_ps(vResult,vTemp); + // Perform the term ((c * (g + c) - 1)^2 / (c * (g - c) + 1)^2 + 1) + GAddC = _mm_mul_ps(GAddC,CosIncidentAngle); + GSubC = _mm_mul_ps(GSubC,CosIncidentAngle); + GAddC = _mm_sub_ps(GAddC,g_XMOne); + GSubC = _mm_add_ps(GSubC,g_XMOne); + GAddC = _mm_mul_ps(GAddC,GAddC); + GSubC = _mm_mul_ps(GSubC,GSubC); + GAddC = _mm_div_ps(GAddC,GSubC); + GAddC = _mm_add_ps(GAddC,g_XMOne); + // Multiply the two term parts + vResult = _mm_mul_ps(vResult,GAddC); + // Clamp to 0.0 - 1.0f + vResult = _mm_max_ps(vResult,g_XMZero); + vResult = _mm_min_ps(vResult,g_XMOne); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMScalarNearEqual +( + FLOAT S1, + FLOAT S2, + FLOAT Epsilon +) +{ + FLOAT Delta = S1 - S2; +#if defined(_XM_NO_INTRINSICS_) + UINT AbsDelta = *(const UINT*)&Delta & 0x7FFFFFFF; + return (*(FLOAT*)&AbsDelta <= Epsilon); +#elif defined(_XM_SSE_INTRINSICS_) + return (fabsf(Delta) <= Epsilon); +#else + return (__fabs(Delta) <= Epsilon); +#endif +} + +//------------------------------------------------------------------------------ +// Modulo the range of the given angle such that -XM_PI <= Angle < XM_PI +XMFINLINE FLOAT XMScalarModAngle +( + FLOAT Angle +) +{ + // Note: The modulo is performed with unsigned math only to work + // around a precision error on numbers that are close to PI + float fTemp; +#if defined(_XM_NO_INTRINSICS_) || !defined(_XM_VMX128_INTRINSICS_) + // Normalize the range from 0.0f to XM_2PI + Angle = Angle + XM_PI; + // Perform the modulo, unsigned + fTemp = fabsf(Angle); + fTemp = fTemp - (XM_2PI * (FLOAT)((INT)(fTemp/XM_2PI))); + // Restore the number to the range of -XM_PI to XM_PI-epsilon + fTemp = fTemp - XM_PI; + // If the modulo'd value was negative, restore negation + if (Angle<0.0f) { + fTemp = -fTemp; + } + return fTemp; +#else +#endif +} + +//------------------------------------------------------------------------------ + +XMINLINE FLOAT XMScalarSin +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ValueMod; + FLOAT ValueSq; + XMVECTOR V0123, V0246, V1357, V9111315, V17192123; + XMVECTOR V1, V7, V8; + XMVECTOR R0, R1, R2; + + ValueMod = XMScalarModAngle(Value); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! + V^9 / 9! - V^11 / 11! + V^13 / 13! - V^15 / 15! + + // V^17 / 17! - V^19 / 19! + V^21 / 21! - V^23 / 23! (for -PI <= V < PI) + + ValueSq = ValueMod * ValueMod; + + V0123 = XMVectorSet(1.0f, ValueMod, ValueSq, ValueSq * ValueMod); + V1 = XMVectorSplatY(V0123); + V0246 = XMVectorMultiply(V0123, V0123); + V1357 = XMVectorMultiply(V0246, V1); + V7 = XMVectorSplatW(V1357); + V8 = XMVectorMultiply(V7, V1); + V9111315 = XMVectorMultiply(V1357, V8); + V17192123 = XMVectorMultiply(V9111315, V8); + + R0 = XMVector4Dot(V1357, g_XMSinCoefficients0.v); + R1 = XMVector4Dot(V9111315, g_XMSinCoefficients1.v); + R2 = XMVector4Dot(V17192123, g_XMSinCoefficients2.v); + + return R0.vector4_f32[0] + R1.vector4_f32[0] + R2.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + return sinf( Value ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE FLOAT XMScalarCos +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ValueMod; + FLOAT ValueSq; + XMVECTOR V0123, V0246, V8101214, V16182022; + XMVECTOR V2, V6, V8; + XMVECTOR R0, R1, R2; + + ValueMod = XMScalarModAngle(Value); + + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! + V^8 / 8! - V^10 / 10! + + // V^12 / 12! - V^14 / 14! + V^16 / 16! - V^18 / 18! + V^20 / 20! - V^22 / 22! (for -PI <= V < PI) + + ValueSq = ValueMod * ValueMod; + + V0123 = XMVectorSet(1.0f, ValueMod, ValueSq, ValueSq * ValueMod); + V0246 = XMVectorMultiply(V0123, V0123); + + V2 = XMVectorSplatZ(V0123); + V6 = XMVectorSplatW(V0246); + V8 = XMVectorMultiply(V6, V2); + + V8101214 = XMVectorMultiply(V0246, V8); + V16182022 = XMVectorMultiply(V8101214, V8); + + R0 = XMVector4Dot(V0246, g_XMCosCoefficients0.v); + R1 = XMVector4Dot(V8101214, g_XMCosCoefficients1.v); + R2 = XMVector4Dot(V16182022, g_XMCosCoefficients2.v); + + return R0.vector4_f32[0] + R1.vector4_f32[0] + R2.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + return cosf(Value); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE VOID XMScalarSinCos +( + FLOAT* pSin, + FLOAT* pCos, + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ValueMod; + FLOAT ValueSq; + XMVECTOR V0123, V0246, V1357, V8101214, V9111315, V16182022, V17192123; + XMVECTOR V1, V2, V6, V8; + XMVECTOR S0, S1, S2, C0, C1, C2; + + XMASSERT(pSin); + XMASSERT(pCos); + + ValueMod = XMScalarModAngle(Value); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! + V^9 / 9! - V^11 / 11! + V^13 / 13! - V^15 / 15! + + // V^17 / 17! - V^19 / 19! + V^21 / 21! - V^23 / 23! (for -PI <= V < PI) + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! + V^8 / 8! - V^10 / 10! + + // V^12 / 12! - V^14 / 14! + V^16 / 16! - V^18 / 18! + V^20 / 20! - V^22 / 22! (for -PI <= V < PI) + + ValueSq = ValueMod * ValueMod; + + V0123 = XMVectorSet(1.0f, ValueMod, ValueSq, ValueSq * ValueMod); + + V1 = XMVectorSplatY(V0123); + V2 = XMVectorSplatZ(V0123); + + V0246 = XMVectorMultiply(V0123, V0123); + V1357 = XMVectorMultiply(V0246, V1); + + V6 = XMVectorSplatW(V0246); + V8 = XMVectorMultiply(V6, V2); + + V8101214 = XMVectorMultiply(V0246, V8); + V9111315 = XMVectorMultiply(V1357, V8); + V16182022 = XMVectorMultiply(V8101214, V8); + V17192123 = XMVectorMultiply(V9111315, V8); + + C0 = XMVector4Dot(V0246, g_XMCosCoefficients0.v); + S0 = XMVector4Dot(V1357, g_XMSinCoefficients0.v); + C1 = XMVector4Dot(V8101214, g_XMCosCoefficients1.v); + S1 = XMVector4Dot(V9111315, g_XMSinCoefficients1.v); + C2 = XMVector4Dot(V16182022, g_XMCosCoefficients2.v); + S2 = XMVector4Dot(V17192123, g_XMSinCoefficients2.v); + + *pCos = C0.vector4_f32[0] + C1.vector4_f32[0] + C2.vector4_f32[0]; + *pSin = S0.vector4_f32[0] + S1.vector4_f32[0] + S2.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSin); + XMASSERT(pCos); + + *pSin = sinf(Value); + *pCos = cosf(Value); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE FLOAT XMScalarASin +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT AbsValue, Value2, Value3, D; + XMVECTOR AbsV, R0, R1, Result; + XMVECTOR V3; + + *(UINT*)&AbsValue = *(const UINT*)&Value & 0x7FFFFFFF; + + Value2 = Value * AbsValue; + Value3 = Value * Value2; + D = (Value - Value2) / sqrtf(1.00000011921f - AbsValue); + + AbsV = XMVectorReplicate(AbsValue); + + V3.vector4_f32[0] = Value3; + V3.vector4_f32[1] = 1.0f; + V3.vector4_f32[2] = Value3; + V3.vector4_f32[3] = 1.0f; + + R1 = XMVectorSet(D, D, Value, Value); + R1 = XMVectorMultiply(R1, V3); + + R0 = XMVectorMultiplyAdd(AbsV, g_XMASinCoefficients0.v, g_XMASinCoefficients1.v); + R0 = XMVectorMultiplyAdd(AbsV, R0, g_XMASinCoefficients2.v); + + Result = XMVector4Dot(R0, R1); + + return Result.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + return asinf(Value); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE FLOAT XMScalarACos +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return XM_PIDIV2 - XMScalarASin(Value); + +#elif defined(_XM_SSE_INTRINSICS_) + return acosf(Value); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE FLOAT XMScalarSinEst +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ValueSq; + XMVECTOR V; + XMVECTOR Y; + XMVECTOR Result; + + XMASSERT(Value >= -XM_PI); + XMASSERT(Value < XM_PI); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! (for -PI <= V < PI) + + ValueSq = Value * Value; + + V = XMVectorSet(1.0f, Value, ValueSq, ValueSq * Value); + Y = XMVectorSplatY(V); + V = XMVectorMultiply(V, V); + V = XMVectorMultiply(V, Y); + + Result = XMVector4Dot(V, g_XMSinEstCoefficients.v); + + return Result.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(Value >= -XM_PI); + XMASSERT(Value < XM_PI); + float ValueSq = Value*Value; + XMVECTOR vValue = _mm_set_ps1(Value); + XMVECTOR vTemp = _mm_set_ps(ValueSq * Value,ValueSq,Value,1.0f); + vTemp = _mm_mul_ps(vTemp,vTemp); + vTemp = _mm_mul_ps(vTemp,vValue); + // vTemp = Value,Value^3,Value^5,Value^7 + vTemp = _mm_mul_ps(vTemp,g_XMSinEstCoefficients); + vValue = _mm_shuffle_ps(vValue,vTemp,_MM_SHUFFLE(1,0,0,0)); // Copy X to the Z position and Y to the W position + vValue = _mm_add_ps(vValue,vTemp); // Add Z = X+Z; W = Y+W; + vTemp = _mm_shuffle_ps(vTemp,vValue,_MM_SHUFFLE(0,3,0,0)); // Copy W to the Z position + vTemp = _mm_add_ps(vTemp,vValue); // Add Z and W together + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(2,2,2,2)); // Splat Z and return +#if defined(_MSC_VER) && (_MSC_VER>=1500) + return _mm_cvtss_f32(vTemp); +#else + return vTemp.m128_f32[0]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE FLOAT XMScalarCosEst +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT ValueSq; + XMVECTOR V; + XMVECTOR Result; + XMASSERT(Value >= -XM_PI); + XMASSERT(Value < XM_PI); + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! (for -PI <= V < PI) + ValueSq = Value * Value; + V = XMVectorSet(1.0f, Value, ValueSq, ValueSq * Value); + V = XMVectorMultiply(V, V); + Result = XMVector4Dot(V, g_XMCosEstCoefficients.v); + return Result.vector4_f32[0]; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(Value >= -XM_PI); + XMASSERT(Value < XM_PI); + float ValueSq = Value*Value; + XMVECTOR vValue = _mm_setzero_ps(); + XMVECTOR vTemp = _mm_set_ps(ValueSq * Value,ValueSq,Value,1.0f); + vTemp = _mm_mul_ps(vTemp,vTemp); + // vTemp = 1.0f,Value^2,Value^4,Value^6 + vTemp = _mm_mul_ps(vTemp,g_XMCosEstCoefficients); + vValue = _mm_shuffle_ps(vValue,vTemp,_MM_SHUFFLE(1,0,0,0)); // Copy X to the Z position and Y to the W position + vValue = _mm_add_ps(vValue,vTemp); // Add Z = X+Z; W = Y+W; + vTemp = _mm_shuffle_ps(vTemp,vValue,_MM_SHUFFLE(0,3,0,0)); // Copy W to the Z position + vTemp = _mm_add_ps(vTemp,vValue); // Add Z and W together + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(2,2,2,2)); // Splat Z and return +#if defined(_MSC_VER) && (_MSC_VER>=1500) + return _mm_cvtss_f32(vTemp); +#else + return vTemp.m128_f32[0]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMScalarSinCosEst +( + FLOAT* pSin, + FLOAT* pCos, + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT ValueSq; + XMVECTOR V, Sin, Cos; + XMVECTOR Y; + + XMASSERT(pSin); + XMASSERT(pCos); + XMASSERT(Value >= -XM_PI); + XMASSERT(Value < XM_PI); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! (for -PI <= V < PI) + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! (for -PI <= V < PI) + + ValueSq = Value * Value; + V = XMVectorSet(1.0f, Value, ValueSq, Value * ValueSq); + Y = XMVectorSplatY(V); + Cos = XMVectorMultiply(V, V); + Sin = XMVectorMultiply(Cos, Y); + + Cos = XMVector4Dot(Cos, g_XMCosEstCoefficients.v); + Sin = XMVector4Dot(Sin, g_XMSinEstCoefficients.v); + + *pCos = Cos.vector4_f32[0]; + *pSin = Sin.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSin); + XMASSERT(pCos); + XMASSERT(Value >= -XM_PI); + XMASSERT(Value < XM_PI); + float ValueSq = Value * Value; + XMVECTOR Cos = _mm_set_ps(Value * ValueSq,ValueSq,Value,1.0f); + XMVECTOR Sin = _mm_set_ps1(Value); + Cos = _mm_mul_ps(Cos,Cos); + Sin = _mm_mul_ps(Sin,Cos); + // Cos = 1.0f,Value^2,Value^4,Value^6 + Cos = XMVector4Dot(Cos,g_XMCosEstCoefficients); + _mm_store_ss(pCos,Cos); + // Sin = Value,Value^3,Value^5,Value^7 + Sin = XMVector4Dot(Sin, g_XMSinEstCoefficients); + _mm_store_ss(pSin,Sin); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE FLOAT XMScalarASinEst +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR VR, CR, CS; + XMVECTOR Result; + FLOAT AbsV, V2, D; + CONST FLOAT OnePlusEps = 1.00000011921f; + + *(UINT*)&AbsV = *(const UINT*)&Value & 0x7FFFFFFF; + V2 = Value * AbsV; + D = OnePlusEps - AbsV; + + CS = XMVectorSet(Value, 1.0f, 1.0f, V2); + VR = XMVectorSet(sqrtf(D), Value, V2, D * AbsV); + CR = XMVectorMultiply(CS, g_XMASinEstCoefficients.v); + + Result = XMVector4Dot(VR, CR); + + return Result.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + CONST FLOAT OnePlusEps = 1.00000011921f; + FLOAT AbsV = fabsf(Value); + FLOAT V2 = Value * AbsV; // Square with sign retained + FLOAT D = OnePlusEps - AbsV; + + XMVECTOR Result = _mm_set_ps(V2,1.0f,1.0f,Value); + XMVECTOR VR = _mm_set_ps(D * AbsV,V2,Value,sqrtf(D)); + Result = _mm_mul_ps(Result, g_XMASinEstCoefficients); + Result = XMVector4Dot(VR,Result); +#if defined(_MSC_VER) && (_MSC_VER>=1500) + return _mm_cvtss_f32(Result); +#else + return Result.m128_f32[0]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE FLOAT XMScalarACosEst +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR VR, CR, CS; + XMVECTOR Result; + FLOAT AbsV, V2, D; + CONST FLOAT OnePlusEps = 1.00000011921f; + + // return XM_PIDIV2 - XMScalarASin(Value); + + *(UINT*)&AbsV = *(const UINT*)&Value & 0x7FFFFFFF; + V2 = Value * AbsV; + D = OnePlusEps - AbsV; + + CS = XMVectorSet(Value, 1.0f, 1.0f, V2); + VR = XMVectorSet(sqrtf(D), Value, V2, D * AbsV); + CR = XMVectorMultiply(CS, g_XMASinEstCoefficients.v); + + Result = XMVector4Dot(VR, CR); + + return XM_PIDIV2 - Result.vector4_f32[0]; + +#elif defined(_XM_SSE_INTRINSICS_) + CONST FLOAT OnePlusEps = 1.00000011921f; + FLOAT AbsV = fabsf(Value); + FLOAT V2 = Value * AbsV; // Value^2 retaining sign + FLOAT D = OnePlusEps - AbsV; + XMVECTOR Result = _mm_set_ps(V2,1.0f,1.0f,Value); + XMVECTOR VR = _mm_set_ps(D * AbsV,V2,Value,sqrtf(D)); + Result = _mm_mul_ps(Result,g_XMASinEstCoefficients); + Result = XMVector4Dot(VR,Result); +#if defined(_MSC_VER) && (_MSC_VER>=1500) + return XM_PIDIV2 - _mm_cvtss_f32(Result); +#else + return XM_PIDIV2 - Result.m128_f32[0]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +#endif // __XNAMATHMISC_INL__ + diff --git a/third_party/xbox_sdk/include/xnamathvector.inl b/third_party/xbox_sdk/include/xnamathvector.inl new file mode 100644 index 0000000..37b7d13 --- /dev/null +++ b/third_party/xbox_sdk/include/xnamathvector.inl @@ -0,0 +1,13673 @@ +/************************************************************************ +* * +* xnamathvector.inl -- SIMD C++ Math library for Windows and Xbox 360 * +* Vector functions * +* * +* Copyright (c) Microsoft Corp. All rights reserved. * +* * +************************************************************************/ + +#if defined(_MSC_VER) && (_MSC_VER > 1000) +#pragma once +#endif + +#ifndef __XNAMATHVECTOR_INL__ +#define __XNAMATHVECTOR_INL__ + +#if defined(_XM_NO_INTRINSICS_) +#define XMISNAN(x) ((*(UINT*)&(x) & 0x7F800000) == 0x7F800000 && (*(UINT*)&(x) & 0x7FFFFF) != 0) +#define XMISINF(x) ((*(UINT*)&(x) & 0x7FFFFFFF) == 0x7F800000) +#endif + +/**************************************************************************** + * + * General Vector + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Assignment operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Return a vector with all elements equaling zero +XMFINLINE XMVECTOR XMVectorZero() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = {0.0f,0.0f,0.0f,0.0f}; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_setzero_ps(); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with four floating point values +XMFINLINE XMVECTOR XMVectorSet +( + FLOAT x, + FLOAT y, + FLOAT z, + FLOAT w +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTORF32 vResult = {x,y,z,w}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_set_ps( w, z, y, x ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with four integer values +XMFINLINE XMVECTOR XMVectorSetInt +( + UINT x, + UINT y, + UINT z, + UINT w +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTORU32 vResult = {x,y,z,w}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_set_epi32( w, z, y, x ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with a replicated floating point value +XMFINLINE XMVECTOR XMVectorReplicate +( + FLOAT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) + XMVECTORF32 vResult = {Value,Value,Value,Value}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_set_ps1( Value ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with a replicated floating point value passed by pointer +XMFINLINE XMVECTOR XMVectorReplicatePtr +( + CONST FLOAT *pValue +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) + FLOAT Value = pValue[0]; + XMVECTORF32 vResult = {Value,Value,Value,Value}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_load_ps1( pValue ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with a replicated integer value +XMFINLINE XMVECTOR XMVectorReplicateInt +( + UINT Value +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) + XMVECTORU32 vResult = {Value,Value,Value,Value}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_set1_epi32( Value ); + return reinterpret_cast(&vTemp)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with a replicated integer value passed by pointer +XMFINLINE XMVECTOR XMVectorReplicateIntPtr +( + CONST UINT *pValue +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) + UINT Value = pValue[0]; + XMVECTORU32 vResult = {Value,Value,Value,Value}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_load_ps1(reinterpret_cast(pValue)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with all bits set (true mask) +XMFINLINE XMVECTOR XMVectorTrueInt() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTORU32 vResult = {0xFFFFFFFFU,0xFFFFFFFFU,0xFFFFFFFFU,0xFFFFFFFFU}; + return vResult.v; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_set1_epi32(-1); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Initialize a vector with all bits clear (false mask) +XMFINLINE XMVECTOR XMVectorFalseInt() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = {0.0f,0.0f,0.0f,0.0f}; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_setzero_ps(); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Replicate the x component of the vector +XMFINLINE XMVECTOR XMVectorSplatX +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_f32[0] = + vResult.vector4_f32[1] = + vResult.vector4_f32[2] = + vResult.vector4_f32[3] = V.vector4_f32[0]; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_shuffle_ps( V, V, _MM_SHUFFLE(0, 0, 0, 0) ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Replicate the y component of the vector +XMFINLINE XMVECTOR XMVectorSplatY +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_f32[0] = + vResult.vector4_f32[1] = + vResult.vector4_f32[2] = + vResult.vector4_f32[3] = V.vector4_f32[1]; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_shuffle_ps( V, V, _MM_SHUFFLE(1, 1, 1, 1) ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Replicate the z component of the vector +XMFINLINE XMVECTOR XMVectorSplatZ +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_f32[0] = + vResult.vector4_f32[1] = + vResult.vector4_f32[2] = + vResult.vector4_f32[3] = V.vector4_f32[2]; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_shuffle_ps( V, V, _MM_SHUFFLE(2, 2, 2, 2) ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Replicate the w component of the vector +XMFINLINE XMVECTOR XMVectorSplatW +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_f32[0] = + vResult.vector4_f32[1] = + vResult.vector4_f32[2] = + vResult.vector4_f32[3] = V.vector4_f32[3]; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_shuffle_ps( V, V, _MM_SHUFFLE(3, 3, 3, 3) ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return a vector of 1.0f,1.0f,1.0f,1.0f +XMFINLINE XMVECTOR XMVectorSplatOne() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_f32[0] = + vResult.vector4_f32[1] = + vResult.vector4_f32[2] = + vResult.vector4_f32[3] = 1.0f; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return g_XMOne; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return a vector of INF,INF,INF,INF +XMFINLINE XMVECTOR XMVectorSplatInfinity() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_u32[0] = + vResult.vector4_u32[1] = + vResult.vector4_u32[2] = + vResult.vector4_u32[3] = 0x7F800000; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return g_XMInfinity; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return a vector of Q_NAN,Q_NAN,Q_NAN,Q_NAN +XMFINLINE XMVECTOR XMVectorSplatQNaN() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_u32[0] = + vResult.vector4_u32[1] = + vResult.vector4_u32[2] = + vResult.vector4_u32[3] = 0x7FC00000; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return g_XMQNaN; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return a vector of 1.192092896e-7f,1.192092896e-7f,1.192092896e-7f,1.192092896e-7f +XMFINLINE XMVECTOR XMVectorSplatEpsilon() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_u32[0] = + vResult.vector4_u32[1] = + vResult.vector4_u32[2] = + vResult.vector4_u32[3] = 0x34000000; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + return g_XMEpsilon; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return a vector of -0.0f (0x80000000),-0.0f,-0.0f,-0.0f +XMFINLINE XMVECTOR XMVectorSplatSignMask() +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult; + vResult.vector4_u32[0] = + vResult.vector4_u32[1] = + vResult.vector4_u32[2] = + vResult.vector4_u32[3] = 0x80000000U; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_set1_epi32( 0x80000000 ); + return reinterpret_cast<__m128*>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return a floating point value via an index. This is not a recommended +// function to use due to performance loss. +XMFINLINE FLOAT XMVectorGetByIndex(FXMVECTOR V,UINT i) +{ + XMASSERT( i <= 3 ); +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_f32[i]; +#elif defined(_XM_SSE_INTRINSICS_) + return V.m128_f32[i]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return the X component in an FPU register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE FLOAT XMVectorGetX(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_f32[0]; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_MSC_VER) && (_MSC_VER>=1500) + return _mm_cvtss_f32(V); +#else + return V.m128_f32[0]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Return the Y component in an FPU register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE FLOAT XMVectorGetY(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_f32[1]; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_MSC_VER) && (_MSC_VER>=1500) + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + return _mm_cvtss_f32(vTemp); +#else + return V.m128_f32[1]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Return the Z component in an FPU register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE FLOAT XMVectorGetZ(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_f32[2]; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_MSC_VER) && (_MSC_VER>=1500) + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + return _mm_cvtss_f32(vTemp); +#else + return V.m128_f32[2]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Return the W component in an FPU register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE FLOAT XMVectorGetW(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_f32[3]; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_MSC_VER) && (_MSC_VER>=1500) + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,3,3,3)); + return _mm_cvtss_f32(vTemp); +#else + return V.m128_f32[3]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Store a component indexed by i into a 32 bit float location in memory. +// This causes Load/Hit/Store on VMX targets +XMFINLINE VOID XMVectorGetByIndexPtr(FLOAT *f,FXMVECTOR V,UINT i) +{ + XMASSERT( f != 0 ); + XMASSERT( i < 4 ); +#if defined(_XM_NO_INTRINSICS_) + *f = V.vector4_f32[i]; +#elif defined(_XM_SSE_INTRINSICS_) + *f = V.m128_f32[i]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Store the X component into a 32 bit float location in memory. +XMFINLINE VOID XMVectorGetXPtr(FLOAT *x,FXMVECTOR V) +{ + XMASSERT( x != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *x = V.vector4_f32[0]; +#elif defined(_XM_SSE_INTRINSICS_) + _mm_store_ss(x,V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Store the Y component into a 32 bit float location in memory. +XMFINLINE VOID XMVectorGetYPtr(FLOAT *y,FXMVECTOR V) +{ + XMASSERT( y != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *y = V.vector4_f32[1]; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + _mm_store_ss(y,vResult); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Store the Z component into a 32 bit float location in memory. +XMFINLINE VOID XMVectorGetZPtr(FLOAT *z,FXMVECTOR V) +{ + XMASSERT( z != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *z = V.vector4_f32[2]; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss(z,vResult); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Store the W component into a 32 bit float location in memory. +XMFINLINE VOID XMVectorGetWPtr(FLOAT *w,FXMVECTOR V) +{ + XMASSERT( w != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *w = V.vector4_f32[3]; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,3,3,3)); + _mm_store_ss(w,vResult); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Return an integer value via an index. This is not a recommended +// function to use due to performance loss. +XMFINLINE UINT XMVectorGetIntByIndex(FXMVECTOR V, UINT i) +{ + XMASSERT( i < 4 ); +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_u32[i]; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_MSC_VER) && (_MSC_VER<1400) + XMVECTORU32 tmp; + tmp.v = V; + return tmp.u[i]; +#else + return V.m128_u32[i]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Return the X component in an integer register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE UINT XMVectorGetIntX(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_u32[0]; +#elif defined(_XM_SSE_INTRINSICS_) + return static_cast(_mm_cvtsi128_si32(reinterpret_cast(&V)[0])); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Return the Y component in an integer register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE UINT XMVectorGetIntY(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_u32[1]; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vResulti = _mm_shuffle_epi32(reinterpret_cast(&V)[0],_MM_SHUFFLE(1,1,1,1)); + return static_cast(_mm_cvtsi128_si32(vResulti)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Return the Z component in an integer register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE UINT XMVectorGetIntZ(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_u32[2]; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vResulti = _mm_shuffle_epi32(reinterpret_cast(&V)[0],_MM_SHUFFLE(2,2,2,2)); + return static_cast(_mm_cvtsi128_si32(vResulti)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Return the W component in an integer register. +// This causes Load/Hit/Store on VMX targets +XMFINLINE UINT XMVectorGetIntW(FXMVECTOR V) +{ +#if defined(_XM_NO_INTRINSICS_) + return V.vector4_u32[3]; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vResulti = _mm_shuffle_epi32(reinterpret_cast(&V)[0],_MM_SHUFFLE(3,3,3,3)); + return static_cast(_mm_cvtsi128_si32(vResulti)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Store a component indexed by i into a 32 bit integer location in memory. +// This causes Load/Hit/Store on VMX targets +XMFINLINE VOID XMVectorGetIntByIndexPtr(UINT *x,FXMVECTOR V,UINT i) +{ + XMASSERT( x != 0 ); + XMASSERT( i < 4 ); +#if defined(_XM_NO_INTRINSICS_) + *x = V.vector4_u32[i]; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_MSC_VER) && (_MSC_VER<1400) + XMVECTORU32 tmp; + tmp.v = V; + *x = tmp.u[i]; +#else + *x = V.m128_u32[i]; +#endif +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Store the X component into a 32 bit integer location in memory. +XMFINLINE VOID XMVectorGetIntXPtr(UINT *x,FXMVECTOR V) +{ + XMASSERT( x != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *x = V.vector4_u32[0]; +#elif defined(_XM_SSE_INTRINSICS_) + _mm_store_ss(reinterpret_cast(x),V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Store the Y component into a 32 bit integer location in memory. +XMFINLINE VOID XMVectorGetIntYPtr(UINT *y,FXMVECTOR V) +{ + XMASSERT( y != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *y = V.vector4_u32[1]; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + _mm_store_ss(reinterpret_cast(y),vResult); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Store the Z component into a 32 bit integer locaCantion in memory. +XMFINLINE VOID XMVectorGetIntZPtr(UINT *z,FXMVECTOR V) +{ + XMASSERT( z != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *z = V.vector4_u32[2]; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + _mm_store_ss(reinterpret_cast(z),vResult); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Store the W component into a 32 bit integer location in memory. +XMFINLINE VOID XMVectorGetIntWPtr(UINT *w,FXMVECTOR V) +{ + XMASSERT( w != 0 ); +#if defined(_XM_NO_INTRINSICS_) + *w = V.vector4_u32[3]; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,3,3,3)); + _mm_store_ss(reinterpret_cast(w),vResult); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Set a single indexed floating point component +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetByIndex(FXMVECTOR V, FLOAT f,UINT i) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( i <= 3 ); + U = V; + U.vector4_f32[i] = f; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( i <= 3 ); + XMVECTOR U = V; + U.m128_f32[i] = f; + return U; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets the X component of a vector to a passed floating point value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetX(FXMVECTOR V, FLOAT x) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_f32[0] = x; + U.vector4_f32[1] = V.vector4_f32[1]; + U.vector4_f32[2] = V.vector4_f32[2]; + U.vector4_f32[3] = V.vector4_f32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_f32[0] = x; + return vResult; +#else + XMVECTOR vResult = _mm_set_ss(x); + vResult = _mm_move_ss(V,vResult); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Y component of a vector to a passed floating point value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetY(FXMVECTOR V, FLOAT y) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_f32[0] = V.vector4_f32[0]; + U.vector4_f32[1] = y; + U.vector4_f32[2] = V.vector4_f32[2]; + U.vector4_f32[3] = V.vector4_f32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_f32[1] = y; + return vResult; +#else + // Swap y and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,2,0,1)); + // Convert input to vector + XMVECTOR vTemp = _mm_set_ss(y); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap y and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,2,0,1)); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} +// Sets the Z component of a vector to a passed floating point value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetZ(FXMVECTOR V, FLOAT z) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_f32[0] = V.vector4_f32[0]; + U.vector4_f32[1] = V.vector4_f32[1]; + U.vector4_f32[2] = z; + U.vector4_f32[3] = V.vector4_f32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_f32[2] = z; + return vResult; +#else + // Swap z and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,0,1,2)); + // Convert input to vector + XMVECTOR vTemp = _mm_set_ss(z); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap z and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,0,1,2)); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the W component of a vector to a passed floating point value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetW(FXMVECTOR V, FLOAT w) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_f32[0] = V.vector4_f32[0]; + U.vector4_f32[1] = V.vector4_f32[1]; + U.vector4_f32[2] = V.vector4_f32[2]; + U.vector4_f32[3] = w; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_f32[3] = w; + return vResult; +#else + // Swap w and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,2,1,3)); + // Convert input to vector + XMVECTOR vTemp = _mm_set_ss(w); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap w and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,2,1,3)); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets a component of a vector to a floating point value passed by pointer +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetByIndexPtr(FXMVECTOR V,CONST FLOAT *f,UINT i) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( f != 0 ); + XMASSERT( i <= 3 ); + U = V; + U.vector4_f32[i] = *f; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( f != 0 ); + XMASSERT( i <= 3 ); + XMVECTOR U = V; + U.m128_f32[i] = *f; + return U; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets the X component of a vector to a floating point value passed by pointer +XMFINLINE XMVECTOR XMVectorSetXPtr(FXMVECTOR V,CONST FLOAT *x) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( x != 0 ); + U.vector4_f32[0] = *x; + U.vector4_f32[1] = V.vector4_f32[1]; + U.vector4_f32[2] = V.vector4_f32[2]; + U.vector4_f32[3] = V.vector4_f32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( x != 0 ); + XMVECTOR vResult = _mm_load_ss(x); + vResult = _mm_move_ss(V,vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Y component of a vector to a floating point value passed by pointer +XMFINLINE XMVECTOR XMVectorSetYPtr(FXMVECTOR V,CONST FLOAT *y) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( y != 0 ); + U.vector4_f32[0] = V.vector4_f32[0]; + U.vector4_f32[1] = *y; + U.vector4_f32[2] = V.vector4_f32[2]; + U.vector4_f32[3] = V.vector4_f32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( y != 0 ); + // Swap y and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,2,0,1)); + // Convert input to vector + XMVECTOR vTemp = _mm_load_ss(y); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap y and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,2,0,1)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Z component of a vector to a floating point value passed by pointer +XMFINLINE XMVECTOR XMVectorSetZPtr(FXMVECTOR V,CONST FLOAT *z) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( z != 0 ); + U.vector4_f32[0] = V.vector4_f32[0]; + U.vector4_f32[1] = V.vector4_f32[1]; + U.vector4_f32[2] = *z; + U.vector4_f32[3] = V.vector4_f32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( z != 0 ); + // Swap z and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,0,1,2)); + // Convert input to vector + XMVECTOR vTemp = _mm_load_ss(z); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap z and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,0,1,2)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the W component of a vector to a floating point value passed by pointer +XMFINLINE XMVECTOR XMVectorSetWPtr(FXMVECTOR V,CONST FLOAT *w) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( w != 0 ); + U.vector4_f32[0] = V.vector4_f32[0]; + U.vector4_f32[1] = V.vector4_f32[1]; + U.vector4_f32[2] = V.vector4_f32[2]; + U.vector4_f32[3] = *w; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( w != 0 ); + // Swap w and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,2,1,3)); + // Convert input to vector + XMVECTOR vTemp = _mm_load_ss(w); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap w and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,2,1,3)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets a component of a vector to an integer passed by value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetIntByIndex(FXMVECTOR V, UINT x, UINT i) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( i <= 3 ); + U = V; + U.vector4_u32[i] = x; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( i <= 3 ); + XMVECTORU32 tmp; + tmp.v = V; + tmp.u[i] = x; + return tmp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets the X component of a vector to an integer passed by value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetIntX(FXMVECTOR V, UINT x) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_u32[0] = x; + U.vector4_u32[1] = V.vector4_u32[1]; + U.vector4_u32[2] = V.vector4_u32[2]; + U.vector4_u32[3] = V.vector4_u32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_i32[0] = x; + return vResult; +#else + __m128i vTemp = _mm_cvtsi32_si128(x); + XMVECTOR vResult = _mm_move_ss(V,reinterpret_cast(&vTemp)[0]); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Y component of a vector to an integer passed by value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetIntY(FXMVECTOR V, UINT y) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_u32[0] = V.vector4_u32[0]; + U.vector4_u32[1] = y; + U.vector4_u32[2] = V.vector4_u32[2]; + U.vector4_u32[3] = V.vector4_u32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_i32[1] = y; + return vResult; +#else // Swap y and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,2,0,1)); + // Convert input to vector + __m128i vTemp = _mm_cvtsi32_si128(y); + // Replace the x component + vResult = _mm_move_ss(vResult,reinterpret_cast(&vTemp)[0]); + // Swap y and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,2,0,1)); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Z component of a vector to an integer passed by value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetIntZ(FXMVECTOR V, UINT z) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_u32[0] = V.vector4_u32[0]; + U.vector4_u32[1] = V.vector4_u32[1]; + U.vector4_u32[2] = z; + U.vector4_u32[3] = V.vector4_u32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_i32[2] = z; + return vResult; +#else + // Swap z and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,0,1,2)); + // Convert input to vector + __m128i vTemp = _mm_cvtsi32_si128(z); + // Replace the x component + vResult = _mm_move_ss(vResult,reinterpret_cast(&vTemp)[0]); + // Swap z and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,0,1,2)); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the W component of a vector to an integer passed by value +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetIntW(FXMVECTOR V, UINT w) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + U.vector4_u32[0] = V.vector4_u32[0]; + U.vector4_u32[1] = V.vector4_u32[1]; + U.vector4_u32[2] = V.vector4_u32[2]; + U.vector4_u32[3] = w; + return U; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_XM_ISVS2005_) + XMVECTOR vResult = V; + vResult.m128_i32[3] = w; + return vResult; +#else + // Swap w and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,2,1,3)); + // Convert input to vector + __m128i vTemp = _mm_cvtsi32_si128(w); + // Replace the x component + vResult = _mm_move_ss(vResult,reinterpret_cast(&vTemp)[0]); + // Swap w and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,2,1,3)); + return vResult; +#endif // _XM_ISVS2005_ +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets a component of a vector to an integer value passed by pointer +// This causes Load/Hit/Store on VMX targets +XMFINLINE XMVECTOR XMVectorSetIntByIndexPtr(FXMVECTOR V, CONST UINT *x,UINT i) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( x != 0 ); + XMASSERT( i <= 3 ); + U = V; + U.vector4_u32[i] = *x; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( x != 0 ); + XMASSERT( i <= 3 ); + XMVECTORU32 tmp; + tmp.v = V; + tmp.u[i] = *x; + return tmp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Sets the X component of a vector to an integer value passed by pointer +XMFINLINE XMVECTOR XMVectorSetIntXPtr(FXMVECTOR V,CONST UINT *x) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( x != 0 ); + U.vector4_u32[0] = *x; + U.vector4_u32[1] = V.vector4_u32[1]; + U.vector4_u32[2] = V.vector4_u32[2]; + U.vector4_u32[3] = V.vector4_u32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( x != 0 ); + XMVECTOR vTemp = _mm_load_ss(reinterpret_cast(x)); + XMVECTOR vResult = _mm_move_ss(V,vTemp); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Y component of a vector to an integer value passed by pointer +XMFINLINE XMVECTOR XMVectorSetIntYPtr(FXMVECTOR V,CONST UINT *y) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( y != 0 ); + U.vector4_u32[0] = V.vector4_u32[0]; + U.vector4_u32[1] = *y; + U.vector4_u32[2] = V.vector4_u32[2]; + U.vector4_u32[3] = V.vector4_u32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( y != 0 ); + // Swap y and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,2,0,1)); + // Convert input to vector + XMVECTOR vTemp = _mm_load_ss(reinterpret_cast(y)); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap y and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,2,0,1)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the Z component of a vector to an integer value passed by pointer +XMFINLINE XMVECTOR XMVectorSetIntZPtr(FXMVECTOR V,CONST UINT *z) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( z != 0 ); + U.vector4_u32[0] = V.vector4_u32[0]; + U.vector4_u32[1] = V.vector4_u32[1]; + U.vector4_u32[2] = *z; + U.vector4_u32[3] = V.vector4_u32[3]; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( z != 0 ); + // Swap z and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,0,1,2)); + // Convert input to vector + XMVECTOR vTemp = _mm_load_ss(reinterpret_cast(z)); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap z and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,0,1,2)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +// Sets the W component of a vector to an integer value passed by pointer +XMFINLINE XMVECTOR XMVectorSetIntWPtr(FXMVECTOR V,CONST UINT *w) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR U; + XMASSERT( w != 0 ); + U.vector4_u32[0] = V.vector4_u32[0]; + U.vector4_u32[1] = V.vector4_u32[1]; + U.vector4_u32[2] = V.vector4_u32[2]; + U.vector4_u32[3] = *w; + return U; +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( w != 0 ); + // Swap w and x + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,2,1,3)); + // Convert input to vector + XMVECTOR vTemp = _mm_load_ss(reinterpret_cast(w)); + // Replace the x component + vResult = _mm_move_ss(vResult,vTemp); + // Swap w and x again + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,2,1,3)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Define a control vector to be used in XMVectorPermute +// operations. Visualize the two vectors V1 and V2 given +// in a permute as arranged back to back in a linear fashion, +// such that they form an array of 8 floating point values. +// The four integers specified in XMVectorPermuteControl +// will serve as indices into the array to select components +// from the two vectors. ElementIndex0 is used to select +// an element from the vectors to be placed in the first +// component of the resulting vector, ElementIndex1 is used +// to select an element for the second component, etc. + +XMFINLINE XMVECTOR XMVectorPermuteControl +( + UINT ElementIndex0, + UINT ElementIndex1, + UINT ElementIndex2, + UINT ElementIndex3 +) +{ +#if defined(_XM_SSE_INTRINSICS_) || defined(_XM_NO_INTRINSICS_) + XMVECTORU32 vControl; + static CONST UINT ControlElement[] = { + XM_PERMUTE_0X, + XM_PERMUTE_0Y, + XM_PERMUTE_0Z, + XM_PERMUTE_0W, + XM_PERMUTE_1X, + XM_PERMUTE_1Y, + XM_PERMUTE_1Z, + XM_PERMUTE_1W + }; + XMASSERT(ElementIndex0 < 8); + XMASSERT(ElementIndex1 < 8); + XMASSERT(ElementIndex2 < 8); + XMASSERT(ElementIndex3 < 8); + + vControl.u[0] = ControlElement[ElementIndex0]; + vControl.u[1] = ControlElement[ElementIndex1]; + vControl.u[2] = ControlElement[ElementIndex2]; + vControl.u[3] = ControlElement[ElementIndex3]; + return vControl.v; +#else +#endif +} + +//------------------------------------------------------------------------------ + +// Using a control vector made up of 16 bytes from 0-31, remap V1 and V2's byte +// entries into a single 16 byte vector and return it. Index 0-15 = V1, +// 16-31 = V2 +XMFINLINE XMVECTOR XMVectorPermute +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR Control +) +{ +#if defined(_XM_NO_INTRINSICS_) + const BYTE *aByte[2]; + XMVECTOR Result; + UINT i, uIndex, VectorIndex; + const BYTE *pControl; + BYTE *pWork; + + // Indices must be in range from 0 to 31 + XMASSERT((Control.vector4_u32[0] & 0xE0E0E0E0) == 0); + XMASSERT((Control.vector4_u32[1] & 0xE0E0E0E0) == 0); + XMASSERT((Control.vector4_u32[2] & 0xE0E0E0E0) == 0); + XMASSERT((Control.vector4_u32[3] & 0xE0E0E0E0) == 0); + + // 0-15 = V1, 16-31 = V2 + aByte[0] = (const BYTE*)(&V1); + aByte[1] = (const BYTE*)(&V2); + i = 16; + pControl = (const BYTE *)(&Control); + pWork = (BYTE *)(&Result); + do { + // Get the byte to map from + uIndex = pControl[0]; + ++pControl; + VectorIndex = (uIndex>>4)&1; + uIndex &= 0x0F; +#if defined(_XM_LITTLEENDIAN_) + uIndex ^= 3; // Swap byte ordering on little endian machines +#endif + pWork[0] = aByte[VectorIndex][uIndex]; + ++pWork; + } while (--i); + return Result; +#elif defined(_XM_SSE_INTRINSICS_) +#if defined(_PREFAST_) || defined(XMDEBUG) + // Indices must be in range from 0 to 31 + static const XMVECTORI32 PremuteTest = {0xE0E0E0E0,0xE0E0E0E0,0xE0E0E0E0,0xE0E0E0E0}; + XMVECTOR vAssert = _mm_and_ps(Control,PremuteTest); + __m128i vAsserti = _mm_cmpeq_epi32(reinterpret_cast(&vAssert)[0],g_XMZero); + XMASSERT(_mm_movemask_ps(*reinterpret_cast(&vAsserti)) == 0xf); +#endif + // Store the vectors onto local memory on the stack + XMVECTOR Array[2]; + Array[0] = V1; + Array[1] = V2; + // Output vector, on the stack + XMVECTORU8 vResult; + // Get pointer to the two vectors on the stack + const BYTE *pInput = reinterpret_cast(Array); + // Store the Control vector on the stack to access the bytes + // don't use Control, it can cause a register variable to spill on the stack. + XMVECTORU8 vControl; + vControl.v = Control; // Write to memory + UINT i = 0; + do { + UINT ComponentIndex = vControl.u[i] & 0x1FU; + ComponentIndex ^= 3; // Swap byte ordering + vResult.u[i] = pInput[ComponentIndex]; + } while (++i<16); + return vResult; +#else // _XM_SSE_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Define a control vector to be used in XMVectorSelect +// operations. The four integers specified in XMVectorSelectControl +// serve as indices to select between components in two vectors. +// The first index controls selection for the first component of +// the vectors involved in a select operation, the second index +// controls selection for the second component etc. A value of +// zero for an index causes the corresponding component from the first +// vector to be selected whereas a one causes the component from the +// second vector to be selected instead. + +XMFINLINE XMVECTOR XMVectorSelectControl +( + UINT VectorIndex0, + UINT VectorIndex1, + UINT VectorIndex2, + UINT VectorIndex3 +) +{ +#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_) + // x=Index0,y=Index1,z=Index2,w=Index3 + __m128i vTemp = _mm_set_epi32(VectorIndex3,VectorIndex2,VectorIndex1,VectorIndex0); + // Any non-zero entries become 0xFFFFFFFF else 0 + vTemp = _mm_cmpgt_epi32(vTemp,g_XMZero); + return reinterpret_cast<__m128 *>(&vTemp)[0]; +#else + XMVECTOR ControlVector; + CONST UINT ControlElement[] = + { + XM_SELECT_0, + XM_SELECT_1 + }; + + XMASSERT(VectorIndex0 < 2); + XMASSERT(VectorIndex1 < 2); + XMASSERT(VectorIndex2 < 2); + XMASSERT(VectorIndex3 < 2); + + ControlVector.vector4_u32[0] = ControlElement[VectorIndex0]; + ControlVector.vector4_u32[1] = ControlElement[VectorIndex1]; + ControlVector.vector4_u32[2] = ControlElement[VectorIndex2]; + ControlVector.vector4_u32[3] = ControlElement[VectorIndex3]; + + return ControlVector; + +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSelect +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR Control +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = (V1.vector4_u32[0] & ~Control.vector4_u32[0]) | (V2.vector4_u32[0] & Control.vector4_u32[0]); + Result.vector4_u32[1] = (V1.vector4_u32[1] & ~Control.vector4_u32[1]) | (V2.vector4_u32[1] & Control.vector4_u32[1]); + Result.vector4_u32[2] = (V1.vector4_u32[2] & ~Control.vector4_u32[2]) | (V2.vector4_u32[2] & Control.vector4_u32[2]); + Result.vector4_u32[3] = (V1.vector4_u32[3] & ~Control.vector4_u32[3]) | (V2.vector4_u32[3] & Control.vector4_u32[3]); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp1 = _mm_andnot_ps(Control,V1); + XMVECTOR vTemp2 = _mm_and_ps(V2,Control); + return _mm_or_ps(vTemp1,vTemp2); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMergeXY +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = V1.vector4_u32[0]; + Result.vector4_u32[1] = V2.vector4_u32[0]; + Result.vector4_u32[2] = V1.vector4_u32[1]; + Result.vector4_u32[3] = V2.vector4_u32[1]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_unpacklo_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMergeZW +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = V1.vector4_u32[2]; + Result.vector4_u32[1] = V2.vector4_u32[2]; + Result.vector4_u32[2] = V1.vector4_u32[3]; + Result.vector4_u32[3] = V2.vector4_u32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_unpackhi_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + + Control.vector4_u32[0] = (V1.vector4_f32[0] == V2.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_f32[1] == V2.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_f32[2] == V2.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_f32[3] == V2.vector4_f32[3]) ? 0xFFFFFFFF : 0; + + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_cmpeq_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorEqualR +( + UINT* pCR, + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ux, uy, uz, uw, CR; + XMVECTOR Control; + + XMASSERT( pCR ); + + ux = (V1.vector4_f32[0] == V2.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + uy = (V1.vector4_f32[1] == V2.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + uz = (V1.vector4_f32[2] == V2.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + uw = (V1.vector4_f32[3] == V2.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + CR = 0; + if (ux&uy&uz&uw) + { + // All elements are greater + CR = XM_CRMASK_CR6TRUE; + } + else if (!(ux|uy|uz|uw)) + { + // All elements are not greater + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + Control.vector4_u32[0] = ux; + Control.vector4_u32[1] = uy; + Control.vector4_u32[2] = uz; + Control.vector4_u32[3] = uw; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( pCR ); + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); + UINT CR = 0; + int iTest = _mm_movemask_ps(vTemp); + if (iTest==0xf) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + // All elements are not greater + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + return vTemp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Treat the components of the vectors as unsigned integers and +// compare individual bits between the two. This is useful for +// comparing control vectors and result vectors returned from +// other comparison operations. + +XMFINLINE XMVECTOR XMVectorEqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + + Control.vector4_u32[0] = (V1.vector4_u32[0] == V2.vector4_u32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_u32[1] == V2.vector4_u32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_u32[2] == V2.vector4_u32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_u32[3] == V2.vector4_u32[3]) ? 0xFFFFFFFF : 0; + + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_cmpeq_epi32( reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0] ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorEqualIntR +( + UINT* pCR, + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + + XMASSERT(pCR); + + Control = XMVectorEqualInt(V1, V2); + + *pCR = 0; + + if (XMVector4EqualInt(Control, XMVectorTrueInt())) + { + // All elements are equal + *pCR |= XM_CRMASK_CR6TRUE; + } + else if (XMVector4EqualInt(Control, XMVectorFalseInt())) + { + // All elements are not equal + *pCR |= XM_CRMASK_CR6FALSE; + } + + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pCR); + __m128i V = _mm_cmpeq_epi32( reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0] ); + int iTemp = _mm_movemask_ps(reinterpret_cast(&V)[0]); + UINT CR = 0; + if (iTemp==0x0F) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTemp) + { + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorNearEqual +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR Epsilon +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT fDeltax, fDeltay, fDeltaz, fDeltaw; + XMVECTOR Control; + + fDeltax = V1.vector4_f32[0]-V2.vector4_f32[0]; + fDeltay = V1.vector4_f32[1]-V2.vector4_f32[1]; + fDeltaz = V1.vector4_f32[2]-V2.vector4_f32[2]; + fDeltaw = V1.vector4_f32[3]-V2.vector4_f32[3]; + + fDeltax = fabsf(fDeltax); + fDeltay = fabsf(fDeltay); + fDeltaz = fabsf(fDeltaz); + fDeltaw = fabsf(fDeltaw); + + Control.vector4_u32[0] = (fDeltax <= Epsilon.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[1] = (fDeltay <= Epsilon.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[2] = (fDeltaz <= Epsilon.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[3] = (fDeltaw <= Epsilon.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + // Get the difference + XMVECTOR vDelta = _mm_sub_ps(V1,V2); + // Get the absolute value of the difference + XMVECTOR vTemp = _mm_setzero_ps(); + vTemp = _mm_sub_ps(vTemp,vDelta); + vTemp = _mm_max_ps(vTemp,vDelta); + vTemp = _mm_cmple_ps(vTemp,Epsilon); + return vTemp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorNotEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V1.vector4_f32[0] != V2.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_f32[1] != V2.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_f32[2] != V2.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_f32[3] != V2.vector4_f32[3]) ? 0xFFFFFFFF : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_cmpneq_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorNotEqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V1.vector4_u32[0] != V2.vector4_u32[0]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[1] = (V1.vector4_u32[1] != V2.vector4_u32[1]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[2] = (V1.vector4_u32[2] != V2.vector4_u32[2]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[3] = (V1.vector4_u32[3] != V2.vector4_u32[3]) ? 0xFFFFFFFFU : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_cmpeq_epi32( reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0] ); + return _mm_xor_ps(reinterpret_cast<__m128 *>(&V)[0],g_XMNegOneMask); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorGreater +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V1.vector4_f32[0] > V2.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_f32[1] > V2.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_f32[2] > V2.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_f32[3] > V2.vector4_f32[3]) ? 0xFFFFFFFF : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_cmpgt_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorGreaterR +( + UINT* pCR, + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ux, uy, uz, uw, CR; + XMVECTOR Control; + + XMASSERT( pCR ); + + ux = (V1.vector4_f32[0] > V2.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + uy = (V1.vector4_f32[1] > V2.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + uz = (V1.vector4_f32[2] > V2.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + uw = (V1.vector4_f32[3] > V2.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + CR = 0; + if (ux&uy&uz&uw) + { + // All elements are greater + CR = XM_CRMASK_CR6TRUE; + } + else if (!(ux|uy|uz|uw)) + { + // All elements are not greater + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + Control.vector4_u32[0] = ux; + Control.vector4_u32[1] = uy; + Control.vector4_u32[2] = uz; + Control.vector4_u32[3] = uw; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( pCR ); + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); + UINT CR = 0; + int iTest = _mm_movemask_ps(vTemp); + if (iTest==0xf) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + // All elements are not greater + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + return vTemp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorGreaterOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V1.vector4_f32[0] >= V2.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_f32[1] >= V2.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_f32[2] >= V2.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_f32[3] >= V2.vector4_f32[3]) ? 0xFFFFFFFF : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_cmpge_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorGreaterOrEqualR +( + UINT* pCR, + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ux, uy, uz, uw, CR; + XMVECTOR Control; + + XMASSERT( pCR ); + + ux = (V1.vector4_f32[0] >= V2.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + uy = (V1.vector4_f32[1] >= V2.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + uz = (V1.vector4_f32[2] >= V2.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + uw = (V1.vector4_f32[3] >= V2.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + CR = 0; + if (ux&uy&uz&uw) + { + // All elements are greater + CR = XM_CRMASK_CR6TRUE; + } + else if (!(ux|uy|uz|uw)) + { + // All elements are not greater + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + Control.vector4_u32[0] = ux; + Control.vector4_u32[1] = uy; + Control.vector4_u32[2] = uz; + Control.vector4_u32[3] = uw; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( pCR ); + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + UINT CR = 0; + int iTest = _mm_movemask_ps(vTemp); + if (iTest==0xf) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + // All elements are not greater + CR = XM_CRMASK_CR6FALSE; + } + *pCR = CR; + return vTemp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorLess +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V1.vector4_f32[0] < V2.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_f32[1] < V2.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_f32[2] < V2.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_f32[3] < V2.vector4_f32[3]) ? 0xFFFFFFFF : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_cmplt_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorLessOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V1.vector4_f32[0] <= V2.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V1.vector4_f32[1] <= V2.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V1.vector4_f32[2] <= V2.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V1.vector4_f32[3] <= V2.vector4_f32[3]) ? 0xFFFFFFFF : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_cmple_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorInBounds +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = (V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[1] = (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[2] = (V.vector4_f32[2] <= Bounds.vector4_f32[2] && V.vector4_f32[2] >= -Bounds.vector4_f32[2]) ? 0xFFFFFFFF : 0; + Control.vector4_u32[3] = (V.vector4_f32[3] <= Bounds.vector4_f32[3] && V.vector4_f32[3] >= -Bounds.vector4_f32[3]) ? 0xFFFFFFFF : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + return vTemp1; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorInBoundsR +( + UINT* pCR, + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT ux, uy, uz, uw, CR; + XMVECTOR Control; + + XMASSERT( pCR != 0 ); + + ux = (V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + uy = (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + uz = (V.vector4_f32[2] <= Bounds.vector4_f32[2] && V.vector4_f32[2] >= -Bounds.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + uw = (V.vector4_f32[3] <= Bounds.vector4_f32[3] && V.vector4_f32[3] >= -Bounds.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + + CR = 0; + + if (ux&uy&uz&uw) + { + // All elements are in bounds + CR = XM_CRMASK_CR6BOUNDS; + } + *pCR = CR; + Control.vector4_u32[0] = ux; + Control.vector4_u32[1] = uy; + Control.vector4_u32[2] = uz; + Control.vector4_u32[3] = uw; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT( pCR != 0 ); + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + + UINT CR = 0; + if (_mm_movemask_ps(vTemp1)==0xf) { + // All elements are in bounds + CR = XM_CRMASK_CR6BOUNDS; + } + *pCR = CR; + return vTemp1; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorIsNaN +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = XMISNAN(V.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[1] = XMISNAN(V.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[2] = XMISNAN(V.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[3] = XMISNAN(V.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the exponent + __m128i vTempInf = _mm_and_si128(reinterpret_cast(&V)[0],g_XMInfinity); + // Mask off the mantissa + __m128i vTempNan = _mm_and_si128(reinterpret_cast(&V)[0],g_XMQNaNTest); + // Are any of the exponents == 0x7F800000? + vTempInf = _mm_cmpeq_epi32(vTempInf,g_XMInfinity); + // Are any of the mantissa's zero? (SSE2 doesn't have a neq test) + vTempNan = _mm_cmpeq_epi32(vTempNan,g_XMZero); + // Perform a not on the NaN test to be true on NON-zero mantissas + vTempNan = _mm_andnot_si128(vTempNan,vTempInf); + // If any are NaN, the signs are true after the merge above + return reinterpret_cast(&vTempNan)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorIsInfinite +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Control; + Control.vector4_u32[0] = XMISINF(V.vector4_f32[0]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[1] = XMISINF(V.vector4_f32[1]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[2] = XMISINF(V.vector4_f32[2]) ? 0xFFFFFFFFU : 0; + Control.vector4_u32[3] = XMISINF(V.vector4_f32[3]) ? 0xFFFFFFFFU : 0; + return Control; + +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the sign bit + __m128 vTemp = _mm_and_ps(V,g_XMAbsMask); + // Compare to infinity + vTemp = _mm_cmpeq_ps(vTemp,g_XMInfinity); + // If any are infinity, the signs are true. + return vTemp; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Rounding and clamping operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMin +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result.vector4_f32[0] = (V1.vector4_f32[0] < V2.vector4_f32[0]) ? V1.vector4_f32[0] : V2.vector4_f32[0]; + Result.vector4_f32[1] = (V1.vector4_f32[1] < V2.vector4_f32[1]) ? V1.vector4_f32[1] : V2.vector4_f32[1]; + Result.vector4_f32[2] = (V1.vector4_f32[2] < V2.vector4_f32[2]) ? V1.vector4_f32[2] : V2.vector4_f32[2]; + Result.vector4_f32[3] = (V1.vector4_f32[3] < V2.vector4_f32[3]) ? V1.vector4_f32[3] : V2.vector4_f32[3]; + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_min_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMax +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result.vector4_f32[0] = (V1.vector4_f32[0] > V2.vector4_f32[0]) ? V1.vector4_f32[0] : V2.vector4_f32[0]; + Result.vector4_f32[1] = (V1.vector4_f32[1] > V2.vector4_f32[1]) ? V1.vector4_f32[1] : V2.vector4_f32[1]; + Result.vector4_f32[2] = (V1.vector4_f32[2] > V2.vector4_f32[2]) ? V1.vector4_f32[2] : V2.vector4_f32[2]; + Result.vector4_f32[3] = (V1.vector4_f32[3] > V2.vector4_f32[3]) ? V1.vector4_f32[3] : V2.vector4_f32[3]; + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_max_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorRound +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + XMVECTOR Bias; + CONST XMVECTOR Zero = XMVectorZero(); + CONST XMVECTOR BiasPos = XMVectorReplicate(0.5f); + CONST XMVECTOR BiasNeg = XMVectorReplicate(-0.5f); + + Bias = XMVectorLess(V, Zero); + Bias = XMVectorSelect(BiasPos, BiasNeg, Bias); + Result = XMVectorAdd(V, Bias); + Result = XMVectorTruncate(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // To handle NAN, INF and numbers greater than 8388608, use masking + // Get the abs value + __m128i vTest = _mm_and_si128(reinterpret_cast(&V)[0],g_XMAbsMask); + // Test for greater than 8388608 (All floats with NO fractionals, NAN and INF + vTest = _mm_cmplt_epi32(vTest,g_XMNoFraction); + // Convert to int and back to float for rounding + __m128i vInt = _mm_cvtps_epi32(V); + // Convert back to floats + XMVECTOR vResult = _mm_cvtepi32_ps(vInt); + // All numbers less than 8388608 will use the round to int + vResult = _mm_and_ps(vResult,reinterpret_cast(&vTest)[0]); + // All others, use the ORIGINAL value + vTest = _mm_andnot_si128(vTest,reinterpret_cast(&V)[0]); + vResult = _mm_or_ps(vResult,reinterpret_cast(&vTest)[0]); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorTruncate +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Result; + UINT i; + + // Avoid C4701 + Result.vector4_f32[0] = 0.0f; + + for (i = 0; i < 4; i++) + { + if (XMISNAN(V.vector4_f32[i])) + { + Result.vector4_u32[i] = 0x7FC00000; + } + else if (fabsf(V.vector4_f32[i]) < 8388608.0f) + { + Result.vector4_f32[i] = (FLOAT)((INT)V.vector4_f32[i]); + } + else + { + Result.vector4_f32[i] = V.vector4_f32[i]; + } + } + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // To handle NAN, INF and numbers greater than 8388608, use masking + // Get the abs value + __m128i vTest = _mm_and_si128(reinterpret_cast(&V)[0],g_XMAbsMask); + // Test for greater than 8388608 (All floats with NO fractionals, NAN and INF + vTest = _mm_cmplt_epi32(vTest,g_XMNoFraction); + // Convert to int and back to float for rounding with truncation + __m128i vInt = _mm_cvttps_epi32(V); + // Convert back to floats + XMVECTOR vResult = _mm_cvtepi32_ps(vInt); + // All numbers less than 8388608 will use the round to int + vResult = _mm_and_ps(vResult,reinterpret_cast(&vTest)[0]); + // All others, use the ORIGINAL value + vTest = _mm_andnot_si128(vTest,reinterpret_cast(&V)[0]); + vResult = _mm_or_ps(vResult,reinterpret_cast(&vTest)[0]); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorFloor +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR vResult = { + floorf(V.vector4_f32[0]), + floorf(V.vector4_f32[1]), + floorf(V.vector4_f32[2]), + floorf(V.vector4_f32[3]) + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // To handle NAN, INF and numbers greater than 8388608, use masking + // Get the abs value + __m128i vTest = _mm_and_si128(reinterpret_cast(&V)[0],g_XMAbsMask); + // Test for greater than 8388608 (All floats with NO fractionals, NAN and INF + vTest = _mm_cmplt_epi32(vTest,g_XMNoFraction); + // Convert to int and back to float for rounding + XMVECTOR vResult = _mm_sub_ps(V,g_XMOneHalfMinusEpsilon); + __m128i vInt = _mm_cvtps_epi32(vResult); + // Convert back to floats + vResult = _mm_cvtepi32_ps(vInt); + // All numbers less than 8388608 will use the round to int + vResult = _mm_and_ps(vResult,reinterpret_cast(&vTest)[0]); + // All others, use the ORIGINAL value + vTest = _mm_andnot_si128(vTest,reinterpret_cast(&V)[0]); + vResult = _mm_or_ps(vResult,reinterpret_cast(&vTest)[0]); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorCeiling +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = { + ceilf(V.vector4_f32[0]), + ceilf(V.vector4_f32[1]), + ceilf(V.vector4_f32[2]), + ceilf(V.vector4_f32[3]) + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // To handle NAN, INF and numbers greater than 8388608, use masking + // Get the abs value + __m128i vTest = _mm_and_si128(reinterpret_cast(&V)[0],g_XMAbsMask); + // Test for greater than 8388608 (All floats with NO fractionals, NAN and INF + vTest = _mm_cmplt_epi32(vTest,g_XMNoFraction); + // Convert to int and back to float for rounding + XMVECTOR vResult = _mm_add_ps(V,g_XMOneHalfMinusEpsilon); + __m128i vInt = _mm_cvtps_epi32(vResult); + // Convert back to floats + vResult = _mm_cvtepi32_ps(vInt); + // All numbers less than 8388608 will use the round to int + vResult = _mm_and_ps(vResult,reinterpret_cast(&vTest)[0]); + // All others, use the ORIGINAL value + vTest = _mm_andnot_si128(vTest,reinterpret_cast(&V)[0]); + vResult = _mm_or_ps(vResult,reinterpret_cast(&vTest)[0]); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorClamp +( + FXMVECTOR V, + FXMVECTOR Min, + FXMVECTOR Max +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + XMASSERT(XMVector4LessOrEqual(Min, Max)); + + Result = XMVectorMax(Min, V); + Result = XMVectorMin(Max, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult; + XMASSERT(XMVector4LessOrEqual(Min, Max)); + vResult = _mm_max_ps(Min,V); + vResult = _mm_min_ps(vResult,Max); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSaturate +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + CONST XMVECTOR Zero = XMVectorZero(); + + return XMVectorClamp(V, Zero, g_XMOne.v); + +#elif defined(_XM_SSE_INTRINSICS_) + // Set <0 to 0 + XMVECTOR vResult = _mm_max_ps(V,g_XMZero); + // Set>1 to 1 + return _mm_min_ps(vResult,g_XMOne); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Bitwise logical operations +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorAndInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = V1.vector4_u32[0] & V2.vector4_u32[0]; + Result.vector4_u32[1] = V1.vector4_u32[1] & V2.vector4_u32[1]; + Result.vector4_u32[2] = V1.vector4_u32[2] & V2.vector4_u32[2]; + Result.vector4_u32[3] = V1.vector4_u32[3] & V2.vector4_u32[3]; + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_and_ps(V1,V2); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorAndCInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = V1.vector4_u32[0] & ~V2.vector4_u32[0]; + Result.vector4_u32[1] = V1.vector4_u32[1] & ~V2.vector4_u32[1]; + Result.vector4_u32[2] = V1.vector4_u32[2] & ~V2.vector4_u32[2]; + Result.vector4_u32[3] = V1.vector4_u32[3] & ~V2.vector4_u32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_andnot_si128( reinterpret_cast(&V2)[0], reinterpret_cast(&V1)[0] ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorOrInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = V1.vector4_u32[0] | V2.vector4_u32[0]; + Result.vector4_u32[1] = V1.vector4_u32[1] | V2.vector4_u32[1]; + Result.vector4_u32[2] = V1.vector4_u32[2] | V2.vector4_u32[2]; + Result.vector4_u32[3] = V1.vector4_u32[3] | V2.vector4_u32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_or_si128( reinterpret_cast(&V1)[0], reinterpret_cast(&V2)[0] ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorNorInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = ~(V1.vector4_u32[0] | V2.vector4_u32[0]); + Result.vector4_u32[1] = ~(V1.vector4_u32[1] | V2.vector4_u32[1]); + Result.vector4_u32[2] = ~(V1.vector4_u32[2] | V2.vector4_u32[2]); + Result.vector4_u32[3] = ~(V1.vector4_u32[3] | V2.vector4_u32[3]); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i Result; + Result = _mm_or_si128( reinterpret_cast(&V1)[0], reinterpret_cast(&V2)[0] ); + Result = _mm_andnot_si128( Result,g_XMNegOneMask); + return reinterpret_cast<__m128 *>(&Result)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorXorInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_u32[0] = V1.vector4_u32[0] ^ V2.vector4_u32[0]; + Result.vector4_u32[1] = V1.vector4_u32[1] ^ V2.vector4_u32[1]; + Result.vector4_u32[2] = V1.vector4_u32[2] ^ V2.vector4_u32[2]; + Result.vector4_u32[3] = V1.vector4_u32[3] ^ V2.vector4_u32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i V = _mm_xor_si128( reinterpret_cast(&V1)[0], reinterpret_cast(&V2)[0] ); + return reinterpret_cast<__m128 *>(&V)[0]; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorNegate +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = -V.vector4_f32[0]; + Result.vector4_f32[1] = -V.vector4_f32[1]; + Result.vector4_f32[2] = -V.vector4_f32[2]; + Result.vector4_f32[3] = -V.vector4_f32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Z; + + Z = _mm_setzero_ps(); + + return _mm_sub_ps( Z, V ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorAdd +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = V1.vector4_f32[0] + V2.vector4_f32[0]; + Result.vector4_f32[1] = V1.vector4_f32[1] + V2.vector4_f32[1]; + Result.vector4_f32[2] = V1.vector4_f32[2] + V2.vector4_f32[2]; + Result.vector4_f32[3] = V1.vector4_f32[3] + V2.vector4_f32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_add_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorAddAngles +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Mask; + XMVECTOR Offset; + XMVECTOR Result; + CONST XMVECTOR Zero = XMVectorZero(); + + // Add the given angles together. If the range of V1 is such + // that -Pi <= V1 < Pi and the range of V2 is such that + // -2Pi <= V2 <= 2Pi, then the range of the resulting angle + // will be -Pi <= Result < Pi. + Result = XMVectorAdd(V1, V2); + + Mask = XMVectorLess(Result, g_XMNegativePi.v); + Offset = XMVectorSelect(Zero, g_XMTwoPi.v, Mask); + + Mask = XMVectorGreaterOrEqual(Result, g_XMPi.v); + Offset = XMVectorSelect(Offset, g_XMNegativeTwoPi.v, Mask); + + Result = XMVectorAdd(Result, Offset); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Adjust the angles + XMVECTOR vResult = _mm_add_ps(V1,V2); + // Less than Pi? + XMVECTOR vOffset = _mm_cmplt_ps(vResult,g_XMNegativePi); + vOffset = _mm_and_ps(vOffset,g_XMTwoPi); + // Add 2Pi to all entries less than -Pi + vResult = _mm_add_ps(vResult,vOffset); + // Greater than or equal to Pi? + vOffset = _mm_cmpge_ps(vResult,g_XMPi); + vOffset = _mm_and_ps(vOffset,g_XMTwoPi); + // Sub 2Pi to all entries greater than Pi + vResult = _mm_sub_ps(vResult,vOffset); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSubtract +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = V1.vector4_f32[0] - V2.vector4_f32[0]; + Result.vector4_f32[1] = V1.vector4_f32[1] - V2.vector4_f32[1]; + Result.vector4_f32[2] = V1.vector4_f32[2] - V2.vector4_f32[2]; + Result.vector4_f32[3] = V1.vector4_f32[3] - V2.vector4_f32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_sub_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSubtractAngles +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Mask; + XMVECTOR Offset; + XMVECTOR Result; + CONST XMVECTOR Zero = XMVectorZero(); + + // Subtract the given angles. If the range of V1 is such + // that -Pi <= V1 < Pi and the range of V2 is such that + // -2Pi <= V2 <= 2Pi, then the range of the resulting angle + // will be -Pi <= Result < Pi. + Result = XMVectorSubtract(V1, V2); + + Mask = XMVectorLess(Result, g_XMNegativePi.v); + Offset = XMVectorSelect(Zero, g_XMTwoPi.v, Mask); + + Mask = XMVectorGreaterOrEqual(Result, g_XMPi.v); + Offset = XMVectorSelect(Offset, g_XMNegativeTwoPi.v, Mask); + + Result = XMVectorAdd(Result, Offset); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Adjust the angles + XMVECTOR vResult = _mm_sub_ps(V1,V2); + // Less than Pi? + XMVECTOR vOffset = _mm_cmplt_ps(vResult,g_XMNegativePi); + vOffset = _mm_and_ps(vOffset,g_XMTwoPi); + // Add 2Pi to all entries less than -Pi + vResult = _mm_add_ps(vResult,vOffset); + // Greater than or equal to Pi? + vOffset = _mm_cmpge_ps(vResult,g_XMPi); + vOffset = _mm_and_ps(vOffset,g_XMTwoPi); + // Sub 2Pi to all entries greater than Pi + vResult = _mm_sub_ps(vResult,vOffset); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMultiply +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Result = { + V1.vector4_f32[0] * V2.vector4_f32[0], + V1.vector4_f32[1] * V2.vector4_f32[1], + V1.vector4_f32[2] * V2.vector4_f32[2], + V1.vector4_f32[3] * V2.vector4_f32[3] + }; + return Result; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_mul_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMultiplyAdd +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR V3 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = { + (V1.vector4_f32[0] * V2.vector4_f32[0]) + V3.vector4_f32[0], + (V1.vector4_f32[1] * V2.vector4_f32[1]) + V3.vector4_f32[1], + (V1.vector4_f32[2] * V2.vector4_f32[2]) + V3.vector4_f32[2], + (V1.vector4_f32[3] * V2.vector4_f32[3]) + V3.vector4_f32[3] + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_mul_ps( V1, V2 ); + return _mm_add_ps(vResult, V3 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorDivide +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Result; + Result.vector4_f32[0] = V1.vector4_f32[0] / V2.vector4_f32[0]; + Result.vector4_f32[1] = V1.vector4_f32[1] / V2.vector4_f32[1]; + Result.vector4_f32[2] = V1.vector4_f32[2] / V2.vector4_f32[2]; + Result.vector4_f32[3] = V1.vector4_f32[3] / V2.vector4_f32[3]; + return Result; +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_div_ps( V1, V2 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorNegativeMultiplySubtract +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR V3 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR vResult = { + V3.vector4_f32[0] - (V1.vector4_f32[0] * V2.vector4_f32[0]), + V3.vector4_f32[1] - (V1.vector4_f32[1] * V2.vector4_f32[1]), + V3.vector4_f32[2] - (V1.vector4_f32[2] * V2.vector4_f32[2]), + V3.vector4_f32[3] - (V1.vector4_f32[3] * V2.vector4_f32[3]) + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR R = _mm_mul_ps( V1, V2 ); + return _mm_sub_ps( V3, R ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorScale +( + FXMVECTOR V, + FLOAT ScaleFactor +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = { + V.vector4_f32[0] * ScaleFactor, + V.vector4_f32[1] * ScaleFactor, + V.vector4_f32[2] * ScaleFactor, + V.vector4_f32[3] * ScaleFactor + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_set_ps1(ScaleFactor); + return _mm_mul_ps(vResult,V); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorReciprocalEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Result; + UINT i; + + // Avoid C4701 + Result.vector4_f32[0] = 0.0f; + + for (i = 0; i < 4; i++) + { + if (XMISNAN(V.vector4_f32[i])) + { + Result.vector4_u32[i] = 0x7FC00000; + } + else if (V.vector4_f32[i] == 0.0f || V.vector4_f32[i] == -0.0f) + { + Result.vector4_u32[i] = 0x7F800000 | (V.vector4_u32[i] & 0x80000000); + } + else + { + Result.vector4_f32[i] = 1.f / V.vector4_f32[i]; + } + } + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_rcp_ps(V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorReciprocal +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + return XMVectorReciprocalEst(V); + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_div_ps(g_XMOne,V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Return an estimated square root +XMFINLINE XMVECTOR XMVectorSqrtEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Select; + + // if (x == +Infinity) sqrt(x) = +Infinity + // if (x == +0.0f) sqrt(x) = +0.0f + // if (x == -0.0f) sqrt(x) = -0.0f + // if (x < 0.0f) sqrt(x) = QNaN + + XMVECTOR Result = XMVectorReciprocalSqrtEst(V); + XMVECTOR Zero = XMVectorZero(); + XMVECTOR VEqualsInfinity = XMVectorEqualInt(V, g_XMInfinity.v); + XMVECTOR VEqualsZero = XMVectorEqual(V, Zero); + Result = XMVectorMultiply(V, Result); + Select = XMVectorEqualInt(VEqualsInfinity, VEqualsZero); + Result = XMVectorSelect(V, Result, Select); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_sqrt_ps(V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSqrt +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Zero; + XMVECTOR VEqualsInfinity, VEqualsZero; + XMVECTOR Select; + XMVECTOR Result; + + // if (x == +Infinity) sqrt(x) = +Infinity + // if (x == +0.0f) sqrt(x) = +0.0f + // if (x == -0.0f) sqrt(x) = -0.0f + // if (x < 0.0f) sqrt(x) = QNaN + + Result = XMVectorReciprocalSqrt(V); + Zero = XMVectorZero(); + VEqualsInfinity = XMVectorEqualInt(V, g_XMInfinity.v); + VEqualsZero = XMVectorEqual(V, Zero); + Result = XMVectorMultiply(V, Result); + Select = XMVectorEqualInt(VEqualsInfinity, VEqualsZero); + Result = XMVectorSelect(V, Result, Select); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_sqrt_ps(V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorReciprocalSqrtEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // if (x == +Infinity) rsqrt(x) = 0 + // if (x == +0.0f) rsqrt(x) = +Infinity + // if (x == -0.0f) rsqrt(x) = -Infinity + // if (x < 0.0f) rsqrt(x) = QNaN + + XMVECTOR Result; + UINT i; + + // Avoid C4701 + Result.vector4_f32[0] = 0.0f; + + for (i = 0; i < 4; i++) + { + if (XMISNAN(V.vector4_f32[i])) + { + Result.vector4_u32[i] = 0x7FC00000; + } + else if (V.vector4_f32[i] == 0.0f || V.vector4_f32[i] == -0.0f) + { + Result.vector4_u32[i] = 0x7F800000 | (V.vector4_u32[i] & 0x80000000); + } + else if (V.vector4_f32[i] < 0.0f) + { + Result.vector4_u32[i] = 0x7FFFFFFF; + } + else if (XMISINF(V.vector4_f32[i])) + { + Result.vector4_f32[i] = 0.0f; + } + else + { + Result.vector4_f32[i] = 1.0f / sqrtf(V.vector4_f32[i]); + } + } + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + return _mm_rsqrt_ps(V); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorReciprocalSqrt +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return XMVectorReciprocalSqrtEst(V); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_sqrt_ps(V); + vResult = _mm_div_ps(g_XMOne,vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorExpEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result.vector4_f32[0] = powf(2.0f, V.vector4_f32[0]); + Result.vector4_f32[1] = powf(2.0f, V.vector4_f32[1]); + Result.vector4_f32[2] = powf(2.0f, V.vector4_f32[2]); + Result.vector4_f32[3] = powf(2.0f, V.vector4_f32[3]); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_setr_ps( + powf(2.0f,XMVectorGetX(V)), + powf(2.0f,XMVectorGetY(V)), + powf(2.0f,XMVectorGetZ(V)), + powf(2.0f,XMVectorGetW(V))); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorExp +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR E, S; + XMVECTOR R, R2, R3, R4; + XMVECTOR V0, V1; + XMVECTOR C0X, C0Y, C0Z, C0W; + XMVECTOR C1X, C1Y, C1Z, C1W; + XMVECTOR Result; + static CONST XMVECTOR C0 = {1.0f, -6.93147182e-1f, 2.40226462e-1f, -5.55036440e-2f}; + static CONST XMVECTOR C1 = {9.61597636e-3f, -1.32823968e-3f, 1.47491097e-4f, -1.08635004e-5f}; + + R = XMVectorFloor(V); + E = XMVectorExpEst(R); + R = XMVectorSubtract(V, R); + R2 = XMVectorMultiply(R, R); + R3 = XMVectorMultiply(R, R2); + R4 = XMVectorMultiply(R2, R2); + + C0X = XMVectorSplatX(C0); + C0Y = XMVectorSplatY(C0); + C0Z = XMVectorSplatZ(C0); + C0W = XMVectorSplatW(C0); + + C1X = XMVectorSplatX(C1); + C1Y = XMVectorSplatY(C1); + C1Z = XMVectorSplatZ(C1); + C1W = XMVectorSplatW(C1); + + V0 = XMVectorMultiplyAdd(R, C0Y, C0X); + V0 = XMVectorMultiplyAdd(R2, C0Z, V0); + V0 = XMVectorMultiplyAdd(R3, C0W, V0); + + V1 = XMVectorMultiplyAdd(R, C1Y, C1X); + V1 = XMVectorMultiplyAdd(R2, C1Z, V1); + V1 = XMVectorMultiplyAdd(R3, C1W, V1); + + S = XMVectorMultiplyAdd(R4, V1, V0); + + S = XMVectorReciprocal(S); + Result = XMVectorMultiply(E, S); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 C0 = {1.0f, -6.93147182e-1f, 2.40226462e-1f, -5.55036440e-2f}; + static CONST XMVECTORF32 C1 = {9.61597636e-3f, -1.32823968e-3f, 1.47491097e-4f, -1.08635004e-5f}; + + // Get the integer of the input + XMVECTOR R = XMVectorFloor(V); + // Get the exponent estimate + XMVECTOR E = XMVectorExpEst(R); + // Get the fractional only + R = _mm_sub_ps(V,R); + // Get R^2 + XMVECTOR R2 = _mm_mul_ps(R,R); + // And R^3 + XMVECTOR R3 = _mm_mul_ps(R,R2); + + XMVECTOR V0 = _mm_load_ps1(&C0.f[1]); + V0 = _mm_mul_ps(V0,R); + XMVECTOR vConstants = _mm_load_ps1(&C0.f[0]); + V0 = _mm_add_ps(V0,vConstants); + vConstants = _mm_load_ps1(&C0.f[2]); + vConstants = _mm_mul_ps(vConstants,R2); + V0 = _mm_add_ps(V0,vConstants); + vConstants = _mm_load_ps1(&C0.f[3]); + vConstants = _mm_mul_ps(vConstants,R3); + V0 = _mm_add_ps(V0,vConstants); + + XMVECTOR V1 = _mm_load_ps1(&C1.f[1]); + V1 = _mm_mul_ps(V1,R); + vConstants = _mm_load_ps1(&C1.f[0]); + V1 = _mm_add_ps(V1,vConstants); + vConstants = _mm_load_ps1(&C1.f[2]); + vConstants = _mm_mul_ps(vConstants,R2); + V1 = _mm_add_ps(V1,vConstants); + vConstants = _mm_load_ps1(&C1.f[3]); + vConstants = _mm_mul_ps(vConstants,R3); + V1 = _mm_add_ps(V1,vConstants); + // R2 = R^4 + R2 = _mm_mul_ps(R2,R2); + R2 = _mm_mul_ps(R2,V1); + R2 = _mm_add_ps(R2,V0); + E = _mm_div_ps(E,R2); + return E; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorLogEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + FLOAT fScale = (1.0f / logf(2.0f)); + XMVECTOR Result; + + Result.vector4_f32[0] = logf(V.vector4_f32[0])*fScale; + Result.vector4_f32[1] = logf(V.vector4_f32[1])*fScale; + Result.vector4_f32[2] = logf(V.vector4_f32[2])*fScale; + Result.vector4_f32[3] = logf(V.vector4_f32[3])*fScale; + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vScale = _mm_set_ps1(1.0f / logf(2.0f)); + XMVECTOR vResult = _mm_setr_ps( + logf(XMVectorGetX(V)), + logf(XMVectorGetY(V)), + logf(XMVectorGetZ(V)), + logf(XMVectorGetW(V))); + vResult = _mm_mul_ps(vResult,vScale); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorLog +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fScale = (1.0f / logf(2.0f)); + XMVECTOR Result; + + Result.vector4_f32[0] = logf(V.vector4_f32[0])*fScale; + Result.vector4_f32[1] = logf(V.vector4_f32[1])*fScale; + Result.vector4_f32[2] = logf(V.vector4_f32[2])*fScale; + Result.vector4_f32[3] = logf(V.vector4_f32[3])*fScale; + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vScale = _mm_set_ps1(1.0f / logf(2.0f)); + XMVECTOR vResult = _mm_setr_ps( + logf(XMVectorGetX(V)), + logf(XMVectorGetY(V)), + logf(XMVectorGetZ(V)), + logf(XMVectorGetW(V))); + vResult = _mm_mul_ps(vResult,vScale); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorPowEst +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = powf(V1.vector4_f32[0], V2.vector4_f32[0]); + Result.vector4_f32[1] = powf(V1.vector4_f32[1], V2.vector4_f32[1]); + Result.vector4_f32[2] = powf(V1.vector4_f32[2], V2.vector4_f32[2]); + Result.vector4_f32[3] = powf(V1.vector4_f32[3], V2.vector4_f32[3]); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_setr_ps( + powf(XMVectorGetX(V1),XMVectorGetX(V2)), + powf(XMVectorGetY(V1),XMVectorGetY(V2)), + powf(XMVectorGetZ(V1),XMVectorGetZ(V2)), + powf(XMVectorGetW(V1),XMVectorGetW(V2))); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorPow +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(_XM_SSE_INTRINSICS_) + + return XMVectorPowEst(V1, V2); + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorAbs +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = { + fabsf(V.vector4_f32[0]), + fabsf(V.vector4_f32[1]), + fabsf(V.vector4_f32[2]), + fabsf(V.vector4_f32[3]) + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_setzero_ps(); + vResult = _mm_sub_ps(vResult,V); + vResult = _mm_max_ps(vResult,V); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorMod +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Reciprocal; + XMVECTOR Quotient; + XMVECTOR Result; + + // V1 % V2 = V1 - V2 * truncate(V1 / V2) + Reciprocal = XMVectorReciprocal(V2); + Quotient = XMVectorMultiply(V1, Reciprocal); + Quotient = XMVectorTruncate(Quotient); + Result = XMVectorNegativeMultiplySubtract(V2, Quotient, V1); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_div_ps(V1, V2); + vResult = XMVectorTruncate(vResult); + vResult = _mm_mul_ps(vResult,V2); + vResult = _mm_sub_ps(V1,vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorModAngles +( + FXMVECTOR Angles +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR Result; + + // Modulo the range of the given angles such that -XM_PI <= Angles < XM_PI + V = XMVectorMultiply(Angles, g_XMReciprocalTwoPi.v); + V = XMVectorRound(V); + Result = XMVectorNegativeMultiplySubtract(g_XMTwoPi.v, V, Angles); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Modulo the range of the given angles such that -XM_PI <= Angles < XM_PI + XMVECTOR vResult = _mm_mul_ps(Angles,g_XMReciprocalTwoPi); + // Use the inline function due to complexity for rounding + vResult = XMVectorRound(vResult); + vResult = _mm_mul_ps(vResult,g_XMTwoPi); + vResult = _mm_sub_ps(Angles,vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorSin +( + FXMVECTOR V +) +{ + +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2, V3, V5, V7, V9, V11, V13, V15, V17, V19, V21, V23; + XMVECTOR S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11; + XMVECTOR Result; + + V1 = XMVectorModAngles(V); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! + V^9 / 9! - V^11 / 11! + V^13 / 13! - + // V^15 / 15! + V^17 / 17! - V^19 / 19! + V^21 / 21! - V^23 / 23! (for -PI <= V < PI) + V2 = XMVectorMultiply(V1, V1); + V3 = XMVectorMultiply(V2, V1); + V5 = XMVectorMultiply(V3, V2); + V7 = XMVectorMultiply(V5, V2); + V9 = XMVectorMultiply(V7, V2); + V11 = XMVectorMultiply(V9, V2); + V13 = XMVectorMultiply(V11, V2); + V15 = XMVectorMultiply(V13, V2); + V17 = XMVectorMultiply(V15, V2); + V19 = XMVectorMultiply(V17, V2); + V21 = XMVectorMultiply(V19, V2); + V23 = XMVectorMultiply(V21, V2); + + S1 = XMVectorSplatY(g_XMSinCoefficients0.v); + S2 = XMVectorSplatZ(g_XMSinCoefficients0.v); + S3 = XMVectorSplatW(g_XMSinCoefficients0.v); + S4 = XMVectorSplatX(g_XMSinCoefficients1.v); + S5 = XMVectorSplatY(g_XMSinCoefficients1.v); + S6 = XMVectorSplatZ(g_XMSinCoefficients1.v); + S7 = XMVectorSplatW(g_XMSinCoefficients1.v); + S8 = XMVectorSplatX(g_XMSinCoefficients2.v); + S9 = XMVectorSplatY(g_XMSinCoefficients2.v); + S10 = XMVectorSplatZ(g_XMSinCoefficients2.v); + S11 = XMVectorSplatW(g_XMSinCoefficients2.v); + + Result = XMVectorMultiplyAdd(S1, V3, V1); + Result = XMVectorMultiplyAdd(S2, V5, Result); + Result = XMVectorMultiplyAdd(S3, V7, Result); + Result = XMVectorMultiplyAdd(S4, V9, Result); + Result = XMVectorMultiplyAdd(S5, V11, Result); + Result = XMVectorMultiplyAdd(S6, V13, Result); + Result = XMVectorMultiplyAdd(S7, V15, Result); + Result = XMVectorMultiplyAdd(S8, V17, Result); + Result = XMVectorMultiplyAdd(S9, V19, Result); + Result = XMVectorMultiplyAdd(S10, V21, Result); + Result = XMVectorMultiplyAdd(S11, V23, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Force the value within the bounds of pi + XMVECTOR vResult = XMVectorModAngles(V); + // Each on is V to the "num" power + // V2 = V1^2 + XMVECTOR V2 = _mm_mul_ps(vResult,vResult); + // V1^3 + XMVECTOR vPower = _mm_mul_ps(vResult,V2); + XMVECTOR vConstants = _mm_load_ps1(&g_XMSinCoefficients0.f[1]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^5 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients0.f[2]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^7 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients0.f[3]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^9 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients1.f[0]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^11 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients1.f[1]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^13 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients1.f[2]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^15 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients1.f[3]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^17 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients2.f[0]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^19 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients2.f[1]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^21 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients2.f[2]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^23 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMSinCoefficients2.f[3]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorCos +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2, V4, V6, V8, V10, V12, V14, V16, V18, V20, V22; + XMVECTOR C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11; + XMVECTOR Result; + + V1 = XMVectorModAngles(V); + + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! + V^8 / 8! - V^10 / 10! + V^12 / 12! - + // V^14 / 14! + V^16 / 16! - V^18 / 18! + V^20 / 20! - V^22 / 22! (for -PI <= V < PI) + V2 = XMVectorMultiply(V1, V1); + V4 = XMVectorMultiply(V2, V2); + V6 = XMVectorMultiply(V4, V2); + V8 = XMVectorMultiply(V4, V4); + V10 = XMVectorMultiply(V6, V4); + V12 = XMVectorMultiply(V6, V6); + V14 = XMVectorMultiply(V8, V6); + V16 = XMVectorMultiply(V8, V8); + V18 = XMVectorMultiply(V10, V8); + V20 = XMVectorMultiply(V10, V10); + V22 = XMVectorMultiply(V12, V10); + + C1 = XMVectorSplatY(g_XMCosCoefficients0.v); + C2 = XMVectorSplatZ(g_XMCosCoefficients0.v); + C3 = XMVectorSplatW(g_XMCosCoefficients0.v); + C4 = XMVectorSplatX(g_XMCosCoefficients1.v); + C5 = XMVectorSplatY(g_XMCosCoefficients1.v); + C6 = XMVectorSplatZ(g_XMCosCoefficients1.v); + C7 = XMVectorSplatW(g_XMCosCoefficients1.v); + C8 = XMVectorSplatX(g_XMCosCoefficients2.v); + C9 = XMVectorSplatY(g_XMCosCoefficients2.v); + C10 = XMVectorSplatZ(g_XMCosCoefficients2.v); + C11 = XMVectorSplatW(g_XMCosCoefficients2.v); + + Result = XMVectorMultiplyAdd(C1, V2, g_XMOne.v); + Result = XMVectorMultiplyAdd(C2, V4, Result); + Result = XMVectorMultiplyAdd(C3, V6, Result); + Result = XMVectorMultiplyAdd(C4, V8, Result); + Result = XMVectorMultiplyAdd(C5, V10, Result); + Result = XMVectorMultiplyAdd(C6, V12, Result); + Result = XMVectorMultiplyAdd(C7, V14, Result); + Result = XMVectorMultiplyAdd(C8, V16, Result); + Result = XMVectorMultiplyAdd(C9, V18, Result); + Result = XMVectorMultiplyAdd(C10, V20, Result); + Result = XMVectorMultiplyAdd(C11, V22, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Force the value within the bounds of pi + XMVECTOR V2 = XMVectorModAngles(V); + // Each on is V to the "num" power + // V2 = V1^2 + V2 = _mm_mul_ps(V2,V2); + // V^2 + XMVECTOR vConstants = _mm_load_ps1(&g_XMCosCoefficients0.f[1]); + vConstants = _mm_mul_ps(vConstants,V2); + XMVECTOR vResult = _mm_add_ps(vConstants,g_XMOne); + + // V^4 + XMVECTOR vPower = _mm_mul_ps(V2,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients0.f[2]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^6 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients0.f[3]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^8 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients1.f[0]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^10 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients1.f[1]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^12 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients1.f[2]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^14 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients1.f[3]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^16 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients2.f[0]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^18 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients2.f[1]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^20 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients2.f[2]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + + // V^22 + vPower = _mm_mul_ps(vPower,V2); + vConstants = _mm_load_ps1(&g_XMCosCoefficients2.f[3]); + vConstants = _mm_mul_ps(vConstants,vPower); + vResult = _mm_add_ps(vResult,vConstants); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE VOID XMVectorSinCos +( + XMVECTOR* pSin, + XMVECTOR* pCos, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13; + XMVECTOR V14, V15, V16, V17, V18, V19, V20, V21, V22, V23; + XMVECTOR S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11; + XMVECTOR C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11; + XMVECTOR Sin, Cos; + + XMASSERT(pSin); + XMASSERT(pCos); + + V1 = XMVectorModAngles(V); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! + V^9 / 9! - V^11 / 11! + V^13 / 13! - + // V^15 / 15! + V^17 / 17! - V^19 / 19! + V^21 / 21! - V^23 / 23! (for -PI <= V < PI) + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! + V^8 / 8! - V^10 / 10! + V^12 / 12! - + // V^14 / 14! + V^16 / 16! - V^18 / 18! + V^20 / 20! - V^22 / 22! (for -PI <= V < PI) + + V2 = XMVectorMultiply(V1, V1); + V3 = XMVectorMultiply(V2, V1); + V4 = XMVectorMultiply(V2, V2); + V5 = XMVectorMultiply(V3, V2); + V6 = XMVectorMultiply(V3, V3); + V7 = XMVectorMultiply(V4, V3); + V8 = XMVectorMultiply(V4, V4); + V9 = XMVectorMultiply(V5, V4); + V10 = XMVectorMultiply(V5, V5); + V11 = XMVectorMultiply(V6, V5); + V12 = XMVectorMultiply(V6, V6); + V13 = XMVectorMultiply(V7, V6); + V14 = XMVectorMultiply(V7, V7); + V15 = XMVectorMultiply(V8, V7); + V16 = XMVectorMultiply(V8, V8); + V17 = XMVectorMultiply(V9, V8); + V18 = XMVectorMultiply(V9, V9); + V19 = XMVectorMultiply(V10, V9); + V20 = XMVectorMultiply(V10, V10); + V21 = XMVectorMultiply(V11, V10); + V22 = XMVectorMultiply(V11, V11); + V23 = XMVectorMultiply(V12, V11); + + S1 = XMVectorSplatY(g_XMSinCoefficients0.v); + S2 = XMVectorSplatZ(g_XMSinCoefficients0.v); + S3 = XMVectorSplatW(g_XMSinCoefficients0.v); + S4 = XMVectorSplatX(g_XMSinCoefficients1.v); + S5 = XMVectorSplatY(g_XMSinCoefficients1.v); + S6 = XMVectorSplatZ(g_XMSinCoefficients1.v); + S7 = XMVectorSplatW(g_XMSinCoefficients1.v); + S8 = XMVectorSplatX(g_XMSinCoefficients2.v); + S9 = XMVectorSplatY(g_XMSinCoefficients2.v); + S10 = XMVectorSplatZ(g_XMSinCoefficients2.v); + S11 = XMVectorSplatW(g_XMSinCoefficients2.v); + + C1 = XMVectorSplatY(g_XMCosCoefficients0.v); + C2 = XMVectorSplatZ(g_XMCosCoefficients0.v); + C3 = XMVectorSplatW(g_XMCosCoefficients0.v); + C4 = XMVectorSplatX(g_XMCosCoefficients1.v); + C5 = XMVectorSplatY(g_XMCosCoefficients1.v); + C6 = XMVectorSplatZ(g_XMCosCoefficients1.v); + C7 = XMVectorSplatW(g_XMCosCoefficients1.v); + C8 = XMVectorSplatX(g_XMCosCoefficients2.v); + C9 = XMVectorSplatY(g_XMCosCoefficients2.v); + C10 = XMVectorSplatZ(g_XMCosCoefficients2.v); + C11 = XMVectorSplatW(g_XMCosCoefficients2.v); + + Sin = XMVectorMultiplyAdd(S1, V3, V1); + Sin = XMVectorMultiplyAdd(S2, V5, Sin); + Sin = XMVectorMultiplyAdd(S3, V7, Sin); + Sin = XMVectorMultiplyAdd(S4, V9, Sin); + Sin = XMVectorMultiplyAdd(S5, V11, Sin); + Sin = XMVectorMultiplyAdd(S6, V13, Sin); + Sin = XMVectorMultiplyAdd(S7, V15, Sin); + Sin = XMVectorMultiplyAdd(S8, V17, Sin); + Sin = XMVectorMultiplyAdd(S9, V19, Sin); + Sin = XMVectorMultiplyAdd(S10, V21, Sin); + Sin = XMVectorMultiplyAdd(S11, V23, Sin); + + Cos = XMVectorMultiplyAdd(C1, V2, g_XMOne.v); + Cos = XMVectorMultiplyAdd(C2, V4, Cos); + Cos = XMVectorMultiplyAdd(C3, V6, Cos); + Cos = XMVectorMultiplyAdd(C4, V8, Cos); + Cos = XMVectorMultiplyAdd(C5, V10, Cos); + Cos = XMVectorMultiplyAdd(C6, V12, Cos); + Cos = XMVectorMultiplyAdd(C7, V14, Cos); + Cos = XMVectorMultiplyAdd(C8, V16, Cos); + Cos = XMVectorMultiplyAdd(C9, V18, Cos); + Cos = XMVectorMultiplyAdd(C10, V20, Cos); + Cos = XMVectorMultiplyAdd(C11, V22, Cos); + + *pSin = Sin; + *pCos = Cos; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSin); + XMASSERT(pCos); + XMVECTOR V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13; + XMVECTOR V14, V15, V16, V17, V18, V19, V20, V21, V22, V23; + XMVECTOR S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11; + XMVECTOR C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11; + XMVECTOR Sin, Cos; + + V1 = XMVectorModAngles(V); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! + V^9 / 9! - V^11 / 11! + V^13 / 13! - + // V^15 / 15! + V^17 / 17! - V^19 / 19! + V^21 / 21! - V^23 / 23! (for -PI <= V < PI) + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! + V^8 / 8! - V^10 / 10! + V^12 / 12! - + // V^14 / 14! + V^16 / 16! - V^18 / 18! + V^20 / 20! - V^22 / 22! (for -PI <= V < PI) + + V2 = XMVectorMultiply(V1, V1); + V3 = XMVectorMultiply(V2, V1); + V4 = XMVectorMultiply(V2, V2); + V5 = XMVectorMultiply(V3, V2); + V6 = XMVectorMultiply(V3, V3); + V7 = XMVectorMultiply(V4, V3); + V8 = XMVectorMultiply(V4, V4); + V9 = XMVectorMultiply(V5, V4); + V10 = XMVectorMultiply(V5, V5); + V11 = XMVectorMultiply(V6, V5); + V12 = XMVectorMultiply(V6, V6); + V13 = XMVectorMultiply(V7, V6); + V14 = XMVectorMultiply(V7, V7); + V15 = XMVectorMultiply(V8, V7); + V16 = XMVectorMultiply(V8, V8); + V17 = XMVectorMultiply(V9, V8); + V18 = XMVectorMultiply(V9, V9); + V19 = XMVectorMultiply(V10, V9); + V20 = XMVectorMultiply(V10, V10); + V21 = XMVectorMultiply(V11, V10); + V22 = XMVectorMultiply(V11, V11); + V23 = XMVectorMultiply(V12, V11); + + S1 = _mm_load_ps1(&g_XMSinCoefficients0.f[1]); + S2 = _mm_load_ps1(&g_XMSinCoefficients0.f[2]); + S3 = _mm_load_ps1(&g_XMSinCoefficients0.f[3]); + S4 = _mm_load_ps1(&g_XMSinCoefficients1.f[0]); + S5 = _mm_load_ps1(&g_XMSinCoefficients1.f[1]); + S6 = _mm_load_ps1(&g_XMSinCoefficients1.f[2]); + S7 = _mm_load_ps1(&g_XMSinCoefficients1.f[3]); + S8 = _mm_load_ps1(&g_XMSinCoefficients2.f[0]); + S9 = _mm_load_ps1(&g_XMSinCoefficients2.f[1]); + S10 = _mm_load_ps1(&g_XMSinCoefficients2.f[2]); + S11 = _mm_load_ps1(&g_XMSinCoefficients2.f[3]); + + C1 = _mm_load_ps1(&g_XMCosCoefficients0.f[1]); + C2 = _mm_load_ps1(&g_XMCosCoefficients0.f[2]); + C3 = _mm_load_ps1(&g_XMCosCoefficients0.f[3]); + C4 = _mm_load_ps1(&g_XMCosCoefficients1.f[0]); + C5 = _mm_load_ps1(&g_XMCosCoefficients1.f[1]); + C6 = _mm_load_ps1(&g_XMCosCoefficients1.f[2]); + C7 = _mm_load_ps1(&g_XMCosCoefficients1.f[3]); + C8 = _mm_load_ps1(&g_XMCosCoefficients2.f[0]); + C9 = _mm_load_ps1(&g_XMCosCoefficients2.f[1]); + C10 = _mm_load_ps1(&g_XMCosCoefficients2.f[2]); + C11 = _mm_load_ps1(&g_XMCosCoefficients2.f[3]); + + S1 = _mm_mul_ps(S1,V3); + Sin = _mm_add_ps(S1,V1); + Sin = XMVectorMultiplyAdd(S2, V5, Sin); + Sin = XMVectorMultiplyAdd(S3, V7, Sin); + Sin = XMVectorMultiplyAdd(S4, V9, Sin); + Sin = XMVectorMultiplyAdd(S5, V11, Sin); + Sin = XMVectorMultiplyAdd(S6, V13, Sin); + Sin = XMVectorMultiplyAdd(S7, V15, Sin); + Sin = XMVectorMultiplyAdd(S8, V17, Sin); + Sin = XMVectorMultiplyAdd(S9, V19, Sin); + Sin = XMVectorMultiplyAdd(S10, V21, Sin); + Sin = XMVectorMultiplyAdd(S11, V23, Sin); + + Cos = _mm_mul_ps(C1,V2); + Cos = _mm_add_ps(Cos,g_XMOne); + Cos = XMVectorMultiplyAdd(C2, V4, Cos); + Cos = XMVectorMultiplyAdd(C3, V6, Cos); + Cos = XMVectorMultiplyAdd(C4, V8, Cos); + Cos = XMVectorMultiplyAdd(C5, V10, Cos); + Cos = XMVectorMultiplyAdd(C6, V12, Cos); + Cos = XMVectorMultiplyAdd(C7, V14, Cos); + Cos = XMVectorMultiplyAdd(C8, V16, Cos); + Cos = XMVectorMultiplyAdd(C9, V18, Cos); + Cos = XMVectorMultiplyAdd(C10, V20, Cos); + Cos = XMVectorMultiplyAdd(C11, V22, Cos); + + *pSin = Sin; + *pCos = Cos; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorTan +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // Cody and Waite algorithm to compute tangent. + + XMVECTOR VA, VB, VC, VC2; + XMVECTOR T0, T1, T2, T3, T4, T5, T6, T7; + XMVECTOR C0, C1, TwoDivPi, Epsilon; + XMVECTOR N, D; + XMVECTOR R0, R1; + XMVECTOR VIsZero, VCNearZero, VBIsEven; + XMVECTOR Zero; + XMVECTOR Result; + UINT i; + static CONST XMVECTOR TanCoefficients0 = {1.0f, -4.667168334e-1f, 2.566383229e-2f, -3.118153191e-4f}; + static CONST XMVECTOR TanCoefficients1 = {4.981943399e-7f, -1.333835001e-1f, 3.424887824e-3f, -1.786170734e-5f}; + static CONST XMVECTOR TanConstants = {1.570796371f, 6.077100628e-11f, 0.000244140625f, 2.0f / XM_PI}; + static CONST XMVECTORU32 Mask = {0x1, 0x1, 0x1, 0x1}; + + TwoDivPi = XMVectorSplatW(TanConstants); + + Zero = XMVectorZero(); + + C0 = XMVectorSplatX(TanConstants); + C1 = XMVectorSplatY(TanConstants); + Epsilon = XMVectorSplatZ(TanConstants); + + VA = XMVectorMultiply(V, TwoDivPi); + + VA = XMVectorRound(VA); + + VC = XMVectorNegativeMultiplySubtract(VA, C0, V); + + VB = XMVectorAbs(VA); + + VC = XMVectorNegativeMultiplySubtract(VA, C1, VC); + + for (i = 0; i < 4; i++) + { + VB.vector4_u32[i] = (UINT)VB.vector4_f32[i]; + } + + VC2 = XMVectorMultiply(VC, VC); + + T7 = XMVectorSplatW(TanCoefficients1); + T6 = XMVectorSplatZ(TanCoefficients1); + T4 = XMVectorSplatX(TanCoefficients1); + T3 = XMVectorSplatW(TanCoefficients0); + T5 = XMVectorSplatY(TanCoefficients1); + T2 = XMVectorSplatZ(TanCoefficients0); + T1 = XMVectorSplatY(TanCoefficients0); + T0 = XMVectorSplatX(TanCoefficients0); + + VBIsEven = XMVectorAndInt(VB, Mask.v); + VBIsEven = XMVectorEqualInt(VBIsEven, Zero); + + N = XMVectorMultiplyAdd(VC2, T7, T6); + D = XMVectorMultiplyAdd(VC2, T4, T3); + N = XMVectorMultiplyAdd(VC2, N, T5); + D = XMVectorMultiplyAdd(VC2, D, T2); + N = XMVectorMultiply(VC2, N); + D = XMVectorMultiplyAdd(VC2, D, T1); + N = XMVectorMultiplyAdd(VC, N, VC); + VCNearZero = XMVectorInBounds(VC, Epsilon); + D = XMVectorMultiplyAdd(VC2, D, T0); + + N = XMVectorSelect(N, VC, VCNearZero); + D = XMVectorSelect(D, g_XMOne.v, VCNearZero); + + R0 = XMVectorNegate(N); + R1 = XMVectorReciprocal(D); + R0 = XMVectorReciprocal(R0); + R1 = XMVectorMultiply(N, R1); + R0 = XMVectorMultiply(D, R0); + + VIsZero = XMVectorEqual(V, Zero); + + Result = XMVectorSelect(R0, R1, VBIsEven); + + Result = XMVectorSelect(Result, Zero, VIsZero); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Cody and Waite algorithm to compute tangent. + + XMVECTOR VA, VB, VC, VC2; + XMVECTOR T0, T1, T2, T3, T4, T5, T6, T7; + XMVECTOR C0, C1, TwoDivPi, Epsilon; + XMVECTOR N, D; + XMVECTOR R0, R1; + XMVECTOR VIsZero, VCNearZero, VBIsEven; + XMVECTOR Zero; + XMVECTOR Result; + static CONST XMVECTORF32 TanCoefficients0 = {1.0f, -4.667168334e-1f, 2.566383229e-2f, -3.118153191e-4f}; + static CONST XMVECTORF32 TanCoefficients1 = {4.981943399e-7f, -1.333835001e-1f, 3.424887824e-3f, -1.786170734e-5f}; + static CONST XMVECTORF32 TanConstants = {1.570796371f, 6.077100628e-11f, 0.000244140625f, 2.0f / XM_PI}; + static CONST XMVECTORI32 Mask = {0x1, 0x1, 0x1, 0x1}; + + TwoDivPi = XMVectorSplatW(TanConstants); + + Zero = XMVectorZero(); + + C0 = XMVectorSplatX(TanConstants); + C1 = XMVectorSplatY(TanConstants); + Epsilon = XMVectorSplatZ(TanConstants); + + VA = XMVectorMultiply(V, TwoDivPi); + + VA = XMVectorRound(VA); + + VC = XMVectorNegativeMultiplySubtract(VA, C0, V); + + VB = XMVectorAbs(VA); + + VC = XMVectorNegativeMultiplySubtract(VA, C1, VC); + + reinterpret_cast<__m128i *>(&VB)[0] = _mm_cvttps_epi32(VB); + + VC2 = XMVectorMultiply(VC, VC); + + T7 = XMVectorSplatW(TanCoefficients1); + T6 = XMVectorSplatZ(TanCoefficients1); + T4 = XMVectorSplatX(TanCoefficients1); + T3 = XMVectorSplatW(TanCoefficients0); + T5 = XMVectorSplatY(TanCoefficients1); + T2 = XMVectorSplatZ(TanCoefficients0); + T1 = XMVectorSplatY(TanCoefficients0); + T0 = XMVectorSplatX(TanCoefficients0); + + VBIsEven = XMVectorAndInt(VB,Mask); + VBIsEven = XMVectorEqualInt(VBIsEven, Zero); + + N = XMVectorMultiplyAdd(VC2, T7, T6); + D = XMVectorMultiplyAdd(VC2, T4, T3); + N = XMVectorMultiplyAdd(VC2, N, T5); + D = XMVectorMultiplyAdd(VC2, D, T2); + N = XMVectorMultiply(VC2, N); + D = XMVectorMultiplyAdd(VC2, D, T1); + N = XMVectorMultiplyAdd(VC, N, VC); + VCNearZero = XMVectorInBounds(VC, Epsilon); + D = XMVectorMultiplyAdd(VC2, D, T0); + + N = XMVectorSelect(N, VC, VCNearZero); + D = XMVectorSelect(D, g_XMOne, VCNearZero); + R0 = XMVectorNegate(N); + R1 = _mm_div_ps(N,D); + R0 = _mm_div_ps(D,R0); + VIsZero = XMVectorEqual(V, Zero); + Result = XMVectorSelect(R0, R1, VBIsEven); + Result = XMVectorSelect(Result, Zero, VIsZero); + + return Result; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorSinH +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = XMVectorMultiplyAdd(V, Scale.v, g_XMNegativeOne.v); + V2 = XMVectorNegativeMultiplySubtract(V, Scale.v, g_XMNegativeOne.v); + + E1 = XMVectorExp(V1); + E2 = XMVectorExp(V2); + + Result = XMVectorSubtract(E1, E2); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = _mm_mul_ps(V, Scale); + V1 = _mm_add_ps(V1,g_XMNegativeOne); + V2 = _mm_mul_ps(V, Scale); + V2 = _mm_sub_ps(g_XMNegativeOne,V2); + E1 = XMVectorExp(V1); + E2 = XMVectorExp(V2); + + Result = _mm_sub_ps(E1, E2); + + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorCosH +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTOR Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = XMVectorMultiplyAdd(V, Scale, g_XMNegativeOne.v); + V2 = XMVectorNegativeMultiplySubtract(V, Scale, g_XMNegativeOne.v); + + E1 = XMVectorExp(V1); + E2 = XMVectorExp(V2); + + Result = XMVectorAdd(E1, E2); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = _mm_mul_ps(V,Scale); + V1 = _mm_add_ps(V1,g_XMNegativeOne); + V2 = _mm_mul_ps(V, Scale); + V2 = _mm_sub_ps(g_XMNegativeOne,V2); + E1 = XMVectorExp(V1); + E2 = XMVectorExp(V2); + Result = _mm_add_ps(E1, E2); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorTanH +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR E; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f}; // 2.0f / ln(2.0f) + + E = XMVectorMultiply(V, Scale.v); + E = XMVectorExp(E); + E = XMVectorMultiplyAdd(E, g_XMOneHalf.v, g_XMOneHalf.v); + E = XMVectorReciprocal(E); + + Result = XMVectorSubtract(g_XMOne.v, E); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 Scale = {2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f}; // 2.0f / ln(2.0f) + + XMVECTOR E = _mm_mul_ps(V, Scale); + E = XMVectorExp(E); + E = _mm_mul_ps(E,g_XMOneHalf); + E = _mm_add_ps(E,g_XMOneHalf); + E = XMVectorReciprocal(E); + E = _mm_sub_ps(g_XMOne, E); + return E; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorASin +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V2, V3, AbsV; + XMVECTOR C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11; + XMVECTOR R0, R1, R2, R3, R4; + XMVECTOR OneMinusAbsV; + XMVECTOR Rsq; + XMVECTOR Result; + static CONST XMVECTOR OnePlusEpsilon = {1.00000011921f, 1.00000011921f, 1.00000011921f, 1.00000011921f}; + + // asin(V) = V * (C0 + C1 * V + C2 * V^2 + C3 * V^3 + C4 * V^4 + C5 * V^5) + (1 - V) * rsq(1 - V) * + // V * (C6 + C7 * V + C8 * V^2 + C9 * V^3 + C10 * V^4 + C11 * V^5) + + AbsV = XMVectorAbs(V); + + V2 = XMVectorMultiply(V, V); + V3 = XMVectorMultiply(V2, AbsV); + + R4 = XMVectorNegativeMultiplySubtract(AbsV, V, V); + + OneMinusAbsV = XMVectorSubtract(OnePlusEpsilon, AbsV); + Rsq = XMVectorReciprocalSqrt(OneMinusAbsV); + + C0 = XMVectorSplatX(g_XMASinCoefficients0.v); + C1 = XMVectorSplatY(g_XMASinCoefficients0.v); + C2 = XMVectorSplatZ(g_XMASinCoefficients0.v); + C3 = XMVectorSplatW(g_XMASinCoefficients0.v); + + C4 = XMVectorSplatX(g_XMASinCoefficients1.v); + C5 = XMVectorSplatY(g_XMASinCoefficients1.v); + C6 = XMVectorSplatZ(g_XMASinCoefficients1.v); + C7 = XMVectorSplatW(g_XMASinCoefficients1.v); + + C8 = XMVectorSplatX(g_XMASinCoefficients2.v); + C9 = XMVectorSplatY(g_XMASinCoefficients2.v); + C10 = XMVectorSplatZ(g_XMASinCoefficients2.v); + C11 = XMVectorSplatW(g_XMASinCoefficients2.v); + + R0 = XMVectorMultiplyAdd(C3, AbsV, C7); + R1 = XMVectorMultiplyAdd(C1, AbsV, C5); + R2 = XMVectorMultiplyAdd(C2, AbsV, C6); + R3 = XMVectorMultiplyAdd(C0, AbsV, C4); + + R0 = XMVectorMultiplyAdd(R0, AbsV, C11); + R1 = XMVectorMultiplyAdd(R1, AbsV, C9); + R2 = XMVectorMultiplyAdd(R2, AbsV, C10); + R3 = XMVectorMultiplyAdd(R3, AbsV, C8); + + R0 = XMVectorMultiplyAdd(R2, V3, R0); + R1 = XMVectorMultiplyAdd(R3, V3, R1); + + R0 = XMVectorMultiply(V, R0); + R1 = XMVectorMultiply(R4, R1); + + Result = XMVectorMultiplyAdd(R1, Rsq, R0); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 OnePlusEpsilon = {1.00000011921f, 1.00000011921f, 1.00000011921f, 1.00000011921f}; + + // asin(V) = V * (C0 + C1 * V + C2 * V^2 + C3 * V^3 + C4 * V^4 + C5 * V^5) + (1 - V) * rsq(1 - V) * + // V * (C6 + C7 * V + C8 * V^2 + C9 * V^3 + C10 * V^4 + C11 * V^5) + // Get abs(V) + XMVECTOR vAbsV = _mm_setzero_ps(); + vAbsV = _mm_sub_ps(vAbsV,V); + vAbsV = _mm_max_ps(vAbsV,V); + + XMVECTOR R0 = vAbsV; + XMVECTOR vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[3]); + R0 = _mm_mul_ps(R0,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[3]); + R0 = _mm_add_ps(R0,vConstants); + + XMVECTOR R1 = vAbsV; + vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[1]); + R1 = _mm_mul_ps(R1,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[1]); + R1 = _mm_add_ps(R1, vConstants); + + XMVECTOR R2 = vAbsV; + vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[2]); + R2 = _mm_mul_ps(R2,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[2]); + R2 = _mm_add_ps(R2, vConstants); + + XMVECTOR R3 = vAbsV; + vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[0]); + R3 = _mm_mul_ps(R3,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[0]); + R3 = _mm_add_ps(R3, vConstants); + + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[3]); + R0 = _mm_mul_ps(R0,vAbsV); + R0 = _mm_add_ps(R0,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[1]); + R1 = _mm_mul_ps(R1,vAbsV); + R1 = _mm_add_ps(R1,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[2]); + R2 = _mm_mul_ps(R2,vAbsV); + R2 = _mm_add_ps(R2,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[0]); + R3 = _mm_mul_ps(R3,vAbsV); + R3 = _mm_add_ps(R3,vConstants); + + // V3 = V^3 + vConstants = _mm_mul_ps(V,V); + vConstants = _mm_mul_ps(vConstants, vAbsV); + // Mul by V^3 + R2 = _mm_mul_ps(R2,vConstants); + R3 = _mm_mul_ps(R3,vConstants); + // Merge the results + R0 = _mm_add_ps(R0,R2); + R1 = _mm_add_ps(R1,R3); + + R0 = _mm_mul_ps(R0,V); + // vConstants = V-(V^2 retaining sign) + vConstants = _mm_mul_ps(vAbsV, V); + vConstants = _mm_sub_ps(V,vConstants); + R1 = _mm_mul_ps(R1,vConstants); + vConstants = _mm_sub_ps(OnePlusEpsilon,vAbsV); + // Do NOT use rsqrt/mul. This needs the precision + vConstants = _mm_sqrt_ps(vConstants); + R1 = _mm_div_ps(R1,vConstants); + R0 = _mm_add_ps(R0,R1); + return R0; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorACos +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V2, V3, AbsV; + XMVECTOR C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11; + XMVECTOR R0, R1, R2, R3, R4; + XMVECTOR OneMinusAbsV; + XMVECTOR Rsq; + XMVECTOR Result; + static CONST XMVECTOR OnePlusEpsilon = {1.00000011921f, 1.00000011921f, 1.00000011921f, 1.00000011921f}; + + // acos(V) = PI / 2 - asin(V) + + AbsV = XMVectorAbs(V); + + V2 = XMVectorMultiply(V, V); + V3 = XMVectorMultiply(V2, AbsV); + + R4 = XMVectorNegativeMultiplySubtract(AbsV, V, V); + + OneMinusAbsV = XMVectorSubtract(OnePlusEpsilon, AbsV); + Rsq = XMVectorReciprocalSqrt(OneMinusAbsV); + + C0 = XMVectorSplatX(g_XMASinCoefficients0.v); + C1 = XMVectorSplatY(g_XMASinCoefficients0.v); + C2 = XMVectorSplatZ(g_XMASinCoefficients0.v); + C3 = XMVectorSplatW(g_XMASinCoefficients0.v); + + C4 = XMVectorSplatX(g_XMASinCoefficients1.v); + C5 = XMVectorSplatY(g_XMASinCoefficients1.v); + C6 = XMVectorSplatZ(g_XMASinCoefficients1.v); + C7 = XMVectorSplatW(g_XMASinCoefficients1.v); + + C8 = XMVectorSplatX(g_XMASinCoefficients2.v); + C9 = XMVectorSplatY(g_XMASinCoefficients2.v); + C10 = XMVectorSplatZ(g_XMASinCoefficients2.v); + C11 = XMVectorSplatW(g_XMASinCoefficients2.v); + + R0 = XMVectorMultiplyAdd(C3, AbsV, C7); + R1 = XMVectorMultiplyAdd(C1, AbsV, C5); + R2 = XMVectorMultiplyAdd(C2, AbsV, C6); + R3 = XMVectorMultiplyAdd(C0, AbsV, C4); + + R0 = XMVectorMultiplyAdd(R0, AbsV, C11); + R1 = XMVectorMultiplyAdd(R1, AbsV, C9); + R2 = XMVectorMultiplyAdd(R2, AbsV, C10); + R3 = XMVectorMultiplyAdd(R3, AbsV, C8); + + R0 = XMVectorMultiplyAdd(R2, V3, R0); + R1 = XMVectorMultiplyAdd(R3, V3, R1); + + R0 = XMVectorMultiply(V, R0); + R1 = XMVectorMultiply(R4, R1); + + Result = XMVectorMultiplyAdd(R1, Rsq, R0); + + Result = XMVectorSubtract(g_XMHalfPi.v, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 OnePlusEpsilon = {1.00000011921f, 1.00000011921f, 1.00000011921f, 1.00000011921f}; + // Uses only 6 registers for good code on x86 targets + // acos(V) = PI / 2 - asin(V) + // Get abs(V) + XMVECTOR vAbsV = _mm_setzero_ps(); + vAbsV = _mm_sub_ps(vAbsV,V); + vAbsV = _mm_max_ps(vAbsV,V); + // Perform the series in precision groups to + // retain precision across 20 bits. (3 bits of imprecision due to operations) + XMVECTOR R0 = vAbsV; + XMVECTOR vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[3]); + R0 = _mm_mul_ps(R0,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[3]); + R0 = _mm_add_ps(R0,vConstants); + R0 = _mm_mul_ps(R0,vAbsV); + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[3]); + R0 = _mm_add_ps(R0,vConstants); + + XMVECTOR R1 = vAbsV; + vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[1]); + R1 = _mm_mul_ps(R1,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[1]); + R1 = _mm_add_ps(R1,vConstants); + R1 = _mm_mul_ps(R1, vAbsV); + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[1]); + R1 = _mm_add_ps(R1,vConstants); + + XMVECTOR R2 = vAbsV; + vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[2]); + R2 = _mm_mul_ps(R2,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[2]); + R2 = _mm_add_ps(R2,vConstants); + R2 = _mm_mul_ps(R2, vAbsV); + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[2]); + R2 = _mm_add_ps(R2,vConstants); + + XMVECTOR R3 = vAbsV; + vConstants = _mm_load_ps1(&g_XMASinCoefficients0.f[0]); + R3 = _mm_mul_ps(R3,vConstants); + vConstants = _mm_load_ps1(&g_XMASinCoefficients1.f[0]); + R3 = _mm_add_ps(R3,vConstants); + R3 = _mm_mul_ps(R3, vAbsV); + vConstants = _mm_load_ps1(&g_XMASinCoefficients2.f[0]); + R3 = _mm_add_ps(R3,vConstants); + + // vConstants = V^3 + vConstants = _mm_mul_ps(V,V); + vConstants = _mm_mul_ps(vConstants,vAbsV); + R2 = _mm_mul_ps(R2,vConstants); + R3 = _mm_mul_ps(R3,vConstants); + // Add the pair of values together here to retain + // as much precision as possible + R0 = _mm_add_ps(R0,R2); + R1 = _mm_add_ps(R1,R3); + + R0 = _mm_mul_ps(R0,V); + // vConstants = V-(V*abs(V)) + vConstants = _mm_mul_ps(V,vAbsV); + vConstants = _mm_sub_ps(V,vConstants); + R1 = _mm_mul_ps(R1,vConstants); + // Episilon exists to allow 1.0 as an answer + vConstants = _mm_sub_ps(OnePlusEpsilon, vAbsV); + // Use sqrt instead of rsqrt for precision + vConstants = _mm_sqrt_ps(vConstants); + R1 = _mm_div_ps(R1,vConstants); + R1 = _mm_add_ps(R1,R0); + vConstants = _mm_sub_ps(g_XMHalfPi,R1); + return vConstants; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorATan +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // Cody and Waite algorithm to compute inverse tangent. + + XMVECTOR N, D; + XMVECTOR VF, G, ReciprocalF, AbsF, FA, FB; + XMVECTOR Sqrt3, Sqrt3MinusOne, TwoMinusSqrt3; + XMVECTOR HalfPi, OneThirdPi, OneSixthPi, Epsilon, MinV, MaxV; + XMVECTOR Zero; + XMVECTOR NegativeHalfPi; + XMVECTOR Angle1, Angle2; + XMVECTOR F_GT_One, F_GT_TwoMinusSqrt3, AbsF_LT_Epsilon, V_LT_Zero, V_GT_MaxV, V_LT_MinV; + XMVECTOR NegativeResult, Result; + XMVECTOR P0, P1, P2, P3, Q0, Q1, Q2, Q3; + static CONST XMVECTOR ATanConstants0 = {-1.3688768894e+1f, -2.0505855195e+1f, -8.4946240351f, -8.3758299368e-1f}; + static CONST XMVECTOR ATanConstants1 = {4.1066306682e+1f, 8.6157349597e+1f, 5.9578436142e+1f, 1.5024001160e+1f}; + static CONST XMVECTOR ATanConstants2 = {1.732050808f, 7.320508076e-1f, 2.679491924e-1f, 0.000244140625f}; // + static CONST XMVECTOR ATanConstants3 = {XM_PIDIV2, XM_PI / 3.0f, XM_PI / 6.0f, 8.507059173e+37f}; // + + Zero = XMVectorZero(); + + P0 = XMVectorSplatX(ATanConstants0); + P1 = XMVectorSplatY(ATanConstants0); + P2 = XMVectorSplatZ(ATanConstants0); + P3 = XMVectorSplatW(ATanConstants0); + + Q0 = XMVectorSplatX(ATanConstants1); + Q1 = XMVectorSplatY(ATanConstants1); + Q2 = XMVectorSplatZ(ATanConstants1); + Q3 = XMVectorSplatW(ATanConstants1); + + Sqrt3 = XMVectorSplatX(ATanConstants2); + Sqrt3MinusOne = XMVectorSplatY(ATanConstants2); + TwoMinusSqrt3 = XMVectorSplatZ(ATanConstants2); + Epsilon = XMVectorSplatW(ATanConstants2); + + HalfPi = XMVectorSplatX(ATanConstants3); + OneThirdPi = XMVectorSplatY(ATanConstants3); + OneSixthPi = XMVectorSplatZ(ATanConstants3); + MaxV = XMVectorSplatW(ATanConstants3); + + VF = XMVectorAbs(V); + ReciprocalF = XMVectorReciprocal(VF); + + F_GT_One = XMVectorGreater(VF, g_XMOne.v); + + VF = XMVectorSelect(VF, ReciprocalF, F_GT_One); + Angle1 = XMVectorSelect(Zero, HalfPi, F_GT_One); + Angle2 = XMVectorSelect(OneSixthPi, OneThirdPi, F_GT_One); + + F_GT_TwoMinusSqrt3 = XMVectorGreater(VF, TwoMinusSqrt3); + + FA = XMVectorMultiplyAdd(Sqrt3MinusOne, VF, VF); + FA = XMVectorAdd(FA, g_XMNegativeOne.v); + FB = XMVectorAdd(VF, Sqrt3); + FB = XMVectorReciprocal(FB); + FA = XMVectorMultiply(FA, FB); + + VF = XMVectorSelect(VF, FA, F_GT_TwoMinusSqrt3); + Angle1 = XMVectorSelect(Angle1, Angle2, F_GT_TwoMinusSqrt3); + + AbsF = XMVectorAbs(VF); + AbsF_LT_Epsilon = XMVectorLess(AbsF, Epsilon); + + G = XMVectorMultiply(VF, VF); + + D = XMVectorAdd(G, Q3); + D = XMVectorMultiplyAdd(D, G, Q2); + D = XMVectorMultiplyAdd(D, G, Q1); + D = XMVectorMultiplyAdd(D, G, Q0); + D = XMVectorReciprocal(D); + + N = XMVectorMultiplyAdd(P3, G, P2); + N = XMVectorMultiplyAdd(N, G, P1); + N = XMVectorMultiplyAdd(N, G, P0); + N = XMVectorMultiply(N, G); + Result = XMVectorMultiply(N, D); + + Result = XMVectorMultiplyAdd(Result, VF, VF); + + Result = XMVectorSelect(Result, VF, AbsF_LT_Epsilon); + + NegativeResult = XMVectorNegate(Result); + Result = XMVectorSelect(Result, NegativeResult, F_GT_One); + + Result = XMVectorAdd(Result, Angle1); + + V_LT_Zero = XMVectorLess(V, Zero); + NegativeResult = XMVectorNegate(Result); + Result = XMVectorSelect(Result, NegativeResult, V_LT_Zero); + + MinV = XMVectorNegate(MaxV); + NegativeHalfPi = XMVectorNegate(HalfPi); + V_GT_MaxV = XMVectorGreater(V, MaxV); + V_LT_MinV = XMVectorLess(V, MinV); + Result = XMVectorSelect(Result, g_XMHalfPi.v, V_GT_MaxV); + Result = XMVectorSelect(Result, NegativeHalfPi, V_LT_MinV); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 ATanConstants0 = {-1.3688768894e+1f, -2.0505855195e+1f, -8.4946240351f, -8.3758299368e-1f}; + static CONST XMVECTORF32 ATanConstants1 = {4.1066306682e+1f, 8.6157349597e+1f, 5.9578436142e+1f, 1.5024001160e+1f}; + static CONST XMVECTORF32 ATanConstants2 = {1.732050808f, 7.320508076e-1f, 2.679491924e-1f, 0.000244140625f}; // + static CONST XMVECTORF32 ATanConstants3 = {XM_PIDIV2, XM_PI / 3.0f, XM_PI / 6.0f, 8.507059173e+37f}; // + + XMVECTOR VF = XMVectorAbs(V); + XMVECTOR F_GT_One = _mm_cmpgt_ps(VF,g_XMOne); + XMVECTOR ReciprocalF = XMVectorReciprocal(VF); + VF = XMVectorSelect(VF, ReciprocalF, F_GT_One); + XMVECTOR Zero = XMVectorZero(); + XMVECTOR HalfPi = _mm_load_ps1(&ATanConstants3.f[0]); + XMVECTOR Angle1 = XMVectorSelect(Zero, HalfPi, F_GT_One); + // Pi/3 + XMVECTOR vConstants = _mm_load_ps1(&ATanConstants3.f[1]); + // Pi/6 + XMVECTOR Angle2 = _mm_load_ps1(&ATanConstants3.f[2]); + Angle2 = XMVectorSelect(Angle2, vConstants, F_GT_One); + + // 1-sqrt(3) + XMVECTOR FA = _mm_load_ps1(&ATanConstants2.f[1]); + FA = _mm_mul_ps(FA,VF); + FA = _mm_add_ps(FA,VF); + FA = _mm_add_ps(FA,g_XMNegativeOne); + // sqrt(3) + vConstants = _mm_load_ps1(&ATanConstants2.f[0]); + vConstants = _mm_add_ps(vConstants,VF); + FA = _mm_div_ps(FA,vConstants); + + // 2-sqrt(3) + vConstants = _mm_load_ps1(&ATanConstants2.f[2]); + // >2-sqrt(3)? + vConstants = _mm_cmpgt_ps(VF,vConstants); + VF = XMVectorSelect(VF, FA, vConstants); + Angle1 = XMVectorSelect(Angle1, Angle2, vConstants); + + XMVECTOR AbsF = XMVectorAbs(VF); + + XMVECTOR G = _mm_mul_ps(VF,VF); + XMVECTOR D = _mm_load_ps1(&ATanConstants1.f[3]); + D = _mm_add_ps(D,G); + D = _mm_mul_ps(D,G); + vConstants = _mm_load_ps1(&ATanConstants1.f[2]); + D = _mm_add_ps(D,vConstants); + D = _mm_mul_ps(D,G); + vConstants = _mm_load_ps1(&ATanConstants1.f[1]); + D = _mm_add_ps(D,vConstants); + D = _mm_mul_ps(D,G); + vConstants = _mm_load_ps1(&ATanConstants1.f[0]); + D = _mm_add_ps(D,vConstants); + + XMVECTOR N = _mm_load_ps1(&ATanConstants0.f[3]); + N = _mm_mul_ps(N,G); + vConstants = _mm_load_ps1(&ATanConstants0.f[2]); + N = _mm_add_ps(N,vConstants); + N = _mm_mul_ps(N,G); + vConstants = _mm_load_ps1(&ATanConstants0.f[1]); + N = _mm_add_ps(N,vConstants); + N = _mm_mul_ps(N,G); + vConstants = _mm_load_ps1(&ATanConstants0.f[0]); + N = _mm_add_ps(N,vConstants); + N = _mm_mul_ps(N,G); + XMVECTOR Result = _mm_div_ps(N,D); + + Result = _mm_mul_ps(Result,VF); + Result = _mm_add_ps(Result,VF); + // Epsilon + vConstants = _mm_load_ps1(&ATanConstants2.f[3]); + vConstants = _mm_cmpge_ps(vConstants,AbsF); + Result = XMVectorSelect(Result,VF,vConstants); + + XMVECTOR NegativeResult = _mm_mul_ps(Result,g_XMNegativeOne); + Result = XMVectorSelect(Result,NegativeResult,F_GT_One); + Result = _mm_add_ps(Result,Angle1); + + Zero = _mm_cmpge_ps(Zero,V); + NegativeResult = _mm_mul_ps(Result,g_XMNegativeOne); + Result = XMVectorSelect(Result,NegativeResult,Zero); + + XMVECTOR MaxV = _mm_load_ps1(&ATanConstants3.f[3]); + XMVECTOR MinV = _mm_mul_ps(MaxV,g_XMNegativeOne); + // Negate HalfPi + HalfPi = _mm_mul_ps(HalfPi,g_XMNegativeOne); + MaxV = _mm_cmple_ps(MaxV,V); + MinV = _mm_cmpge_ps(MinV,V); + Result = XMVectorSelect(Result,g_XMHalfPi,MaxV); + // HalfPi = -HalfPi + Result = XMVectorSelect(Result,HalfPi,MinV); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVectorATan2 +( + FXMVECTOR Y, + FXMVECTOR X +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // Return the inverse tangent of Y / X in the range of -Pi to Pi with the following exceptions: + + // Y == 0 and X is Negative -> Pi with the sign of Y + // y == 0 and x is positive -> 0 with the sign of y + // Y != 0 and X == 0 -> Pi / 2 with the sign of Y + // Y != 0 and X is Negative -> atan(y/x) + (PI with the sign of Y) + // X == -Infinity and Finite Y -> Pi with the sign of Y + // X == +Infinity and Finite Y -> 0 with the sign of Y + // Y == Infinity and X is Finite -> Pi / 2 with the sign of Y + // Y == Infinity and X == -Infinity -> 3Pi / 4 with the sign of Y + // Y == Infinity and X == +Infinity -> Pi / 4 with the sign of Y + + XMVECTOR Reciprocal; + XMVECTOR V; + XMVECTOR YSign; + XMVECTOR Pi, PiOverTwo, PiOverFour, ThreePiOverFour; + XMVECTOR YEqualsZero, XEqualsZero, XIsPositive, YEqualsInfinity, XEqualsInfinity; + XMVECTOR ATanResultValid; + XMVECTOR R0, R1, R2, R3, R4, R5; + XMVECTOR Zero; + XMVECTOR Result; + static CONST XMVECTOR ATan2Constants = {XM_PI, XM_PIDIV2, XM_PIDIV4, XM_PI * 3.0f / 4.0f}; + + Zero = XMVectorZero(); + ATanResultValid = XMVectorTrueInt(); + + Pi = XMVectorSplatX(ATan2Constants); + PiOverTwo = XMVectorSplatY(ATan2Constants); + PiOverFour = XMVectorSplatZ(ATan2Constants); + ThreePiOverFour = XMVectorSplatW(ATan2Constants); + + YEqualsZero = XMVectorEqual(Y, Zero); + XEqualsZero = XMVectorEqual(X, Zero); + XIsPositive = XMVectorAndInt(X, g_XMNegativeZero.v); + XIsPositive = XMVectorEqualInt(XIsPositive, Zero); + YEqualsInfinity = XMVectorIsInfinite(Y); + XEqualsInfinity = XMVectorIsInfinite(X); + + YSign = XMVectorAndInt(Y, g_XMNegativeZero.v); + Pi = XMVectorOrInt(Pi, YSign); + PiOverTwo = XMVectorOrInt(PiOverTwo, YSign); + PiOverFour = XMVectorOrInt(PiOverFour, YSign); + ThreePiOverFour = XMVectorOrInt(ThreePiOverFour, YSign); + + R1 = XMVectorSelect(Pi, YSign, XIsPositive); + R2 = XMVectorSelect(ATanResultValid, PiOverTwo, XEqualsZero); + R3 = XMVectorSelect(R2, R1, YEqualsZero); + R4 = XMVectorSelect(ThreePiOverFour, PiOverFour, XIsPositive); + R5 = XMVectorSelect(PiOverTwo, R4, XEqualsInfinity); + Result = XMVectorSelect(R3, R5, YEqualsInfinity); + ATanResultValid = XMVectorEqualInt(Result, ATanResultValid); + + Reciprocal = XMVectorReciprocal(X); + V = XMVectorMultiply(Y, Reciprocal); + R0 = XMVectorATan(V); + + R1 = XMVectorSelect( Pi, Zero, XIsPositive ); + R2 = XMVectorAdd(R0, R1); + + Result = XMVectorSelect(Result, R2, ATanResultValid); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 ATan2Constants = {XM_PI, XM_PIDIV2, XM_PIDIV4, XM_PI * 3.0f / 4.0f}; + + // Mask if Y>0 && Y!=INF + XMVECTOR YEqualsInfinity = XMVectorIsInfinite(Y); + // Get the sign of (Y&0x80000000) + XMVECTOR YSign = _mm_and_ps(Y, g_XMNegativeZero); + // Get the sign bits of X + XMVECTOR XIsPositive = _mm_and_ps(X,g_XMNegativeZero); + // Change them to masks + XIsPositive = XMVectorEqualInt(XIsPositive,g_XMZero); + // Get Pi + XMVECTOR Pi = _mm_load_ps1(&ATan2Constants.f[0]); + // Copy the sign of Y + Pi = _mm_or_ps(Pi,YSign); + XMVECTOR R1 = XMVectorSelect(Pi,YSign,XIsPositive); + // Mask for X==0 + XMVECTOR vConstants = _mm_cmpeq_ps(X,g_XMZero); + // Get Pi/2 with with sign of Y + XMVECTOR PiOverTwo = _mm_load_ps1(&ATan2Constants.f[1]); + PiOverTwo = _mm_or_ps(PiOverTwo,YSign); + XMVECTOR R2 = XMVectorSelect(g_XMNegOneMask,PiOverTwo,vConstants); + // Mask for Y==0 + vConstants = _mm_cmpeq_ps(Y,g_XMZero); + R2 = XMVectorSelect(R2,R1,vConstants); + // Get Pi/4 with sign of Y + XMVECTOR PiOverFour = _mm_load_ps1(&ATan2Constants.f[2]); + PiOverFour = _mm_or_ps(PiOverFour,YSign); + // Get (Pi*3)/4 with sign of Y + XMVECTOR ThreePiOverFour = _mm_load_ps1(&ATan2Constants.f[3]); + ThreePiOverFour = _mm_or_ps(ThreePiOverFour,YSign); + vConstants = XMVectorSelect(ThreePiOverFour, PiOverFour, XIsPositive); + XMVECTOR XEqualsInfinity = XMVectorIsInfinite(X); + vConstants = XMVectorSelect(PiOverTwo,vConstants,XEqualsInfinity); + + XMVECTOR vResult = XMVectorSelect(R2,vConstants,YEqualsInfinity); + vConstants = XMVectorSelect(R1,vResult,YEqualsInfinity); + // At this point, any entry that's zero will get the result + // from XMVectorATan(), otherwise, return the failsafe value + vResult = XMVectorSelect(vResult,vConstants,XEqualsInfinity); + // Any entries not 0xFFFFFFFF, are considered precalculated + XMVECTOR ATanResultValid = XMVectorEqualInt(vResult,g_XMNegOneMask); + // Let's do the ATan2 function + vConstants = _mm_div_ps(Y,X); + vConstants = XMVectorATan(vConstants); + // Discard entries that have been declared void + + XMVECTOR R3 = XMVectorSelect( Pi, g_XMZero, XIsPositive ); + vConstants = _mm_add_ps( vConstants, R3 ); + + vResult = XMVectorSelect(vResult,vConstants,ATanResultValid); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSinEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V2, V3, V5, V7; + XMVECTOR S1, S2, S3; + XMVECTOR Result; + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! (for -PI <= V < PI) + V2 = XMVectorMultiply(V, V); + V3 = XMVectorMultiply(V2, V); + V5 = XMVectorMultiply(V3, V2); + V7 = XMVectorMultiply(V5, V2); + + S1 = XMVectorSplatY(g_XMSinEstCoefficients.v); + S2 = XMVectorSplatZ(g_XMSinEstCoefficients.v); + S3 = XMVectorSplatW(g_XMSinEstCoefficients.v); + + Result = XMVectorMultiplyAdd(S1, V3, V); + Result = XMVectorMultiplyAdd(S2, V5, Result); + Result = XMVectorMultiplyAdd(S3, V7, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! (for -PI <= V < PI) + XMVECTOR V2 = _mm_mul_ps(V,V); + XMVECTOR V3 = _mm_mul_ps(V2,V); + XMVECTOR vResult = _mm_load_ps1(&g_XMSinEstCoefficients.f[1]); + vResult = _mm_mul_ps(vResult,V3); + vResult = _mm_add_ps(vResult,V); + XMVECTOR vConstants = _mm_load_ps1(&g_XMSinEstCoefficients.f[2]); + // V^5 + V3 = _mm_mul_ps(V3,V2); + vConstants = _mm_mul_ps(vConstants,V3); + vResult = _mm_add_ps(vResult,vConstants); + vConstants = _mm_load_ps1(&g_XMSinEstCoefficients.f[3]); + // V^7 + V3 = _mm_mul_ps(V3,V2); + vConstants = _mm_mul_ps(vConstants,V3); + vResult = _mm_add_ps(vResult,vConstants); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorCosEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V2, V4, V6; + XMVECTOR C0, C1, C2, C3; + XMVECTOR Result; + + V2 = XMVectorMultiply(V, V); + V4 = XMVectorMultiply(V2, V2); + V6 = XMVectorMultiply(V4, V2); + + C0 = XMVectorSplatX(g_XMCosEstCoefficients.v); + C1 = XMVectorSplatY(g_XMCosEstCoefficients.v); + C2 = XMVectorSplatZ(g_XMCosEstCoefficients.v); + C3 = XMVectorSplatW(g_XMCosEstCoefficients.v); + + Result = XMVectorMultiplyAdd(C1, V2, C0); + Result = XMVectorMultiplyAdd(C2, V4, Result); + Result = XMVectorMultiplyAdd(C3, V6, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Get V^2 + XMVECTOR V2 = _mm_mul_ps(V,V); + XMVECTOR vResult = _mm_load_ps1(&g_XMCosEstCoefficients.f[1]); + vResult = _mm_mul_ps(vResult,V2); + XMVECTOR vConstants = _mm_load_ps1(&g_XMCosEstCoefficients.f[0]); + vResult = _mm_add_ps(vResult,vConstants); + vConstants = _mm_load_ps1(&g_XMCosEstCoefficients.f[2]); + // Get V^4 + XMVECTOR V4 = _mm_mul_ps(V2, V2); + vConstants = _mm_mul_ps(vConstants,V4); + vResult = _mm_add_ps(vResult,vConstants); + vConstants = _mm_load_ps1(&g_XMCosEstCoefficients.f[3]); + // It's really V^6 + V4 = _mm_mul_ps(V4,V2); + vConstants = _mm_mul_ps(vConstants,V4); + vResult = _mm_add_ps(vResult,vConstants); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMVectorSinCosEst +( + XMVECTOR* pSin, + XMVECTOR* pCos, + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V2, V3, V4, V5, V6, V7; + XMVECTOR S1, S2, S3; + XMVECTOR C0, C1, C2, C3; + XMVECTOR Sin, Cos; + + XMASSERT(pSin); + XMASSERT(pCos); + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! (for -PI <= V < PI) + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! (for -PI <= V < PI) + V2 = XMVectorMultiply(V, V); + V3 = XMVectorMultiply(V2, V); + V4 = XMVectorMultiply(V2, V2); + V5 = XMVectorMultiply(V3, V2); + V6 = XMVectorMultiply(V3, V3); + V7 = XMVectorMultiply(V4, V3); + + S1 = XMVectorSplatY(g_XMSinEstCoefficients.v); + S2 = XMVectorSplatZ(g_XMSinEstCoefficients.v); + S3 = XMVectorSplatW(g_XMSinEstCoefficients.v); + + C0 = XMVectorSplatX(g_XMCosEstCoefficients.v); + C1 = XMVectorSplatY(g_XMCosEstCoefficients.v); + C2 = XMVectorSplatZ(g_XMCosEstCoefficients.v); + C3 = XMVectorSplatW(g_XMCosEstCoefficients.v); + + Sin = XMVectorMultiplyAdd(S1, V3, V); + Sin = XMVectorMultiplyAdd(S2, V5, Sin); + Sin = XMVectorMultiplyAdd(S3, V7, Sin); + + Cos = XMVectorMultiplyAdd(C1, V2, C0); + Cos = XMVectorMultiplyAdd(C2, V4, Cos); + Cos = XMVectorMultiplyAdd(C3, V6, Cos); + + *pSin = Sin; + *pCos = Cos; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pSin); + XMASSERT(pCos); + XMVECTOR V2, V3, V4, V5, V6, V7; + XMVECTOR S1, S2, S3; + XMVECTOR C0, C1, C2, C3; + XMVECTOR Sin, Cos; + + // sin(V) ~= V - V^3 / 3! + V^5 / 5! - V^7 / 7! (for -PI <= V < PI) + // cos(V) ~= 1 - V^2 / 2! + V^4 / 4! - V^6 / 6! (for -PI <= V < PI) + V2 = XMVectorMultiply(V, V); + V3 = XMVectorMultiply(V2, V); + V4 = XMVectorMultiply(V2, V2); + V5 = XMVectorMultiply(V3, V2); + V6 = XMVectorMultiply(V3, V3); + V7 = XMVectorMultiply(V4, V3); + + S1 = _mm_load_ps1(&g_XMSinEstCoefficients.f[1]); + S2 = _mm_load_ps1(&g_XMSinEstCoefficients.f[2]); + S3 = _mm_load_ps1(&g_XMSinEstCoefficients.f[3]); + + C0 = _mm_load_ps1(&g_XMCosEstCoefficients.f[0]); + C1 = _mm_load_ps1(&g_XMCosEstCoefficients.f[1]); + C2 = _mm_load_ps1(&g_XMCosEstCoefficients.f[2]); + C3 = _mm_load_ps1(&g_XMCosEstCoefficients.f[3]); + + Sin = XMVectorMultiplyAdd(S1, V3, V); + Sin = XMVectorMultiplyAdd(S2, V5, Sin); + Sin = XMVectorMultiplyAdd(S3, V7, Sin); + + Cos = XMVectorMultiplyAdd(C1, V2, C0); + Cos = XMVectorMultiplyAdd(C2, V4, Cos); + Cos = XMVectorMultiplyAdd(C3, V6, Cos); + + *pSin = Sin; + *pCos = Cos; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorTanEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2, V1T0, V1T1, V2T2; + XMVECTOR T0, T1, T2; + XMVECTOR N, D; + XMVECTOR OneOverPi; + XMVECTOR Result; + + OneOverPi = XMVectorSplatW(g_XMTanEstCoefficients.v); + + V1 = XMVectorMultiply(V, OneOverPi); + V1 = XMVectorRound(V1); + + V1 = XMVectorNegativeMultiplySubtract(g_XMPi.v, V1, V); + + T0 = XMVectorSplatX(g_XMTanEstCoefficients.v); + T1 = XMVectorSplatY(g_XMTanEstCoefficients.v); + T2 = XMVectorSplatZ(g_XMTanEstCoefficients.v); + + V2T2 = XMVectorNegativeMultiplySubtract(V1, V1, T2); + V2 = XMVectorMultiply(V1, V1); + V1T0 = XMVectorMultiply(V1, T0); + V1T1 = XMVectorMultiply(V1, T1); + + D = XMVectorReciprocalEst(V2T2); + N = XMVectorMultiplyAdd(V2, V1T1, V1T0); + + Result = XMVectorMultiply(N, D); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1, V2, V1T0, V1T1, V2T2; + XMVECTOR T0, T1, T2; + XMVECTOR N, D; + XMVECTOR OneOverPi; + XMVECTOR Result; + + OneOverPi = XMVectorSplatW(g_XMTanEstCoefficients); + + V1 = XMVectorMultiply(V, OneOverPi); + V1 = XMVectorRound(V1); + + V1 = XMVectorNegativeMultiplySubtract(g_XMPi, V1, V); + + T0 = XMVectorSplatX(g_XMTanEstCoefficients); + T1 = XMVectorSplatY(g_XMTanEstCoefficients); + T2 = XMVectorSplatZ(g_XMTanEstCoefficients); + + V2T2 = XMVectorNegativeMultiplySubtract(V1, V1, T2); + V2 = XMVectorMultiply(V1, V1); + V1T0 = XMVectorMultiply(V1, T0); + V1T1 = XMVectorMultiply(V1, T1); + + D = XMVectorReciprocalEst(V2T2); + N = XMVectorMultiplyAdd(V2, V1T1, V1T0); + + Result = XMVectorMultiply(N, D); + + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorSinHEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = XMVectorMultiplyAdd(V, Scale.v, g_XMNegativeOne.v); + V2 = XMVectorNegativeMultiplySubtract(V, Scale.v, g_XMNegativeOne.v); + + E1 = XMVectorExpEst(V1); + E2 = XMVectorExpEst(V2); + + Result = XMVectorSubtract(E1, E2); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = _mm_mul_ps(V,Scale); + V1 = _mm_add_ps(V1,g_XMNegativeOne); + V2 = _mm_mul_ps(V,Scale); + V2 = _mm_sub_ps(g_XMNegativeOne,V2); + E1 = XMVectorExpEst(V1); + E2 = XMVectorExpEst(V2); + Result = _mm_sub_ps(E1, E2); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorCosHEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTOR Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = XMVectorMultiplyAdd(V, Scale, g_XMNegativeOne.v); + V2 = XMVectorNegativeMultiplySubtract(V, Scale, g_XMNegativeOne.v); + + E1 = XMVectorExpEst(V1); + E2 = XMVectorExpEst(V2); + + Result = XMVectorAdd(E1, E2); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1, V2; + XMVECTOR E1, E2; + XMVECTOR Result; + static CONST XMVECTORF32 Scale = {1.442695040888963f, 1.442695040888963f, 1.442695040888963f, 1.442695040888963f}; // 1.0f / ln(2.0f) + + V1 = _mm_mul_ps(V,Scale); + V1 = _mm_add_ps(V1,g_XMNegativeOne); + V2 = _mm_mul_ps(V, Scale); + V2 = _mm_sub_ps(g_XMNegativeOne,V2); + E1 = XMVectorExpEst(V1); + E2 = XMVectorExpEst(V2); + Result = _mm_add_ps(E1, E2); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorTanHEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR E; + XMVECTOR Result; + static CONST XMVECTOR Scale = {2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f}; // 2.0f / ln(2.0f) + + E = XMVectorMultiply(V, Scale); + E = XMVectorExpEst(E); + E = XMVectorMultiplyAdd(E, g_XMOneHalf.v, g_XMOneHalf.v); + E = XMVectorReciprocalEst(E); + + Result = XMVectorSubtract(g_XMOne.v, E); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 Scale = {2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f, 2.8853900817779268f}; // 2.0f / ln(2.0f) + + XMVECTOR E = _mm_mul_ps(V, Scale); + E = XMVectorExpEst(E); + E = _mm_mul_ps(E,g_XMOneHalf); + E = _mm_add_ps(E,g_XMOneHalf); + E = XMVectorReciprocalEst(E); + E = _mm_sub_ps(g_XMOne, E); + return E; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorASinEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR AbsV, V2, VD, VC0, V2C3; + XMVECTOR C0, C1, C2, C3; + XMVECTOR D, Rsq, SqrtD; + XMVECTOR OnePlusEps; + XMVECTOR Result; + + AbsV = XMVectorAbs(V); + + OnePlusEps = XMVectorSplatX(g_XMASinEstConstants.v); + + C0 = XMVectorSplatX(g_XMASinEstCoefficients.v); + C1 = XMVectorSplatY(g_XMASinEstCoefficients.v); + C2 = XMVectorSplatZ(g_XMASinEstCoefficients.v); + C3 = XMVectorSplatW(g_XMASinEstCoefficients.v); + + D = XMVectorSubtract(OnePlusEps, AbsV); + + Rsq = XMVectorReciprocalSqrtEst(D); + SqrtD = XMVectorMultiply(D, Rsq); + + V2 = XMVectorMultiply(V, AbsV); + V2C3 = XMVectorMultiply(V2, C3); + VD = XMVectorMultiply(D, AbsV); + VC0 = XMVectorMultiply(V, C0); + + Result = XMVectorMultiply(V, C1); + Result = XMVectorMultiplyAdd(V2, C2, Result); + Result = XMVectorMultiplyAdd(V2C3, VD, Result); + Result = XMVectorMultiplyAdd(VC0, SqrtD, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Get abs(V) + XMVECTOR vAbsV = _mm_setzero_ps(); + vAbsV = _mm_sub_ps(vAbsV,V); + vAbsV = _mm_max_ps(vAbsV,V); + + XMVECTOR D = _mm_load_ps1(&g_XMASinEstConstants.f[0]); + D = _mm_sub_ps(D,vAbsV); + // Since this is an estimate, rqsrt is okay + XMVECTOR vConstants = _mm_rsqrt_ps(D); + XMVECTOR SqrtD = _mm_mul_ps(D,vConstants); + // V2 = V^2 retaining sign + XMVECTOR V2 = _mm_mul_ps(V,vAbsV); + D = _mm_mul_ps(D,vAbsV); + + XMVECTOR vResult = _mm_load_ps1(&g_XMASinEstCoefficients.f[1]); + vResult = _mm_mul_ps(vResult,V); + vConstants = _mm_load_ps1(&g_XMASinEstCoefficients.f[2]); + vConstants = _mm_mul_ps(vConstants,V2); + vResult = _mm_add_ps(vResult,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinEstCoefficients.f[3]); + vConstants = _mm_mul_ps(vConstants,V2); + vConstants = _mm_mul_ps(vConstants,D); + vResult = _mm_add_ps(vResult,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinEstCoefficients.f[0]); + vConstants = _mm_mul_ps(vConstants,V); + vConstants = _mm_mul_ps(vConstants,SqrtD); + vResult = _mm_add_ps(vResult,vConstants); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorACosEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR AbsV, V2, VD, VC0, V2C3; + XMVECTOR C0, C1, C2, C3; + XMVECTOR D, Rsq, SqrtD; + XMVECTOR OnePlusEps, HalfPi; + XMVECTOR Result; + + // acos(V) = PI / 2 - asin(V) + + AbsV = XMVectorAbs(V); + + OnePlusEps = XMVectorSplatX(g_XMASinEstConstants.v); + HalfPi = XMVectorSplatY(g_XMASinEstConstants.v); + + C0 = XMVectorSplatX(g_XMASinEstCoefficients.v); + C1 = XMVectorSplatY(g_XMASinEstCoefficients.v); + C2 = XMVectorSplatZ(g_XMASinEstCoefficients.v); + C3 = XMVectorSplatW(g_XMASinEstCoefficients.v); + + D = XMVectorSubtract(OnePlusEps, AbsV); + + Rsq = XMVectorReciprocalSqrtEst(D); + SqrtD = XMVectorMultiply(D, Rsq); + + V2 = XMVectorMultiply(V, AbsV); + V2C3 = XMVectorMultiply(V2, C3); + VD = XMVectorMultiply(D, AbsV); + VC0 = XMVectorMultiply(V, C0); + + Result = XMVectorMultiply(V, C1); + Result = XMVectorMultiplyAdd(V2, C2, Result); + Result = XMVectorMultiplyAdd(V2C3, VD, Result); + Result = XMVectorMultiplyAdd(VC0, SqrtD, Result); + Result = XMVectorSubtract(HalfPi, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // acos(V) = PI / 2 - asin(V) + // Get abs(V) + XMVECTOR vAbsV = _mm_setzero_ps(); + vAbsV = _mm_sub_ps(vAbsV,V); + vAbsV = _mm_max_ps(vAbsV,V); + // Calc D + XMVECTOR D = _mm_load_ps1(&g_XMASinEstConstants.f[0]); + D = _mm_sub_ps(D,vAbsV); + // SqrtD = sqrt(D-abs(V)) estimated + XMVECTOR vConstants = _mm_rsqrt_ps(D); + XMVECTOR SqrtD = _mm_mul_ps(D,vConstants); + // V2 = V^2 while retaining sign + XMVECTOR V2 = _mm_mul_ps(V, vAbsV); + // Drop vAbsV here. D = (Const-abs(V))*abs(V) + D = _mm_mul_ps(D, vAbsV); + + XMVECTOR vResult = _mm_load_ps1(&g_XMASinEstCoefficients.f[1]); + vResult = _mm_mul_ps(vResult,V); + vConstants = _mm_load_ps1(&g_XMASinEstCoefficients.f[2]); + vConstants = _mm_mul_ps(vConstants,V2); + vResult = _mm_add_ps(vResult,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinEstCoefficients.f[3]); + vConstants = _mm_mul_ps(vConstants,V2); + vConstants = _mm_mul_ps(vConstants,D); + vResult = _mm_add_ps(vResult,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinEstCoefficients.f[0]); + vConstants = _mm_mul_ps(vConstants,V); + vConstants = _mm_mul_ps(vConstants,SqrtD); + vResult = _mm_add_ps(vResult,vConstants); + + vConstants = _mm_load_ps1(&g_XMASinEstConstants.f[1]); + vResult = _mm_sub_ps(vConstants,vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorATanEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR AbsV, V2S2, N, D; + XMVECTOR S0, S1, S2; + XMVECTOR HalfPi; + XMVECTOR Result; + + S0 = XMVectorSplatX(g_XMATanEstCoefficients.v); + S1 = XMVectorSplatY(g_XMATanEstCoefficients.v); + S2 = XMVectorSplatZ(g_XMATanEstCoefficients.v); + HalfPi = XMVectorSplatW(g_XMATanEstCoefficients.v); + + AbsV = XMVectorAbs(V); + + V2S2 = XMVectorMultiplyAdd(V, V, S2); + N = XMVectorMultiplyAdd(AbsV, HalfPi, S0); + D = XMVectorMultiplyAdd(AbsV, S1, V2S2); + N = XMVectorMultiply(N, V); + D = XMVectorReciprocalEst(D); + + Result = XMVectorMultiply(N, D); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Get abs(V) + XMVECTOR vAbsV = _mm_setzero_ps(); + vAbsV = _mm_sub_ps(vAbsV,V); + vAbsV = _mm_max_ps(vAbsV,V); + + XMVECTOR vResult = _mm_load_ps1(&g_XMATanEstCoefficients.f[3]); + vResult = _mm_mul_ps(vResult,vAbsV); + XMVECTOR vConstants = _mm_load_ps1(&g_XMATanEstCoefficients.f[0]); + vResult = _mm_add_ps(vResult,vConstants); + vResult = _mm_mul_ps(vResult,V); + + XMVECTOR D = _mm_mul_ps(V,V); + vConstants = _mm_load_ps1(&g_XMATanEstCoefficients.f[2]); + D = _mm_add_ps(D,vConstants); + vConstants = _mm_load_ps1(&g_XMATanEstCoefficients.f[1]); + vConstants = _mm_mul_ps(vConstants,vAbsV); + D = _mm_add_ps(D,vConstants); + vResult = _mm_div_ps(vResult,D); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorATan2Est +( + FXMVECTOR Y, + FXMVECTOR X +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Reciprocal; + XMVECTOR V; + XMVECTOR YSign; + XMVECTOR Pi, PiOverTwo, PiOverFour, ThreePiOverFour; + XMVECTOR YEqualsZero, XEqualsZero, XIsPositive, YEqualsInfinity, XEqualsInfinity; + XMVECTOR ATanResultValid; + XMVECTOR R0, R1, R2, R3, R4, R5; + XMVECTOR Zero; + XMVECTOR Result; + static CONST XMVECTOR ATan2Constants = {XM_PI, XM_PIDIV2, XM_PIDIV4, XM_PI * 3.0f / 4.0f}; + + Zero = XMVectorZero(); + ATanResultValid = XMVectorTrueInt(); + + Pi = XMVectorSplatX(ATan2Constants); + PiOverTwo = XMVectorSplatY(ATan2Constants); + PiOverFour = XMVectorSplatZ(ATan2Constants); + ThreePiOverFour = XMVectorSplatW(ATan2Constants); + + YEqualsZero = XMVectorEqual(Y, Zero); + XEqualsZero = XMVectorEqual(X, Zero); + XIsPositive = XMVectorAndInt(X, g_XMNegativeZero.v); + XIsPositive = XMVectorEqualInt(XIsPositive, Zero); + YEqualsInfinity = XMVectorIsInfinite(Y); + XEqualsInfinity = XMVectorIsInfinite(X); + + YSign = XMVectorAndInt(Y, g_XMNegativeZero.v); + Pi = XMVectorOrInt(Pi, YSign); + PiOverTwo = XMVectorOrInt(PiOverTwo, YSign); + PiOverFour = XMVectorOrInt(PiOverFour, YSign); + ThreePiOverFour = XMVectorOrInt(ThreePiOverFour, YSign); + + R1 = XMVectorSelect(Pi, YSign, XIsPositive); + R2 = XMVectorSelect(ATanResultValid, PiOverTwo, XEqualsZero); + R3 = XMVectorSelect(R2, R1, YEqualsZero); + R4 = XMVectorSelect(ThreePiOverFour, PiOverFour, XIsPositive); + R5 = XMVectorSelect(PiOverTwo, R4, XEqualsInfinity); + Result = XMVectorSelect(R3, R5, YEqualsInfinity); + ATanResultValid = XMVectorEqualInt(Result, ATanResultValid); + + Reciprocal = XMVectorReciprocalEst(X); + V = XMVectorMultiply(Y, Reciprocal); + R0 = XMVectorATanEst(V); + + R1 = XMVectorSelect( Pi, Zero, XIsPositive ); + R2 = XMVectorAdd(R0, R1); + + Result = XMVectorSelect(Result, R2, ATanResultValid); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static CONST XMVECTORF32 ATan2Constants = {XM_PI, XM_PIDIV2, XM_PIDIV4, XM_PI * 3.0f / 4.0f}; + + // Mask if Y>0 && Y!=INF + XMVECTOR YEqualsInfinity = XMVectorIsInfinite(Y); + // Get the sign of (Y&0x80000000) + XMVECTOR YSign = _mm_and_ps(Y, g_XMNegativeZero); + // Get the sign bits of X + XMVECTOR XIsPositive = _mm_and_ps(X,g_XMNegativeZero); + // Change them to masks + XIsPositive = XMVectorEqualInt(XIsPositive,g_XMZero); + // Get Pi + XMVECTOR Pi = _mm_load_ps1(&ATan2Constants.f[0]); + // Copy the sign of Y + Pi = _mm_or_ps(Pi,YSign); + XMVECTOR R1 = XMVectorSelect(Pi,YSign,XIsPositive); + // Mask for X==0 + XMVECTOR vConstants = _mm_cmpeq_ps(X,g_XMZero); + // Get Pi/2 with with sign of Y + XMVECTOR PiOverTwo = _mm_load_ps1(&ATan2Constants.f[1]); + PiOverTwo = _mm_or_ps(PiOverTwo,YSign); + XMVECTOR R2 = XMVectorSelect(g_XMNegOneMask,PiOverTwo,vConstants); + // Mask for Y==0 + vConstants = _mm_cmpeq_ps(Y,g_XMZero); + R2 = XMVectorSelect(R2,R1,vConstants); + // Get Pi/4 with sign of Y + XMVECTOR PiOverFour = _mm_load_ps1(&ATan2Constants.f[2]); + PiOverFour = _mm_or_ps(PiOverFour,YSign); + // Get (Pi*3)/4 with sign of Y + XMVECTOR ThreePiOverFour = _mm_load_ps1(&ATan2Constants.f[3]); + ThreePiOverFour = _mm_or_ps(ThreePiOverFour,YSign); + vConstants = XMVectorSelect(ThreePiOverFour, PiOverFour, XIsPositive); + XMVECTOR XEqualsInfinity = XMVectorIsInfinite(X); + vConstants = XMVectorSelect(PiOverTwo,vConstants,XEqualsInfinity); + + XMVECTOR vResult = XMVectorSelect(R2,vConstants,YEqualsInfinity); + vConstants = XMVectorSelect(R1,vResult,YEqualsInfinity); + // At this point, any entry that's zero will get the result + // from XMVectorATan(), otherwise, return the failsafe value + vResult = XMVectorSelect(vResult,vConstants,XEqualsInfinity); + // Any entries not 0xFFFFFFFF, are considered precalculated + XMVECTOR ATanResultValid = XMVectorEqualInt(vResult,g_XMNegOneMask); + // Let's do the ATan2 function + XMVECTOR Reciprocal = _mm_rcp_ps(X); + vConstants = _mm_mul_ps(Y, Reciprocal); + vConstants = XMVectorATanEst(vConstants); + // Discard entries that have been declared void + + XMVECTOR R3 = XMVectorSelect( Pi, g_XMZero, XIsPositive ); + vConstants = _mm_add_ps( vConstants, R3 ); + + vResult = XMVectorSelect(vResult,vConstants,ATanResultValid); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorLerp +( + FXMVECTOR V0, + FXMVECTOR V1, + FLOAT t +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Scale; + XMVECTOR Length; + XMVECTOR Result; + + // V0 + t * (V1 - V0) + Scale = XMVectorReplicate(t); + Length = XMVectorSubtract(V1, V0); + Result = XMVectorMultiplyAdd(Length, Scale, V0); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR L, S; + XMVECTOR Result; + + L = _mm_sub_ps( V1, V0 ); + + S = _mm_set_ps1( t ); + + Result = _mm_mul_ps( L, S ); + + return _mm_add_ps( Result, V0 ); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorLerpV +( + FXMVECTOR V0, + FXMVECTOR V1, + FXMVECTOR T +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Length; + XMVECTOR Result; + + // V0 + T * (V1 - V0) + Length = XMVectorSubtract(V1, V0); + Result = XMVectorMultiplyAdd(Length, T, V0); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Length; + XMVECTOR Result; + + Length = _mm_sub_ps( V1, V0 ); + + Result = _mm_mul_ps( Length, T ); + + return _mm_add_ps( Result, V0 ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorHermite +( + FXMVECTOR Position0, + FXMVECTOR Tangent0, + FXMVECTOR Position1, + CXMVECTOR Tangent1, + FLOAT t +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR P0; + XMVECTOR T0; + XMVECTOR P1; + XMVECTOR T1; + XMVECTOR Result; + FLOAT t2; + FLOAT t3; + + // Result = (2 * t^3 - 3 * t^2 + 1) * Position0 + + // (t^3 - 2 * t^2 + t) * Tangent0 + + // (-2 * t^3 + 3 * t^2) * Position1 + + // (t^3 - t^2) * Tangent1 + t2 = t * t; + t3 = t * t2; + + P0 = XMVectorReplicate(2.0f * t3 - 3.0f * t2 + 1.0f); + T0 = XMVectorReplicate(t3 - 2.0f * t2 + t); + P1 = XMVectorReplicate(-2.0f * t3 + 3.0f * t2); + T1 = XMVectorReplicate(t3 - t2); + + Result = XMVectorMultiply(P0, Position0); + Result = XMVectorMultiplyAdd(T0, Tangent0, Result); + Result = XMVectorMultiplyAdd(P1, Position1, Result); + Result = XMVectorMultiplyAdd(T1, Tangent1, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + FLOAT t2 = t * t; + FLOAT t3 = t * t2; + + XMVECTOR P0 = _mm_set_ps1(2.0f * t3 - 3.0f * t2 + 1.0f); + XMVECTOR T0 = _mm_set_ps1(t3 - 2.0f * t2 + t); + XMVECTOR P1 = _mm_set_ps1(-2.0f * t3 + 3.0f * t2); + XMVECTOR T1 = _mm_set_ps1(t3 - t2); + + XMVECTOR vResult = _mm_mul_ps(P0, Position0); + XMVECTOR vTemp = _mm_mul_ps(T0, Tangent0); + vResult = _mm_add_ps(vResult,vTemp); + vTemp = _mm_mul_ps(P1, Position1); + vResult = _mm_add_ps(vResult,vTemp); + vTemp = _mm_mul_ps(T1, Tangent1); + vResult = _mm_add_ps(vResult,vTemp); + return vResult; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorHermiteV +( + FXMVECTOR Position0, + FXMVECTOR Tangent0, + FXMVECTOR Position1, + CXMVECTOR Tangent1, + CXMVECTOR T +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR P0; + XMVECTOR T0; + XMVECTOR P1; + XMVECTOR T1; + XMVECTOR Result; + XMVECTOR T2; + XMVECTOR T3; + + // Result = (2 * t^3 - 3 * t^2 + 1) * Position0 + + // (t^3 - 2 * t^2 + t) * Tangent0 + + // (-2 * t^3 + 3 * t^2) * Position1 + + // (t^3 - t^2) * Tangent1 + T2 = XMVectorMultiply(T, T); + T3 = XMVectorMultiply(T , T2); + + P0 = XMVectorReplicate(2.0f * T3.vector4_f32[0] - 3.0f * T2.vector4_f32[0] + 1.0f); + T0 = XMVectorReplicate(T3.vector4_f32[1] - 2.0f * T2.vector4_f32[1] + T.vector4_f32[1]); + P1 = XMVectorReplicate(-2.0f * T3.vector4_f32[2] + 3.0f * T2.vector4_f32[2]); + T1 = XMVectorReplicate(T3.vector4_f32[3] - T2.vector4_f32[3]); + + Result = XMVectorMultiply(P0, Position0); + Result = XMVectorMultiplyAdd(T0, Tangent0, Result); + Result = XMVectorMultiplyAdd(P1, Position1, Result); + Result = XMVectorMultiplyAdd(T1, Tangent1, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 CatMulT2 = {-3.0f,-2.0f,3.0f,-1.0f}; + static const XMVECTORF32 CatMulT3 = {2.0f,1.0f,-2.0f,1.0f}; + + // Result = (2 * t^3 - 3 * t^2 + 1) * Position0 + + // (t^3 - 2 * t^2 + t) * Tangent0 + + // (-2 * t^3 + 3 * t^2) * Position1 + + // (t^3 - t^2) * Tangent1 + XMVECTOR T2 = _mm_mul_ps(T,T); + XMVECTOR T3 = _mm_mul_ps(T,T2); + // Mul by the constants against t^2 + T2 = _mm_mul_ps(T2,CatMulT2); + // Mul by the constants against t^3 + T3 = _mm_mul_ps(T3,CatMulT3); + // T3 now has the pre-result. + T3 = _mm_add_ps(T3,T2); + // I need to add t.y only + T2 = _mm_and_ps(T,g_XMMaskY); + T3 = _mm_add_ps(T3,T2); + // Add 1.0f to x + T3 = _mm_add_ps(T3,g_XMIdentityR0); + // Now, I have the constants created + // Mul the x constant to Position0 + XMVECTOR vResult = _mm_shuffle_ps(T3,T3,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,Position0); + // Mul the y constant to Tangent0 + T2 = _mm_shuffle_ps(T3,T3,_MM_SHUFFLE(1,1,1,1)); + T2 = _mm_mul_ps(T2,Tangent0); + vResult = _mm_add_ps(vResult,T2); + // Mul the z constant to Position1 + T2 = _mm_shuffle_ps(T3,T3,_MM_SHUFFLE(2,2,2,2)); + T2 = _mm_mul_ps(T2,Position1); + vResult = _mm_add_ps(vResult,T2); + // Mul the w constant to Tangent1 + T3 = _mm_shuffle_ps(T3,T3,_MM_SHUFFLE(3,3,3,3)); + T3 = _mm_mul_ps(T3,Tangent1); + vResult = _mm_add_ps(vResult,T3); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorCatmullRom +( + FXMVECTOR Position0, + FXMVECTOR Position1, + FXMVECTOR Position2, + CXMVECTOR Position3, + FLOAT t +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR P0; + XMVECTOR P1; + XMVECTOR P2; + XMVECTOR P3; + XMVECTOR Result; + FLOAT t2; + FLOAT t3; + + // Result = ((-t^3 + 2 * t^2 - t) * Position0 + + // (3 * t^3 - 5 * t^2 + 2) * Position1 + + // (-3 * t^3 + 4 * t^2 + t) * Position2 + + // (t^3 - t^2) * Position3) * 0.5 + t2 = t * t; + t3 = t * t2; + + P0 = XMVectorReplicate((-t3 + 2.0f * t2 - t) * 0.5f); + P1 = XMVectorReplicate((3.0f * t3 - 5.0f * t2 + 2.0f) * 0.5f); + P2 = XMVectorReplicate((-3.0f * t3 + 4.0f * t2 + t) * 0.5f); + P3 = XMVectorReplicate((t3 - t2) * 0.5f); + + Result = XMVectorMultiply(P0, Position0); + Result = XMVectorMultiplyAdd(P1, Position1, Result); + Result = XMVectorMultiplyAdd(P2, Position2, Result); + Result = XMVectorMultiplyAdd(P3, Position3, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + FLOAT t2 = t * t; + FLOAT t3 = t * t2; + + XMVECTOR P0 = _mm_set_ps1((-t3 + 2.0f * t2 - t) * 0.5f); + XMVECTOR P1 = _mm_set_ps1((3.0f * t3 - 5.0f * t2 + 2.0f) * 0.5f); + XMVECTOR P2 = _mm_set_ps1((-3.0f * t3 + 4.0f * t2 + t) * 0.5f); + XMVECTOR P3 = _mm_set_ps1((t3 - t2) * 0.5f); + + P0 = _mm_mul_ps(P0, Position0); + P1 = _mm_mul_ps(P1, Position1); + P2 = _mm_mul_ps(P2, Position2); + P3 = _mm_mul_ps(P3, Position3); + P0 = _mm_add_ps(P0,P1); + P2 = _mm_add_ps(P2,P3); + P0 = _mm_add_ps(P0,P2); + return P0; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorCatmullRomV +( + FXMVECTOR Position0, + FXMVECTOR Position1, + FXMVECTOR Position2, + CXMVECTOR Position3, + CXMVECTOR T +) +{ +#if defined(_XM_NO_INTRINSICS_) + float fx = T.vector4_f32[0]; + float fy = T.vector4_f32[1]; + float fz = T.vector4_f32[2]; + float fw = T.vector4_f32[3]; + XMVECTOR vResult = { + 0.5f*((-fx*fx*fx+2*fx*fx-fx)*Position0.vector4_f32[0]+ + (3*fx*fx*fx-5*fx*fx+2)*Position1.vector4_f32[0]+ + (-3*fx*fx*fx+4*fx*fx+fx)*Position2.vector4_f32[0]+ + (fx*fx*fx-fx*fx)*Position3.vector4_f32[0]), + 0.5f*((-fy*fy*fy+2*fy*fy-fy)*Position0.vector4_f32[1]+ + (3*fy*fy*fy-5*fy*fy+2)*Position1.vector4_f32[1]+ + (-3*fy*fy*fy+4*fy*fy+fy)*Position2.vector4_f32[1]+ + (fy*fy*fy-fy*fy)*Position3.vector4_f32[1]), + 0.5f*((-fz*fz*fz+2*fz*fz-fz)*Position0.vector4_f32[2]+ + (3*fz*fz*fz-5*fz*fz+2)*Position1.vector4_f32[2]+ + (-3*fz*fz*fz+4*fz*fz+fz)*Position2.vector4_f32[2]+ + (fz*fz*fz-fz*fz)*Position3.vector4_f32[2]), + 0.5f*((-fw*fw*fw+2*fw*fw-fw)*Position0.vector4_f32[3]+ + (3*fw*fw*fw-5*fw*fw+2)*Position1.vector4_f32[3]+ + (-3*fw*fw*fw+4*fw*fw+fw)*Position2.vector4_f32[3]+ + (fw*fw*fw-fw*fw)*Position3.vector4_f32[3]) + }; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 Catmul2 = {2.0f,2.0f,2.0f,2.0f}; + static const XMVECTORF32 Catmul3 = {3.0f,3.0f,3.0f,3.0f}; + static const XMVECTORF32 Catmul4 = {4.0f,4.0f,4.0f,4.0f}; + static const XMVECTORF32 Catmul5 = {5.0f,5.0f,5.0f,5.0f}; + // Cache T^2 and T^3 + XMVECTOR T2 = _mm_mul_ps(T,T); + XMVECTOR T3 = _mm_mul_ps(T,T2); + // Perform the Position0 term + XMVECTOR vResult = _mm_add_ps(T2,T2); + vResult = _mm_sub_ps(vResult,T); + vResult = _mm_sub_ps(vResult,T3); + vResult = _mm_mul_ps(vResult,Position0); + // Perform the Position1 term and add + XMVECTOR vTemp = _mm_mul_ps(T3,Catmul3); + XMVECTOR vTemp2 = _mm_mul_ps(T2,Catmul5); + vTemp = _mm_sub_ps(vTemp,vTemp2); + vTemp = _mm_add_ps(vTemp,Catmul2); + vTemp = _mm_mul_ps(vTemp,Position1); + vResult = _mm_add_ps(vResult,vTemp); + // Perform the Position2 term and add + vTemp = _mm_mul_ps(T2,Catmul4); + vTemp2 = _mm_mul_ps(T3,Catmul3); + vTemp = _mm_sub_ps(vTemp,vTemp2); + vTemp = _mm_add_ps(vTemp,T); + vTemp = _mm_mul_ps(vTemp,Position2); + vResult = _mm_add_ps(vResult,vTemp); + // Position3 is the last term + T3 = _mm_sub_ps(T3,T2); + T3 = _mm_mul_ps(T3,Position3); + vResult = _mm_add_ps(vResult,T3); + // Multiply by 0.5f and exit + vResult = _mm_mul_ps(vResult,g_XMOneHalf); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorBaryCentric +( + FXMVECTOR Position0, + FXMVECTOR Position1, + FXMVECTOR Position2, + FLOAT f, + FLOAT g +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // Result = Position0 + f * (Position1 - Position0) + g * (Position2 - Position0) + XMVECTOR P10; + XMVECTOR P20; + XMVECTOR ScaleF; + XMVECTOR ScaleG; + XMVECTOR Result; + + P10 = XMVectorSubtract(Position1, Position0); + ScaleF = XMVectorReplicate(f); + + P20 = XMVectorSubtract(Position2, Position0); + ScaleG = XMVectorReplicate(g); + + Result = XMVectorMultiplyAdd(P10, ScaleF, Position0); + Result = XMVectorMultiplyAdd(P20, ScaleG, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR R1 = _mm_sub_ps(Position1,Position0); + XMVECTOR SF = _mm_set_ps1(f); + XMVECTOR R2 = _mm_sub_ps(Position2,Position0); + XMVECTOR SG = _mm_set_ps1(g); + R1 = _mm_mul_ps(R1,SF); + R2 = _mm_mul_ps(R2,SG); + R1 = _mm_add_ps(R1,Position0); + R1 = _mm_add_ps(R1,R2); + return R1; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVectorBaryCentricV +( + FXMVECTOR Position0, + FXMVECTOR Position1, + FXMVECTOR Position2, + CXMVECTOR F, + CXMVECTOR G +) +{ +#if defined(_XM_NO_INTRINSICS_) + + // Result = Position0 + f * (Position1 - Position0) + g * (Position2 - Position0) + XMVECTOR P10; + XMVECTOR P20; + XMVECTOR Result; + + P10 = XMVectorSubtract(Position1, Position0); + P20 = XMVectorSubtract(Position2, Position0); + + Result = XMVectorMultiplyAdd(P10, F, Position0); + Result = XMVectorMultiplyAdd(P20, G, Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR R1 = _mm_sub_ps(Position1,Position0); + XMVECTOR R2 = _mm_sub_ps(Position2,Position0); + R1 = _mm_mul_ps(R1,F); + R2 = _mm_mul_ps(R2,G); + R1 = _mm_add_ps(R1,Position0); + R1 = _mm_add_ps(R1,R2); + return R1; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +/**************************************************************************** + * + * 2D Vector + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2Equal +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] == V2.vector4_f32[0]) && (V1.vector4_f32[1] == V2.vector4_f32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); +// z and w are don't care + return (((_mm_movemask_ps(vTemp)&3)==3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector2EqualR(V1, V2)); +#endif +} + + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector2EqualR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + UINT CR = 0; + + if ((V1.vector4_f32[0] == V2.vector4_f32[0]) && + (V1.vector4_f32[1] == V2.vector4_f32[1])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] != V2.vector4_f32[0]) && + (V1.vector4_f32[1] != V2.vector4_f32[1])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); +// z and w are don't care + int iTest = _mm_movemask_ps(vTemp)&3; + UINT CR = 0; + if (iTest==3) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2EqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_u32[0] == V2.vector4_u32[0]) && (V1.vector4_u32[1] == V2.vector4_u32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + return (((_mm_movemask_ps(reinterpret_cast(&vTemp)[0])&3)==3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector2EqualIntR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector2EqualIntR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + UINT CR = 0; + if ((V1.vector4_u32[0] == V2.vector4_u32[0]) && + (V1.vector4_u32[1] == V2.vector4_u32[1])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_u32[0] != V2.vector4_u32[0]) && + (V1.vector4_u32[1] != V2.vector4_u32[1])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + int iTest = _mm_movemask_ps(reinterpret_cast(&vTemp)[0])&3; + UINT CR = 0; + if (iTest==3) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2NearEqual +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR Epsilon +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT dx, dy; + dx = fabsf(V1.vector4_f32[0]-V2.vector4_f32[0]); + dy = fabsf(V1.vector4_f32[1]-V2.vector4_f32[1]); + return ((dx <= Epsilon.vector4_f32[0]) && + (dy <= Epsilon.vector4_f32[1])); +#elif defined(_XM_SSE_INTRINSICS_) + // Get the difference + XMVECTOR vDelta = _mm_sub_ps(V1,V2); + // Get the absolute value of the difference + XMVECTOR vTemp = _mm_setzero_ps(); + vTemp = _mm_sub_ps(vTemp,vDelta); + vTemp = _mm_max_ps(vTemp,vDelta); + vTemp = _mm_cmple_ps(vTemp,Epsilon); + // z and w are don't care + return (((_mm_movemask_ps(vTemp)&3)==0x3) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2NotEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] != V2.vector4_f32[0]) || (V1.vector4_f32[1] != V2.vector4_f32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); +// z and w are don't care + return (((_mm_movemask_ps(vTemp)&3)!=3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAnyFalse(XMVector2EqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2NotEqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_u32[0] != V2.vector4_u32[0]) || (V1.vector4_u32[1] != V2.vector4_u32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + return (((_mm_movemask_ps(reinterpret_cast(&vTemp)[0])&3)!=3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAnyFalse(XMVector2EqualIntR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2Greater +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] > V2.vector4_f32[0]) && (V1.vector4_f32[1] > V2.vector4_f32[1])) != 0); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); +// z and w are don't care + return (((_mm_movemask_ps(vTemp)&3)==3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector2GreaterR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector2GreaterR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + UINT CR = 0; + if ((V1.vector4_f32[0] > V2.vector4_f32[0]) && + (V1.vector4_f32[1] > V2.vector4_f32[1])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] <= V2.vector4_f32[0]) && + (V1.vector4_f32[1] <= V2.vector4_f32[1])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); + int iTest = _mm_movemask_ps(vTemp)&3; + UINT CR = 0; + if (iTest==3) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2GreaterOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] >= V2.vector4_f32[0]) && (V1.vector4_f32[1] >= V2.vector4_f32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&3)==3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector2GreaterOrEqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector2GreaterOrEqualR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V1.vector4_f32[0] >= V2.vector4_f32[0]) && + (V1.vector4_f32[1] >= V2.vector4_f32[1])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] < V2.vector4_f32[0]) && + (V1.vector4_f32[1] < V2.vector4_f32[1])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + int iTest = _mm_movemask_ps(vTemp)&3; + UINT CR = 0; + if (iTest == 3) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2Less +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] < V2.vector4_f32[0]) && (V1.vector4_f32[1] < V2.vector4_f32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmplt_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&3)==3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector2GreaterR(V2, V1)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2LessOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] <= V2.vector4_f32[0]) && (V1.vector4_f32[1] <= V2.vector4_f32[1])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmple_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&3)==3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector2GreaterOrEqualR(V2, V1)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2InBounds +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ + #if defined(_XM_NO_INTRINSICS_) + return (((V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) && + (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1])) != 0); + #elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + // x and y in bounds? (z and w are don't care) + return (((_mm_movemask_ps(vTemp1)&0x3)==0x3) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllInBounds(XMVector2InBoundsR(V, Bounds)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector2InBoundsR +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) && + (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1])) + { + CR = XM_CRMASK_CR6BOUNDS; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + // x and y in bounds? (z and w are don't care) + return ((_mm_movemask_ps(vTemp1)&0x3)==0x3) ? XM_CRMASK_CR6BOUNDS : 0; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2IsNaN +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (XMISNAN(V.vector4_f32[0]) || + XMISNAN(V.vector4_f32[1])); +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the exponent + __m128i vTempInf = _mm_and_si128(reinterpret_cast(&V)[0],g_XMInfinity); + // Mask off the mantissa + __m128i vTempNan = _mm_and_si128(reinterpret_cast(&V)[0],g_XMQNaNTest); + // Are any of the exponents == 0x7F800000? + vTempInf = _mm_cmpeq_epi32(vTempInf,g_XMInfinity); + // Are any of the mantissa's zero? (SSE2 doesn't have a neq test) + vTempNan = _mm_cmpeq_epi32(vTempNan,g_XMZero); + // Perform a not on the NaN test to be true on NON-zero mantissas + vTempNan = _mm_andnot_si128(vTempNan,vTempInf); + // If x or y are NaN, the signs are true after the merge above + return ((_mm_movemask_ps(reinterpret_cast(&vTempNan)[0])&3) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector2IsInfinite +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return (XMISINF(V.vector4_f32[0]) || + XMISINF(V.vector4_f32[1])); +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the sign bit + __m128 vTemp = _mm_and_ps(V,g_XMAbsMask); + // Compare to infinity + vTemp = _mm_cmpeq_ps(vTemp,g_XMInfinity); + // If x or z are infinity, the signs are true. + return ((_mm_movemask_ps(vTemp)&3) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Dot +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = + Result.vector4_f32[1] = + Result.vector4_f32[2] = + Result.vector4_f32[3] = V1.vector4_f32[0] * V2.vector4_f32[0] + V1.vector4_f32[1] * V2.vector4_f32[1]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V1,V2); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Cross +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fCross = (V1.vector4_f32[0] * V2.vector4_f32[1]) - (V1.vector4_f32[1] * V2.vector4_f32[0]); + XMVECTOR vResult = { + fCross, + fCross, + fCross, + fCross + }; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + // Swap x and y + XMVECTOR vResult = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(0,1,0,1)); + // Perform the muls + vResult = _mm_mul_ps(vResult,V1); + // Splat y + XMVECTOR vTemp = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(1,1,1,1)); + // Sub the values + vResult = _mm_sub_ss(vResult,vTemp); + // Splat the cross product + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,0,0,0)); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2LengthSq +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + return XMVector2Dot(V, V); +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + return vLengthSq; +#else + return XMVector2Dot(V, V); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2ReciprocalLengthEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector2LengthSq(V); + Result = XMVectorReciprocalSqrtEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_rsqrt_ss(vLengthSq); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2ReciprocalLength +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector2LengthSq(V); + Result = XMVectorReciprocalSqrt(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_sqrt_ss(vLengthSq); + vLengthSq = _mm_div_ss(g_XMOne,vLengthSq); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2LengthEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Result; + Result = XMVector2LengthSq(V); + Result = XMVectorSqrtEst(Result); + return Result; +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_sqrt_ss(vLengthSq); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Length +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result = XMVector2LengthSq(V); + Result = XMVectorSqrt(Result); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + vLengthSq = _mm_sqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// XMVector2NormalizeEst uses a reciprocal estimate and +// returns QNaN on zero and infinite vectors. + +XMFINLINE XMVECTOR XMVector2NormalizeEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result = XMVector2ReciprocalLength(V); + Result = XMVectorMultiply(V, Result); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has y splatted + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + // x+y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_rsqrt_ss(vLengthSq); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + vLengthSq = _mm_mul_ps(vLengthSq,V); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Normalize +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fLength; + XMVECTOR vResult; + + vResult = XMVector2Length( V ); + fLength = vResult.vector4_f32[0]; + + // Prevent divide by zero + if (fLength > 0) { + fLength = 1.0f/fLength; + } + + vResult.vector4_f32[0] = V.vector4_f32[0]*fLength; + vResult.vector4_f32[1] = V.vector4_f32[1]*fLength; + vResult.vector4_f32[2] = V.vector4_f32[2]*fLength; + vResult.vector4_f32[3] = V.vector4_f32[3]*fLength; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x and y only + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,1,1,1)); + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + // Prepare for the division + XMVECTOR vResult = _mm_sqrt_ps(vLengthSq); + // Create zero with a single instruction + XMVECTOR vZeroMask = _mm_setzero_ps(); + // Test for a divide by zero (Must be FP to detect -0.0) + vZeroMask = _mm_cmpneq_ps(vZeroMask,vResult); + // Failsafe on zero (Or epsilon) length planes + // If the length is infinity, set the elements to zero + vLengthSq = _mm_cmpneq_ps(vLengthSq,g_XMInfinity); + // Reciprocal mul to perform the normalization + vResult = _mm_div_ps(V,vResult); + // Any that are infinity, set to zero + vResult = _mm_and_ps(vResult,vZeroMask); + // Select qnan or result based on infinite length + XMVECTOR vTemp1 = _mm_andnot_ps(vLengthSq,g_XMQNaN); + XMVECTOR vTemp2 = _mm_and_ps(vResult,vLengthSq); + vResult = _mm_or_ps(vTemp1,vTemp2); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2ClampLength +( + FXMVECTOR V, + FLOAT LengthMin, + FLOAT LengthMax +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR ClampMax; + XMVECTOR ClampMin; + + ClampMax = XMVectorReplicate(LengthMax); + ClampMin = XMVectorReplicate(LengthMin); + + return XMVector2ClampLengthV(V, ClampMin, ClampMax); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR ClampMax = _mm_set_ps1(LengthMax); + XMVECTOR ClampMin = _mm_set_ps1(LengthMin); + return XMVector2ClampLengthV(V, ClampMin, ClampMax); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2ClampLengthV +( + FXMVECTOR V, + FXMVECTOR LengthMin, + FXMVECTOR LengthMax +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR ClampLength; + XMVECTOR LengthSq; + XMVECTOR RcpLength; + XMVECTOR Length; + XMVECTOR Normal; + XMVECTOR Zero; + XMVECTOR InfiniteLength; + XMVECTOR ZeroLength; + XMVECTOR Select; + XMVECTOR ControlMax; + XMVECTOR ControlMin; + XMVECTOR Control; + XMVECTOR Result; + + XMASSERT((LengthMin.vector4_f32[1] == LengthMin.vector4_f32[0])); + XMASSERT((LengthMax.vector4_f32[1] == LengthMax.vector4_f32[0])); + XMASSERT(XMVector2GreaterOrEqual(LengthMin, XMVectorZero())); + XMASSERT(XMVector2GreaterOrEqual(LengthMax, XMVectorZero())); + XMASSERT(XMVector2GreaterOrEqual(LengthMax, LengthMin)); + + LengthSq = XMVector2LengthSq(V); + + Zero = XMVectorZero(); + + RcpLength = XMVectorReciprocalSqrt(LengthSq); + + InfiniteLength = XMVectorEqualInt(LengthSq, g_XMInfinity.v); + ZeroLength = XMVectorEqual(LengthSq, Zero); + + Length = XMVectorMultiply(LengthSq, RcpLength); + + Normal = XMVectorMultiply(V, RcpLength); + + Select = XMVectorEqualInt(InfiniteLength, ZeroLength); + Length = XMVectorSelect(LengthSq, Length, Select); + Normal = XMVectorSelect(LengthSq, Normal, Select); + + ControlMax = XMVectorGreater(Length, LengthMax); + ControlMin = XMVectorLess(Length, LengthMin); + + ClampLength = XMVectorSelect(Length, LengthMax, ControlMax); + ClampLength = XMVectorSelect(ClampLength, LengthMin, ControlMin); + + Result = XMVectorMultiply(Normal, ClampLength); + + // Preserve the original vector (with no precision loss) if the length falls within the given range + Control = XMVectorEqualInt(ControlMax, ControlMin); + Result = XMVectorSelect(Result, V, Control); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR ClampLength; + XMVECTOR LengthSq; + XMVECTOR RcpLength; + XMVECTOR Length; + XMVECTOR Normal; + XMVECTOR InfiniteLength; + XMVECTOR ZeroLength; + XMVECTOR Select; + XMVECTOR ControlMax; + XMVECTOR ControlMin; + XMVECTOR Control; + XMVECTOR Result; + + XMASSERT((XMVectorGetY(LengthMin) == XMVectorGetX(LengthMin))); + XMASSERT((XMVectorGetY(LengthMax) == XMVectorGetX(LengthMax))); + XMASSERT(XMVector2GreaterOrEqual(LengthMin, g_XMZero)); + XMASSERT(XMVector2GreaterOrEqual(LengthMax, g_XMZero)); + XMASSERT(XMVector2GreaterOrEqual(LengthMax, LengthMin)); + LengthSq = XMVector2LengthSq(V); + RcpLength = XMVectorReciprocalSqrt(LengthSq); + InfiniteLength = XMVectorEqualInt(LengthSq, g_XMInfinity); + ZeroLength = XMVectorEqual(LengthSq, g_XMZero); + Length = _mm_mul_ps(LengthSq, RcpLength); + Normal = _mm_mul_ps(V, RcpLength); + Select = XMVectorEqualInt(InfiniteLength, ZeroLength); + Length = XMVectorSelect(LengthSq, Length, Select); + Normal = XMVectorSelect(LengthSq, Normal, Select); + ControlMax = XMVectorGreater(Length, LengthMax); + ControlMin = XMVectorLess(Length, LengthMin); + ClampLength = XMVectorSelect(Length, LengthMax, ControlMax); + ClampLength = XMVectorSelect(ClampLength, LengthMin, ControlMin); + Result = _mm_mul_ps(Normal, ClampLength); + // Preserve the original vector (with no precision loss) if the length falls within the given range + Control = XMVectorEqualInt(ControlMax, ControlMin); + Result = XMVectorSelect(Result, V, Control); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Reflect +( + FXMVECTOR Incident, + FXMVECTOR Normal +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + // Result = Incident - (2 * dot(Incident, Normal)) * Normal + Result = XMVector2Dot(Incident, Normal); + Result = XMVectorAdd(Result, Result); + Result = XMVectorNegativeMultiplySubtract(Result, Normal, Incident); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = Incident - (2 * dot(Incident, Normal)) * Normal + XMVECTOR Result = XMVector2Dot(Incident,Normal); + Result = _mm_add_ps(Result, Result); + Result = _mm_mul_ps(Result, Normal); + Result = _mm_sub_ps(Incident,Result); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Refract +( + FXMVECTOR Incident, + FXMVECTOR Normal, + FLOAT RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Index; + Index = XMVectorReplicate(RefractionIndex); + return XMVector2RefractV(Incident, Normal, Index); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Index = _mm_set_ps1(RefractionIndex); + return XMVector2RefractV(Incident,Normal,Index); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +// Return the refraction of a 2D vector +XMFINLINE XMVECTOR XMVector2RefractV +( + FXMVECTOR Incident, + FXMVECTOR Normal, + FXMVECTOR RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + float IDotN; + float RX,RY; + XMVECTOR vResult; + // Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + + // sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) + IDotN = (Incident.vector4_f32[0]*Normal.vector4_f32[0])+(Incident.vector4_f32[1]*Normal.vector4_f32[1]); + // R = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) + RY = 1.0f-(IDotN*IDotN); + RX = 1.0f-(RY*RefractionIndex.vector4_f32[0]*RefractionIndex.vector4_f32[0]); + RY = 1.0f-(RY*RefractionIndex.vector4_f32[1]*RefractionIndex.vector4_f32[1]); + if (RX>=0.0f) { + RX = (RefractionIndex.vector4_f32[0]*Incident.vector4_f32[0])-(Normal.vector4_f32[0]*((RefractionIndex.vector4_f32[0]*IDotN)+sqrtf(RX))); + } else { + RX = 0.0f; + } + if (RY>=0.0f) { + RY = (RefractionIndex.vector4_f32[1]*Incident.vector4_f32[1])-(Normal.vector4_f32[1]*((RefractionIndex.vector4_f32[1]*IDotN)+sqrtf(RY))); + } else { + RY = 0.0f; + } + vResult.vector4_f32[0] = RX; + vResult.vector4_f32[1] = RY; + vResult.vector4_f32[2] = 0.0f; + vResult.vector4_f32[3] = 0.0f; + return vResult; +#elif defined(_XM_SSE_INTRINSICS_) + // Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + + // sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) + // Get the 2D Dot product of Incident-Normal + XMVECTOR IDotN = _mm_mul_ps(Incident,Normal); + XMVECTOR vTemp = _mm_shuffle_ps(IDotN,IDotN,_MM_SHUFFLE(1,1,1,1)); + IDotN = _mm_add_ss(IDotN,vTemp); + IDotN = _mm_shuffle_ps(IDotN,IDotN,_MM_SHUFFLE(0,0,0,0)); + // vTemp = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) + vTemp = _mm_mul_ps(IDotN,IDotN); + vTemp = _mm_sub_ps(g_XMOne,vTemp); + vTemp = _mm_mul_ps(vTemp,RefractionIndex); + vTemp = _mm_mul_ps(vTemp,RefractionIndex); + vTemp = _mm_sub_ps(g_XMOne,vTemp); + // If any terms are <=0, sqrt() will fail, punt to zero + XMVECTOR vMask = _mm_cmpgt_ps(vTemp,g_XMZero); + // R = RefractionIndex * IDotN + sqrt(R) + vTemp = _mm_sqrt_ps(vTemp); + XMVECTOR vResult = _mm_mul_ps(RefractionIndex,IDotN); + vTemp = _mm_add_ps(vTemp,vResult); + // Result = RefractionIndex * Incident - Normal * R + vResult = _mm_mul_ps(RefractionIndex,Incident); + vTemp = _mm_mul_ps(vTemp,Normal); + vResult = _mm_sub_ps(vResult,vTemp); + vResult = _mm_and_ps(vResult,vMask); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Orthogonal +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = -V.vector4_f32[1]; + Result.vector4_f32[1] = V.vector4_f32[0]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,2,0,1)); + vResult = _mm_mul_ps(vResult,g_XMNegateX); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2AngleBetweenNormalsEst +( + FXMVECTOR N1, + FXMVECTOR N2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + Result = XMVector2Dot(N1, N2); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + Result = XMVectorClamp(Result, NegativeOne, One); + Result = XMVectorACosEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = XMVector2Dot(N1,N2); + // Clamp to -1.0f to 1.0f + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne);; + vResult = XMVectorACosEst(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2AngleBetweenNormals +( + FXMVECTOR N1, + FXMVECTOR N2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + Result = XMVector2Dot(N1, N2); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + Result = XMVectorClamp(Result, NegativeOne, One); + Result = XMVectorACos(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = XMVector2Dot(N1,N2); + // Clamp to -1.0f to 1.0f + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne);; + vResult = XMVectorACos(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2AngleBetweenVectors +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR L1; + XMVECTOR L2; + XMVECTOR Dot; + XMVECTOR CosAngle; + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + L1 = XMVector2ReciprocalLength(V1); + L2 = XMVector2ReciprocalLength(V2); + + Dot = XMVector2Dot(V1, V2); + + L1 = XMVectorMultiply(L1, L2); + + CosAngle = XMVectorMultiply(Dot, L1); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + CosAngle = XMVectorClamp(CosAngle, NegativeOne, One); + + Result = XMVectorACos(CosAngle); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR L1; + XMVECTOR L2; + XMVECTOR Dot; + XMVECTOR CosAngle; + XMVECTOR Result; + L1 = XMVector2ReciprocalLength(V1); + L2 = XMVector2ReciprocalLength(V2); + Dot = XMVector2Dot(V1, V2); + L1 = _mm_mul_ps(L1, L2); + CosAngle = _mm_mul_ps(Dot, L1); + CosAngle = XMVectorClamp(CosAngle, g_XMNegativeOne,g_XMOne); + Result = XMVectorACos(CosAngle); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2LinePointDistance +( + FXMVECTOR LinePoint1, + FXMVECTOR LinePoint2, + FXMVECTOR Point +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR PointVector; + XMVECTOR LineVector; + XMVECTOR ReciprocalLengthSq; + XMVECTOR PointProjectionScale; + XMVECTOR DistanceVector; + XMVECTOR Result; + + // Given a vector PointVector from LinePoint1 to Point and a vector + // LineVector from LinePoint1 to LinePoint2, the scaled distance + // PointProjectionScale from LinePoint1 to the perpendicular projection + // of PointVector onto the line is defined as: + // + // PointProjectionScale = dot(PointVector, LineVector) / LengthSq(LineVector) + + PointVector = XMVectorSubtract(Point, LinePoint1); + LineVector = XMVectorSubtract(LinePoint2, LinePoint1); + + ReciprocalLengthSq = XMVector2LengthSq(LineVector); + ReciprocalLengthSq = XMVectorReciprocal(ReciprocalLengthSq); + + PointProjectionScale = XMVector2Dot(PointVector, LineVector); + PointProjectionScale = XMVectorMultiply(PointProjectionScale, ReciprocalLengthSq); + + DistanceVector = XMVectorMultiply(LineVector, PointProjectionScale); + DistanceVector = XMVectorSubtract(PointVector, DistanceVector); + + Result = XMVector2Length(DistanceVector); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR PointVector = _mm_sub_ps(Point,LinePoint1); + XMVECTOR LineVector = _mm_sub_ps(LinePoint2,LinePoint1); + XMVECTOR ReciprocalLengthSq = XMVector2LengthSq(LineVector); + XMVECTOR vResult = XMVector2Dot(PointVector,LineVector); + vResult = _mm_div_ps(vResult,ReciprocalLengthSq); + vResult = _mm_mul_ps(vResult,LineVector); + vResult = _mm_sub_ps(PointVector,vResult); + vResult = XMVector2Length(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2IntersectLine +( + FXMVECTOR Line1Point1, + FXMVECTOR Line1Point2, + FXMVECTOR Line2Point1, + CXMVECTOR Line2Point2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V1; + XMVECTOR V2; + XMVECTOR V3; + XMVECTOR C1; + XMVECTOR C2; + XMVECTOR Result; + CONST XMVECTOR Zero = XMVectorZero(); + + V1 = XMVectorSubtract(Line1Point2, Line1Point1); + V2 = XMVectorSubtract(Line2Point2, Line2Point1); + V3 = XMVectorSubtract(Line1Point1, Line2Point1); + + C1 = XMVector2Cross(V1, V2); + C2 = XMVector2Cross(V2, V3); + + if (XMVector2NearEqual(C1, Zero, g_XMEpsilon.v)) + { + if (XMVector2NearEqual(C2, Zero, g_XMEpsilon.v)) + { + // Coincident + Result = g_XMInfinity.v; + } + else + { + // Parallel + Result = g_XMQNaN.v; + } + } + else + { + // Intersection point = Line1Point1 + V1 * (C2 / C1) + XMVECTOR Scale; + Scale = XMVectorReciprocal(C1); + Scale = XMVectorMultiply(C2, Scale); + Result = XMVectorMultiplyAdd(V1, Scale, Line1Point1); + } + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR V1 = _mm_sub_ps(Line1Point2, Line1Point1); + XMVECTOR V2 = _mm_sub_ps(Line2Point2, Line2Point1); + XMVECTOR V3 = _mm_sub_ps(Line1Point1, Line2Point1); + // Generate the cross products + XMVECTOR C1 = XMVector2Cross(V1, V2); + XMVECTOR C2 = XMVector2Cross(V2, V3); + // If C1 is not close to epsilon, use the calculated value + XMVECTOR vResultMask = _mm_setzero_ps(); + vResultMask = _mm_sub_ps(vResultMask,C1); + vResultMask = _mm_max_ps(vResultMask,C1); + // 0xFFFFFFFF if the calculated value is to be used + vResultMask = _mm_cmpgt_ps(vResultMask,g_XMEpsilon); + // If C1 is close to epsilon, which fail type is it? INFINITY or NAN? + XMVECTOR vFailMask = _mm_setzero_ps(); + vFailMask = _mm_sub_ps(vFailMask,C2); + vFailMask = _mm_max_ps(vFailMask,C2); + vFailMask = _mm_cmple_ps(vFailMask,g_XMEpsilon); + XMVECTOR vFail = _mm_and_ps(vFailMask,g_XMInfinity); + vFailMask = _mm_andnot_ps(vFailMask,g_XMQNaN); + // vFail is NAN or INF + vFail = _mm_or_ps(vFail,vFailMask); + // Intersection point = Line1Point1 + V1 * (C2 / C1) + XMVECTOR vResult = _mm_div_ps(C2,C1); + vResult = _mm_mul_ps(vResult,V1); + vResult = _mm_add_ps(vResult,Line1Point1); + // Use result, or failure value + vResult = _mm_and_ps(vResult,vResultMask); + vResultMask = _mm_andnot_ps(vResultMask,vFail); + vResult = _mm_or_ps(vResult,vResultMask); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2Transform +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Result; + + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiplyAdd(Y, M.r[1], M.r[3]); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,M.r[0]); + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + vTemp = _mm_mul_ps(vTemp,M.r[1]); + vResult = _mm_add_ps(vResult,vTemp); + vResult = _mm_add_ps(vResult,M.r[3]); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT4* XMVector2TransformStream +( + XMFLOAT4* pOutputStream, + size_t OutputStride, + CONST XMFLOAT2* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat2((const XMFLOAT2*)pInputVector); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); +// Y = XMVectorReplicate(((XMFLOAT2*)pInputVector)->y); +// X = XMVectorReplicate(((XMFLOAT2*)pInputVector)->x); + + Result = XMVectorMultiplyAdd(Y, M.r[1], M.r[3]); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + XMStoreFloat4((XMFLOAT4*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + for (i = 0; i < VectorCount; i++) + { + XMVECTOR X = _mm_load_ps1(&reinterpret_cast(pInputVector)->x); + XMVECTOR vResult = _mm_load_ps1(&reinterpret_cast(pInputVector)->y); + vResult = _mm_mul_ps(vResult,M.r[1]); + vResult = _mm_add_ps(vResult,M.r[3]); + X = _mm_mul_ps(X,M.r[0]); + vResult = _mm_add_ps(vResult,X); + _mm_storeu_ps(reinterpret_cast(pOutputVector),vResult); + pInputVector += InputStride; + pOutputVector += OutputStride; + } + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT4* XMVector2TransformStreamNC +( + XMFLOAT4* pOutputStream, + size_t OutputStride, + CONST XMFLOAT2* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) || defined(_XM_SSE_INTRINSICS_) + return XMVector2TransformStream( pOutputStream, OutputStride, pInputStream, InputStride, VectorCount, M ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2TransformCoord +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR InverseW; + XMVECTOR Result; + + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiplyAdd(Y, M.r[1], M.r[3]); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + InverseW = XMVectorSplatW(Result); + InverseW = XMVectorReciprocal(InverseW); + + Result = XMVectorMultiply(Result, InverseW); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,M.r[0]); + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + vTemp = _mm_mul_ps(vTemp,M.r[1]); + vResult = _mm_add_ps(vResult,vTemp); + vResult = _mm_add_ps(vResult,M.r[3]); + vTemp = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,3,3,3)); + vResult = _mm_div_ps(vResult,vTemp); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT2* XMVector2TransformCoordStream +( + XMFLOAT2* pOutputStream, + size_t OutputStride, + CONST XMFLOAT2* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR InverseW; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat2((const XMFLOAT2*)pInputVector); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); +// Y = XMVectorReplicate(((XMFLOAT2*)pInputVector)->y); +// X = XMVectorReplicate(((XMFLOAT2*)pInputVector)->x); + + Result = XMVectorMultiplyAdd(Y, M.r[1], M.r[3]); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + InverseW = XMVectorSplatW(Result); + InverseW = XMVectorReciprocal(InverseW); + + Result = XMVectorMultiply(Result, InverseW); + + XMStoreFloat2((XMFLOAT2*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + size_t i; + CONST BYTE *pInputVector = (CONST BYTE*)pInputStream; + BYTE *pOutputVector = (BYTE*)pOutputStream; + + for (i = 0; i < VectorCount; i++) + { + XMVECTOR X = _mm_load_ps1(&reinterpret_cast(pInputVector)->x); + XMVECTOR vResult = _mm_load_ps1(&reinterpret_cast(pInputVector)->y); + vResult = _mm_mul_ps(vResult,M.r[1]); + vResult = _mm_add_ps(vResult,M.r[3]); + X = _mm_mul_ps(X,M.r[0]); + vResult = _mm_add_ps(vResult,X); + X = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,3,3,3)); + vResult = _mm_div_ps(vResult,X); + _mm_store_sd(reinterpret_cast(pOutputVector),reinterpret_cast<__m128d *>(&vResult)[0]); + pInputVector += InputStride; + pOutputVector += OutputStride; + } + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector2TransformNormal +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Result; + + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiply(Y, M.r[1]); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,M.r[0]); + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + vTemp = _mm_mul_ps(vTemp,M.r[1]); + vResult = _mm_add_ps(vResult,vTemp); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT2* XMVector2TransformNormalStream +( + XMFLOAT2* pOutputStream, + size_t OutputStride, + CONST XMFLOAT2* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat2((const XMFLOAT2*)pInputVector); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); +// Y = XMVectorReplicate(((XMFLOAT2*)pInputVector)->y); +// X = XMVectorReplicate(((XMFLOAT2*)pInputVector)->x); + + Result = XMVectorMultiply(Y, M.r[1]); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + XMStoreFloat2((XMFLOAT2*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + size_t i; + CONST BYTE*pInputVector = (CONST BYTE*)pInputStream; + BYTE *pOutputVector = (BYTE*)pOutputStream; + for (i = 0; i < VectorCount; i++) + { + XMVECTOR X = _mm_load_ps1(&reinterpret_cast(pInputVector)->x); + XMVECTOR vResult = _mm_load_ps1(&reinterpret_cast(pInputVector)->y); + vResult = _mm_mul_ps(vResult,M.r[1]); + X = _mm_mul_ps(X,M.r[0]); + vResult = _mm_add_ps(vResult,X); + _mm_store_sd(reinterpret_cast(pOutputVector),reinterpret_cast(&vResult)[0]); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +/**************************************************************************** + * + * 3D Vector + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3Equal +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] == V2.vector4_f32[0]) && (V1.vector4_f32[1] == V2.vector4_f32[1]) && (V1.vector4_f32[2] == V2.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&7)==7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector3EqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector3EqualR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V1.vector4_f32[0] == V2.vector4_f32[0]) && + (V1.vector4_f32[1] == V2.vector4_f32[1]) && + (V1.vector4_f32[2] == V2.vector4_f32[2])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] != V2.vector4_f32[0]) && + (V1.vector4_f32[1] != V2.vector4_f32[1]) && + (V1.vector4_f32[2] != V2.vector4_f32[2])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); + int iTest = _mm_movemask_ps(vTemp)&7; + UINT CR = 0; + if (iTest==7) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3EqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_u32[0] == V2.vector4_u32[0]) && (V1.vector4_u32[1] == V2.vector4_u32[1]) && (V1.vector4_u32[2] == V2.vector4_u32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + return (((_mm_movemask_ps(reinterpret_cast(&vTemp)[0])&7)==7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector3EqualIntR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector3EqualIntR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V1.vector4_u32[0] == V2.vector4_u32[0]) && + (V1.vector4_u32[1] == V2.vector4_u32[1]) && + (V1.vector4_u32[2] == V2.vector4_u32[2])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_u32[0] != V2.vector4_u32[0]) && + (V1.vector4_u32[1] != V2.vector4_u32[1]) && + (V1.vector4_u32[2] != V2.vector4_u32[2])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + int iTemp = _mm_movemask_ps(reinterpret_cast(&vTemp)[0])&7; + UINT CR = 0; + if (iTemp==7) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTemp) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3NearEqual +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR Epsilon +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT dx, dy, dz; + + dx = fabsf(V1.vector4_f32[0]-V2.vector4_f32[0]); + dy = fabsf(V1.vector4_f32[1]-V2.vector4_f32[1]); + dz = fabsf(V1.vector4_f32[2]-V2.vector4_f32[2]); + return (((dx <= Epsilon.vector4_f32[0]) && + (dy <= Epsilon.vector4_f32[1]) && + (dz <= Epsilon.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + // Get the difference + XMVECTOR vDelta = _mm_sub_ps(V1,V2); + // Get the absolute value of the difference + XMVECTOR vTemp = _mm_setzero_ps(); + vTemp = _mm_sub_ps(vTemp,vDelta); + vTemp = _mm_max_ps(vTemp,vDelta); + vTemp = _mm_cmple_ps(vTemp,Epsilon); + // w is don't care + return (((_mm_movemask_ps(vTemp)&7)==0x7) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3NotEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] != V2.vector4_f32[0]) || (V1.vector4_f32[1] != V2.vector4_f32[1]) || (V1.vector4_f32[2] != V2.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&7)!=7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAnyFalse(XMVector3EqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3NotEqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_u32[0] != V2.vector4_u32[0]) || (V1.vector4_u32[1] != V2.vector4_u32[1]) || (V1.vector4_u32[2] != V2.vector4_u32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + return (((_mm_movemask_ps(reinterpret_cast(&vTemp)[0])&7)!=7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAnyFalse(XMVector3EqualIntR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3Greater +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] > V2.vector4_f32[0]) && (V1.vector4_f32[1] > V2.vector4_f32[1]) && (V1.vector4_f32[2] > V2.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&7)==7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector3GreaterR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector3GreaterR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V1.vector4_f32[0] > V2.vector4_f32[0]) && + (V1.vector4_f32[1] > V2.vector4_f32[1]) && + (V1.vector4_f32[2] > V2.vector4_f32[2])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] <= V2.vector4_f32[0]) && + (V1.vector4_f32[1] <= V2.vector4_f32[1]) && + (V1.vector4_f32[2] <= V2.vector4_f32[2])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); + UINT CR = 0; + int iTest = _mm_movemask_ps(vTemp)&7; + if (iTest==7) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3GreaterOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] >= V2.vector4_f32[0]) && (V1.vector4_f32[1] >= V2.vector4_f32[1]) && (V1.vector4_f32[2] >= V2.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&7)==7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector3GreaterOrEqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector3GreaterOrEqualR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + UINT CR = 0; + if ((V1.vector4_f32[0] >= V2.vector4_f32[0]) && + (V1.vector4_f32[1] >= V2.vector4_f32[1]) && + (V1.vector4_f32[2] >= V2.vector4_f32[2])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] < V2.vector4_f32[0]) && + (V1.vector4_f32[1] < V2.vector4_f32[1]) && + (V1.vector4_f32[2] < V2.vector4_f32[2])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + UINT CR = 0; + int iTest = _mm_movemask_ps(vTemp)&7; + if (iTest==7) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3Less +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] < V2.vector4_f32[0]) && (V1.vector4_f32[1] < V2.vector4_f32[1]) && (V1.vector4_f32[2] < V2.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmplt_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&7)==7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector3GreaterR(V2, V1)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3LessOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] <= V2.vector4_f32[0]) && (V1.vector4_f32[1] <= V2.vector4_f32[1]) && (V1.vector4_f32[2] <= V2.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmple_ps(V1,V2); + return (((_mm_movemask_ps(vTemp)&7)==7) != 0); +#else // _XM_VMX128_INTRINSICS_ + return XMComparisonAllTrue(XMVector3GreaterOrEqualR(V2, V1)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3InBounds +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) && + (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1]) && + (V.vector4_f32[2] <= Bounds.vector4_f32[2] && V.vector4_f32[2] >= -Bounds.vector4_f32[2])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + // x,y and z in bounds? (w is don't care) + return (((_mm_movemask_ps(vTemp1)&0x7)==0x7) != 0); +#else + return XMComparisonAllInBounds(XMVector3InBoundsR(V, Bounds)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector3InBoundsR +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) && + (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1]) && + (V.vector4_f32[2] <= Bounds.vector4_f32[2] && V.vector4_f32[2] >= -Bounds.vector4_f32[2])) + { + CR = XM_CRMASK_CR6BOUNDS; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + // x,y and z in bounds? (w is don't care) + return ((_mm_movemask_ps(vTemp1)&0x7)==0x7) ? XM_CRMASK_CR6BOUNDS : 0; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3IsNaN +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return (XMISNAN(V.vector4_f32[0]) || + XMISNAN(V.vector4_f32[1]) || + XMISNAN(V.vector4_f32[2])); + +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the exponent + __m128i vTempInf = _mm_and_si128(reinterpret_cast(&V)[0],g_XMInfinity); + // Mask off the mantissa + __m128i vTempNan = _mm_and_si128(reinterpret_cast(&V)[0],g_XMQNaNTest); + // Are any of the exponents == 0x7F800000? + vTempInf = _mm_cmpeq_epi32(vTempInf,g_XMInfinity); + // Are any of the mantissa's zero? (SSE2 doesn't have a neq test) + vTempNan = _mm_cmpeq_epi32(vTempNan,g_XMZero); + // Perform a not on the NaN test to be true on NON-zero mantissas + vTempNan = _mm_andnot_si128(vTempNan,vTempInf); + // If x, y or z are NaN, the signs are true after the merge above + return ((_mm_movemask_ps(reinterpret_cast(&vTempNan)[0])&7) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector3IsInfinite +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (XMISINF(V.vector4_f32[0]) || + XMISINF(V.vector4_f32[1]) || + XMISINF(V.vector4_f32[2])); +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the sign bit + __m128 vTemp = _mm_and_ps(V,g_XMAbsMask); + // Compare to infinity + vTemp = _mm_cmpeq_ps(vTemp,g_XMInfinity); + // If x,y or z are infinity, the signs are true. + return ((_mm_movemask_ps(vTemp)&7) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Dot +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fValue = V1.vector4_f32[0] * V2.vector4_f32[0] + V1.vector4_f32[1] * V2.vector4_f32[1] + V1.vector4_f32[2] * V2.vector4_f32[2]; + XMVECTOR vResult = { + fValue, + fValue, + fValue, + fValue + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product + XMVECTOR vDot = _mm_mul_ps(V1,V2); + // x=Dot.vector4_f32[1], y=Dot.vector4_f32[2] + XMVECTOR vTemp = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(2,1,2,1)); + // Result.vector4_f32[0] = x+y + vDot = _mm_add_ss(vDot,vTemp); + // x=Dot.vector4_f32[2] + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // Result.vector4_f32[0] = (x+y)+z + vDot = _mm_add_ss(vDot,vTemp); + // Splat x + return _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(0,0,0,0)); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Cross +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR vResult = { + (V1.vector4_f32[1] * V2.vector4_f32[2]) - (V1.vector4_f32[2] * V2.vector4_f32[1]), + (V1.vector4_f32[2] * V2.vector4_f32[0]) - (V1.vector4_f32[0] * V2.vector4_f32[2]), + (V1.vector4_f32[0] * V2.vector4_f32[1]) - (V1.vector4_f32[1] * V2.vector4_f32[0]), + 0.0f + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // y1,z1,x1,w1 + XMVECTOR vTemp1 = _mm_shuffle_ps(V1,V1,_MM_SHUFFLE(3,0,2,1)); + // z2,x2,y2,w2 + XMVECTOR vTemp2 = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(3,1,0,2)); + // Perform the left operation + XMVECTOR vResult = _mm_mul_ps(vTemp1,vTemp2); + // z1,x1,y1,w1 + vTemp1 = _mm_shuffle_ps(vTemp1,vTemp1,_MM_SHUFFLE(3,0,2,1)); + // y2,z2,x2,w2 + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(3,1,0,2)); + // Perform the right operation + vTemp1 = _mm_mul_ps(vTemp1,vTemp2); + // Subract the right from left, and return answer + vResult = _mm_sub_ps(vResult,vTemp1); + // Set w to zero + return _mm_and_ps(vResult,g_XMMask3); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3LengthSq +( + FXMVECTOR V +) +{ + return XMVector3Dot(V, V); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3ReciprocalLengthEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector3LengthSq(V); + Result = XMVectorReciprocalSqrtEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y and z + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and y + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,2,1,2)); + // x+z, y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + // y,y,y,y + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // x+z+y,??,??,?? + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + // Splat the length squared + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + // Get the reciprocal + vLengthSq = _mm_rsqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3ReciprocalLength +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector3LengthSq(V); + Result = XMVectorReciprocalSqrt(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product + XMVECTOR vDot = _mm_mul_ps(V,V); + // x=Dot.y, y=Dot.z + XMVECTOR vTemp = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(2,1,2,1)); + // Result.x = x+y + vDot = _mm_add_ss(vDot,vTemp); + // x=Dot.z + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // Result.x = (x+y)+z + vDot = _mm_add_ss(vDot,vTemp); + // Splat x + vDot = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(0,0,0,0)); + // Get the reciprocal + vDot = _mm_sqrt_ps(vDot); + // Get the reciprocal + vDot = _mm_div_ps(g_XMOne,vDot); + return vDot; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3LengthEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector3LengthSq(V); + Result = XMVectorSqrtEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y and z + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and y + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,2,1,2)); + // x+z, y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + // y,y,y,y + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // x+z+y,??,??,?? + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + // Splat the length squared + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + // Get the length + vLengthSq = _mm_sqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Length +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector3LengthSq(V); + Result = XMVectorSqrt(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y and z + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and y + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,2,1,2)); + // x+z, y + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + // y,y,y,y + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // x+z+y,??,??,?? + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + // Splat the length squared + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + // Get the length + vLengthSq = _mm_sqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// XMVector3NormalizeEst uses a reciprocal estimate and +// returns QNaN on zero and infinite vectors. + +XMFINLINE XMVECTOR XMVector3NormalizeEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result = XMVector3ReciprocalLength(V); + Result = XMVectorMultiply(V, Result); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product + XMVECTOR vDot = _mm_mul_ps(V,V); + // x=Dot.y, y=Dot.z + XMVECTOR vTemp = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(2,1,2,1)); + // Result.x = x+y + vDot = _mm_add_ss(vDot,vTemp); + // x=Dot.z + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + // Result.x = (x+y)+z + vDot = _mm_add_ss(vDot,vTemp); + // Splat x + vDot = _mm_shuffle_ps(vDot,vDot,_MM_SHUFFLE(0,0,0,0)); + // Get the reciprocal + vDot = _mm_rsqrt_ps(vDot); + // Perform the normalization + vDot = _mm_mul_ps(vDot,V); + return vDot; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Normalize +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fLength; + XMVECTOR vResult; + + vResult = XMVector3Length( V ); + fLength = vResult.vector4_f32[0]; + + // Prevent divide by zero + if (fLength > 0) { + fLength = 1.0f/fLength; + } + + vResult.vector4_f32[0] = V.vector4_f32[0]*fLength; + vResult.vector4_f32[1] = V.vector4_f32[1]*fLength; + vResult.vector4_f32[2] = V.vector4_f32[2]*fLength; + vResult.vector4_f32[3] = V.vector4_f32[3]*fLength; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y and z only + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,1,2,1)); + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vTemp = _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(1,1,1,1)); + vLengthSq = _mm_add_ss(vLengthSq,vTemp); + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(0,0,0,0)); + // Prepare for the division + XMVECTOR vResult = _mm_sqrt_ps(vLengthSq); + // Create zero with a single instruction + XMVECTOR vZeroMask = _mm_setzero_ps(); + // Test for a divide by zero (Must be FP to detect -0.0) + vZeroMask = _mm_cmpneq_ps(vZeroMask,vResult); + // Failsafe on zero (Or epsilon) length planes + // If the length is infinity, set the elements to zero + vLengthSq = _mm_cmpneq_ps(vLengthSq,g_XMInfinity); + // Divide to perform the normalization + vResult = _mm_div_ps(V,vResult); + // Any that are infinity, set to zero + vResult = _mm_and_ps(vResult,vZeroMask); + // Select qnan or result based on infinite length + XMVECTOR vTemp1 = _mm_andnot_ps(vLengthSq,g_XMQNaN); + XMVECTOR vTemp2 = _mm_and_ps(vResult,vLengthSq); + vResult = _mm_or_ps(vTemp1,vTemp2); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3ClampLength +( + FXMVECTOR V, + FLOAT LengthMin, + FLOAT LengthMax +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR ClampMax; + XMVECTOR ClampMin; + + ClampMax = XMVectorReplicate(LengthMax); + ClampMin = XMVectorReplicate(LengthMin); + + return XMVector3ClampLengthV(V, ClampMin, ClampMax); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR ClampMax = _mm_set_ps1(LengthMax); + XMVECTOR ClampMin = _mm_set_ps1(LengthMin); + return XMVector3ClampLengthV(V,ClampMin,ClampMax); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3ClampLengthV +( + FXMVECTOR V, + FXMVECTOR LengthMin, + FXMVECTOR LengthMax +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR ClampLength; + XMVECTOR LengthSq; + XMVECTOR RcpLength; + XMVECTOR Length; + XMVECTOR Normal; + XMVECTOR Zero; + XMVECTOR InfiniteLength; + XMVECTOR ZeroLength; + XMVECTOR Select; + XMVECTOR ControlMax; + XMVECTOR ControlMin; + XMVECTOR Control; + XMVECTOR Result; + + XMASSERT((LengthMin.vector4_f32[1] == LengthMin.vector4_f32[0]) && (LengthMin.vector4_f32[2] == LengthMin.vector4_f32[0])); + XMASSERT((LengthMax.vector4_f32[1] == LengthMax.vector4_f32[0]) && (LengthMax.vector4_f32[2] == LengthMax.vector4_f32[0])); + XMASSERT(XMVector3GreaterOrEqual(LengthMin, XMVectorZero())); + XMASSERT(XMVector3GreaterOrEqual(LengthMax, XMVectorZero())); + XMASSERT(XMVector3GreaterOrEqual(LengthMax, LengthMin)); + + LengthSq = XMVector3LengthSq(V); + + Zero = XMVectorZero(); + + RcpLength = XMVectorReciprocalSqrt(LengthSq); + + InfiniteLength = XMVectorEqualInt(LengthSq, g_XMInfinity.v); + ZeroLength = XMVectorEqual(LengthSq, Zero); + + Normal = XMVectorMultiply(V, RcpLength); + + Length = XMVectorMultiply(LengthSq, RcpLength); + + Select = XMVectorEqualInt(InfiniteLength, ZeroLength); + Length = XMVectorSelect(LengthSq, Length, Select); + Normal = XMVectorSelect(LengthSq, Normal, Select); + + ControlMax = XMVectorGreater(Length, LengthMax); + ControlMin = XMVectorLess(Length, LengthMin); + + ClampLength = XMVectorSelect(Length, LengthMax, ControlMax); + ClampLength = XMVectorSelect(ClampLength, LengthMin, ControlMin); + + Result = XMVectorMultiply(Normal, ClampLength); + + // Preserve the original vector (with no precision loss) if the length falls within the given range + Control = XMVectorEqualInt(ControlMax, ControlMin); + Result = XMVectorSelect(Result, V, Control); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR ClampLength; + XMVECTOR LengthSq; + XMVECTOR RcpLength; + XMVECTOR Length; + XMVECTOR Normal; + XMVECTOR InfiniteLength; + XMVECTOR ZeroLength; + XMVECTOR Select; + XMVECTOR ControlMax; + XMVECTOR ControlMin; + XMVECTOR Control; + XMVECTOR Result; + + XMASSERT((XMVectorGetY(LengthMin) == XMVectorGetX(LengthMin)) && (XMVectorGetZ(LengthMin) == XMVectorGetX(LengthMin))); + XMASSERT((XMVectorGetY(LengthMax) == XMVectorGetX(LengthMax)) && (XMVectorGetZ(LengthMax) == XMVectorGetX(LengthMax))); + XMASSERT(XMVector3GreaterOrEqual(LengthMin, g_XMZero)); + XMASSERT(XMVector3GreaterOrEqual(LengthMax, g_XMZero)); + XMASSERT(XMVector3GreaterOrEqual(LengthMax, LengthMin)); + + LengthSq = XMVector3LengthSq(V); + RcpLength = XMVectorReciprocalSqrt(LengthSq); + InfiniteLength = XMVectorEqualInt(LengthSq, g_XMInfinity); + ZeroLength = XMVectorEqual(LengthSq,g_XMZero); + Normal = _mm_mul_ps(V, RcpLength); + Length = _mm_mul_ps(LengthSq, RcpLength); + Select = XMVectorEqualInt(InfiniteLength, ZeroLength); + Length = XMVectorSelect(LengthSq, Length, Select); + Normal = XMVectorSelect(LengthSq, Normal, Select); + ControlMax = XMVectorGreater(Length, LengthMax); + ControlMin = XMVectorLess(Length, LengthMin); + ClampLength = XMVectorSelect(Length, LengthMax, ControlMax); + ClampLength = XMVectorSelect(ClampLength, LengthMin, ControlMin); + Result = _mm_mul_ps(Normal, ClampLength); + // Preserve the original vector (with no precision loss) if the length falls within the given range + Control = XMVectorEqualInt(ControlMax, ControlMin); + Result = XMVectorSelect(Result, V, Control); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Reflect +( + FXMVECTOR Incident, + FXMVECTOR Normal +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + // Result = Incident - (2 * dot(Incident, Normal)) * Normal + Result = XMVector3Dot(Incident, Normal); + Result = XMVectorAdd(Result, Result); + Result = XMVectorNegativeMultiplySubtract(Result, Normal, Incident); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = Incident - (2 * dot(Incident, Normal)) * Normal + XMVECTOR Result = XMVector3Dot(Incident, Normal); + Result = _mm_add_ps(Result, Result); + Result = _mm_mul_ps(Result, Normal); + Result = _mm_sub_ps(Incident,Result); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Refract +( + FXMVECTOR Incident, + FXMVECTOR Normal, + FLOAT RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Index; + Index = XMVectorReplicate(RefractionIndex); + return XMVector3RefractV(Incident, Normal, Index); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Index = _mm_set_ps1(RefractionIndex); + return XMVector3RefractV(Incident,Normal,Index); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3RefractV +( + FXMVECTOR Incident, + FXMVECTOR Normal, + FXMVECTOR RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR IDotN; + XMVECTOR R; + CONST XMVECTOR Zero = XMVectorZero(); + + // Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + + // sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) + + IDotN = XMVector3Dot(Incident, Normal); + + // R = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) + R = XMVectorNegativeMultiplySubtract(IDotN, IDotN, g_XMOne.v); + R = XMVectorMultiply(R, RefractionIndex); + R = XMVectorNegativeMultiplySubtract(R, RefractionIndex, g_XMOne.v); + + if (XMVector4LessOrEqual(R, Zero)) + { + // Total internal reflection + return Zero; + } + else + { + XMVECTOR Result; + + // R = RefractionIndex * IDotN + sqrt(R) + R = XMVectorSqrt(R); + R = XMVectorMultiplyAdd(RefractionIndex, IDotN, R); + + // Result = RefractionIndex * Incident - Normal * R + Result = XMVectorMultiply(RefractionIndex, Incident); + Result = XMVectorNegativeMultiplySubtract(Normal, R, Result); + + return Result; + } + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + + // sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) + XMVECTOR IDotN = XMVector3Dot(Incident, Normal); + // R = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) + XMVECTOR R = _mm_mul_ps(IDotN, IDotN); + R = _mm_sub_ps(g_XMOne,R); + R = _mm_mul_ps(R, RefractionIndex); + R = _mm_mul_ps(R, RefractionIndex); + R = _mm_sub_ps(g_XMOne,R); + + XMVECTOR vResult = _mm_cmple_ps(R,g_XMZero); + if (_mm_movemask_ps(vResult)==0x0f) + { + // Total internal reflection + vResult = g_XMZero; + } + else + { + // R = RefractionIndex * IDotN + sqrt(R) + R = _mm_sqrt_ps(R); + vResult = _mm_mul_ps(RefractionIndex,IDotN); + R = _mm_add_ps(R,vResult); + // Result = RefractionIndex * Incident - Normal * R + vResult = _mm_mul_ps(RefractionIndex, Incident); + R = _mm_mul_ps(R,Normal); + vResult = _mm_sub_ps(vResult,R); + } + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Orthogonal +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegativeV; + XMVECTOR Z, YZYY; + XMVECTOR ZIsNegative, YZYYIsNegative; + XMVECTOR S, D; + XMVECTOR R0, R1; + XMVECTOR Select; + XMVECTOR Zero; + XMVECTOR Result; + static CONST XMVECTORU32 Permute1X0X0X0X = {XM_PERMUTE_1X, XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0X}; + static CONST XMVECTORU32 Permute0Y0Z0Y0Y= {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_0Y}; + + Zero = XMVectorZero(); + Z = XMVectorSplatZ(V); + YZYY = XMVectorPermute(V, V, Permute0Y0Z0Y0Y.v); + + NegativeV = XMVectorSubtract(Zero, V); + + ZIsNegative = XMVectorLess(Z, Zero); + YZYYIsNegative = XMVectorLess(YZYY, Zero); + + S = XMVectorAdd(YZYY, Z); + D = XMVectorSubtract(YZYY, Z); + + Select = XMVectorEqualInt(ZIsNegative, YZYYIsNegative); + + R0 = XMVectorPermute(NegativeV, S, Permute1X0X0X0X.v); + R1 = XMVectorPermute(V, D, Permute1X0X0X0X.v); + + Result = XMVectorSelect(R1, R0, Select); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR NegativeV; + XMVECTOR Z, YZYY; + XMVECTOR ZIsNegative, YZYYIsNegative; + XMVECTOR S, D; + XMVECTOR R0, R1; + XMVECTOR Select; + XMVECTOR Zero; + XMVECTOR Result; + static CONST XMVECTORI32 Permute1X0X0X0X = {XM_PERMUTE_1X, XM_PERMUTE_0X, XM_PERMUTE_0X, XM_PERMUTE_0X}; + static CONST XMVECTORI32 Permute0Y0Z0Y0Y= {XM_PERMUTE_0Y, XM_PERMUTE_0Z, XM_PERMUTE_0Y, XM_PERMUTE_0Y}; + + Zero = XMVectorZero(); + Z = XMVectorSplatZ(V); + YZYY = XMVectorPermute(V, V, Permute0Y0Z0Y0Y); + + NegativeV = _mm_sub_ps(Zero, V); + + ZIsNegative = XMVectorLess(Z, Zero); + YZYYIsNegative = XMVectorLess(YZYY, Zero); + + S = _mm_add_ps(YZYY, Z); + D = _mm_sub_ps(YZYY, Z); + + Select = XMVectorEqualInt(ZIsNegative, YZYYIsNegative); + + R0 = XMVectorPermute(NegativeV, S, Permute1X0X0X0X); + R1 = XMVectorPermute(V, D,Permute1X0X0X0X); + Result = XMVectorSelect(R1, R0, Select); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3AngleBetweenNormalsEst +( + FXMVECTOR N1, + FXMVECTOR N2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + XMVECTOR NegativeOne; + XMVECTOR One; + + Result = XMVector3Dot(N1, N2); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + Result = XMVectorClamp(Result, NegativeOne, One); + Result = XMVectorACosEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = XMVector3Dot(N1,N2); + // Clamp to -1.0f to 1.0f + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + vResult = XMVectorACosEst(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3AngleBetweenNormals +( + FXMVECTOR N1, + FXMVECTOR N2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + XMVECTOR NegativeOne; + XMVECTOR One; + + Result = XMVector3Dot(N1, N2); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + Result = XMVectorClamp(Result, NegativeOne, One); + Result = XMVectorACos(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = XMVector3Dot(N1,N2); + // Clamp to -1.0f to 1.0f + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne); + vResult = XMVectorACos(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3AngleBetweenVectors +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR L1; + XMVECTOR L2; + XMVECTOR Dot; + XMVECTOR CosAngle; + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + L1 = XMVector3ReciprocalLength(V1); + L2 = XMVector3ReciprocalLength(V2); + + Dot = XMVector3Dot(V1, V2); + + L1 = XMVectorMultiply(L1, L2); + + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + + CosAngle = XMVectorMultiply(Dot, L1); + + CosAngle = XMVectorClamp(CosAngle, NegativeOne, One); + + Result = XMVectorACos(CosAngle); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR L1; + XMVECTOR L2; + XMVECTOR Dot; + XMVECTOR CosAngle; + XMVECTOR Result; + + L1 = XMVector3ReciprocalLength(V1); + L2 = XMVector3ReciprocalLength(V2); + Dot = XMVector3Dot(V1, V2); + L1 = _mm_mul_ps(L1, L2); + CosAngle = _mm_mul_ps(Dot, L1); + CosAngle = XMVectorClamp(CosAngle,g_XMNegativeOne,g_XMOne); + Result = XMVectorACos(CosAngle); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3LinePointDistance +( + FXMVECTOR LinePoint1, + FXMVECTOR LinePoint2, + FXMVECTOR Point +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR PointVector; + XMVECTOR LineVector; + XMVECTOR ReciprocalLengthSq; + XMVECTOR PointProjectionScale; + XMVECTOR DistanceVector; + XMVECTOR Result; + + // Given a vector PointVector from LinePoint1 to Point and a vector + // LineVector from LinePoint1 to LinePoint2, the scaled distance + // PointProjectionScale from LinePoint1 to the perpendicular projection + // of PointVector onto the line is defined as: + // + // PointProjectionScale = dot(PointVector, LineVector) / LengthSq(LineVector) + + PointVector = XMVectorSubtract(Point, LinePoint1); + LineVector = XMVectorSubtract(LinePoint2, LinePoint1); + + ReciprocalLengthSq = XMVector3LengthSq(LineVector); + ReciprocalLengthSq = XMVectorReciprocal(ReciprocalLengthSq); + + PointProjectionScale = XMVector3Dot(PointVector, LineVector); + PointProjectionScale = XMVectorMultiply(PointProjectionScale, ReciprocalLengthSq); + + DistanceVector = XMVectorMultiply(LineVector, PointProjectionScale); + DistanceVector = XMVectorSubtract(PointVector, DistanceVector); + + Result = XMVector3Length(DistanceVector); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR PointVector = _mm_sub_ps(Point,LinePoint1); + XMVECTOR LineVector = _mm_sub_ps(LinePoint2,LinePoint1); + XMVECTOR ReciprocalLengthSq = XMVector3LengthSq(LineVector); + XMVECTOR vResult = XMVector3Dot(PointVector,LineVector); + vResult = _mm_div_ps(vResult,ReciprocalLengthSq); + vResult = _mm_mul_ps(vResult,LineVector); + vResult = _mm_sub_ps(PointVector,vResult); + vResult = XMVector3Length(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE VOID XMVector3ComponentsFromNormal +( + XMVECTOR* pParallel, + XMVECTOR* pPerpendicular, + FXMVECTOR V, + FXMVECTOR Normal +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Parallel; + XMVECTOR Scale; + + XMASSERT(pParallel); + XMASSERT(pPerpendicular); + + Scale = XMVector3Dot(V, Normal); + + Parallel = XMVectorMultiply(Normal, Scale); + + *pParallel = Parallel; + *pPerpendicular = XMVectorSubtract(V, Parallel); + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pParallel); + XMASSERT(pPerpendicular); + XMVECTOR Scale = XMVector3Dot(V, Normal); + XMVECTOR Parallel = _mm_mul_ps(Normal,Scale); + *pParallel = Parallel; + *pPerpendicular = _mm_sub_ps(V,Parallel); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Transform a vector using a rotation expressed as a unit quaternion + +XMFINLINE XMVECTOR XMVector3Rotate +( + FXMVECTOR V, + FXMVECTOR RotationQuaternion +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR A; + XMVECTOR Q; + XMVECTOR Result; + + A = XMVectorSelect(g_XMSelect1110.v, V, g_XMSelect1110.v); + Q = XMQuaternionConjugate(RotationQuaternion); + Result = XMQuaternionMultiply(Q, A); + Result = XMQuaternionMultiply(Result, RotationQuaternion); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR A; + XMVECTOR Q; + XMVECTOR Result; + + A = _mm_and_ps(V,g_XMMask3); + Q = XMQuaternionConjugate(RotationQuaternion); + Result = XMQuaternionMultiply(Q, A); + Result = XMQuaternionMultiply(Result, RotationQuaternion); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Transform a vector using the inverse of a rotation expressed as a unit quaternion + +XMFINLINE XMVECTOR XMVector3InverseRotate +( + FXMVECTOR V, + FXMVECTOR RotationQuaternion +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR A; + XMVECTOR Q; + XMVECTOR Result; + + A = XMVectorSelect(g_XMSelect1110.v, V, g_XMSelect1110.v); + Result = XMQuaternionMultiply(RotationQuaternion, A); + Q = XMQuaternionConjugate(RotationQuaternion); + Result = XMQuaternionMultiply(Result, Q); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR A; + XMVECTOR Q; + XMVECTOR Result; + A = _mm_and_ps(V,g_XMMask3); + Result = XMQuaternionMultiply(RotationQuaternion, A); + Q = XMQuaternionConjugate(RotationQuaternion); + Result = XMQuaternionMultiply(Result, Q); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Transform +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR Result; + + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiplyAdd(Z, M.r[2], M.r[3]); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,M.r[0]); + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + vTemp = _mm_mul_ps(vTemp,M.r[1]); + vResult = _mm_add_ps(vResult,vTemp); + vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + vTemp = _mm_mul_ps(vTemp,M.r[2]); + vResult = _mm_add_ps(vResult,vTemp); + vResult = _mm_add_ps(vResult,M.r[3]); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT4* XMVector3TransformStream +( + XMFLOAT4* pOutputStream, + size_t OutputStride, + CONST XMFLOAT3* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiplyAdd(Z, M.r[2], M.r[3]); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + XMStoreFloat4((XMFLOAT4*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + for (i = 0; i < VectorCount; i++) + { + XMVECTOR X = _mm_load_ps1(&reinterpret_cast(pInputVector)->x); + XMVECTOR Y = _mm_load_ps1(&reinterpret_cast(pInputVector)->y); + XMVECTOR vResult = _mm_load_ps1(&reinterpret_cast(pInputVector)->z); + vResult = _mm_mul_ps(vResult,M.r[2]); + vResult = _mm_add_ps(vResult,M.r[3]); + Y = _mm_mul_ps(Y,M.r[1]); + vResult = _mm_add_ps(vResult,Y); + X = _mm_mul_ps(X,M.r[0]); + vResult = _mm_add_ps(vResult,X); + _mm_storeu_ps(reinterpret_cast(pOutputVector),vResult); + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT4* XMVector3TransformStreamNC +( + XMFLOAT4* pOutputStream, + size_t OutputStride, + CONST XMFLOAT3* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS) || defined(_XM_SSE_INTRINSICS_) + return XMVector3TransformStream( pOutputStream, OutputStride, pInputStream, InputStride, VectorCount, M ); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3TransformCoord +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR InverseW; + XMVECTOR Result; + + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiplyAdd(Z, M.r[2], M.r[3]); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + InverseW = XMVectorSplatW(Result); + InverseW = XMVectorReciprocal(InverseW); + + Result = XMVectorMultiply(Result, InverseW); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,M.r[0]); + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + vTemp = _mm_mul_ps(vTemp,M.r[1]); + vResult = _mm_add_ps(vResult,vTemp); + vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + vTemp = _mm_mul_ps(vTemp,M.r[2]); + vResult = _mm_add_ps(vResult,vTemp); + vResult = _mm_add_ps(vResult,M.r[3]); + vTemp = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,3,3,3)); + vResult = _mm_div_ps(vResult,vTemp); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT3* XMVector3TransformCoordStream +( + XMFLOAT3* pOutputStream, + size_t OutputStride, + CONST XMFLOAT3* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR InverseW; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); +// Z = XMVectorReplicate(((XMFLOAT3*)pInputVector)->z); +// Y = XMVectorReplicate(((XMFLOAT3*)pInputVector)->y); +// X = XMVectorReplicate(((XMFLOAT3*)pInputVector)->x); + + Result = XMVectorMultiplyAdd(Z, M.r[2], M.r[3]); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + InverseW = XMVectorSplatW(Result); + InverseW = XMVectorReciprocal(InverseW); + + Result = XMVectorMultiply(Result, InverseW); + + XMStoreFloat3((XMFLOAT3*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + size_t i; + CONST BYTE *pInputVector = (CONST BYTE*)pInputStream; + BYTE *pOutputVector = (BYTE*)pOutputStream; + + for (i = 0; i < VectorCount; i++) + { + XMVECTOR X = _mm_load_ps1(&reinterpret_cast(pInputVector)->x); + XMVECTOR Y = _mm_load_ps1(&reinterpret_cast(pInputVector)->y); + XMVECTOR vResult = _mm_load_ps1(&reinterpret_cast(pInputVector)->z); + vResult = _mm_mul_ps(vResult,M.r[2]); + vResult = _mm_add_ps(vResult,M.r[3]); + Y = _mm_mul_ps(Y,M.r[1]); + vResult = _mm_add_ps(vResult,Y); + X = _mm_mul_ps(X,M.r[0]); + vResult = _mm_add_ps(vResult,X); + + X = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(3,3,3,3)); + vResult = _mm_div_ps(vResult,X); + _mm_store_ss(&reinterpret_cast(pOutputVector)->x,vResult); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + _mm_store_ss(&reinterpret_cast(pOutputVector)->y,vResult); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + _mm_store_ss(&reinterpret_cast(pOutputVector)->z,vResult); + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3TransformNormal +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR Result; + + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); + + Result = XMVectorMultiply(Z, M.r[2]); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + vResult = _mm_mul_ps(vResult,M.r[0]); + XMVECTOR vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + vTemp = _mm_mul_ps(vTemp,M.r[1]); + vResult = _mm_add_ps(vResult,vTemp); + vTemp = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + vTemp = _mm_mul_ps(vTemp,M.r[2]); + vResult = _mm_add_ps(vResult,vTemp); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT3* XMVector3TransformNormalStream +( + XMFLOAT3* pOutputStream, + size_t OutputStride, + CONST XMFLOAT3* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); +// Z = XMVectorReplicate(((XMFLOAT3*)pInputVector)->z); +// Y = XMVectorReplicate(((XMFLOAT3*)pInputVector)->y); +// X = XMVectorReplicate(((XMFLOAT3*)pInputVector)->x); + + Result = XMVectorMultiply(Z, M.r[2]); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + XMStoreFloat3((XMFLOAT3*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + size_t i; + CONST BYTE *pInputVector = (CONST BYTE*)pInputStream; + BYTE *pOutputVector = (BYTE*)pOutputStream; + + for (i = 0; i < VectorCount; i++) + { + XMVECTOR X = _mm_load_ps1(&reinterpret_cast(pInputVector)->x); + XMVECTOR Y = _mm_load_ps1(&reinterpret_cast(pInputVector)->y); + XMVECTOR vResult = _mm_load_ps1(&reinterpret_cast(pInputVector)->z); + vResult = _mm_mul_ps(vResult,M.r[2]); + Y = _mm_mul_ps(Y,M.r[1]); + vResult = _mm_add_ps(vResult,Y); + X = _mm_mul_ps(X,M.r[0]); + vResult = _mm_add_ps(vResult,X); + _mm_store_ss(&reinterpret_cast(pOutputVector)->x,vResult); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + _mm_store_ss(&reinterpret_cast(pOutputVector)->y,vResult); + vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,3,2,1)); + _mm_store_ss(&reinterpret_cast(pOutputVector)->z,vResult); + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMVECTOR XMVector3Project +( + FXMVECTOR V, + FLOAT ViewportX, + FLOAT ViewportY, + FLOAT ViewportWidth, + FLOAT ViewportHeight, + FLOAT ViewportMinZ, + FLOAT ViewportMaxZ, + CXMMATRIX Projection, + CXMMATRIX View, + CXMMATRIX World +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX Transform; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR Result; + FLOAT HalfViewportWidth = ViewportWidth * 0.5f; + FLOAT HalfViewportHeight = ViewportHeight * 0.5f; + + Scale = XMVectorSet(HalfViewportWidth, + -HalfViewportHeight, + ViewportMaxZ - ViewportMinZ, + 0.0f); + + Offset = XMVectorSet(ViewportX + HalfViewportWidth, + ViewportY + HalfViewportHeight, + ViewportMinZ, + 0.0f); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + + Result = XMVector3TransformCoord(V, Transform); + + Result = XMVectorMultiplyAdd(Result, Scale, Offset); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX Transform; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR Result; + FLOAT HalfViewportWidth = ViewportWidth * 0.5f; + FLOAT HalfViewportHeight = ViewportHeight * 0.5f; + + Scale = XMVectorSet(HalfViewportWidth, + -HalfViewportHeight, + ViewportMaxZ - ViewportMinZ, + 0.0f); + + Offset = XMVectorSet(ViewportX + HalfViewportWidth, + ViewportY + HalfViewportHeight, + ViewportMinZ, + 0.0f); + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + Result = XMVector3TransformCoord(V, Transform); + Result = _mm_mul_ps(Result,Scale); + Result = _mm_add_ps(Result,Offset); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT3* XMVector3ProjectStream +( + XMFLOAT3* pOutputStream, + size_t OutputStride, + CONST XMFLOAT3* pInputStream, + size_t InputStride, + size_t VectorCount, + FLOAT ViewportX, + FLOAT ViewportY, + FLOAT ViewportWidth, + FLOAT ViewportHeight, + FLOAT ViewportMinZ, + FLOAT ViewportMaxZ, + CXMMATRIX Projection, + CXMMATRIX View, + CXMMATRIX World +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX Transform; + XMVECTOR V; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR Result; + size_t i; + FLOAT HalfViewportWidth = ViewportWidth * 0.5f; + FLOAT HalfViewportHeight = ViewportHeight * 0.5f; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + Scale = XMVectorSet(HalfViewportWidth, + -HalfViewportHeight, + ViewportMaxZ - ViewportMinZ, + 1.0f); + + Offset = XMVectorSet(ViewportX + HalfViewportWidth, + ViewportY + HalfViewportHeight, + ViewportMinZ, + 0.0f); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + + Result = XMVector3TransformCoord(V, Transform); + + Result = XMVectorMultiplyAdd(Result, Scale, Offset); + + XMStoreFloat3((XMFLOAT3*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + XMMATRIX Transform; + XMVECTOR V; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR Result; + size_t i; + FLOAT HalfViewportWidth = ViewportWidth * 0.5f; + FLOAT HalfViewportHeight = ViewportHeight * 0.5f; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + Scale = XMVectorSet(HalfViewportWidth, + -HalfViewportHeight, + ViewportMaxZ - ViewportMinZ, + 1.0f); + + Offset = XMVectorSet(ViewportX + HalfViewportWidth, + ViewportY + HalfViewportHeight, + ViewportMinZ, + 0.0f); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + + Result = XMVector3TransformCoord(V, Transform); + + Result = _mm_mul_ps(Result,Scale); + Result = _mm_add_ps(Result,Offset); + XMStoreFloat3((XMFLOAT3*)pOutputVector, Result); + pInputVector += InputStride; + pOutputVector += OutputStride; + } + return pOutputStream; + +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector3Unproject +( + FXMVECTOR V, + FLOAT ViewportX, + FLOAT ViewportY, + FLOAT ViewportWidth, + FLOAT ViewportHeight, + FLOAT ViewportMinZ, + FLOAT ViewportMaxZ, + CXMMATRIX Projection, + CXMMATRIX View, + CXMMATRIX World +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX Transform; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR Determinant; + XMVECTOR Result; + CONST XMVECTOR D = XMVectorSet(-1.0f, 1.0f, 0.0f, 0.0f); + + Scale = XMVectorSet(ViewportWidth * 0.5f, + -ViewportHeight * 0.5f, + ViewportMaxZ - ViewportMinZ, + 1.0f); + Scale = XMVectorReciprocal(Scale); + + Offset = XMVectorSet(-ViewportX, + -ViewportY, + -ViewportMinZ, + 0.0f); + Offset = XMVectorMultiplyAdd(Scale, Offset, D); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + Transform = XMMatrixInverse(&Determinant, Transform); + + Result = XMVectorMultiplyAdd(V, Scale, Offset); + + Result = XMVector3TransformCoord(Result, Transform); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMMATRIX Transform; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR Determinant; + XMVECTOR Result; + CONST XMVECTORF32 D = {-1.0f, 1.0f, 0.0f, 0.0f}; + + Scale = XMVectorSet(ViewportWidth * 0.5f, + -ViewportHeight * 0.5f, + ViewportMaxZ - ViewportMinZ, + 1.0f); + Scale = XMVectorReciprocal(Scale); + + Offset = XMVectorSet(-ViewportX, + -ViewportY, + -ViewportMinZ, + 0.0f); + Offset = _mm_mul_ps(Offset,Scale); + Offset = _mm_add_ps(Offset,D); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + Transform = XMMatrixInverse(&Determinant, Transform); + + Result = _mm_mul_ps(V,Scale); + Result = _mm_add_ps(Result,Offset); + + Result = XMVector3TransformCoord(Result, Transform); + + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT3* XMVector3UnprojectStream +( + XMFLOAT3* pOutputStream, + size_t OutputStride, + CONST XMFLOAT3* pInputStream, + size_t InputStride, + size_t VectorCount, + FLOAT ViewportX, + FLOAT ViewportY, + FLOAT ViewportWidth, + FLOAT ViewportHeight, + FLOAT ViewportMinZ, + FLOAT ViewportMaxZ, + CXMMATRIX Projection, + CXMMATRIX View, + CXMMATRIX World) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMMATRIX Transform; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR V; + XMVECTOR Determinant; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + CONST XMVECTOR D = XMVectorSet(-1.0f, 1.0f, 0.0f, 0.0f); + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + Scale = XMVectorSet(ViewportWidth * 0.5f, + -ViewportHeight * 0.5f, + ViewportMaxZ - ViewportMinZ, + 1.0f); + Scale = XMVectorReciprocal(Scale); + + Offset = XMVectorSet(-ViewportX, + -ViewportY, + -ViewportMinZ, + 0.0f); + Offset = XMVectorMultiplyAdd(Scale, Offset, D); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + Transform = XMMatrixInverse(&Determinant, Transform); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + + Result = XMVectorMultiplyAdd(V, Scale, Offset); + + Result = XMVector3TransformCoord(Result, Transform); + + XMStoreFloat3((XMFLOAT3*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + XMMATRIX Transform; + XMVECTOR Scale; + XMVECTOR Offset; + XMVECTOR V; + XMVECTOR Determinant; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + CONST XMVECTORF32 D = {-1.0f, 1.0f, 0.0f, 0.0f}; + + Scale = XMVectorSet(ViewportWidth * 0.5f, + -ViewportHeight * 0.5f, + ViewportMaxZ - ViewportMinZ, + 1.0f); + Scale = XMVectorReciprocal(Scale); + + Offset = XMVectorSet(-ViewportX, + -ViewportY, + -ViewportMinZ, + 0.0f); + Offset = _mm_mul_ps(Offset,Scale); + Offset = _mm_add_ps(Offset,D); + + Transform = XMMatrixMultiply(World, View); + Transform = XMMatrixMultiply(Transform, Projection); + Transform = XMMatrixInverse(&Determinant, Transform); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat3((const XMFLOAT3*)pInputVector); + + Result = XMVectorMultiplyAdd(V, Scale, Offset); + + Result = XMVector3TransformCoord(Result, Transform); + + XMStoreFloat3((XMFLOAT3*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +/**************************************************************************** + * + * 4D Vector + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ +// Comparison operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4Equal +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] == V2.vector4_f32[0]) && (V1.vector4_f32[1] == V2.vector4_f32[1]) && (V1.vector4_f32[2] == V2.vector4_f32[2]) && (V1.vector4_f32[3] == V2.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); + return ((_mm_movemask_ps(vTemp)==0x0f) != 0); +#else + return XMComparisonAllTrue(XMVector4EqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector4EqualR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + UINT CR = 0; + + if ((V1.vector4_f32[0] == V2.vector4_f32[0]) && + (V1.vector4_f32[1] == V2.vector4_f32[1]) && + (V1.vector4_f32[2] == V2.vector4_f32[2]) && + (V1.vector4_f32[3] == V2.vector4_f32[3])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] != V2.vector4_f32[0]) && + (V1.vector4_f32[1] != V2.vector4_f32[1]) && + (V1.vector4_f32[2] != V2.vector4_f32[2]) && + (V1.vector4_f32[3] != V2.vector4_f32[3])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpeq_ps(V1,V2); + int iTest = _mm_movemask_ps(vTemp); + UINT CR = 0; + if (iTest==0xf) // All equal? + { + CR = XM_CRMASK_CR6TRUE; + } + else if (iTest==0) // All not equal? + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4EqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_u32[0] == V2.vector4_u32[0]) && (V1.vector4_u32[1] == V2.vector4_u32[1]) && (V1.vector4_u32[2] == V2.vector4_u32[2]) && (V1.vector4_u32[3] == V2.vector4_u32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + return ((_mm_movemask_ps(reinterpret_cast(&vTemp)[0])==0xf) != 0); +#else + return XMComparisonAllTrue(XMVector4EqualIntR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector4EqualIntR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if (V1.vector4_u32[0] == V2.vector4_u32[0] && + V1.vector4_u32[1] == V2.vector4_u32[1] && + V1.vector4_u32[2] == V2.vector4_u32[2] && + V1.vector4_u32[3] == V2.vector4_u32[3]) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (V1.vector4_u32[0] != V2.vector4_u32[0] && + V1.vector4_u32[1] != V2.vector4_u32[1] && + V1.vector4_u32[2] != V2.vector4_u32[2] && + V1.vector4_u32[3] != V2.vector4_u32[3]) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + int iTest = _mm_movemask_ps(reinterpret_cast(&vTemp)[0]); + UINT CR = 0; + if (iTest==0xf) // All equal? + { + CR = XM_CRMASK_CR6TRUE; + } + else if (iTest==0) // All not equal? + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +XMFINLINE BOOL XMVector4NearEqual +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR Epsilon +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT dx, dy, dz, dw; + + dx = fabsf(V1.vector4_f32[0]-V2.vector4_f32[0]); + dy = fabsf(V1.vector4_f32[1]-V2.vector4_f32[1]); + dz = fabsf(V1.vector4_f32[2]-V2.vector4_f32[2]); + dw = fabsf(V1.vector4_f32[3]-V2.vector4_f32[3]); + return (((dx <= Epsilon.vector4_f32[0]) && + (dy <= Epsilon.vector4_f32[1]) && + (dz <= Epsilon.vector4_f32[2]) && + (dw <= Epsilon.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + // Get the difference + XMVECTOR vDelta = _mm_sub_ps(V1,V2); + // Get the absolute value of the difference + XMVECTOR vTemp = _mm_setzero_ps(); + vTemp = _mm_sub_ps(vTemp,vDelta); + vTemp = _mm_max_ps(vTemp,vDelta); + vTemp = _mm_cmple_ps(vTemp,Epsilon); + return ((_mm_movemask_ps(vTemp)==0xf) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4NotEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] != V2.vector4_f32[0]) || (V1.vector4_f32[1] != V2.vector4_f32[1]) || (V1.vector4_f32[2] != V2.vector4_f32[2]) || (V1.vector4_f32[3] != V2.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpneq_ps(V1,V2); + return ((_mm_movemask_ps(vTemp)) != 0); +#else + return XMComparisonAnyFalse(XMVector4EqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4NotEqualInt +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_u32[0] != V2.vector4_u32[0]) || (V1.vector4_u32[1] != V2.vector4_u32[1]) || (V1.vector4_u32[2] != V2.vector4_u32[2]) || (V1.vector4_u32[3] != V2.vector4_u32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + __m128i vTemp = _mm_cmpeq_epi32(reinterpret_cast(&V1)[0],reinterpret_cast(&V2)[0]); + return ((_mm_movemask_ps(reinterpret_cast(&vTemp)[0])!=0xF) != 0); +#else + return XMComparisonAnyFalse(XMVector4EqualIntR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4Greater +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] > V2.vector4_f32[0]) && (V1.vector4_f32[1] > V2.vector4_f32[1]) && (V1.vector4_f32[2] > V2.vector4_f32[2]) && (V1.vector4_f32[3] > V2.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); + return ((_mm_movemask_ps(vTemp)==0x0f) != 0); +#else + return XMComparisonAllTrue(XMVector4GreaterR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector4GreaterR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if (V1.vector4_f32[0] > V2.vector4_f32[0] && + V1.vector4_f32[1] > V2.vector4_f32[1] && + V1.vector4_f32[2] > V2.vector4_f32[2] && + V1.vector4_f32[3] > V2.vector4_f32[3]) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (V1.vector4_f32[0] <= V2.vector4_f32[0] && + V1.vector4_f32[1] <= V2.vector4_f32[1] && + V1.vector4_f32[2] <= V2.vector4_f32[2] && + V1.vector4_f32[3] <= V2.vector4_f32[3]) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + UINT CR = 0; + XMVECTOR vTemp = _mm_cmpgt_ps(V1,V2); + int iTest = _mm_movemask_ps(vTemp); + if (iTest==0xf) { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4GreaterOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] >= V2.vector4_f32[0]) && (V1.vector4_f32[1] >= V2.vector4_f32[1]) && (V1.vector4_f32[2] >= V2.vector4_f32[2]) && (V1.vector4_f32[3] >= V2.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + return ((_mm_movemask_ps(vTemp)==0x0f) != 0); +#else + return XMComparisonAllTrue(XMVector4GreaterOrEqualR(V1, V2)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector4GreaterOrEqualR +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + UINT CR = 0; + if ((V1.vector4_f32[0] >= V2.vector4_f32[0]) && + (V1.vector4_f32[1] >= V2.vector4_f32[1]) && + (V1.vector4_f32[2] >= V2.vector4_f32[2]) && + (V1.vector4_f32[3] >= V2.vector4_f32[3])) + { + CR = XM_CRMASK_CR6TRUE; + } + else if ((V1.vector4_f32[0] < V2.vector4_f32[0]) && + (V1.vector4_f32[1] < V2.vector4_f32[1]) && + (V1.vector4_f32[2] < V2.vector4_f32[2]) && + (V1.vector4_f32[3] < V2.vector4_f32[3])) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + UINT CR = 0; + XMVECTOR vTemp = _mm_cmpge_ps(V1,V2); + int iTest = _mm_movemask_ps(vTemp); + if (iTest==0x0f) + { + CR = XM_CRMASK_CR6TRUE; + } + else if (!iTest) + { + CR = XM_CRMASK_CR6FALSE; + } + return CR; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4Less +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] < V2.vector4_f32[0]) && (V1.vector4_f32[1] < V2.vector4_f32[1]) && (V1.vector4_f32[2] < V2.vector4_f32[2]) && (V1.vector4_f32[3] < V2.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmplt_ps(V1,V2); + return ((_mm_movemask_ps(vTemp)==0x0f) != 0); +#else + return XMComparisonAllTrue(XMVector4GreaterR(V2, V1)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4LessOrEqual +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V1.vector4_f32[0] <= V2.vector4_f32[0]) && (V1.vector4_f32[1] <= V2.vector4_f32[1]) && (V1.vector4_f32[2] <= V2.vector4_f32[2]) && (V1.vector4_f32[3] <= V2.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp = _mm_cmple_ps(V1,V2); + return ((_mm_movemask_ps(vTemp)==0x0f) != 0); +#else + return XMComparisonAllTrue(XMVector4GreaterOrEqualR(V2, V1)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4InBounds +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (((V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) && + (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1]) && + (V.vector4_f32[2] <= Bounds.vector4_f32[2] && V.vector4_f32[2] >= -Bounds.vector4_f32[2]) && + (V.vector4_f32[3] <= Bounds.vector4_f32[3] && V.vector4_f32[3] >= -Bounds.vector4_f32[3])) != 0); +#elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + // All in bounds? + return ((_mm_movemask_ps(vTemp1)==0x0f) != 0); +#else + return XMComparisonAllInBounds(XMVector4InBoundsR(V, Bounds)); +#endif +} + +//------------------------------------------------------------------------------ + +XMFINLINE UINT XMVector4InBoundsR +( + FXMVECTOR V, + FXMVECTOR Bounds +) +{ +#if defined(_XM_NO_INTRINSICS_) + + UINT CR = 0; + if ((V.vector4_f32[0] <= Bounds.vector4_f32[0] && V.vector4_f32[0] >= -Bounds.vector4_f32[0]) && + (V.vector4_f32[1] <= Bounds.vector4_f32[1] && V.vector4_f32[1] >= -Bounds.vector4_f32[1]) && + (V.vector4_f32[2] <= Bounds.vector4_f32[2] && V.vector4_f32[2] >= -Bounds.vector4_f32[2]) && + (V.vector4_f32[3] <= Bounds.vector4_f32[3] && V.vector4_f32[3] >= -Bounds.vector4_f32[3])) + { + CR = XM_CRMASK_CR6BOUNDS; + } + return CR; + +#elif defined(_XM_SSE_INTRINSICS_) + // Test if less than or equal + XMVECTOR vTemp1 = _mm_cmple_ps(V,Bounds); + // Negate the bounds + XMVECTOR vTemp2 = _mm_mul_ps(Bounds,g_XMNegativeOne); + // Test if greater or equal (Reversed) + vTemp2 = _mm_cmple_ps(vTemp2,V); + // Blend answers + vTemp1 = _mm_and_ps(vTemp1,vTemp2); + // All in bounds? + return (_mm_movemask_ps(vTemp1)==0x0f) ? XM_CRMASK_CR6BOUNDS : 0; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4IsNaN +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + return (XMISNAN(V.vector4_f32[0]) || + XMISNAN(V.vector4_f32[1]) || + XMISNAN(V.vector4_f32[2]) || + XMISNAN(V.vector4_f32[3])); +#elif defined(_XM_SSE_INTRINSICS_) + // Test against itself. NaN is always not equal + XMVECTOR vTempNan = _mm_cmpneq_ps(V,V); + // If any are NaN, the mask is non-zero + return (_mm_movemask_ps(vTempNan)!=0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE BOOL XMVector4IsInfinite +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + return (XMISINF(V.vector4_f32[0]) || + XMISINF(V.vector4_f32[1]) || + XMISINF(V.vector4_f32[2]) || + XMISINF(V.vector4_f32[3])); + +#elif defined(_XM_SSE_INTRINSICS_) + // Mask off the sign bit + XMVECTOR vTemp = _mm_and_ps(V,g_XMAbsMask); + // Compare to infinity + vTemp = _mm_cmpeq_ps(vTemp,g_XMInfinity); + // If any are infinity, the signs are true. + return (_mm_movemask_ps(vTemp) != 0); +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// Computation operations +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Dot +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result.vector4_f32[0] = + Result.vector4_f32[1] = + Result.vector4_f32[2] = + Result.vector4_f32[3] = V1.vector4_f32[0] * V2.vector4_f32[0] + V1.vector4_f32[1] * V2.vector4_f32[1] + V1.vector4_f32[2] * V2.vector4_f32[2] + V1.vector4_f32[3] * V2.vector4_f32[3]; + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vTemp2 = V2; + XMVECTOR vTemp = _mm_mul_ps(V1,vTemp2); + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp,_MM_SHUFFLE(1,0,0,0)); // Copy X to the Z position and Y to the W position + vTemp2 = _mm_add_ps(vTemp2,vTemp); // Add Z = X+Z; W = Y+W; + vTemp = _mm_shuffle_ps(vTemp,vTemp2,_MM_SHUFFLE(0,3,0,0)); // Copy W to the Z position + vTemp = _mm_add_ps(vTemp,vTemp2); // Add Z and W together + return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(2,2,2,2)); // Splat Z and return +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Cross +( + FXMVECTOR V1, + FXMVECTOR V2, + FXMVECTOR V3 +) +{ +#if defined(_XM_NO_INTRINSICS_) + XMVECTOR Result; + + Result.vector4_f32[0] = (((V2.vector4_f32[2]*V3.vector4_f32[3])-(V2.vector4_f32[3]*V3.vector4_f32[2]))*V1.vector4_f32[1])-(((V2.vector4_f32[1]*V3.vector4_f32[3])-(V2.vector4_f32[3]*V3.vector4_f32[1]))*V1.vector4_f32[2])+(((V2.vector4_f32[1]*V3.vector4_f32[2])-(V2.vector4_f32[2]*V3.vector4_f32[1]))*V1.vector4_f32[3]); + Result.vector4_f32[1] = (((V2.vector4_f32[3]*V3.vector4_f32[2])-(V2.vector4_f32[2]*V3.vector4_f32[3]))*V1.vector4_f32[0])-(((V2.vector4_f32[3]*V3.vector4_f32[0])-(V2.vector4_f32[0]*V3.vector4_f32[3]))*V1.vector4_f32[2])+(((V2.vector4_f32[2]*V3.vector4_f32[0])-(V2.vector4_f32[0]*V3.vector4_f32[2]))*V1.vector4_f32[3]); + Result.vector4_f32[2] = (((V2.vector4_f32[1]*V3.vector4_f32[3])-(V2.vector4_f32[3]*V3.vector4_f32[1]))*V1.vector4_f32[0])-(((V2.vector4_f32[0]*V3.vector4_f32[3])-(V2.vector4_f32[3]*V3.vector4_f32[0]))*V1.vector4_f32[1])+(((V2.vector4_f32[0]*V3.vector4_f32[1])-(V2.vector4_f32[1]*V3.vector4_f32[0]))*V1.vector4_f32[3]); + Result.vector4_f32[3] = (((V2.vector4_f32[2]*V3.vector4_f32[1])-(V2.vector4_f32[1]*V3.vector4_f32[2]))*V1.vector4_f32[0])-(((V2.vector4_f32[2]*V3.vector4_f32[0])-(V2.vector4_f32[0]*V3.vector4_f32[2]))*V1.vector4_f32[1])+(((V2.vector4_f32[1]*V3.vector4_f32[0])-(V2.vector4_f32[0]*V3.vector4_f32[1]))*V1.vector4_f32[2]); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // V2zwyz * V3wzwy + XMVECTOR vResult = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(2,1,3,2)); + XMVECTOR vTemp3 = _mm_shuffle_ps(V3,V3,_MM_SHUFFLE(1,3,2,3)); + vResult = _mm_mul_ps(vResult,vTemp3); + // - V2wzwy * V3zwyz + XMVECTOR vTemp2 = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(1,3,2,3)); + vTemp3 = _mm_shuffle_ps(vTemp3,vTemp3,_MM_SHUFFLE(1,3,0,1)); + vTemp2 = _mm_mul_ps(vTemp2,vTemp3); + vResult = _mm_sub_ps(vResult,vTemp2); + // term1 * V1yxxx + XMVECTOR vTemp1 = _mm_shuffle_ps(V1,V1,_MM_SHUFFLE(0,0,0,1)); + vResult = _mm_mul_ps(vResult,vTemp1); + + // V2ywxz * V3wxwx + vTemp2 = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(2,0,3,1)); + vTemp3 = _mm_shuffle_ps(V3,V3,_MM_SHUFFLE(0,3,0,3)); + vTemp3 = _mm_mul_ps(vTemp3,vTemp2); + // - V2wxwx * V3ywxz + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(2,1,2,1)); + vTemp1 = _mm_shuffle_ps(V3,V3,_MM_SHUFFLE(2,0,3,1)); + vTemp2 = _mm_mul_ps(vTemp2,vTemp1); + vTemp3 = _mm_sub_ps(vTemp3,vTemp2); + // vResult - temp * V1zzyy + vTemp1 = _mm_shuffle_ps(V1,V1,_MM_SHUFFLE(1,1,2,2)); + vTemp1 = _mm_mul_ps(vTemp1,vTemp3); + vResult = _mm_sub_ps(vResult,vTemp1); + + // V2yzxy * V3zxyx + vTemp2 = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(1,0,2,1)); + vTemp3 = _mm_shuffle_ps(V3,V3,_MM_SHUFFLE(0,1,0,2)); + vTemp3 = _mm_mul_ps(vTemp3,vTemp2); + // - V2zxyx * V3yzxy + vTemp2 = _mm_shuffle_ps(vTemp2,vTemp2,_MM_SHUFFLE(2,0,2,1)); + vTemp1 = _mm_shuffle_ps(V3,V3,_MM_SHUFFLE(1,0,2,1)); + vTemp1 = _mm_mul_ps(vTemp1,vTemp2); + vTemp3 = _mm_sub_ps(vTemp3,vTemp1); + // vResult + term * V1wwwz + vTemp1 = _mm_shuffle_ps(V1,V1,_MM_SHUFFLE(2,3,3,3)); + vTemp3 = _mm_mul_ps(vTemp3,vTemp1); + vResult = _mm_add_ps(vResult,vTemp3); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4LengthSq +( + FXMVECTOR V +) +{ + return XMVector4Dot(V, V); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4ReciprocalLengthEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector4LengthSq(V); + Result = XMVectorReciprocalSqrtEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y,z and w + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and w + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(3,2,3,2)); + // x+z, y+w + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // x+z,x+z,x+z,y+w + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,0,0,0)); + // ??,??,y+w,y+w + vTemp = _mm_shuffle_ps(vTemp,vLengthSq,_MM_SHUFFLE(3,3,0,0)); + // ??,??,x+z+y+w,?? + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // Splat the length + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,2,2,2)); + // Get the reciprocal + vLengthSq = _mm_rsqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4ReciprocalLength +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector4LengthSq(V); + Result = XMVectorReciprocalSqrt(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y,z and w + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and w + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(3,2,3,2)); + // x+z, y+w + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // x+z,x+z,x+z,y+w + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,0,0,0)); + // ??,??,y+w,y+w + vTemp = _mm_shuffle_ps(vTemp,vLengthSq,_MM_SHUFFLE(3,3,0,0)); + // ??,??,x+z+y+w,?? + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // Splat the length + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,2,2,2)); + // Get the reciprocal + vLengthSq = _mm_sqrt_ps(vLengthSq); + // Accurate! + vLengthSq = _mm_div_ps(g_XMOne,vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4LengthEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector4LengthSq(V); + Result = XMVectorSqrtEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y,z and w + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and w + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(3,2,3,2)); + // x+z, y+w + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // x+z,x+z,x+z,y+w + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,0,0,0)); + // ??,??,y+w,y+w + vTemp = _mm_shuffle_ps(vTemp,vLengthSq,_MM_SHUFFLE(3,3,0,0)); + // ??,??,x+z+y+w,?? + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // Splat the length + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,2,2,2)); + // Prepare for the division + vLengthSq = _mm_sqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Length +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + Result = XMVector4LengthSq(V); + Result = XMVectorSqrt(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y,z and w + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and w + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(3,2,3,2)); + // x+z, y+w + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // x+z,x+z,x+z,y+w + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,0,0,0)); + // ??,??,y+w,y+w + vTemp = _mm_shuffle_ps(vTemp,vLengthSq,_MM_SHUFFLE(3,3,0,0)); + // ??,??,x+z+y+w,?? + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // Splat the length + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,2,2,2)); + // Prepare for the division + vLengthSq = _mm_sqrt_ps(vLengthSq); + return vLengthSq; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ +// XMVector4NormalizeEst uses a reciprocal estimate and +// returns QNaN on zero and infinite vectors. + +XMFINLINE XMVECTOR XMVector4NormalizeEst +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result = XMVector4ReciprocalLength(V); + Result = XMVectorMultiply(V, Result); + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y,z and w + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and w + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(3,2,3,2)); + // x+z, y+w + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // x+z,x+z,x+z,y+w + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,0,0,0)); + // ??,??,y+w,y+w + vTemp = _mm_shuffle_ps(vTemp,vLengthSq,_MM_SHUFFLE(3,3,0,0)); + // ??,??,x+z+y+w,?? + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // Splat the length + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,2,2,2)); + // Get the reciprocal + XMVECTOR vResult = _mm_rsqrt_ps(vLengthSq); + // Reciprocal mul to perform the normalization + vResult = _mm_mul_ps(vResult,V); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Normalize +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fLength; + XMVECTOR vResult; + + vResult = XMVector4Length( V ); + fLength = vResult.vector4_f32[0]; + + // Prevent divide by zero + if (fLength > 0) { + fLength = 1.0f/fLength; + } + + vResult.vector4_f32[0] = V.vector4_f32[0]*fLength; + vResult.vector4_f32[1] = V.vector4_f32[1]*fLength; + vResult.vector4_f32[2] = V.vector4_f32[2]*fLength; + vResult.vector4_f32[3] = V.vector4_f32[3]*fLength; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // Perform the dot product on x,y,z and w + XMVECTOR vLengthSq = _mm_mul_ps(V,V); + // vTemp has z and w + XMVECTOR vTemp = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(3,2,3,2)); + // x+z, y+w + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // x+z,x+z,x+z,y+w + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(1,0,0,0)); + // ??,??,y+w,y+w + vTemp = _mm_shuffle_ps(vTemp,vLengthSq,_MM_SHUFFLE(3,3,0,0)); + // ??,??,x+z+y+w,?? + vLengthSq = _mm_add_ps(vLengthSq,vTemp); + // Splat the length + vLengthSq = _mm_shuffle_ps(vLengthSq,vLengthSq,_MM_SHUFFLE(2,2,2,2)); + // Prepare for the division + XMVECTOR vResult = _mm_sqrt_ps(vLengthSq); + // Create zero with a single instruction + XMVECTOR vZeroMask = _mm_setzero_ps(); + // Test for a divide by zero (Must be FP to detect -0.0) + vZeroMask = _mm_cmpneq_ps(vZeroMask,vResult); + // Failsafe on zero (Or epsilon) length planes + // If the length is infinity, set the elements to zero + vLengthSq = _mm_cmpneq_ps(vLengthSq,g_XMInfinity); + // Divide to perform the normalization + vResult = _mm_div_ps(V,vResult); + // Any that are infinity, set to zero + vResult = _mm_and_ps(vResult,vZeroMask); + // Select qnan or result based on infinite length + XMVECTOR vTemp1 = _mm_andnot_ps(vLengthSq,g_XMQNaN); + XMVECTOR vTemp2 = _mm_and_ps(vResult,vLengthSq); + vResult = _mm_or_ps(vTemp1,vTemp2); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4ClampLength +( + FXMVECTOR V, + FLOAT LengthMin, + FLOAT LengthMax +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR ClampMax; + XMVECTOR ClampMin; + + ClampMax = XMVectorReplicate(LengthMax); + ClampMin = XMVectorReplicate(LengthMin); + + return XMVector4ClampLengthV(V, ClampMin, ClampMax); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR ClampMax = _mm_set_ps1(LengthMax); + XMVECTOR ClampMin = _mm_set_ps1(LengthMin); + return XMVector4ClampLengthV(V, ClampMin, ClampMax); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4ClampLengthV +( + FXMVECTOR V, + FXMVECTOR LengthMin, + FXMVECTOR LengthMax +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR ClampLength; + XMVECTOR LengthSq; + XMVECTOR RcpLength; + XMVECTOR Length; + XMVECTOR Normal; + XMVECTOR Zero; + XMVECTOR InfiniteLength; + XMVECTOR ZeroLength; + XMVECTOR Select; + XMVECTOR ControlMax; + XMVECTOR ControlMin; + XMVECTOR Control; + XMVECTOR Result; + + XMASSERT((LengthMin.vector4_f32[1] == LengthMin.vector4_f32[0]) && (LengthMin.vector4_f32[2] == LengthMin.vector4_f32[0]) && (LengthMin.vector4_f32[3] == LengthMin.vector4_f32[0])); + XMASSERT((LengthMax.vector4_f32[1] == LengthMax.vector4_f32[0]) && (LengthMax.vector4_f32[2] == LengthMax.vector4_f32[0]) && (LengthMax.vector4_f32[3] == LengthMax.vector4_f32[0])); + XMASSERT(XMVector4GreaterOrEqual(LengthMin, XMVectorZero())); + XMASSERT(XMVector4GreaterOrEqual(LengthMax, XMVectorZero())); + XMASSERT(XMVector4GreaterOrEqual(LengthMax, LengthMin)); + + LengthSq = XMVector4LengthSq(V); + + Zero = XMVectorZero(); + + RcpLength = XMVectorReciprocalSqrt(LengthSq); + + InfiniteLength = XMVectorEqualInt(LengthSq, g_XMInfinity.v); + ZeroLength = XMVectorEqual(LengthSq, Zero); + + Normal = XMVectorMultiply(V, RcpLength); + + Length = XMVectorMultiply(LengthSq, RcpLength); + + Select = XMVectorEqualInt(InfiniteLength, ZeroLength); + Length = XMVectorSelect(LengthSq, Length, Select); + Normal = XMVectorSelect(LengthSq, Normal, Select); + + ControlMax = XMVectorGreater(Length, LengthMax); + ControlMin = XMVectorLess(Length, LengthMin); + + ClampLength = XMVectorSelect(Length, LengthMax, ControlMax); + ClampLength = XMVectorSelect(ClampLength, LengthMin, ControlMin); + + Result = XMVectorMultiply(Normal, ClampLength); + + // Preserve the original vector (with no precision loss) if the length falls within the given range + Control = XMVectorEqualInt(ControlMax, ControlMin); + Result = XMVectorSelect(Result, V, Control); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR ClampLength; + XMVECTOR LengthSq; + XMVECTOR RcpLength; + XMVECTOR Length; + XMVECTOR Normal; + XMVECTOR Zero; + XMVECTOR InfiniteLength; + XMVECTOR ZeroLength; + XMVECTOR Select; + XMVECTOR ControlMax; + XMVECTOR ControlMin; + XMVECTOR Control; + XMVECTOR Result; + + XMASSERT((XMVectorGetY(LengthMin) == XMVectorGetX(LengthMin)) && (XMVectorGetZ(LengthMin) == XMVectorGetX(LengthMin)) && (XMVectorGetW(LengthMin) == XMVectorGetX(LengthMin))); + XMASSERT((XMVectorGetY(LengthMax) == XMVectorGetX(LengthMax)) && (XMVectorGetZ(LengthMax) == XMVectorGetX(LengthMax)) && (XMVectorGetW(LengthMax) == XMVectorGetX(LengthMax))); + XMASSERT(XMVector4GreaterOrEqual(LengthMin, g_XMZero)); + XMASSERT(XMVector4GreaterOrEqual(LengthMax, g_XMZero)); + XMASSERT(XMVector4GreaterOrEqual(LengthMax, LengthMin)); + + LengthSq = XMVector4LengthSq(V); + Zero = XMVectorZero(); + RcpLength = XMVectorReciprocalSqrt(LengthSq); + InfiniteLength = XMVectorEqualInt(LengthSq, g_XMInfinity); + ZeroLength = XMVectorEqual(LengthSq, Zero); + Normal = _mm_mul_ps(V, RcpLength); + Length = _mm_mul_ps(LengthSq, RcpLength); + Select = XMVectorEqualInt(InfiniteLength, ZeroLength); + Length = XMVectorSelect(LengthSq, Length, Select); + Normal = XMVectorSelect(LengthSq, Normal, Select); + ControlMax = XMVectorGreater(Length, LengthMax); + ControlMin = XMVectorLess(Length, LengthMin); + ClampLength = XMVectorSelect(Length, LengthMax, ControlMax); + ClampLength = XMVectorSelect(ClampLength, LengthMin, ControlMin); + Result = _mm_mul_ps(Normal, ClampLength); + // Preserve the original vector (with no precision loss) if the length falls within the given range + Control = XMVectorEqualInt(ControlMax,ControlMin); + Result = XMVectorSelect(Result,V,Control); + return Result; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Reflect +( + FXMVECTOR Incident, + FXMVECTOR Normal +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + + // Result = Incident - (2 * dot(Incident, Normal)) * Normal + Result = XMVector4Dot(Incident, Normal); + Result = XMVectorAdd(Result, Result); + Result = XMVectorNegativeMultiplySubtract(Result, Normal, Incident); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = Incident - (2 * dot(Incident, Normal)) * Normal + XMVECTOR Result = XMVector4Dot(Incident,Normal); + Result = _mm_add_ps(Result,Result); + Result = _mm_mul_ps(Result,Normal); + Result = _mm_sub_ps(Incident,Result); + return Result; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Refract +( + FXMVECTOR Incident, + FXMVECTOR Normal, + FLOAT RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Index; + Index = XMVectorReplicate(RefractionIndex); + return XMVector4RefractV(Incident, Normal, Index); + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR Index = _mm_set_ps1(RefractionIndex); + return XMVector4RefractV(Incident,Normal,Index); +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4RefractV +( + FXMVECTOR Incident, + FXMVECTOR Normal, + FXMVECTOR RefractionIndex +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR IDotN; + XMVECTOR R; + CONST XMVECTOR Zero = XMVectorZero(); + + // Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + + // sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) + + IDotN = XMVector4Dot(Incident, Normal); + + // R = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) + R = XMVectorNegativeMultiplySubtract(IDotN, IDotN, g_XMOne.v); + R = XMVectorMultiply(R, RefractionIndex); + R = XMVectorNegativeMultiplySubtract(R, RefractionIndex, g_XMOne.v); + + if (XMVector4LessOrEqual(R, Zero)) + { + // Total internal reflection + return Zero; + } + else + { + XMVECTOR Result; + + // R = RefractionIndex * IDotN + sqrt(R) + R = XMVectorSqrt(R); + R = XMVectorMultiplyAdd(RefractionIndex, IDotN, R); + + // Result = RefractionIndex * Incident - Normal * R + Result = XMVectorMultiply(RefractionIndex, Incident); + Result = XMVectorNegativeMultiplySubtract(Normal, R, Result); + + return Result; + } + +#elif defined(_XM_SSE_INTRINSICS_) + // Result = RefractionIndex * Incident - Normal * (RefractionIndex * dot(Incident, Normal) + + // sqrt(1 - RefractionIndex * RefractionIndex * (1 - dot(Incident, Normal) * dot(Incident, Normal)))) + + XMVECTOR IDotN = XMVector4Dot(Incident,Normal); + + // R = 1.0f - RefractionIndex * RefractionIndex * (1.0f - IDotN * IDotN) + XMVECTOR R = _mm_mul_ps(IDotN,IDotN); + R = _mm_sub_ps(g_XMOne,R); + R = _mm_mul_ps(R, RefractionIndex); + R = _mm_mul_ps(R, RefractionIndex); + R = _mm_sub_ps(g_XMOne,R); + + XMVECTOR vResult = _mm_cmple_ps(R,g_XMZero); + if (_mm_movemask_ps(vResult)==0x0f) + { + // Total internal reflection + vResult = g_XMZero; + } + else + { + // R = RefractionIndex * IDotN + sqrt(R) + R = _mm_sqrt_ps(R); + vResult = _mm_mul_ps(RefractionIndex, IDotN); + R = _mm_add_ps(R,vResult); + // Result = RefractionIndex * Incident - Normal * R + vResult = _mm_mul_ps(RefractionIndex, Incident); + R = _mm_mul_ps(R,Normal); + vResult = _mm_sub_ps(vResult,R); + } + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Orthogonal +( + FXMVECTOR V +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR Result; + Result.vector4_f32[0] = V.vector4_f32[2]; + Result.vector4_f32[1] = V.vector4_f32[3]; + Result.vector4_f32[2] = -V.vector4_f32[0]; + Result.vector4_f32[3] = -V.vector4_f32[1]; + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + static const XMVECTORF32 FlipZW = {1.0f,1.0f,-1.0f,-1.0f}; + XMVECTOR vResult = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,0,3,2)); + vResult = _mm_mul_ps(vResult,FlipZW); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4AngleBetweenNormalsEst +( + FXMVECTOR N1, + FXMVECTOR N2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + Result = XMVector4Dot(N1, N2); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + Result = XMVectorClamp(Result, NegativeOne, One); + Result = XMVectorACosEst(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = XMVector4Dot(N1,N2); + // Clamp to -1.0f to 1.0f + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne);; + vResult = XMVectorACosEst(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4AngleBetweenNormals +( + FXMVECTOR N1, + FXMVECTOR N2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + Result = XMVector4Dot(N1, N2); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + Result = XMVectorClamp(Result, NegativeOne, One); + Result = XMVectorACos(Result); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR vResult = XMVector4Dot(N1,N2); + // Clamp to -1.0f to 1.0f + vResult = _mm_max_ps(vResult,g_XMNegativeOne); + vResult = _mm_min_ps(vResult,g_XMOne);; + vResult = XMVectorACos(vResult); + return vResult; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4AngleBetweenVectors +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR L1; + XMVECTOR L2; + XMVECTOR Dot; + XMVECTOR CosAngle; + XMVECTOR NegativeOne; + XMVECTOR One; + XMVECTOR Result; + + L1 = XMVector4ReciprocalLength(V1); + L2 = XMVector4ReciprocalLength(V2); + + Dot = XMVector4Dot(V1, V2); + + L1 = XMVectorMultiply(L1, L2); + + CosAngle = XMVectorMultiply(Dot, L1); + NegativeOne = XMVectorSplatConstant(-1, 0); + One = XMVectorSplatOne(); + CosAngle = XMVectorClamp(CosAngle, NegativeOne, One); + + Result = XMVectorACos(CosAngle); + + return Result; + +#elif defined(_XM_SSE_INTRINSICS_) + XMVECTOR L1; + XMVECTOR L2; + XMVECTOR Dot; + XMVECTOR CosAngle; + XMVECTOR Result; + + L1 = XMVector4ReciprocalLength(V1); + L2 = XMVector4ReciprocalLength(V2); + Dot = XMVector4Dot(V1, V2); + L1 = _mm_mul_ps(L1,L2); + CosAngle = _mm_mul_ps(Dot,L1); + CosAngle = XMVectorClamp(CosAngle, g_XMNegativeOne, g_XMOne); + Result = XMVectorACos(CosAngle); + return Result; + +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR XMVector4Transform +( + FXMVECTOR V, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + FLOAT fX = (M.m[0][0]*V.vector4_f32[0])+(M.m[1][0]*V.vector4_f32[1])+(M.m[2][0]*V.vector4_f32[2])+(M.m[3][0]*V.vector4_f32[3]); + FLOAT fY = (M.m[0][1]*V.vector4_f32[0])+(M.m[1][1]*V.vector4_f32[1])+(M.m[2][1]*V.vector4_f32[2])+(M.m[3][1]*V.vector4_f32[3]); + FLOAT fZ = (M.m[0][2]*V.vector4_f32[0])+(M.m[1][2]*V.vector4_f32[1])+(M.m[2][2]*V.vector4_f32[2])+(M.m[3][2]*V.vector4_f32[3]); + FLOAT fW = (M.m[0][3]*V.vector4_f32[0])+(M.m[1][3]*V.vector4_f32[1])+(M.m[2][3]*V.vector4_f32[2])+(M.m[3][3]*V.vector4_f32[3]); + XMVECTOR vResult = { + fX, + fY, + fZ, + fW + }; + return vResult; + +#elif defined(_XM_SSE_INTRINSICS_) + // Splat x,y,z and w + XMVECTOR vTempX = _mm_shuffle_ps(V,V,_MM_SHUFFLE(0,0,0,0)); + XMVECTOR vTempY = _mm_shuffle_ps(V,V,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR vTempZ = _mm_shuffle_ps(V,V,_MM_SHUFFLE(2,2,2,2)); + XMVECTOR vTempW = _mm_shuffle_ps(V,V,_MM_SHUFFLE(3,3,3,3)); + // Mul by the matrix + vTempX = _mm_mul_ps(vTempX,M.r[0]); + vTempY = _mm_mul_ps(vTempY,M.r[1]); + vTempZ = _mm_mul_ps(vTempZ,M.r[2]); + vTempW = _mm_mul_ps(vTempW,M.r[3]); + // Add them all together + vTempX = _mm_add_ps(vTempX,vTempY); + vTempZ = _mm_add_ps(vTempZ,vTempW); + vTempX = _mm_add_ps(vTempX,vTempZ); + return vTempX; +#else // _XM_VMX128_INTRINSICS_ +#endif // _XM_VMX128_INTRINSICS_ +} + +//------------------------------------------------------------------------------ + +XMINLINE XMFLOAT4* XMVector4TransformStream +( + XMFLOAT4* pOutputStream, + size_t OutputStride, + CONST XMFLOAT4* pInputStream, + size_t InputStride, + size_t VectorCount, + CXMMATRIX M +) +{ +#if defined(_XM_NO_INTRINSICS_) + + XMVECTOR V; + XMVECTOR X; + XMVECTOR Y; + XMVECTOR Z; + XMVECTOR W; + XMVECTOR Result; + size_t i; + CONST BYTE* pInputVector = (CONST BYTE*)pInputStream; + BYTE* pOutputVector = (BYTE*)pOutputStream; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + for (i = 0; i < VectorCount; i++) + { + V = XMLoadFloat4((const XMFLOAT4*)pInputVector); + W = XMVectorSplatW(V); + Z = XMVectorSplatZ(V); + Y = XMVectorSplatY(V); + X = XMVectorSplatX(V); +// W = XMVectorReplicate(((XMFLOAT4*)pInputVector)->w); +// Z = XMVectorReplicate(((XMFLOAT4*)pInputVector)->z); +// Y = XMVectorReplicate(((XMFLOAT4*)pInputVector)->y); +// X = XMVectorReplicate(((XMFLOAT4*)pInputVector)->x); + + Result = XMVectorMultiply(W, M.r[3]); + Result = XMVectorMultiplyAdd(Z, M.r[2], Result); + Result = XMVectorMultiplyAdd(Y, M.r[1], Result); + Result = XMVectorMultiplyAdd(X, M.r[0], Result); + + XMStoreFloat4((XMFLOAT4*)pOutputVector, Result); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + + return pOutputStream; + +#elif defined(_XM_SSE_INTRINSICS_) + size_t i; + + XMASSERT(pOutputStream); + XMASSERT(pInputStream); + + const BYTE*pInputVector = reinterpret_cast(pInputStream); + BYTE* pOutputVector = reinterpret_cast(pOutputStream); + for (i = 0; i < VectorCount; i++) + { + // Fetch the row and splat it + XMVECTOR vTempx = _mm_loadu_ps(reinterpret_cast(pInputVector)); + XMVECTOR vTempy = _mm_shuffle_ps(vTempx,vTempx,_MM_SHUFFLE(1,1,1,1)); + XMVECTOR vTempz = _mm_shuffle_ps(vTempx,vTempx,_MM_SHUFFLE(2,2,2,2)); + XMVECTOR vTempw = _mm_shuffle_ps(vTempx,vTempx,_MM_SHUFFLE(3,3,3,3)); + vTempx = _mm_shuffle_ps(vTempx,vTempx,_MM_SHUFFLE(0,0,0,0)); + vTempx = _mm_mul_ps(vTempx,M.r[0]); + vTempy = _mm_mul_ps(vTempy,M.r[1]); + vTempz = _mm_mul_ps(vTempz,M.r[2]); + vTempw = _mm_mul_ps(vTempw,M.r[3]); + vTempx = _mm_add_ps(vTempx,vTempy); + vTempw = _mm_add_ps(vTempw,vTempz); + vTempw = _mm_add_ps(vTempw,vTempx); + // Store the transformed vector + _mm_storeu_ps(reinterpret_cast(pOutputVector),vTempw); + + pInputVector += InputStride; + pOutputVector += OutputStride; + } + return pOutputStream; +#elif defined(XM_NO_MISALIGNED_VECTOR_ACCESS) +#endif // _XM_VMX128_INTRINSICS_ +} + +#ifdef __cplusplus + +/**************************************************************************** + * + * XMVECTOR operators + * + ****************************************************************************/ + +#ifndef XM_NO_OPERATOR_OVERLOADS + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator+ (FXMVECTOR V) +{ + return V; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator- (FXMVECTOR V) +{ + return XMVectorNegate(V); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR& operator+= +( + XMVECTOR& V1, + FXMVECTOR V2 +) +{ + V1 = XMVectorAdd(V1, V2); + return V1; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR& operator-= +( + XMVECTOR& V1, + FXMVECTOR V2 +) +{ + V1 = XMVectorSubtract(V1, V2); + return V1; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR& operator*= +( + XMVECTOR& V1, + FXMVECTOR V2 +) +{ + V1 = XMVectorMultiply(V1, V2); + return V1; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR& operator/= +( + XMVECTOR& V1, + FXMVECTOR V2 +) +{ + V1 = XMVectorDivide(V1,V2); + return V1; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR& operator*= +( + XMVECTOR& V, + CONST FLOAT S +) +{ + V = XMVectorScale(V, S); + return V; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR& operator/= +( + XMVECTOR& V, + CONST FLOAT S +) +{ + V = XMVectorScale(V, 1.0f / S); + return V; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator+ +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ + return XMVectorAdd(V1, V2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator- +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ + return XMVectorSubtract(V1, V2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator* +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ + return XMVectorMultiply(V1, V2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator/ +( + FXMVECTOR V1, + FXMVECTOR V2 +) +{ + return XMVectorDivide(V1,V2); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator* +( + FXMVECTOR V, + CONST FLOAT S +) +{ + return XMVectorScale(V, S); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator/ +( + FXMVECTOR V, + CONST FLOAT S +) +{ + return XMVectorScale(V, 1.0f / S); +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMVECTOR operator* +( + FLOAT S, + FXMVECTOR V +) +{ + return XMVectorScale(V, S); +} + +#endif // !XM_NO_OPERATOR_OVERLOADS + +/**************************************************************************** + * + * XMFLOAT2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT2::_XMFLOAT2 +( + CONST FLOAT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT2& _XMFLOAT2::operator= +( + CONST _XMFLOAT2& Float2 +) +{ + x = Float2.x; + y = Float2.y; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMFLOAT2A& XMFLOAT2A::operator= +( + CONST XMFLOAT2A& Float2 +) +{ + x = Float2.x; + y = Float2.y; + return *this; +} + +/**************************************************************************** + * + * XMINT2 operators + * + ****************************************************************************/ + +XMFINLINE _XMINT2::_XMINT2 +( + CONST INT *pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMINT2& _XMINT2::operator= +( + CONST _XMINT2& Int2 +) +{ + x = Int2.x; + y = Int2.y; + return *this; +} + +/**************************************************************************** + * + * XMUINT2 operators + * + ****************************************************************************/ + +XMFINLINE _XMUINT2::_XMUINT2 +( + CONST UINT *pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMUINT2& _XMUINT2::operator= +( + CONST _XMUINT2& UInt2 +) +{ + x = UInt2.x; + y = UInt2.y; + return *this; +} + +/**************************************************************************** + * + * XMHALF2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF2::_XMHALF2 +( + CONST HALF* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF2::_XMHALF2 +( + FLOAT _x, + FLOAT _y +) +{ + x = XMConvertFloatToHalf(_x); + y = XMConvertFloatToHalf(_y); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF2::_XMHALF2 +( + CONST FLOAT* pArray +) +{ + x = XMConvertFloatToHalf(pArray[0]); + y = XMConvertFloatToHalf(pArray[1]); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF2& _XMHALF2::operator= +( + CONST _XMHALF2& Half2 +) +{ + x = Half2.x; + y = Half2.y; + return *this; +} + +/**************************************************************************** + * + * XMSHORTN2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN2::_XMSHORTN2 +( + CONST SHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN2::_XMSHORTN2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreShortN2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN2::_XMSHORTN2 +( + CONST FLOAT* pArray +) +{ + XMStoreShortN2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN2& _XMSHORTN2::operator= +( + CONST _XMSHORTN2& ShortN2 +) +{ + x = ShortN2.x; + y = ShortN2.y; + return *this; +} + +/**************************************************************************** + * + * XMSHORT2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT2::_XMSHORT2 +( + CONST SHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT2::_XMSHORT2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreShort2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT2::_XMSHORT2 +( + CONST FLOAT* pArray +) +{ + XMStoreShort2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT2& _XMSHORT2::operator= +( + CONST _XMSHORT2& Short2 +) +{ + x = Short2.x; + y = Short2.y; + return *this; +} + +/**************************************************************************** + * + * XMUSHORTN2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN2::_XMUSHORTN2 +( + CONST USHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN2::_XMUSHORTN2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreUShortN2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN2::_XMUSHORTN2 +( + CONST FLOAT* pArray +) +{ + XMStoreUShortN2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN2& _XMUSHORTN2::operator= +( + CONST _XMUSHORTN2& UShortN2 +) +{ + x = UShortN2.x; + y = UShortN2.y; + return *this; +} + +/**************************************************************************** + * + * XMUSHORT2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT2::_XMUSHORT2 +( + CONST USHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT2::_XMUSHORT2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreUShort2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT2::_XMUSHORT2 +( + CONST FLOAT* pArray +) +{ + XMStoreUShort2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT2& _XMUSHORT2::operator= +( + CONST _XMUSHORT2& UShort2 +) +{ + x = UShort2.x; + y = UShort2.y; + return *this; +} + +/**************************************************************************** + * + * XMBYTEN2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN2::_XMBYTEN2 +( + CONST CHAR* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN2::_XMBYTEN2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreByteN2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN2::_XMBYTEN2 +( + CONST FLOAT* pArray +) +{ + XMStoreByteN2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN2& _XMBYTEN2::operator= +( + CONST _XMBYTEN2& ByteN2 +) +{ + x = ByteN2.x; + y = ByteN2.y; + return *this; +} + +/**************************************************************************** + * + * XMBYTE2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE2::_XMBYTE2 +( + CONST CHAR* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE2::_XMBYTE2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreByte2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE2::_XMBYTE2 +( + CONST FLOAT* pArray +) +{ + XMStoreByte2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE2& _XMBYTE2::operator= +( + CONST _XMBYTE2& Byte2 +) +{ + x = Byte2.x; + y = Byte2.y; + return *this; +} + +/**************************************************************************** + * + * XMUBYTEN2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN2::_XMUBYTEN2 +( + CONST BYTE* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN2::_XMUBYTEN2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreUByteN2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN2::_XMUBYTEN2 +( + CONST FLOAT* pArray +) +{ + XMStoreUByteN2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN2& _XMUBYTEN2::operator= +( + CONST _XMUBYTEN2& UByteN2 +) +{ + x = UByteN2.x; + y = UByteN2.y; + return *this; +} + +/**************************************************************************** + * + * XMUBYTE2 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE2::_XMUBYTE2 +( + CONST BYTE* pArray +) +{ + x = pArray[0]; + y = pArray[1]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE2::_XMUBYTE2 +( + FLOAT _x, + FLOAT _y +) +{ + XMStoreUByte2(this, XMVectorSet(_x, _y, 0.0f, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE2::_XMUBYTE2 +( + CONST FLOAT* pArray +) +{ + XMStoreUByte2(this, XMLoadFloat2((const XMFLOAT2*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE2& _XMUBYTE2::operator= +( + CONST _XMUBYTE2& UByte2 +) +{ + x = UByte2.x; + y = UByte2.y; + return *this; +} + +/**************************************************************************** + * + * XMFLOAT3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT3::_XMFLOAT3 +( + CONST FLOAT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT3& _XMFLOAT3::operator= +( + CONST _XMFLOAT3& Float3 +) +{ + x = Float3.x; + y = Float3.y; + z = Float3.z; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMFLOAT3A& XMFLOAT3A::operator= +( + CONST XMFLOAT3A& Float3 +) +{ + x = Float3.x; + y = Float3.y; + z = Float3.z; + return *this; +} + +/**************************************************************************** + * + * XMINT3 operators + * + ****************************************************************************/ + +XMFINLINE _XMINT3::_XMINT3 +( + CONST INT *pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMINT3& _XMINT3::operator= +( + CONST _XMINT3& Int3 +) +{ + x = Int3.x; + y = Int3.y; + z = Int3.z; + return *this; +} + +/**************************************************************************** + * + * XMUINT3 operators + * + ****************************************************************************/ + +XMFINLINE _XMUINT3::_XMUINT3 +( + CONST UINT *pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMUINT3& _XMUINT3::operator= +( + CONST _XMUINT3& UInt3 +) +{ + x = UInt3.x; + y = UInt3.y; + z = UInt3.z; + return *this; +} + +/**************************************************************************** + * + * XMHENDN3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHENDN3::_XMHENDN3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreHenDN3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHENDN3::_XMHENDN3 +( + CONST FLOAT* pArray +) +{ + XMStoreHenDN3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHENDN3& _XMHENDN3::operator= +( + CONST _XMHENDN3& HenDN3 +) +{ + v = HenDN3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHENDN3& _XMHENDN3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMHEND3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHEND3::_XMHEND3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreHenD3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHEND3::_XMHEND3 +( + CONST FLOAT* pArray +) +{ + XMStoreHenD3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHEND3& _XMHEND3::operator= +( + CONST _XMHEND3& HenD3 +) +{ + v = HenD3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHEND3& _XMHEND3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUHENDN3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHENDN3::_XMUHENDN3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreUHenDN3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHENDN3::_XMUHENDN3 +( + CONST FLOAT* pArray +) +{ + XMStoreUHenDN3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHENDN3& _XMUHENDN3::operator= +( + CONST _XMUHENDN3& UHenDN3 +) +{ + v = UHenDN3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHENDN3& _XMUHENDN3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUHEND3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHEND3::_XMUHEND3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreUHenD3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHEND3::_XMUHEND3 +( + CONST FLOAT* pArray +) +{ + XMStoreUHenD3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHEND3& _XMUHEND3::operator= +( + CONST _XMUHEND3& UHenD3 +) +{ + v = UHenD3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUHEND3& _XMUHEND3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMDHENN3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHENN3::_XMDHENN3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreDHenN3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHENN3::_XMDHENN3 +( + CONST FLOAT* pArray +) +{ + XMStoreDHenN3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHENN3& _XMDHENN3::operator= +( + CONST _XMDHENN3& DHenN3 +) +{ + v = DHenN3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHENN3& _XMDHENN3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMDHEN3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHEN3::_XMDHEN3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreDHen3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHEN3::_XMDHEN3 +( + CONST FLOAT* pArray +) +{ + XMStoreDHen3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHEN3& _XMDHEN3::operator= +( + CONST _XMDHEN3& DHen3 +) +{ + v = DHen3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDHEN3& _XMDHEN3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUDHENN3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHENN3::_XMUDHENN3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreUDHenN3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHENN3::_XMUDHENN3 +( + CONST FLOAT* pArray +) +{ + XMStoreUDHenN3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHENN3& _XMUDHENN3::operator= +( + CONST _XMUDHENN3& UDHenN3 +) +{ + v = UDHenN3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHENN3& _XMUDHENN3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUDHEN3 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHEN3::_XMUDHEN3 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreUDHen3(this, XMVectorSet(_x, _y, _z, 0.0f)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHEN3::_XMUDHEN3 +( + CONST FLOAT* pArray +) +{ + XMStoreUDHen3(this, XMLoadFloat3((const XMFLOAT3*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHEN3& _XMUDHEN3::operator= +( + CONST _XMUDHEN3& UDHen3 +) +{ + v = UDHen3.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDHEN3& _XMUDHEN3::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMU565 operators + * + ****************************************************************************/ + +XMFINLINE _XMU565::_XMU565 +( + CONST CHAR *pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; +} + +XMFINLINE _XMU565::_XMU565 +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreU565(this, XMVectorSet( _x, _y, _z, 0.0f )); +} + +XMFINLINE _XMU565::_XMU565 +( + CONST FLOAT *pArray +) +{ + XMStoreU565(this, XMLoadFloat3((const XMFLOAT3*)pArray )); +} + +XMFINLINE _XMU565& _XMU565::operator= +( + CONST _XMU565& U565 +) +{ + v = U565.v; + return *this; +} + +XMFINLINE _XMU565& _XMU565::operator= +( + CONST USHORT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMFLOAT3PK operators + * + ****************************************************************************/ + +XMFINLINE _XMFLOAT3PK::_XMFLOAT3PK +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreFloat3PK(this, XMVectorSet( _x, _y, _z, 0.0f )); +} + +XMFINLINE _XMFLOAT3PK::_XMFLOAT3PK +( + CONST FLOAT *pArray +) +{ + XMStoreFloat3PK(this, XMLoadFloat3((const XMFLOAT3*)pArray )); +} + +XMFINLINE _XMFLOAT3PK& _XMFLOAT3PK::operator= +( + CONST _XMFLOAT3PK& float3pk +) +{ + v = float3pk.v; + return *this; +} + +XMFINLINE _XMFLOAT3PK& _XMFLOAT3PK::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMFLOAT3SE operators + * + ****************************************************************************/ + +XMFINLINE _XMFLOAT3SE::_XMFLOAT3SE +( + FLOAT _x, + FLOAT _y, + FLOAT _z +) +{ + XMStoreFloat3SE(this, XMVectorSet( _x, _y, _z, 0.0f )); +} + +XMFINLINE _XMFLOAT3SE::_XMFLOAT3SE +( + CONST FLOAT *pArray +) +{ + XMStoreFloat3SE(this, XMLoadFloat3((const XMFLOAT3*)pArray )); +} + +XMFINLINE _XMFLOAT3SE& _XMFLOAT3SE::operator= +( + CONST _XMFLOAT3SE& float3se +) +{ + v = float3se.v; + return *this; +} + +XMFINLINE _XMFLOAT3SE& _XMFLOAT3SE::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMFLOAT4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4::_XMFLOAT4 +( + CONST FLOAT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMFLOAT4& _XMFLOAT4::operator= +( + CONST _XMFLOAT4& Float4 +) +{ + x = Float4.x; + y = Float4.y; + z = Float4.z; + w = Float4.w; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMFLOAT4A& XMFLOAT4A::operator= +( + CONST XMFLOAT4A& Float4 +) +{ + x = Float4.x; + y = Float4.y; + z = Float4.z; + w = Float4.w; + return *this; +} + +/**************************************************************************** + * + * XMINT4 operators + * + ****************************************************************************/ + +XMFINLINE _XMINT4::_XMINT4 +( + CONST INT *pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMINT4& _XMINT4::operator= +( + CONST _XMINT4& Int4 +) +{ + x = Int4.x; + y = Int4.y; + z = Int4.z; + w = Int4.w; + return *this; +} + +/**************************************************************************** + * + * XMUINT4 operators + * + ****************************************************************************/ + +XMFINLINE _XMUINT4::_XMUINT4 +( + CONST UINT *pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE XMUINT4& _XMUINT4::operator= +( + CONST _XMUINT4& UInt4 +) +{ + x = UInt4.x; + y = UInt4.y; + z = UInt4.z; + w = UInt4.w; + return *this; +} + +/**************************************************************************** + * + * XMHALF4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF4::_XMHALF4 +( + CONST HALF* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF4::_XMHALF4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + x = XMConvertFloatToHalf(_x); + y = XMConvertFloatToHalf(_y); + z = XMConvertFloatToHalf(_z); + w = XMConvertFloatToHalf(_w); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF4::_XMHALF4 +( + CONST FLOAT* pArray +) +{ + XMConvertFloatToHalfStream(&x, sizeof(HALF), pArray, sizeof(FLOAT), 4); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMHALF4& _XMHALF4::operator= +( + CONST _XMHALF4& Half4 +) +{ + x = Half4.x; + y = Half4.y; + z = Half4.z; + w = Half4.w; + return *this; +} + +/**************************************************************************** + * + * XMSHORTN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN4::_XMSHORTN4 +( + CONST SHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN4::_XMSHORTN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreShortN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN4::_XMSHORTN4 +( + CONST FLOAT* pArray +) +{ + XMStoreShortN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORTN4& _XMSHORTN4::operator= +( + CONST _XMSHORTN4& ShortN4 +) +{ + x = ShortN4.x; + y = ShortN4.y; + z = ShortN4.z; + w = ShortN4.w; + return *this; +} + +/**************************************************************************** + * + * XMSHORT4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT4::_XMSHORT4 +( + CONST SHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT4::_XMSHORT4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreShort4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT4::_XMSHORT4 +( + CONST FLOAT* pArray +) +{ + XMStoreShort4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMSHORT4& _XMSHORT4::operator= +( + CONST _XMSHORT4& Short4 +) +{ + x = Short4.x; + y = Short4.y; + z = Short4.z; + w = Short4.w; + return *this; +} + +/**************************************************************************** + * + * XMUSHORTN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN4::_XMUSHORTN4 +( + CONST USHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN4::_XMUSHORTN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUShortN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN4::_XMUSHORTN4 +( + CONST FLOAT* pArray +) +{ + XMStoreUShortN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORTN4& _XMUSHORTN4::operator= +( + CONST _XMUSHORTN4& UShortN4 +) +{ + x = UShortN4.x; + y = UShortN4.y; + z = UShortN4.z; + w = UShortN4.w; + return *this; +} + +/**************************************************************************** + * + * XMUSHORT4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT4::_XMUSHORT4 +( + CONST USHORT* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT4::_XMUSHORT4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUShort4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT4::_XMUSHORT4 +( + CONST FLOAT* pArray +) +{ + XMStoreUShort4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUSHORT4& _XMUSHORT4::operator= +( + CONST _XMUSHORT4& UShort4 +) +{ + x = UShort4.x; + y = UShort4.y; + z = UShort4.z; + w = UShort4.w; + return *this; +} + +/**************************************************************************** + * + * XMXDECN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDECN4::_XMXDECN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreXDecN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDECN4::_XMXDECN4 +( + CONST FLOAT* pArray +) +{ + XMStoreXDecN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDECN4& _XMXDECN4::operator= +( + CONST _XMXDECN4& XDecN4 +) +{ + v = XDecN4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDECN4& _XMXDECN4::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMXDEC4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDEC4::_XMXDEC4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreXDec4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDEC4::_XMXDEC4 +( + CONST FLOAT* pArray +) +{ + XMStoreXDec4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDEC4& _XMXDEC4::operator= +( + CONST _XMXDEC4& XDec4 +) +{ + v = XDec4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXDEC4& _XMXDEC4::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMDECN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDECN4::_XMDECN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreDecN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDECN4::_XMDECN4 +( + CONST FLOAT* pArray +) +{ + XMStoreDecN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDECN4& _XMDECN4::operator= +( + CONST _XMDECN4& DecN4 +) +{ + v = DecN4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDECN4& _XMDECN4::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMDEC4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDEC4::_XMDEC4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreDec4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDEC4::_XMDEC4 +( + CONST FLOAT* pArray +) +{ + XMStoreDec4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDEC4& _XMDEC4::operator= +( + CONST _XMDEC4& Dec4 +) +{ + v = Dec4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMDEC4& _XMDEC4::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUDECN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDECN4::_XMUDECN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUDecN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDECN4::_XMUDECN4 +( + CONST FLOAT* pArray +) +{ + XMStoreUDecN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDECN4& _XMUDECN4::operator= +( + CONST _XMUDECN4& UDecN4 +) +{ + v = UDecN4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDECN4& _XMUDECN4::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUDEC4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDEC4::_XMUDEC4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUDec4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDEC4::_XMUDEC4 +( + CONST FLOAT* pArray +) +{ + XMStoreUDec4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDEC4& _XMUDEC4::operator= +( + CONST _XMUDEC4& UDec4 +) +{ + v = UDec4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUDEC4& _XMUDEC4::operator= +( + CONST UINT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMXICON4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICON4::_XMXICON4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreXIcoN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICON4::_XMXICON4 +( + CONST FLOAT* pArray +) +{ + XMStoreXIcoN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICON4& _XMXICON4::operator= +( + CONST _XMXICON4& XIcoN4 +) +{ + v = XIcoN4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICON4& _XMXICON4::operator= +( + CONST UINT64 Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMXICO4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICO4::_XMXICO4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreXIco4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICO4::_XMXICO4 +( + CONST FLOAT* pArray +) +{ + XMStoreXIco4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICO4& _XMXICO4::operator= +( + CONST _XMXICO4& XIco4 +) +{ + v = XIco4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMXICO4& _XMXICO4::operator= +( + CONST UINT64 Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMICON4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICON4::_XMICON4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreIcoN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICON4::_XMICON4 +( + CONST FLOAT* pArray +) +{ + XMStoreIcoN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICON4& _XMICON4::operator= +( + CONST _XMICON4& IcoN4 +) +{ + v = IcoN4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICON4& _XMICON4::operator= +( + CONST UINT64 Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMICO4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICO4::_XMICO4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreIco4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICO4::_XMICO4 +( + CONST FLOAT* pArray +) +{ + XMStoreIco4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICO4& _XMICO4::operator= +( + CONST _XMICO4& Ico4 +) +{ + v = Ico4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMICO4& _XMICO4::operator= +( + CONST UINT64 Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUICON4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICON4::_XMUICON4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUIcoN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICON4::_XMUICON4 +( + CONST FLOAT* pArray +) +{ + XMStoreUIcoN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICON4& _XMUICON4::operator= +( + CONST _XMUICON4& UIcoN4 +) +{ + v = UIcoN4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICON4& _XMUICON4::operator= +( + CONST UINT64 Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMUICO4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICO4::_XMUICO4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUIco4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICO4::_XMUICO4 +( + CONST FLOAT* pArray +) +{ + XMStoreUIco4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICO4& _XMUICO4::operator= +( + CONST _XMUICO4& UIco4 +) +{ + v = UIco4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUICO4& _XMUICO4::operator= +( + CONST UINT64 Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMCOLOR4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMCOLOR::_XMCOLOR +( + FLOAT _r, + FLOAT _g, + FLOAT _b, + FLOAT _a +) +{ + XMStoreColor(this, XMVectorSet(_r, _g, _b, _a)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMCOLOR::_XMCOLOR +( + CONST FLOAT* pArray +) +{ + XMStoreColor(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMCOLOR& _XMCOLOR::operator= +( + CONST _XMCOLOR& Color +) +{ + c = Color.c; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMCOLOR& _XMCOLOR::operator= +( + CONST UINT Color +) +{ + c = Color; + return *this; +} + +/**************************************************************************** + * + * XMBYTEN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN4::_XMBYTEN4 +( + CONST CHAR* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN4::_XMBYTEN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreByteN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN4::_XMBYTEN4 +( + CONST FLOAT* pArray +) +{ + XMStoreByteN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTEN4& _XMBYTEN4::operator= +( + CONST _XMBYTEN4& ByteN4 +) +{ + x = ByteN4.x; + y = ByteN4.y; + z = ByteN4.z; + w = ByteN4.w; + return *this; +} + +/**************************************************************************** + * + * XMBYTE4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE4::_XMBYTE4 +( + CONST CHAR* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE4::_XMBYTE4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreByte4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE4::_XMBYTE4 +( + CONST FLOAT* pArray +) +{ + XMStoreByte4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMBYTE4& _XMBYTE4::operator= +( + CONST _XMBYTE4& Byte4 +) +{ + x = Byte4.x; + y = Byte4.y; + z = Byte4.z; + w = Byte4.w; + return *this; +} + +/**************************************************************************** + * + * XMUBYTEN4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN4::_XMUBYTEN4 +( + CONST BYTE* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN4::_XMUBYTEN4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUByteN4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN4::_XMUBYTEN4 +( + CONST FLOAT* pArray +) +{ + XMStoreUByteN4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTEN4& _XMUBYTEN4::operator= +( + CONST _XMUBYTEN4& UByteN4 +) +{ + x = UByteN4.x; + y = UByteN4.y; + z = UByteN4.z; + w = UByteN4.w; + return *this; +} + +/**************************************************************************** + * + * XMUBYTE4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE4::_XMUBYTE4 +( + CONST BYTE* pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE4::_XMUBYTE4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUByte4(this, XMVectorSet(_x, _y, _z, _w)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE4::_XMUBYTE4 +( + CONST FLOAT* pArray +) +{ + XMStoreUByte4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUBYTE4& _XMUBYTE4::operator= +( + CONST _XMUBYTE4& UByte4 +) +{ + x = UByte4.x; + y = UByte4.y; + z = UByte4.z; + w = UByte4.w; + return *this; +} + +/**************************************************************************** + * + * XMUNIBBLE4 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUNIBBLE4::_XMUNIBBLE4 +( + CONST CHAR *pArray +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = pArray[3]; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUNIBBLE4::_XMUNIBBLE4 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + FLOAT _w +) +{ + XMStoreUNibble4(this, XMVectorSet( _x, _y, _z, _w )); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUNIBBLE4::_XMUNIBBLE4 +( + CONST FLOAT *pArray +) +{ + XMStoreUNibble4(this, XMLoadFloat4((const XMFLOAT4*)pArray)); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUNIBBLE4& _XMUNIBBLE4::operator= +( + CONST _XMUNIBBLE4& UNibble4 +) +{ + v = UNibble4.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMUNIBBLE4& _XMUNIBBLE4::operator= +( + CONST USHORT Packed +) +{ + v = Packed; + return *this; +} + +/**************************************************************************** + * + * XMU555 operators + * + ****************************************************************************/ + +//------------------------------------------------------------------------------ + +XMFINLINE _XMU555::_XMU555 +( + CONST CHAR *pArray, + BOOL _w +) +{ + x = pArray[0]; + y = pArray[1]; + z = pArray[2]; + w = _w; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMU555::_XMU555 +( + FLOAT _x, + FLOAT _y, + FLOAT _z, + BOOL _w +) +{ + XMStoreU555(this, XMVectorSet(_x, _y, _z, ((_w) ? 1.0f : 0.0f) )); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMU555::_XMU555 +( + CONST FLOAT *pArray, + BOOL _w +) +{ + XMVECTOR V = XMLoadFloat3((const XMFLOAT3*)pArray); + XMStoreU555(this, XMVectorSetW(V, ((_w) ? 1.0f : 0.0f) )); +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMU555& _XMU555::operator= +( + CONST _XMU555& U555 +) +{ + v = U555.v; + return *this; +} + +//------------------------------------------------------------------------------ + +XMFINLINE _XMU555& _XMU555::operator= +( + CONST USHORT Packed +) +{ + v = Packed; + return *this; +} + +#endif // __cplusplus + +#if defined(_XM_NO_INTRINSICS_) +#undef XMISNAN +#undef XMISINF +#endif + +#endif // __XNAMATHVECTOR_INL__ + diff --git a/third_party/xbox_sdk/include/xsim.h b/third_party/xbox_sdk/include/xsim.h new file mode 100644 index 0000000..77e84c2 --- /dev/null +++ b/third_party/xbox_sdk/include/xsim.h @@ -0,0 +1,157 @@ +//-------------------------------------------------------------------------------------- +// XSim.h +// +// C-Style API for XSim +// +// Microsoft Game Studios Tools and Technology Group +// Copyright (C) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- +#pragma once + +#ifndef _XSIM_H_ +#define _XSIM_H_ + +#include + +// Putting these here so that XSim clients only need to include XSim.h + +#ifndef XSIM_INTERNAL +#include +#endif +#include "XSimError.h" + +#ifdef __cplusplus +extern "C" { +#endif + +const DWORD DEFAULT_COMPONENT_FRAMERATE = 60; +const DWORD DM_AUTOMATION_INPUTQUEUE_LENGTH = 100; +const DWORD IO_BUFFER_SIZE = 16384; // Buffer size is one Xbox HD sector. + +//------------------------------------------------------------------------------ +// Handle definition +//------------------------------------------------------------------------------ +typedef HANDLE XSIMHANDLE; + +//------------------------------------------------------------------------------ +// General component status +//------------------------------------------------------------------------------ +typedef enum _XSIM_COMPONENTSTATUS { + XSIM_COMPONENTSTATUS_IDLE, + XSIM_COMPONENTSTATUS_RUNNING +} XSIM_COMPONENTSTATUS; + +//------------------------------------------------------------------------------ +// Synchronization mode used by TextSequencePlayer +//------------------------------------------------------------------------------ +typedef enum _XSIM_SYNCHMODE { + XSIM_SYNCHMODE_FRAME = 0x00000001, + XSIM_SYNCHMODE_TIME = 0x00000002 +} XSIM_SYNCHMODE; + +//------------------------------------------------------------------------------ +// Structs used for Random Input Player button press timings +//------------------------------------------------------------------------------ +typedef struct _XSIM_BUTTONPRESSATTRIBUTES { + DWORD dwIntervalMinMs; + DWORD dwIntervalMaxMs; + DWORD dwHoldTimeMinMs; + DWORD dwHoldTimeMaxMs; +} XSIM_BUTTONPRESSATTRIBUTES; + +typedef struct _XSIM_CONTROLLERPRESSATTRIBUTES { + XSIM_BUTTONPRESSATTRIBUTES DpadUp; + XSIM_BUTTONPRESSATTRIBUTES DpadDown; + XSIM_BUTTONPRESSATTRIBUTES DpadLeft; + XSIM_BUTTONPRESSATTRIBUTES DpadRight; + XSIM_BUTTONPRESSATTRIBUTES Start; + XSIM_BUTTONPRESSATTRIBUTES Back; + XSIM_BUTTONPRESSATTRIBUTES LeftThumb; + XSIM_BUTTONPRESSATTRIBUTES RightThumb; + XSIM_BUTTONPRESSATTRIBUTES LeftShoulder; + XSIM_BUTTONPRESSATTRIBUTES RightShoulder; + XSIM_BUTTONPRESSATTRIBUTES A; + XSIM_BUTTONPRESSATTRIBUTES B; + XSIM_BUTTONPRESSATTRIBUTES X; + XSIM_BUTTONPRESSATTRIBUTES Y; + XSIM_BUTTONPRESSATTRIBUTES XBox360Button; + XSIM_BUTTONPRESSATTRIBUTES RightTrigger; + XSIM_BUTTONPRESSATTRIBUTES LeftTrigger; + XSIM_BUTTONPRESSATTRIBUTES ThumbLX; + XSIM_BUTTONPRESSATTRIBUTES ThumbLY; + XSIM_BUTTONPRESSATTRIBUTES ThumbRX; + XSIM_BUTTONPRESSATTRIBUTES ThumbRY; +} XSIM_CONTROLLERPRESSATTRIBUTES; + +//------------------------------------------------------------------------------ +// User index bits used for building user index masks +//------------------------------------------------------------------------------ +typedef enum _XSIM_USERINDEXMASK { + XSIM_USERINDEXMASK_0 = 0x00000001, + XSIM_USERINDEXMASK_1 = 0x00000002, + XSIM_USERINDEXMASK_2 = 0x00000004, + XSIM_USERINDEXMASK_3 = 0x00000008, + XSIM_USERINDEXMASK_ALL = 0x0000000F, +} XSIM_USERINDEXMASK; + +//------------------------------------------------------------------------------ +// XSim Functions +//------------------------------------------------------------------------------ +// Initialize/Uninitialize +HRESULT WINAPI XSimInitialize( __in DWORD dwComponentFrameRate ); +HRESULT WINAPI XSimUninitialize( ); + +// Take/Return control from/to the physical controller +HRESULT WINAPI XSimAcquireControl( __in DWORD dwUserIndexMask ); +HRESULT WINAPI XSimReturnControl( __in DWORD dwUserIndexMask ); + +// Player creation +HRESULT WINAPI XSimCreateRandomInputPlayer( __out XSIMHANDLE* phXSimHandle ); +HRESULT WINAPI XSimCreateRandomStatePlayer( __in_z LPCSTR lpFileName, __out XSIMHANDLE* phXSimHandle ); +HRESULT WINAPI XSimCreateFilePlayer( __in_z LPCSTR lpFileName, + __in XSIM_SYNCHMODE eSynchMode, + __out XSIMHANDLE* phXSimHandle ); +HRESULT WINAPI XSimCreateTextSequencePlayer( __in_z LPCSTR lpPlaybackString, + __in XSIM_SYNCHMODE eSynchMode, + __in DWORD dwDefaultPlaybackRate, + __out XSIMHANDLE* phXSimHandle ); +// Recorder creation +HRESULT WINAPI XSimCreateFileRecorder( __in_z LPCSTR lpFileName, __out XSIMHANDLE* phXSimHandle ); + +// Handle releasing +HRESULT WINAPI XSimCloseHandle( __in XSIMHANDLE hXSimHandle ); + +// Start/Stop player(s) +HRESULT WINAPI XSimStartPlayer( __in XSIMHANDLE hXSimHandle, __in DWORD dwUserIndex ); +HRESULT WINAPI XSimStopPlayer( __in DWORD dwUserIndex); + +// Start/Stop recorder(s) +HRESULT WINAPI XSimStartRecorder( __in XSIMHANDLE hXSimHandle, __in DWORD dwUserIndex ); +HRESULT WINAPI XSimStopRecorder( __in DWORD dwUserIndex ); + +// Player/Recorder status +HRESULT WINAPI XSimGetPortPlayerStatus( __in DWORD dwUserIndex, __out XSIM_COMPONENTSTATUS* pStatus ); +HRESULT WINAPI XSimGetPortRecorderStatus( __in DWORD dwUserIndex, __out XSIM_COMPONENTSTATUS* pStatus ); + +// Random Input Player settings +HRESULT WINAPI XSimSetRandomInputPlayerConnectAttributes( __in XSIMHANDLE hXSimHandle, + __in BOOL bStartConnected, + __in DWORD dwDisconnectIntervalMin, + __in DWORD dwDisconnectIntervalMax, + __in DWORD dwReconnectIntervalMin, + __in DWORD dwReconnectIntervalMax ); +HRESULT WINAPI XSimGetRandomInputPlayerPressAttributes( __in XSIMHANDLE hXSimHandle, __out XSIM_CONTROLLERPRESSATTRIBUTES* pPressAttributes ); +HRESULT WINAPI XSimSetRandomInputPlayerPressAttributes( __in XSIMHANDLE hXSimHandle, __in XSIM_CONTROLLERPRESSATTRIBUTES* pPressAttributes ); + +// Random State Player state control +HRESULT WINAPI XSimGetRandomStatePlayerState( __in XSIMHANDLE hXSimHandle, + __in DWORD dwBufferSize, + __out_ecount(dwBufferSize) LPSTR lpStateName ); +HRESULT WINAPI XSimSetRandomStatePlayerState( __in XSIMHANDLE hXSimHandle, __in_z LPCSTR lpStateName ); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/third_party/xbox_sdk/include/xsimerror.h b/third_party/xbox_sdk/include/xsimerror.h new file mode 100644 index 0000000..590a7cf --- /dev/null +++ b/third_party/xbox_sdk/include/xsimerror.h @@ -0,0 +1,72 @@ +//-------------------------------------------------------------------------------------- +// XSimError +// +// Error codes generated by XSim +// +// Microsoft Game Studios Tools and Technology Group +// Copyright (C) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + +#pragma once + +#ifndef MAKE_HRESULT +#define MAKE_HRESULT(sev,fac,code) ((HRESULT)(((unsigned long)(sev)<<31)|((unsigned long)(fac)<<16)|((unsigned long)(code)))) +#endif + +#define XSIM_FACILITY 0x71 + +// Success codes +#define XSIM_S_OK S_OK + +#define XSIM_S_FIRST MAKE_HRESULT(0, XSIM_FACILITY, 0x0000) +#define XSIM_S_ALREADY_STARTED XSIM_S_FIRST + 1 // 0x00710001 // player/recorder already started +#define XSIM_S_ALREADY_STOPPED XSIM_S_FIRST + 2 // 0x00710002 // player/recorder already stopped +#define XSIM_S_THREAD_ALREADYRUNNING XSIM_S_FIRST + 3 // 0x00710003 // The thread is already running +#define XSIM_S_OUTOFINPUTS XSIM_S_FIRST + 4 // 0x00710004 // The sequence player is out of inputs (queue manager should stop the player) + +// Error codes +#define XSIM_E_FIRST_ERROR MAKE_HRESULT(SEVERITY_ERROR, XSIM_FACILITY, 0x0000) +#define XSIM_E_FAIL XSIM_E_FIRST_ERROR + 1 // 0x80710001 // Unspecified failure +#define XSIM_E_MEMORY XSIM_E_FIRST_ERROR + 2 // 0x80710002 // Out of memory +#define XSIM_E_THREAD XSIM_E_FIRST_ERROR + 3 // 0x80710003 // Threading error +#define XSIM_E_SEQUENCE_PARSE_ERROR XSIM_E_FIRST_ERROR + 4 // 0x80710004 // Error parsing text sequence +#define XSIM_E_OPEN_FILE_FAILED XSIM_E_FIRST_ERROR + 5 // 0x80710005 // Couldn't open file +#define XSIM_E_READ_FILE_FAILED XSIM_E_FIRST_ERROR + 6 // 0x80710006 // Couldn't read from file +#define XSIM_E_WRITE_FILE_FAILED XSIM_E_FIRST_ERROR + 7 // 0x80710007 // Couldn't write to file +#define XSIM_E_INVALID_FILE XSIM_E_FIRST_ERROR + 8 // 0x80710008 // Invalid file format +#define XSIM_E_XML_PARSE_ERROR XSIM_E_FIRST_ERROR + 9 // 0x80710009 // RandomState XML file parse error +#define XSIM_E_UNSPECIFIED_INITIAL_STATE XSIM_E_FIRST_ERROR + 10 // 0x8071000A // RandomState no initial state specified +#define XSIM_E_NO_CURRENT_STATE XSIM_E_FIRST_ERROR + 11 // 0x8071000B // RandomState no current state set +#define XSIM_E_NO_CURRENT_CHOICE XSIM_E_FIRST_ERROR + 12 // 0x8071000C // RandomState no current choice set +#define XSIM_E_NO_STATES XSIM_E_FIRST_ERROR + 13 // 0x8071000D // RandomState no states defined +#define XSIM_E_NO_CHOICES XSIM_E_FIRST_ERROR + 14 // 0x8071000E // RandomState no choices defined in state +#define XSIM_E_NO_ACTION XSIM_E_FIRST_ERROR + 15 // 0x8071000F // RandomState no action define in choice +#define XSIM_E_ASYNC_REQUIRES_BUFFER XSIM_E_FIRST_ERROR + 16 // 0x80710010 // Asynchronous read/writes require bufsize > 0 +#define XSIM_E_INVALID_HANDLE XSIM_E_FIRST_ERROR + 17 // 0x80710011 // Invalid handle +#define XSIM_E_NOT_INITIALIZED XSIM_E_FIRST_ERROR + 18 // 0x80710012 // XSimInitialize() hasn't been called +#define XSIM_E_INVALIDARG XSIM_E_FIRST_ERROR + 19 // 0x80710013 // Invalid argument (NULL pointer, etc) +#define XSIM_E_OUT_OF_HANDLES XSIM_E_FIRST_ERROR + 20 // 0x80710014 // No free handles remaining +#define XSIM_E_INVALID_USER_INDEX XSIM_E_FIRST_ERROR + 21 // 0x80710015 // Specified a user index greater than XUSER_MAX_COUNT-1 +#define XSIM_E_INVALID_PLAYER XSIM_E_FIRST_ERROR + 22 // 0x80710016 // Attempted an operation with component that wasn't a player +#define XSIM_E_INVALID_RECORDER XSIM_E_FIRST_ERROR + 23 // 0x80710017 // Attempted an operation with component that wasn't a recorder +#define XSIM_E_PLAYER_IN_USE XSIM_E_FIRST_ERROR + 24 // 0x80710018 // Attempted to start a player that is already in use on another port +#define XSIM_E_RECORDER_IN_USE XSIM_E_FIRST_ERROR + 25 // 0x80710019 // Attempted to start a player that is already in use on another port +#define XSIM_E_NO_CONNECTION XSIM_E_FIRST_ERROR + 26 // 0x8071001A // Attempted to send a message to the XSim debugger extension DLL without a connection handle +#define XSIM_E_NOTIMPL XSIM_E_FIRST_ERROR + 27 // 0x8071001B // Feature not implemented +#define XSIM_E_INVALID_MSG XSIM_E_FIRST_ERROR + 28 // 0x8071001C // XSim Debugger extension received a debug channel message it did not understand +#define XSIM_E_NOT_SYNCHRONOUS XSIM_E_FIRST_ERROR + 29 // 0x8071001D // A player or recorder was told to start synchronously on the console, but it's not a remote player! +#define XSIM_E_INVALID_STATE_NAME XSIM_E_FIRST_ERROR + 30 // 0x8071001E // RandomState Invalid state name +#define XSIM_E_BUFFER_TOO_SMALL XSIM_E_FIRST_ERROR + 31 // 0x8071001F // Buffer too small +#define XSIM_E_INVALID_SYNCMODE XSIM_E_FIRST_ERROR + 32 // 0x80710020 // Invalid sync mode for FileRecorder or FilePlayer +#define XSIM_E_INVALID_PRESSDURATION XSIM_E_FIRST_ERROR + 33 // 0x80710021 // Invalid press duruation supplied to queue manager +#define XSIM_E_USER_INDEX_NOT_ACQUIRED XSIM_E_FIRST_ERROR + 34 // 0x80710022 // Attempted to use a player/recorder on an unbound user index +#define XSIM_E_ALREADY_ACQUIRED XSIM_E_FIRST_ERROR + 35 // 0x80710023 // Attempted to acquire a controller that is already acquired +#define XSIM_E_NOT_ACQUIRED XSIM_E_FIRST_ERROR + 36 // 0x80710024 // Attempted to release a controller that is not acquired +#define XSIM_E_ALREADY_INITIALIZED XSIM_E_FIRST_ERROR + 37 // 0x80710025 // XSimInitialize() has already been called +#define XSIM_E_FILENOTFOUND XSIM_E_FIRST_ERROR + 38 // 0x80710026 // The file specified for the fileplayer or filerecorder was not found on the console +#define XSIM_E_CANNOTACCESS XSIM_E_FIRST_ERROR + 39 // 0x80710027 // The default console is locked and/or the automation PC does not have permission connect to it +#define XSIM_E_SINGLE_PLAYER_ONLY XSIM_E_FIRST_ERROR + 40 // 0x80710028 // Only one player is allowed to be playing at any time +#define XSIM_E_SINGLE_RECORDER_ONLY XSIM_E_FIRST_ERROR + 41 // 0x80710029 // Only one recorder is allowed to be recording at any time +#define XSIM_E_CONNECTIONLOST XSIM_E_FIRST_ERROR + 42 // 0x8071002A // The connection was lost to the console. Check network cables, etc. shut down, restart, retry +#define XSIM_E_EXTENSION_NOTFOUND XSIM_E_FIRST_ERROR + 43 // 0x8071002B // XSim.xex was not found on your Xbox + diff --git a/third_party/xbox_sdk/include/xwmaencoder.h b/third_party/xbox_sdk/include/xwmaencoder.h new file mode 100644 index 0000000..1dbc074 --- /dev/null +++ b/third_party/xbox_sdk/include/xwmaencoder.h @@ -0,0 +1,103 @@ +/************************************************************************** + * + * Copyright (C) Microsoft Corporation. All rights reserved. + * + * Module Name: + * + * XWMAEncoder.h + * + * Abstract: + * + * xWMA encoder public interfaces, functions and data types + * + **************************************************************************/ + +#ifndef _XWMAENCODER_H_ +#define _XWMAENCODER_H_ + +#if defined (_MSC_VER) && (_MSC_VER >= 1020) + #pragma once +#endif // #if defined (_MSC_VER) && (_MSC_VER >= 1020) + +// Default XWMA encoding bitrate +#define XWMA_DEFAULT_BITRATE 48000 + +// XWMA encoder error codes +#define FACILITY_XWMA 0x899 +#define XWMA_ERROR(n) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_XWMA, n) + +#define XWMA_E_UNSUPPORTED_FORMATTAG XWMA_ERROR(0x01) // format tag must be WAVE_FORMAT_PCM or WAVE_FORMAT_IEEE_FLOAT +#define XWMA_E_UNSUPPORTED_FRAMERATE XWMA_ERROR(0x02) // nSamplesPerSec must be between 1kHz and 200kHz +#define XWMA_E_UNSUPPORTED_CHANNELS XWMA_ERROR(0x03) // nChannels must be 1, 2, or 6 +#define XWMA_E_UNSUPPORTED_BITSPERSAMPLE XWMA_ERROR(0x04) // wBitsPerSample must be 8, 16 or 24 for integer input data or 32 for floating-point data +#define XWMA_E_UNSUPPORTED_BITRATE XWMA_ERROR(0x05) // bitrate must be 20kbps, 32kbps, 48kbps, 64kbps, 96kbps, 16kbps0, or 192kbps + +#ifndef _WAVEFORMATEX_ +#define _WAVEFORMATEX_ + #pragma pack(push, 1) + typedef struct tWAVEFORMATEX + { + WORD wFormatTag; // format type + WORD nChannels; // number of channels (i.e. mono, stereo...) + DWORD nSamplesPerSec; // sample rate + DWORD nAvgBytesPerSec; // for buffer estimation + WORD nBlockAlign; // block size of data + WORD wBitsPerSample; // Number of bits per sample of mono data + WORD cbSize; // The count in bytes of the size of extra information (after cbSize) + + } WAVEFORMATEX, *PWAVEFORMATEX; + typedef WAVEFORMATEX NEAR *NPWAVEFORMATEX; + typedef WAVEFORMATEX FAR *LPWAVEFORMATEX; + #pragma pack(pop) +#endif + +//// +// DESCRIPTION: +// Encodes PCM data to xWMA +// +// REMARKS: +// Resamples and pads the input data if necessary for it to encode successfully. +// May have to adjust the bitrate. +// +// PARAMETERS: +// pInputBuffer - [in] input buffer, contains PCM data, must contain at least one frame +// inputBufferSize - [in] size of input buffer (in bytes) +// pInputFormat - [in] input buffer format +// outputBitrate - [in] requested WMA encoder bitrate +// Must be one of 20000, 32000, 48000, 64000, 96000, 160000 or 192000 +// Natively supported bitrates per sample rate and channel count: +// 22050Hz mono: 20000 +// 22050Hz stereo: 32000 +// 32000Hz mono: 20000 +// 32000Hz stereo: 32000, 48000 +// 44100Hz mono: 32000, 48000 +// 44100Hz stereo: 32000, 48000, 96000, 192000 +// 44100Hz 5.1: 96000, 192000 +// 48000Hz stereo: 48000, 64000, 96000, 160000, 192000 +// 48000Hz 5.1: 48000, 192000 +// ppEncodedBuffer - [out] output buffer (use free [] to release) +// pEncodedBufferSize - [out] size of output buffer (in bytes) +// ppEncodedBufferFormat - [out] output buffer format (use free [] to release) +// pEncodedBufferFormatSize - [out] size of output buffer format +// ppDecodedPacketCumulativeBytes - [out] decoded packet cumulative data size array (use free [] to release) +// pDecodedPacketCumulativeBytesSize - [out] size of decoded packet cumulative data (in bytes) - number of packets = *pDecodedPacketCumulativeBytesSize / sizeof(DWORD) +// +// RETURN VALUE: +// S_OK on success, any other value on failure (see error codes above for reference) +//// + +STDAPI +XWMAEncoder( + __in_bcount(inputBufferSize) const BYTE* pInputBuffer, + __in DWORD inputBufferSize, + __in const WAVEFORMATEX* pInputFormat, + __in DWORD outputBitrate, + __deref_out_bcount(*pEncodedBufferSize) BYTE** ppEncodedBuffer, + __out DWORD* pEncodedBufferSize, + __deref_out_bcount(*pEncodedBufferFormatSize) WAVEFORMATEX** ppEncodedBufferFormat, + __out DWORD* pEncodedBufferFormatSize, + __deref_out_bcount(*pDecodedPacketCumulativeBytesSize) DWORD** ppDecodedPacketCumulativeBytes, + __out DWORD* pDecodedPacketCumulativeBytesSize + ); + +#endif // #ifndef _XWMAENCODER_H_ diff --git a/third_party/xbox_sdk/lib/xcompress32.dll b/third_party/xbox_sdk/lib/xcompress32.dll new file mode 100644 index 0000000..2e22c63 Binary files /dev/null and b/third_party/xbox_sdk/lib/xcompress32.dll differ diff --git a/third_party/xbox_sdk/lib/xcompress32.lib b/third_party/xbox_sdk/lib/xcompress32.lib new file mode 100644 index 0000000..7597f53 Binary files /dev/null and b/third_party/xbox_sdk/lib/xcompress32.lib differ diff --git a/third_party/xbox_sdk/lib/xcompress64.dll b/third_party/xbox_sdk/lib/xcompress64.dll new file mode 100644 index 0000000..58518de Binary files /dev/null and b/third_party/xbox_sdk/lib/xcompress64.dll differ diff --git a/third_party/xbox_sdk/lib/xcompress64.lib b/third_party/xbox_sdk/lib/xcompress64.lib new file mode 100644 index 0000000..e84b564 Binary files /dev/null and b/third_party/xbox_sdk/lib/xcompress64.lib differ diff --git a/third_party/xna/lib/XnaNative.dll b/third_party/xna/lib/XnaNative.dll new file mode 100644 index 0000000..b8ab1b4 Binary files /dev/null and b/third_party/xna/lib/XnaNative.dll differ diff --git a/third_party/zlib/include/deflate.h b/third_party/zlib/include/deflate.h new file mode 100644 index 0000000..a5d5acc --- /dev/null +++ b/third_party/zlib/include/deflate.h @@ -0,0 +1,331 @@ +/* deflate.h -- internal compression state + * Copyright (C) 1995-2004 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id$ */ + +#ifndef DEFLATE_H +#define DEFLATE_H + +#include "zutil.h" + +/* define NO_GZIP when compiling if you want to disable gzip header and + trailer creation by deflate(). NO_GZIP would be used to avoid linking in + the crc code when it is not needed. For shared libraries, gzip encoding + should be left enabled. */ +#ifndef NO_GZIP +# define GZIP +#endif + +/* =========================================================================== + * Internal compression state. + */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define INIT_STATE 42 +#define EXTRA_STATE 69 +#define NAME_STATE 73 +#define COMMENT_STATE 91 +#define HCRC_STATE 103 +#define BUSY_STATE 113 +#define FINISH_STATE 666 +/* Stream status */ + + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data_s { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} FAR ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +typedef struct static_tree_desc_s static_tree_desc; + +typedef struct tree_desc_s { + ct_data *dyn_tree; /* the dynamic tree */ + int max_code; /* largest code with non zero frequency */ + static_tree_desc *stat_desc; /* the corresponding static tree */ +} FAR tree_desc; + +typedef ush Pos; +typedef Pos FAR Posf; +typedef unsigned IPos; + +/* A Pos is an index in the character window. We use short instead of int to + * save space in the various tables. IPos is used only for parameter passing. + */ + +typedef struct internal_state { + z_streamp strm; /* pointer back to this zlib stream */ + int status; /* as the name implies */ + Byte_zf *pending_buf; /* output still pending */ + ulg pending_buf_size; /* size of pending_buf */ + Byte_zf *pending_out; /* next pending byte to output to the stream */ + uInt pending; /* nb of bytes in the pending buffer */ + int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ + gz_headerp gzhead; /* gzip header information to write */ + uInt gzindex; /* where in extra, name, or comment */ + Byte_z method; /* STORED (for zip only) or DEFLATED */ + int last_flush; /* value of flush param for previous deflate call */ + + /* used by deflate.c: */ + + uInt w_size; /* LZ77 window size (32K by default) */ + uInt w_bits; /* log2(w_size) (8..16) */ + uInt w_mask; /* w_size - 1 */ + + Byte_zf *window; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. Also, it limits + * the window size to 64K, which is quite useful on MSDOS. + * To do: use the user input buffer as sliding window. + */ + + ulg window_size; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + Posf *prev; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + Posf *head; /* Heads of the hash chains or NIL. */ + + uInt ins_h; /* hash index of string to be inserted */ + uInt hash_size; /* number of elements in hash table */ + uInt hash_bits; /* log2(hash_size) */ + uInt hash_mask; /* hash_size-1 */ + + uInt hash_shift; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + long block_start; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + uInt match_length; /* length of best match */ + IPos prev_match; /* previous match */ + int match_available; /* set if previous match exists */ + uInt strstart; /* start of string to insert */ + uInt match_start; /* start of matching string */ + uInt lookahead; /* number of valid bytes ahead in window */ + + uInt prev_length; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + uInt max_chain_length; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + uInt max_lazy_match; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +# define max_insert_length max_lazy_match + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + int level; /* compression level (1..9) */ + int strategy; /* favor or force Huffman coding*/ + + uInt good_match; + /* Use a faster search when the previous match is longer than this */ + + int nice_match; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + /* Didn't use ct_data typedef below to supress compiler warning */ + struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + struct tree_desc_s l_desc; /* desc. for literal tree */ + struct tree_desc_s d_desc; /* desc. for distance tree */ + struct tree_desc_s bl_desc; /* desc. for bit length tree */ + + ush bl_count[MAX_BITS+1]; + /* number of codes at each bit length for an optimal tree */ + + int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + int heap_len; /* number of elements in the heap */ + int heap_max; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + uch depth[2*L_CODES+1]; + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + uchf *l_buf; /* buffer for literals or lengths */ + + uInt lit_bufsize; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + uInt last_lit; /* running index in l_buf */ + + ushf *d_buf; + /* Buffer for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + ulg opt_len; /* bit length of current block with optimal trees */ + ulg static_len; /* bit length of current block with static trees */ + uInt matches; /* number of string matches in current block */ + int last_eob_len; /* bit length of EOB code for last block */ + +#ifdef DEBUG + ulg compressed_len; /* total bit length of compressed file mod 2^32 */ + ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ +#endif + + ush bi_buf; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + int bi_valid; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + +} FAR deflate_state; + +/* Output a byte on the stream. + * IN assertion: there is enough room in pending_buf. + */ +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} + + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + + /* in trees.c */ +void _tr_init OF((deflate_state *s)); +int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); +void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, + int eof)); +void _tr_align OF((deflate_state *s)); +void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, + int eof)); + +#define d_code(dist) \ + ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. _dist_code[256] and _dist_code[257] are never + * used. + */ + +#ifndef DEBUG +/* Inline versions of _tr_tally for speed: */ + +#if defined(GEN_TREES_H) || !defined(STDC) + extern uch _length_code[]; + extern uch _dist_code[]; +#else + extern const uch _length_code[]; + extern const uch _dist_code[]; +#endif + +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->last_lit] = 0; \ + s->l_buf[s->last_lit++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (length); \ + ush dist = (distance); \ + s->d_buf[s->last_lit] = dist; \ + s->l_buf[s->last_lit++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->last_lit == s->lit_bufsize-1); \ + } +#else +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) +# define _tr_tally_dist(s, distance, length, flush) \ + flush = _tr_tally(s, distance, length) +#endif + +#endif /* DEFLATE_H */ diff --git a/third_party/zlib/include/zconf.h b/third_party/zlib/include/zconf.h new file mode 100644 index 0000000..b9ad50d --- /dev/null +++ b/third_party/zlib/include/zconf.h @@ -0,0 +1,332 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + */ +#ifdef Z_PREFIX +# define deflateInit_ z_deflateInit_ +# define deflate z_deflate +# define deflateEnd z_deflateEnd +# define inflateInit_ z_inflateInit_ +# define inflate z_inflate +# define inflateEnd z_inflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateSetDictionary z_deflateSetDictionary +# define deflateCopy z_deflateCopy +# define deflateReset z_deflateReset +# define deflateParams z_deflateParams +# define deflateBound z_deflateBound +# define deflatePrime z_deflatePrime +# define inflateInit2_ z_inflateInit2_ +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateCopy z_inflateCopy +# define inflateReset z_inflateReset +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# define uncompress z_uncompress +# define adler32 z_adler32 +# define crc32 z_crc32 +# define get_crc_table z_get_crc_table +# define zError z_zError + +# define alloc_func z_alloc_func +# define free_func z_free_func +# define in_func z_in_func +# define out_func z_out_func +# define Byte_z z_Byte_z +# define uInt z_uInt +# define uLong z_uLong +# define Byte_zf z_Byte_zf +# define charf z_charf +# define intf z_intf +# define uIntf z_uIntf +# define uLongf z_uLongf +# define voidpf z_voidpf +# define voidp z_voidp +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte_z; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Byte_zf Byte_z FAR +#else + typedef Byte_z FAR Byte_zf; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte_z const *voidpc; + typedef Byte_z FAR *voidpf; + typedef Byte_z *voidp; +#endif + +#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ +# include /* for off_t */ +# include /* for SEEK_* and off_t */ +# ifdef VMS +# include /* for off_t */ +# endif +# define z_off_t off_t +#endif +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif +#ifndef z_off_t +# define z_off_t long +#endif + +#if defined(__OS400__) +# define NO_vsnprintf +#endif + +#if defined(__MVS__) +# define NO_vsnprintf +# ifdef FAR +# undef FAR +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) +# pragma map(deflateInit_,"DEIN") +# pragma map(deflateInit2_,"DEIN2") +# pragma map(deflateEnd,"DEEND") +# pragma map(deflateBound,"DEBND") +# pragma map(inflateInit_,"ININ") +# pragma map(inflateInit2_,"ININ2") +# pragma map(inflateEnd,"INEND") +# pragma map(inflateSync,"INSY") +# pragma map(inflateSetDictionary,"INSEDI") +# pragma map(compressBound,"CMBND") +# pragma map(inflate_table,"INTABL") +# pragma map(inflate_fast,"INFA") +# pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/third_party/zlib/include/zlib.h b/third_party/zlib/include/zlib.h new file mode 100644 index 0000000..08759ed --- /dev/null +++ b/third_party/zlib/include/zlib.h @@ -0,0 +1,1357 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.3, July 18th, 2005 + + Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.3" +#define ZLIB_VERNUM 0x1230 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed + data. This version of the library supports only one compression method + (deflation) but other algorithms will be added later and will have the same + stream interface. + + Compression can be done in a single step if the buffers are large + enough (for example if an input file is mmap'ed), or can be done by + repeated calls of the compression function. In the latter case, the + application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip streams in memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never + crash even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Byte_zf *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Byte_zf *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Byte_zf *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Byte_zf *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Byte_zf *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has + dropped to zero. It must update next_out and avail_out when avail_out + has dropped to zero. The application must initialize zalloc, zfree and + opaque before calling the init function. All other fields are set by the + compression library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, + pointers returned by zalloc for objects of exactly 65536 bytes *must* + have their offset normalized to zero. The default allocation function + provided by this library ensures this (see zutil.c). To reduce memory + requirements and avoid any allocation of 64K objects, at the expense of + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or + progress reports. After compression, total_in holds the total size of + the uncompressed data and may be saved for use in the decompressor + (particularly if the decompressor wants to decompress everything in + a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field (though see inflate()) */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is + not compatible with the zlib.h header file used by the application. + This check is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. + If zalloc and zfree are set to Z_NULL, deflateInit updates them to + use default allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at + all (the input data is simply copied a block at a time). + Z_DEFAULT_COMPRESSION requests a default compromise between speed and + compression (currently equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if level is not a valid compression level, + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). + msg is set to null if there is no error message. deflateInit does not + perform any compression: this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce some + output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). + Some output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating avail_in or avail_out accordingly; avail_out + should never be zero before the call. The application can consume the + compressed output when it wants, for example when the output buffer is full + (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK + and with zero avail_out, it must be called again after making room in the + output buffer because there might be more output pending. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumualte before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In particular + avail_in is zero after the call if enough output space has been provided + before the call.) Flushing may degrade compression for some compression + algorithms and so it should be used only when necessary. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there + was enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the + stream are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least + the value returned by deflateBound (see below). If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered + binary. This field is only for information purposes and does not affect + the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not + fatal, and deflate() can be called again with more input and more output + space to continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, + msg may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the exact + value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller. msg is set to null if there is no error + message. inflateInit does not perform any decompression apart from reading + the zlib header if present: this will be done by inflate(). (So next_in and + avail_in may be modified, but next_out and avail_out are unchanged.) +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing + will resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there + is no more input data or no more space in the output buffer (see below + about the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating the next_* and avail_* values accordingly. + The application can consume the uncompressed output when it wants, for + example when the output buffer is full (avail_out == 0), or after each + call of inflate(). If inflate returns Z_OK and with zero avail_out, it + must be called again after making room in the output buffer because there + might be more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, + Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() stop + if and when it gets to the next deflate block boundary. When decoding the + zlib or gzip format, this will cause inflate() to return immediately after + the header and before the first block. When doing a raw inflate, inflate() + will go ahead and process the first block, and will return when it gets to + the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + Also to assist in this, on return inflate() will set strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 + if inflate() is currently decoding the last block in the deflate stream, + plus 128 if inflate() returned immediately after decoding an end-of-block + code or decoding the complete header up to just before the first byte of the + deflate stream. The end-of-block will not be indicated until all of the + uncompressed data from that block has been written to strm->next_out. The + number of unused bits may in general be greater than seven, except when + bit 7 of data_type is set, in which case the number of unused bits will be + less than eight. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step + (a single call of inflate), the parameter flush should be set to + Z_FINISH. In this case all pending input is processed and all pending + output is flushed; avail_out must be large enough to hold all the + uncompressed data. (The size of the uncompressed data may have been saved + by the compressor for this purpose.) The next operation on this stream must + be inflateEnd to deallocate the decompression state. The use of Z_FINISH + is never required, but can be used to inform inflate that a faster approach + may be used for the single inflate() call. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the only effect of the flush parameter in this implementation + is on the return value of inflate(), as noted below, or when it returns early + because Z_BLOCK is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the adler32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the adler32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed adler32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() will decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically. Any information + contained in the gzip header is not retained, so applications that need that + information should instead use raw inflate, see inflateInit2() below, or + inflateBack() and perform their own processing of the gzip header and + trailer. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value), Z_STREAM_ERROR if the stream structure was inconsistent (for example + if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, + Z_BUF_ERROR if no progress is possible or if there was not enough room in the + output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may then + call inflateSync() to look for a good compression block if a partial recovery + of the data is desired. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by + the caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute an adler32 check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), + no header crc, and the operating system will be set to 255 (unknown). If a + gzip stream is being written, strm->adler is a crc32 instead of an adler32. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but + is slow and reduces compression ratio; memLevel=9 uses maximum memory + for optimal speed. The default value is 8. See zconf.h for total memory + usage as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as + Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy + parameter only affects the compression ratio but not the correctness of the + compressed output even if it is not set appropriately. Z_FIXED prevents the + use of dynamic Huffman codes, allowing for a simpler decoder for special + applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid + method). msg is set to null if there is no error message. deflateInit2 does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Byte_zf *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any + call of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size in + deflate or deflate2. Thus the strings most likely to be useful should be + put at the end of the dictionary, not at the front. In addition, the + current implementation of deflate will use at most the window size minus + 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + adler32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and + can consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. + The stream will keep the same compression level and any other attributes + that may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different + strategy. If the compression level is changed, the input available so far + is compressed with the old level (and may be flushed); the new level will + take effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to + be compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR + if strm->avail_out was zero. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() + or deflateInit2(). This would be used to allocate an output buffer + for deflation in a single pass, and so would be called before deflate(). +*/ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the + bits leftover from a previous deflate stream when appending to it. As such, + this function can only be used for raw deflate, and must be used before the + first deflate() call after a deflateInit2() or deflateReset(). bits must be + less than or equal to 16, and that many of the least significant bits of + value will be inserted in the output. + + deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an adler32 or a crc32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is + a crc32 instead of an adler32. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg + is set to null if there is no error message. inflateInit2 does not perform + any decompression apart from reading the zlib header if present: this will + be done by inflate(). (So next_in and avail_in may be modified, but next_out + and avail_out are unchanged.) +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Byte_zf *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the adler32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called + immediately after inflateInit2() or inflateReset() and before any call of + inflate() to set the dictionary. The application must insure that the + dictionary that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been found, + or Z_STREAM_ERROR if the stream structure was inconsistent. In the success + case, the application may save the current current value of total_in which + indicates where valid compressed data was found. In the error case, the + application may repeatedly call inflateSync, providing more input each time, + until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. + The stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK can be used to + force inflate() to return immediately after header processing is complete + and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When + any of extra, name, or comment are not Z_NULL and the respective field is + not present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the paramaters are invalid, Z_MEM_ERROR if the internal state could not + be allocated, or Z_VERSION_ERROR if the version of the library does not + match the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is more efficient than inflate() for + file i/o applications in that it avoids copying between the output and the + sliding window by simply making the window itself the output buffer. This + function trusts the application to not change the output buffer passed by + the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free + the allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects + only the raw deflate stream to decompress. This is different from the + normal behavior of inflate(), which expects either a zlib or gzip header and + trailer around the deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero--buf is ignored in that + case--and inflateBack() will return a buffer error. inflateBack() will call + out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() + should return zero on success, or non-zero on failure. If out() returns + non-zero, inflateBack() will return with an error. Neither in() nor out() + are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format + error in the deflate stream (in which case strm->msg is set to indicate the + nature of the error), or Z_STREAM_ERROR if the stream was not properly + initialized. In the case of Z_BUF_ERROR, an input or output error can be + distinguished using strm->next_in which will be Z_NULL only if in() returned + an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to + out() returning non-zero. (in() will always be called before out(), so + strm->next_in is assured to be defined if out() returns non-zero.) Note + that inflateBack() cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the + basic stream-oriented functions. To simplify the interface, some + default options are assumed (compression level and memory usage, + standard memory allocation functions). The source code of these + utility functions can easily be modified if you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Byte_zf *dest, uLongf *destLen, + const Byte_zf *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be at least the value returned + by compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + This function can be used to compress a whole file at once if the + input file is mmap'ed. + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Byte_zf *dest, uLongf *destLen, + const Byte_zf *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before + a compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Byte_zf *dest, uLongf *destLen, + const Byte_zf *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. +*/ + + +typedef voidp gzFile; + +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +/* + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb") but can also include a compression level + ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for + Huffman only compression as in "wb1h", or 'R' for run-length encoding + as in "wb1R". (See the description of deflateInit2 for more information + about the strategy parameter.) + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). */ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen() associates a gzFile with the file descriptor fd. File + descriptors are obtained from calls like open, dup, creat, pipe or + fileno (in the file has been previously opened with fopen). + The mode parameter is as in gzopen. + The next call of gzclose on the returned gzFile will also close the + file descriptor fd, just like fclose(fdopen(fd), mode) closes the file + descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). + gzdopen returns NULL if there was insufficient memory to allocate + the (de)compression state. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. + If the input file was not in gzip format, gzread copies the given number + of bytes into the buffer. + gzread returns the number of uncompressed bytes actually read (0 for + end of file, -1 for error). */ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes actually written + (0 in case of error). +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). The number of + uncompressed bytes written is limited to 4095. The caller should assure that + this limit is not exceeded. If it is exceeded, then gzprintf() will return + return an error (0) with nothing written. In this case, there may also be a + buffer overflow with unpredictable consequences, which is possible only if + zlib was compiled with the insecure functions sprintf() or vsprintf() + because the secure snprintf() or vsnprintf() functions were not available. +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or + a newline character is read and transferred to buf, or an end-of-file + condition is encountered. The string is then terminated with a null + character. + gzgets returns buf, or Z_NULL in case of error. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read again later. + Only one character of push-back is allowed. gzungetc() returns the + character pushed, or -1 on failure. gzungetc() will fail if a + character has been pushed but not read yet, or if c is -1. The pushed + character will be discarded if the stream is repositioned with gzseek() + or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. The return value is the zlib + error number (see function gzerror below). gzflush returns Z_OK if + the flush parameter is Z_FINISH and all output could be flushed. + gzflush should be called only when strictly necessary because it can + degrade compression. +*/ + +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); +/* + Sets the starting position for the next gzread or gzwrite on the + given compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +/* + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns 1 if file is being read directly without decompression, otherwise + zero. +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. The return value is the zlib + error number (see function gzerror below). +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the + given compressed file. errnum is set to zlib error number. If an + error occurred in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the + compression library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Byte_zf *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is NULL, this function returns + the required initial value for the checksum. + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); +/* + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Byte_zf *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is NULL, this function returns the required initial + value for the for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + +/* + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) +#define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, sizeof(z_stream)) + + +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; /* hack for buggy compilers */ +#endif + +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/third_party/zlib/include/zutil.h b/third_party/zlib/include/zutil.h new file mode 100644 index 0000000..6cc3fc1 --- /dev/null +++ b/third_party/zlib/include/zutil.h @@ -0,0 +1,269 @@ +/* zutil.h -- internal interface and configuration of the compression library + * Copyright (C) 1995-2005 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* WARNING: this file should *not* be used by applications. It is + part of the implementation of the compression library and is + subject to change. Applications should only use zlib.h. + */ + +/* @(#) $Id$ */ + +#ifndef ZUTIL_H +#define ZUTIL_H + +#define ZLIB_INTERNAL +#include "zlib.h" + +#ifdef STDC +# ifndef _WIN32_WCE +# include +# endif +# include +# include +#endif +#ifdef NO_ERRNO_H +# ifdef _WIN32_WCE + /* The Microsoft C Run-Time Library for Windows CE doesn't have + * errno. We define it as a global variable to simplify porting. + * Its value is always 0 and should not be used. We rename it to + * avoid conflict with other libraries that use the same workaround. + */ +# define errno z_errno +# endif + extern int errno; +#else +# ifndef _WIN32_WCE +# include +# endif +#endif + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +typedef unsigned char uch; +typedef uch FAR uchf; +typedef unsigned short ush; +typedef ush FAR ushf; +typedef unsigned long ulg; + +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ +/* (size given to avoid silly warnings with Visual C++) */ + +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] + +#define ERR_RETURN(strm,err) \ + return (strm->msg = (char*)ERR_MSG(err), (err)) +/* To be used only when the state is known to be valid */ + + /* common constants */ + +#ifndef DEF_WBITS +# define DEF_WBITS MAX_WBITS +#endif +/* default windowBits for decompression. MAX_WBITS is for compression only */ + +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +/* default memLevel */ + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ + + /* target dependencies */ + +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) +# define OS_CODE 0x00 +# if defined(__TURBOC__) || defined(__BORLANDC__) +# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) + /* Allow compilation with ANSI keywords only enabled */ + void _Cdecl farfree( void *block ); + void *_Cdecl farmalloc( unsigned long nbytes ); +# else +# include +# endif +# else /* MSC or DJGPP */ +# include +# endif +#endif + +#ifdef AMIGA +# define OS_CODE 0x01 +#endif + +#if defined(VAXC) || defined(VMS) +# define OS_CODE 0x02 +# define F_OPEN(name, mode) \ + fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") +#endif + +#if defined(ATARI) || defined(atarist) +# define OS_CODE 0x05 +#endif + +#ifdef OS2 +# define OS_CODE 0x06 +# ifdef M_I86 + #include +# endif +#endif + +#if defined(MACOS) || defined(TARGET_OS_MAC) +# define OS_CODE 0x07 +# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +# include /* for fdopen */ +# else +# ifndef fdopen +# define fdopen(fd,mode) NULL /* No fdopen() */ +# endif +# endif +#endif + +#ifdef TOPS20 +# define OS_CODE 0x0a +#endif + +#ifdef WIN32 +# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ +# define OS_CODE 0x0b +# endif +#endif + +#ifdef __50SERIES /* Prime/PRIMOS */ +# define OS_CODE 0x0f +#endif + +#if defined(_BEOS_) || defined(RISCOS) +# define fdopen(fd,mode) NULL /* No fdopen() */ +#endif + +#if (defined(_MSC_VER) && (_MSC_VER > 600)) +# if defined(_WIN32_WCE) +# define fdopen(fd,mode) NULL /* No fdopen() */ +# ifndef _PTRDIFF_T_DEFINED + typedef int ptrdiff_t; +# define _PTRDIFF_T_DEFINED +# endif +# else +# define fdopen(fd,type) _fdopen(fd,type) +# endif +#endif + + /* common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef F_OPEN +# define F_OPEN(name, mode) fopen((name), (mode)) +#endif + + /* functions */ + +#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif +#if defined(__CYGWIN__) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF +# endif +#endif +#ifndef HAVE_VSNPRINTF +# ifdef MSDOS + /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), + but for now we just assume it doesn't. */ +# define NO_vsnprintf +# endif +# ifdef __TURBOC__ +# define NO_vsnprintf +# endif +# ifdef WIN32 + /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ +# if !defined(vsnprintf) && !defined(NO_vsnprintf) +# define vsnprintf _vsnprintf +# endif +# endif +# ifdef __SASC +# define NO_vsnprintf +# endif +#endif +#ifdef VMS +# define NO_vsnprintf +#endif + +#if defined(pyr) +# define NO_MEMCPY +#endif +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) + /* Use our own functions for small and medium model with MSC <= 5.0. + * You may have to use the same strategy for Borland C (untested). + * The __SC__ check is for Symantec. + */ +# define NO_MEMCPY +#endif +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) +# define HAVE_MEMCPY +#endif +#ifdef HAVE_MEMCPY +# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ +# define zmemcpy _fmemcpy +# define zmemcmp _fmemcmp +# define zmemzero(dest, len) _fmemset(dest, 0, len) +# else +# define zmemcpy memcpy +# define zmemcmp memcmp +# define zmemzero(dest, len) memset(dest, 0, len) +# endif +#else + extern void zmemcpy OF((Byte_zf* dest, const Byte_zf* source, uInt len)); + extern int zmemcmp OF((const Byte_zf* s1, const Byte_zf* s2, uInt len)); + extern void zmemzero OF((Byte_zf* dest, uInt len)); +#endif + +/* Diagnostic functions */ +#ifdef DEBUG +# include + extern int z_verbose; + extern void z_error OF((char *m)); +# define Assert(cond,msg) {if(!(cond)) z_error(msg);} +# define Trace(x) {if (z_verbose>=0) fprintf x ;} +# define Tracev(x) {if (z_verbose>0) fprintf x ;} +# define Tracevv(x) {if (z_verbose>1) fprintf x ;} +# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} +# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + + +voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); +void zcfree OF((voidpf opaque, voidpf ptr)); + +#define ZALLOC(strm, items, size) \ + (*((strm)->zalloc))((strm)->opaque, (items), (size)) +#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} + +#endif /* ZUTIL_H */ diff --git a/third_party/zlib/lib/zlib.lib b/third_party/zlib/lib/zlib.lib new file mode 100644 index 0000000..36a53de Binary files /dev/null and b/third_party/zlib/lib/zlib.lib differ diff --git a/tools/tools.pro b/tools/tools.pro new file mode 100644 index 0000000..8bb493d --- /dev/null +++ b/tools/tools.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS += zentry diff --git a/tools/zentry/zentry.ico b/tools/zentry/zentry.ico new file mode 100644 index 0000000..68c58cd Binary files /dev/null and b/tools/zentry/zentry.ico differ diff --git a/tools/zentry/zentry.pro b/tools/zentry/zentry.pro new file mode 100644 index 0000000..06c4b31 --- /dev/null +++ b/tools/zentry/zentry.pro @@ -0,0 +1,32 @@ +QT += core widgets gui multimedia + +RC_ICONS = zentry.ico + +SUBDIRS += zentry + +CONFIG += c++17 + +SOURCES += \ + zentrymain.cpp \ + zentrywindow.cpp + +HEADERS += \ + zentrywindow.h + +FORMS += + +app.depends += \ + libs/compression + +LIBS += \ + -L$$OUT_PWD/../../libs/ -lcompression \ + -L$$PWD/../../third_party/xbox_sdk/lib -lxcompress64 + +INCLUDEPATH += \ + $$PWD/../../libs/compression \ + $$PWD/../../third_party/xbox_sdk/include + +DEPENDPATH += \ + $$PWD/../../libs/compression \ + $$PWD/../../third_party/xbox_sdk/include + diff --git a/tools/zentry/zentrymain.cpp b/tools/zentry/zentrymain.cpp new file mode 100644 index 0000000..113c6b7 --- /dev/null +++ b/tools/zentry/zentrymain.cpp @@ -0,0 +1,11 @@ +#include "zentrywindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ZentryWindow w; + w.show(); + return a.exec(); +} diff --git a/tools/zentry/zentrywindow.cpp b/tools/zentry/zentrywindow.cpp new file mode 100644 index 0000000..44fc065 --- /dev/null +++ b/tools/zentry/zentrywindow.cpp @@ -0,0 +1,118 @@ +#include "zentrywindow.h" +#include "compression.h" +#include "qfiledialog.h" + +#include +#include +#include +#include + +ZentryWindow::ZentryWindow(QWidget *parent) + : QMainWindow{parent} { + setWindowTitle("Zentry Tool"); + setMinimumSize(250, 150); + setMaximumSize(250, 150); + setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); + + QLabel *dragLabel = new QLabel(this); + dragLabel->setText("Drop file here..."); + dragLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + dragLabel->setStyleSheet("QLabel {" + " color: white;" + " background-color: grey;" + "}" + "QLabel::hover " + "{" + " background-color: black;" + "}"); + + setCentralWidget(dragLabel); +} + +ZentryWindow::~ZentryWindow() { + +} + +void ZentryWindow::dragEnterEvent(QDragEnterEvent *event) { + const QMimeData *mimeData = event->mimeData(); + bool goodDrag = true; + if (mimeData->hasUrls()) { + qDebug() << mimeData->urls(); + } else { + goodDrag = false; + } + if (goodDrag) { + event->acceptProposedAction(); + } +} + +void ZentryWindow::dragMoveEvent(QDragMoveEvent *event) { + Q_UNUSED(event); +} + +void ZentryWindow::dragLeaveEvent(QDragLeaveEvent *event) { + Q_UNUSED(event); +} + +void ZentryWindow::dropEvent(QDropEvent *event) { + const QMimeData *mimeData = event->mimeData(); + if (mimeData->hasUrls()) { + foreach (const QUrl &url, mimeData->urls()) { + const QString fileName = url.toString().split('/').last(); + QMessageBox msgBox; + msgBox.setWindowTitle("Handle File"); + msgBox.setText("Choose how to handle " + fileName); + + QPushButton *compressButton = msgBox.addButton(tr("Compress"), QMessageBox::AcceptRole); + QPushButton *decompressButton = msgBox.addButton(tr("Decompress"), QMessageBox::RejectRole); + QPushButton *cancelButton = msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole); + msgBox.exec(); + + if ((QPushButton*)msgBox.clickedButton() == compressButton) { + // Compress + } else if ((QPushButton*)msgBox.clickedButton() == decompressButton) { + // Decompress + QFile compressedFile(url.toLocalFile()); + if (!compressedFile.open(QIODevice::ReadOnly)) { + qDebug() << QString("Failed to open %1!").arg(fileName); + continue; + } + + const QByteArray compressedData = compressedFile.readAll(); + QByteArray decompressedData; + if (compressedData.left(2).toHex() == "7801") { + qDebug() << "Detected zlib data! (No Compression/low)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else if (compressedData.left(2).toHex() == "785e") { + qDebug() << "Detected zlib data! (Fast Compression)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else if (compressedData.left(2).toHex() == "789c") { + qDebug() << "Detected zlib data! (Default Compression)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else if (compressedData.left(2).toHex() == "78da") { + qDebug() << "Detected zlib data! (Best Compression)"; + decompressedData = Compression::DecompressZLIB(compressedData); + } else { + qDebug() << "Invalid zlib header!"; + continue; + } + + if (decompressedData.isEmpty()) { + qDebug() << "Zlib output was empty!"; + continue; + } + + const QString decompressedPath = QFileDialog::getSaveFileName(this, "Choose save name"); + QFile decompressedFile(decompressedPath); + if (!decompressedFile.open(QIODevice::WriteOnly)) { + qDebug() << QString("Failed to open %1!").arg(decompressedPath.split('/').last()); + continue; + } + decompressedFile.write(decompressedData); + decompressedFile.close(); + } else if ((QPushButton*)msgBox.clickedButton() == cancelButton) { + // Cancel + } + } + } +} diff --git a/tools/zentry/zentrywindow.h b/tools/zentry/zentrywindow.h new file mode 100644 index 0000000..81379d0 --- /dev/null +++ b/tools/zentry/zentrywindow.h @@ -0,0 +1,32 @@ +#ifndef ZENTRYWINDOW_H +#define ZENTRYWINDOW_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class ZentryWindow; +} +QT_END_NAMESPACE + +class ZentryWindow : public QMainWindow +{ + Q_OBJECT + +public: + ZentryWindow(QWidget *parent = nullptr); + ~ZentryWindow(); + +protected: + void dragEnterEvent(QDragEnterEvent *event) override; + void dragMoveEvent(QDragMoveEvent *event) override; + void dragLeaveEvent(QDragLeaveEvent *event) override; + void dropEvent(QDropEvent *event) override; + +private: + Ui::ZentryWindow *ui; +}; +#endif // ZENTRYWINDOW_H diff --git a/utils.h b/utils.h deleted file mode 100644 index 674ce30..0000000 --- a/utils.h +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H - -#include "enums.h" -#include "qdir.h" - -#include -#include - -class Utils { -public: - /* - AssetTypeToString() - - Convert asset type string to asset desc string -*/ - static QString AssetTypeToString(const QString aAssetType) { - const QString cleanedType = aAssetType.toUpper(); - if (cleanedType == "17000000") { // localized string PARTIALLY VERIFIED - return "LOCAL STRING"; - } else if (cleanedType == "20000000") { // raw_file PARTIALLY VERIFIED - return "RAW FILE"; - } else if (cleanedType == "1A000000") { // fx PARTIALLY VERIFIED - return "EFFECT"; - } else if (cleanedType == "09000000") { // loaded_sound PARTIALLY VERIFIED - return "SOUND"; - } else if (cleanedType == "04000000") { // x_anim PARTIALLY VERIFIED - return "ANIMATION"; - } else if (cleanedType == "0C000000") { // collision_map PARTIALLY VERIFIED - return "COLLISION MAP"; - } else if (cleanedType == "21000000") { // string_table PARTIALLY VERIFIED - return "STRING TABLE"; - } else if (cleanedType == "15000000") { // menu_file PARTIALLY VERIFIED - return "MENU"; - } else if (cleanedType == "07000000") { // tech set PARTIALLY VERIFIED - return "TECH SET"; - } else if (cleanedType == "18000000") { // weapon PARTIALLY VERIFIED - return "WEAPON"; - } else if (cleanedType == "11000000") { // d3dbsp dump PARTIALLY VERIFIED - return "D3DBSP DUMP"; - } else if (cleanedType == "12000000") { // light_def PARTIALLY VERIFIED - return "LIGHT DEF"; - } else if (cleanedType == "14000000") { // font PARTIALLY VERIFIED - return "FONT"; - } else if (cleanedType == "05000000") { // xmodel PARTIALLY VERIFIED - return "MODEL"; - } else if (cleanedType == "0D000000") { // shader PARTIALLY VERIFIED - return "SHADER"; - } else if (cleanedType == "06000000") { // material PARTIALLY VERIFIED - return "MATERIAL"; - } - return "UNKNOWN"; - } - - /* - LumpTypeToString() - - Convert BSP lump type to desc string -*/ - static QString LumpTypeToString(LUMP_TYPE aLumpType) { - switch (aLumpType) { - case LUMP_MATERIALS: return "LUMP_MATERIALS"; - case LUMP_LIGHTBYTES: return "LUMP_LIGHTBYTES"; - case LUMP_LIGHTGRIDENTRIES: return "LUMP_LIGHTGRIDENTRIES"; - case LUMP_LIGHTGRIDCOLORS: return "LUMP_LIGHTGRIDCOLORS"; - case LUMP_PLANES: return "LUMP_PLANES"; - case LUMP_BRUSHSIDES: return "LUMP_BRUSHSIDES"; - case LUMP_BRUSHSIDEEDGECOUNTS: return "LUMP_BRUSHSIDEEDGECOUNTS"; - case LUMP_BRUSHEDGES: return "LUMP_BRUSHEDGES"; - case LUMP_BRUSHES: return "LUMP_BRUSHES"; - case LUMP_TRIANGLES: return "LUMP_TRIANGLES"; - case LUMP_DRAWVERTS: return "LUMP_DRAWVERTS"; - case LUMP_DRAWINDICES: return "LUMP_DRAWINDICES"; - case LUMP_CULLGROUPS: return "LUMP_CULLGROUPS"; - case LUMP_CULLGROUPINDICES: return "LUMP_CULLGROUPINDICES"; - case LUMP_OBSOLETE_1: return "LUMP_OBSOLETE_1"; - case LUMP_OBSOLETE_2: return "LUMP_OBSOLETE_2"; - case LUMP_OBSOLETE_3: return "LUMP_OBSOLETE_3"; - case LUMP_OBSOLETE_4: return "LUMP_OBSOLETE_4"; - case LUMP_OBSOLETE_5: return "LUMP_OBSOLETE_5"; - case LUMP_PORTALVERTS: return "LUMP_PORTALVERTS"; - case LUMP_OBSOLETE_6: return "LUMP_OBSOLETE_6"; - case LUMP_UINDS: return "LUMP_UINDS"; - case LUMP_BRUSHVERTSCOUNTS: return "LUMP_BRUSHVERTSCOUNTS"; - case LUMP_BRUSHVERTS: return "LUMP_BRUSHVERTS"; - case LUMP_AABBTREES: return "LUMP_AABBTREES"; - case LUMP_CELLS: return "LUMP_CELLS"; - case LUMP_PORTALS: return "LUMP_PORTALS"; - case LUMP_NODES: return "LUMP_NODES"; - case LUMP_LEAFS: return "LUMP_LEAFS"; - case LUMP_LEAFBRUSHES: return "LUMP_LEAFBRUSHES"; - case LUMP_LEAFSURFACES: return "LUMP_LEAFSURFACES"; - case LUMP_COLLISIONVERTS: return "LUMP_COLLISIONVERTS"; - case LUMP_COLLISIONTRIS: return "LUMP_COLLISIONTRIS"; - case LUMP_COLLISIONEDGEWALKABLE: return "LUMP_COLLISIONEDGEWALKABLE"; - case LUMP_COLLISIONBORDERS: return "LUMP_COLLISIONBORDERS"; - case LUMP_COLLISIONPARTITIONS: return "LUMP_COLLISIONPARTITIONS"; - case LUMP_COLLISIONAABBS: return "LUMP_COLLISIONAABBS"; - case LUMP_MODELS: return "LUMP_MODELS"; - case LUMP_VISIBILITY: return "LUMP_VISIBILITY"; - case LUMP_ENTITIES: return "LUMP_ENTITIES"; - case LUMP_PATHCONNECTIONS: return "LUMP_PATHCONNECTIONS"; - case LUMP_REFLECTION_PROBES: return "LUMP_REFLECTION_PROBES"; - case LUMP_VERTEX_LAYER_DATA: return "LUMP_VERTEX_LAYER_DATA"; - case LUMP_PRIMARY_LIGHTS: return "LUMP_PRIMARY_LIGHTS"; - case LUMP_LIGHTGRIDHEADER: return "LUMP_LIGHTGRIDHEADER"; - case LUMP_LIGHTGRIDROWS: return "LUMP_LIGHTGRIDROWS"; - case LUMP_OBSOLETE_10: return "LUMP_OBSOLETE_10"; - case LUMP_UNLAYERED_TRIANGLES: return "LUMP_UNLAYERED_TRIANGLES"; - case LUMP_UNLAYERED_DRAWVERTS: return "LUMP_UNLAYERED_DRAWVERTS"; - case LUMP_UNLAYERED_DRAWINDICES: return "LUMP_UNLAYERED_DRAWINDICES"; - case LUMP_UNLAYERED_CULLGROUPS: return "LUMP_UNLAYERED_CULLGROUPS"; - case LUMP_UNLAYERED_AABBTREES: return "LUMP_UNLAYERED_AABBTREES"; - case LUMP_WATERHEADER: return "LUMP_WATERHEADER"; - case LUMP_WATERCELLS: return "LUMP_WATERCELLS"; - case LUMP_WATERCELLDATA: return "LUMP_WATERCELLDATA"; - case LUMP_BURNABLEHEADER: return "LUMP_BURNABLEHEADER"; - case LUMP_BURNABLECELLS: return "LUMP_BURNABLECELLS"; - case LUMP_BURNABLECELLDATA: return "LUMP_BURNABLECELLDATA"; - case LUMP_SIMPLELIGHTMAPBYTES: return "LUMP_SIMPLELIGHTMAPBYTES"; - case LUMP_LODCHAINS: return "LUMP_LODCHAINS"; - case LUMP_LODINFOS: return "LUMP_LODINFOS"; - case LUMP_LODSURFACES: return "LUMP_LODSURFACES"; - case LUMP_LIGHTREGIONS: return "LUMP_LIGHTREGIONS"; - case LUMP_LIGHTREGION_HULLS: return "LUMP_LIGHTREGION_HULLS"; - case LUMP_LIGHTREGION_AXES: return "LUMP_LIGHTREGION_AXES"; - case LUMP_WIILIGHTGRID: return "LUMP_WIILIGHTGRID"; - case LUMP_LIGHTGRID2D_LIGHTS: return "LUMP_LIGHTGRID2D_LIGHTS"; - case LUMP_LIGHTGRID2D_INDICES: return "LUMP_LIGHTGRID2D_INDICES"; - case LUMP_LIGHTGRID2D_POINTS: return "LUMP_LIGHTGRID2D_POINTS"; - case LUMP_LIGHTGRID2D_CELLS: return "LUMP_LIGHTGRID2D_CELLS"; - case LUMP_LIGHT_CORONAS: return "LUMP_LIGHT_CORONAS"; - case LUMP_SHADOWMAP_VOLUMES: return "LUMP_SHADOWMAP_VOLUMES"; - case LUMP_SHADOWMAP_VOLUME_PLANES: return "LUMP_SHADOWMAP_VOLUME_PLANES"; - case LUMP_EXPOSURE_VOLUMES: return "LUMP_EXPOSURE_VOLUMES"; - case LUMP_EXPOSURE_VOLUME_PLANES: return "LUMP_EXPOSURE_VOLUME_PLANES"; - case LUMP_OCCLUDERS: return "LUMP_OCCLUDERS"; - case LUMP_OUTDOORBOUNDS: return "LUMP_OUTDOORBOUNDS"; - case LUMP_HERO_ONLY_LIGHTS: return "LUMP_HERO_ONLY_LIGHTS"; - default: return "Unknown Lump Type"; - } - return "Unknown Lump Type"; - } - - static QString ZLibErrorToString(int result) { - switch (result) { - case Z_ERRNO: - return "Encountered file operation error!"; - case Z_STREAM_ERROR: - return "Stream was not initialized properly!"; - case Z_DATA_ERROR: - return "The input data was corrupted or incomplete!"; - case Z_MEM_ERROR: - return "There was not enough memory!"; - case Z_BUF_ERROR: - return "There was not enough room in the output buffer!"; - case Z_VERSION_ERROR: - return "Linked libraries are out of date!"; - } - return ""; - } - - static quint32 PadInt4(quint32 size) { - return (size + 3) & ~3; // Align size to 4 bytes - } - - static quint32 PaddingSize(quint32 size) { - return PadInt4(size) - size; - } -}; - -#endif // UTILS_H