More common things moved out from the GFX plugins. No visible changes.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@27 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-07-18 19:33:55 +00:00
parent ca13c54855
commit b3c55018a6
36 changed files with 857 additions and 924 deletions

View File

@ -279,13 +279,11 @@ union UGQR
{ {
unsigned ST_TYPE : 3; unsigned ST_TYPE : 3;
unsigned : 5; unsigned : 5;
// signed ST_SCALE : 6; unsigned ST_SCALE : 6;
unsigned ST_SCALE : 6;
unsigned : 2; unsigned : 2;
unsigned LD_TYPE : 3; unsigned LD_TYPE : 3;
unsigned : 5; unsigned : 5;
// signed LD_SCALE : 6; unsigned LD_SCALE : 6;
unsigned LD_SCALE : 6;
unsigned : 2; unsigned : 2;
}; };

View File

@ -346,6 +346,7 @@ namespace Jit64
js.blockStart = emaddress; js.blockStart = emaddress;
js.fifoBytesThisBlock = 0; js.fifoBytesThisBlock = 0;
js.curBlock = &b; js.curBlock = &b;
js.blockSetsQuantizers = false;
//Analyze the block, collect all instructions it is made of (including inlining, //Analyze the block, collect all instructions it is made of (including inlining,
//if that is enabled), reorder instructions for optimal performance, and join joinable instructions. //if that is enabled), reorder instructions for optimal performance, and join joinable instructions.

View File

@ -49,6 +49,7 @@ namespace Jit64
int downcountAmount; int downcountAmount;
bool isLastInstruction; bool isLastInstruction;
bool blockSetsQuantizers;
int fifoBytesThisBlock; int fifoBytesThisBlock;

View File

@ -95,12 +95,14 @@ const double m_dequantizeTableD[] =
(1 << 4), (1 << 3), (1 << 2), (1 << 1), (1 << 4), (1 << 3), (1 << 2), (1 << 1),
}; };
// The big problem is likely instructions that set the quantizers in the same block.
// We will have to break block after quantizers are written to.
u32 temp; u32 temp;
void psq_st(UGeckoInstruction inst) void psq_st(UGeckoInstruction inst)
{ {
BIT32OLD; BIT32OLD;
OLD; OLD;
if (!Core::GetStartupParameter().bOptimizeQuantizers) if (js.blockSetsQuantizers || !Core::GetStartupParameter().bOptimizeQuantizers)
{ {
Default(inst); Default(inst);
return; return;
@ -220,7 +222,7 @@ void psq_l(UGeckoInstruction inst)
{ {
BIT32OLD; BIT32OLD;
OLD; OLD;
if (!Core::GetStartupParameter().bOptimizeQuantizers) if (js.blockSetsQuantizers || !Core::GetStartupParameter().bOptimizeQuantizers)
{ {
Default(inst); Default(inst);
return; return;
@ -296,6 +298,14 @@ void psq_l(UGeckoInstruction inst)
ADD(32, gpr.R(inst.RA), Imm32(offset)); ADD(32, gpr.R(inst.RA), Imm32(offset));
} }
break; break;
/*
Dynamic quantizer. Todo when we have a test set.
MOVZX(32, 8, EAX, M(((char *)&PowerPC::ppcState.spr[SPR_GQR0 + inst.I]) + 3)); // it's in the high byte.
AND(32, R(EAX), Imm8(0x3F));
MOV(32, R(ECX), Imm32((u32)&m_dequantizeTableD));
MOVDDUP(r, MComplex(RCX, EAX, 8, 0));
*/
#endif #endif
default: default:
// 4 0 // 4 0

View File

@ -35,15 +35,32 @@ namespace Jit64
{ {
case SPR_LR: case SPR_LR:
case SPR_CTR: case SPR_CTR:
gpr.Lock(d); // These are safe to do the easy way, see the bottom of this function.
gpr.LoadToX64(d,true);
MOV(32, M(&PowerPC::ppcState.spr[iIndex]), gpr.R(d));
gpr.UnlockAll();
break; break;
case SPR_GQR0:
case SPR_GQR0 + 1:
case SPR_GQR0 + 2:
case SPR_GQR0 + 3:
case SPR_GQR0 + 4:
case SPR_GQR0 + 5:
case SPR_GQR0 + 6:
case SPR_GQR0 + 7:
js.blockSetsQuantizers = false;
// Prevent recompiler from compiling in old quantizer values.
// TODO - actually save the set state and use it in following quantizer ops.
break;
// TODO - break block if quantizers are written to.
default: default:
Default(inst); Default(inst);
return; return;
} }
// OK, this is easy.
gpr.Lock(d);
gpr.LoadToX64(d,true);
MOV(32, M(&PowerPC::ppcState.spr[iIndex]), gpr.R(d));
gpr.UnlockAll();
} }
void mfspr(UGeckoInstruction inst) void mfspr(UGeckoInstruction inst)

View File

@ -0,0 +1,27 @@
#include "LookUpTables.h"
int lut3to8[8];
int lut4to8[16];
int lut5to8[32];
int lut6to8[64];
float lutu8tosfloat[256];
float lutu8toufloat[256];
float luts8tosfloat[256];
void InitLUTs()
{
for (int i = 0; i < 8; i++)
lut3to8[i] = (i*255) / 7;
for (int i = 0; i < 16; i++)
lut4to8[i] = (i*255) / 15;
for (int i = 0; i < 32; i++)
lut5to8[i] = (i*255) / 31;
for (int i = 0; i < 64; i++)
lut6to8[i] = (i*255) / 63;
for (int i = 0; i < 256; i++)
{
lutu8tosfloat[i] = (float)(i-128) / 127.0f;
lutu8toufloat[i] = (float)(i) / 255.0f;
luts8tosfloat[i] = ((float)(signed char)(char)i) / 127.0f;
}
}

View File

@ -0,0 +1,16 @@
#ifndef _LOOKUPTABLES_H
#define _LOOKUPTABLES_H
#include "Common.h"
extern int lut3to8[8];
extern int lut4to8[16];
extern int lut5to8[32];
extern int lut6to8[64];
extern float lutu8tosfloat[256];
extern float lutu8toufloat[256];
extern float luts8tosfloat[256];
void InitLUTs();
#endif

View File

@ -0,0 +1,4 @@
#include "XFMemory.h"
XFRegisters xfregs;
u32 xfmem[XFMEM_SIZE];

View File

@ -0,0 +1,218 @@
#ifndef _XFMEMORY_H
#define _XFMEMORY_H
#include "Common.h"
/////////////
// Lighting
/////////////
#define XF_TEXPROJ_ST 0
#define XF_TEXPROJ_STQ 1
#define XF_TEXINPUT_AB11 0
#define XF_TEXINPUT_ABC1 1
#define XF_TEXGEN_REGULAR 0
#define XF_TEXGEN_EMBOSS_MAP 1 // used when bump mapping
#define XF_TEXGEN_COLOR_STRGBC0 2
#define XF_TEXGEN_COLOR_STRGBC1 3
#define XF_SRCGEOM_INROW 0 // input is abc
#define XF_SRCNORMAL_INROW 1 // input is abc
#define XF_SRCCOLORS_INROW 2
#define XF_SRCBINORMAL_T_INROW 3 // input is abc
#define XF_SRCBINORMAL_B_INROW 4 // input is abc
#define XF_SRCTEX0_INROW 5
#define XF_SRCTEX1_INROW 6
#define XF_SRCTEX2_INROW 7
#define XF_SRCTEX3_INROW 8
#define XF_SRCTEX4_INROW 9
#define XF_SRCTEX5_INROW 10
#define XF_SRCTEX6_INROW 11
#define XF_SRCTEX7_INROW 12
#define GX_SRC_REG 0
#define GX_SRC_VTX 1
struct Light
{
u32 useless[3];
u32 color; //rgba
float a0; //attenuation
float a1;
float a2;
float k0; //k stuff
float k1;
float k2;
union
{
struct {
float dpos[3];
float ddir[3]; // specular lights only
};
struct {
float sdir[3];
float shalfangle[3]; // specular lights only
};
};
};
#define LIGHTDIF_NONE 0
#define LIGHTDIF_SIGN 1
#define LIGHTDIF_CLAMP 2
#define LIGHTATTN_SPEC 0 // specular attenuation
#define LIGHTATTN_SPOT 1 // distance/spotlight attenuation
#define LIGHTATTN_NONE 2
#define LIGHTATTN_DIR 3
union LitChannel
{
struct
{
unsigned matsource : 1;
unsigned enablelighting : 1;
unsigned lightMask0_3 : 4;
unsigned ambsource : 1;
unsigned diffusefunc : 2; // LIGHTDIF_X
unsigned attnfunc : 2; // LIGHTATTN_X
unsigned lightMask4_7 : 4;
};
struct
{
u32 hex : 15;
u32 unused : 17;
};
struct
{
u32 dummy0 : 7;
u32 lightparams : 4;
u32 dummy1 : 21;
};
unsigned int GetFullLightMask() const
{
return enablelighting ? (lightMask0_3 | (lightMask4_7 << 4)) : 0;
}
};
struct ColorChannel
{
u32 ambColor;
u32 matColor;
LitChannel color;
LitChannel alpha;
};
union INVTXSPEC
{
struct
{
unsigned numcolors : 2;
unsigned numnormals : 2; // 0 - nothing, 1 - just normal, 2 - normals and binormals
unsigned numtextures : 4;
unsigned unused : 24;
};
u32 hex;
};
union TexMtxInfo
{
struct
{
unsigned unknown : 1;
unsigned projection : 1; // XF_TEXPROJ_X
unsigned inputform : 2; // XF_TEXINPUT_X
unsigned texgentype : 3; // XF_TEXGEN_X
unsigned sourcerow : 5; // XF_SRCGEOM_X
unsigned embosssourceshift : 3; // what generated texcoord to use
unsigned embosslightshift : 3; // light index that is used
};
u32 hex;
};
union PostMtxInfo
{
struct
{
unsigned index : 6; // base row of dual transform matrix
unsigned unused : 2;
unsigned normalize : 1; // normalize before send operation
};
u32 hex;
};
struct TexCoordInfo
{
TexMtxInfo texmtxinfo;
PostMtxInfo postmtxinfo;
};
struct XFRegisters
{
int numTexGens;
int nNumChans;
INVTXSPEC hostinfo; // number of textures,colors,normals from vertex input
ColorChannel colChans[2]; //C0A0 C1A1
TexCoordInfo texcoords[8];
bool bEnableDualTexTransform;
};
#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
// Matrix indices
union TMatrixIndexA
{
struct
{
unsigned PosNormalMtxIdx : 6;
unsigned Tex0MtxIdx : 6;
unsigned Tex1MtxIdx : 6;
unsigned Tex2MtxIdx : 6;
unsigned Tex3MtxIdx : 6;
};
struct
{
u32 Hex : 30;
u32 unused : 2;
};
};
union TMatrixIndexB
{
struct
{
unsigned Tex4MtxIdx : 6;
unsigned Tex5MtxIdx : 6;
unsigned Tex6MtxIdx : 6;
unsigned Tex7MtxIdx : 6;
};
struct
{
u32 Hex : 24;
u32 unused : 8;
};
};
struct Viewport
{
float wd;
float ht;
float nearZ;
float xOrig;
float yOrig;
float farZ;
};
extern XFRegisters xfregs;
extern u32 xfmem[XFMEM_SIZE];
#endif

View File

@ -405,6 +405,22 @@
RelativePath=".\Src\CPMemory.h" RelativePath=".\Src\CPMemory.h"
> >
</File> </File>
<File
RelativePath=".\Src\LookUpTables.cpp"
>
</File>
<File
RelativePath=".\Src\LookUpTables.h"
>
</File>
<File
RelativePath=".\Src\XFMemory.cpp"
>
</File>
<File
RelativePath=".\Src\XFMemory.h"
>
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@ -3,39 +3,7 @@
#include "Common.h" #include "Common.h"
#include "CPMemory.h" #include "CPMemory.h"
#include "XFMemory.h"
#pragma pack(4)
//////////////////////////////////////////////////////////////////////////
// Matrix indices
//////////////////////////////////////////////////////////////////////////
union TMatrixIndexA
{
u32 Hex;
struct
{
unsigned PosNormalMtxIdx : 6;
unsigned Tex0MtxIdx : 6;
unsigned Tex1MtxIdx : 6;
unsigned Tex2MtxIdx : 6;
unsigned Tex3MtxIdx : 6;
};
};
union TMatrixIndexB
{
u32 Hex;
struct
{
unsigned Tex4MtxIdx : 6;
unsigned Tex5MtxIdx : 6;
unsigned Tex6MtxIdx : 6;
unsigned Tex7MtxIdx : 6;
};
};
#pragma pack ()
extern TMatrixIndexA MatrixIndexA; extern TMatrixIndexA MatrixIndexA;
extern TMatrixIndexB MatrixIndexB; extern TMatrixIndexB MatrixIndexB;

View File

@ -248,7 +248,7 @@ tevhash GetCurrentTEV()
{ {
hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13); hash = _rotl(hash,3) ^ (bpmem.combiners[i].colorC.hex*13);
hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3); hash = _rotl(hash,7) ^ ((bpmem.combiners[i].alphaC.hex&0xFFFFFFFC)*3);
hash = _rotl(hash,9) ^ texcoords[i].texmtxinfo.projection*451; hash = _rotl(hash,9) ^ xfregs.texcoords[i].texmtxinfo.projection*451;
} }
for (int i = 0; i < (int)bpmem.genMode.numtevstages/2+1; i++) for (int i = 0; i < (int)bpmem.genMode.numtevstages/2+1; i++)
{ {
@ -369,7 +369,7 @@ void WriteStage(char *&p, int n)
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap]; char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap]; char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
int texfun = texcoords[n].texmtxinfo.projection; int texfun = xfregs.texcoords[n].texmtxinfo.projection;
WRITE(p,"rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap); WRITE(p,"rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap);
if (bpmem.tevorders[n/2].getEnable(n&1)) if (bpmem.tevorders[n/2].getEnable(n&1))

View File

@ -27,16 +27,29 @@ enum TextureFormat
GX_TF_C14X2 = 0xA, GX_TF_C14X2 = 0xA,
GX_TF_CMPR = 0xE, GX_TF_CMPR = 0xE,
_GX_TF_CTF = 0x20, /* copy-texture-format only */ _GX_TF_CTF = 0x20, // copy-texture-format only (simply means linear?)
_GX_TF_ZTF = 0x10, /* Z-texture-format */ _GX_TF_ZTF = 0x10, // Z-texture-format
GX_TF_Z8 = 0x1 | _GX_TF_ZTF, // these formats are also valid when copying targets
GX_CTF_R4 = 0x0 | _GX_TF_CTF,
GX_CTF_RA4 = 0x2 | _GX_TF_CTF,
GX_CTF_RA8 = 0x3 | _GX_TF_CTF,
GX_CTF_YUVA8 = 0x6 | _GX_TF_CTF,
GX_CTF_A8 = 0x7 | _GX_TF_CTF,
GX_CTF_R8 = 0x8 | _GX_TF_CTF,
GX_CTF_G8 = 0x9 | _GX_TF_CTF,
GX_CTF_B8 = 0xA | _GX_TF_CTF,
GX_CTF_RG8 = 0xB | _GX_TF_CTF,
GX_CTF_GB8 = 0xC | _GX_TF_CTF,
GX_TF_Z8 = 0x1 | _GX_TF_ZTF,
GX_TF_Z16 = 0x3 | _GX_TF_ZTF, GX_TF_Z16 = 0x3 | _GX_TF_ZTF,
GX_TF_Z24X8 = 0x6 | _GX_TF_ZTF, GX_TF_Z24X8 = 0x6 | _GX_TF_ZTF,
//and the strange copy texture formats.. GX_CTF_Z4 = 0x0 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8M = 0x9 | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z8L = 0xA | _GX_TF_ZTF | _GX_TF_CTF,
GX_CTF_Z16L = 0xC | _GX_TF_ZTF | _GX_TF_CTF,
}; };
int TexDecoder_GetTexelSizeInNibbles(int format); int TexDecoder_GetTexelSizeInNibbles(int format);

