more gl plugin cleanup, code moving

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@900 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2008-10-17 12:08:28 +00:00
parent dcbc8e78d4
commit 7bbd6fda63
12 changed files with 177 additions and 192 deletions

View File

@ -28,15 +28,18 @@ int lut6to8[64];
float lutu8tosfloat[256]; float lutu8tosfloat[256];
float lutu8toufloat[256]; float lutu8toufloat[256];
float luts8tosfloat[256]; float luts8tosfloat[256];
float shiftLookup[32];
void InitLUTs() void InitLUTs()
{ {
for (int i = 0; i < 64; i++) for (int i = 0; i < 32; i++)
lut6to8[i] = (i*255) / 63; shiftLookup[i] = 1.0f / float(1 << i);
for (int i = 0; i < 256; i++) for (int i = 0; i < 64; i++)
{ lut6to8[i] = (i*255) / 63;
lutu8tosfloat[i] = (float)(i - 128) / 127.0f; for (int i = 0; i < 256; i++)
lutu8toufloat[i] = (float)(i) / 255.0f; {
luts8tosfloat[i] = ((float)(signed char)(char)i) / 127.0f; lutu8tosfloat[i] = (float)(i - 128) / 127.0f;
} lutu8toufloat[i] = (float)(i) / 255.0f;
luts8tosfloat[i] = ((float)(signed char)(char)i) / 127.0f;
}
} }

View File

@ -27,6 +27,7 @@ extern int lut6to8[64];
extern float lutu8tosfloat[256]; extern float lutu8tosfloat[256];
extern float lutu8toufloat[256]; extern float lutu8toufloat[256];
extern float luts8tosfloat[256]; extern float luts8tosfloat[256];
extern float shiftLookup[32];
void InitLUTs(); void InitLUTs();

View File

