mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 22:59:47 -06:00
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:
@ -28,9 +28,12 @@ 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 < 32; i++)
|
||||||
|
shiftLookup[i] = 1.0f / float(1 << i);
|
||||||
for (int i = 0; i < 64; i++)
|
for (int i = 0; i < 64; i++)
|
||||||
lut6to8[i] = (i*255) / 63;
|
lut6to8[i] = (i*255) / 63;
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
|
@ -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"
|
||||||
|
@ -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) {
|
||||||
|
@ -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.
|
||||||
|
|
||||||
@ -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++)
|
||||||
@ -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();
|
||||||
|
|
||||||
|
@ -32,18 +32,6 @@ using namespace std;
|
|||||||
#define LOADERDECL __cdecl
|
#define LOADERDECL __cdecl
|
||||||
typedef void (LOADERDECL *TPipelineFunction)(void*);
|
typedef void (LOADERDECL *TPipelineFunction)(void*);
|
||||||
|
|
||||||
// There are 8 of these. Most games only use the first, and just reconfigure it all the time
|
|
||||||
// as needed, unfortunately.
|
|
||||||
class VertexLoader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
NRM_ZERO = 0,
|
|
||||||
NRM_ONE = 1,
|
|
||||||
NRM_THREE = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
// m_components
|
// m_components
|
||||||
enum {
|
enum {
|
||||||
VB_HAS_POSMTXIDX =(1<<1),
|
VB_HAS_POSMTXIDX =(1<<1),
|
||||||
@ -77,6 +65,19 @@ public:
|
|||||||
VB_HAS_UVTEXMTXSHIFT=13,
|
VB_HAS_UVTEXMTXSHIFT=13,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// There are 8 of these. Most games only use the first, and just reconfigure it all the time
|
||||||
|
// as needed, unfortunately.
|
||||||
|
class VertexLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
NRM_ZERO = 0,
|
||||||
|
NRM_ONE = 1,
|
||||||
|
NRM_THREE = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TPipelineFunction m_PipelineStates[32];
|
TPipelineFunction m_PipelineStates[32];
|
||||||
int m_numPipelineStates;
|
int m_numPipelineStates;
|
||||||
|
@ -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) {
|
||||||
@ -88,15 +80,14 @@ 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()
|
||||||
@ -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;
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -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);
|
||||||
|
Reference in New Issue
Block a user