View File

@ -1,5 +1,6 @@
#include "Common.h" #include "Common.h"
#include "Globals.h" #include "Globals.h"
#include "Vec3.h"
#include "TransformEngine.h" #include "TransformEngine.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "VertexLoader.h" #include "VertexLoader.h"
@ -34,7 +35,7 @@ float DoLighting(const Light *light, const LitChannel &chan, const Vec3 &pos, co
float val; float val;
if (chan.attnfunc == 0 || chan.attnfunc == 2) //no attn if (chan.attnfunc == 0 || chan.attnfunc == 2) //no attn
{ {
Vec3 ldir = (light->dpos-pos); Vec3 ldir = (Vec3(light->dpos) - pos);
val = ldir.normalized() * normal; val = ldir.normalized() * normal;
} }
else else
@ -44,17 +45,17 @@ float DoLighting(const Light *light, const LitChannel &chan, const Vec3 &pos, co
float mul = 1.0f; float mul = 1.0f;
if (chan.attnfunc == 3) if (chan.attnfunc == 3)
{ {
Vec3 ldir = (light->dpos - pos); Vec3 ldir = (Vec3(light->dpos) - pos);
d = ldir.length(); d = ldir.length();
Vec3 ldirNorm = ldir / d; //normalize Vec3 ldirNorm = ldir / d; //normalize
float l = ldirNorm * normal; float l = ldirNorm * normal;
aattn = light->ddir * ldirNorm; aattn = Vec3(light->ddir) * ldirNorm;
mul = l; mul = l;
} }
else if (chan.attnfunc == 1) else if (chan.attnfunc == 1)
{ {
d = aattn = light->shalfangle * normal; d = aattn = Vec3(light->shalfangle) * normal;
mul = (light->sdir * normal > 0) ? (normal * light->shalfangle) : 0; mul = (Vec3(light->sdir) * normal > 0) ? (normal * Vec3(light->shalfangle)) : 0;
if (mul < 0) if (mul < 0)
mul = 0; mul = 0;
} }
@ -167,14 +168,14 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//find all used lights //find all used lights
u32 lightMask = u32 lightMask =
colChans[0].color.GetFullLightMask() | colChans[0].alpha.GetFullLightMask() | xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask() |
colChans[1].color.GetFullLightMask() | colChans[1].alpha.GetFullLightMask(); xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask();
float r0=0,g0=0,b0=0,a0=0; float r0=0,g0=0,b0=0,a0=0;
//go through them and compute the lit colors //go through them and compute the lit colors
//Sum lighting for both two color channels if they're active //Sum lighting for both two color channels if they're active
for (int j=0; j<(int)bpmem.genMode.numcolchans; j++) for (int j = 0; j < (int)bpmem.genMode.numcolchans; j++)
{ {
RGBAFloat material; RGBAFloat material;
RGBAFloat lightSum(0,0,0,0); RGBAFloat lightSum(0,0,0,0);
@ -182,8 +183,8 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
bool hasColorJ = (varray->GetComponents() & (VB_HAS_COL0 << j)) != 0; bool hasColorJ = (varray->GetComponents() & (VB_HAS_COL0 << j)) != 0;
//get basic material color from appropriate sources (this would compile nicely!:) //get basic material color from appropriate sources (this would compile nicely!:)
if (colChans[j].color.matsource==GX_SRC_REG) if (xfregs.colChans[j].color.matsource == GX_SRC_REG)
material.convertRGB_GC(colChans[j].matColor); material.convertRGB_GC(xfregs.colChans[j].matColor);
else else
{ {
if (hasColorJ) if (hasColorJ)
@ -192,8 +193,8 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
material.r=material.g=material.b=1.0f; material.r=material.g=material.b=1.0f;
} }
if (colChans[j].alpha.matsource==GX_SRC_REG) if (xfregs.colChans[j].alpha.matsource == GX_SRC_REG)
material.convertA_GC(colChans[j].matColor); material.convertA_GC(xfregs.colChans[j].matColor);
else else
{ {
if (hasColorJ) if (hasColorJ)
@ -203,11 +204,11 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
} }
//combine together the light values from the lights that affect the color //combine together the light values from the lights that affect the color
if (colChans[j].color.enablelighting) if (xfregs.colChans[j].color.enablelighting)
{ {
//choose ambient source and start our lightsum accumulator with its value.. //choose ambient source and start our lightsum accumulator with its value..
if (colChans[j].color.ambsource == GX_SRC_REG) if (xfregs.colChans[j].color.ambsource == GX_SRC_REG)
lightSum.convertRGB_GC(colChans[j].ambColor); //ambient lightSum.convertRGB_GC(xfregs.colChans[j].ambColor); //ambient
else else
{ {
if (hasColorJ) if (hasColorJ)
@ -219,12 +220,12 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
} }
//accumulate light colors //accumulate light colors
int cmask = colChans[j].color.GetFullLightMask(); int cmask = xfregs.colChans[j].color.GetFullLightMask();
for (int l=0; l<8; l++) for (int l=0; l<8; l++)
{ {
if (cmask&1) if (cmask&1)
{ {
float val = DoLighting(GetLight(l), colChans[j].color, TempPos, TempNormal); float val = DoLighting(GetLight(l), xfregs.colChans[j].color, TempPos, TempNormal);
float r = lightColors[l].r * val; float r = lightColors[l].r * val;
float g = lightColors[l].g * val; float g = lightColors[l].g * val;
float b = lightColors[l].b * val; float b = lightColors[l].b * val;
@ -237,15 +238,15 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
} }
else else
{ {
lightSum.r=lightSum.g=lightSum.b=1.0f; lightSum.r = lightSum.g = lightSum.b = 1.0f;
} }
//combine together the light values from the lights that affect alpha (should be rare) //combine together the light values from the lights that affect alpha (should be rare)
if (colChans[j].alpha.enablelighting) if (xfregs.colChans[j].alpha.enablelighting)
{ {
//choose ambient source.. //choose ambient source..
if (colChans[j].alpha.ambsource==GX_SRC_REG) if (xfregs.colChans[j].alpha.ambsource==GX_SRC_REG)
lightSum.convertA_GC(colChans[j].ambColor); lightSum.convertA_GC(xfregs.colChans[j].ambColor);
else else
{ {
if (hasColorJ) if (hasColorJ)
@ -254,12 +255,12 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
lightSum.a=0.0f; lightSum.a=0.0f;
} }
//accumulate light alphas //accumulate light alphas
int amask = colChans[j].alpha.GetFullLightMask(); int amask = xfregs.colChans[j].alpha.GetFullLightMask();
for (int l=0; l<8; l++) for (int l = 0; l < 8; l++)
{ {
if (amask&1) if (amask&1)
{ {
float val = DoLighting(GetLight(l),colChans[j].alpha,TempPos,TempNormal); float val = DoLighting(GetLight(l), xfregs.colChans[j].alpha, TempPos, TempNormal);
float a = lightColors[l].a * val; float a = lightColors[l].a * val;
lightSum.a += a; lightSum.a += a;
} }
@ -279,21 +280,21 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
//Step 3: Generate texture coordinates! //Step 3: Generate texture coordinates!
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Vec3 TempUVs[8]; Vec3 TempUVs[8];
for (int j=0; j<miscxf.numTexGens; j++) for (int j = 0; j < xfregs.numTexGens; j++)
{ {
int n = bpmem.tevorders[j/2].getTexCoord(j&1); // <- yazor: dirty zelda patch ^^ int n = bpmem.tevorders[j / 2].getTexCoord(j & 1); // <- yazor: dirty zelda patch ^^
n = j; n = j;
Vec3 t; Vec3 t;
switch(texcoords[n].texmtxinfo.sourcerow) { switch (xfregs.texcoords[n].texmtxinfo.sourcerow) {
case XF_GEOM_INROW: t = OrigPos; break; //HACK WTFF??? case XF_SRCGEOM_INROW: t = OrigPos; break; //HACK WTFF???
case XF_NORMAL_INROW: t = OrigNormal; break; case XF_SRCNORMAL_INROW: t = OrigNormal; break;
case XF_COLORS_INROW: break; //set uvs to something? case XF_SRCCOLORS_INROW: break; //set uvs to something?
case XF_BINORMAL_T_INROW: t=Vec3(0,0,0);break; case XF_SRCBINORMAL_T_INROW: t=Vec3(0,0,0);break;
case XF_BINORMAL_B_INROW: t=Vec3(0,0,0);break; case XF_SRCBINORMAL_B_INROW: t=Vec3(0,0,0);break;
default: default:
{ {
int c = texcoords[n].texmtxinfo.sourcerow - XF_TEX0_INROW; int c = xfregs.texcoords[n].texmtxinfo.sourcerow - XF_SRCTEX0_INROW;
bool hasTCC = (varray->GetComponents() & (VB_HAS_UV0 << c)) != 0; bool hasTCC = (varray->GetComponents() & (VB_HAS_UV0 << c)) != 0;
if (c >= 0 && c <= 7 && hasTCC) if (c >= 0 && c <= 7 && hasTCC)
{ {
@ -304,26 +305,26 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
} }
Vec3 out,out2; Vec3 out,out2;
switch (texcoords[n].texmtxinfo.texgentype) switch (xfregs.texcoords[n].texmtxinfo.texgentype)
{ {
case XF_TEXGEN_COLOR_STRGBC0: case XF_TEXGEN_COLOR_STRGBC0:
out=Vec3(chans[0].r*255, chans[0].g*255, 1)/255.0f; out = Vec3(chans[0].r*255, chans[0].g*255, 1)/255.0f;
break; break;
case XF_TEXGEN_COLOR_STRGBC1: case XF_TEXGEN_COLOR_STRGBC1:
out=Vec3(chans[1].r*255, chans[1].g*255, 1)/255.0f; //FIX: take color1 instead out = Vec3(chans[1].r*255, chans[1].g*255, 1)/255.0f; //FIX: take color1 instead
break; break;
case XF_TEXGEN_REGULAR: case XF_TEXGEN_REGULAR:
if (texcoords[n].texmtxinfo.projection) if (xfregs.texcoords[n].texmtxinfo.projection)
VtxMulMtx43(out, t, m_pTexMatrix[n]); VtxMulMtx43(out, t, m_pTexMatrix[n]);
else else
VtxMulMtx42(out, t, m_pTexMatrix[n]); VtxMulMtx42(out, t, m_pTexMatrix[n]);
break; break;
} }
if (texcoords[n].postmtxinfo.normalize) if (xfregs.texcoords[n].postmtxinfo.normalize)
out.normalize(); out.normalize();
int postMatrix = texcoords[n].postmtxinfo.index; int postMatrix = xfregs.texcoords[n].postmtxinfo.index;
float *pmtx = ((float*)xfmem) + 0x500 + postMatrix * 4; //CHECK float *pmtx = ((float*)xfmem) + 0x500 + postMatrix * 4; //CHECK
//multiply with postmatrix //multiply with postmatrix
VtxMulMtx43(TempUVs[j], out, pmtx); VtxMulMtx43(TempUVs[j], out, pmtx);
@ -332,12 +333,12 @@ void CTransformEngine::TransformVertices(int _numVertices, const DecodedVArray *
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//Step 4: Output the vertex! //Step 4: Output the vertex!
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
for (int j=0; j<2; j++) for (int j = 0; j < 2; j++)
chans[j].convertToD3DColor(vbuffer[i].colors[j]); chans[j].convertToD3DColor(vbuffer[i].colors[j]);
vbuffer[i].pos = TempPos; vbuffer[i].pos = TempPos;
vbuffer[i].normal = TempNormal; vbuffer[i].normal = TempNormal;
for (int j=0; j<(int)bpmem.genMode.numtexgens; j++) for (int j = 0; j < (int)bpmem.genMode.numtexgens; j++)
{ {
vbuffer[i].uv[j].u = TempUVs[j].x; vbuffer[i].uv[j].u = TempUVs[j].x;
vbuffer[i].uv[j].v = TempUVs[j].y; vbuffer[i].uv[j].v = TempUVs[j].y;

View File

@ -3,18 +3,11 @@
#include "Common.h" #include "Common.h"
#include "main.h" #include "main.h"
#include "LookUpTables.h"
extern int frameCount; extern int frameCount;
extern int lut3to8[8];
extern int lut4to8[16];
extern int lut5to8[32];
extern int lut6to8[64];
extern float lutu8tosfloat[256];
extern float lutu8toufloat[256];
extern float luts8tosfloat[256];
LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void InitLUTs();
//#define RAM_MASK 0x1FFFFFF //#define RAM_MASK 0x1FFFFFF

View File

@ -10,6 +10,7 @@ public:
float x,y,z; float x,y,z;
Vec3() { } Vec3() { }
explicit Vec3(float f) {x=y=z=f;} explicit Vec3(float f) {x=y=z=f;}
explicit Vec3(const float *f) {x=f[0]; y=f[1]; z=f[2];}
Vec3(const float _x, const float _y, const float _z) { Vec3(const float _x, const float _y, const float _z) {
x=_x; y=_y; z=_z; x=_x; y=_y; z=_z;
} }

View File

@ -5,23 +5,13 @@
#include "VertexHandler.h" #include "VertexHandler.h"
#include "Utils.h" #include "Utils.h"
//XF state
ColorChannel colChans[2]; //C0A0 C1A1
TexCoordInfo texcoords[8];
MiscXF miscxf;
u32 xfmem[XFMEM_SIZE];
float rawViewPort[6]; float rawViewPort[6];
float rawProjection[7]; float rawProjection[7];
#define BEGINSAVELOAD char *optr=ptr; #define BEGINSAVELOAD char *optr=ptr;
#define SAVELOAD(what,size) memcpy((void*)((save)?(void*)(ptr):(void*)(what)),(void*)((save)?(void*)(what):(void*)(ptr)),(size)); ptr+=(size); #define SAVELOAD(what,size) memcpy((void*)((save)?(void*)(ptr):(void*)(what)),(void*)((save)?(void*)(what):(void*)(ptr)),(size)); ptr+=(size);
#define ENDSAVELOAD return ptr-optr; #define ENDSAVELOAD return ptr-optr;
// __________________________________________________________________________________________________ // __________________________________________________________________________________________________
// LoadXFReg 0x10 // LoadXFReg 0x10
// //
@ -52,54 +42,54 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
break; break;
case 0x1009: //GXSetNumChans (no) case 0x1009: //GXSetNumChans (no)
break; break;
case 0x100a: colChans[0].ambColor = data; break; //GXSetChanAmbientcolor case 0x100a: xfregs.colChans[0].ambColor = data; break; //GXSetChanAmbientcolor
case 0x100b: colChans[1].ambColor = data; break; //GXSetChanAmbientcolor case 0x100b: xfregs.colChans[1].ambColor = data; break; //GXSetChanAmbientcolor
case 0x100c: colChans[0].matColor = data; break; //GXSetChanMatcolor (rgba) case 0x100c: xfregs.colChans[0].matColor = data; break; //GXSetChanMatcolor (rgba)
case 0x100d: colChans[1].matColor = data; break; //GXSetChanMatcolor (rgba) case 0x100d: xfregs.colChans[1].matColor = data; break; //GXSetChanMatcolor (rgba)
case 0x100e: colChans[0].color.hex = data; break; //color0 case 0x100e: xfregs.colChans[0].color.hex = data; break; //color0
case 0x100f: colChans[1].color.hex = data; break; //color1 case 0x100f: xfregs.colChans[1].color.hex = data; break; //color1
case 0x1010: colChans[0].alpha.hex = data; break; //alpha0 case 0x1010: xfregs.colChans[0].alpha.hex = data; break; //alpha0
case 0x1011: colChans[1].alpha.hex = data; break; //alpha1 case 0x1011: xfregs.colChans[1].alpha.hex = data; break; //alpha1
case 0x1018: case 0x1018:
break; break;
case 0x101a: case 0x101a:
CVertexHandler::Flush(); CVertexHandler::Flush();
memcpy(rawViewPort,&pData[i],sizeof(rawViewPort)); memcpy(rawViewPort, &pData[i], sizeof(rawViewPort));
XFUpdateVP(); XFUpdateVP();
i += 6; i += 6;
break; break;
case 0x1020: case 0x1020:
CVertexHandler::Flush(); CVertexHandler::Flush();
memcpy(rawProjection,&pData[i],sizeof(rawProjection)); memcpy(rawProjection, &pData[i], sizeof(rawProjection));
XFUpdatePJ(); XFUpdatePJ();
i += 7; i += 7;
return; return;
case 0x103f: case 0x103f:
miscxf.numTexGens = data; xfregs.numTexGens = data;
break; break;
case 0x1040: texcoords[0].texmtxinfo.hex = data; break; case 0x1040: xfregs.texcoords[0].texmtxinfo.hex = data; break;
case 0x1041: texcoords[1].texmtxinfo.hex = data; break; case 0x1041: xfregs.texcoords[1].texmtxinfo.hex = data; break;
case 0x1042: texcoords[2].texmtxinfo.hex = data; break; case 0x1042: xfregs.texcoords[2].texmtxinfo.hex = data; break;
case 0x1043: texcoords[3].texmtxinfo.hex = data; break; case 0x1043: xfregs.texcoords[3].texmtxinfo.hex = data; break;
case 0x1044: texcoords[4].texmtxinfo.hex = data; break; case 0x1044: xfregs.texcoords[4].texmtxinfo.hex = data; break;
case 0x1045: texcoords[5].texmtxinfo.hex = data; break; case 0x1045: xfregs.texcoords[5].texmtxinfo.hex = data; break;
case 0x1046: texcoords[6].texmtxinfo.hex = data; break; case 0x1046: xfregs.texcoords[6].texmtxinfo.hex = data; break;
case 0x1047: texcoords[7].texmtxinfo.hex = data; break; case 0x1047: xfregs.texcoords[7].texmtxinfo.hex = data; break;
case 0x1050: texcoords[0].postmtxinfo.hex = data; break; case 0x1050: xfregs.texcoords[0].postmtxinfo.hex = data; break;
case 0x1051: texcoords[1].postmtxinfo.hex = data; break; case 0x1051: xfregs.texcoords[1].postmtxinfo.hex = data; break;
case 0x1052: texcoords[2].postmtxinfo.hex = data; break; case 0x1052: xfregs.texcoords[2].postmtxinfo.hex = data; break;
case 0x1053: texcoords[3].postmtxinfo.hex = data; break; case 0x1053: xfregs.texcoords[3].postmtxinfo.hex = data; break;
case 0x1054: texcoords[4].postmtxinfo.hex = data; break; case 0x1054: xfregs.texcoords[4].postmtxinfo.hex = data; break;
case 0x1055: texcoords[5].postmtxinfo.hex = data; break; case 0x1055: xfregs.texcoords[5].postmtxinfo.hex = data; break;
case 0x1056: texcoords[6].postmtxinfo.hex = data; break; case 0x1056: xfregs.texcoords[6].postmtxinfo.hex = data; break;
case 0x1057: texcoords[7].postmtxinfo.hex = data; break; case 0x1057: xfregs.texcoords[7].postmtxinfo.hex = data; break;
default: default:
break; break;
@ -118,9 +108,9 @@ void LoadIndexedXF(u32 val, int array)
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
int index = val>>16; int index = val >> 16;
int address = val&0xFFF; //check mask int address = val & 0xFFF; //check mask
int size = ((val>>12)&0xF)+1; int size = ((val >> 12) & 0xF)+1;
//load stuff from array to address in xf mem //load stuff from array to address in xf mem
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
xfmem[address + i] = Memory_Read_U32(arraybases[array] + arraystrides[array]*index + i*4); xfmem[address + i] = Memory_Read_U32(arraybases[array] + arraystrides[array]*index + i*4);
@ -138,9 +128,8 @@ void XFUpdatePJ()
size_t XFSaveLoadState(char *ptr, BOOL save) size_t XFSaveLoadState(char *ptr, BOOL save)
{ {
BEGINSAVELOAD; BEGINSAVELOAD;
SAVELOAD(colChans,2*sizeof(ColorChannel)); SAVELOAD(xfregs.colChans,2*sizeof(ColorChannel));
SAVELOAD(texcoords,16*sizeof(TexCoordInfo)); SAVELOAD(xfregs.texcoords,16*sizeof(TexCoordInfo));
SAVELOAD(&miscxf,sizeof(MiscXF));
SAVELOAD(rawViewPort,sizeof(rawViewPort)); SAVELOAD(rawViewPort,sizeof(rawViewPort));
SAVELOAD(rawProjection,sizeof(rawProjection)); SAVELOAD(rawProjection,sizeof(rawProjection));
SAVELOAD(xfmem,XFMEM_SIZE*sizeof(u32)); SAVELOAD(xfmem,XFMEM_SIZE*sizeof(u32));

View File

@ -3,153 +3,7 @@
#include "Common.h" #include "Common.h"
#include "Vec3.h" #include "Vec3.h"
#include "XFMemory.h"
#pragma pack(4)
//////////////////////////////////////////////////////////////////////////
// Lighting
//////////////////////////////////////////////////////////////////////////
#define XF_TEX_ST 0x00000000
#define XF_TEX_STQ 0x00000001
#define XF_TEX_AB11 0x00000000
#define XF_TEX_ABC1 0x00000001
#define XF_TEXGEN_REGULAR 0x00000000
#define XF_TEXGEN_EMBOSS_MAP 0x00000001
#define XF_TEXGEN_COLOR_STRGBC0 0x00000002
#define XF_TEXGEN_COLOR_STRGBC1 0x00000003
#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
struct Light
{
u32 useless[3];
//Vec3 direction;
u32 color; //rgba
float a0; //attenuation
float a1;
float a2;
float k0; //k stuff
float k1;
float k2;
union
{
struct {
Vec3 dpos;
Vec3 ddir;
};
struct {
Vec3 sdir;
Vec3 shalfangle;
};
};
};
#define GX_SRC_REG 0
#define GX_SRC_VTX 1
union LitChannel
{
struct
{
unsigned matsource : 1;
unsigned enablelighting : 1;
unsigned lightMask0_3 : 4;
unsigned ambsource : 1;
unsigned diffusefunc : 2; //0=none 1=sign 2=clamp
unsigned attnfunc : 2; //1=spec 3=spot 2=none ???
unsigned lightMask4_7 : 4;
};
u32 hex;
unsigned int GetFullLightMask()
{
return lightMask0_3 | (lightMask4_7 << 4);
}
};
struct ColorChannel
{
u32 ambColor;
u32 matColor;
LitChannel color;
LitChannel alpha;
};
struct MiscXF
{
int numTexGens;
};
union TexMtxInfo
{
struct
{
unsigned unknown : 1;
unsigned projection : 1;
unsigned inputform : 2; //1 if three-component, 0 if two-component ?
unsigned texgentype : 3; //0-POS 1-NRM 3-BINRM 4-TANGENT 5-TEX0 ...12-TEX7 13-COLOR
unsigned sourcerow : 5;
unsigned embosssourceshift : 3;
unsigned embosslightshift : 3;
};
u32 hex;
};
union PostMtxInfo
{
struct
{
unsigned index : 8;
unsigned normalize : 1;
};
u32 hex;
};
struct TexCoordInfo
{
TexMtxInfo texmtxinfo;
PostMtxInfo postmtxinfo;
};
struct Viewport
{
float wd;
float ht;
float nearZ;
float xOrig;
float yOrig;
float farZ;
};
#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];
extern ColorChannel colChans[2]; //C0A0 C1A1
extern MiscXF miscxf;
extern unsigned __int32 xfmem[XFMEM_SIZE];
extern float rawViewPort[6]; extern float rawViewPort[6];
extern float rawProjection[7]; extern float rawProjection[7];

View File

@ -20,6 +20,7 @@
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "Render.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "TextureMngr.h" #include "TextureMngr.h"
#include "TextureDecoder.h" #include "TextureDecoder.h"

View File

@ -24,13 +24,6 @@
#include <assert.h> #include <assert.h>
int frameCount; int frameCount;
int lut3to8[8];
int lut4to8[16];
int lut5to8[32];
int lut6to8[64];
float lutu8tosfloat[256];
float lutu8toufloat[256];
float luts8tosfloat[256];
int g_Res[NUMWNDRES][2] = int g_Res[NUMWNDRES][2] =
{ {
@ -50,25 +43,6 @@ void Statistics::ResetFrame()
memset(&thisFrame,0,sizeof(ThisFrame)); memset(&thisFrame,0,sizeof(ThisFrame));
} }
void InitLUTs()
{
int i;
for (i=0; i<8; i++)
lut3to8[i] = (i*255)/7;
for (i=0; i<16; i++)
lut4to8[i] = (i*255)/15;
for (i=0; i<32; i++)
lut5to8[i] = (i*255)/31;
for (i=0; i<64; i++)
lut6to8[i] = (i*255)/63;
for (i=0; i<256; i++)
{
lutu8tosfloat[i] = (float)(i-128)/127.0f;
lutu8toufloat[i] = (float)(i)/255.0f;
luts8tosfloat[i] = ((float)(signed char)(char)i) / 127.0f;
}
}
Config::Config() Config::Config()
{ {
memset(this, 0, sizeof(Config)); memset(this, 0, sizeof(Config));

View File

@ -128,20 +128,7 @@ struct RECT
#define SAVELOAD(what,size) memcpy((void*)((save)?(void*)(ptr):(void*)(what)),(void*)((save)?(void*)(what):(void*)(ptr)),(size)); ptr+=(size); #define SAVELOAD(what,size) memcpy((void*)((save)?(void*)(ptr):(void*)(what)),(void*)((save)?(void*)(what):(void*)(ptr)),(size)); ptr+=(size);
#define ENDSAVELOAD return ptr-optr; #define ENDSAVELOAD return ptr-optr;
struct TEXTUREFMT
{
TEXTUREFMT(GLenum format, GLenum type) : type(type), format(format) {}
GLenum type, format;
};
extern int frameCount; extern int frameCount;
extern int lut3to8[8];
extern int lut4to8[16];
extern int lut5to8[32];
extern int lut6to8[64];
extern float lutu8tosfloat[256];
extern float lutu8toufloat[256];
extern float luts8tosfloat[256];
#define NUMWNDRES 6 #define NUMWNDRES 6
extern int g_Res[NUMWNDRES][2]; extern int g_Res[NUMWNDRES][2];

View File

@ -16,12 +16,13 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h" #include "Globals.h"
#include <cmath> #include <cmath>
#include <assert.h> #include <assert.h>
#include "PixelShader.h" #include "PixelShader.h"
#include "VertexShader.h" // for texture projection mode #include "XFMemory.h" // for texture projection mode
#include "PixelShaderManager.h" #include "BPMemory.h"
// old tev->pixelshader notes // old tev->pixelshader notes
// //
@ -32,8 +33,8 @@
// output is given by .outreg // output is given by .outreg
// tevtemp is set according to swapmodetables and // tevtemp is set according to swapmodetables and
void WriteStage(char *&p, int n); void WriteStage(char *&p, int n, u32 texture_mask);
void WrapNonPow2Tex(char* &p, const char* var, int texmap); void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask);
void WriteAlphaCompare(char *&p, int num, int comp); void WriteAlphaCompare(char *&p, int num, int comp);
bool WriteAlphaTest(char *&p); bool WriteAlphaTest(char *&p);
@ -234,14 +235,14 @@ const char *tevRasTable[] =
const char *tevTexFunc[] = { "tex2D", "texRECT" }; const char *tevTexFunc[] = { "tex2D", "texRECT" };
const char *tevCOutputTable[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" }; const char *tevCOutputTable[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" };
const char *tevAOutputTable[] = { "prev.a", "c0.a", "c1.a", "c2.a" }; const char *tevAOutputTable[] = { "prev.a", "c0.a", "c1.a", "c2.a" };
const char* tevIndAlphaSel[] = {"", "x", "y", "z"}; const char* tevIndAlphaSel[] = {"", "x", "y", "z"};
const char* tevIndAlphaScale[] = {"", "*32","*16","*8"}; const char* tevIndAlphaScale[] = {"", "*32","*16","*8"};
const char* tevIndBiasField[] = {"", "x", "y", "xy", "z", "xz", "yz", "xyz"}; // indexed by bias const char* tevIndBiasField[] = {"", "x", "y", "xy", "z", "xz", "yz", "xyz"}; // indexed by bias
const char* tevIndBiasAdd[] = {"-128.0f", "1.0f", "1.0f", "1.0f" }; // indexed by fmt const char* tevIndBiasAdd[] = {"-128.0f", "1.0f", "1.0f", "1.0f" }; // indexed by fmt
const char* tevIndWrapStart[] = {"0", "256", "128", "64", "32", "16", "0.001" }; const char* tevIndWrapStart[] = {"0", "256", "128", "64", "32", "16", "0.001" };
const char* tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" }; const char* tevIndFmtScale[] = {"255.0f", "31.0f", "15.0f", "8.0f" };
#define WRITE p+=sprintf #define WRITE p+=sprintf
@ -251,7 +252,7 @@ char swapModeTable[4][5];
void BuildSwapModeTable() void BuildSwapModeTable()
{ {
//bpmem.tevregs[0]. //bpmem.tevregs[0].
for (int i=0; i<4; i++) for (int i = 0; i < 4; i++)
{ {
swapModeTable[i][0]=swapColors[bpmem.tevksel[i*2].swap1]; swapModeTable[i][0]=swapColors[bpmem.tevksel[i*2].swap1];
swapModeTable[i][1]=swapColors[bpmem.tevksel[i*2].swap2]; swapModeTable[i][1]=swapColors[bpmem.tevksel[i*2].swap2];
@ -262,7 +263,7 @@ void BuildSwapModeTable()
} }
static char text[16384]; static char text[16384];
bool GeneratePixelShader(FRAGMENTSHADER& ps) char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0)
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
@ -275,11 +276,11 @@ bool GeneratePixelShader(FRAGMENTSHADER& ps)
WRITE(p,"//%i TEV stages, %i texgens, %i IND stages\n", WRITE(p,"//%i TEV stages, %i texgens, %i IND stages\n",
numStages,numTexgen,bpmem.genMode.numindstages); numStages,numTexgen,bpmem.genMode.numindstages);
bool bRenderZ = Renderer::GetZBufferTarget() != 0 && bpmem.zmode.updateenable; bool bRenderZ = has_zbuffer_target && bpmem.zmode.updateenable;
bool bOutputZ = bpmem.ztex2.op != ZTEXTURE_DISABLE; bool bOutputZ = bpmem.ztex2.op != ZTEXTURE_DISABLE;
bool bInputZ = bpmem.ztex2.op==ZTEXTURE_ADD || bRenderZ; bool bInputZ = bpmem.ztex2.op==ZTEXTURE_ADD || bRenderZ;
bool bRenderZToCol0 = Renderer::GetRenderMode()!=Renderer::RM_Normal; // output z and alpha to color0 // bool bRenderZToCol0 = ; // output z and alpha to color0
assert( !bRenderZToCol0 || bRenderZ ); assert( !bRenderZToCol0 || bRenderZ );
int ztexcoord = -1; int ztexcoord = -1;
@ -296,11 +297,11 @@ bool GeneratePixelShader(FRAGMENTSHADER& ps)
} }
// samplers // samplers
if( s_texturemask ) { if( texture_mask ) {
WRITE(p,"uniform samplerRECT "); WRITE(p,"uniform samplerRECT ");
bool bfirst = true; bool bfirst = true;
for(int i = 0; i < 8; ++i) { for(int i = 0; i < 8; ++i) {
if( s_texturemask & (1<<i) ) { if( texture_mask & (1<<i) ) {
WRITE(p, "%s samp%d : register(s%d)", bfirst?"":",", i, i); WRITE(p, "%s samp%d : register(s%d)", bfirst?"":",", i, i);
bfirst = false; bfirst = false;
} }
@ -308,11 +309,11 @@ bool GeneratePixelShader(FRAGMENTSHADER& ps)
WRITE(p, ";\n"); WRITE(p, ";\n");
} }
if( s_texturemask != 0xff ) { if( texture_mask != 0xff ) {
WRITE(p,"uniform sampler2D "); WRITE(p,"uniform sampler2D ");
bool bfirst = true; bool bfirst = true;
for(int i = 0; i < 8; ++i) { for(int i = 0; i < 8; ++i) {
if( !(s_texturemask & (1<<i)) ) { if( !(texture_mask & (1<<i)) ) {
WRITE(p, "%s samp%d : register(s%d)", bfirst?"":",",i, i); WRITE(p, "%s samp%d : register(s%d)", bfirst?"":",",i, i);
bfirst = false; bfirst = false;
} }
@ -378,13 +379,13 @@ bool GeneratePixelShader(FRAGMENTSHADER& ps)
// note that we have to scale by the regular texture map's coordinates since this is a texRECT call // note that we have to scale by the regular texture map's coordinates since this is a texRECT call
// (and we have to match with the game's texscale calls) // (and we have to match with the game's texscale calls)
int texcoord = bpmem.tevindref.getTexCoord(i); int texcoord = bpmem.tevindref.getTexCoord(i);
if( s_texturemask & (1<<bpmem.tevindref.getTexMap(i)) ) { if( texture_mask & (1<<bpmem.tevindref.getTexMap(i)) ) {
// TODO - Buggy? "Too many arguments for format" // TODO - Buggy? "Too many arguments for format"
WRITE(p, "float2 induv%d=uv%d.xy * "I_INDTEXSCALE"[%d].%s;\n", i, texcoord, i/2, (i&1)?"zw":"xy",bpmem.tevindref.getTexMap(i)); WRITE(p, "float2 induv%d=uv%d.xy * "I_INDTEXSCALE"[%d].%s;\n", i, texcoord, i/2, (i&1)?"zw":"xy",bpmem.tevindref.getTexMap(i));
char str[16]; char str[16];
sprintf(str, "induv%d", i); sprintf(str, "induv%d", i);
WrapNonPow2Tex(p, str, bpmem.tevindref.getTexMap(i)); WrapNonPow2Tex(p, str, bpmem.tevindref.getTexMap(i), texture_mask);
WRITE(p,"float3 indtex%d=texRECT(samp%d,induv%d.xy).abg;\n", i, bpmem.tevindref.getTexMap(i), i); WRITE(p,"float3 indtex%d=texRECT(samp%d,induv%d.xy).abg;\n", i, bpmem.tevindref.getTexMap(i), i);
} }
else { else {
@ -393,8 +394,8 @@ bool GeneratePixelShader(FRAGMENTSHADER& ps)
} }
} }
for (int i=0; i<numStages; i++) for (int i = 0; i < numStages; i++)
WriteStage(p,i); //build the equation for this stage WriteStage(p, i, texture_mask); //build the equation for this stage
if( bOutputZ ) { if( bOutputZ ) {
// use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format... // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format...
@ -442,10 +443,10 @@ bool GeneratePixelShader(FRAGMENTSHADER& ps)
WRITE(p,"}\n\0"); WRITE(p,"}\n\0");
return PixelShaderMngr::CompilePixelShader(ps, text); return text;
} }
void WriteStage(char *&p, int n) void WriteStage(char *&p, int n, u32 texture_mask)
{ {
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap]; char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap]; char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
@ -456,7 +457,7 @@ void WriteStage(char *&p, int n)
int texfun = xfregs.texcoords[texcoord].texmtxinfo.projection; int texfun = xfregs.texcoords[texcoord].texmtxinfo.projection;
bool bHasIndStage = bpmem.tevind[n].IsActive() && bpmem.tevind[n].bt < bpmem.genMode.numindstages; bool bHasIndStage = bpmem.tevind[n].IsActive() && bpmem.tevind[n].bt < bpmem.genMode.numindstages;
if( bHasIndStage ) { if (bHasIndStage) {
// perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords // perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords
bHasIndStage = true; bHasIndStage = true;
int texmap = bpmem.tevorders[n/2].getEnable(n&1) ? bpmem.tevorders[n/2].getTexMap(n&1) : bpmem.tevindref.getTexMap(bpmem.tevind[n].bt); int texmap = bpmem.tevorders[n/2].getEnable(n&1) ? bpmem.tevorders[n/2].getTexMap(n&1) : bpmem.tevindref.getTexMap(bpmem.tevind[n].bt);
@ -496,7 +497,7 @@ void WriteStage(char *&p, int n)
} }
// wrapping // wrapping
if( !bpmem.tevorders[n/2].getEnable(n&1) || (s_texturemask & (1<<texmap)) ) { if( !bpmem.tevorders[n/2].getEnable(n&1) || (texture_mask & (1<<texmap)) ) {
// non pow2 // non pow2
if( bpmem.tevind[n].sw != ITW_OFF || bpmem.tevind[n].tw != ITW_OFF ) { if( bpmem.tevind[n].sw != ITW_OFF || bpmem.tevind[n].tw != ITW_OFF ) {
@ -577,17 +578,16 @@ void WriteStage(char *&p, int n)
WRITE(p,"rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap); WRITE(p,"rastemp=%s.%s;\n",tevRasTable[bpmem.tevorders[n/2].getColorChan(n&1)],rasswap);
if (bpmem.tevorders[n/2].getEnable(n&1)) { if (bpmem.tevorders[n/2].getEnable(n&1)) {
int texmap = bpmem.tevorders[n/2].getTexMap(n&1); int texmap = bpmem.tevorders[n/2].getTexMap(n&1);
if(!bHasIndStage) { if(!bHasIndStage) {
// calc tevcord // calc tevcord
if( s_texturemask & (1<<texmap) ) { if( texture_mask & (1<<texmap) ) {
// nonpow2 // nonpow2
if( texfun == XF_TEXPROJ_STQ ) if( texfun == XF_TEXPROJ_STQ )
WRITE(p,"tevcoord.xy = uv%d.xy / uv%d.z;\n", texcoord, texcoord); WRITE(p,"tevcoord.xy = uv%d.xy / uv%d.z;\n", texcoord, texcoord);
else else
WRITE(p,"tevcoord.xy = uv%d.xy;\n", texcoord); WRITE(p,"tevcoord.xy = uv%d.xy;\n", texcoord);
WrapNonPow2Tex(p, "tevcoord", texmap); WrapNonPow2Tex(p, "tevcoord", texmap, texture_mask);
} }
else { else {
if( texfun == XF_TEXPROJ_STQ ) { if( texfun == XF_TEXPROJ_STQ ) {
@ -598,11 +598,11 @@ void WriteStage(char *&p, int n)
} }
} }
} }
else if( s_texturemask & (1<<texmap) ) { else if( texture_mask & (1<<texmap) ) {
// if non pow 2, have to manually repeat // if non pow 2, have to manually repeat
//WrapNonPow2Tex(p, "tevcoord", texmap); //WrapNonPow2Tex(p, "tevcoord", texmap);
bool bwraps = !!(s_texturemask & (0x100<<texmap)); bool bwraps = !!(texture_mask & (0x100<<texmap));
bool bwrapt = !!(s_texturemask & (0x10000<<texmap)); bool bwrapt = !!(texture_mask & (0x10000<<texmap));
if( bwraps || bwrapt ) { if( bwraps || bwrapt ) {
const char* field = bwraps ? (bwrapt ? "xy" : "x") : "y"; const char* field = bwraps ? (bwrapt ? "xy" : "x") : "y";
@ -610,7 +610,7 @@ void WriteStage(char *&p, int n)
} }
} }
if( s_texturemask & (1<<texmap) ) if( texture_mask & (1<<texmap) )
WRITE(p,"textemp=texRECT(samp%d,tevcoord.xy).%s;\n", texmap, texswap); WRITE(p,"textemp=texRECT(samp%d,tevcoord.xy).%s;\n", texmap, texswap);
else else
WRITE(p,"textemp=tex2D(samp%d,tevcoord.xy).%s;\n", texmap, texswap); WRITE(p,"textemp=tex2D(samp%d,tevcoord.xy).%s;\n", texmap, texswap);
@ -720,11 +720,11 @@ void WriteStage(char *&p, int n)
WRITE(p, "\n"); WRITE(p, "\n");
} }
void WrapNonPow2Tex(char* &p, const char* var, int texmap) void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask)
{ {
_assert_(s_texturemask & (1<<texmap)); _assert_(texture_mask & (1<<texmap));
bool bwraps = !!(s_texturemask & (0x100<<texmap)); bool bwraps = !!(texture_mask & (0x100<<texmap));
bool bwrapt = !!(s_texturemask & (0x10000<<texmap)); bool bwrapt = !!(texture_mask & (0x10000<<texmap));
if( bwraps || bwrapt ) { if( bwraps || bwrapt ) {
const char* field = bwraps ? (bwrapt ? "xy" : "x") : "y"; const char* field = bwraps ? (bwrapt ? "xy" : "x") : "y";

View File

@ -18,8 +18,7 @@
#ifndef GCOGL_PIXELSHADER #ifndef GCOGL_PIXELSHADER
#define GCOGL_PIXELSHADER #define GCOGL_PIXELSHADER
#include "Render.h" #include "Common.h"
#include "BPStructs.h"
#define I_COLORS "color" #define I_COLORS "color"
#define I_KCOLORS "k" #define I_KCOLORS "k"
@ -40,16 +39,6 @@
#define C_COLORMATRIX (C_INDTEXMTX+6) #define C_COLORMATRIX (C_INDTEXMTX+6)
struct FRAGMENTSHADER char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0);
{
FRAGMENTSHADER() : glprogid(0) { }
GLuint glprogid; // opengl program id
#ifdef _DEBUG
std::string strprog;
#endif
};
bool GeneratePixelShader(FRAGMENTSHADER& ps);
#endif #endif

View File

@ -20,6 +20,7 @@
#include <cmath> #include <cmath>
#include "Common.h" #include "Common.h"
#include "Render.h"
#include "VertexShader.h" #include "VertexShader.h"
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "PixelShader.h" #include "PixelShader.h"
@ -47,6 +48,14 @@ static u32 maptocoord_mask=0;
static GLuint s_ColorMatrixProgram=0; static GLuint s_ColorMatrixProgram=0;
void PixelShaderMngr::SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4) {
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f1, f2, f3, f4);
}
void PixelShaderMngr::SetPSConstant4fv(int const_number, const float *f) {
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number, f);
}
void PixelShaderMngr::Init() void PixelShaderMngr::Init()
{ {
s_nColorsChanged[0] = s_nColorsChanged[1] = 0; s_nColorsChanged[0] = s_nColorsChanged[1] = 0;
@ -119,7 +128,10 @@ FRAGMENTSHADER* PixelShaderMngr::GetShader()
PSCacheEntry& newentry = pshaders[uid]; PSCacheEntry& newentry = pshaders[uid];
if (!GeneratePixelShader(newentry.shader)) { char *code = GeneratePixelShader(s_texturemask,
Renderer::GetZBufferTarget() != 0,
Renderer::GetRenderMode() != Renderer::RM_Normal);
if (!code || !CompilePixelShader(newentry.shader, code)) {
ERROR_LOG("failed to create pixel shader\n"); ERROR_LOG("failed to create pixel shader\n");
return NULL; return NULL;
} }
@ -218,7 +230,7 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
int baseind = i?C_KCOLORS:C_COLORS; int baseind = i?C_KCOLORS:C_COLORS;
for(int j = 0; j < 4; ++j) { for(int j = 0; j < 4; ++j) {
if( s_nColorsChanged[i] & (1<<j) ) { if( s_nColorsChanged[i] & (1<<j) ) {
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, baseind+j, &lastRGBAfull[i][j][0]); SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]);
} }
} }
s_nColorsChanged[i] = 0; s_nColorsChanged[i] = 0;
@ -283,13 +295,13 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
} }
PRIM_LOG("texdims%d: %f %f %f %f\n", i, fdims[0], fdims[1], fdims[2], fdims[3]); PRIM_LOG("texdims%d: %f %f %f %f\n", i, fdims[0], fdims[1], fdims[2], fdims[3]);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_TEXDIMS+i, fdims); SetPSConstant4fv(C_TEXDIMS + i, fdims);
} }
s_nTexDimsChanged[0] = s_nTexDimsChanged[1] = -1; s_nTexDimsChanged[0] = s_nTexDimsChanged[1] = -1;
} }
if( s_bAlphaChanged ) { if( s_bAlphaChanged ) {
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f); SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f);
} }
if( s_bZBiasChanged ) { if( s_bZBiasChanged ) {
@ -311,8 +323,8 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
break; break;
} }
//ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias); //ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_ZBIAS, ftemp); SetPSConstant4fv(C_ZBIAS, ftemp);
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, C_ZBIAS+1, 0, 0, 0, (float)( (((int)lastZBias<<8)>>8))/16777216.0f); SetPSConstant4f(C_ZBIAS+1, 0, 0, 0, (float)( (((int)lastZBias<<8)>>8))/16777216.0f);
} }
// indirect incoming texture scales, update all! // indirect incoming texture scales, update all!
@ -330,10 +342,10 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2*i], f[2*i+1]); PRIM_LOG("tex indscale%d: %f %f\n", i, f[2*i], f[2*i+1]);
} }
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_INDTEXSCALE, f); SetPSConstant4fv(C_INDTEXSCALE, f);
if( bpmem.genMode.numindstages > 2 ) if( bpmem.genMode.numindstages > 2 )
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_INDTEXSCALE+1, &f[4]); SetPSConstant4fv(C_INDTEXSCALE+1, &f[4]);
s_bIndTexScaleChanged = false; s_bIndTexScaleChanged = false;
} }
@ -346,9 +358,9 @@ void PixelShaderMngr::SetConstants(FRAGMENTSHADER& ps)
// xyz - static matrix // xyz - static matrix
//TODO w - dynamic matrix scale / 256...... somehow / 4 works better //TODO w - dynamic matrix scale / 256...... somehow / 4 works better
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, C_INDTEXMTX+2*i, SetPSConstant4f(C_INDTEXMTX+2*i,
bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, bpmem.indmtx[i].col2.me * fscale, fscale * 256.0f); bpmem.indmtx[i].col0.ma * fscale, bpmem.indmtx[i].col1.mc * fscale, bpmem.indmtx[i].col2.me * fscale, fscale * 256.0f);
glProgramEnvParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, C_INDTEXMTX+2*i+1, SetPSConstant4f(C_INDTEXMTX+2*i+1,
bpmem.indmtx[i].col0.mb * fscale, bpmem.indmtx[i].col1.md * fscale, bpmem.indmtx[i].col2.mf * fscale, fscale * 256.0f); bpmem.indmtx[i].col0.mb * fscale, bpmem.indmtx[i].col1.md * fscale, bpmem.indmtx[i].col2.mf * fscale, fscale * 256.0f);
PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n", i, PRIM_LOG("indmtx%d: scale=%f, mat=(%f %f %f; %f %f %f)\n", i,
@ -470,11 +482,11 @@ void PixelShaderMngr::SetTexDimsChanged(int texmapid)
void PixelShaderMngr::SetColorMatrix(const float* pmatrix, const float* pfConstAdd) void PixelShaderMngr::SetColorMatrix(const float* pmatrix, const float* pfConstAdd)
{ {
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_COLORMATRIX, pmatrix); SetPSConstant4fv(C_COLORMATRIX, pmatrix);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_COLORMATRIX+1, pmatrix+4); SetPSConstant4fv(C_COLORMATRIX+1, pmatrix+4);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_COLORMATRIX+2, pmatrix+8); SetPSConstant4fv(C_COLORMATRIX+2, pmatrix+8);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_COLORMATRIX+3, pmatrix+12); SetPSConstant4fv(C_COLORMATRIX+3, pmatrix+12);
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, C_COLORMATRIX+4, pfConstAdd); SetPSConstant4fv(C_COLORMATRIX+4, pfConstAdd);
} }
GLuint PixelShaderMngr::GetColorMatrixProgram() GLuint PixelShaderMngr::GetColorMatrixProgram()

View File

@ -20,8 +20,19 @@
#include "PixelShader.h" #include "PixelShader.h"
extern u32 s_texturemask; #include "BPMemory.h"
#include <map>
struct FRAGMENTSHADER
{
FRAGMENTSHADER() : glprogid(0) { }
GLuint glprogid; // opengl program id
#ifdef _DEBUG
std::string strprog;
#endif
};
class PixelShaderMngr class PixelShaderMngr
{ {
class PIXELSHADERUID class PIXELSHADERUID
@ -110,6 +121,8 @@ class PixelShaderMngr
static void GetPixelShaderId(PIXELSHADERUID&); static void GetPixelShaderId(PIXELSHADERUID&);
static PIXELSHADERUID s_curuid; // the current pixel shader uid (progressively changed as memory is written) static PIXELSHADERUID s_curuid; // the current pixel shader uid (progressively changed as memory is written)
static void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4);
static void SetPSConstant4fv(int const_number, const float *f);
public: public:
static void Init(); static void Init();
static void Cleanup(); static void Cleanup();

View File

@ -19,19 +19,20 @@
#include "Common.h" #include "Common.h"
#include "TextureDecoder.h" #include "TextureDecoder.h"
#include "LookUpTables.h"
// TRAM // TRAM
u8 texMem[TMEM_SIZE]; u8 texMem[TMEM_SIZE];
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Gamecube texture decoder // Gamecube/Wii texture decoder
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Decodes all known Gamecube texture formats. // Decodes all known Gamecube/Wii texture formats.
// by ector // by ector
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
int TexDecoder_GetTexelSizeInNibbles(int format) int TexDecoder_GetTexelSizeInNibbles(int format)
{ {
switch(format&0x3f) { switch (format & 0x3f) {
case GX_TF_I4: return 1; case GX_TF_I4: return 1;
case GX_TF_I8: return 2; case GX_TF_I8: return 2;
case GX_TF_IA4: return 2; case GX_TF_IA4: return 2;
@ -49,7 +50,7 @@ int TexDecoder_GetTexelSizeInNibbles(int format)
int TexDecoder_GetBlockWidthInTexels(int format) int TexDecoder_GetBlockWidthInTexels(int format)
{ {
switch(format) { switch (format) {
case GX_TF_I4: return 8; case GX_TF_I4: return 8;
case GX_TF_I8: return 8; case GX_TF_I8: return 8;
case GX_TF_IA4: return 8; case GX_TF_IA4: return 8;
@ -80,9 +81,9 @@ int TexDecoder_GetPaletteSize(int format)
inline u32 decode565(u16 val) inline u32 decode565(u16 val)
{ {
int r,g,b,a; int r,g,b,a;
r=lut5to8[(val>>11)&0x1f]; r=lut5to8[(val>>11) & 0x1f];
g=lut6to8[(val>>5 )&0x3f]; g=lut6to8[(val>>5 ) & 0x3f];
b=lut5to8[(val )&0x1f]; b=lut5to8[(val ) & 0x1f];
a=0xFF; a=0xFF;
return (a<<24) | (r<<16) | (g<<8) | b; return (a<<24) | (r<<16) | (g<<8) | b;
} }
@ -100,17 +101,17 @@ inline u32 decode5A3(u16 val)
int r,g,b,a; int r,g,b,a;
if ((val&0x8000)) if ((val&0x8000))
{ {
r=lut5to8[(val>>10)&0x1f]; r=lut5to8[(val>>10) & 0x1f];
g=lut5to8[(val>>5 )&0x1f]; g=lut5to8[(val>>5 ) & 0x1f];
b=lut5to8[(val )&0x1f]; b=lut5to8[(val ) & 0x1f];
a=0xFF; a=0xFF;
} }
else else
{ {
a=lut3to8[(val>>12)&0x7]; a=lut3to8[(val>>12) & 0x7];
r=lut4to8[(val>>8 )&0xf]; r=lut4to8[(val>>8 ) & 0xf];
g=lut4to8[(val>>4 )&0xf]; g=lut4to8[(val>>4 ) & 0xf];
b=lut4to8[(val )&0xf]; b=lut4to8[(val ) & 0xf];
} }
return (a<<24) | (r<<16) | (g<<8) | b; return (a<<24) | (r<<16) | (g<<8) | b;
} }
@ -132,7 +133,7 @@ inline int expand8888(const int j)
inline void decodebytesI4(u32 *dst, u8 *src, int numbytes) inline void decodebytesI4(u32 *dst, u8 *src, int numbytes)
{ {
for (int x=0; x<numbytes; x++) for (int x = 0; x < numbytes; x++)
{ {
int val = src[x]; int val = src[x];
*dst++ = expand8888(lut4to8[val>>4]); *dst++ = expand8888(lut4to8[val>>4]);
@ -142,28 +143,28 @@ inline void decodebytesI4(u32 *dst, u8 *src, int numbytes)
inline void decodebytesI8(u32 *dst, u8 *src, int numbytes) inline void decodebytesI8(u32 *dst, u8 *src, int numbytes)
{ {
for (int x=0; x<numbytes; x++) for (int x = 0; x < numbytes; x++)
*dst++ = expand8888(src[x]); //asm bswap loop? *dst++ = expand8888(src[x]);
} }
inline void decodebytesC4(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlutfmt) inline void decodebytesC4(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlutfmt)
{ {
u16 *tlut = (u16*)(texMem+tlutaddr); u16 *tlut = (u16*)(texMem + tlutaddr);
for (int x=0; x<numbytes; x++) for (int x = 0; x < numbytes; x++)
{ {
int val = src[x]; int val = src[x];
switch(tlutfmt) { switch (tlutfmt) {
case 0: case 0:
*dst++ = decodeIA8(Common::swap16(tlut[(val>>4)])); *dst++ = decodeIA8(Common::swap16(tlut[val >> 4]));
*dst++ = decodeIA8(Common::swap16(tlut[(val&15)])); *dst++ = decodeIA8(Common::swap16(tlut[val & 15]));
break; break;
case 1: case 1:
*dst++ = decode565(Common::swap16(tlut[(val>>4)])); *dst++ = decode565(Common::swap16(tlut[val >> 4]));
*dst++ = decode565(Common::swap16(tlut[(val&15)])); *dst++ = decode565(Common::swap16(tlut[val & 15]));
break; break;
case 2: case 2:
*dst++ = decode5A3(Common::swap16(tlut[(val>>4)])); *dst++ = decode5A3(Common::swap16(tlut[val >> 4]));
*dst++ = decode5A3(Common::swap16(tlut[(val&15)])); *dst++ = decode5A3(Common::swap16(tlut[val & 15]));
break; break;
case 3: //ERROR case 3: //ERROR
*dst++ = 0xFFFF00FF; *dst++ = 0xFFFF00FF;
@ -176,10 +177,10 @@ inline void decodebytesC4(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlu
inline void decodebytesC8(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlutfmt) inline void decodebytesC8(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlutfmt)
{ {
u16 *tlut = (u16*)(texMem+tlutaddr); u16 *tlut = (u16*)(texMem+tlutaddr);
for (int x=0; x<numbytes; x++) for (int x = 0; x < numbytes; x++)
{ {
int val = src[x]; int val = src[x];
switch(tlutfmt) { switch (tlutfmt) {
case 0: case 0:
*dst++ = decodeIA8(Common::swap16(tlut[val])); *dst++ = decodeIA8(Common::swap16(tlut[val]));
break; break;
@ -200,10 +201,10 @@ inline void decodebytesC8(u32 *dst, u8 *src, int numbytes, int tlutaddr, int tlu
inline void decodebytesC14X2(u32 *dst, u16 *src, int numpixels, int tlutaddr, int tlutfmt) inline void decodebytesC14X2(u32 *dst, u16 *src, int numpixels, int tlutaddr, int tlutfmt)
{ {
u16 *tlut = (u16*)(texMem+tlutaddr); u16 *tlut = (u16*)(texMem+tlutaddr);
for (int x=0; x<numpixels; x++) for (int x = 0; x < numpixels; x++)
{ {
int val = Common::swap16(src[x]); int val = Common::swap16(src[x]);
switch(tlutfmt) { switch (tlutfmt) {
case 0: case 0:
*dst++ = decodeIA8(Common::swap16(tlut[(val&0x3FFF)])); *dst++ = decodeIA8(Common::swap16(tlut[(val&0x3FFF)]));
break; break;
@ -222,13 +223,13 @@ inline void decodebytesC14X2(u32 *dst, u16 *src, int numpixels, int tlutaddr, in
inline void decodebytesRGB565(u32 *dst, u16 *src, int numpixels) inline void decodebytesRGB565(u32 *dst, u16 *src, int numpixels)
{ {
for (int x=0; x<numpixels; x++) for (int x = 0; x < numpixels; x++)
*dst++ = decode565(Common::swap16(src[x])); *dst++ = decode565(Common::swap16(src[x]));
} }
inline void decodebytesIA4(u32 *dst, u8 *src, int numbytes) inline void decodebytesIA4(u32 *dst, u8 *src, int numbytes)
{ {
for (int x=0; x<numbytes; x++) for (int x = 0; x < numbytes; x++)
{ {
int val = src[x]; int val = src[x];
@ -240,19 +241,19 @@ inline void decodebytesIA4(u32 *dst, u8 *src, int numbytes)
inline void decodebytesIA8(u32 *dst, u16 *src, int numpixels) inline void decodebytesIA8(u32 *dst, u16 *src, int numpixels)
{ {
for (int x=0; x<numpixels; x++) for (int x = 0; x < numpixels; x++)
*dst++ = decodeIA8(Common::swap16(src[x])); *dst++ = decodeIA8(Common::swap16(src[x]));
} }
inline void decodebytesRGB5A3(u32 *dst, u16 *src, int numpixels) inline void decodebytesRGB5A3(u32 *dst, u16 *src, int numpixels)
{ {
for (int x=0; x<numpixels; x++) for (int x = 0; x < numpixels; x++)
*dst++ = decode5A3(Common::swap16(src[x])); *dst++ = decode5A3(Common::swap16(src[x]));
} }
inline void decodebytesARGB8pass1(u32 *dst, u16 *src, int numpixels) inline void decodebytesARGB8pass1(u32 *dst, u16 *src, int numpixels)
{ {
for (int x=0; x<numpixels; x++) for (int x = 0; x < numpixels; x++)
{ {
int val = Common::swap16(src[x]); int val = Common::swap16(src[x]);
int a=val&0xFF; int a=val&0xFF;
@ -264,7 +265,7 @@ inline void decodebytesARGB8pass1(u32 *dst, u16 *src, int numpixels)
inline void decodebytesARGB8pass2(u32 *dst, u16 *src, int numpixels) inline void decodebytesARGB8pass2(u32 *dst, u16 *src, int numpixels)
{ {
for (int x=0; x<numpixels; x++) for (int x = 0; x < numpixels; x++)
{ {
int val = Common::swap16(src[x]); int val = Common::swap16(src[x]);
int a=val&0xFF; int a=val&0xFF;
@ -274,12 +275,11 @@ inline void decodebytesARGB8pass2(u32 *dst, u16 *src, int numpixels)
} }
} }
inline u32 makecol(int r,int g,int b,int a) inline u32 makecol(int r, int g, int b, int a)
{ {
return ((a&255)<<24)|((r&255)<<16)|((g&255)<<8)|((b&255)); return ((a&255)<<24)|((r&255)<<16)|((g&255)<<8)|((b&255));
} }
//this needs to be FAST, used by some games realtime video //this needs to be FAST, used by some games realtime video
//TODO: port to ASM or intrinsics //TODO: port to ASM or intrinsics
void decodeDXTBlock(u32 *dst, DXTBlock *src, int pitch) void decodeDXTBlock(u32 *dst, DXTBlock *src, int pitch)
@ -288,37 +288,37 @@ void decodeDXTBlock(u32 *dst, DXTBlock *src, int pitch)
u16 c2 = Common::swap16(src->color2); u16 c2 = Common::swap16(src->color2);
int blue1 = lut5to8[c1&0x1F]; int blue1 = lut5to8[c1&0x1F];
int blue2 = lut5to8[c2&0x1F]; int blue2 = lut5to8[c2&0x1F];
int green1 = lut6to8[(c1>>5)&0x3F]; int green1 = lut6to8[(c1>>5) & 0x3F];
int green2 = lut6to8[(c2>>5)&0x3F]; int green2 = lut6to8[(c2>>5) & 0x3F];
int red1 = lut5to8[(c1>>11)&0x1F]; int red1 = lut5to8[(c1>>11) & 0x1F];
int red2 = lut5to8[(c2>>11)&0x1F]; int red2 = lut5to8[(c2>>11) & 0x1F];
int colors[4]; int colors[4];
if (c1>c2) if (c1 > c2)
{ {
colors[0]=makecol(red1,green1,blue1,255); colors[0] = makecol(red1, green1, blue1, 255);
colors[1]=makecol(red2,green2,blue2,255); colors[1] = makecol(red2, green2, blue2, 255);
colors[2]=makecol(red1+(red2-red1)/3,green1+(green2-green1)/3,blue1+(blue2-blue1)/3,255); colors[2] = makecol(red1+(red2-red1)/3, green1+(green2-green1)/3, blue1+(blue2-blue1)/3, 255);
colors[3]=makecol(red2+(red1-red2)/3,green2+(green1-green2)/3,blue2+(blue1-blue2)/3,255); colors[3] = makecol(red2+(red1-red2)/3, green2+(green1-green2)/3, blue2+(blue1-blue2)/3, 255);
} }
else else
{ {
colors[0]=makecol(red1,green1,blue1,255); colors[0] = makecol(red1, green1, blue1, 255);
colors[1]=makecol(red2,green2,blue2,255); colors[1] = makecol(red2, green2, blue2, 255);
colors[2]=makecol((red1+red2)/2,(green1+green2)/2,(blue1+blue2)/2,255); colors[2] = makecol((red1+red2)/2, (green1+green2)/2, (blue1+blue2)/2, 255);
colors[3]=makecol(0,0,0,0); //transparent colors[3] = makecol(0,0,0,0); //transparent
} }
for (int y=0; y<4; y++) for (int y = 0; y < 4; y++)
{ {
int val = src->lines[y]; int val = src->lines[y];
for (int x=0; x<4; x++) for (int x = 0; x < 4; x++)
{ {
dst[x] = colors[(val>>6)&3]; dst[x] = colors[(val>>6) & 3];
val<<=2; val <<= 2;
} }
dst+=pitch; dst += pitch;
} }
} }
@ -327,7 +327,7 @@ void decodeDXTBlock(u32 *dst, DXTBlock *src, int pitch)
//TODO: to save memory, don't blindly convert everything to argb8888 //TODO: to save memory, don't blindly convert everything to argb8888
//also ARGB order needs to be swapped later, to accommodate modern hardware better //also ARGB order needs to be swapped later, to accommodate modern hardware better
//need to add DXT support too //need to add DXT support too
TEXTUREFMT TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texformat, int tlutaddr, int tlutfmt) PC_TexFormat TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texformat, int tlutaddr, int tlutfmt)
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
@ -335,108 +335,108 @@ TEXTUREFMT TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texfor
{ {
case GX_TF_C4: case GX_TF_C4:
{ {
for (int y=0; y<height; y+=8) for (int y = 0; y < height; y += 8)
for (int x=0; x<width; x+=8) for (int x = 0; x < width; x += 8)
for (int iy=0; iy<8; iy++, src+=4) for (int iy = 0; iy < 8; iy++, src += 4)
decodebytesC4((u32*)dst+(y+iy)*width+x,src,4,tlutaddr,tlutfmt); decodebytesC4((u32*)dst+(y+iy)*width+x, src, 4, tlutaddr, tlutfmt);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_I4: case GX_TF_I4:
{ {
for (int y=0; y<height; y+=8) for (int y = 0; y < height; y += 8)
for (int x=0; x<width; x+=8) for (int x = 0; x < width; x += 8)
for (int iy=0; iy<8; iy++, src+=4) for (int iy = 0; iy < 8; iy++, src += 4)
decodebytesI4((u32*)dst+(y+iy)*width+x,src,4); decodebytesI4((u32*)dst+(y+iy)*width+x, src, 4);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_C8: case GX_TF_C8:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=8) for (int x = 0; x < width; x += 8)
for (int iy=0; iy<4; iy++, src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesC8((u32*)dst+(y+iy)*width+x,src,8,tlutaddr,tlutfmt); decodebytesC8((u32*)dst+(y+iy)*width+x, src, 8, tlutaddr, tlutfmt);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_I8: case GX_TF_I8:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=8) for (int x = 0; x < width; x += 8)
for (int iy=0; iy<4; iy++, src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesI8((u32*)dst+(y+iy)*width+x,src,8); decodebytesI8((u32*)dst+(y+iy)*width+x, src, 8);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_IA4: case GX_TF_IA4:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=8) for (int x = 0; x < width; x += 8)
for (int iy=0; iy<4; iy++, src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesIA4((u32*)dst+(y+iy)*width+x,src,8); decodebytesIA4((u32*)dst+(y+iy)*width+x, src, 8);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_IA8: case GX_TF_IA8:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=4) for (int x = 0; x < width; x += 4)
for (int iy=0; iy<4; iy++,src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesIA8((u32*)dst+(y+iy)*width+x,(u16*)src,4); decodebytesIA8((u32*)dst+(y+iy)*width+x, (u16*)src, 4);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_C14X2: case GX_TF_C14X2:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=4) for (int x = 0; x < width; x += 4)
for (int iy=0; iy<4; iy++,src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesC14X2((u32*)dst+(y+iy)*width+x,(u16*)src,4,tlutaddr,tlutfmt); decodebytesC14X2((u32*)dst+(y+iy)*width+x, (u16*)src, 4, tlutaddr, tlutfmt);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_RGB565: case GX_TF_RGB565:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=4) for (int x = 0; x < width; x += 4)
for (int iy=0; iy<4; iy++,src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesRGB565((u32*)dst+(y+iy)*width+x,(u16*)src,4); decodebytesRGB565((u32*)dst+(y+iy)*width+x, (u16*)src, 4);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_RGB5A3: case GX_TF_RGB5A3:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=4) for (int x = 0; x < width; x += 4)
for (int iy=0; iy<4; iy++,src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesRGB5A3((u32*)dst+(y+iy)*width+x,(u16*)src,4); decodebytesRGB5A3((u32*)dst+(y+iy)*width+x, (u16*)src, 4);
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_RGBA8: case GX_TF_RGBA8:
{ {
for (int y=0; y<height; y+=4) for (int y = 0; y < height; y += 4)
for (int x=0; x<width; x+=4) for (int x = 0; x < width; x += 4)
{ {
for (int iy=0; iy<4; iy++,src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesARGB8pass1((u32*)dst+(y+iy)*width+x,(u16*)src,4); decodebytesARGB8pass1((u32*)dst+(y+iy)*width+x, (u16*)src, 4);
for (int iy=0; iy<4; iy++,src+=8) for (int iy = 0; iy < 4; iy++, src += 8)
decodebytesARGB8pass2((u32*)dst+(y+iy)*width+x,(u16*)src,4); decodebytesARGB8pass2((u32*)dst+(y+iy)*width+x, (u16*)src, 4);
} }
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
case GX_TF_CMPR: case GX_TF_CMPR:
{ {
// 11111111 22222222 55555555 66666666 // 11111111 22222222 55555555 66666666
// 33333333 44444444 77777777 88888888 // 33333333 44444444 77777777 88888888
for (int y = 0; y < height; y += 8)
for (int x = 0; x < width; x += 8)
for (int y=0; y<height; y+=8)
for (int x=0; x<width; x+=8)
{ {
decodeDXTBlock((u32*)dst+y*width+x,(DXTBlock*)src,width);src+=sizeof(DXTBlock); decodeDXTBlock((u32*)dst+y*width+x, (DXTBlock*)src, width);
decodeDXTBlock((u32*)dst+y*width+x+4,(DXTBlock*)src,width);src+=sizeof(DXTBlock); src += sizeof(DXTBlock);
decodeDXTBlock((u32*)dst+(y+4)*width+x,(DXTBlock*)src,width);src+=sizeof(DXTBlock); decodeDXTBlock((u32*)dst+y*width+x+4, (DXTBlock*)src, width);
decodeDXTBlock((u32*)dst+(y+4)*width+x+4,(DXTBlock*)src,width);src+=sizeof(DXTBlock); src += sizeof(DXTBlock);
decodeDXTBlock((u32*)dst+(y+4)*width+x, (DXTBlock*)src, width);
src += sizeof(DXTBlock);
decodeDXTBlock((u32*)dst+(y+4)*width+x+4, (DXTBlock*)src, width);
src += sizeof(DXTBlock);
} }
} }
return TEXTUREFMT(GL_BGRA, GL_UNSIGNED_BYTE); return PC_TEX_FMT_BGRA32;
} }
// The "copy" texture formats, too? // The "copy" texture formats, too?
return PC_TEX_FMT_NONE;
return TEXTUREFMT(0, 0);
} }

View File

@ -68,6 +68,12 @@ int TexDecoder_GetTexelSizeInNibbles(int format);
int TexDecoder_GetBlockWidthInTexels(int format); int TexDecoder_GetBlockWidthInTexels(int format);
int TexDecoder_GetPaletteSize(int fmt); int TexDecoder_GetPaletteSize(int fmt);
TEXTUREFMT TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texformat, int tlutaddr, int tlutfmt); enum PC_TexFormat
{
PC_TEX_FMT_NONE = 0,
PC_TEX_FMT_BGRA32 = 1,
};
PC_TexFormat TexDecoder_Decode(u8 *dst, u8 *src, int width, int height, int texformat, int tlutaddr, int tlutfmt);
#endif #endif

View File

@ -224,7 +224,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
int bs = TexDecoder_GetBlockWidthInTexels(format)-1; //TexelSizeInNibbles(format)*width*height/16; int bs = TexDecoder_GetBlockWidthInTexels(format)-1; //TexelSizeInNibbles(format)*width*height/16;
int expandedWidth = (width+bs) & (~bs); int expandedWidth = (width+bs) & (~bs);
TEXTUREFMT dfmt = TexDecoder_Decode(temp,ptr,expandedWidth,height,format, tlutaddr, tlutfmt); PC_TexFormat dfmt = TexDecoder_Decode(temp,ptr,expandedWidth,height,format, tlutaddr, tlutfmt);
//Make an entry in the table //Make an entry in the table
TCacheEntry& entry = textures[address]; TCacheEntry& entry = textures[address];
@ -247,12 +247,22 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
if (expandedWidth != width) if (expandedWidth != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, expandedWidth); glPixelStorei(GL_UNPACK_ROW_LENGTH, expandedWidth);
int gl_format;
int gl_type;
switch (dfmt) {
case PC_TEX_FMT_NONE:
PanicAlert("Invalid PC texture format %i", dfmt);
case PC_TEX_FMT_BGRA32:
gl_format = GL_BGRA;
gl_type = GL_UNSIGNED_BYTE;
break;
}
if( !entry.isNonPow2 && ((tm0.min_filter&3)==1||(tm0.min_filter&3)==2) ) { if( !entry.isNonPow2 && ((tm0.min_filter&3)==1||(tm0.min_filter&3)==2) ) {
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_BGRA, GL_UNSIGNED_BYTE, temp); gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, gl_format, gl_type, temp);
entry.bHaveMipMaps = true; entry.bHaveMipMaps = true;
} }
else else
glTexImage2D(target, 0, 4, width, height, 0, dfmt.format, dfmt.type, temp); glTexImage2D(target, 0, 4, width, height, 0, gl_format, gl_type, temp);
if (expandedWidth != width) // reset if (expandedWidth != width) // reset
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

View File

@ -21,6 +21,7 @@
#include "x64Emitter.h" #include "x64Emitter.h"
#include "Render.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "DataReader.h" #include "DataReader.h"

View File

@ -18,6 +18,8 @@
#ifndef _VERTEXLOADERCOLOR_H #ifndef _VERTEXLOADERCOLOR_H
#define _VERTEXLOADERCOLOR_H #define _VERTEXLOADERCOLOR_H
#include "LookUpTables.h"
#define RSHIFT 0 #define RSHIFT 0
#define GSHIFT 8 #define GSHIFT 8
#define BSHIFT 16 #define BSHIFT 16

View File

@ -15,13 +15,13 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h" #include "Globals.h"
#include <math.h> #include <math.h>
#include "Render.h"
#include "VertexShader.h"
#include "VertexShaderManager.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "VertexShader.h"
// This is the tricky one to get rid off.
#include "VertexLoader.h" #include "VertexLoader.h"
static char text[16384]; static char text[16384];
@ -29,9 +29,9 @@ static char text[16384];
#define LIGHTS_POS "" #define LIGHTS_POS ""
char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha); char *GenerateLightShader(char* p, int index, const LitChannel& chan, const char* dest, int coloralpha);
bool GenerateVertexShader(VERTEXSHADER& vs, u32 components) char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
@ -44,7 +44,7 @@ bool GenerateVertexShader(VERTEXSHADER& vs, u32 components)
if( xfregs.nNumChans > 1 ) if( xfregs.nNumChans > 1 )
lightMask |= xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask(); lightMask |= xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask();
bool bOutputZ = bpmem.ztex2.op==ZTEXTURE_ADD || Renderer::GetZBufferTarget()!=0; bool bOutputZ = bpmem.ztex2.op==ZTEXTURE_ADD || has_zbuffer_target;
int ztexcoord = -1; int ztexcoord = -1;
char *p = text; char *p = text;
@ -95,15 +95,15 @@ bool GenerateVertexShader(VERTEXSHADER& vs, u32 components)
// if outputting Z, embed the Z coordinate in the w component of a texture coordinate // if outputting Z, embed the Z coordinate in the w component of a texture coordinate
// if number of tex gens occupies all the texture coordinates, use the last tex coord // if number of tex gens occupies all the texture coordinates, use the last tex coord
// otherwise use the next available tex coord // otherwise use the next available tex coord
for(int i = 0; i < xfregs.numTexGens; ++i) { for (int i = 0; i < xfregs.numTexGens; ++i) {
WRITE(p," float%d tex%d : TEXCOORD%d;\n", (i==(xfregs.numTexGens-1)&&bOutputZ)?4:3, i, i); WRITE(p," float%d tex%d : TEXCOORD%d;\n", (i==(xfregs.numTexGens-1)&&bOutputZ)?4:3, i, i);
} }
if( bOutputZ && xfregs.numTexGens == 0 ) { if (bOutputZ && xfregs.numTexGens == 0) {
ztexcoord = 0; ztexcoord = 0;
WRITE(p," float4 tex%d : TEXCOORD%d;\n", ztexcoord, ztexcoord); WRITE(p," float4 tex%d : TEXCOORD%d;\n", ztexcoord, ztexcoord);
} }
else if( bOutputZ ) else if (bOutputZ)
ztexcoord = xfregs.numTexGens-1; ztexcoord = xfregs.numTexGens - 1;
WRITE(p,"};\n"); WRITE(p,"};\n");
WRITE(p,"\n"); WRITE(p,"\n");
@ -404,7 +404,7 @@ bool GenerateVertexShader(VERTEXSHADER& vs, u32 components)
WRITE(p,"return o;\n}\n\0"); WRITE(p,"return o;\n}\n\0");
return VertexShaderMngr::CompileVertexShader(vs, text); return text;
} }
// coloralpha - 1 if color, 2 if alpha // coloralpha - 1 if color, 2 if alpha

View File

@ -18,215 +18,29 @@
#ifndef GCOGL_VERTEXSHADER_H #ifndef GCOGL_VERTEXSHADER_H
#define GCOGL_VERTEXSHADER_H #define GCOGL_VERTEXSHADER_H
#include "XFMemory.h"
///////////// // shader variables
// Lighting #define I_POSNORMALMATRIX "cpnmtx"
///////////// #define I_PROJECTION "cproj"
#define XF_TEXPROJ_ST 0 #define I_MATERIALS "cmtrl"
#define XF_TEXPROJ_STQ 1 #define I_LIGHTS "clights"
#define I_TEXMATRICES "ctexmtx"
#define I_TRANSFORMMATRICES "ctrmtx"
#define I_NORMALMATRICES "cnmtx"
#define I_POSTTRANSFORMMATRICES "cpostmtx"
#define I_FOGPARAMS "cfog"
#define XF_TEXINPUT_AB11 0 #define C_POSNORMALMATRIX 0
#define XF_TEXINPUT_ABC1 1 #define C_PROJECTION (C_POSNORMALMATRIX+6)
#define C_MATERIALS (C_PROJECTION+4)
#define C_LIGHTS (C_MATERIALS+4)
#define C_TEXMATRICES (C_LIGHTS+40)
#define C_TRANSFORMMATRICES (C_TEXMATRICES+24)
#define C_NORMALMATRICES (C_TRANSFORMMATRICES+64)
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES+32)
#define C_FOGPARAMS (C_POSTTRANSFORMMATRICES+64)
#define XF_TEXGEN_REGULAR 0 char *GenerateVertexShader(u32 components, bool has_zbuffer_target);
#define XF_TEXGEN_EMBOSS_MAP 1 // used when bump mapping
#define XF_TEXGEN_COLOR_STRGBC0 2
#define XF_TEXGEN_COLOR_STRGBC1 3
#define XF_SRCGEOM_INROW 0 // input is abc
#define XF_SRCNORMAL_INROW 1 // input is abc
#define XF_SRCCOLORS_INROW 2
#define XF_SRCBINORMAL_T_INROW 3 // input is abc
#define XF_SRCBINORMAL_B_INROW 4 // input is abc
#define XF_SRCTEX0_INROW 5
#define XF_SRCTEX1_INROW 6
#define XF_SRCTEX2_INROW 7
#define XF_SRCTEX3_INROW 8
#define XF_SRCTEX4_INROW 9
#define XF_SRCTEX5_INROW 10
#define XF_SRCTEX6_INROW 11
#define XF_SRCTEX7_INROW 12
struct Light
{
u32 useless[3];
u32 color; //rgba
float a0; //attenuation
float a1;
float a2;
float k0; //k stuff
float k1;
float k2;
union
{
struct {
float dpos[3];
float ddir[3]; // specular lights only
};
struct {
float sdir[3];
float shalfangle[3]; // specular lights only
};
};
};
#define LIGHTDIF_NONE 0
#define LIGHTDIF_SIGN 1
#define LIGHTDIF_CLAMP 2
#define LIGHTATTN_SPEC 0 // specular attenuation
#define LIGHTATTN_SPOT 1 // distance/spotlight attenuation
#define LIGHTATTN_NONE 2
#define LIGHTATTN_DIR 3
union LitChannel
{
struct
{
unsigned matsource : 1;
unsigned enablelighting : 1;
unsigned lightMask0_3 : 4;
unsigned ambsource : 1;
unsigned diffusefunc : 2; // LIGHTDIF_X
unsigned attnfunc : 2; // LIGHTATTN_X
unsigned lightMask4_7 : 4;
};
struct
{
u32 hex : 15;
u32 unused : 17;
};
struct
{
u32 dummy0 : 7;
u32 lightparams : 4;
u32 dummy1 : 21;
};
unsigned int GetFullLightMask() const
{
return enablelighting ? (lightMask0_3 | (lightMask4_7 << 4)) : 0;
}
};
struct ColorChannel
{
u32 ambColor;
u32 matColor;
LitChannel color;
LitChannel alpha;
};
union INVTXSPEC
{
struct
{
unsigned numcolors : 2;
unsigned numnormals : 2; // 0 - nothing, 1 - just normal, 2 - normals and binormals
unsigned numtextures : 4;
unsigned unused : 24;
};
u32 hex;
};
union TexMtxInfo
{
struct
{
unsigned unknown : 1;
unsigned projection : 1; // XF_TEXPROJ_X
unsigned inputform : 2; // XF_TEXINPUT_X
unsigned texgentype : 3; // XF_TEXGEN_X
unsigned sourcerow : 5; // XF_SRCGEOM_X
unsigned embosssourceshift : 3; // what generated texcoord to use
unsigned embosslightshift : 3; // light index that is used
};
u32 hex;
};
union PostMtxInfo
{
struct
{
unsigned index : 6; // base row of dual transform matrix
unsigned unused : 2;
unsigned normalize : 1; // normalize before send operation
};
u32 hex;
};
struct TexCoordInfo
{
TexMtxInfo texmtxinfo;
PostMtxInfo postmtxinfo;
};
struct XFRegisters
{
int numTexGens;
int nNumChans;
INVTXSPEC hostinfo; // number of textures,colors,normals from vertex input
ColorChannel colChans[2]; //C0A0 C1A1
TexCoordInfo texcoords[8];
bool bEnableDualTexTransform;
};
#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
// Matrix indices
union TMatrixIndexA
{
struct
{
unsigned PosNormalMtxIdx : 6;
unsigned Tex0MtxIdx : 6;
unsigned Tex1MtxIdx : 6;
unsigned Tex2MtxIdx : 6;
unsigned Tex3MtxIdx : 6;
};
struct
{
u32 Hex : 30;
u32 unused : 2;
};
};
union TMatrixIndexB
{
struct
{
unsigned Tex4MtxIdx : 6;
unsigned Tex5MtxIdx : 6;
unsigned Tex6MtxIdx : 6;
unsigned Tex7MtxIdx : 6;
};
struct
{
u32 Hex : 24;
u32 unused : 8;
};
};
struct VERTEXSHADER
{
VERTEXSHADER() : glprogid(0) {}
GLuint glprogid; // opengl program id
#ifdef _DEBUG
std::string strprog;
#endif
};
bool GenerateVertexShader(VERTEXSHADER& vs, u32 components);
extern XFRegisters xfregs;
#endif #endif

View File

@ -22,9 +22,9 @@
#include "Render.h" #include "Render.h"
#include "VertexShader.h" #include "VertexShader.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "BPStructs.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPMemory.h"
#include "XFMemory.h"
VertexShaderMngr::VSCache VertexShaderMngr::vshaders; VertexShaderMngr::VSCache VertexShaderMngr::vshaders;
VERTEXSHADER* VertexShaderMngr::pShaderLast = NULL; VERTEXSHADER* VertexShaderMngr::pShaderLast = NULL;
@ -39,8 +39,6 @@ static int s_nMaxVertexInstructions;
//////////////////////// ////////////////////////
// Internal Variables // // Internal Variables //
//////////////////////// ////////////////////////
XFRegisters xfregs;
static u32 xfmem[XFMEM_SIZE];
static float s_fMaterials[16]; static float s_fMaterials[16];
// track changes // track changes
@ -51,6 +49,14 @@ static int nNormalMatricesChanged[2]; // min,max
static int nPostTransformMatricesChanged[2]; // min,max static int nPostTransformMatricesChanged[2]; // min,max
static int nLightsChanged[2]; // min,max static int nLightsChanged[2]; // min,max
void VertexShaderMngr::SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4) {
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
}
void VertexShaderMngr::SetVSConstant4fv(int const_number, const float *f) {
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
}
void VertexShaderMngr::Init() void VertexShaderMngr::Init()
{ {
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1; nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
@ -93,10 +99,11 @@ VERTEXSHADER* VertexShaderMngr::GetShader(u32 components)
} }
VSCacheEntry& entry = vshaders[uid]; VSCacheEntry& entry = vshaders[uid];
char *code = GenerateVertexShader(components, Renderer::GetZBufferTarget() != 0);
if (!GenerateVertexShader(entry.shader, components)) { if (!code || !VertexShaderMngr::CompileVertexShader(entry.shader, code)) {
ERROR_LOG("failed to create vertex shader\n"); ERROR_LOG("failed to create vertex shader\n");
} return NULL;
}
//Make an entry in the table //Make an entry in the table
entry.frameCount=frameCount; entry.frameCount=frameCount;
@ -210,7 +217,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
int endn = (nTransformMatricesChanged[1]+3)/4; int endn = (nTransformMatricesChanged[1]+3)/4;
const float* pstart = (const float*)&xfmem[startn*4]; const float* pstart = (const float*)&xfmem[startn*4];
for(int i = startn; i < endn; ++i, pstart += 4) for(int i = startn; i < endn; ++i, pstart += 4)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TRANSFORMMATRICES+i, pstart); SetVSConstant4fv(C_TRANSFORMMATRICES+i, pstart);
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1; nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
} }
if (nNormalMatricesChanged[0] >= 0) { if (nNormalMatricesChanged[0] >= 0) {
@ -219,7 +226,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
const float* pnstart = (const float*)&xfmem[XFMEM_NORMALMATRICES+3*startn]; const float* pnstart = (const float*)&xfmem[XFMEM_NORMALMATRICES+3*startn];
for(int i = startn; i < endn; ++i, pnstart += 3) for(int i = startn; i < endn; ++i, pnstart += 3)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_NORMALMATRICES+i, pnstart); SetVSConstant4fv(C_NORMALMATRICES+i, pnstart);
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1; nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
} }
@ -229,7 +236,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
int endn = (nPostTransformMatricesChanged[1]+3)/4; int endn = (nPostTransformMatricesChanged[1]+3)/4;
const float* pstart = (const float*)&xfmem[XFMEM_POSTMATRICES+startn*4]; const float* pstart = (const float*)&xfmem[XFMEM_POSTMATRICES+startn*4];
for(int i = startn; i < endn; ++i, pstart += 4) for(int i = startn; i < endn; ++i, pstart += 4)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSTTRANSFORMMATRICES+i, pstart); SetVSConstant4fv(C_POSTTRANSFORMMATRICES+i, pstart);
} }
if (nLightsChanged[0] >= 0) { if (nLightsChanged[0] >= 0) {
@ -240,16 +247,16 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
for(int i = istart; i < iend; ++i) { for(int i = istart; i < iend; ++i) {
u32 color = *(const u32*)(xfmemptr+3); u32 color = *(const u32*)(xfmemptr+3);
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, C_LIGHTS+5*i, SetVSConstant4f(C_LIGHTS+5*i,
((color>>24)&0xFF)/255.0f, ((color>>16)&0xFF)/255.0f, ((color>>8)&0xFF)/255.0f, ((color)&0xFF)/255.0f); ((color>>24)&0xFF)/255.0f, ((color>>16)&0xFF)/255.0f, ((color>>8)&0xFF)/255.0f, ((color)&0xFF)/255.0f);
xfmemptr += 4; xfmemptr += 4;
for(int j = 0; j < 4; ++j, xfmemptr += 3) { for(int j = 0; j < 4; ++j, xfmemptr += 3) {
if( j == 1 && fabs(xfmemptr[0]) < 0.00001f && fabs(xfmemptr[1]) < 0.00001f && fabs(xfmemptr[2]) < 0.00001f) { if( j == 1 && fabs(xfmemptr[0]) < 0.00001f && fabs(xfmemptr[1]) < 0.00001f && fabs(xfmemptr[2]) < 0.00001f) {
// dist atten, make sure not equal to 0!!! // dist atten, make sure not equal to 0!!!
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, C_LIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0); SetVSConstant4f(C_LIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0);
} }
else else
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_LIGHTS+5*i+j+1, xfmemptr); SetVSConstant4fv(C_LIGHTS+5*i+j+1, xfmemptr);
} }
} }
@ -259,7 +266,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
if (nMaterialsChanged) { if (nMaterialsChanged) {
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 4; ++i) {
if( nMaterialsChanged&(1<<i) ) if( nMaterialsChanged&(1<<i) )
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_MATERIALS+i, &s_fMaterials[4*i]); SetVSConstant4fv(C_MATERIALS+i, &s_fMaterials[4*i]);
} }
nMaterialsChanged = 0; nMaterialsChanged = 0;
} }
@ -270,12 +277,12 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
float* pos = (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4; float* pos = (float*)xfmem + MatrixIndexA.PosNormalMtxIdx * 4;
float* norm = (float*)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31); float* norm = (float*)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSNORMALMATRIX, pos); SetVSConstant4fv(C_POSNORMALMATRIX, pos);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSNORMALMATRIX+1, pos+4); SetVSConstant4fv(C_POSNORMALMATRIX+1, pos+4);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSNORMALMATRIX+2, pos+8); SetVSConstant4fv(C_POSNORMALMATRIX+2, pos+8);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSNORMALMATRIX+3, norm); SetVSConstant4fv(C_POSNORMALMATRIX+3, norm);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSNORMALMATRIX+4, norm+3); SetVSConstant4fv(C_POSNORMALMATRIX+4, norm+3);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_POSNORMALMATRIX+5, norm+6); SetVSConstant4fv(C_POSNORMALMATRIX+5, norm+6);
} }
if (bTexMatricesChanged[0]) { if (bTexMatricesChanged[0]) {
@ -285,9 +292,9 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
(float*)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex3MtxIdx * 4 }; (float*)xfmem + MatrixIndexA.Tex2MtxIdx * 4, (float*)xfmem + MatrixIndexA.Tex3MtxIdx * 4 };
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 4; ++i) {
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TEXMATRICES+3*i, fptrs[i]); SetVSConstant4fv(C_TEXMATRICES+3*i, fptrs[i]);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TEXMATRICES+3*i+1, fptrs[i]+4); SetVSConstant4fv(C_TEXMATRICES+3*i+1, fptrs[i]+4);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TEXMATRICES+3*i+2, fptrs[i]+8); SetVSConstant4fv(C_TEXMATRICES+3*i+2, fptrs[i]+8);
} }
} }
@ -298,9 +305,9 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
(float*)xfmem + MatrixIndexB.Tex6MtxIdx * 4, (float*)xfmem + MatrixIndexB.Tex7MtxIdx * 4 }; (float*)xfmem + MatrixIndexB.Tex6MtxIdx * 4, (float*)xfmem + MatrixIndexB.Tex7MtxIdx * 4 };
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 4; ++i) {
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TEXMATRICES+3*i+12, fptrs[i]); SetVSConstant4fv(C_TEXMATRICES+3*i+12, fptrs[i]);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TEXMATRICES+3*i+12+1, fptrs[i]+4); SetVSConstant4fv(C_TEXMATRICES+3*i+12+1, fptrs[i]+4);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_TEXMATRICES+3*i+12+2, fptrs[i]+8); SetVSConstant4fv(C_TEXMATRICES+3*i+12+2, fptrs[i]+8);
} }
} }
@ -367,10 +374,10 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
} }
PRIM_LOG("Projection: %f %f %f %f %f %f\n",rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]); PRIM_LOG("Projection: %f %f %f %f %f %f\n",rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_PROJECTION, &g_fProjectionMatrix[0]); SetVSConstant4fv(C_PROJECTION, &g_fProjectionMatrix[0]);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_PROJECTION+1, &g_fProjectionMatrix[4]); SetVSConstant4fv(C_PROJECTION+1, &g_fProjectionMatrix[4]);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_PROJECTION+2, &g_fProjectionMatrix[8]); SetVSConstant4fv(C_PROJECTION+2, &g_fProjectionMatrix[8]);
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, C_PROJECTION+3, &g_fProjectionMatrix[12]); SetVSConstant4fv(C_PROJECTION+3, &g_fProjectionMatrix[12]);
} }
} }