@ -31,9 +31,6 @@
using namespace D3D; using namespace D3D;
//TODO(ector): remove and calculate inline?
float shiftLookup[32];
IndexGenerator indexGen; IndexGenerator indexGen;
Collection CVertexHandler::collection; Collection CVertexHandler::collection;
@ -65,10 +62,6 @@ const D3DVERTEXELEMENT9 decl[] =
void CVertexHandler::Init() void CVertexHandler::Init()
{ {
collection = C_NOTHING; collection = C_NOTHING;
for (int i = 0; i < 31; i++)
shiftLookup[i] = 1.0f / float(1 << i);
fakeVBuffer = new D3DVertex[65536]; fakeVBuffer = new D3DVertex[65536];
fakeIBuffer = new u16[65536]; fakeIBuffer = new u16[65536];
CreateDeviceObjects(); CreateDeviceObjects();

View File

@ -22,8 +22,6 @@
#include "VertexLoader.h" #include "VertexLoader.h"
#include "DecodedVArray.h" #include "DecodedVArray.h"
extern float shiftLookup[32];
struct UV struct UV
{ {
float u,v,w; float u,v,w;

View File

@ -20,6 +20,7 @@
#include "x64Emitter.h" #include "x64Emitter.h"
#include "Common.h" #include "Common.h"
#include "LookUpTables.h"
#include "Profiler.h" #include "Profiler.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "VertexLoader.h" #include "VertexLoader.h"

View File

@ -387,10 +387,10 @@ void Renderer::ProcessMessages()
int time_left = (int)(it->dwTimeStamp - timeGetTime()); int time_left = (int)(it->dwTimeStamp - timeGetTime());
int alpha = 255; int alpha = 255;
if(time_left<1024) if (time_left < 1024)
{ {
alpha=time_left>>2; alpha = time_left >> 2;
if(time_left<0) alpha=0; if (time_left < 0) alpha = 0;
} }
alpha <<= 24; alpha <<= 24;

View File

@ -137,7 +137,6 @@ void TextureMngr::Shutdown()
void TextureMngr::Cleanup() void TextureMngr::Cleanup()
{ {
TexCache::iterator iter = textures.begin(); TexCache::iterator iter = textures.begin();
while (iter != textures.end()) { while (iter != textures.end()) {
if (frameCount > 20 + iter->second.frameCount) { if (frameCount > 20 + iter->second.frameCount) {
if (!iter->second.isRenderTarget) { if (!iter->second.isRenderTarget) {

View File

@ -56,9 +56,6 @@ static int colIndex;
#endif #endif
TVtxDesc VertexManager::s_GlobalVtxDesc; TVtxDesc VertexManager::s_GlobalVtxDesc;
float VertexManager::shiftLookup[32];
// ============================================================================== // ==============================================================================
// Direct // Direct
@ -259,9 +256,9 @@ int VertexLoader::ComputeVertexSize()
} }
// Note the use of CallCdeclFunction3I etc. // Note the use of CallCdeclFunction3I etc.
// This is a horrible hack that is necessary because Opengl32.dll is based way, way above the 32-bit address space // This is a horrible hack that is necessary because in 64-bit mode, Opengl32.dll is based way, way above the 32-bit
// that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we want to grab // address space that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we
// the function pointers from the import table instead. // want to grab the function pointers from the import table instead.
// This problem does not apply to glew functions, only core opengl32 functions. // This problem does not apply to glew functions, only core opengl32 functions.
@ -362,7 +359,7 @@ void VertexLoader::ProcessFormat()
} }
WriteCall(pFunc); WriteCall(pFunc);
int sizePro=0; int sizePro = 0;
switch (m_VtxAttr.NormalFormat) switch (m_VtxAttr.NormalFormat)
{ {
case FORMAT_UBYTE: sizePro=1; break; case FORMAT_UBYTE: sizePro=1; break;
@ -385,7 +382,7 @@ void VertexLoader::ProcessFormat()
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
SetupColor(i, col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements); SetupColor(i, col[i], m_VtxAttr.color[i].Comp, m_VtxAttr.color[i].Elements);
if (col[i] != NOT_PRESENT ) if (col[i] != NOT_PRESENT)
m_VBVertexStride+=4; m_VBVertexStride+=4;
} }
@ -399,7 +396,7 @@ void VertexLoader::ProcessFormat()
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac); SetupTexCoord(i, tc[i], m_VtxAttr.texCoord[i].Format, m_VtxAttr.texCoord[i].Elements, m_VtxAttr.texCoord[i].Frac);
if( m_components&(VB_HAS_TEXMTXIDX0<<i) ) { if (m_components&(VB_HAS_TEXMTXIDX0<<i)) {
if (tc[i] != NOT_PRESENT) { if (tc[i] != NOT_PRESENT) {
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index // if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
WriteCall(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2); WriteCall(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2);
@ -419,25 +416,25 @@ void VertexLoader::ProcessFormat()
if (tc[i] == NOT_PRESENT) { if (tc[i] == NOT_PRESENT) {
// if there's more tex coords later, have to write a dummy call // if there's more tex coords later, have to write a dummy call
int j = i+1; int j = i + 1;
for(; j < 8; ++j) { for (; j < 8; ++j) {
if( tc[j] != NOT_PRESENT ) { if (tc[j] != NOT_PRESENT) {
WriteCall(TexCoord_Read_Dummy); // important to get indices right! WriteCall(TexCoord_Read_Dummy); // important to get indices right!
break; break;
} }
} }
if( j == 8 && !((m_components&VB_HAS_TEXMTXIDXALL)&(VB_HAS_TEXMTXIDXALL<<(i+1))) ) // no more tex coords and tex matrices, so exit loop if (j == 8 && !((m_components&VB_HAS_TEXMTXIDXALL)&(VB_HAS_TEXMTXIDXALL<<(i+1)))) // no more tex coords and tex matrices, so exit loop
break; break;
} }
} }
if( m_VtxDesc.PosMatIdx ) { if (m_VtxDesc.PosMatIdx) {
WriteCall(PosMtx_Write); WriteCall(PosMtx_Write);
m_VBVertexStride += 1; m_VBVertexStride += 1;
} }
if( m_VBVertexStride & 3 ) { if (m_VBVertexStride & 3) {
// make sure all strides are at least divisible by 4 (some gfx cards experience a 3x speed boost) // make sure all strides are at least divisible by 4 (some gfx cards experience a 3x speed boost)
m_VBStridePad = 4 - (m_VBVertexStride&3); m_VBStridePad = 4 - (m_VBVertexStride&3);
m_VBVertexStride += m_VBStridePad; m_VBVertexStride += m_VBStridePad;
@ -462,16 +459,16 @@ void VertexLoader::ProcessFormat()
case FORMAT_BYTE: case FORMAT_BYTE:
CallCdeclFunction3_I(glNormalPointer, GL_BYTE, m_VBVertexStride, offset); offset += 3; CallCdeclFunction3_I(glNormalPointer, GL_BYTE, m_VBVertexStride, offset); offset += 3;
if (m_VtxAttr.NormalElements) { if (m_VtxAttr.NormalElements) {
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB,3,GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3; CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3;
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB,3,GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3; CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_BYTE, GL_TRUE, m_VBVertexStride, offset); offset += 3;
} }
break; break;
case FORMAT_USHORT: case FORMAT_USHORT:
case FORMAT_SHORT: case FORMAT_SHORT:
CallCdeclFunction3_I(glNormalPointer, GL_SHORT, m_VBVertexStride, offset); offset += 6; CallCdeclFunction3_I(glNormalPointer, GL_SHORT, m_VBVertexStride, offset); offset += 6;
if (m_VtxAttr.NormalElements) { if (m_VtxAttr.NormalElements) {
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB,3,GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6; CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM1_ATTRIB, 3, GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6;
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB,3,GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6; CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_NORM2_ATTRIB, 3, GL_SHORT, GL_TRUE, m_VBVertexStride, offset); offset += 6;
} }
break; break;
case FORMAT_FLOAT: case FORMAT_FLOAT:
@ -497,7 +494,7 @@ void VertexLoader::ProcessFormat()
// TextureCoord // TextureCoord
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (tc[i] != NOT_PRESENT || (m_components&(VB_HAS_TEXMTXIDX0<<i)) ) { if (tc[i] != NOT_PRESENT || (m_components&(VB_HAS_TEXMTXIDX0<<i))) {
int id = GL_TEXTURE0+i; int id = GL_TEXTURE0+i;
#ifdef _M_X64 #ifdef _M_X64
@ -554,11 +551,11 @@ void VertexLoader::ProcessFormat()
void VertexLoader::PrepareRun() void VertexLoader::PrepareRun()
{ {
posScale = VertexManager::shiftLookup[m_VtxAttr.PosFrac]; posScale = shiftLookup[m_VtxAttr.PosFrac];
if( m_components & VB_HAS_UVALL ) { if (m_components & VB_HAS_UVALL) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
tcScaleU[i] = VertexManager::shiftLookup[m_VtxAttr.texCoord[i].Frac]; tcScaleU[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac];
tcScaleV[i] = VertexManager::shiftLookup[m_VtxAttr.texCoord[i].Frac]; tcScaleV[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac];
} }
} }
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
@ -568,7 +565,7 @@ void VertexLoader::PrepareRun()
void VertexLoader::SetupColor(int num, int mode, int format, int elements) void VertexLoader::SetupColor(int num, int mode, int format, int elements)
{ {
// if COL0 not present, then embed COL1 into COL0 // if COL0 not present, then embed COL1 into COL0
if( num == 1 && !(m_components & VB_HAS_COL0) ) num = 0; if (num == 1 && !(m_components & VB_HAS_COL0) ) num = 0;
m_components |= VB_HAS_COL0 << num; m_components |= VB_HAS_COL0 << num;
switch (mode) switch (mode)
@ -686,60 +683,7 @@ void VertexLoader::RunVertices(int primitive, int count)
ProcessFormat(); ProcessFormat();
fnSetupVertexPointers = (void (*)())(void*)m_compiledCode; fnSetupVertexPointers = (void (*)())(void*)m_compiledCode;
// Move this code into VertexManager? VertexManager::EnableComponents(m_components);
if (VertexManager::s_prevcomponents != m_components) {
VertexManager::Flush();
// matrices
if ((m_components & VB_HAS_POSMTXIDX) != (VertexManager::s_prevcomponents & VB_HAS_POSMTXIDX)) {
if (m_components & VB_HAS_POSMTXIDX)
glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
else
glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
}
// normals
if ((m_components & VB_HAS_NRM0) != (VertexManager::s_prevcomponents & VB_HAS_NRM0)) {
if (m_components & VB_HAS_NRM0)
glEnableClientState(GL_NORMAL_ARRAY);
else
glDisableClientState(GL_NORMAL_ARRAY);
}
if ((m_components & VB_HAS_NRM1) != (VertexManager::s_prevcomponents & VB_HAS_NRM1)) {
if (m_components & VB_HAS_NRM1) {
glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
}
else {
glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
}
}
// color
for (int i = 0; i < 2; ++i) {
if ((m_components & (VB_HAS_COL0 << i)) != (VertexManager::s_prevcomponents & (VB_HAS_COL0 << i))) {
if (m_components & (VB_HAS_COL0 << 0))
glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
else
glDisableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
}
}
// tex
for (int i = 0; i < 8; ++i) {
if ((m_components & (VB_HAS_UV0 << i)) != (VertexManager::s_prevcomponents & (VB_HAS_UV0 << i))) {
glClientActiveTexture(GL_TEXTURE0 + i);
if (m_components & (VB_HAS_UV0 << i))
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
VertexManager::s_prevcomponents = m_components;
VertexManager::s_prevvbstride = m_VBVertexStride;
}
PrepareRun(); PrepareRun();
@ -749,11 +693,11 @@ void VertexLoader::RunVertices(int primitive, int count)
switch(primitive) { switch(primitive) {
case 3: // strip case 3: // strip
case 4: // fan case 4: // fan
if( VertexManager::GetRemainingSize() < 3*m_VBVertexStride ) if (VertexManager::GetRemainingSize() < 3*m_VBVertexStride )
VertexManager::Flush(); VertexManager::Flush();
break; break;
case 6: // line strip case 6: // line strip
if( VertexManager::GetRemainingSize() < 2*m_VBVertexStride ) if (VertexManager::GetRemainingSize() < 2*m_VBVertexStride )
VertexManager::Flush(); VertexManager::Flush();
break; break;
case 0: // quads case 0: // quads
@ -774,7 +718,7 @@ void VertexLoader::RunVertices(int primitive, int count)
{ {
if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) { if (VertexManager::GetRemainingSize() < granularity*m_VBVertexStride) {
u8* plastptr = VertexManager::s_pCurBufferPointer; u8* plastptr = VertexManager::s_pCurBufferPointer;
if (v-startv > 0) if (v - startv > 0)
VertexManager::AddVertices(primitive, v-startv+extraverts); VertexManager::AddVertices(primitive, v-startv+extraverts);
VertexManager::Flush(); VertexManager::Flush();
// Why does this need to be so complicated? // Why does this need to be so complicated?
@ -823,5 +767,5 @@ void VertexLoader::RunVertices(int primitive, int count)
} }
if (startv < count) if (startv < count)
VertexManager::AddVertices(primitive, count-startv+extraverts); VertexManager::AddVertices(primitive, count - startv + extraverts);
} }

View File

@ -32,6 +32,39 @@ using namespace std;
#define LOADERDECL __cdecl #define LOADERDECL __cdecl
typedef void (LOADERDECL *TPipelineFunction)(void*); typedef void (LOADERDECL *TPipelineFunction)(void*);
// m_components
enum {
VB_HAS_POSMTXIDX =(1<<1),
VB_HAS_TEXMTXIDX0=(1<<2),
VB_HAS_TEXMTXIDX1=(1<<3),
VB_HAS_TEXMTXIDX2=(1<<4),
VB_HAS_TEXMTXIDX3=(1<<5),
VB_HAS_TEXMTXIDX4=(1<<6),
VB_HAS_TEXMTXIDX5=(1<<7),
VB_HAS_TEXMTXIDX6=(1<<8),
VB_HAS_TEXMTXIDX7=(1<<9),
VB_HAS_TEXMTXIDXALL=(0xff<<2),
//VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
VB_HAS_NRM0=(1<<10),
VB_HAS_NRM1=(1<<11),
VB_HAS_NRM2=(1<<12),
VB_HAS_NRMALL=(7<<10),
VB_HAS_COL0=(1<<13),
VB_HAS_COL1=(1<<14),
VB_HAS_UV0=(1<<15),
VB_HAS_UV1=(1<<16),
VB_HAS_UV2=(1<<17),
VB_HAS_UV3=(1<<18),
VB_HAS_UV4=(1<<19),
VB_HAS_UV5=(1<<20),
VB_HAS_UV6=(1<<21),
VB_HAS_UV7=(1<<22),
VB_HAS_UVALL=(0xff<<15),
VB_HAS_UVTEXMTXSHIFT=13,
};
// There are 8 of these. Most games only use the first, and just reconfigure it all the time // There are 8 of these. Most games only use the first, and just reconfigure it all the time
// as needed, unfortunately. // as needed, unfortunately.
class VertexLoader class VertexLoader
@ -44,38 +77,6 @@ public:
NRM_THREE = 3 NRM_THREE = 3
}; };
// m_components
enum {
VB_HAS_POSMTXIDX =(1<<1),
VB_HAS_TEXMTXIDX0=(1<<2),
VB_HAS_TEXMTXIDX1=(1<<3),
VB_HAS_TEXMTXIDX2=(1<<4),
VB_HAS_TEXMTXIDX3=(1<<5),
VB_HAS_TEXMTXIDX4=(1<<6),
VB_HAS_TEXMTXIDX5=(1<<7),
VB_HAS_TEXMTXIDX6=(1<<8),
VB_HAS_TEXMTXIDX7=(1<<9),
VB_HAS_TEXMTXIDXALL=(0xff<<2),
//VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
VB_HAS_NRM0=(1<<10),
VB_HAS_NRM1=(1<<11),
VB_HAS_NRM2=(1<<12),
VB_HAS_NRMALL=(7<<10),
VB_HAS_COL0=(1<<13),
VB_HAS_COL1=(1<<14),
VB_HAS_UV0=(1<<15),
VB_HAS_UV1=(1<<16),
VB_HAS_UV2=(1<<17),
VB_HAS_UV3=(1<<18),
VB_HAS_UV4=(1<<19),
VB_HAS_UV5=(1<<20),
VB_HAS_UV6=(1<<21),
VB_HAS_UV7=(1<<22),
VB_HAS_UVALL=(0xff<<15),
VB_HAS_UVTEXMTXSHIFT=13,
};
private: private:
TPipelineFunction m_PipelineStates[32]; TPipelineFunction m_PipelineStates[32];

View File

@ -15,14 +15,11 @@
static GLuint s_vboBuffers[0x40] = {0}; static GLuint s_vboBuffers[0x40] = {0};
static int s_nCurVBOIndex = 0; // current free buffer static int s_nCurVBOIndex = 0; // current free buffer
static GLenum s_prevprimitive = 0; // current primitive type
static u8 *s_pBaseBufferPointer = NULL; static u8 *s_pBaseBufferPointer = NULL;
static vector< pair<int, int> > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays static vector< pair<int, int> > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays
static u32 s_prevcomponents; // previous state set
u8* VertexManager::s_pCurBufferPointer = NULL; u8* VertexManager::s_pCurBufferPointer = NULL;
u32 VertexManager::s_prevvbstride;
u32 VertexManager::s_prevcomponents; // previous state set
const GLenum c_primitiveType[8] = const GLenum c_primitiveType[8] =
{ {
@ -45,14 +42,9 @@ bool VertexManager::Init()
s_GlobalVtxDesc.Hex = 0; s_GlobalVtxDesc.Hex = 0;
s_prevcomponents = 0; s_prevcomponents = 0;
s_prevvbstride = 12; // just pos
s_prevprimitive = 0;
s_pBaseBufferPointer = (u8*)AllocateMemoryPages(MAX_BUFFER_SIZE); s_pBaseBufferPointer = (u8*)AllocateMemoryPages(MAX_BUFFER_SIZE);
s_pCurBufferPointer = s_pBaseBufferPointer; s_pCurBufferPointer = s_pBaseBufferPointer;
for (u32 i = 0; i < ARRAYSIZE(shiftLookup); i++)
shiftLookup[i] = 1.0f / float(1 << i);
s_nCurVBOIndex = 0; s_nCurVBOIndex = 0;
glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers); glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
for (u32 i = 0; i < ARRAYSIZE(s_vboBuffers); ++i) { for (u32 i = 0; i < ARRAYSIZE(s_vboBuffers); ++i) {
@ -80,7 +72,7 @@ void VertexManager::Destroy()
void VertexManager::ResetBuffer() void VertexManager::ResetBuffer()
{ {
s_nCurVBOIndex = (s_nCurVBOIndex+1)%ARRAYSIZE(s_vboBuffers); s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
s_pCurBufferPointer = s_pBaseBufferPointer; s_pCurBufferPointer = s_pBaseBufferPointer;
s_vStoredPrimitives.resize(0); s_vStoredPrimitives.resize(0);
} }
@ -88,20 +80,19 @@ void VertexManager::ResetBuffer()
void VertexManager::ResetComponents() void VertexManager::ResetComponents()
{ {
s_prevcomponents = 0; s_prevcomponents = 0;
s_prevvbstride = 12; // just pos
s_prevprimitive = 0;
glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB); glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
glDisableVertexAttribArray(SHADER_NORM1_ATTRIB); glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
glDisableVertexAttribArray(SHADER_NORM2_ATTRIB); glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_SECONDARY_COLOR_ARRAY); glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
for (int i = 0; i < 8; ++i) glDisableClientState(GL_TEXTURE_COORD_ARRAY); for (int i = 0; i < 8; i++)
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} }
int VertexManager::GetRemainingSize() int VertexManager::GetRemainingSize()
{ {
return MAX_BUFFER_SIZE - (int)(s_pCurBufferPointer-s_pBaseBufferPointer); return MAX_BUFFER_SIZE - (int)(s_pCurBufferPointer - s_pBaseBufferPointer);
} }
void VertexManager::AddVertices(int primitive, int numvertices) void VertexManager::AddVertices(int primitive, int numvertices)
@ -122,8 +113,8 @@ void VertexManager::Flush()
if (s_vStoredPrimitives.size() == 0) if (s_vStoredPrimitives.size() == 0)
return; return;
_assert_( fnSetupVertexPointers != NULL ); _assert_(fnSetupVertexPointers != NULL);
_assert_( s_pCurBufferPointer != s_pBaseBufferPointer ); _assert_(s_pCurBufferPointer != s_pBaseBufferPointer);
#ifdef _DEBUG #ifdef _DEBUG
PRIM_LOG("frame%d:\ncomps=0x%x, texgen=%d, numchan=%d, dualtex=%d, ztex=%d, proj=%d, cole=%d, alpe=%d, ze=%d\n", g_Config.iSaveTargetId, s_prevcomponents, xfregs.numTexGens, PRIM_LOG("frame%d:\ncomps=0x%x, texgen=%d, numchan=%d, dualtex=%d, ztex=%d, proj=%d, cole=%d, alpe=%d, ze=%d\n", g_Config.iSaveTargetId, s_prevcomponents, xfregs.numTexGens,
@ -135,6 +126,7 @@ void VertexManager::Flush()
ch = &xfregs.colChans[i].alpha; ch = &xfregs.colChans[i].alpha;
PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc); PRIM_LOG("alpchan%d: matsrc=%d, light=0x%x, ambsrc=%d, diffunc=%d, attfunc=%d\n", i, ch->matsource, ch->GetFullLightMask(), ch->ambsource, ch->diffusefunc, ch->attnfunc);
} }
for (int i = 0; i < xfregs.numTexGens; ++i) { for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo; TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff; if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff;
@ -183,7 +175,7 @@ void VertexManager::Flush()
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (usedtextures & (1 << i)) { if (usedtextures & (1 << i)) {
glActiveTexture(GL_TEXTURE0+i); glActiveTexture(GL_TEXTURE0+i);
FourTexUnits &tex = bpmem.tex[i>>2]; FourTexUnits &tex = bpmem.tex[i>>2];
TextureMngr::TCacheEntry* tentry = TextureMngr::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5, TextureMngr::TCacheEntry* tentry = TextureMngr::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1, tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
@ -193,9 +185,9 @@ void VertexManager::Flush()
// texture loaded fine, set dims for pixel shader // texture loaded fine, set dims for pixel shader
if (tentry->isNonPow2) { if (tentry->isNonPow2) {
PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, tentry->mode.wrap_s, tentry->mode.wrap_t); PixelShaderMngr::SetTexDims(i, tentry->w, tentry->h, tentry->mode.wrap_s, tentry->mode.wrap_t);
nonpow2tex |= 1<<i; nonpow2tex |= 1 << i;
if (tentry->mode.wrap_s > 0 ) nonpow2tex |= 1<<(8+i); if (tentry->mode.wrap_s > 0) nonpow2tex |= 1 << (8 + i);
if (tentry->mode.wrap_t > 0 ) nonpow2tex |= 1<<(16+i); if (tentry->mode.wrap_t > 0) nonpow2tex |= 1 << (16 + i);
TextureMngr::EnableTexRECT(i); TextureMngr::EnableTexRECT(i);
} }
// if texture is power of two, set to ones (since don't need scaling) // if texture is power of two, set to ones (since don't need scaling)
@ -226,7 +218,7 @@ void VertexManager::Flush()
FRAGMENTSHADER* ps = PixelShaderMngr::GetShader(); FRAGMENTSHADER* ps = PixelShaderMngr::GetShader();
VERTEXSHADER* vs = VertexShaderMngr::GetShader(s_prevcomponents); VERTEXSHADER* vs = VertexShaderMngr::GetShader(s_prevcomponents);
_assert_( ps != NULL && vs != NULL ); _assert_(ps != NULL && vs != NULL);
bool bRestoreBuffers = false; bool bRestoreBuffers = false;
if (Renderer::GetZBufferTarget()) { if (Renderer::GetZBufferTarget()) {
@ -241,9 +233,9 @@ void VertexManager::Flush()
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
bRestoreBuffers = true; bRestoreBuffers = true;
} }
} } else {
else
Renderer::SetRenderMode(Renderer::RM_Normal); Renderer::SetRenderMode(Renderer::RM_Normal);
}
// set global constants // set global constants
VertexShaderMngr::SetConstants(*vs); VertexShaderMngr::SetConstants(*vs);
@ -258,8 +250,7 @@ void VertexManager::Flush()
#endif #endif
int offset = 0; int offset = 0;
vector< pair<int, int> >::iterator it; for (vector< pair<int, int> >::const_iterator it = s_vStoredPrimitives.begin(); it != s_vStoredPrimitives.end(); ++it) {
for (it = s_vStoredPrimitives.begin(); it != s_vStoredPrimitives.end(); ++it) {
glDrawArrays(it->first, offset, it->second); glDrawArrays(it->first, offset, it->second);
offset += it->second; offset += it->second;
} }
@ -323,3 +314,59 @@ void VertexManager::LoadCPReg(u32 SubCmd, u32 Value)
case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break; case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break;
} }
} }
void VertexManager::EnableComponents(u32 components)
{
if (s_prevcomponents != components) {
VertexManager::Flush();
// matrices
if ((components & VB_HAS_POSMTXIDX) != (s_prevcomponents & VB_HAS_POSMTXIDX)) {
if (components & VB_HAS_POSMTXIDX)
glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
else
glDisableVertexAttribArray(SHADER_POSMTX_ATTRIB);
}
// normals
if ((components & VB_HAS_NRM0) != (s_prevcomponents & VB_HAS_NRM0)) {
if (components & VB_HAS_NRM0)
glEnableClientState(GL_NORMAL_ARRAY);
else
glDisableClientState(GL_NORMAL_ARRAY);
}
if ((components & VB_HAS_NRM1) != (s_prevcomponents & VB_HAS_NRM1)) {
if (components & VB_HAS_NRM1) {
glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
}
else {
glDisableVertexAttribArray(SHADER_NORM1_ATTRIB);
glDisableVertexAttribArray(SHADER_NORM2_ATTRIB);
}
}
// color
for (int i = 0; i < 2; ++i) {
if ((components & (VB_HAS_COL0 << i)) != (s_prevcomponents & (VB_HAS_COL0 << i))) {
if (components & (VB_HAS_COL0 << 0))
glEnableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
else
glDisableClientState(i ? GL_SECONDARY_COLOR_ARRAY : GL_COLOR_ARRAY);
}
}
// tex
for (int i = 0; i < 8; ++i) {
if ((components & (VB_HAS_UV0 << i)) != (s_prevcomponents & (VB_HAS_UV0 << i))) {
glClientActiveTexture(GL_TEXTURE0 + i);
if (components & (VB_HAS_UV0 << i))
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
else
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
s_prevcomponents = components;
}
}

View File

@ -49,12 +49,10 @@ public:
static TVtxDesc &GetVtxDesc() {return s_GlobalVtxDesc; } static TVtxDesc &GetVtxDesc() {return s_GlobalVtxDesc; }
static void LoadCPReg(u32 SubCmd, u32 Value); static void LoadCPReg(u32 SubCmd, u32 Value);
static void EnableComponents(u32 components);
// TODO - don't expose these like this. // TODO - don't expose these like this.
static u32 s_prevvbstride;
static u32 s_prevcomponents; // previous state set
static u8* s_pCurBufferPointer; static u8* s_pCurBufferPointer;
static float shiftLookup[32];
}; };
#endif // _VERTEXMANAGER_H #endif // _VERTEXMANAGER_H

View File

@ -111,7 +111,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
// uniforms // uniforms
// bool bTexMtx = ((components & VertexLoader::VB_HAS_TEXMTXIDXALL)<<VertexLoader::VB_HAS_UVTEXMTXSHIFT)!=0; unused TODO: keep? // bool bTexMtx = ((components & VB_HAS_TEXMTXIDXALL)<<VB_HAS_UVTEXMTXSHIFT)!=0; unused TODO: keep?
WRITE(p, "uniform s_"I_TRANSFORMMATRICES" "I_TRANSFORMMATRICES" : register(c%d);\n", C_TRANSFORMMATRICES); WRITE(p, "uniform s_"I_TRANSFORMMATRICES" "I_TRANSFORMMATRICES" : register(c%d);\n", C_TRANSFORMMATRICES);
WRITE(p, "uniform s_"I_TEXMATRICES" "I_TEXMATRICES" : register(c%d);\n", C_TEXMATRICES); // also using tex matrices WRITE(p, "uniform s_"I_TEXMATRICES" "I_TEXMATRICES" : register(c%d);\n", C_TEXMATRICES); // also using tex matrices
@ -126,60 +126,60 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
WRITE(p, "VS_OUTPUT main(\n"); WRITE(p, "VS_OUTPUT main(\n");
// inputs // inputs
if (components & VertexLoader::VB_HAS_NRM0) if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 : NORMAL,\n"); WRITE(p, " float3 rawnorm0 : NORMAL,\n");
if (components & VertexLoader::VB_HAS_NRM1) if (components & VB_HAS_NRM1)
WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB); WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
if (components & VertexLoader::VB_HAS_NRM2) if (components & VB_HAS_NRM2)
WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB); WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
if (components & VertexLoader::VB_HAS_COL0) if (components & VB_HAS_COL0)
WRITE(p, " float4 color0 : COLOR0,\n"); WRITE(p, " float4 color0 : COLOR0,\n");
if (components & VertexLoader::VB_HAS_COL1) if (components & VB_HAS_COL1)
WRITE(p, " float4 color1 : COLOR1,\n"); WRITE(p, " float4 color1 : COLOR1,\n");
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
u32 hastexmtx = (components & (VertexLoader::VB_HAS_TEXMTXIDX0<<i)); u32 hastexmtx = (components & (VB_HAS_TEXMTXIDX0<<i));
if ((components & (VertexLoader::VB_HAS_UV0<<i)) || hastexmtx ) if ((components & (VB_HAS_UV0<<i)) || hastexmtx )
WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i); WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i);
} }
if (components & VertexLoader::VB_HAS_POSMTXIDX) if (components & VB_HAS_POSMTXIDX)
WRITE(p, " half posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB); WRITE(p, " half posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
WRITE(p, " float4 rawpos : POSITION) {\n"); WRITE(p, " float4 rawpos : POSITION) {\n");
WRITE(p, "VS_OUTPUT o;\n"); WRITE(p, "VS_OUTPUT o;\n");
// transforms // transforms
if (components & VertexLoader::VB_HAS_POSMTXIDX) { if (components & VB_HAS_POSMTXIDX) {
WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos),1);\n"); WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos),1);\n");
if (components & VertexLoader::VB_HAS_NRMALL) { if (components & VB_HAS_NRMALL) {
WRITE(p, "int normidx = posmtx >= 32 ? (posmtx-32) : posmtx;\n"); WRITE(p, "int normidx = posmtx >= 32 ? (posmtx-32) : posmtx;\n");
WRITE(p, "float3 N0 = "I_NORMALMATRICES".T[normidx].t.xyz, N1 = "I_NORMALMATRICES".T[normidx+1].t.xyz, N2 = "I_NORMALMATRICES".T[normidx+2].t.xyz;\n"); WRITE(p, "float3 N0 = "I_NORMALMATRICES".T[normidx].t.xyz, N1 = "I_NORMALMATRICES".T[normidx+1].t.xyz, N2 = "I_NORMALMATRICES".T[normidx+2].t.xyz;\n");
} }
if (components & VertexLoader::VB_HAS_NRM0) if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n" WRITE(p, "half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n"); "half3 norm0 = normalize(_norm0);\n");
if (components & VertexLoader::VB_HAS_NRM1) if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n"); WRITE(p, "half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n"); //"half3 norm1 = normalize(_norm1);\n");
if (components & VertexLoader::VB_HAS_NRM2) if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n"); WRITE(p, "half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n"); //"half3 norm2 = normalize(_norm2);\n");
} }
else { else {
WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1);\n"); WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1);\n");
if (components & VertexLoader::VB_HAS_NRM0) if (components & VB_HAS_NRM0)
WRITE(p, "half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n" WRITE(p, "half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
"half3 norm0 = normalize(_norm0);\n"); "half3 norm0 = normalize(_norm0);\n");
if (components & VertexLoader::VB_HAS_NRM1) if (components & VB_HAS_NRM1)
WRITE(p, "half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n"); WRITE(p, "half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
//"half3 norm1 = normalize(_norm1);\n"); //"half3 norm1 = normalize(_norm1);\n");
if (components & VertexLoader::VB_HAS_NRM2) if (components & VB_HAS_NRM2)
WRITE(p, "half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n"); WRITE(p, "half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
//"half3 norm2 = normalize(_norm2);\n"); //"half3 norm2 = normalize(_norm2);\n");
} }
if (!(components & VertexLoader::VB_HAS_NRM0)) if (!(components & VB_HAS_NRM0))
WRITE(p, "half3 _norm0 = half3(0,0,0), norm0= half3(0,0,0);\n"); WRITE(p, "half3 _norm0 = half3(0,0,0), norm0= half3(0,0,0);\n");
WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n"); WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n");
@ -198,7 +198,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
WRITE(p, "{\n"); WRITE(p, "{\n");
if (color.matsource) {// from vertex if (color.matsource) {// from vertex
if (components & (VertexLoader::VB_HAS_COL0<<j) ) if (components & (VB_HAS_COL0<<j) )
WRITE(p, "mat = color%d;\n", j); WRITE(p, "mat = color%d;\n", j);
else WRITE(p, "mat = half4(1,1,1,1);\n"); else WRITE(p, "mat = half4(1,1,1,1);\n");
} }
@ -207,7 +207,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
if (color.enablelighting) { if (color.enablelighting) {
if (color.ambsource) {// from vertex if (color.ambsource) {// from vertex
if (components & (VertexLoader::VB_HAS_COL0<<j) ) if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc = color%d;\n", j); WRITE(p, "lacc = color%d;\n", j);
else WRITE(p, "lacc = half4(0.0f,0.0f,0.0f,0.0f);\n"); else WRITE(p, "lacc = half4(0.0f,0.0f,0.0f,0.0f);\n");
} }
@ -218,7 +218,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
// check if alpha is different // check if alpha is different
if (alpha.matsource != color.matsource) { if (alpha.matsource != color.matsource) {
if (alpha.matsource) {// from vertex if (alpha.matsource) {// from vertex
if (components & (VertexLoader::VB_HAS_COL0<<j) ) if (components & (VB_HAS_COL0<<j) )
WRITE(p, "mat.w = color%d.w;\n", j); WRITE(p, "mat.w = color%d.w;\n", j);
else WRITE(p, "mat.w = 1;\n"); else WRITE(p, "mat.w = 1;\n");
} }
@ -228,7 +228,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
if (alpha.enablelighting && alpha.ambsource != color.ambsource) { if (alpha.enablelighting && alpha.ambsource != color.ambsource) {
if (alpha.ambsource) {// from vertex if (alpha.ambsource) {// from vertex
if (components & (VertexLoader::VB_HAS_COL0<<j) ) if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc.w = color%d.w;\n", j); WRITE(p, "lacc.w = color%d.w;\n", j);
else WRITE(p, "lacc.w = 0;\n"); else WRITE(p, "lacc.w = 0;\n");
} }
@ -298,7 +298,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
WRITE(p, "float4 coord = rawpos;\n"); // pos.w is 1 WRITE(p, "float4 coord = rawpos;\n"); // pos.w is 1
break; break;
case XF_SRCNORMAL_INROW: case XF_SRCNORMAL_INROW:
if (components & VertexLoader::VB_HAS_NRM0) { if (components & VB_HAS_NRM0) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 ); _assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm0.xyz, 1.0);\n"); WRITE(p, "float4 coord = float4(rawnorm0.xyz, 1.0);\n");
} }
@ -308,14 +308,14 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
_assert_( texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC0 || texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC1 ); _assert_( texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC0 || texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC1 );
break; break;
case XF_SRCBINORMAL_T_INROW: case XF_SRCBINORMAL_T_INROW:
if (components & VertexLoader::VB_HAS_NRM1) { if (components & VB_HAS_NRM1) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 ); _assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm1.xyz, 1.0);\n"); WRITE(p, "float4 coord = float4(rawnorm1.xyz, 1.0);\n");
} }
else WRITE(p, "float4 coord = 0;\n"); else WRITE(p, "float4 coord = 0;\n");
break; break;
case XF_SRCBINORMAL_B_INROW: case XF_SRCBINORMAL_B_INROW:
if (components & VertexLoader::VB_HAS_NRM2) { if (components & VB_HAS_NRM2) {
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 ); _assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
WRITE(p, "float4 coord = float4(rawnorm2.xyz, 1.0);\n"); WRITE(p, "float4 coord = float4(rawnorm2.xyz, 1.0);\n");
} }
@ -323,7 +323,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
break; break;
default: default:
_assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW); _assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW);
if (components & (VertexLoader::VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) ) if (components & (VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) )
WRITE(p, "float4 coord = float4(tex%d.x, tex%d.y, 1.0f, 1.0f);\n", texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW); WRITE(p, "float4 coord = float4(tex%d.x, tex%d.y, 1.0f, 1.0f);\n", texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW);
else else
WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n");
@ -333,7 +333,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
// firs transformation // firs transformation
switch (texinfo.texgentype) { switch (texinfo.texgentype) {
case XF_TEXGEN_REGULAR: case XF_TEXGEN_REGULAR:
if (components & (VertexLoader::VB_HAS_TEXMTXIDX0<<i)) { if (components & (VB_HAS_TEXMTXIDX0<<i)) {
if (texinfo.projection == XF_TEXPROJ_STQ ) if (texinfo.projection == XF_TEXPROJ_STQ )
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+2].t));\n", i, i, i, i); WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+2].t));\n", i, i, i, i);
else { else {
@ -349,7 +349,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
break; break;
case XF_TEXGEN_EMBOSS_MAP: // calculate tex coords into bump map case XF_TEXGEN_EMBOSS_MAP: // calculate tex coords into bump map
if (components & (VertexLoader::VB_HAS_NRM1|VertexLoader::VB_HAS_NRM2)) { if (components & (VB_HAS_NRM1|VB_HAS_NRM2)) {
// transform the light dir into tangent space // transform the light dir into tangent space
WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift); WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift);
WRITE(p, "o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift); WRITE(p, "o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift);