diff --git a/Externals/wxWidgets/build/msw/wx_base.vcproj b/Externals/wxWidgets/build/msw/wx_base.vcproj
index 657287285a..f3f881b0e0 100644
--- a/Externals/wxWidgets/build/msw/wx_base.vcproj
+++ b/Externals/wxWidgets/build/msw/wx_base.vcproj
@@ -1,7 +1,7 @@
-
-
@@ -5798,6 +5793,10 @@
/>
+
+
+
+
@@ -17012,10 +17021,6 @@
/>
-
-
@@ -125,7 +124,6 @@
PrecompiledHeaderThrough="stdafx.h"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -198,7 +196,6 @@
PrecompiledHeaderThrough="stdafx.h"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -272,7 +269,6 @@
PrecompiledHeaderThrough="stdafx.h"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -340,7 +336,6 @@
PrecompiledHeaderThrough="stdafx.h"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -409,7 +404,6 @@
PrecompiledHeaderThrough="stdafx.h"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
diff --git a/Source/Core/Core/Core.vcproj b/Source/Core/Core/Core.vcproj
index 4d6b36c2d8..510d623aa8 100644
--- a/Source/Core/Core/Core.vcproj
+++ b/Source/Core/Core/Core.vcproj
@@ -53,7 +53,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
ForcedIncludeFiles="stdafx.h"
/>
@@ -122,7 +121,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -195,7 +193,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -271,7 +268,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="0"
ForcedIncludeFiles="stdafx.h"
/>
@@ -342,7 +338,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -414,7 +409,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp
index d6ea127bb3..3773672bd9 100644
--- a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp
+++ b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp
@@ -66,7 +66,6 @@ void CEXIMemoryCard::Flush()
{
FILE* pFile = NULL;
pFile = fopen(m_strFilename.c_str(), "wb");
-
if (pFile)
{
fwrite(memory_card_content, memory_card_size, 1, pFile);
@@ -74,7 +73,8 @@ void CEXIMemoryCard::Flush()
}
else
{
- PanicAlert("ERROR - could not write memory card file %s", m_strFilename.c_str());
+ PanicAlert("Could not write memory card file %s.\n\n"
+ "Are you running Dolphin from a CD/DVD, or is the save file maybe write protected?", m_strFilename.c_str());
}
}
diff --git a/Source/Core/DebuggerWX/DebuggerWX.vcproj b/Source/Core/DebuggerWX/DebuggerWX.vcproj
index 64693dfc19..7509f8f222 100644
--- a/Source/Core/DebuggerWX/DebuggerWX.vcproj
+++ b/Source/Core/DebuggerWX/DebuggerWX.vcproj
@@ -1,7 +1,7 @@
@@ -117,7 +116,6 @@
RuntimeLibrary="1"
UsePrecompiledHeader="2"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles=""
/>
@@ -179,7 +177,6 @@
RuntimeLibrary="0"
UsePrecompiledHeader="2"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles=""
/>
@@ -243,7 +240,6 @@
RuntimeLibrary="0"
UsePrecompiledHeader="2"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles=""
/>
@@ -305,7 +301,6 @@
RuntimeLibrary="0"
UsePrecompiledHeader="2"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles=""
/>
@@ -368,7 +363,6 @@
RuntimeLibrary="0"
UsePrecompiledHeader="2"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles=""
/>
diff --git a/Source/Core/VideoCommon/Src/BPMemory.cpp b/Source/Core/VideoCommon/Src/BPMemory.cpp
new file mode 100644
index 0000000000..483edad1ae
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/BPMemory.cpp
@@ -0,0 +1,7 @@
+#include "Common.h"
+
+#include "BPMemory.h"
+
+//BP state
+BPMemory bpmem;
+
diff --git a/Source/Core/VideoCommon/Src/BPMemory.h b/Source/Core/VideoCommon/Src/BPMemory.h
new file mode 100644
index 0000000000..42eb872647
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/BPMemory.h
@@ -0,0 +1,793 @@
+#ifndef _BPMEMORY_H
+#define _BPMEMORY_H
+
+#include "Common.h"
+
+#pragma pack(4)
+
+//////////////////////////////////////////////////////////////////////////
+// Tev/combiner things
+//////////////////////////////////////////////////////////////////////////
+
+#define TEVOP_ADD 0
+#define TEVOP_SUB 1
+#define TEVCMP_R8_GT 8
+#define TEVCMP_R8_EQ 9
+#define TEVCMP_GR16_GT 10
+#define TEVCMP_GR16_EQ 11
+#define TEVCMP_BGR24_GT 12
+#define TEVCMP_BGR24_EQ 13
+#define TEVCMP_RGB8_GT 14
+#define TEVCMP_RGB8_EQ 15
+#define TEVCMP_A8_GT 14
+#define TEVCMP_A8_EQ 15
+
+#define TEVCOLORARG_CPREV 0
+#define TEVCOLORARG_APREV 1
+#define TEVCOLORARG_C0 2
+#define TEVCOLORARG_A0 3
+#define TEVCOLORARG_C1 4
+#define TEVCOLORARG_A1 5
+#define TEVCOLORARG_C2 6
+#define TEVCOLORARG_A2 7
+#define TEVCOLORARG_TEXC 8
+#define TEVCOLORARG_TEXA 9
+#define TEVCOLORARG_RASC 10
+#define TEVCOLORARG_RASA 11
+#define TEVCOLORARG_ONE 12
+#define TEVCOLORARG_HALF 13
+#define TEVCOLORARG_KONST 14
+#define TEVCOLORARG_ZERO 15
+
+#define TEVALPHAARG_APREV 0
+#define TEVALPHAARG_A0 1
+#define TEVALPHAARG_A1 2
+#define TEVALPHAARG_A2 3
+#define TEVALPHAARG_TEXA 4
+#define TEVALPHAARG_RASA 5
+#define TEVALPHAARG_KONST 6
+#define TEVALPHAARG_ZERO 7
+
+#define ALPHACMP_NEVER 0
+#define ALPHACMP_LESS 1
+#define ALPHACMP_EQUAL 2
+#define ALPHACMP_LEQUAL 3
+#define ALPHACMP_GREATER 4
+#define ALPHACMP_NEQUAL 5
+#define ALPHACMP_GEQUAL 6
+#define ALPHACMP_ALWAYS 7
+
+enum Compare
+{
+ COMPARE_NEVER = 0,
+ COMPARE_LESS,
+ COMPARE_EQUAL,
+ COMPARE_LEQUAL,
+ COMPARE_GREATER,
+ COMPARE_NEQUAL,
+ COMPARE_GEQUAL,
+ COMPARE_ALWAYS
+};
+
+#define ZTEXTURE_DISABLE 0
+#define ZTEXTURE_ADD 1
+#define ZTEXTURE_REPLACE 2
+
+enum TevBias
+{
+ TB_ZERO = 0,
+ TB_ADDHALF = 1,
+ TB_SUBHALF = 2,
+ TB_COMPARE = 3,
+};
+
+enum AlphaOp
+{
+ ALPHAOP_AND = 0,
+ ALPHAOP_OR,
+ ALPHAOP_XOR,
+ ALPHAOP_XNOR,
+};
+
+union IND_MTXA
+{
+ struct
+ {
+ signed ma : 11;
+ signed mb : 11;
+ unsigned s0 : 2; // bits 0-1 of scale factor
+ unsigned rid : 8;
+ };
+ u32 hex;
+};
+
+union IND_MTXB
+{
+ struct
+ {
+ signed mc : 11;
+ signed md : 11;
+ unsigned s1 : 2; // bits 2-3 of scale factor
+ unsigned rid : 8;
+ };
+ u32 hex;
+};
+
+union IND_MTXC
+{
+ struct
+ {
+ signed me : 11;
+ signed mf : 11;
+ unsigned s2 : 2; // bits 4-5 of scale factor
+ unsigned rid : 8;
+ };
+ u32 hex;
+};
+
+struct IND_MTX
+{
+ IND_MTXA col0;
+ IND_MTXB col1;
+ IND_MTXC col2;
+};
+
+union IND_IMASK
+{
+ struct
+ {
+ unsigned mask : 24;
+ unsigned rid : 8;
+ };
+ u32 hex;
+};
+
+#define TEVSELCC_CPREV 0
+#define TEVSELCC_APREV 1
+#define TEVSELCC_C0 2
+#define TEVSELCC_A0 3
+#define TEVSELCC_C1 4
+#define TEVSELCC_A1 5
+#define TEVSELCC_C2 6
+#define TEVSELCC_A2 7
+#define TEVSELCC_TEXC 8
+#define TEVSELCC_TEXA 9
+#define TEVSELCC_RASC 10
+#define TEVSELCC_RASA 11
+#define TEVSELCC_ONE 12
+#define TEVSELCC_HALF 13
+#define TEVSELCC_KONST 14
+#define TEVSELCC_ZERO 15
+
+#define TEVSELCA_APREV 0
+#define TEVSELCA_A0 1
+#define TEVSELCA_A1 2
+#define TEVSELCA_A2 3
+#define TEVSELCA_TEXA 4
+#define TEVSELCA_RASA 5
+#define TEVSELCA_KONST 6
+#define TEVSELCA_ZERO 7
+
+struct TevStageCombiner
+{
+ union ColorCombiner
+ {
+ struct //abc=8bit,d=10bit
+ {
+ unsigned d : 4; // TEVSELCC_X
+ unsigned c : 4; // TEVSELCC_X
+ unsigned b : 4; // TEVSELCC_X
+ unsigned a : 4; // TEVSELCC_X
+
+ unsigned bias : 2;
+ unsigned op : 1;
+ unsigned clamp : 1;
+
+ unsigned shift : 2;
+ unsigned dest : 2; //1,2,3
+
+ };
+ u32 hex;
+ };
+ union AlphaCombiner
+ {
+ struct
+ {
+ unsigned rswap : 2;
+ unsigned tswap : 2;
+ unsigned d : 3; // TEVSELCA_
+ unsigned c : 3; // TEVSELCA_
+ unsigned b : 3; // TEVSELCA_
+ unsigned a : 3; // TEVSELCA_
+
+ unsigned bias : 2; //GXTevBias
+ unsigned op : 1;
+ unsigned clamp : 1;
+
+ unsigned shift : 2;
+ unsigned dest : 2; //1,2,3
+ };
+ u32 hex;
+ };
+
+ ColorCombiner colorC;
+ AlphaCombiner alphaC;
+};
+
+#define ITF_8 0
+#define ITF_5 1
+#define ITF_4 2
+#define ITF_3 3
+
+#define ITB_NONE 0
+#define ITB_S 1
+#define ITB_T 2
+#define ITB_ST 3
+#define ITB_U 4
+#define ITB_SU 5
+#define ITB_TU 6
+#define ITB_STU 7
+
+#define ITBA_OFF 0
+#define ITBA_S 1
+#define ITBA_T 2
+#define ITBA_U 3
+
+#define ITW_OFF 0
+#define ITW_256 1
+#define ITW_128 2
+#define ITW_64 3
+#define ITW_32 4
+#define ITW_16 5
+#define ITW_0 6
+
+// several discoveries:
+// GXSetTevIndBumpST(tevstage, indstage, matrixind)
+// if( matrix == 2 ) realmat = 6; // 10
+// else if( matrix == 3 ) realmat = 7; // 11
+// else if( matrix == 1 ) realmat = 5; // 9
+// GXSetTevIndirect(tevstage, indstage, 0, 3, realmat, 6, 6, 0, 0, 0)
+// GXSetTevIndirect(tevstage+1, indstage, 0, 3, realmat+4, 6, 6, 1, 0, 0)
+// GXSetTevIndirect(tevstage+2, indstage, 0, 0, 0, 0, 0, 1, 0, 0)
+
+union TevStageIndirect
+{
+ // if mid, sw, tw, and addprev are 0, then no indirect stage is used, mask = 0x17fe00
+ struct
+ {
+ unsigned bt : 2; // indirect tex stage ID
+ unsigned fmt : 2; // format: ITF_X
+ unsigned bias : 3; // ITB_X
+ unsigned bs : 2; // ITBA_X, indicates which coordinate will become the 'bump alpha'
+ unsigned mid : 4; // matrix id to multiply offsets with
+ unsigned sw : 3; // ITW_X, wrapping factor for S of regular coord
+ unsigned tw : 3; // ITW_X, wrapping factor for T of regular coord
+ unsigned lb_utclod : 1; // use modified or unmodified texture coordinates for LOD computation
+ unsigned fb_addprev : 1; // 1 if the texture coordinate results from the previous TEV stage should be added
+ unsigned pad0 : 3;
+ unsigned rid : 8;
+ };
+ struct
+ {
+ u32 hex : 21;
+ u32 unused : 11;
+ };
+
+ bool IsActive() { return (hex&0x17fe00)!=0; }
+};
+
+union TwoTevStageOrders
+{
+ struct
+ {
+ unsigned texmap0 : 3; // indirect tex stage texmap
+ unsigned texcoord0 : 3;
+ unsigned enable0 : 1; // 1 if should read from texture
+ unsigned colorchan0 : 3; // RAS1_CC_X
+
+ unsigned pad0 : 2;
+
+ unsigned texmap1 : 3;
+ unsigned texcoord1 : 3;
+ unsigned enable1 : 1; // 1 if should read from texture
+ unsigned colorchan1 : 3; // RAS1_CC_X
+
+ unsigned pad1 : 2;
+ unsigned rid : 8;
+ };
+ u32 hex;
+ int getTexMap(int i){return i?texmap1:texmap0;}
+ int getTexCoord(int i){return i?texcoord1:texcoord0;}
+ int getEnable(int i){return i?enable1:enable0;}
+ int getColorChan(int i){return i?colorchan1:colorchan0;}
+};
+
+union TEXSCALE
+{
+ struct
+ {
+ unsigned ss0 : 4; // indirect tex stage 0, 2^(-ss0)
+ unsigned ts0 : 4; // indirect tex stage 0
+ unsigned ss1 : 4; // indirect tex stage 1
+ unsigned ts1 : 4; // indirect tex stage 1
+ unsigned pad : 8;
+ unsigned rid : 8;
+ };
+ u32 hex;
+
+ float getScaleS(int i){return 1.0f/(float)(1<<(i?ss1:ss0));}
+ float getScaleT(int i){return 1.0f/(float)(1<<(i?ts1:ts0));}
+};
+
+union RAS1_IREF
+{
+ struct
+ {
+ unsigned bi0 : 3; // indirect tex stage 0 ntexmap
+ unsigned bc0 : 3; // indirect tex stage 0 ntexcoord
+ unsigned bi1 : 3;
+ unsigned bc1 : 3;
+ unsigned bi2 : 3;
+ unsigned bc3 : 3;
+ unsigned bi4 : 3;
+ unsigned bc4 : 3;
+ unsigned rid : 8;
+ };
+ u32 hex;
+
+ u32 getTexCoord(int i) { return (hex>>(6*i+3))&3; }
+ u32 getTexMap(int i) { return (hex>>(6*i))&3; }
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Texture structs
+//////////////////////////////////////////////////////////////////////////
+union TexMode0
+{
+ struct
+ {
+ unsigned wrap_s : 2;
+ unsigned wrap_t : 2;
+ unsigned mag_filter : 1;
+ unsigned min_filter : 3;
+ unsigned diag_lod : 1;
+ signed lod_bias : 10;
+ unsigned max_aniso : 2;
+ unsigned lod_clamp : 1;
+ };
+ u32 hex;
+};
+union TexMode1
+{
+ struct
+ {
+ unsigned min_lod : 8;
+ unsigned max_lod : 8;
+ };
+ u32 hex;
+};
+union TexImage0
+{
+ struct
+ {
+ unsigned width : 10; //actually w-1
+ unsigned height : 10; //actually h-1
+ unsigned format : 4;
+ };
+ u32 hex;
+};
+union TexImage1
+{
+ struct
+ {
+ unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
+ unsigned cache_width : 3;
+ unsigned cache_height : 3;
+ unsigned image_type : 1;
+ };
+ u32 hex;
+};
+
+union TexImage2
+{
+ struct
+ {
+ unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
+ unsigned cache_width : 3;
+ unsigned cache_height : 3;
+ };
+ u32 hex;
+};
+
+union TexImage3
+{
+ struct
+ {
+ unsigned image_base: 24; //address in memory >> 5 (was 20 for GC)
+ };
+ u32 hex;
+};
+union TexTLUT
+{
+ struct
+ {
+ unsigned tmem_offset : 10;
+ unsigned tlut_format : 2;
+ };
+ u32 hex;
+};
+
+union ZTex1
+{
+ struct
+ {
+ unsigned bias : 24;
+ };
+ u32 hex;
+};
+
+union ZTex2
+{
+ struct
+ {
+ unsigned type : 2; // TEV_Z_TYPE_X
+ unsigned op : 2; // GXZTexOp
+ };
+ u32 hex;
+};
+
+// Z-texture types (formats)
+#define TEV_ZTEX_TYPE_U8 0
+#define TEV_ZTEX_TYPE_U16 1
+#define TEV_ZTEX_TYPE_U24 2
+
+#define TEV_ZTEX_DISABLE 0
+#define TEV_ZTEX_ADD 1
+#define TEV_ZTEX_REPLACE 2
+
+
+struct FourTexUnits
+{
+ TexMode0 texMode0[4];
+ TexMode1 texMode1[4];
+ TexImage0 texImage0[4];
+ TexImage1 texImage1[4];
+ TexImage2 texImage2[4];
+ TexImage3 texImage3[4];
+ TexTLUT texTlut[4];
+ u32 unknown[4];
+};
+
+
+//////////////////////////////////////////////////////////////////////////
+// Geometry/other structs
+//////////////////////////////////////////////////////////////////////////
+union GenMode
+{
+ struct
+ {
+ unsigned numtexgens : 4; // 0xF
+ unsigned numcolchans : 5; // 0x1E0
+ unsigned ms_en : 1; // 0x200
+ unsigned numtevstages : 4; // 0x3C00
+ unsigned cullmode : 2; // 0xC000
+ unsigned numindstages : 3; // 0x30000
+ unsigned zfreeze : 5; //0x3C0000
+ };
+ u32 hex;
+};
+
+union LPSize
+{
+ struct
+ {
+ unsigned linesize : 8; // in 1/6th pixels
+ unsigned pointsize : 8; // in 1/6th pixels
+ unsigned lineoff : 3;
+ unsigned pointoff : 3;
+ unsigned lineaspect : 1;
+ unsigned padding : 1;
+ };
+ u32 hex;
+};
+
+
+union X12Y12
+{
+ struct
+ {
+ unsigned y : 12;
+ unsigned x : 12;
+ };
+ u32 hex;
+};
+union X10Y10
+{
+ struct
+ {
+ unsigned x : 10;
+ unsigned y : 10;
+ };
+ u32 hex;
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Framebuffer/pixel stuff (incl fog)
+//////////////////////////////////////////////////////////////////////////
+union BlendMode
+{
+ struct
+ {
+ unsigned blendenable : 1;
+ unsigned logicopenable : 1;
+ unsigned dither : 1;
+ unsigned colorupdate : 1;
+ unsigned alphaupdate : 1;
+ unsigned dstfactor : 3; //BLEND_ONE, BLEND_INV_SRc etc
+ unsigned srcfactor : 3;
+ unsigned subtract : 1;
+ unsigned logicmode : 4;
+ };
+ u32 hex;
+};
+
+
+union FogParam0
+{
+ struct
+ {
+ unsigned mantissa : 11;
+ unsigned exponent : 8;
+ unsigned sign : 1;
+ };
+
+ float GetA() {
+ union { u32 i; float f; } dummy;
+ dummy.i = ((u32)sign<<31)|((u32)exponent<<23)|((u32)mantissa<<12);
+ return dummy.f;
+ }
+
+ u32 hex;
+};
+
+union FogParam3
+{
+ struct
+ {
+ unsigned c_mant : 11;
+ unsigned c_exp : 8;
+ unsigned c_sign : 1;
+ unsigned proj : 1; // 0 - perspective, 1 - orthographic
+ unsigned fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
+ };
+
+ // amount to subtract from eyespacez after range adjustment
+ float GetC() {
+ union { u32 i; float f; } dummy;
+ dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12);
+ return dummy.f;
+ }
+
+ u32 hex;
+};
+
+// final eq: ze = A/(B_MAG - (Zs>>B_SHF));
+struct FogParams
+{
+ FogParam0 a;
+ u32 b_magnitude;
+ u32 b_shift; // b's exp + 1?
+ FogParam3 c_proj_fsel;
+ u32 color; //0:b 8:g 16:r - nice!
+};
+
+union ZMode
+{
+ struct
+ {
+ unsigned testenable : 1;
+ unsigned func : 3;
+ unsigned updateenable : 1; //size?
+ };
+ u32 hex;
+};
+
+union ConstantAlpha
+{
+ struct
+ {
+ unsigned alpha : 8;
+ unsigned enable : 1;
+ };
+ u32 hex;
+};
+
+#define PIXELFMT_RGB8_Z24 0
+#define PIXELFMT_RGBA6_Z24 1
+#define PIXELFMT_RGB565_Z16 2
+#define PIXELFMT_Z24 3
+#define PIXELFMT_Y8 4
+#define PIXELFMT_U8 5
+#define PIXELFMT_V8 6
+#define PIXELFMT_YUV420 7
+
+union PE_CONTROL
+{
+ struct
+ {
+ unsigned pixel_format : 3; // PIXELFMT_X
+ unsigned zformat : 3; // 0 - linear, 1 - near, 2 - mid, 3 - far
+ unsigned zcomploc : 1; // 1: before tex stage
+ unsigned unused : 17;
+ unsigned rid : 8;
+ };
+ u32 hex;
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Texture coordinate stuff
+//////////////////////////////////////////////////////////////////////////
+union TCInfo
+{
+ struct
+ {
+ unsigned scale_minus_1 : 16;
+ unsigned range_bias : 1;
+ unsigned cylindric_wrap : 1;
+ };
+ u32 hex;
+};
+struct TCoordInfo
+{
+ TCInfo s;
+ TCInfo t;
+};
+
+
+union ColReg
+{
+ u32 hex;
+ struct
+ {
+ signed a : 11;
+ unsigned : 1;
+ signed b : 11;
+ unsigned type : 1;
+ };
+};
+
+struct TevReg
+{
+ ColReg low;
+ ColReg high;
+};
+
+union TevKSel
+{
+ struct {
+ unsigned swap1 : 2;
+ unsigned swap2 : 2;
+ unsigned kcsel0 : 5;
+ unsigned kasel0 : 5;
+ unsigned kcsel1 : 5;
+ unsigned kasel1 : 5;
+ };
+ u32 hex;
+
+ int getKC(int i) {return i?kcsel1:kcsel0;}
+ int getKA(int i) {return i?kasel1:kasel0;}
+};
+
+union AlphaFunc
+{
+ struct
+ {
+ unsigned ref0 : 8;
+ unsigned ref1 : 8;
+ unsigned comp0 : 3;
+ unsigned comp1 : 3;
+ unsigned logic : 2;
+ };
+ u32 hex;
+};
+
+union UPE_Copy
+{
+ u32 Hex;
+ struct
+ {
+ unsigned clamp0 : 1;
+ unsigned clamp1 : 1;
+ unsigned : 1;
+ unsigned target_pixel_format : 4; // realformat is (fmt/2)+((fmt&1)*8).... for some reason the msb is the lsb
+ unsigned gamma : 2;
+ unsigned half_scale : 1; // real size should be 2x smaller (run a gauss filter?)
+ unsigned scale_something : 1;
+ unsigned clear : 1;
+ unsigned frame_to_field : 2;
+ unsigned copy_to_xfb : 1;
+ unsigned intensity_fmt : 1; // if set, is an intensity format (I4,I8,IA4,IA8)
+ unsigned : 16; // seems to set everything to 1s when target pixel format is invalid
+ };
+};
+
+//////////////////////////////////////////////////////////////////////////
+// All of BP memory
+//////////////////////////////////////////////////////////////////////////
+
+struct BPMemory
+{
+ GenMode genMode;
+ u32 display_copy_filter[4]; //01-04
+ u32 unknown; //05
+ // indirect matrices (set by GXSetIndTexMtx, selected by TevStageIndirect::mid)
+ // abc form a 2x3 offset matrix, there's 3 such matrices
+ // the 3 offset matrices can either be indirect type, S-type, or T-type
+ // 6bit scale factor s is distributed across IND_MTXA/B/C.
+ // before using matrices scale by 2^-(s-17)
+ IND_MTX indmtx[3];//06-0e GXSetIndTexMtx, 2x3 matrices
+ IND_IMASK imask;//0f
+ TevStageIndirect tevind[16];//10 GXSetTevIndirect
+ X12Y12 scissorTL; //20
+ X12Y12 scissorBR; //21
+ LPSize lineptwidth; //22 line and point width
+ u32 sucounter; //23
+ u32 rascounter; //24
+ TEXSCALE texscale[2]; //25-26 GXSetIndTexCoordScale
+ RAS1_IREF tevindref; //27 GXSetIndTexOrder
+ TwoTevStageOrders tevorders[8]; //28-2F
+ TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t...
+ ZMode zmode; //40
+ BlendMode blendmode; //41
+ ConstantAlpha dstalpha; //42
+ PE_CONTROL zcontrol; //43 GXSetZCompLoc, GXPixModeSync
+ u32 fieldmask; //44
+ u32 drawdone; //45, bit1=1 if end of list
+ u32 unknown5; //46 clock?
+ u32 petoken; //47
+ u32 petokenint; //48
+ X10Y10 copyTexSrcXY; //49
+ X10Y10 copyTexSrcWH; //4a
+ u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it)
+ u32 unknown6; //4c
+ u32 copyMipMapStrideChannels; // 4d usually set to 4 when dest is single channel, 8 when dest is 2 channel, 16 when dest is RGBA
+ // also, doubles whenever mipmap box filter option is set (excent on RGBA). Probably to do with number of bytes to look at when smoothing
+ u32 dispcopyyscale; //4e
+ u32 clearcolorAR; //4f
+ u32 clearcolorGB; //50
+ u32 clearZValue; //51
+ u32 triggerEFBCopy; //52
+ u32 copyfilter[2]; //53,54
+ u32 boundbox0;//55
+ u32 boundbox1;//56
+ u32 unknown7[2];//57,58
+ X10Y10 scissorOffset; //59
+ u32 unknown8[10]; //5a,5b,5c,5d, 5e,5f,60,61, 62, 63 (GXTexModeSync), 0x60-0x63 have to do with preloaded textures?
+ u32 tlutXferSrc; //64
+ u32 tlutXferDest; //65
+ u32 texinvalidate;//66
+ u32 metric; //67
+ u32 fieldmode;//68
+ u32 unknown10[7];//69-6F
+ u32 unknown11[16];//70-7F
+ FourTexUnits tex[2]; //80-bf
+ TevStageCombiner combiners[16]; //0xC0-0xDF
+ TevReg tevregs[4]; //0xE0
+ u32 fogRangeAdj; //0xE8
+ u32 unknown15[3]; //0xe9,0xea,0xeb - fog related
+ u32 tev_range_adj_c; //0xec - screenx center for range adjustment, range adjustment enable
+ u32 tev_range_adj_k; //0xed - specifies range adjustment function = sqrt(x*x+k*k)/k
+ FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2
+ AlphaFunc alphaFunc; //0xF3
+ ZTex1 ztex1; //0xf4,0xf5
+ ZTex2 ztex2;
+ TevKSel tevksel[8];//0xf6,0xf7,f8,f9,fa,fb,fc,fd
+ u32 bpMask; //0xFE
+ u32 unknown18; //ff
+};
+
+#pragma pack()
+
+extern BPMemory bpmem;
+
+#endif
diff --git a/Source/Core/VideoCommon/Src/CPMemory.cpp b/Source/Core/VideoCommon/Src/CPMemory.cpp
new file mode 100644
index 0000000000..36d910f038
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/CPMemory.cpp
@@ -0,0 +1,7 @@
+#include "Common.h"
+#include "CPMemory.h"
+
+// CP state
+u32 arraybases[16];
+u32 arraystrides[16];
+
diff --git a/Source/Core/VideoCommon/Src/CPMemory.h b/Source/Core/VideoCommon/Src/CPMemory.h
new file mode 100644
index 0000000000..5200ff7b59
--- /dev/null
+++ b/Source/Core/VideoCommon/Src/CPMemory.h
@@ -0,0 +1,191 @@
+#ifndef _CPMEMORY_H
+#define _CPMEMORY_H
+
+#include "Common.h"
+
+// Vertex array numbers
+enum
+{
+ ARRAY_POSITION = 0,
+ ARRAY_NORMAL = 1,
+ ARRAY_COLOR = 2,
+ ARRAY_COLOR2 = 3,
+ ARRAY_TEXCOORD0 = 4,
+};
+
+// Vertex components
+enum
+{
+ NOT_PRESENT = 0,
+ DIRECT = 1,
+ INDEX8 = 2,
+ INDEX16 = 3,
+};
+
+enum
+{
+ FORMAT_UBYTE = 0, // 2 Cmp
+ FORMAT_BYTE = 1, // 3 Cmp
+ FORMAT_USHORT = 2,
+ FORMAT_SHORT = 3,
+ FORMAT_FLOAT = 4,
+};
+
+enum
+{
+ FORMAT_16B_565 = 0, // NA
+ FORMAT_24B_888 = 1,
+ FORMAT_32B_888x = 2,
+ FORMAT_16B_4444 = 3,
+ FORMAT_24B_6666 = 4,
+ FORMAT_32B_8888 = 5,
+};
+
+#pragma pack(4)
+union TVtxDesc
+{
+ u64 Hex;
+ struct
+ {
+ // 0: not present
+ // 1: present
+ unsigned PosMatIdx : 1;
+ unsigned Tex0MatIdx : 1;
+ unsigned Tex1MatIdx : 1;
+ unsigned Tex2MatIdx : 1;
+ unsigned Tex3MatIdx : 1;
+ unsigned Tex4MatIdx : 1;
+ unsigned Tex5MatIdx : 1;
+ unsigned Tex6MatIdx : 1;
+ unsigned Tex7MatIdx : 1;
+
+ // 00: not present
+ // 01: direct
+ // 10: 8 bit index
+ // 11: 16 bit index
+ unsigned Position : 2;
+ unsigned Normal : 2;
+ unsigned Color0 : 2;
+ unsigned Color1 : 2;
+ unsigned Tex0Coord : 2;
+ unsigned Tex1Coord : 2;
+ unsigned Tex2Coord : 2;
+ unsigned Tex3Coord : 2;
+ unsigned Tex4Coord : 2;
+ unsigned Tex5Coord : 2;
+ unsigned Tex6Coord : 2;
+ unsigned Tex7Coord : 2;
+ unsigned :31;
+ };
+ struct {
+ u32 Hex0, Hex1;
+ };
+};
+
+union UVAT_group0
+{
+ u32 Hex;
+ struct
+ {
+ // 0:8
+ unsigned PosElements : 1;
+ unsigned PosFormat : 3;
+ unsigned PosFrac : 5;
+ // 9:12
+ unsigned NormalElements : 1;
+ unsigned NormalFormat : 3;
+ // 13:16
+ unsigned Color0Elements : 1;
+ unsigned Color0Comp : 3;
+ // 17:20
+ unsigned Color1Elements : 1;
+ unsigned Color1Comp : 3;
+ // 21:29
+ unsigned Tex0CoordElements : 1;
+ unsigned Tex0CoordFormat : 3;
+ unsigned Tex0Frac : 5;
+ // 30:31
+ unsigned ByteDequant: 1;
+ unsigned NormalIndex3: 1;
+ };
+};
+
+union UVAT_group1
+{
+ u32 Hex;
+ struct
+ {
+ // 0:8
+ unsigned Tex1CoordElements : 1;
+ unsigned Tex1CoordFormat : 3;
+ unsigned Tex1Frac : 5;
+ // 9:17
+ unsigned Tex2CoordElements : 1;
+ unsigned Tex2CoordFormat : 3;
+ unsigned Tex2Frac : 5;
+ // 18:26
+ unsigned Tex3CoordElements : 1;
+ unsigned Tex3CoordFormat : 3;
+ unsigned Tex3Frac : 5;
+ // 27:30
+ unsigned Tex4CoordElements : 1;
+ unsigned Tex4CoordFormat : 3;
+ //
+ unsigned : 1;
+ };
+};
+
+union UVAT_group2
+{
+ u32 Hex;
+ struct
+ {
+ // 0:4
+ unsigned Tex4Frac : 5;
+ // 5:13
+ unsigned Tex5CoordElements : 1;
+ unsigned Tex5CoordFormat : 3;
+ unsigned Tex5Frac : 5;
+ // 14:22
+ unsigned Tex6CoordElements : 1;
+ unsigned Tex6CoordFormat : 3;
+ unsigned Tex6Frac : 5;
+ // 23:31
+ unsigned Tex7CoordElements : 1;
+ unsigned Tex7CoordFormat : 3;
+ unsigned Tex7Frac : 5;
+ };
+};
+
+struct ColorAttr
+{
+ u8 Elements;
+ u8 Comp;
+};
+
+struct TexAttr
+{
+ u8 Elements;
+ u8 Format;
+ u8 Frac;
+};
+
+struct TVtxAttr
+{
+ u8 PosElements;
+ u8 PosFormat;
+ u8 PosFrac;
+ u8 NormalElements;
+ u8 NormalFormat;
+ ColorAttr color[2];
+ TexAttr texCoord[8];
+ u8 ByteDequant;
+ u8 NormalIndex3;
+};
+
+#pragma pack()
+
+extern u32 arraybases[16];
+extern u32 arraystrides[16];
+
+#endif
diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj
new file mode 100644
index 0000000000..3987410b7f
--- /dev/null
+++ b/Source/Core/VideoCommon/VideoCommon.vcproj
@@ -0,0 +1,411 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/Dolphin.sln b/Source/Dolphin.sln
index a97278153b..24fd3059b5 100644
--- a/Source/Dolphin.sln
+++ b/Source/Dolphin.sln
@@ -9,8 +9,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "Core\Core\Core.vcpr
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_VideoDX9", "Plugins\Plugin_VideoDX9\Plugin_VideoDX9.vcproj", "{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}"
ProjectSection(ProjectDependencies) = postProject
- {3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63}
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA} = {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}
+ {3E03C179-8251-46E4-81F4-466F114BAC63} = {3E03C179-8251-46E4-81F4-466F114BAC63}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_PadSimple", "Plugins\Plugin_PadSimple\Plugin_PadSimple.vcproj", "{9A183B48-ECC2-4121-876A-9B3793686073}"
@@ -32,6 +33,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_VideoOGL", "Plugins\Plugin_VideoOGL\Plugin_VideoOGL.vcproj", "{CFDCEE0E-FA45-4F72-9FCC-0B88F5A75160}"
ProjectSection(ProjectDependencies) = postProject
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA} = {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Core\Common\Common.vcproj", "{C573CAF7-EE6A-458E-8049-16C0BF34C2E9}"
@@ -71,6 +73,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_DSP_NULL", "Plugins\
{C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VideoCommon", "Core\VideoCommon\VideoCommon.vcproj", "{E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}"
+ ProjectSection(ProjectDependencies) = postProject
+ {C573CAF7-EE6A-458E-8049-16C0BF34C2E9} = {C573CAF7-EE6A-458E-8049-16C0BF34C2E9}
+ EndProjectSection
+EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_PadDX9", "Plugins\Plugin_PadDX9\Plugin_PadDX9.vcproj", "{805B34AA-82A5-4875-8DC7-3C85BDC0BCEE}"
EndProject
Global
@@ -251,6 +258,18 @@ Global
{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}.Release|Win32.Build.0 = Release|Win32
{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}.Release|x64.ActiveCfg = Release|x64
{9AC65CBE-7854-4A86-AA10-D73FF9E5D61F}.Release|x64.Build.0 = Release|x64
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Debug|Win32.Build.0 = Debug|Win32
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Debug|x64.ActiveCfg = Debug|x64
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Debug|x64.Build.0 = Debug|x64
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.DebugFast|Win32.ActiveCfg = Debug|Win32
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.DebugFast|Win32.Build.0 = Debug|Win32
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.DebugFast|x64.ActiveCfg = DebugFast|x64
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.DebugFast|x64.Build.0 = DebugFast|x64
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Release|Win32.ActiveCfg = Release|Win32
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Release|Win32.Build.0 = Release|Win32
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Release|x64.ActiveCfg = Release|x64
+ {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}.Release|x64.Build.0 = Release|x64
{805B34AA-82A5-4875-8DC7-3C85BDC0BCEE}.Debug|Win32.ActiveCfg = Debug|Win32
{805B34AA-82A5-4875-8DC7-3C85BDC0BCEE}.Debug|Win32.Build.0 = Debug|Win32
{805B34AA-82A5-4875-8DC7-3C85BDC0BCEE}.Debug|x64.ActiveCfg = Debug|x64
diff --git a/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj b/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj
index 3df83b89e4..15e492003a 100644
--- a/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj
+++ b/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj
@@ -1,7 +1,7 @@
@@ -138,7 +137,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -225,7 +223,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -315,7 +312,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -403,7 +399,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -493,7 +488,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
diff --git a/Source/Plugins/Plugin_DSP_NULL/Plugin_DSP_NULL.vcproj b/Source/Plugins/Plugin_DSP_NULL/Plugin_DSP_NULL.vcproj
index da9242548b..5d24e9663e 100644
--- a/Source/Plugins/Plugin_DSP_NULL/Plugin_DSP_NULL.vcproj
+++ b/Source/Plugins/Plugin_DSP_NULL/Plugin_DSP_NULL.vcproj
@@ -1,7 +1,7 @@
@@ -137,7 +136,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -225,7 +223,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -316,7 +313,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -406,7 +402,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
@@ -497,7 +492,6 @@
UsePrecompiledHeader="2"
AssemblerListingLocation="$(IntDir)\"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
ForcedIncludeFiles="stdafx.h"
/>
diff --git a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj
index 3d9f033dbe..81bdd2a752 100644
--- a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj
+++ b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj
@@ -57,7 +57,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="false"
WholeProgramOptimization="true"
- AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src"
+ AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;"
PreprocessorDefinitions="_WIN32;WIN32;NDEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true"
RuntimeLibrary="0"
@@ -164,7 +164,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="false"
WholeProgramOptimization="true"
- AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src"
+ AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;VIDEO_DIRECTX9_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true"
ExceptionHandling="1"
@@ -266,7 +266,7 @@
SetRenderState(D3DRS_ALPHABLENDENABLE,bpmem.blendmode.blendenable);
- if (changes & 2) ; // Logic op blending. D3D can't do this but can fake some modes.
+ if (changes & 2) {} // Logic op blending. D3D can't do this but can fake some modes.
if (changes & 4) {
// Dithering is pointless. Will make things uglier and will be different from GC.
// dev->SetRenderState(D3DRS_DITHERENABLE,bpmem.blendmode.dither);
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.h b/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.h
index 68c28be18e..e0f3d912c7 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.h
+++ b/Source/Plugins/Plugin_VideoDX9/Src/BPStructs.h
@@ -3,731 +3,7 @@
#pragma pack(4)
-//////////////////////////////////////////////////////////////////////////
-// Tev/combiner things
-//////////////////////////////////////////////////////////////////////////
-
-enum TevBias
-{
- TB_ZERO = 0,
- TB_ADDHALF = 1,
- TB_SUBHALF = 2,
- TB_COMPARE = 3,
-};
-
-
-enum AlphaOp
-{
- ALPHAOP_AND = 0,
- ALPHAOP_OR,
- ALPHAOP_XOR,
- ALPHAOP_XNOR,
-};
-
-enum Compare
-{
- COMPARE_NEVER,
- COMPARE_LESS,
- COMPARE_EQUAL,
- COMPARE_LEQUAL,
- COMPARE_GREATER,
- COMPARE_NEQUAL,
- COMPARE_GEQUAL,
- COMPARE_ALWAYS
-};
-
-#define TEVCMP_R8_GT 8
-#define TEVCMP_R8_EQ 9
-#define TEVCMP_GR16_GT 10
-#define TEVCMP_GR16_EQ 11
-#define TEVCMP_BGR24_GT 12
-#define TEVCMP_BGR24_EQ 13
-#define TEVCMP_RGB8_GT 14
-#define TEVCMP_RGB8_EQ 15
-#define TEVCMP_A8_GT 14
-#define TEVCMP_A8_EQ 15
-
-//color chan above:
-// rasterized color selections
-#define RAS1_CC_0 0x00000000 /* color channel 0 */
-#define RAS1_CC_1 0x00000001 /* color channel 1 */
-#define RAS1_CC_B 0x00000005 /* indirect texture bump alpha */
-#define RAS1_CC_BN 0x00000006 /* ind tex bump alpha, normalized 0-255 */
-#define RAS1_CC_Z 0x00000007 /* set color value to zero */
-
-// Z-texture types (formats)
-#define TEV_Z_TYPE_U8 0x00000000
-#define TEV_Z_TYPE_U16 0x00000001
-#define TEV_Z_TYPE_U24 0x00000002
-
-#define ZTEXTURE_DISABLE 0
-#define ZTEXTURE_ADD 1
-#define ZTEXTURE_REPLACE 2
-
-
-union IND_MTXA
-{
- struct
- {
- signed ma : 11;
- signed mb : 11;
- unsigned s0 : 2; // bits 0-1 of scale factor
- unsigned rid : 8;
- };
- u32 hex;
-};
-
-union IND_MTXB
-{
- struct
- {
- signed mc : 11;
- signed md : 11;
- unsigned s1 : 2; // bits 2-3 of scale factor
- unsigned rid : 8;
- };
- u32 hex;
-};
-
-union IND_MTXC
-{
- struct
- {
- signed me : 11;
- signed mf : 11;
- unsigned s2 : 2; // bits 4-5 of scale factor
- unsigned rid : 8;
- };
- u32 hex;
-};
-
-struct IND_MTX
-{
- IND_MTXA col0;
- IND_MTXB col1;
- IND_MTXC col2;
-};
-
-union IND_IMASK
-{
- struct
- {
- unsigned mask : 24;
- unsigned rid : 8;
- };
- u32 hex;
-};
-
-struct TevStageCombiner
-{
- union ColorCombiner
- {
- struct //abc=8bit,d=10bit
- {
- unsigned d : 4;
- unsigned c : 4;
- unsigned b : 4;
- unsigned a : 4;
-
- unsigned bias : 2;
- unsigned op : 1;
- unsigned clamp : 1;
-
- unsigned shift : 2;
- unsigned outreg : 2; //1,2,3
-
- };
- u32 hex;
- };
- union AlphaCombiner
- {
- struct
- {
- unsigned rswap : 2;
- unsigned tswap : 2;
- unsigned d : 3;
- unsigned c : 3;
- unsigned b : 3;
- unsigned a : 3;
-
- unsigned bias : 2;
- unsigned op : 1;
- unsigned clamp : 1;
-
- unsigned shift : 2;
- unsigned outreg : 2; //1,2,3
- };
- u32 hex;
- };
-
- ColorCombiner colorC;
- AlphaCombiner alphaC;
-};
-
-#define ITF_8 0
-#define ITF_5 1
-#define ITF_4 2
-#define ITF_3 3
-
-#define ITB_NONE 0
-#define ITB_S 1
-#define ITB_T 2
-#define ITB_ST 3
-#define ITB_U 4
-#define ITB_SU 5
-#define ITB_TU 6
-#define ITB_STU 7
-
-#define ITBA_OFF 0
-#define ITBA_S 1
-#define ITBA_T 2
-#define ITBA_U 3
-
-#define ITW_OFF 0
-#define ITW_256 1
-#define ITW_128 2
-#define ITW_64 3
-#define ITW_32 4
-#define ITW_16 5
-#define ITW_0 6
-
-// several discoveries:
-// GXSetTevIndBumpST(tevstage, indstage, matrixind)
-// if( matrix == 2 ) realmat = 6; // 10
-// else if( matrix == 3 ) realmat = 7; // 11
-// else if( matrix == 1 ) realmat = 5; // 9
-// GXSetTevIndirect(tevstage, indstage, 0, 3, realmat, 6, 6, 0, 0, 0)
-// GXSetTevIndirect(tevstage+1, indstage, 0, 3, realmat+4, 6, 6, 1, 0, 0)
-// GXSetTevIndirect(tevstage+2, indstage, 0, 0, 0, 0, 0, 1, 0, 0)
-
-union TevStageIndirect
-{
- // if mid, sw, tw, and addprev are 0, then no indirect stage is used, mask = 0x17fe00
- struct
- {
- unsigned bt : 2; // indirect tex stage ID
- unsigned fmt : 2; // format: ITF_X
- unsigned bias : 3; // ITB_X
- unsigned bs : 2; // ITBA_X, indicates which coordinate will become the 'bump alpha'
- unsigned mid : 4; // matrix id to multiply offsets with
- unsigned sw : 3; // ITW_X, wrapping factor for S of regular coord
- unsigned tw : 3; // ITW_X, wrapping factor for T of regular coord
- unsigned lb_utclod : 1; // use modified or unmodified texture coordinates for LOD computation
- unsigned fb_addprev : 1; // 1 if the texture coordinate results from the previous TEV stage should be added
- unsigned pad0 : 3;
- unsigned rid : 8;
- };
- struct
- {
- u32 hex : 21;
- u32 unused : 11;
- };
-
- bool IsActive() { return (hex&0x17fe00)!=0; }
-};
-
-union TwoTevStageOrders
-{
- struct
- {
- unsigned texmap0 : 3;
- unsigned texcoord0 : 3;
- unsigned enable0 : 1;
- unsigned colorchan0 : 3;
-
- unsigned pad0 : 2;
-
- unsigned texmap1 : 3;
- unsigned texcoord1 : 3;
- unsigned enable1 : 1;
- unsigned colorchan1 : 3;
-
- unsigned pad1 : 2;
- };
- u32 hex;
- int getTexMap(int i){return i?texmap1:texmap0;}
- int getTexCoord(int i){return i?texcoord1:texcoord0;}
- int getEnable(int i){return i?enable1:enable0;}
- int getColorChan(int i){return i?colorchan1:colorchan0;}
-};
-
-union TEXSCALE
-{
- struct
- {
- unsigned ss0 : 4; // indirect tex stage 0, 2^(-ss0)
- unsigned ts0 : 4; // indirect tex stage 0
- unsigned ss1 : 4; // indirect tex stage 1
- unsigned ts1 : 4; // indirect tex stage 1
- unsigned pad : 8;
- unsigned rid : 8;
- };
- u32 hex;
-
- float getScaleS(int i){return 1.0f/(float)(1<<(i?ss1:ss0));}
- float getScaleT(int i){return 1.0f/(float)(1<<(i?ts1:ts0));}
-};
-
-union RAS1_IREF
-{
- struct
- {
- unsigned bi0 : 3; // indirect tex stage 0 ntexmap
- unsigned bc0 : 3; // indirect tex stage 0 ntexcoord
- unsigned bi1 : 3;
- unsigned bc1 : 3;
- unsigned bi2 : 3;
- unsigned bc3 : 3;
- unsigned bi4 : 3;
- unsigned bc4 : 3;
- unsigned rid : 8;
- };
- u32 hex;
-
- u32 getTexCoord(int i) { return (hex>>(6*i+3))&3; }
- u32 getTexMap(int i) { return (hex>>(6*i))&3; }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Texture structs
-//////////////////////////////////////////////////////////////////////////
-union TexMode0
-{
- struct
- {
- unsigned wrap_s : 2;
- unsigned wrap_t : 2;
- unsigned mag_filter : 1;
- unsigned min_filter : 3;
- unsigned diag_lod : 1;
- signed lod_bias : 8;
- unsigned max_aniso : 2;
- unsigned lod_clamp : 1;
- };
- u32 hex;
-};
-union TexMode1
-{
- struct
- {
- unsigned min_lod : 8;
- unsigned max_lod : 8;
- };
- u32 hex;
-};
-union TexImage0
-{
- struct
- {
- unsigned width : 10; //actually w-1
- unsigned height : 10; //actually h-1
- unsigned format : 4;
- };
- u32 hex;
-};
-union TexImage1
-{
- struct
- {
- unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
- unsigned cache_width : 3;
- unsigned cache_height : 3;
- unsigned image_type : 1;
- };
- u32 hex;
-};
-
-union TexImage2
-{
- struct
- {
- unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
- unsigned cache_width : 3;
- unsigned cache_height : 3;
- };
- u32 hex;
-};
-
-union TexImage3
-{
- struct
- {
- unsigned image_base: 24; //address in memory >> 5
- };
- u32 hex;
-};
-union TexTLUT
-{
- struct
- {
- unsigned tmem_offset : 10;
- unsigned tlut_format : 2;
- };
- u32 hex;
-};
-
-union ZTex1
-{
- struct
- {
- unsigned bias : 24;
- };
- u32 hex;
-};
-
-union ZTex2
-{
- struct
- {
- unsigned type : 2;
- unsigned op : 2;
- };
- u32 hex;
-};
-
-// Z-texture types (formats)
-#define TEV_ZTEX_TYPE_U8 0x00000000
-#define TEV_ZTEX_TYPE_U16 0x00000001
-#define TEV_ZTEX_TYPE_U24 0x00000002
-
-#define TEV_ZTEX_DISABLE 0
-#define TEV_ZTEX_ADD 1
-#define TEV_ZTEX_REPLACE 2
-
-
-struct FourTexUnits
-{
- TexMode0 texMode0[4];
- TexMode1 texMode1[4];
- TexImage0 texImage0[4];
- TexImage1 texImage1[4];
- TexImage2 texImage2[4];
- TexImage3 texImage3[4];
- TexTLUT texTlut[4];
- u32 unknown[4];
-};
-
-
-//////////////////////////////////////////////////////////////////////////
-// Geometry/other structs
-//////////////////////////////////////////////////////////////////////////
-union GenMode
-{
- struct
- {
- unsigned numtexgens : 4; // 0xF
- unsigned numcolchans : 5; // 0x1E0
- unsigned ms_en : 1; // 0x200
- unsigned numtevstages : 4; // 0x3C00
- unsigned cullmode : 2; // 0xC000
- unsigned numindstages : 3; // 0x30000
- unsigned zfreeze : 5; //0x3C0000
- };
- u32 hex;
-};
-
-union LPSize
-{
- struct
- {
- unsigned linesize : 8;
- unsigned pointsize : 8;
- unsigned lineoff : 3;
- unsigned pointoff : 3;
- unsigned lineaspect : 1;
- unsigned padding : 1;
- };
- u32 hex;
-};
-
-
-union X12Y12
-{
- struct
- {
- unsigned y : 12;
- unsigned x : 12;
- };
- u32 hex;
-};
-union X10Y10
-{
- struct
- {
- unsigned x : 10;
- unsigned y : 10;
- };
- u32 hex;
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Framebuffer/pixel stuff (incl fog)
-//////////////////////////////////////////////////////////////////////////
-union BlendMode
-{
- struct
- {
- unsigned blendenable : 1;
- unsigned logicopenable : 1;
- unsigned dither : 1;
- unsigned colorupdate : 1;
- unsigned alphaupdate : 1;
- unsigned dstfactor : 3; //BLEND_ONE, BLEND_INV_SRc etc
- unsigned srcfactor : 3;
- unsigned subtract : 1;
- unsigned logicmode : 4;
- };
- u32 hex;
-};
-
-
-union FogParam0
-{
- struct
- {
- unsigned mantissa : 11;
- unsigned exponent : 8;
- unsigned sign : 1;
- };
- u32 hex;
-};
-union FogParam3
-{
- struct
- {
- unsigned c_mant : 11;
- unsigned c_exp : 8;
- unsigned c_sign : 1;
- unsigned proj : 1; // 0 - perspective, 1 - orthographic
- unsigned fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
- };
-
- // amount to subtract from eyespacez after range adjustment
- float GetC() {
- union { u32 i; float f; } dummy;
- dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12);
- return dummy.f;
- }
-
- u32 hex;
-};
-struct FogParams
-{
- FogParam0 a;
- u32 b_magnitude;
- u32 b_exponent;
- FogParam3 c_proj_fsel;
- u32 color; //0:b 8:g 16:r - nice!
-};
-
-union ZMode
-{
- struct
- {
- unsigned testenable : 1;
- unsigned func : 3;
- unsigned updateenable : 1; //size?
- };
- u32 hex;
-};
-
-union ConstantAlpha
-{
- struct
- {
- unsigned alpha : 8;
- unsigned enable : 1;
- };
- u32 hex;
-};
-
-#define PIXELFMT_RGB8_Z24 0
-#define PIXELFMT_RGBA6_Z24 1
-#define PIXELFMT_RGB565_Z16 2
-#define PIXELFMT_Z24 3
-#define PIXELFMT_Y8 4
-#define PIXELFMT_U8 5
-#define PIXELFMT_V8 6
-#define PIXELFMT_YUV420 7
-
-union PE_CONTROL
-{
- struct
- {
- unsigned pixel_format : 3; // PIXELFMT_X
- unsigned zformat : 3; // 0 - linear, 1 - near, 2 - mid, 3 - far
- unsigned zcomploc : 1; // 1: before tex stage
- unsigned unused : 17;
- unsigned rid : 8;
- };
- u32 hex;
-};
-
-
-//////////////////////////////////////////////////////////////////////////
-// Texture coordinate stuff
-//////////////////////////////////////////////////////////////////////////
-union TCInfo
-{
- struct
- {
- unsigned scale_minus_1 : 16;
- unsigned range_bias : 1;
- unsigned cylindric_wrap : 1;
- };
- u32 hex;
-};
-struct TCoordInfo
-{
- TCInfo s;
- TCInfo t;
-};
-
-union ColReg
-{
- u32 hex;
- struct
- {
- signed a : 11;
- unsigned : 1;
- signed b : 11;
- unsigned type : 1;
- };
-};
-
-struct TevReg
-{
- ColReg low;
- ColReg high;
-};
-
-union TevKSel
-{
- struct {
- unsigned swap1 : 2;
- unsigned swap2 : 2;
- unsigned kcsel0 : 5;
- unsigned kasel0 : 5;
- unsigned kcsel1 : 5;
- unsigned kasel1 : 5;
- };
- u32 hex;
-
- int getKC(int i) {return i?kcsel1:kcsel0;}
- int getKA(int i) {return i?kasel1:kasel0;}
-};
-
-union AlphaFunc
-{
- struct
- {
- unsigned ref0 : 8;
- unsigned ref1 : 8;
- unsigned comp0 : 3;
- unsigned comp1 : 3;
- unsigned logic : 2;
- };
- u32 hex;
-};
-
-union UPE_Copy
-{
- u32 Hex;
- struct
- {
- unsigned clamp0 : 1;
- unsigned clamp1 : 1;
- unsigned target_pixel_format : 3;
- unsigned : 2;
- unsigned gamma : 2;
- unsigned : 1;
- unsigned scale_something : 1;
- unsigned clear : 1;
- unsigned frame_to_field : 2;
- unsigned copy_to_xfb : 1;
- unsigned : 17;
- };
-};
-
-#define EFBCOPY_EFBTOTEXTURE 0x10000
-#define EFBCOPY_CLEAR 0x800
-#define EFBCOPY_GENERATEMIPS 0x200
-
-
-//////////////////////////////////////////////////////////////////////////
-// All of BP memory
-//////////////////////////////////////////////////////////////////////////
-
-struct BPMemory
-{
- GenMode genMode;
- u32 display_copy_filter[4]; //01-04
- u32 unknown; //05
- // indirect matrices (set by GXSetIndTexMtx, selected by TevStageIndirect::mid)
- // abc form a 2x3 offset matrix, there's 3 such matrices
- // the 3 offset matrices can either be indirect type, S-type, or T-type
- // 6bit scale factor s is distributed across IND_MTXA/B/C.
- // before using matrices scale by 2^-(s-17)
- IND_MTX indmtx[3];//06-0e GXSetIndTexMtx, 2x3 matrices
- IND_IMASK imask;//0f
- TevStageIndirect tevind[16];//10 GXSetTevIndirect
- X12Y12 scissorTL; //20
- X12Y12 scissorBR; //21
- LPSize lineptwidth; //22 line and point width
- u32 sucounter; //23
- u32 rascounter; //24
- TEXSCALE texscale[2]; //25-26 GXSetIndTexCoordScale
- RAS1_IREF tevindref; //27 GXSetIndTexOrder
- TwoTevStageOrders tevorders[8]; //28-2F
- TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t...
- ZMode zmode; //40
- BlendMode blendmode; //41
- ConstantAlpha dstalpha; //42
- PE_CONTROL zcontrol; //43 GXSetZCompLoc, GXPixModeSync
- u32 fieldmask; //44
- u32 drawdone; //45, bit1=1 if end of list
- u32 unknown5; //46 clock?
- u32 petoken; //47
- u32 petokenint; //48
- X10Y10 copyTexSrcXY; //49
- X10Y10 copyTexSrcWH; //4a
- u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it)
- u32 unknown6; //4c, 4d
- u32 copyMipMapStrideChannels; // 4d usually set to 4 when dest is single channel, 8 when dest is 2 channel, 16 when dest is RGBA
- // also, doubles whenever mipmap box filter option is set (excent on RGBA). Probably to do with number of bytes to look at when smoothing
- u32 dispcopyyscale; //4e
- u32 clearcolorAR; //4f
- u32 clearcolorGB; //50
- u32 clearZValue; //51
- u32 triggerEFBCopy; //52
- u32 copyfilter[2]; //53,54
- u32 boundbox0;//55
- u32 boundbox1;//56
- u32 unknown7[2];//57,58
- X10Y10 scissorOffset; //59
- u32 unknown8[10]; //5a,5b,5c,5d, 5e,5f,60,61, 62, 63 (GXTexModeSync),
- u32 tlutXferSrc; //64
- u32 tlutXferDest; //65
- u32 texinvalidate;//66
- u32 unknown9; //67
- u32 fieldmode; //68
- u32 unknown10[7];//69-6F
- u32 unknown11[16];//70-7F
- FourTexUnits tex[2]; //80-bf
- TevStageCombiner combiners[16]; //0xC0-0xDF
- TevReg tevregs[4]; //0xE0
- u32 fogRangeAdj; //0xE8
- u32 unknown15[3]; //0xe9,0xea,0xeb,0xec,0xed
- u32 tev_range_adj_c; //0xec - screenx center for range adjustment, range adjustment enable
- u32 tev_range_adj_k; //0xed - specifies range adjustment function = sqrt(x*x+k*k)/k
- FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2
- AlphaFunc alphaFunc; //0xF3
- ZTex1 ztex1; //0xf4,0xf5
- ZTex2 ztex2;
- TevKSel tevksel[8];//0xf6,0xf7,f8,f9,fa,fb,fc,fd
- u32 bpMask; //0xFE
- u32 unknown18; //ff
-};
+#include "BPMemory.h"
void BPInit();
size_t BPSaveLoadState(char *ptr, BOOL save);
@@ -736,8 +12,4 @@ void LoadBPReg(u32 value0);
void ActivateTextures();
-extern BPMemory bpmem;
-
-#pragma pack()
-
#endif
\ No newline at end of file
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.cpp b/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.cpp
index 307f51c8e9..f6eb5604a5 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.cpp
@@ -6,10 +6,6 @@
#include "VertexHandler.h"
#include "VertexLoader.h"
-// CP state
-u32 arraybases[16];
-u32 arraystrides[16];
-
TMatrixIndexA MatrixIndexA;
TMatrixIndexB MatrixIndexB;
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.h b/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.h
index addab692c6..5d45fa7284 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.h
+++ b/Source/Plugins/Plugin_VideoDX9/Src/CPStructs.h
@@ -2,187 +2,10 @@
#define _CPSTRUCTS_H
#include "Common.h"
-
-// Vertex array numbers
-enum
-{
- ARRAY_POSITION = 0,
- ARRAY_NORMAL = 1,
- ARRAY_COLOR = 2,
- ARRAY_COLOR2 = 3,
- ARRAY_TEXCOORD0 = 4
-};
-
-// Vertex components
-enum
-{
- NOT_PRESENT = 0,
- DIRECT = 1,
- INDEX8 = 2,
- INDEX16 = 3,
-};
+#include "CPMemory.h"
#pragma pack(4)
-union TVtxDesc
-{
- u64 Hex;
- struct
- {
- // 0: not present
- // 1: present
- unsigned PosMatIdx : 1;
- unsigned Tex0MatIdx : 1;
- unsigned Tex1MatIdx : 1;
- unsigned Tex2MatIdx : 1;
- unsigned Tex3MatIdx : 1;
- unsigned Tex4MatIdx : 1;
- unsigned Tex5MatIdx : 1;
- unsigned Tex6MatIdx : 1;
- unsigned Tex7MatIdx : 1;
-
- // 00: not present
- // 01: direct
- // 10: 8 bit index
- // 11: 16 bit index
- unsigned Position : 2;
- unsigned Normal : 2;
- unsigned Color0 : 2;
- unsigned Color1 : 2;
- unsigned Tex0Coord : 2;
- unsigned Tex1Coord : 2;
- unsigned Tex2Coord : 2;
- unsigned Tex3Coord : 2;
- unsigned Tex4Coord : 2;
- unsigned Tex5Coord : 2;
- unsigned Tex6Coord : 2;
- unsigned Tex7Coord : 2;
- unsigned :31;
- };
-};
-
-
-
-enum
-{
- FORMAT_UBYTE = 0, // 2 Cmp
- FORMAT_BYTE = 1, // 3 Cmp
- FORMAT_USHORT = 2,
- FORMAT_SHORT = 3,
- FORMAT_FLOAT = 4,
-};
-
-enum
-{
- FORMAT_16B_565 = 0, // NA
- FORMAT_24B_888 = 1,
- FORMAT_32B_888x = 2,
- FORMAT_16B_4444 = 3,
- FORMAT_24B_6666 = 4,
- FORMAT_32B_8888 = 5,
-};
-
-union UVAT_group0
-{
- u32 Hex;
- struct
- {
- // 0:8
- unsigned PosElements : 1;
- unsigned PosFormat : 3;
- unsigned PosFrac : 5;
- // 9:12
- unsigned NormalElements : 1;
- unsigned NormalFormat : 3;
- // 13:16
- unsigned Color0Elements : 1;
- unsigned Color0Comp : 3;
- // 17:20
- unsigned Color1Elements : 1;
- unsigned Color1Comp : 3;
- // 21:29
- unsigned Tex0CoordElements : 1;
- unsigned Tex0CoordFormat : 3;
- unsigned Tex0Frac : 5;
- // 30:31
- unsigned ByteDequant: 1;
- unsigned NormalIndex3: 1;
- };
-};
-
-union UVAT_group1
-{
- u32 Hex;
- struct
- {
- // 0:8
- unsigned Tex1CoordElements : 1;
- unsigned Tex1CoordFormat : 3;
- unsigned Tex1Frac : 5;
- // 9:17
- unsigned Tex2CoordElements : 1;
- unsigned Tex2CoordFormat : 3;
- unsigned Tex2Frac : 5;
- // 18:26
- unsigned Tex3CoordElements : 1;
- unsigned Tex3CoordFormat : 3;
- unsigned Tex3Frac : 5;
- // 27:30
- unsigned Tex4CoordElements : 1;
- unsigned Tex4CoordFormat : 3;
- //
- unsigned : 1;
- };
-};
-
-union UVAT_group2
-{
- u32 Hex;
- struct
- {
- // 0:4
- unsigned Tex4Frac : 5;
- // 5:13
- unsigned Tex5CoordElements : 1;
- unsigned Tex5CoordFormat : 3;
- unsigned Tex5Frac : 5;
- // 14:22
- unsigned Tex6CoordElements : 1;
- unsigned Tex6CoordFormat : 3;
- unsigned Tex6Frac : 5;
- // 23:31
- unsigned Tex7CoordElements : 1;
- unsigned Tex7CoordFormat : 3;
- unsigned Tex7Frac : 5;
- };
-};
-
-struct ColorAttr
-{
- u8 Elements;
- u8 Comp;
-};
-
-struct TexAttr
-{
- u8 Elements;
- u8 Format;
- u8 Frac;
-};
-
-struct TVtxAttr
-{
- u8 PosElements;
- u8 PosFormat;
- u8 PosFrac;
- u8 NormalElements;
- u8 NormalFormat;
- ColorAttr color[2];
- TexAttr texCoord[8];
- u8 ByteDequant;
- u8 NormalIndex3;
-};
-
//////////////////////////////////////////////////////////////////////////
// Matrix indices
//////////////////////////////////////////////////////////////////////////
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShader.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShader.cpp
index 9eb66329a9..e5394bf46f 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShader.cpp
+++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShader.cpp
@@ -388,7 +388,7 @@ void WriteStage(char *&p, int n)
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[n].colorC;
TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[n].alphaC;
- WRITE(p,"float4(%s,%s)=", tevCOutputTable[cc.outreg], tevAOutputTable[ac.outreg]);
+ WRITE(p,"float4(%s,%s)=", tevCOutputTable[cc.dest], tevAOutputTable[ac.dest]);
//////////////////////////////////////////////////////////////////////////
//start of color
@@ -469,7 +469,7 @@ void WriteStage(char *&p, int n)
}
WRITE(p, ");");
if (ac.clamp)
- WRITE(p, "%s = clamp(%s, 0.0f, 1.0f);\n", tevAOutputTable[ac.outreg], tevAOutputTable[ac.outreg]);
+ WRITE(p, "%s = clamp(%s, 0.0f, 1.0f);\n", tevAOutputTable[ac.dest], tevAOutputTable[ac.dest]);
WRITE(p, "\n");
}
@@ -477,14 +477,14 @@ void WriteAlphaCompare(char *&p, int num, int comp)
{
WRITE(p," res%i = ",num);
switch(comp) {
- case COMPARE_ALWAYS: WRITE(p,"0;\n"); break;
- case COMPARE_NEVER: WRITE(p,"1;\n"); break;
- case COMPARE_LEQUAL: WRITE(p,"prev.a - %s.x;\n",alphaRef[num]); break;
- case COMPARE_LESS: WRITE(p,"prev.a - %s.x + %f;\n",alphaRef[num],epsilon*2);break;
- case COMPARE_GEQUAL: WRITE(p,"%s - prev.a;\n",alphaRef[num]); break;
- case COMPARE_GREATER: WRITE(p,"%s - prev.a + %f;\n",alphaRef[num],epsilon*2);break;
- case COMPARE_EQUAL: WRITE(p,"abs(%s-prev.a)-%f;\n",alphaRef[num],epsilon*2); break;
- case COMPARE_NEQUAL: WRITE(p,"%f-abs(%s-prev.a);\n",epsilon*2,alphaRef[num]); break;
+ case ALPHACMP_ALWAYS: WRITE(p,"0;\n"); break;
+ case ALPHACMP_NEVER: WRITE(p,"1;\n"); break;
+ case ALPHACMP_LEQUAL: WRITE(p,"prev.a - %s.x;\n",alphaRef[num]); break;
+ case ALPHACMP_LESS: WRITE(p,"prev.a - %s.x + %f;\n",alphaRef[num],epsilon*2);break;
+ case ALPHACMP_GEQUAL: WRITE(p,"%s - prev.a;\n",alphaRef[num]); break;
+ case ALPHACMP_GREATER: WRITE(p,"%s - prev.a + %f;\n",alphaRef[num],epsilon*2);break;
+ case ALPHACMP_EQUAL: WRITE(p,"abs(%s-prev.a)-%f;\n",alphaRef[num],epsilon*2); break;
+ case ALPHACMP_NEQUAL: WRITE(p,"%f-abs(%s-prev.a);\n",epsilon*2,alphaRef[num]); break;
}
}
diff --git a/Source/Plugins/Plugin_VideoDX9/Src/XFStructs.h b/Source/Plugins/Plugin_VideoDX9/Src/XFStructs.h
index 058269748a..22bfb5ca32 100644
--- a/Source/Plugins/Plugin_VideoDX9/Src/XFStructs.h
+++ b/Source/Plugins/Plugin_VideoDX9/Src/XFStructs.h
@@ -1,45 +1,38 @@
#ifndef _XFSTRUCTS_H
#define _XFSTRUCTS_H
-
#include "Common.h"
#include "Vec3.h"
-
#pragma pack(4)
//////////////////////////////////////////////////////////////////////////
// Lighting
//////////////////////////////////////////////////////////////////////////
-// xf_tex_projection_f enum
#define XF_TEX_ST 0x00000000
#define XF_TEX_STQ 0x00000001
-// xf_tex_input_form_f enum
#define XF_TEX_AB11 0x00000000
#define XF_TEX_ABC1 0x00000001
-// xf_tex_texgen_type_f enum
#define XF_TEXGEN_REGULAR 0x00000000
#define XF_TEXGEN_EMBOSS_MAP 0x00000001
#define XF_TEXGEN_COLOR_STRGBC0 0x00000002
#define XF_TEXGEN_COLOR_STRGBC1 0x00000003
-// xf_tex_source_row_f enum
-#define XF_GEOM_INROW 0x00000000
-#define XF_NORMAL_INROW 0x00000001
-#define XF_COLORS_INROW 0x00000002
+#define XF_GEOM_INROW 0x00000000
+#define XF_NORMAL_INROW 0x00000001
+#define XF_COLORS_INROW 0x00000002
#define XF_BINORMAL_T_INROW 0x00000003
#define XF_BINORMAL_B_INROW 0x00000004
-#define XF_TEX0_INROW 0x00000005
-#define XF_TEX1_INROW 0x00000006
-#define XF_TEX2_INROW 0x00000007
-#define XF_TEX3_INROW 0x00000008
-#define XF_TEX4_INROW 0x00000009
-#define XF_TEX5_INROW 0x0000000a
-#define XF_TEX6_INROW 0x0000000b
-#define XF_TEX7_INROW 0x0000000c
-
+#define XF_TEX0_INROW 0x00000005
+#define XF_TEX1_INROW 0x00000006
+#define XF_TEX2_INROW 0x00000007
+#define XF_TEX3_INROW 0x00000008
+#define XF_TEX4_INROW 0x00000009
+#define XF_TEX5_INROW 0x0000000a
+#define XF_TEX6_INROW 0x0000000b
+#define XF_TEX7_INROW 0x0000000c
struct Light
{
@@ -68,8 +61,6 @@ struct Light
#define GX_SRC_REG 0
#define GX_SRC_VTX 1
-
-
union LitChannel
{
struct
@@ -88,6 +79,7 @@ union LitChannel
return lightMask0_3 | (lightMask4_7 << 4);
}
};
+
struct ColorChannel
{
u32 ambColor;
@@ -95,10 +87,12 @@ struct ColorChannel
LitChannel color;
LitChannel alpha;
};
+
struct MiscXF
{
int numTexGens;
};
+
union TexMtxInfo
{
struct
@@ -113,6 +107,7 @@ union TexMtxInfo
};
u32 hex;
};
+
union PostMtxInfo
{
struct
@@ -122,6 +117,7 @@ union PostMtxInfo
};
u32 hex;
};
+
struct TexCoordInfo
{
TexMtxInfo texmtxinfo;
@@ -138,14 +134,15 @@ struct Viewport
float farZ;
};
-
-#define XFMEM_SIZE 0x8000
-
-
-#define XFMEM_POSMATRICES 0x000
-#define XFMEM_NORMALMATRICES 0x400
-#define XFMEM_POSTMATRICES 0x500
-#define XFMEM_LIGHTS 0x600
+#define XFMEM_SIZE 0x8000
+#define XFMEM_POSMATRICES 0x000
+#define XFMEM_POSMATRICES_END 0x100
+#define XFMEM_NORMALMATRICES 0x400
+#define XFMEM_NORMALMATRICES_END 0x460
+#define XFMEM_POSTMATRICES 0x500
+#define XFMEM_POSTMATRICES_END 0x600
+#define XFMEM_LIGHTS 0x600
+#define XFMEM_LIGHTS_END 0x680
extern TexCoordInfo texcoords[8];
diff --git a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj
index 06d40f998f..6b864f1861 100644
--- a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj
+++ b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj
@@ -56,7 +56,7 @@
EnableIntrinsicFunctions="true"
OmitFramePointers="true"
WholeProgramOptimization="true"
- AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;./Src;./Src/Windows;../../../Externals;./Src/Windows/libjpeg"
+ AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;./Src;./Src/Windows;../../../Externals;./Src/Windows/libjpeg"
PreprocessorDefinitions="_WIN32;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true"
RuntimeLibrary="0"
@@ -163,7 +163,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="false"
WholeProgramOptimization="true"
- AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;./Src;./Src/Windows;../../../Externals;./Src/Windows/libjpeg"
+ AdditionalIncludeDirectories="../../PluginSpecs;../../Core/Common/Src;../../Core/VideoCommon/Src;./Src;./Src/Windows;../../../Externals;./Src/Windows/libjpeg"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true"
ExceptionHandling="1"
@@ -268,7 +268,7 @@
>(6*i+3))&3; }
- u32 getTexMap(int i) { return (hex>>(6*i))&3; }
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Texture structs
-//////////////////////////////////////////////////////////////////////////
-union TexMode0
-{
- struct
- {
- unsigned wrap_s : 2;
- unsigned wrap_t : 2;
- unsigned mag_filter : 1;
- unsigned min_filter : 3;
- unsigned diag_lod : 1;
- signed lod_bias : 10;
- unsigned max_aniso : 2;
- unsigned lod_clamp : 1;
- };
- u32 hex;
-};
-union TexMode1
-{
- struct
- {
- unsigned min_lod : 8;
- unsigned max_lod : 8;
- };
- u32 hex;
-};
-union TexImage0
-{
- struct
- {
- unsigned width : 10; //actually w-1
- unsigned height : 10; //actually h-1
- unsigned format : 4;
- };
- u32 hex;
-};
-union TexImage1
-{
- struct
- {
- unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
- unsigned cache_width : 3;
- unsigned cache_height : 3;
- unsigned image_type : 1;
- };
- u32 hex;
-};
-
-union TexImage2
-{
- struct
- {
- unsigned tmem_offset : 15; // we ignore texture caching for now, we do it ourselves
- unsigned cache_width : 3;
- unsigned cache_height : 3;
- };
- u32 hex;
-};
-
-union TexImage3
-{
- struct
- {
- unsigned image_base: 24; //address in memory >> 5 (was 20 for GC)
- };
- u32 hex;
-};
-union TexTLUT
-{
- struct
- {
- unsigned tmem_offset : 10;
- unsigned tlut_format : 2;
- };
- u32 hex;
-};
-
-union ZTex1
-{
- struct
- {
- unsigned bias : 24;
- };
- u32 hex;
-};
-
-union ZTex2
-{
- struct
- {
- unsigned type : 2; // TEV_Z_TYPE_X
- unsigned op : 2; // GXZTexOp
- };
- u32 hex;
-};
-
-// Z-texture types (formats)
-#define TEV_ZTEX_TYPE_U8 0
-#define TEV_ZTEX_TYPE_U16 1
-#define TEV_ZTEX_TYPE_U24 2
-
-#define TEV_ZTEX_DISABLE 0
-#define TEV_ZTEX_ADD 1
-#define TEV_ZTEX_REPLACE 2
-
-
-struct FourTexUnits
-{
- TexMode0 texMode0[4];
- TexMode1 texMode1[4];
- TexImage0 texImage0[4];
- TexImage1 texImage1[4];
- TexImage2 texImage2[4];
- TexImage3 texImage3[4];
- TexTLUT texTlut[4];
- u32 unknown[4];
-};
-
-
-//////////////////////////////////////////////////////////////////////////
-// Geometry/other structs
-//////////////////////////////////////////////////////////////////////////
-union GenMode
-{
- struct
- {
- unsigned numtexgens : 4; // 0xF
- unsigned numcolchans : 5; // 0x1E0
- unsigned ms_en : 1; // 0x200
- unsigned numtevstages : 4; // 0x3C00
- unsigned cullmode : 2; // 0xC000
- unsigned numindstages : 3; // 0x30000
- unsigned zfreeze : 5; //0x3C0000
- };
- u32 hex;
-};
-
-union LPSize
-{
- struct
- {
- unsigned linesize : 8; // in 1/6th pixels
- unsigned pointsize : 8; // in 1/6th pixels
- unsigned lineoff : 3;
- unsigned pointoff : 3;
- unsigned lineaspect : 1;
- unsigned padding : 1;
- };
- u32 hex;
-};
-
-
-union X12Y12
-{
- struct
- {
- unsigned y : 12;
- unsigned x : 12;
- };
- u32 hex;
-};
-union X10Y10
-{
- struct
- {
- unsigned x : 10;
- unsigned y : 10;
- };
- u32 hex;
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Framebuffer/pixel stuff (incl fog)
-//////////////////////////////////////////////////////////////////////////
-union BlendMode
-{
- struct
- {
- unsigned blendenable : 1;
- unsigned logicopenable : 1;
- unsigned dither : 1;
- unsigned colorupdate : 1;
- unsigned alphaupdate : 1;
- unsigned dstfactor : 3; //BLEND_ONE, BLEND_INV_SRc etc
- unsigned srcfactor : 3;
- unsigned subtract : 1;
- unsigned logicmode : 4;
- };
- u32 hex;
-};
-
-
-union FogParam0
-{
- struct
- {
- unsigned mantissa : 11;
- unsigned exponent : 8;
- unsigned sign : 1;
- };
-
- float GetA() {
- union { u32 i; float f; } dummy;
- dummy.i = ((u32)sign<<31)|((u32)exponent<<23)|((u32)mantissa<<12);
- return dummy.f;
- }
-
- u32 hex;
-};
-
-union FogParam3
-{
- struct
- {
- unsigned c_mant : 11;
- unsigned c_exp : 8;
- unsigned c_sign : 1;
- unsigned proj : 1; // 0 - perspective, 1 - orthographic
- unsigned fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
- };
-
- // amount to subtract from eyespacez after range adjustment
- float GetC() {
- union { u32 i; float f; } dummy;
- dummy.i = ((u32)c_sign << 31) | ((u32)c_exp << 23) | ((u32)c_mant << 12);
- return dummy.f;
- }
-
- u32 hex;
-};
-
-// final eq: ze = A/(B_MAG - (Zs>>B_SHF));
-struct FogParams
-{
- FogParam0 a;
- u32 b_magnitude;
- u32 b_shift; // b's exp + 1?
- FogParam3 c_proj_fsel;
- u32 color; //0:b 8:g 16:r - nice!
-};
-
-union ZMode
-{
- struct
- {
- unsigned testenable : 1;
- unsigned func : 3;
- unsigned updateenable : 1; //size?
- };
- u32 hex;
-};
-
-union ConstantAlpha
-{
- struct
- {
- unsigned alpha : 8;
- unsigned enable : 1;
- };
- u32 hex;
-};
-
-#define PIXELFMT_RGB8_Z24 0
-#define PIXELFMT_RGBA6_Z24 1
-#define PIXELFMT_RGB565_Z16 2
-#define PIXELFMT_Z24 3
-#define PIXELFMT_Y8 4
-#define PIXELFMT_U8 5
-#define PIXELFMT_V8 6
-#define PIXELFMT_YUV420 7
-
-union PE_CONTROL
-{
- struct
- {
- unsigned pixel_format : 3; // PIXELFMT_X
- unsigned zformat : 3; // 0 - linear, 1 - near, 2 - mid, 3 - far
- unsigned zcomploc : 1; // 1: before tex stage
- unsigned unused : 17;
- unsigned rid : 8;
- };
- u32 hex;
-};
-
-//////////////////////////////////////////////////////////////////////////
-// Texture coordinate stuff
-//////////////////////////////////////////////////////////////////////////
-union TCInfo
-{
- struct
- {
- unsigned scale_minus_1 : 16;
- unsigned range_bias : 1;
- unsigned cylindric_wrap : 1;
- };
- u32 hex;
-};
-struct TCoordInfo
-{
- TCInfo s;
- TCInfo t;
-};
-
-
-union ColReg
-{
- u32 hex;
- struct
- {
- signed a : 11;
- unsigned : 1;
- signed b : 11;
- unsigned type : 1;
- };
-};
-
-struct TevReg
-{
- ColReg low;
- ColReg high;
-};
-
-union TevKSel
-{
- struct {
- unsigned swap1 : 2;
- unsigned swap2 : 2;
- unsigned kcsel0 : 5;
- unsigned kasel0 : 5;
- unsigned kcsel1 : 5;
- unsigned kasel1 : 5;
- };
- u32 hex;
-
- int getKC(int i) {return i?kcsel1:kcsel0;}
- int getKA(int i) {return i?kasel1:kasel0;}
-};
-
-union AlphaFunc
-{
- struct
- {
- unsigned ref0 : 8;
- unsigned ref1 : 8;
- unsigned comp0 : 3;
- unsigned comp1 : 3;
- unsigned logic : 2;
- };
- u32 hex;
-};
-
-union UPE_Copy
-{
- u32 Hex;
- struct
- {
- unsigned clamp0 : 1;
- unsigned clamp1 : 1;
- unsigned : 1;
- unsigned target_pixel_format : 4; // realformat is (fmt/2)+((fmt&1)*8).... for some reason the msb is the lsb
- unsigned gamma : 2;
- unsigned half_scale : 1; // real size should be 2x smaller (run a gauss filter?)
- unsigned scale_something : 1;
- unsigned clear : 1;
- unsigned frame_to_field : 2;
- unsigned copy_to_xfb : 1;
- unsigned intensity_fmt : 1; // if set, is an intensity format (I4,I8,IA4,IA8)
- unsigned : 16; // seems to set everything to 1s when target pixel format is invalid
- };
-};
-
-//////////////////////////////////////////////////////////////////////////
-// All of BP memory
-//////////////////////////////////////////////////////////////////////////
-
-struct BPMemory
-{
- GenMode genMode;
- u32 display_copy_filter[4]; //01-04
- u32 unknown; //05
- // indirect matrices (set by GXSetIndTexMtx, selected by TevStageIndirect::mid)
- // abc form a 2x3 offset matrix, there's 3 such matrices
- // the 3 offset matrices can either be indirect type, S-type, or T-type
- // 6bit scale factor s is distributed across IND_MTXA/B/C.
- // before using matrices scale by 2^-(s-17)
- IND_MTX indmtx[3];//06-0e GXSetIndTexMtx, 2x3 matrices
- IND_IMASK imask;//0f
- TevStageIndirect tevind[16];//10 GXSetTevIndirect
- X12Y12 scissorTL; //20
- X12Y12 scissorBR; //21
- LPSize lineptwidth; //22 line and point width
- u32 sucounter; //23
- u32 rascounter; //24
- TEXSCALE texscale[2]; //25-26 GXSetIndTexCoordScale
- RAS1_IREF tevindref; //27 GXSetIndTexOrder
- TwoTevStageOrders tevorders[8]; //28-2F
- TCoordInfo texcoords[8]; //0x30 s,t,s,t,s,t,s,t...
- ZMode zmode; //40
- BlendMode blendmode; //41
- ConstantAlpha dstalpha; //42
- PE_CONTROL zcontrol; //43 GXSetZCompLoc, GXPixModeSync
- u32 fieldmask; //44
- u32 drawdone; //45, bit1=1 if end of list
- u32 unknown5; //46 clock?
- u32 petoken; //47
- u32 petokenint; //48
- X10Y10 copyTexSrcXY; //49
- X10Y10 copyTexSrcWH; //4a
- u32 copyTexDest; //4b// 4b == CopyAddress (GXDispCopy and GXTexCopy use it)
- u32 unknown6; //4c
- u32 copyMipMapStrideChannels; // 4d usually set to 4 when dest is single channel, 8 when dest is 2 channel, 16 when dest is RGBA
- // also, doubles whenever mipmap box filter option is set (excent on RGBA). Probably to do with number of bytes to look at when smoothing
- u32 dispcopyyscale; //4e
- u32 clearcolorAR; //4f
- u32 clearcolorGB; //50
- u32 clearZValue; //51
- u32 triggerEFBCopy; //52
- u32 copyfilter[2]; //53,54
- u32 boundbox0;//55
- u32 boundbox1;//56
- u32 unknown7[2];//57,58
- X10Y10 scissorOffset; //59
- u32 unknown8[10]; //5a,5b,5c,5d, 5e,5f,60,61, 62, 63 (GXTexModeSync), 0x60-0x63 have to do with preloaded textures?
- u32 tlutXferSrc; //64
- u32 tlutXferDest; //65
- u32 texinvalidate;//66
- u32 metric; //67
- u32 fieldmode;//68
- u32 unknown10[7];//69-6F
- u32 unknown11[16];//70-7F
- FourTexUnits tex[2]; //80-bf
- TevStageCombiner combiners[16]; //0xC0-0xDF
- TevReg tevregs[4]; //0xE0
- u32 fogRangeAdj; //0xE8
- u32 unknown15[3]; //0xe9,0xea,0xeb - fog related
- u32 tev_range_adj_c; //0xec - screenx center for range adjustment, range adjustment enable
- u32 tev_range_adj_k; //0xed - specifies range adjustment function = sqrt(x*x+k*k)/k
- FogParams fog; //0xEE,0xEF,0xF0,0xF1,0xF2
- AlphaFunc alphaFunc; //0xF3
- ZTex1 ztex1; //0xf4,0xf5
- ZTex2 ztex2;
- TevKSel tevksel[8];//0xf6,0xf7,f8,f9,fa,fb,fc,fd
- u32 bpMask; //0xFE
- u32 unknown18; //ff
-};
+#include "BPMemory.h"
void BPInit();
size_t BPSaveLoadState(char *ptr, BOOL save);
@@ -780,8 +28,4 @@ void LoadBPReg(u32 value0);
void SetColorMask();
bool SetScissorRect();
-extern BPMemory bpmem;
-
-#pragma pack()
-
#endif
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShader.h b/Source/Plugins/Plugin_VideoOGL/Src/PixelShader.h
index 247c8acbde..f41c0203b4 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShader.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShader.h
@@ -48,7 +48,7 @@ class PixelShaderMngr
values[i] = r.values[i];
}
- bool operator<(const PIXELSHADERUID& _Right) const
+ bool operator <(const PIXELSHADERUID& _Right) const
{
if( values[0] < _Right.values[0] )
return true;
@@ -75,7 +75,7 @@ class PixelShaderMngr
return false;
}
- bool operator==(const PIXELSHADERUID& _Right) const
+ bool operator ==(const PIXELSHADERUID& _Right) const
{
if( values[0] != _Right.values[0] )
return false;
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureDecoder.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureDecoder.cpp
index 552333c20a..730cb7ab60 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureDecoder.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureDecoder.cpp
@@ -16,12 +16,10 @@
// http://code.google.com/p/dolphin-emu/
#include "Globals.h"
+#include "Common.h"
-#include "BPStructs.h"
#include "TextureDecoder.h"
-#include "OpcodeDecoding.h"
-
// TRAM
u8 texMem[TMEM_SIZE];
@@ -48,6 +46,7 @@ int TexDecoder_GetTexelSizeInNibbles(int format)
default: return 1;
}
}
+
int TexDecoder_GetBlockWidthInTexels(int format)
{
switch(format) {
@@ -62,7 +61,7 @@ int TexDecoder_GetBlockWidthInTexels(int format)
case GX_TF_C8: return 8;
case GX_TF_C14X2: return 4;
case GX_TF_CMPR: return 8;
- default:return 8;
+ default: return 8;
}
}
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp
index 66a174a571..3967618883 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.cpp
@@ -15,1144 +15,1141 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
-#include "Globals.h"
-#include
-#include
-
-#include "x64Emitter.h"
-
-#include "VertexLoader.h"
-#include "BPStructs.h"
-#include "DataReader.h"
-
-#include "VertexShader.h"
-#include "PixelShader.h"
-#include "TextureMngr.h"
-
-#include "MemoryUtil.h"
-
-#include
-
-#define MAX_BUFFER_SIZE 0x4000
-
-// CP state
-u32 arraybases[16];
-u32 arraystrides[16];
-
-// internal state for loading vertices
-static u32 s_prevvbstride, s_prevcomponents; // previous state set
-static u8 *s_pBaseBufferPointer = NULL;
-static GLuint s_vboBuffers[0x40] = {0};
-static int s_nCurVBOIndex = 0; // current free buffer
-static GLenum s_prevprimitive = 0; // current primitive type
-static vector< pair > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays
-static void (*fnSetupVertexPointers)() = NULL;
-
-//these don't need to be saved
-float posScale;
-float tcScale[8];
-int colElements[2];
-float tcScaleU[8];
-float tcScaleV[8];
-int tcIndex;
-int colIndex;
-
-inline u8 ReadBuffer8()
-{
- return g_pDataReader->Read8();
-}
-
-inline u16 ReadBuffer16()
-{
- //PowerPC byte ordering :(
- return g_pDataReader->Read16();
-}
-
-inline u32 ReadBuffer32()
-{
- //PowerPC byte ordering :(
- return g_pDataReader->Read32();
-}
-
-inline float ReadBuffer32F()
-{
- u32 temp = g_pDataReader->Read32();
- return *(float*)(&temp);
-}
-
-// ==============================================================================
-// Direct
-// ==============================================================================
-static u8 s_curposmtx, s_curtexmtx[8];
-static int s_texmtxwrite = 0, s_texmtxread = 0;
-
-void LOADERDECL PosMtx_ReadDirect_UByte(void* _p)
-{
- s_curposmtx = ReadBuffer8()&0x3f;
- PRIM_LOG("posmtx: %d, ", s_curposmtx);
-}
-
-void LOADERDECL PosMtx_Write(void* _p)
-{
- *VertexManager::s_pCurBufferPointer++ = s_curposmtx;
- //*VertexManager::s_pCurBufferPointer++ = 0;
- //*VertexManager::s_pCurBufferPointer++ = 0;
- //*VertexManager::s_pCurBufferPointer++ = 0;
-}
-
-void LOADERDECL TexMtx_ReadDirect_UByte(void* _p)
-{
- s_curtexmtx[s_texmtxread] = ReadBuffer8()&0x3f;
- PRIM_LOG("texmtx%d: %d, ", s_texmtxread, s_curtexmtx[s_texmtxread]);
- s_texmtxread++;
-}
-
-void LOADERDECL TexMtx_Write_Float(void* _p)
-{
- *(float*)VertexManager::s_pCurBufferPointer = (float)s_curtexmtx[s_texmtxwrite++];
- VertexManager::s_pCurBufferPointer += 4;
-}
-
-void LOADERDECL TexMtx_Write_Float2(void* _p)
-{
- ((float*)VertexManager::s_pCurBufferPointer)[0] = 0;
- ((float*)VertexManager::s_pCurBufferPointer)[1] = (float)s_curtexmtx[s_texmtxwrite++];
- VertexManager::s_pCurBufferPointer += 8;
-}
-
-void LOADERDECL TexMtx_Write_Short3(void* _p)
-{
- ((s16*)VertexManager::s_pCurBufferPointer)[0] = 0;
- ((s16*)VertexManager::s_pCurBufferPointer)[1] = 0;
- ((s16*)VertexManager::s_pCurBufferPointer)[2] = s_curtexmtx[s_texmtxwrite++];
- VertexManager::s_pCurBufferPointer += 6;
-}
-
-#include "VertexLoader_Position.h"
-#include "VertexLoader_Normal.h"
-#include "VertexLoader_Color.h"
-#include "VertexLoader_TextCoord.h"
-
-VertexLoader g_VertexLoaders[8];
-
-#define COMPILED_CODE_SIZE 4096
-
-VertexLoader::VertexLoader()
-{
- m_numPipelineStates = 0;
- m_VertexSize = 0;
- m_AttrDirty = 2;
- VertexLoader_Normal::Init();
-
- m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE);
- if (m_compiledCode) {
- memset(m_compiledCode, 0, COMPILED_CODE_SIZE);
- }
-}
-
-VertexLoader::~VertexLoader()
-{
- FreeMemoryPages(m_compiledCode, COMPILED_CODE_SIZE);
-}
-
-int VertexLoader::ComputeVertexSize()
-{
- if (m_AttrDirty < 2) {
-
- if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
- return m_VertexSize;
-
- m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
- }
- else {
- // set anyway
- m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
- }
-
- if( fnSetupVertexPointers != NULL && fnSetupVertexPointers == (void (*)())(void*)m_compiledCode )
- VertexManager::Flush();
-
- m_AttrDirty = 1;
- m_VertexSize = 0;
- // Position Matrix Index
- if (m_VtxDesc.PosMatIdx)
- m_VertexSize += 1;
-
- // Texture matrix indices
- if (m_VtxDesc.Tex0MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex1MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex2MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex3MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex4MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex5MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex6MatIdx) {m_VertexSize+=1; }
- if (m_VtxDesc.Tex7MatIdx) {m_VertexSize+=1; }
-
- switch (m_VtxDesc.Position) {
- case NOT_PRESENT: {_assert_("Vertex descriptor without position!");} break;
- case DIRECT:
- {
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE:
- case FORMAT_BYTE: m_VertexSize += m_VtxAttr.PosElements?3:2; break;
- case FORMAT_USHORT:
- case FORMAT_SHORT: m_VertexSize += m_VtxAttr.PosElements?6:4; break;
- case FORMAT_FLOAT: m_VertexSize += m_VtxAttr.PosElements?12:8; break;
- default: _assert_(0); break;
- }
- }
- break;
- case INDEX8:
- m_VertexSize+=1;
- break;
- case INDEX16:
- m_VertexSize+=2;
- break;
- }
-
- if (m_VtxDesc.Normal != NOT_PRESENT)
- m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
-
- // Colors
- int col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1};
- for (int i = 0; i < 2; i++) {
- switch (col[i])
- {
- case NOT_PRESENT:
- break;
- case DIRECT:
- switch (m_VtxAttr.color[i].Comp)
- {
- case FORMAT_16B_565: m_VertexSize+=2; break;
- case FORMAT_24B_888: m_VertexSize+=3; break;
- case FORMAT_32B_888x: m_VertexSize+=4; break;
- case FORMAT_16B_4444: m_VertexSize+=2; break;
- case FORMAT_24B_6666: m_VertexSize+=3; break;
- case FORMAT_32B_8888: m_VertexSize+=4; break;
- default: _assert_(0); break;
- }
- break;
- case INDEX8:
- m_VertexSize+=1;
- break;
- case INDEX16:
- m_VertexSize+=2;
- break;
- }
- }
-
- // TextureCoord
- int tc[8] = {
- m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, m_VtxDesc.Tex3Coord,
- m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord,
- };
-
- for (int i = 0; i < 8; i++) {
- switch (tc[i]) {
- case NOT_PRESENT:
- break;
- case DIRECT:
- {
- switch (m_VtxAttr.texCoord[i].Format)
- {
- case FORMAT_UBYTE:
- case FORMAT_BYTE: m_VertexSize += m_VtxAttr.texCoord[i].Elements?2:1; break;
- case FORMAT_USHORT:
- case FORMAT_SHORT: m_VertexSize += m_VtxAttr.texCoord[i].Elements?4:2; break;
- case FORMAT_FLOAT: m_VertexSize += m_VtxAttr.texCoord[i].Elements?8:4; break;
- default: _assert_(0); break;
- }
- }
- break;
- case INDEX8:
- m_VertexSize+=1;
- break;
- case INDEX16:
- m_VertexSize+=2;
- break;
- }
- }
-
- return m_VertexSize;
-}
-
-
-// Note the use of CallCdeclFunction3I etc.
-// This is a horrible hack that is necessary because Opengl32.dll is based way, way above the 32-bit address space
-// that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we want to grab
-// the function pointers from the import table instead.
-
-// This problem does not apply to glew functions, only core opengl32 functions.
-
-DECLARE_IMPORT(glNormalPointer);
-DECLARE_IMPORT(glVertexPointer);
-DECLARE_IMPORT(glColorPointer);
-DECLARE_IMPORT(glTexCoordPointer);
-
-void VertexLoader::ProcessFormat()
-{
- using namespace Gen;
-
- //_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer );
-
- if (!m_AttrDirty ) {
-
- if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
- // same
- return;
-
- m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
- }
- else {
- // set anyway
- m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
- m_AttrDirty = 0;
- }
-
- DVSTARTPROFILE();
-
- // Reset pipeline
- m_VBStridePad = 0;
- m_VBVertexStride = 0;
- m_numPipelineStates = 0;
- m_components = 0;
-
- // m_VBVertexStride for texmtx and posmtx is computed later when writing
-
- // Position Matrix Index
- if (m_VtxDesc.PosMatIdx) {
- m_PipelineStates[m_numPipelineStates++] = PosMtx_ReadDirect_UByte;
- m_components |= VB_HAS_POSMTXIDX;
- }
-
- if (m_VtxDesc.Tex0MatIdx) {m_components|=VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex1MatIdx) {m_components|=VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex2MatIdx) {m_components|=VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex3MatIdx) {m_components|=VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex4MatIdx) {m_components|=VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex5MatIdx) {m_components|=VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex6MatIdx) {m_components|=VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); }
- if (m_VtxDesc.Tex7MatIdx) {m_components|=VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); }
-
- // Position
- if (m_VtxDesc.Position != NOT_PRESENT)
- m_VBVertexStride += 12;
-
- switch (m_VtxDesc.Position) {
- case NOT_PRESENT: {_assert_msg_(0,"Vertex descriptor without position!","WTF?");} break;
- case DIRECT:
- {
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE: WriteCall(Pos_ReadDirect_UByte); break;
- case FORMAT_BYTE: WriteCall(Pos_ReadDirect_Byte); break;
- case FORMAT_USHORT: WriteCall(Pos_ReadDirect_UShort); break;
- case FORMAT_SHORT: WriteCall(Pos_ReadDirect_Short); break;
- case FORMAT_FLOAT: WriteCall(Pos_ReadDirect_Float); break;
- default: _assert_(0); break;
- }
- }
- break;
- case INDEX8:
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE: WriteCall(Pos_ReadIndex8_UByte); break; //WTF?
- case FORMAT_BYTE: WriteCall(Pos_ReadIndex8_Byte); break;
- case FORMAT_USHORT: WriteCall(Pos_ReadIndex8_UShort); break;
- case FORMAT_SHORT: WriteCall(Pos_ReadIndex8_Short); break;
- case FORMAT_FLOAT: WriteCall(Pos_ReadIndex8_Float); break;
- default: _assert_(0); break;
- }
- break;
- case INDEX16:
- switch (m_VtxAttr.PosFormat) {
- case FORMAT_UBYTE: WriteCall(Pos_ReadIndex16_UByte); break;
- case FORMAT_BYTE: WriteCall(Pos_ReadIndex16_Byte); break;
- case FORMAT_USHORT: WriteCall(Pos_ReadIndex16_UShort); break;
- case FORMAT_SHORT: WriteCall(Pos_ReadIndex16_Short); break;
- case FORMAT_FLOAT: WriteCall(Pos_ReadIndex16_Float); break;
- default: _assert_(0); break;
- }
- break;
- }
-
- // Normals
- if (m_VtxDesc.Normal != NOT_PRESENT) {
- VertexLoader_Normal::index3 = m_VtxAttr.NormalIndex3 ? true : false;
- unsigned int uSize = VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
- TPipelineFunction pFunc = VertexLoader_Normal::GetFunction(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
- if (pFunc == 0)
- {
- char temp[256];
- sprintf(temp,"%i %i %i", m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
- SysMessage("VertexLoader_Normal::GetFunction returned zero!");
- }
- WriteCall(pFunc);
-
- int sizePro=0;
- switch (m_VtxAttr.NormalFormat)
- {
- case FORMAT_UBYTE: sizePro=1; break;
- case FORMAT_BYTE: sizePro=1; break;
- case FORMAT_USHORT: sizePro=2; break;
- case FORMAT_SHORT: sizePro=2; break;
- case FORMAT_FLOAT: sizePro=4; break;
- default: _assert_(0); break;
- }
- m_VBVertexStride += sizePro * 3 * (m_VtxAttr.NormalElements?3:1);
-
- int m_numNormals = (m_VtxAttr.NormalElements==1) ? NRM_THREE : NRM_ONE;
- m_components |= VB_HAS_NRM0;
- if (m_numNormals == NRM_THREE)
- m_components |= VB_HAS_NRM1 | VB_HAS_NRM2;
- }
-
- // Colors
- int col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1};
- for (int i = 0; i < 2; i++) {
- SetupColor(i,col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
-
- if (col[i] != NOT_PRESENT )
- m_VBVertexStride+=4;
- }
-
- // TextureCoord
- int tc[8] = {
- m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, m_VtxDesc.Tex3Coord,
- m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord,
- };
-
- // Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
- for (int i = 0; i < 8; i++) {
- SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac);
-
- if( m_components&(VB_HAS_TEXMTXIDX0< COMPILED_CODE_SIZE)
- {
- assert(0);
- Crash();
- }
-
- SetCodePtr(0);
-}
-
-void VertexLoader::PrepareRun()
-{
- posScale = VertexManager::shiftLookup[m_VtxAttr.PosFrac];
- if( m_components & VB_HAS_UVALL ) {
- for (int i = 0; i < 8; i++) {
- tcScaleU[i] = VertexManager::shiftLookup[m_VtxAttr.texCoord[i].Frac];
- tcScaleV[i] = VertexManager::shiftLookup[m_VtxAttr.texCoord[i].Frac];
- }
- }
- for (int i = 0; i < 2; i++)
- colElements[i] = m_VtxAttr.color[i].Elements;
-}
-
-void VertexLoader::SetupColor(int num, int mode, int format, int elements)
-{
- // if COL0 not present, then embed COL1 into COL0
- if( num == 1 && !(m_components & VB_HAS_COL0) ) num = 0;
-
- m_components |= VB_HAS_COL0 << num;
- switch (mode)
- {
- case NOT_PRESENT:
- m_components &= ~(VB_HAS_COL0 << num);
- break;
- case DIRECT:
- switch (format)
- {
- case FORMAT_16B_565: WriteCall(Color_ReadDirect_16b_565); break;
- case FORMAT_24B_888: WriteCall(Color_ReadDirect_24b_888); break;
- case FORMAT_32B_888x: WriteCall(Color_ReadDirect_32b_888x); break;
- case FORMAT_16B_4444: WriteCall(Color_ReadDirect_16b_4444); break;
- case FORMAT_24B_6666: WriteCall(Color_ReadDirect_24b_6666); break;
- case FORMAT_32B_8888: WriteCall(Color_ReadDirect_32b_8888); break;
- default: _assert_(0); break;
- }
- break;
- case INDEX8:
- switch (format)
- {
- case FORMAT_16B_565: WriteCall(Color_ReadIndex8_16b_565); break;
- case FORMAT_24B_888: WriteCall(Color_ReadIndex8_24b_888); break;
- case FORMAT_32B_888x: WriteCall(Color_ReadIndex8_32b_888x); break;
- case FORMAT_16B_4444: WriteCall(Color_ReadIndex8_16b_4444); break;
- case FORMAT_24B_6666: WriteCall(Color_ReadIndex8_24b_6666); break;
- case FORMAT_32B_8888: WriteCall(Color_ReadIndex8_32b_8888); break;
- default: _assert_(0); break;
- }
- break;
- case INDEX16:
- switch (format)
- {
- case FORMAT_16B_565: WriteCall(Color_ReadIndex16_16b_565); break;
- case FORMAT_24B_888: WriteCall(Color_ReadIndex16_24b_888); break;
- case FORMAT_32B_888x: WriteCall(Color_ReadIndex16_32b_888x); break;
- case FORMAT_16B_4444: WriteCall(Color_ReadIndex16_16b_4444); break;
- case FORMAT_24B_6666: WriteCall(Color_ReadIndex16_24b_6666); break;
- case FORMAT_32B_8888: WriteCall(Color_ReadIndex16_32b_8888); break;
- default: _assert_(0); break;
- }
- break;
- }
-}
-
-void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, int _iFrac)
-{
- m_components |= VB_HAS_UV0 << num;
-
- switch (mode)
- {
- case NOT_PRESENT:
- m_components &= ~(VB_HAS_UV0 << num);
- break;
- case DIRECT:
- switch (format)
- {
- case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadDirect_UByte2:TexCoord_ReadDirect_UByte1); break;
- case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadDirect_Byte2:TexCoord_ReadDirect_Byte1); break;
- case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadDirect_UShort2:TexCoord_ReadDirect_UShort1); break;
- case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadDirect_Short2:TexCoord_ReadDirect_Short1); break;
- case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadDirect_Float2:TexCoord_ReadDirect_Float1); break;
- default: _assert_(0); break;
- }
- break;
- case INDEX8:
- switch (format)
- {
- case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadIndex8_UByte2:TexCoord_ReadIndex8_UByte1); break;
- case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadIndex8_Byte2:TexCoord_ReadIndex8_Byte1); break;
- case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadIndex8_UShort2:TexCoord_ReadIndex8_UShort1); break;
- case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadIndex8_Short2:TexCoord_ReadIndex8_Short1); break;
- case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadIndex8_Float2:TexCoord_ReadIndex8_Float1); break;
- default: _assert_(0); break;
- }
- break;
- case INDEX16:
- switch (format)
- {
- case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadIndex16_UByte2:TexCoord_ReadIndex16_UByte1); break;
- case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadIndex16_Byte2:TexCoord_ReadIndex16_Byte1); break;
- case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadIndex16_UShort2:TexCoord_ReadIndex16_UShort1); break;
- case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadIndex16_Short2:TexCoord_ReadIndex16_Short1); break;
- case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadIndex16_Float2:TexCoord_ReadIndex16_Float1); break;
- default: _assert_(0);
- }
- break;
- }
-}
-
-void VertexLoader::WriteCall(void (LOADERDECL *func)(void *))
-{
- m_PipelineStates[m_numPipelineStates++] = func;;
-}
-
-void VertexLoader::RunVertices(int primitive, int count)
-{
- if( count <= 0 )
- return;
-
- if( fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode )
- VertexManager::Flush();
-
- if( bpmem.genMode.cullmode == 3 && primitive < 5) {
- // if cull mode is none, ignore triangles and quads
- g_pDataReader->Skip(count*m_VertexSize);
- return;
- }
-
- DVSTARTPROFILE();
- ProcessFormat();
-
- fnSetupVertexPointers = (void (*)())(void*)m_compiledCode;
-
- if (s_prevcomponents != m_components) {
-
- VertexManager::Flush();
-
- // matrices
- if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents&VB_HAS_POSMTXIDX)) {
- if (m_components & VB_HAS_POSMTXIDX)
- glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
- else
- glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
- }
-
- // normals
- if ((m_components & VB_HAS_NRM0) != (s_prevcomponents&VB_HAS_NRM0)) {
- if (m_components & VB_HAS_NRM0)
- glEnableClientState(GL_NORMAL_ARRAY);
- else
- glDisableClientState(GL_NORMAL_ARRAY);
- }
- if ((m_components & VB_HAS_NRM1) != (s_prevcomponents&VB_HAS_NRM1)) {
- if (m_components & VB_HAS_NRM1) {
- glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
- glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
- }
- else {
- glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
- glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
- }
- }
-
- // color
- for(int i = 0; i < 2; ++i) {
- if ( (m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i)) ) {
- if (m_components & (VB_HAS_COL0 << 0))
- glEnableClientState(i?GL_SECONDARY_COLOR_ARRAY:GL_COLOR_ARRAY);
- else
- glDisableClientState(i?GL_SECONDARY_COLOR_ARRAY:GL_COLOR_ARRAY);
- }
- }
-
- // tex
- for (int i = 0; i < 8; ++i) {
- if ((m_components&(VB_HAS_UV0< 0 )
- VertexManager::AddVertices(primitive, v-startv+extraverts);
- VertexManager::Flush();
-
- switch( primitive ) {
- case 3: // triangle strip, copy last two vertices
-
- // a little trick since we have to keep track of signs
- if( v & 1 ) {
- memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-2*m_VBVertexStride, m_VBVertexStride);
- memcpy_gc(VertexManager::s_pCurBufferPointer+m_VBVertexStride, plastptr-m_VBVertexStride*2, 2*m_VBVertexStride);
- VertexManager::s_pCurBufferPointer += m_VBVertexStride*3;
- extraverts = 3;
- }
- else {
- memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride*2, m_VBVertexStride*2);
- VertexManager::s_pCurBufferPointer += m_VBVertexStride*2;
- extraverts = 2;
- }
- break;
- case 4: // tri fan, copy first and last vert
- memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride*(v-startv+extraverts), m_VBVertexStride);
- VertexManager::s_pCurBufferPointer += m_VBVertexStride;
- memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride, m_VBVertexStride);
- VertexManager::s_pCurBufferPointer += m_VBVertexStride;
- extraverts = 2;
- break;
- case 6: // line strip
- memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride, m_VBVertexStride);
- VertexManager::s_pCurBufferPointer += m_VBVertexStride;
- extraverts = 1;
- break;
- default:
- extraverts = 0;
- }
-
- startv = v;
- }
- }
-
- tcIndex = 0;
- colIndex = 0;
- s_texmtxwrite = s_texmtxread = 0;
- for (int i = 0; i < m_numPipelineStates; i++)
- m_PipelineStates[i](&m_VtxAttr);
- VertexManager::s_pCurBufferPointer += m_VBStridePad;
- PRIM_LOG("\n");
- }
-
- if( startv < count )
- VertexManager::AddVertices(primitive, count-startv+extraverts);
-}
-
-///////////////////
-// VertexManager //
-///////////////////
-
-TVtxDesc VertexManager::s_GlobalVtxDesc;
-u8* VertexManager::s_pCurBufferPointer=NULL;
-float VertexManager::shiftLookup[32];
-
-const GLenum c_primitiveType[8] =
-{
- GL_QUADS,
- 0, //nothing
- GL_TRIANGLES,
- GL_TRIANGLE_STRIP,
- GL_TRIANGLE_FAN,
- GL_LINES,
- GL_LINE_STRIP,
- GL_POINTS
-};
-
-bool VertexManager::Init()
-{
- Destroy();
-
- s_GlobalVtxDesc.Hex = 0;
- s_prevcomponents = 0;
- s_prevvbstride = 12; // just pos
- s_prevprimitive = 0;
- s_pBaseBufferPointer = (u8*)_aligned_malloc(MAX_BUFFER_SIZE, 256);
- s_pCurBufferPointer = s_pBaseBufferPointer;
-
- for (int i = 0; i < ARRAYSIZE(shiftLookup); i++)
- shiftLookup[i] = 1.0f / float(1 << i);
-
- s_nCurVBOIndex = 0;
- glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
- for (int i = 0; i < ARRAYSIZE(s_vboBuffers); ++i) {
- glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[i]);
- glBufferData(GL_ARRAY_BUFFER, MAX_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
- }
-
- glEnableClientState(GL_VERTEX_ARRAY);
- fnSetupVertexPointers = NULL;
- GL_REPORT_ERRORD();
-
- return true;
-}
-
-void VertexManager::Destroy()
-{
- _aligned_free(s_pBaseBufferPointer); s_pBaseBufferPointer = s_pCurBufferPointer = NULL;
- glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
- memset(s_vboBuffers, 0, sizeof(s_vboBuffers));
-
- s_vStoredPrimitives.resize(0);
- s_nCurVBOIndex = 0;
- ResetBuffer();
-}
-
-void VertexManager::ResetBuffer()
-{
- s_nCurVBOIndex = (s_nCurVBOIndex+1)%ARRAYSIZE(s_vboBuffers);
- s_pCurBufferPointer = s_pBaseBufferPointer;
- s_vStoredPrimitives.resize(0);
-}
-
-void VertexManager::ResetComponents()
-{
- s_prevcomponents = 0;
- s_prevvbstride = 12; // just pos
- s_prevprimitive = 0;
- glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
- glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
- for (int i = 0; i < 8; ++i) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-}
-
-int VertexManager::GetRemainingSize()
-{
- return MAX_BUFFER_SIZE - (int)(s_pCurBufferPointer-s_pBaseBufferPointer);
-}
-
-void VertexManager::AddVertices(int primitive, int numvertices)
-{
- _assert_( numvertices > 0 );
-
- ADDSTAT(stats.thisFrame.numPrims, numvertices);
- s_vStoredPrimitives.push_back(pair(c_primitiveType[primitive], numvertices));
-
- static const char *sprims[8] = {"quads", "nothing", "tris", "tstrip", "tfan", "lines", "lstrip", "points"};
- PRIM_LOG("prim: %s, c=%d\n", sprims[primitive], numvertices);
-}
-
-void VertexManager::Flush()
-{
- if (s_vStoredPrimitives.size() == 0)
- return;
-
- _assert_( fnSetupVertexPointers != NULL );
- _assert_( s_pCurBufferPointer != s_pBaseBufferPointer );
-
-#ifdef _DEBUG
- PRIM_LOG("frame%d:\ncomps=0x%x, texgen=%d, numchan=%d, dualtex=%d, ztex=%d, proj=%d, cole=%d, alpe=%d, ze=%d\n", g_Config.iSaveTargetId, s_prevcomponents, xfregs.numTexGens,
- xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op, VertexShaderMngr::rawProjection[6]==0,
- bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable);
- for(int i = 0; i < xfregs.nNumChans; ++i) {
- LitChannel* ch = &xfregs.colChans[i].color;
- PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
- ch = &xfregs.colChans[i].alpha;
- PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
- }
- for(int i = 0; i < xfregs.numTexGens; ++i) {
- TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
- if( tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff;
- if( tinfo.texgentype != XF_TEXGEN_REGULAR ) tinfo.projection = 0;
-
- PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d\n",
- i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift,
- xfregs.texcoords[i].postmtxinfo.index, xfregs.texcoords[i].postmtxinfo.normalize);
- }
-
- PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphafunc=0x%x\n", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,
- bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alphaFunc.hex>>16)&0xff);
-#endif
-
- DVSTARTPROFILE();
-
- GL_REPORT_ERRORD();
-
- glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[s_nCurVBOIndex]);
- glBufferData(GL_ARRAY_BUFFER, s_pCurBufferPointer-s_pBaseBufferPointer, s_pBaseBufferPointer, GL_STREAM_DRAW);
- GL_REPORT_ERRORD();
-
- // setup the pointers
- fnSetupVertexPointers();
- GL_REPORT_ERRORD();
-
- // set the textures
- {
- DVProfileFunc _pf("VertexManager::Flush:textures");
-
- u32 usedtextures = 0;
- for (u32 i = 0; i < bpmem.genMode.numtevstages+1; ++i) {
- if( bpmem.tevorders[i/2].getEnable(i&1) )
- usedtextures |= 1< 0 ) {
- for(u32 i = 0; i < bpmem.genMode.numtevstages+1; ++i) {
- if( bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages ) {
- usedtextures |= 1<>2];
- TextureMngr::TCacheEntry* tentry = TextureMngr::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
- tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
- tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, tex.texTlut[i&3].tlut_format);
-
- if( tentry != NULL ) {
- // texture loaded fine, set dims for pixel shader
- if( tentry->isNonPow2 ) {
- PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, tentry->mode.wrap_s, tentry->mode.wrap_t);
- nonpow2tex |= 1<mode.wrap_s > 0 ) nonpow2tex |= 1<<(8+i);
- if( tentry->mode.wrap_t > 0 ) nonpow2tex |= 1<<(16+i);
- }
- // if texture is power of two, set to ones (since don't need scaling)
- else PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, 0, 0);
-
- if( tentry->isNonPow2 ) TextureMngr::EnableTexRECT(i);
- else TextureMngr::EnableTex2D(i);
-
- if( g_Config.iLog & CONF_PRIMLOG ) {
- // save the textures
- char strfile[255];
- sprintf(strfile, "frames/tex%.3d_%d.tga", g_Config.iSaveTargetId, i);
- SaveTexture(strfile, tentry->isNonPow2?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D, tentry->texture, tentry->w, tentry->h);
- }
- }
- else {
- ERROR_LOG("error loading tex\n");
- TextureMngr::DisableStage(i); // disable since won't be used
- }
- }
- else {
- TextureMngr::DisableStage(i); // disable since won't be used
- }
- }
-
- PixelShaderMngr::SetTexturesUsed(nonpow2tex);
- }
-
- FRAGMENTSHADER* ps = PixelShaderMngr::GetShader();
- VERTEXSHADER* vs = VertexShaderMngr::GetShader(s_prevcomponents);
- _assert_( ps != NULL && vs != NULL );
-
- bool bRestoreBuffers = false;
- if( Renderer::GetZBufferTarget() ) {
- if( bpmem.zmode.updateenable ) {
- if( !bpmem.blendmode.colorupdate ) {
- Renderer::SetRenderMode(bpmem.blendmode.alphaupdate?Renderer::RM_ZBufferAlpha:Renderer::RM_ZBufferOnly);
- }
- }
- else {
- Renderer::SetRenderMode(Renderer::RM_Normal);
- // remove temporarily
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
- bRestoreBuffers = true;
- }
- }
- else
- Renderer::SetRenderMode(Renderer::RM_Normal);
-
- // set global constants
- VertexShaderMngr::SetConstants(*vs);
- PixelShaderMngr::SetConstants(*ps);
-
- // finally bind
- glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid);
- glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid);
-
- PRIM_LOG("\n");
-
- int offset = 0;
- vector< pair >::iterator it;
- FORIT (it, s_vStoredPrimitives) {
- glDrawArrays(it->first, offset, it->second);
- offset += it->second;
- }
-
-#ifdef _DEBUG
- if( g_Config.iLog & CONF_PRIMLOG ) {
- // save the shaders
- char strfile[255];
- sprintf(strfile, "frames/ps%.3d.txt", g_Config.iSaveTargetId);
- std::ofstream fps(strfile);
- fps << ps->strprog.c_str();
- sprintf(strfile, "frames/vs%.3d.txt", g_Config.iSaveTargetId);
- ofstream fvs(strfile);
- fvs << vs->strprog.c_str();
- }
-
- if( g_Config.iLog & CONF_SAVETARGETS ) {
- char str[128];
- sprintf(str, "frames/targ%.3d.tga", g_Config.iSaveTargetId);
- Renderer::SaveRenderTarget(str, 0);
- }
-#endif
- g_Config.iSaveTargetId++;
-
- GL_REPORT_ERRORD();
-
- if( bRestoreBuffers ) {
- GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
- glDrawBuffers(2, s_drawbuffers);
- SetColorMask();
- }
-
- ResetBuffer();
-}
-
-void VertexManager::LoadCPReg(u32 SubCmd, u32 Value)
-{
- switch (SubCmd & 0xF0)
- {
- case 0x30:
- VertexShaderMngr::SetTexMatrixChangedA(Value);
- break;
- case 0x40:
- VertexShaderMngr::SetTexMatrixChangedB(Value);
- break;
-
- case 0x50:
- s_GlobalVtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits
- s_GlobalVtxDesc.Hex |= Value;
- break;
- case 0x60:
- s_GlobalVtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits
- s_GlobalVtxDesc.Hex |= (u64)Value << 17;
- break;
-
- case 0x70: g_VertexLoaders[SubCmd & 7].SetVAT_group0(Value); _assert_((SubCmd & 0x0F) < 8); break;
- case 0x80: g_VertexLoaders[SubCmd & 7].SetVAT_group1(Value); _assert_((SubCmd & 0x0F) < 8); break;
- case 0x90: g_VertexLoaders[SubCmd & 7].SetVAT_group2(Value); _assert_((SubCmd & 0x0F) < 8); break;
-
- case 0xA0: arraybases[SubCmd & 0xF] = Value & 0xFFFFFFFF; break;
- case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break;
- }
-}
-
-size_t VertexManager::SaveLoadState(char *ptr, BOOL save)
-{
- BEGINSAVELOAD;
- SAVELOAD(arraybases,16*sizeof(u32));
- SAVELOAD(arraystrides,16*sizeof(u32));
- ENDSAVELOAD;
-}
-
+#include "Globals.h"
+#include
+#include
+
+#include "x64Emitter.h"
+
+#include "VertexLoader.h"
+#include "BPStructs.h"
+#include "DataReader.h"
+
+#include "VertexShader.h"
+#include "PixelShader.h"
+#include "TextureMngr.h"
+
+#include "MemoryUtil.h"
+
+#include
+
+#define MAX_BUFFER_SIZE 0x4000
+
+
+// internal state for loading vertices
+static u32 s_prevvbstride, s_prevcomponents; // previous state set
+static u8 *s_pBaseBufferPointer = NULL;
+static GLuint s_vboBuffers[0x40] = {0};
+static int s_nCurVBOIndex = 0; // current free buffer
+static GLenum s_prevprimitive = 0; // current primitive type
+static vector< pair > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays
+static void (*fnSetupVertexPointers)() = NULL;
+
+//these don't need to be saved
+float posScale;
+float tcScale[8];
+int colElements[2];
+float tcScaleU[8];
+float tcScaleV[8];
+int tcIndex;
+int colIndex;
+
+inline u8 ReadBuffer8()
+{
+ return g_pDataReader->Read8();
+}
+
+inline u16 ReadBuffer16()
+{
+ //PowerPC byte ordering :(
+ return g_pDataReader->Read16();
+}
+
+inline u32 ReadBuffer32()
+{
+ //PowerPC byte ordering :(
+ return g_pDataReader->Read32();
+}
+
+inline float ReadBuffer32F()
+{
+ u32 temp = g_pDataReader->Read32();
+ return *(float*)(&temp);
+}
+
+// ==============================================================================
+// Direct
+// ==============================================================================
+static u8 s_curposmtx, s_curtexmtx[8];
+static int s_texmtxwrite = 0, s_texmtxread = 0;
+
+void LOADERDECL PosMtx_ReadDirect_UByte(void* _p)
+{
+ s_curposmtx = ReadBuffer8()&0x3f;
+ PRIM_LOG("posmtx: %d, ", s_curposmtx);
+}
+
+void LOADERDECL PosMtx_Write(void* _p)
+{
+ *VertexManager::s_pCurBufferPointer++ = s_curposmtx;
+ //*VertexManager::s_pCurBufferPointer++ = 0;
+ //*VertexManager::s_pCurBufferPointer++ = 0;
+ //*VertexManager::s_pCurBufferPointer++ = 0;
+}
+
+void LOADERDECL TexMtx_ReadDirect_UByte(void* _p)
+{
+ s_curtexmtx[s_texmtxread] = ReadBuffer8()&0x3f;
+ PRIM_LOG("texmtx%d: %d, ", s_texmtxread, s_curtexmtx[s_texmtxread]);
+ s_texmtxread++;
+}
+
+void LOADERDECL TexMtx_Write_Float(void* _p)
+{
+ *(float*)VertexManager::s_pCurBufferPointer = (float)s_curtexmtx[s_texmtxwrite++];
+ VertexManager::s_pCurBufferPointer += 4;
+}
+
+void LOADERDECL TexMtx_Write_Float2(void* _p)
+{
+ ((float*)VertexManager::s_pCurBufferPointer)[0] = 0;
+ ((float*)VertexManager::s_pCurBufferPointer)[1] = (float)s_curtexmtx[s_texmtxwrite++];
+ VertexManager::s_pCurBufferPointer += 8;
+}
+
+void LOADERDECL TexMtx_Write_Short3(void* _p)
+{
+ ((s16*)VertexManager::s_pCurBufferPointer)[0] = 0;
+ ((s16*)VertexManager::s_pCurBufferPointer)[1] = 0;
+ ((s16*)VertexManager::s_pCurBufferPointer)[2] = s_curtexmtx[s_texmtxwrite++];
+ VertexManager::s_pCurBufferPointer += 6;
+}
+
+#include "VertexLoader_Position.h"
+#include "VertexLoader_Normal.h"
+#include "VertexLoader_Color.h"
+#include "VertexLoader_TextCoord.h"
+
+VertexLoader g_VertexLoaders[8];
+
+#define COMPILED_CODE_SIZE 4096
+
+VertexLoader::VertexLoader()
+{
+ m_numPipelineStates = 0;
+ m_VertexSize = 0;
+ m_AttrDirty = 2;
+ VertexLoader_Normal::Init();
+
+ m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE);
+ if (m_compiledCode) {
+ memset(m_compiledCode, 0, COMPILED_CODE_SIZE);
+ }
+}
+
+VertexLoader::~VertexLoader()
+{
+ FreeMemoryPages(m_compiledCode, COMPILED_CODE_SIZE);
+}
+
+int VertexLoader::ComputeVertexSize()
+{
+ if (m_AttrDirty < 2) {
+
+ if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
+ return m_VertexSize;
+
+ m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
+ }
+ else {
+ // set anyway
+ m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
+ }
+
+ if( fnSetupVertexPointers != NULL && fnSetupVertexPointers == (void (*)())(void*)m_compiledCode )
+ VertexManager::Flush();
+
+ m_AttrDirty = 1;
+ m_VertexSize = 0;
+ // Position Matrix Index
+ if (m_VtxDesc.PosMatIdx)
+ m_VertexSize += 1;
+
+ // Texture matrix indices
+ if (m_VtxDesc.Tex0MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex1MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex2MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex3MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex4MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex5MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex6MatIdx) {m_VertexSize+=1; }
+ if (m_VtxDesc.Tex7MatIdx) {m_VertexSize+=1; }
+
+ switch (m_VtxDesc.Position) {
+ case NOT_PRESENT: {_assert_("Vertex descriptor without position!");} break;
+ case DIRECT:
+ {
+ switch (m_VtxAttr.PosFormat) {
+ case FORMAT_UBYTE:
+ case FORMAT_BYTE: m_VertexSize += m_VtxAttr.PosElements?3:2; break;
+ case FORMAT_USHORT:
+ case FORMAT_SHORT: m_VertexSize += m_VtxAttr.PosElements?6:4; break;
+ case FORMAT_FLOAT: m_VertexSize += m_VtxAttr.PosElements?12:8; break;
+ default: _assert_(0); break;
+ }
+ }
+ break;
+ case INDEX8:
+ m_VertexSize+=1;
+ break;
+ case INDEX16:
+ m_VertexSize+=2;
+ break;
+ }
+
+ if (m_VtxDesc.Normal != NOT_PRESENT)
+ m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
+
+ // Colors
+ int col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1};
+ for (int i = 0; i < 2; i++) {
+ switch (col[i])
+ {
+ case NOT_PRESENT:
+ break;
+ case DIRECT:
+ switch (m_VtxAttr.color[i].Comp)
+ {
+ case FORMAT_16B_565: m_VertexSize+=2; break;
+ case FORMAT_24B_888: m_VertexSize+=3; break;
+ case FORMAT_32B_888x: m_VertexSize+=4; break;
+ case FORMAT_16B_4444: m_VertexSize+=2; break;
+ case FORMAT_24B_6666: m_VertexSize+=3; break;
+ case FORMAT_32B_8888: m_VertexSize+=4; break;
+ default: _assert_(0); break;
+ }
+ break;
+ case INDEX8:
+ m_VertexSize+=1;
+ break;
+ case INDEX16:
+ m_VertexSize+=2;
+ break;
+ }
+ }
+
+ // TextureCoord
+ int tc[8] = {
+ m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, m_VtxDesc.Tex3Coord,
+ m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord,
+ };
+
+ for (int i = 0; i < 8; i++) {
+ switch (tc[i]) {
+ case NOT_PRESENT:
+ break;
+ case DIRECT:
+ {
+ switch (m_VtxAttr.texCoord[i].Format)
+ {
+ case FORMAT_UBYTE:
+ case FORMAT_BYTE: m_VertexSize += m_VtxAttr.texCoord[i].Elements?2:1; break;
+ case FORMAT_USHORT:
+ case FORMAT_SHORT: m_VertexSize += m_VtxAttr.texCoord[i].Elements?4:2; break;
+ case FORMAT_FLOAT: m_VertexSize += m_VtxAttr.texCoord[i].Elements?8:4; break;
+ default: _assert_(0); break;
+ }
+ }
+ break;
+ case INDEX8:
+ m_VertexSize+=1;
+ break;
+ case INDEX16:
+ m_VertexSize+=2;
+ break;
+ }
+ }
+
+ return m_VertexSize;
+}
+
+
+// Note the use of CallCdeclFunction3I etc.
+// This is a horrible hack that is necessary because Opengl32.dll is based way, way above the 32-bit address space
+// that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we want to grab
+// the function pointers from the import table instead.
+
+// This problem does not apply to glew functions, only core opengl32 functions.
+
+DECLARE_IMPORT(glNormalPointer);
+DECLARE_IMPORT(glVertexPointer);
+DECLARE_IMPORT(glColorPointer);
+DECLARE_IMPORT(glTexCoordPointer);
+
+void VertexLoader::ProcessFormat()
+{
+ using namespace Gen;
+
+ //_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer );
+
+ if (!m_AttrDirty ) {
+
+ if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1&1)==(VertexManager::GetVtxDesc().Hex1&1))
+ // same
+ return;
+
+ m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
+ }
+ else {
+ // set anyway
+ m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
+ m_AttrDirty = 0;
+ }
+
+ DVSTARTPROFILE();
+
+ // Reset pipeline
+ m_VBStridePad = 0;
+ m_VBVertexStride = 0;
+ m_numPipelineStates = 0;
+ m_components = 0;
+
+ // m_VBVertexStride for texmtx and posmtx is computed later when writing
+
+ // Position Matrix Index
+ if (m_VtxDesc.PosMatIdx) {
+ m_PipelineStates[m_numPipelineStates++] = PosMtx_ReadDirect_UByte;
+ m_components |= VB_HAS_POSMTXIDX;
+ }
+
+ if (m_VtxDesc.Tex0MatIdx) {m_components|=VB_HAS_TEXMTXIDX0; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex1MatIdx) {m_components|=VB_HAS_TEXMTXIDX1; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex2MatIdx) {m_components|=VB_HAS_TEXMTXIDX2; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex3MatIdx) {m_components|=VB_HAS_TEXMTXIDX3; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex4MatIdx) {m_components|=VB_HAS_TEXMTXIDX4; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex5MatIdx) {m_components|=VB_HAS_TEXMTXIDX5; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex6MatIdx) {m_components|=VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); }
+ if (m_VtxDesc.Tex7MatIdx) {m_components|=VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); }
+
+ // Position
+ if (m_VtxDesc.Position != NOT_PRESENT)
+ m_VBVertexStride += 12;
+
+ switch (m_VtxDesc.Position) {
+ case NOT_PRESENT: {_assert_msg_(0,"Vertex descriptor without position!","WTF?");} break;
+ case DIRECT:
+ {
+ switch (m_VtxAttr.PosFormat) {
+ case FORMAT_UBYTE: WriteCall(Pos_ReadDirect_UByte); break;
+ case FORMAT_BYTE: WriteCall(Pos_ReadDirect_Byte); break;
+ case FORMAT_USHORT: WriteCall(Pos_ReadDirect_UShort); break;
+ case FORMAT_SHORT: WriteCall(Pos_ReadDirect_Short); break;
+ case FORMAT_FLOAT: WriteCall(Pos_ReadDirect_Float); break;
+ default: _assert_(0); break;
+ }
+ }
+ break;
+ case INDEX8:
+ switch (m_VtxAttr.PosFormat) {
+ case FORMAT_UBYTE: WriteCall(Pos_ReadIndex8_UByte); break; //WTF?
+ case FORMAT_BYTE: WriteCall(Pos_ReadIndex8_Byte); break;
+ case FORMAT_USHORT: WriteCall(Pos_ReadIndex8_UShort); break;
+ case FORMAT_SHORT: WriteCall(Pos_ReadIndex8_Short); break;
+ case FORMAT_FLOAT: WriteCall(Pos_ReadIndex8_Float); break;
+ default: _assert_(0); break;
+ }
+ break;
+ case INDEX16:
+ switch (m_VtxAttr.PosFormat) {
+ case FORMAT_UBYTE: WriteCall(Pos_ReadIndex16_UByte); break;
+ case FORMAT_BYTE: WriteCall(Pos_ReadIndex16_Byte); break;
+ case FORMAT_USHORT: WriteCall(Pos_ReadIndex16_UShort); break;
+ case FORMAT_SHORT: WriteCall(Pos_ReadIndex16_Short); break;
+ case FORMAT_FLOAT: WriteCall(Pos_ReadIndex16_Float); break;
+ default: _assert_(0); break;
+ }
+ break;
+ }
+
+ // Normals
+ if (m_VtxDesc.Normal != NOT_PRESENT) {
+ VertexLoader_Normal::index3 = m_VtxAttr.NormalIndex3 ? true : false;
+ unsigned int uSize = VertexLoader_Normal::GetSize(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
+ TPipelineFunction pFunc = VertexLoader_Normal::GetFunction(m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
+ if (pFunc == 0)
+ {
+ char temp[256];
+ sprintf(temp,"%i %i %i", m_VtxDesc.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements);
+ SysMessage("VertexLoader_Normal::GetFunction returned zero!");
+ }
+ WriteCall(pFunc);
+
+ int sizePro=0;
+ switch (m_VtxAttr.NormalFormat)
+ {
+ case FORMAT_UBYTE: sizePro=1; break;
+ case FORMAT_BYTE: sizePro=1; break;
+ case FORMAT_USHORT: sizePro=2; break;
+ case FORMAT_SHORT: sizePro=2; break;
+ case FORMAT_FLOAT: sizePro=4; break;
+ default: _assert_(0); break;
+ }
+ m_VBVertexStride += sizePro * 3 * (m_VtxAttr.NormalElements?3:1);
+
+ int m_numNormals = (m_VtxAttr.NormalElements==1) ? NRM_THREE : NRM_ONE;
+ m_components |= VB_HAS_NRM0;
+ if (m_numNormals == NRM_THREE)
+ m_components |= VB_HAS_NRM1 | VB_HAS_NRM2;
+ }
+
+ // Colors
+ int col[2] = {m_VtxDesc.Color0, m_VtxDesc.Color1};
+ for (int i = 0; i < 2; i++) {
+ SetupColor(i,col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
+
+ if (col[i] != NOT_PRESENT )
+ m_VBVertexStride+=4;
+ }
+
+ // TextureCoord
+ int tc[8] = {
+ m_VtxDesc.Tex0Coord, m_VtxDesc.Tex1Coord, m_VtxDesc.Tex2Coord, m_VtxDesc.Tex3Coord,
+ m_VtxDesc.Tex4Coord, m_VtxDesc.Tex5Coord, m_VtxDesc.Tex6Coord, m_VtxDesc.Tex7Coord,
+ };
+
+ // Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
+ for (int i = 0; i < 8; i++) {
+ SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac);
+
+ if( m_components&(VB_HAS_TEXMTXIDX0< COMPILED_CODE_SIZE)
+ {
+ assert(0);
+ Crash();
+ }
+
+ SetCodePtr(0);
+}
+
+void VertexLoader::PrepareRun()
+{
+ posScale = VertexManager::shiftLookup[m_VtxAttr.PosFrac];
+ if( m_components & VB_HAS_UVALL ) {
+ for (int i = 0; i < 8; i++) {
+ tcScaleU[i] = VertexManager::shiftLookup[m_VtxAttr.texCoord[i].Frac];
+ tcScaleV[i] = VertexManager::shiftLookup[m_VtxAttr.texCoord[i].Frac];
+ }
+ }
+ for (int i = 0; i < 2; i++)
+ colElements[i] = m_VtxAttr.color[i].Elements;
+}
+
+void VertexLoader::SetupColor(int num, int mode, int format, int elements)
+{
+ // if COL0 not present, then embed COL1 into COL0
+ if( num == 1 && !(m_components & VB_HAS_COL0) ) num = 0;
+
+ m_components |= VB_HAS_COL0 << num;
+ switch (mode)
+ {
+ case NOT_PRESENT:
+ m_components &= ~(VB_HAS_COL0 << num);
+ break;
+ case DIRECT:
+ switch (format)
+ {
+ case FORMAT_16B_565: WriteCall(Color_ReadDirect_16b_565); break;
+ case FORMAT_24B_888: WriteCall(Color_ReadDirect_24b_888); break;
+ case FORMAT_32B_888x: WriteCall(Color_ReadDirect_32b_888x); break;
+ case FORMAT_16B_4444: WriteCall(Color_ReadDirect_16b_4444); break;
+ case FORMAT_24B_6666: WriteCall(Color_ReadDirect_24b_6666); break;
+ case FORMAT_32B_8888: WriteCall(Color_ReadDirect_32b_8888); break;
+ default: _assert_(0); break;
+ }
+ break;
+ case INDEX8:
+ switch (format)
+ {
+ case FORMAT_16B_565: WriteCall(Color_ReadIndex8_16b_565); break;
+ case FORMAT_24B_888: WriteCall(Color_ReadIndex8_24b_888); break;
+ case FORMAT_32B_888x: WriteCall(Color_ReadIndex8_32b_888x); break;
+ case FORMAT_16B_4444: WriteCall(Color_ReadIndex8_16b_4444); break;
+ case FORMAT_24B_6666: WriteCall(Color_ReadIndex8_24b_6666); break;
+ case FORMAT_32B_8888: WriteCall(Color_ReadIndex8_32b_8888); break;
+ default: _assert_(0); break;
+ }
+ break;
+ case INDEX16:
+ switch (format)
+ {
+ case FORMAT_16B_565: WriteCall(Color_ReadIndex16_16b_565); break;
+ case FORMAT_24B_888: WriteCall(Color_ReadIndex16_24b_888); break;
+ case FORMAT_32B_888x: WriteCall(Color_ReadIndex16_32b_888x); break;
+ case FORMAT_16B_4444: WriteCall(Color_ReadIndex16_16b_4444); break;
+ case FORMAT_24B_6666: WriteCall(Color_ReadIndex16_24b_6666); break;
+ case FORMAT_32B_8888: WriteCall(Color_ReadIndex16_32b_8888); break;
+ default: _assert_(0); break;
+ }
+ break;
+ }
+}
+
+void VertexLoader::SetupTexCoord(int num, int mode, int format, int elements, int _iFrac)
+{
+ m_components |= VB_HAS_UV0 << num;
+
+ switch (mode)
+ {
+ case NOT_PRESENT:
+ m_components &= ~(VB_HAS_UV0 << num);
+ break;
+ case DIRECT:
+ switch (format)
+ {
+ case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadDirect_UByte2:TexCoord_ReadDirect_UByte1); break;
+ case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadDirect_Byte2:TexCoord_ReadDirect_Byte1); break;
+ case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadDirect_UShort2:TexCoord_ReadDirect_UShort1); break;
+ case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadDirect_Short2:TexCoord_ReadDirect_Short1); break;
+ case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadDirect_Float2:TexCoord_ReadDirect_Float1); break;
+ default: _assert_(0); break;
+ }
+ break;
+ case INDEX8:
+ switch (format)
+ {
+ case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadIndex8_UByte2:TexCoord_ReadIndex8_UByte1); break;
+ case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadIndex8_Byte2:TexCoord_ReadIndex8_Byte1); break;
+ case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadIndex8_UShort2:TexCoord_ReadIndex8_UShort1); break;
+ case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadIndex8_Short2:TexCoord_ReadIndex8_Short1); break;
+ case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadIndex8_Float2:TexCoord_ReadIndex8_Float1); break;
+ default: _assert_(0); break;
+ }
+ break;
+ case INDEX16:
+ switch (format)
+ {
+ case FORMAT_UBYTE: WriteCall(elements?TexCoord_ReadIndex16_UByte2:TexCoord_ReadIndex16_UByte1); break;
+ case FORMAT_BYTE: WriteCall(elements?TexCoord_ReadIndex16_Byte2:TexCoord_ReadIndex16_Byte1); break;
+ case FORMAT_USHORT: WriteCall(elements?TexCoord_ReadIndex16_UShort2:TexCoord_ReadIndex16_UShort1); break;
+ case FORMAT_SHORT: WriteCall(elements?TexCoord_ReadIndex16_Short2:TexCoord_ReadIndex16_Short1); break;
+ case FORMAT_FLOAT: WriteCall(elements?TexCoord_ReadIndex16_Float2:TexCoord_ReadIndex16_Float1); break;
+ default: _assert_(0);
+ }
+ break;
+ }
+}
+
+void VertexLoader::WriteCall(void (LOADERDECL *func)(void *))
+{
+ m_PipelineStates[m_numPipelineStates++] = func;;
+}
+
+void VertexLoader::RunVertices(int primitive, int count)
+{
+ if( count <= 0 )
+ return;
+
+ if( fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode )
+ VertexManager::Flush();
+
+ if( bpmem.genMode.cullmode == 3 && primitive < 5) {
+ // if cull mode is none, ignore triangles and quads
+ g_pDataReader->Skip(count*m_VertexSize);
+ return;
+ }
+
+ DVSTARTPROFILE();
+ ProcessFormat();
+
+ fnSetupVertexPointers = (void (*)())(void*)m_compiledCode;
+
+ if (s_prevcomponents != m_components) {
+
+ VertexManager::Flush();
+
+ // matrices
+ if ((m_components & VB_HAS_POSMTXIDX) != (s_prevcomponents&VB_HAS_POSMTXIDX)) {
+ if (m_components & VB_HAS_POSMTXIDX)
+ glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
+ else
+ glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
+ }
+
+ // normals
+ if ((m_components & VB_HAS_NRM0) != (s_prevcomponents&VB_HAS_NRM0)) {
+ if (m_components & VB_HAS_NRM0)
+ glEnableClientState(GL_NORMAL_ARRAY);
+ else
+ glDisableClientState(GL_NORMAL_ARRAY);
+ }
+ if ((m_components & VB_HAS_NRM1) != (s_prevcomponents&VB_HAS_NRM1)) {
+ if (m_components & VB_HAS_NRM1) {
+ glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
+ glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
+ }
+ else {
+ glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
+ glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
+ }
+ }
+
+ // color
+ for(int i = 0; i < 2; ++i) {
+ if ( (m_components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i)) ) {
+ if (m_components & (VB_HAS_COL0 << 0))
+ glEnableClientState(i?GL_SECONDARY_COLOR_ARRAY:GL_COLOR_ARRAY);
+ else
+ glDisableClientState(i?GL_SECONDARY_COLOR_ARRAY:GL_COLOR_ARRAY);
+ }
+ }
+
+ // tex
+ for (int i = 0; i < 8; ++i) {
+ if ((m_components&(VB_HAS_UV0< 0 )
+ VertexManager::AddVertices(primitive, v-startv+extraverts);
+ VertexManager::Flush();
+
+ switch( primitive ) {
+ case 3: // triangle strip, copy last two vertices
+
+ // a little trick since we have to keep track of signs
+ if( v & 1 ) {
+ memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-2*m_VBVertexStride, m_VBVertexStride);
+ memcpy_gc(VertexManager::s_pCurBufferPointer+m_VBVertexStride, plastptr-m_VBVertexStride*2, 2*m_VBVertexStride);
+ VertexManager::s_pCurBufferPointer += m_VBVertexStride*3;
+ extraverts = 3;
+ }
+ else {
+ memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride*2, m_VBVertexStride*2);
+ VertexManager::s_pCurBufferPointer += m_VBVertexStride*2;
+ extraverts = 2;
+ }
+ break;
+ case 4: // tri fan, copy first and last vert
+ memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride*(v-startv+extraverts), m_VBVertexStride);
+ VertexManager::s_pCurBufferPointer += m_VBVertexStride;
+ memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride, m_VBVertexStride);
+ VertexManager::s_pCurBufferPointer += m_VBVertexStride;
+ extraverts = 2;
+ break;
+ case 6: // line strip
+ memcpy_gc(VertexManager::s_pCurBufferPointer, plastptr-m_VBVertexStride, m_VBVertexStride);
+ VertexManager::s_pCurBufferPointer += m_VBVertexStride;
+ extraverts = 1;
+ break;
+ default:
+ extraverts = 0;
+ }
+
+ startv = v;
+ }
+ }
+
+ tcIndex = 0;
+ colIndex = 0;
+ s_texmtxwrite = s_texmtxread = 0;
+ for (int i = 0; i < m_numPipelineStates; i++)
+ m_PipelineStates[i](&m_VtxAttr);
+ VertexManager::s_pCurBufferPointer += m_VBStridePad;
+ PRIM_LOG("\n");
+ }
+
+ if( startv < count )
+ VertexManager::AddVertices(primitive, count-startv+extraverts);
+}
+
+///////////////////
+// VertexManager //
+///////////////////
+
+TVtxDesc VertexManager::s_GlobalVtxDesc;
+u8* VertexManager::s_pCurBufferPointer=NULL;
+float VertexManager::shiftLookup[32];
+
+const GLenum c_primitiveType[8] =
+{
+ GL_QUADS,
+ 0, //nothing
+ GL_TRIANGLES,
+ GL_TRIANGLE_STRIP,
+ GL_TRIANGLE_FAN,
+ GL_LINES,
+ GL_LINE_STRIP,
+ GL_POINTS
+};
+
+bool VertexManager::Init()
+{
+ Destroy();
+
+ s_GlobalVtxDesc.Hex = 0;
+ s_prevcomponents = 0;
+ s_prevvbstride = 12; // just pos
+ s_prevprimitive = 0;
+ s_pBaseBufferPointer = (u8*)_aligned_malloc(MAX_BUFFER_SIZE, 256);
+ s_pCurBufferPointer = s_pBaseBufferPointer;
+
+ for (int i = 0; i < ARRAYSIZE(shiftLookup); i++)
+ shiftLookup[i] = 1.0f / float(1 << i);
+
+ s_nCurVBOIndex = 0;
+ glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
+ for (int i = 0; i < ARRAYSIZE(s_vboBuffers); ++i) {
+ glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[i]);
+ glBufferData(GL_ARRAY_BUFFER, MAX_BUFFER_SIZE, NULL, GL_STREAM_DRAW);
+ }
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ fnSetupVertexPointers = NULL;
+ GL_REPORT_ERRORD();
+
+ return true;
+}
+
+void VertexManager::Destroy()
+{
+ _aligned_free(s_pBaseBufferPointer); s_pBaseBufferPointer = s_pCurBufferPointer = NULL;
+ glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
+ memset(s_vboBuffers, 0, sizeof(s_vboBuffers));
+
+ s_vStoredPrimitives.resize(0);
+ s_nCurVBOIndex = 0;
+ ResetBuffer();
+}
+
+void VertexManager::ResetBuffer()
+{
+ s_nCurVBOIndex = (s_nCurVBOIndex+1)%ARRAYSIZE(s_vboBuffers);
+ s_pCurBufferPointer = s_pBaseBufferPointer;
+ s_vStoredPrimitives.resize(0);
+}
+
+void VertexManager::ResetComponents()
+{
+ s_prevcomponents = 0;
+ s_prevvbstride = 12; // just pos
+ s_prevprimitive = 0;
+ glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
+ glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
+ for (int i = 0; i < 8; ++i) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+int VertexManager::GetRemainingSize()
+{
+ return MAX_BUFFER_SIZE - (int)(s_pCurBufferPointer-s_pBaseBufferPointer);
+}
+
+void VertexManager::AddVertices(int primitive, int numvertices)
+{
+ _assert_( numvertices > 0 );
+
+ ADDSTAT(stats.thisFrame.numPrims, numvertices);
+ s_vStoredPrimitives.push_back(pair(c_primitiveType[primitive], numvertices));
+
+ static const char *sprims[8] = {"quads", "nothing", "tris", "tstrip", "tfan", "lines", "lstrip", "points"};
+ PRIM_LOG("prim: %s, c=%d\n", sprims[primitive], numvertices);
+}
+
+void VertexManager::Flush()
+{
+ if (s_vStoredPrimitives.size() == 0)
+ return;
+
+ _assert_( fnSetupVertexPointers != NULL );
+ _assert_( s_pCurBufferPointer != s_pBaseBufferPointer );
+
+#ifdef _DEBUG
+ PRIM_LOG("frame%d:\ncomps=0x%x, texgen=%d, numchan=%d, dualtex=%d, ztex=%d, proj=%d, cole=%d, alpe=%d, ze=%d\n", g_Config.iSaveTargetId, s_prevcomponents, xfregs.numTexGens,
+ xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op, VertexShaderMngr::rawProjection[6]==0,
+ bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.zmode.updateenable);
+ for(int i = 0; i < xfregs.nNumChans; ++i) {
+ LitChannel* ch = &xfregs.colChans[i].color;
+ PRIM_LOG("colchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
+ ch = &xfregs.colChans[i].alpha;
+ PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
+ }
+ for(int i = 0; i < xfregs.numTexGens; ++i) {
+ TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
+ if( tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff;
+ if( tinfo.texgentype != XF_TEXGEN_REGULAR ) tinfo.projection = 0;
+
+ PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d\n",
+ i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift,
+ xfregs.texcoords[i].postmtxinfo.index, xfregs.texcoords[i].postmtxinfo.normalize);
+ }
+
+ PRIM_LOG("pixel: tev=%d, ind=%d, texgen=%d, dstalpha=%d, alphafunc=0x%x\n", bpmem.genMode.numtevstages+1, bpmem.genMode.numindstages,
+ bpmem.genMode.numtexgens, (u32)bpmem.dstalpha.enable, (bpmem.alphaFunc.hex>>16)&0xff);
+#endif
+
+ DVSTARTPROFILE();
+
+ GL_REPORT_ERRORD();
+
+ glBindBuffer(GL_ARRAY_BUFFER, s_vboBuffers[s_nCurVBOIndex]);
+ glBufferData(GL_ARRAY_BUFFER, s_pCurBufferPointer-s_pBaseBufferPointer, s_pBaseBufferPointer, GL_STREAM_DRAW);
+ GL_REPORT_ERRORD();
+
+ // setup the pointers
+ fnSetupVertexPointers();
+ GL_REPORT_ERRORD();
+
+ // set the textures
+ {
+ DVProfileFunc _pf("VertexManager::Flush:textures");
+
+ u32 usedtextures = 0;
+ for (u32 i = 0; i < bpmem.genMode.numtevstages+1; ++i) {
+ if( bpmem.tevorders[i/2].getEnable(i&1) )
+ usedtextures |= 1< 0 ) {
+ for(u32 i = 0; i < bpmem.genMode.numtevstages+1; ++i) {
+ if( bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages ) {
+ usedtextures |= 1<>2];
+ TextureMngr::TCacheEntry* tentry = TextureMngr::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
+ tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
+ tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, tex.texTlut[i&3].tlut_format);
+
+ if( tentry != NULL ) {
+ // texture loaded fine, set dims for pixel shader
+ if( tentry->isNonPow2 ) {
+ PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, tentry->mode.wrap_s, tentry->mode.wrap_t);
+ nonpow2tex |= 1<mode.wrap_s > 0 ) nonpow2tex |= 1<<(8+i);
+ if( tentry->mode.wrap_t > 0 ) nonpow2tex |= 1<<(16+i);
+ }
+ // if texture is power of two, set to ones (since don't need scaling)
+ else PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, 0, 0);
+
+ if( tentry->isNonPow2 ) TextureMngr::EnableTexRECT(i);
+ else TextureMngr::EnableTex2D(i);
+
+ if( g_Config.iLog & CONF_PRIMLOG ) {
+ // save the textures
+ char strfile[255];
+ sprintf(strfile, "frames/tex%.3d_%d.tga", g_Config.iSaveTargetId, i);
+ SaveTexture(strfile, tentry->isNonPow2?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D, tentry->texture, tentry->w, tentry->h);
+ }
+ }
+ else {
+ ERROR_LOG("error loading tex\n");
+ TextureMngr::DisableStage(i); // disable since won't be used
+ }
+ }
+ else {
+ TextureMngr::DisableStage(i); // disable since won't be used
+ }
+ }
+
+ PixelShaderMngr::SetTexturesUsed(nonpow2tex);
+ }
+
+ FRAGMENTSHADER* ps = PixelShaderMngr::GetShader();
+ VERTEXSHADER* vs = VertexShaderMngr::GetShader(s_prevcomponents);
+ _assert_( ps != NULL && vs != NULL );
+
+ bool bRestoreBuffers = false;
+ if( Renderer::GetZBufferTarget() ) {
+ if( bpmem.zmode.updateenable ) {
+ if( !bpmem.blendmode.colorupdate ) {
+ Renderer::SetRenderMode(bpmem.blendmode.alphaupdate?Renderer::RM_ZBufferAlpha:Renderer::RM_ZBufferOnly);
+ }
+ }
+ else {
+ Renderer::SetRenderMode(Renderer::RM_Normal);
+ // remove temporarily
+ glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+ bRestoreBuffers = true;
+ }
+ }
+ else
+ Renderer::SetRenderMode(Renderer::RM_Normal);
+
+ // set global constants
+ VertexShaderMngr::SetConstants(*vs);
+ PixelShaderMngr::SetConstants(*ps);
+
+ // finally bind
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs->glprogid);
+ glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps->glprogid);
+
+ PRIM_LOG("\n");
+
+ int offset = 0;
+ vector< pair >::iterator it;
+ FORIT (it, s_vStoredPrimitives) {
+ glDrawArrays(it->first, offset, it->second);
+ offset += it->second;
+ }
+
+#ifdef _DEBUG
+ if( g_Config.iLog & CONF_PRIMLOG ) {
+ // save the shaders
+ char strfile[255];
+ sprintf(strfile, "frames/ps%.3d.txt", g_Config.iSaveTargetId);
+ std::ofstream fps(strfile);
+ fps << ps->strprog.c_str();
+ sprintf(strfile, "frames/vs%.3d.txt", g_Config.iSaveTargetId);
+ ofstream fvs(strfile);
+ fvs << vs->strprog.c_str();
+ }
+
+ if( g_Config.iLog & CONF_SAVETARGETS ) {
+ char str[128];
+ sprintf(str, "frames/targ%.3d.tga", g_Config.iSaveTargetId);
+ Renderer::SaveRenderTarget(str, 0);
+ }
+#endif
+ g_Config.iSaveTargetId++;
+
+ GL_REPORT_ERRORD();
+
+ if( bRestoreBuffers ) {
+ GLenum s_drawbuffers[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
+ glDrawBuffers(2, s_drawbuffers);
+ SetColorMask();
+ }
+
+ ResetBuffer();
+}
+
+void VertexManager::LoadCPReg(u32 SubCmd, u32 Value)
+{
+ switch (SubCmd & 0xF0)
+ {
+ case 0x30:
+ VertexShaderMngr::SetTexMatrixChangedA(Value);
+ break;
+ case 0x40:
+ VertexShaderMngr::SetTexMatrixChangedB(Value);
+ break;
+
+ case 0x50:
+ s_GlobalVtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits
+ s_GlobalVtxDesc.Hex |= Value;
+ break;
+ case 0x60:
+ s_GlobalVtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits
+ s_GlobalVtxDesc.Hex |= (u64)Value << 17;
+ break;
+
+ case 0x70: g_VertexLoaders[SubCmd & 7].SetVAT_group0(Value); _assert_((SubCmd & 0x0F) < 8); break;
+ case 0x80: g_VertexLoaders[SubCmd & 7].SetVAT_group1(Value); _assert_((SubCmd & 0x0F) < 8); break;
+ case 0x90: g_VertexLoaders[SubCmd & 7].SetVAT_group2(Value); _assert_((SubCmd & 0x0F) < 8); break;
+
+ case 0xA0: arraybases[SubCmd & 0xF] = Value & 0xFFFFFFFF; break;
+ case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break;
+ }
+}
+
+size_t VertexManager::SaveLoadState(char *ptr, BOOL save)
+{
+ BEGINSAVELOAD;
+ SAVELOAD(arraybases,16*sizeof(u32));
+ SAVELOAD(arraystrides,16*sizeof(u32));
+ ENDSAVELOAD;
+}
+
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h
index 63206a14e0..34232f4428 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexLoader.h
@@ -26,194 +26,7 @@
using namespace std;
-////////////////
-// CP Structs //
-////////////////
-
-// Vertex array numbers
-enum
-{
- ARRAY_POSITION = 0,
- ARRAY_NORMAL = 1,
- ARRAY_COLOR = 2,
- ARRAY_COLOR2 = 3,
- ARRAY_TEXCOORD0 = 4
-};
-
-// Vertex components
-enum
-{
- NOT_PRESENT = 0,
- DIRECT = 1,
- INDEX8 = 2,
- INDEX16 = 3,
-};
-
-#pragma pack(4)
-
-union TVtxDesc
-{
- u64 Hex;
- struct
- {
- // 0: not present
- // 1: present
- unsigned PosMatIdx : 1;
- unsigned Tex0MatIdx : 1;
- unsigned Tex1MatIdx : 1;
- unsigned Tex2MatIdx : 1;
- unsigned Tex3MatIdx : 1;
- unsigned Tex4MatIdx : 1;
- unsigned Tex5MatIdx : 1;
- unsigned Tex6MatIdx : 1;
- unsigned Tex7MatIdx : 1;
-
- // 00: not present
- // 01: direct
- // 10: 8 bit index
- // 11: 16 bit index
- unsigned Position : 2;
- unsigned Normal : 2;
- unsigned Color0 : 2;
- unsigned Color1 : 2;
- unsigned Tex0Coord : 2;
- unsigned Tex1Coord : 2;
- unsigned Tex2Coord : 2;
- unsigned Tex3Coord : 2;
- unsigned Tex4Coord : 2;
- unsigned Tex5Coord : 2;
- unsigned Tex6Coord : 2;
- unsigned Tex7Coord : 2;
- unsigned :31;
- };
- struct {
- u32 Hex0, Hex1;
- };
-};
-
-
-
-enum
-{
- FORMAT_UBYTE = 0, // 2 Cmp
- FORMAT_BYTE = 1, // 3 Cmp
- FORMAT_USHORT = 2,
- FORMAT_SHORT = 3,
- FORMAT_FLOAT = 4,
-};
-
-enum
-{
- FORMAT_16B_565 = 0, // NA
- FORMAT_24B_888 = 1,
- FORMAT_32B_888x = 2,
- FORMAT_16B_4444 = 3,
- FORMAT_24B_6666 = 4,
- FORMAT_32B_8888 = 5,
-};
-
-union UVAT_group0
-{
- u32 Hex;
- struct
- {
- // 0:8
- unsigned PosElements : 1;
- unsigned PosFormat : 3;
- unsigned PosFrac : 5;
- // 9:12
- unsigned NormalElements : 1;
- unsigned NormalFormat : 3;
- // 13:16
- unsigned Color0Elements : 1;
- unsigned Color0Comp : 3;
- // 17:20
- unsigned Color1Elements : 1;
- unsigned Color1Comp : 3;
- // 21:29
- unsigned Tex0CoordElements : 1;
- unsigned Tex0CoordFormat : 3;
- unsigned Tex0Frac : 5;
- // 30:31
- unsigned ByteDequant: 1;
- unsigned NormalIndex3: 1;
- };
-};
-
-union UVAT_group1
-{
- u32 Hex;
- struct
- {
- // 0:8
- unsigned Tex1CoordElements : 1;
- unsigned Tex1CoordFormat : 3;
- unsigned Tex1Frac : 5;
- // 9:17
- unsigned Tex2CoordElements : 1;
- unsigned Tex2CoordFormat : 3;
- unsigned Tex2Frac : 5;
- // 18:26
- unsigned Tex3CoordElements : 1;
- unsigned Tex3CoordFormat : 3;
- unsigned Tex3Frac : 5;
- // 27:30
- unsigned Tex4CoordElements : 1;
- unsigned Tex4CoordFormat : 3;
- //
- unsigned : 1;
- };
-};
-
-union UVAT_group2
-{
- u32 Hex;
- struct
- {
- // 0:4
- unsigned Tex4Frac : 5;
- // 5:13
- unsigned Tex5CoordElements : 1;
- unsigned Tex5CoordFormat : 3;
- unsigned Tex5Frac : 5;
- // 14:22
- unsigned Tex6CoordElements : 1;
- unsigned Tex6CoordFormat : 3;
- unsigned Tex6Frac : 5;
- // 23:31
- unsigned Tex7CoordElements : 1;
- unsigned Tex7CoordFormat : 3;
- unsigned Tex7Frac : 5;
- };
-};
-
-struct ColorAttr
-{
- u8 Elements;
- u8 Comp;
-};
-
-struct TexAttr
-{
- u8 Elements;
- u8 Format;
- u8 Frac;
-};
-
-struct TVtxAttr
-{
- u8 PosElements;
- u8 PosFormat;
- u8 PosFrac;
- u8 NormalElements;
- u8 NormalFormat;
- ColorAttr color[2];
- TexAttr texCoord[8];
- u8 ByteDequant;
- u8 NormalIndex3;
-};
-
-#pragma pack ()
+#include "CPMemory.h"
#define LOADERDECL __cdecl
typedef void (LOADERDECL *TPipelineFunction)(void*);
@@ -407,8 +220,7 @@ public:
};
extern VertexLoader g_VertexLoaders[8];
-extern u32 arraybases[16];
-extern u32 arraystrides[16];
+
u8 ReadBuffer8();
u16 ReadBuffer16();
u32 ReadBuffer32();
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShader.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexShader.h
index bd09fcd3dd..d3f3f79255 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShader.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShader.h
@@ -172,15 +172,15 @@ struct XFRegisters
bool bEnableDualTexTransform;
};
-#define XFMEM_SIZE 0x8000
-#define XFMEM_POSMATRICES 0x000
-#define XFMEM_POSMATRICES_END 0x100
-#define XFMEM_NORMALMATRICES 0x400
+#define XFMEM_SIZE 0x8000
+#define XFMEM_POSMATRICES 0x000
+#define XFMEM_POSMATRICES_END 0x100
+#define XFMEM_NORMALMATRICES 0x400
#define XFMEM_NORMALMATRICES_END 0x460
-#define XFMEM_POSTMATRICES 0x500
-#define XFMEM_POSTMATRICES_END 0x600
-#define XFMEM_LIGHTS 0x600
-#define XFMEM_LIGHTS_END 0x680
+#define XFMEM_POSTMATRICES 0x500
+#define XFMEM_POSTMATRICES_END 0x600
+#define XFMEM_LIGHTS 0x600
+#define XFMEM_LIGHTS_END 0x680
// Matrix indices
union TMatrixIndexA