View File

@ -22,27 +22,16 @@
#include "VertexShader.h" #include "VertexShader.h"
// shader variables
#define I_POSNORMALMATRIX "cpnmtx"
#define I_PROJECTION "cproj"
#define I_MATERIALS "cmtrl"
#define I_LIGHTS "clights"
#define I_TEXMATRICES "ctexmtx"
#define I_TRANSFORMMATRICES "ctrmtx"
#define I_NORMALMATRICES "cnmtx"
#define I_POSTTRANSFORMMATRICES "cpostmtx"
#define I_FOGPARAMS "cfog"
#define C_POSNORMALMATRIX 0 struct VERTEXSHADER
#define C_PROJECTION (C_POSNORMALMATRIX+6) {
#define C_MATERIALS (C_PROJECTION+4) VERTEXSHADER() : glprogid(0) {}
#define C_LIGHTS (C_MATERIALS+4) GLuint glprogid; // opengl program id
#define C_TEXMATRICES (C_LIGHTS+40)
#define C_TRANSFORMMATRICES (C_TEXMATRICES+24)
#define C_NORMALMATRICES (C_TRANSFORMMATRICES+64)
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES+32)
#define C_FOGPARAMS (C_POSTTRANSFORMMATRICES+64)
#ifdef _DEBUG
std::string strprog;
#endif
};
class VertexShaderMngr class VertexShaderMngr
{ {
@ -109,6 +98,8 @@ class VertexShaderMngr
static void GetVertexShaderId(VERTEXSHADERUID& uid, u32 components); static void GetVertexShaderId(VERTEXSHADERUID& uid, u32 components);
static void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4);
static void SetVSConstant4fv(int const_number, const float *f);
public: public:
static void Init(); static void Init();
static void Cleanup(); static void Cleanup();
@ -136,5 +127,4 @@ public:
static float rawProjection[7]; static float rawProjection[7];
}; };
#endif #endif