moar cleanup

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1694 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-12-26 17:02:46 +00:00
parent acd0e0d8da
commit 2a552421a5
23 changed files with 435 additions and 493 deletions

View file

@ -97,6 +97,7 @@ public:
virtual void Initialize(const PortableVertexDeclaration &vtx_decl) = 0;
virtual void SetupVertexPointers() const = 0;
virtual void EnableComponents(u32 components) {}
static NativeVertexFormat *Create();

View file

@ -25,9 +25,8 @@ namespace VertexManager
void AddVertices(int primitive, int numvertices);
void Flush(); // flushes the current buffer
// These two don't really belong here and are not relevant for D3D - TODO, find better place to put them.
// This doesn't really belong here and are not relevant for D3D - TODO, find better place to put them.
int GetRemainingSize(); // remaining space in the current buffer.
void EnableComponents(u32 components); // very implementation specific - D3D9 won't need this one.
// TODO: move, rename.
extern u8* s_pCurBufferPointer;

View file

@ -507,7 +507,7 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int count)
return;
}
VertexManager::EnableComponents(m_NativeFmt->m_components);
m_NativeFmt->EnableComponents(m_NativeFmt->m_components);
// Load position and texcoord scale factors.
m_VtxAttr.PosFrac = g_VtxAttr[vtx_attr_group].g0.PosFrac;

View file

@ -1237,6 +1237,10 @@
RelativePath=".\Src\VertexLoader_TextCoord.h"
>
</File>
<File
RelativePath=".\Src\VertexLoaderManager.cpp"
>
</File>
<File
RelativePath=".\Src\VertexManager.cpp"
>

View file

@ -18,8 +18,6 @@
#ifndef _BPSTRUCTS_H
#define _BPSTRUCTS_H
#pragma pack(4)
#include "BPMemory.h"
void BPInit();

View file

@ -39,7 +39,6 @@ void Config::Load()
iniFile.Get("Settings", "OverlayStats", &bOverlayStats, false);
iniFile.Get("Settings", "Postprocess", &iPostprocessEffect, 0);
iniFile.Get("Settings", "DLOptimize", &iCompileDLsLevel, 0);
iniFile.Get("Settings", "DumpTextures", &bDumpTextures, 0);
iniFile.Get("Settings", "ShowShaderErrors", &bShowShaderErrors, 0);
iniFile.Get("Settings", "Multisample", &iMultisampleMode, 0);
@ -67,7 +66,6 @@ void Config::Save()
iniFile.Set("Settings", "OverlayStats", bOverlayStats);
iniFile.Set("Settings", "OverlayStats", bOverlayStats);
iniFile.Set("Settings", "Postprocess", iPostprocessEffect);
iniFile.Set("Settings", "DLOptimize", iCompileDLsLevel);
iniFile.Set("Settings", "DumpTextures", bDumpTextures);
iniFile.Set("Settings", "ShowShaderErrors", bShowShaderErrors);
iniFile.Set("Settings", "Multisample", iMultisampleMode);

View file

@ -31,7 +31,6 @@ struct Config
int iMultisampleMode;
int iPostprocessEffect;
int iCompileDLsLevel;
bool renderToMainframe;
bool bFullscreen;

View file

@ -21,10 +21,11 @@
namespace D3D
{
bool fullScreen = false, nextFullScreen=false;
LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device
LPDIRECT3DSURFACE9 backBuffer;
bool fullScreen = false;
bool nextFullScreen = false;
LPDIRECT3D9 D3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 dev = NULL; // Our rendering device
LPDIRECT3DSURFACE9 backBuffer;
D3DCAPS9 caps;
int multisample;
int resolution;
@ -163,7 +164,7 @@ namespace D3D
{
if (qlevels > 2)
{
// 8x, 8xQ are available
// 16x, 16xQ are available
// See http://developer.nvidia.com/object/coverage-sampled-aa.html
a.aa_levels.push_back(AALevel("16x CSAA", D3DMULTISAMPLE_4_SAMPLES, 4));
a.aa_levels.push_back(AALevel("16xQ CSAA", D3DMULTISAMPLE_8_SAMPLES, 2));
@ -337,10 +338,12 @@ namespace D3D
{
return xres;
}
int GetDisplayHeight()
{
return yres;
}
void SwitchFullscreen(bool fullscreen)
{
nextFullScreen = fullscreen;
@ -386,4 +389,4 @@ namespace D3D
}
}
}
} // namespace

View file

@ -21,88 +21,89 @@
#include "Config.h"
#include "D3DShader.h"
namespace D3D
{
LPDIRECT3DVERTEXSHADER9 CompileVShader(const char *code, int len)
LPDIRECT3DVERTEXSHADER9 CompileVShader(const char *code, int len)
{
//try to compile
LPD3DXBUFFER shaderBuffer = 0;
LPD3DXBUFFER errorBuffer = 0;
LPDIRECT3DVERTEXSHADER9 vShader = 0;
HRESULT hr = D3DXCompileShader(code, len, 0, 0, "main", "vs_1_1", 0, &shaderBuffer, &errorBuffer, 0);
if (FAILED(hr))
{
//try to compile
LPD3DXBUFFER shaderBuffer = 0, errorBuffer = 0;
LPDIRECT3DVERTEXSHADER9 vShader = 0;
HRESULT hr = D3DXCompileShader(code,len,0,0,"main","vs_1_1",0,&shaderBuffer,&errorBuffer,0);
if (FAILED(hr))
{
//let's try 2.0
hr = D3DXCompileShader(code,len,0,0,"main","vs_2_0",0,&shaderBuffer,&errorBuffer,0);
}
if (FAILED(hr))
{
//compilation error
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
if (g_Config.bShowShaderErrors)
MessageBox(0, hello.c_str(), "Error compiling vertex shader", MB_ICONERROR);
vShader = 0;
}
else if (SUCCEEDED(hr))
{
//create it
HRESULT hr = E_FAIL;
if (shaderBuffer)
hr = D3D::dev->CreateVertexShader((DWORD *)shaderBuffer->GetBufferPointer(), &vShader);
if (FAILED(hr) || vShader == 0)
{
if (g_Config.bShowShaderErrors)
MessageBox(0,code,(char*)errorBuffer->GetBufferPointer(),MB_ICONERROR);
}
}
//cleanup
if (shaderBuffer)
shaderBuffer->Release();
if (errorBuffer)
errorBuffer->Release();
return vShader;
//let's try 2.0
hr = D3DXCompileShader(code, len, 0, 0, "main", "vs_2_0", 0, &shaderBuffer, &errorBuffer, 0);
}
LPDIRECT3DPIXELSHADER9 CompilePShader(const char *code, int len)
if (FAILED(hr))
{
LPD3DXBUFFER shaderBuffer = 0, errorBuffer = 0;
LPDIRECT3DPIXELSHADER9 pShader = 0;
static char *versions[6] = {"ERROR","ps_1_1","ps_1_4","ps_2_0","ps_3_0","ps_4_0"};
HRESULT hr = D3DXCompileShader(code,len,0,0,
"main","ps_2_0", // Pixel Shader 2.0 is enough for all we do
0,&shaderBuffer,&errorBuffer,0);
if (FAILED(hr))
{
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
if (g_Config.bShowShaderErrors)
MessageBox(0, hello.c_str(), "Error compiling pixel shader", MB_ICONERROR);
pShader = 0;
}
else
{
//create it
HRESULT hr = D3D::dev->CreatePixelShader((DWORD *)shaderBuffer->GetBufferPointer(), &pShader);
if (FAILED(hr) || pShader == 0)
{
if (g_Config.bShowShaderErrors)
MessageBox(0,"damn","error creating pixelshader",MB_ICONERROR);
}
}
//cleanup
if (shaderBuffer)
shaderBuffer->Release();
if (errorBuffer)
errorBuffer->Release();
return pShader;
//compilation error
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
if (g_Config.bShowShaderErrors)
MessageBox(0, hello.c_str(), "Error compiling vertex shader", MB_ICONERROR);
vShader = 0;
}
else if (SUCCEEDED(hr))
{
//create it
HRESULT hr = E_FAIL;
if (shaderBuffer)
hr = D3D::dev->CreateVertexShader((DWORD *)shaderBuffer->GetBufferPointer(), &vShader);
if (FAILED(hr) || vShader == 0)
{
if (g_Config.bShowShaderErrors)
MessageBox(0,code,(char*)errorBuffer->GetBufferPointer(),MB_ICONERROR);
}
}
//cleanup
if (shaderBuffer)
shaderBuffer->Release();
if (errorBuffer)
errorBuffer->Release();
return vShader;
}
LPDIRECT3DPIXELSHADER9 CompilePShader(const char *code, int len)
{
LPD3DXBUFFER shaderBuffer = 0;
LPD3DXBUFFER errorBuffer = 0;
LPDIRECT3DPIXELSHADER9 pShader = 0;
static char *versions[6] = {"ERROR", "ps_1_1", "ps_1_4", "ps_2_0", "ps_3_0", "ps_4_0"};
HRESULT hr = D3DXCompileShader(code, len, 0, 0, "main", "ps_2_0", // Pixel Shader 2.0 is enough for all we do
0, &shaderBuffer, &errorBuffer, 0);
if (FAILED(hr))
{
std::string hello = (char*)errorBuffer->GetBufferPointer();
hello += "\n\n";
hello += code;
if (g_Config.bShowShaderErrors)
MessageBox(0, hello.c_str(), "Error compiling pixel shader", MB_ICONERROR);
pShader = 0;
}
else
{
//create it
HRESULT hr = D3D::dev->CreatePixelShader((DWORD *)shaderBuffer->GetBufferPointer(), &pShader);
if (FAILED(hr) || pShader == 0)
{
if (g_Config.bShowShaderErrors)
MessageBox(0,"damn","error creating pixelshader",MB_ICONERROR);
}
}
//cleanup
if (shaderBuffer)
shaderBuffer->Release();
if (errorBuffer)
errorBuffer->Release();
return pShader;
}
}

View file

@ -20,96 +20,97 @@
namespace D3D
{
LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int height,const int pitch, D3DFORMAT fmt)
LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int height,const int pitch, D3DFORMAT fmt)
{
u32* pBuffer = (u32*)buffer;
LPDIRECT3DTEXTURE9 pTexture;
// crazy bitmagic, sorry :)
bool isPow2 = !((width&(width-1)) || (height&(height-1)));
HRESULT hr;
// TODO(ector): allow mipmaps for non-pow textures on newer cards?
if (!isPow2)
hr = dev->CreateTexture(width, height, 1, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
else
hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
if(FAILED(hr))
return 0;
int level = 0;
D3DLOCKED_RECT Lock;
pTexture->LockRect(level, &Lock, NULL, 0 );
u32* pIn = pBuffer;
switch(fmt)
{
u32* pBuffer = (u32*)buffer;
LPDIRECT3DTEXTURE9 pTexture;
// crazy bitmagic
bool isPow2 = !((width&(width-1)) || (height&(height-1)));
HRESULT hr;
// TODO(ector): allow mipmaps for non-pow textures on newer cards?
if (!isPow2)
hr = dev->CreateTexture(width, height, 1, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
else
hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
if(FAILED(hr))
return 0;
int level = 0;
D3DLOCKED_RECT Lock;
pTexture->LockRect(level, &Lock, NULL, 0 );
u32* pIn = pBuffer;
switch(fmt)
case D3DFMT_A8R8G8B8:
{
case D3DFMT_A8R8G8B8:
for (int y = 0; y < height; y++)
{
for (int y = 0; y < height; y++)
{
u32* pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
memcpy(pBits, pIn, width * 4);
pIn += pitch;
}
u32* pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
memcpy(pBits, pIn, width * 4);
pIn += pitch;
}
break;
case D3DFMT_DXT1:
memcpy(Lock.pBits,buffer,(width/4)*(height/4)*8);
break;
}
pTexture->UnlockRect(level);
return pTexture;
}
void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int width, const int height,const int pitch, D3DFORMAT fmt)
{
u32* pBuffer = (u32*)buffer;
int level = 0;
D3DLOCKED_RECT Lock;
pTexture->LockRect(level, &Lock, NULL, 0 );
u32* pIn = pBuffer;
switch(fmt)
{
case D3DFMT_A8R8G8B8:
{
for (int y = 0; y < height; y++)
{
u32* pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
memcpy(pBits,pIn, width*4);
pIn += pitch;
}
}
break;
case D3DFMT_DXT1:
memcpy(Lock.pBits,buffer,(width/4)*(height/4)*8);
break;
}
pTexture->UnlockRect(level);
}
LPDIRECT3DTEXTURE9 CreateRenderTarget(const int width, const int height)
{
LPDIRECT3DTEXTURE9 tex;
HRESULT hr = dev->CreateTexture(width,height,0,D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&tex,NULL);
if (FAILED(hr))
return 0;
else
return tex;
}
LPDIRECT3DSURFACE9 CreateDepthStencilSurface(const int width, const int height)
{
LPDIRECT3DSURFACE9 surf;
HRESULT hr = dev->CreateDepthStencilSurface(width,height,D3DFMT_D24S8,D3DMULTISAMPLE_NONE,0,0,&surf,0);
if (FAILED(hr))
return 0;
else
return surf;
break;
case D3DFMT_DXT1:
memcpy(Lock.pBits,buffer,(width/4)*(height/4)*8);
break;
}
pTexture->UnlockRect(level);
return pTexture;
}
void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int width, const int height,const int pitch, D3DFORMAT fmt)
{
u32* pBuffer = (u32*)buffer;
int level = 0;
D3DLOCKED_RECT Lock;
pTexture->LockRect(level, &Lock, NULL, 0 );
u32* pIn = pBuffer;
switch(fmt)
{
case D3DFMT_A8R8G8B8:
{
for (int y = 0; y < height; y++)
{
u32* pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
memcpy(pBits, pIn, width * 4);
pIn += pitch;
}
}
break;
case D3DFMT_DXT1:
memcpy(Lock.pBits,buffer,(width/4)*(height/4)*8);
break;
}
pTexture->UnlockRect(level);
}
LPDIRECT3DTEXTURE9 CreateRenderTarget(const int width, const int height)
{
LPDIRECT3DTEXTURE9 tex;
HRESULT hr = dev->CreateTexture(width,height,0,D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&tex,NULL);
if (FAILED(hr))
return 0;
else
return tex;
}
LPDIRECT3DSURFACE9 CreateDepthStencilSurface(const int width, const int height)
{
LPDIRECT3DSURFACE9 surf;
HRESULT hr = dev->CreateDepthStencilSurface(width,height,D3DFMT_D24S8,D3DMULTISAMPLE_NONE,0,0,&surf,0);
if (FAILED(hr))
return 0;
else
return surf;
}
} // namespace

View file

@ -36,7 +36,7 @@ namespace D3D
#define D3DFVF_FONT2DVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
#define D3DFVF_FONT3DVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_NORMAL|D3DFVF_TEX1)
inline FONT2DVERTEX InitFont2DVertex( float x, float y, u32 color, float tu, float tv )
inline FONT2DVERTEX InitFont2DVertex(float x, float y, u32 color, float tu, float tv)
{
FONT2DVERTEX v; v.x=x; v.y=y; v.z=0; v.rhw=1.0f; v.color = color; v.tu = tu; v.tv = tv;
return v;
@ -51,17 +51,16 @@ namespace D3D
int CD3DFont::Init()
{
int hr;
m_fTextScale = 1.0f; // Draw fonts into texture without scaling
// Create a new texture for the font
hr = dev->CreateTexture( m_dwTexWidth, m_dwTexHeight, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &m_pTexture, NULL );
if( FAILED(hr) )
HRESULT hr = dev->CreateTexture(m_dwTexWidth, m_dwTexHeight, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, &m_pTexture, NULL);
if (FAILED(hr))
return hr;
// Prepare to create a bitmap
int *pBitmapBits;
BITMAPINFO bmi;
ZeroMemory( &bmi.bmiHeader, sizeof(BITMAPINFOHEADER) );
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
@ -70,33 +69,32 @@ namespace D3D
bmi.bmiHeader.biBitCount = 32;
// Create a DC and a bitmap for the font
HDC hDC = CreateCompatibleDC( NULL );
HBITMAP hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
(VOID**)&pBitmapBits, NULL, 0 );
SetMapMode( hDC, MM_TEXT );
HDC hDC = CreateCompatibleDC(NULL);
HBITMAP hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (VOID**)&pBitmapBits, NULL, 0);
SetMapMode(hDC, MM_TEXT);
// Create a font. By specifying ANTIALIASED_QUALITY, we might get an
// antialiased font, but this is not guaranteed.
// We definitely don't want to get it cleartype'd, anyway.
int m_dwFontHeight = 36;
int nHeight = -MulDiv( m_dwFontHeight, int(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
int nHeight = -MulDiv(m_dwFontHeight, int(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72);
int dwBold = FW_NORMAL; ///FW_BOLD
HFONT hFont = CreateFont( nHeight, 0, 0, 0, dwBold, 0,
HFONT hFont = CreateFont(nHeight, 0, 0, 0, dwBold, 0,
FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
VARIABLE_PITCH, "Tahoma");
VARIABLE_PITCH, "Courier New");
if (NULL == hFont)
return E_FAIL;
HGDIOBJ hOldbmBitmap = SelectObject( hDC, hbmBitmap );
HGDIOBJ hOldFont = SelectObject( hDC, hFont );
HGDIOBJ hOldbmBitmap = SelectObject(hDC, hbmBitmap);
HGDIOBJ hOldFont = SelectObject(hDC, hFont);
// Set text properties
SetTextColor( hDC, 0xFFFFFF );
SetBkColor ( hDC, 0 );
SetTextAlign( hDC, TA_TOP );
SetTextColor(hDC, 0xFFFFFF);
SetBkColor (hDC, 0);
SetTextAlign(hDC, TA_TOP);
// Loop through all printable character and output them to the bitmap..
// Meanwhile, keep track of the corresponding tex coords for each character.
@ -105,18 +103,18 @@ namespace D3D
char str[2] = "\0";
SIZE size;
for( char c=0; c<127-32; c++ )
for (char c=0; c<127-32; c++)
{
str[0] = c+32;
GetTextExtentPoint32( hDC, str, 1, &size );
GetTextExtentPoint32(hDC, str, 1, &size);
if( (int)(x+size.cx+1) > m_dwTexWidth )
if ((int)(x+size.cx+1) > m_dwTexWidth)
{
x = 0;
y += size.cy+1;
}
ExtTextOut( hDC, x+1, y+0, ETO_OPAQUE | ETO_CLIPPED, NULL, str, 1, NULL );
ExtTextOut(hDC, x+1, y+0, ETO_OPAQUE | ETO_CLIPPED, NULL, str, 1, NULL);
m_fTexCoords[c][0] = ((float)(x+0))/m_dwTexWidth;
m_fTexCoords[c][1] = ((float)(y+0))/m_dwTexHeight;
@ -128,13 +126,13 @@ namespace D3D
// Lock the surface and write the alpha values for the set pixels
D3DLOCKED_RECT d3dlr;
m_pTexture->LockRect( 0, &d3dlr, 0, 0 );
m_pTexture->LockRect(0, &d3dlr, 0, 0);
unsigned short* pDst16 = (unsigned short*)d3dlr.pBits;
int bAlpha; // 4-bit measure of pixel intensity
for( y=0; y < m_dwTexHeight; y++ )
for (y=0; y < m_dwTexHeight; y++)
{
for( x=0; x < m_dwTexWidth; x++ )
for (x=0; x < m_dwTexWidth; x++)
{
bAlpha = ((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4);
*pDst16++ = (bAlpha << 12) | 0x0fff;
@ -144,16 +142,16 @@ namespace D3D
// Done updating texture, so clean up used objects
m_pTexture->UnlockRect(0);
SelectObject( hDC, hOldbmBitmap );
DeleteObject( hbmBitmap );
SelectObject(hDC, hOldbmBitmap);
DeleteObject(hbmBitmap);
SelectObject( hDC, hOldFont );
DeleteObject( hFont );
SelectObject(hDC, hOldFont);
DeleteObject(hFont);
// Create vertex buffer for the letters
if( FAILED( hr = dev->CreateVertexBuffer( MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
if (FAILED(hr = dev->CreateVertexBuffer(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
D3DPOOL_DEFAULT, &m_pVB,NULL ) ) )
D3DPOOL_DEFAULT, &m_pVB,NULL)))
{
return hr;
}
@ -163,8 +161,8 @@ namespace D3D
int CD3DFont::Shutdown()
{
SAFE_RELEASE( m_pVB );
SAFE_RELEASE( m_pTexture );
SAFE_RELEASE(m_pVB);
SAFE_RELEASE(m_pTexture);
return S_OK;
}
@ -213,7 +211,7 @@ namespace D3D
void CD3DFont::SetRenderStates()
{
// dev->SetTexture(0, m_pTexture);
Renderer::SetTexture( 0, m_pTexture );
Renderer::SetTexture(0, m_pTexture);
dev->SetPixelShader(0);
dev->SetVertexShader(0);
@ -226,15 +224,15 @@ namespace D3D
// dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0],RS[i][1]);
// dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]);
Renderer::SetRenderState( (_D3DRENDERSTATETYPE)RS[i][0], RS[i][1] );
Renderer::SetTextureStageState( 0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1] );
Renderer::SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS[i][1]);
Renderer::SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]);
}
}
void RestoreRenderStates()
{
// dev->SetTexture(0, texture_old);
Renderer::SetTexture( 0, texture_old );
Renderer::SetTexture(0, texture_old);
dev->SetPixelShader(ps_old);
dev->SetVertexShader(vs_old);
@ -248,16 +246,16 @@ namespace D3D
// dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]);
// dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]);
Renderer::SetRenderState( (_D3DRENDERSTATETYPE)RS[i][0], RS_old[i] );
Renderer::SetTextureStageState( 0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i] );
Renderer::SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]);
Renderer::SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]);
}
}
int CD3DFont::DrawTextScaled( float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const char* strText, bool center )
int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const char* strText, bool center)
{
SaveRenderStates();
SetRenderStates();
dev->SetStreamSource( 0, m_pVB, 0, sizeof(FONT2DVERTEX) );
dev->SetStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX));
float vpWidth = 1;
float vpHeight = 1;
@ -267,11 +265,11 @@ namespace D3D
float fStartX = sx;
float invLineHeight = 1.0f / (( m_fTexCoords[0][3] - m_fTexCoords[0][1] ) * m_dwTexHeight);
float invLineHeight = 1.0f / ((m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight);
// Fill vertex buffer
FONT2DVERTEX* pVertices;
int dwNumTriangles = 0L;
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
const char *oldstrText=strText;
//First, let's measure the text
@ -279,13 +277,13 @@ namespace D3D
float mx=0;
float maxx=0;
while( *strText )
while(*strText)
{
char c = *strText++;
if( c == ('\n') )
if (c == ('\n'))
mx=0;
if( c < (' ') )
if (c < (' '))
continue;
float tx1 = m_fTexCoords[c-32][0];
@ -309,16 +307,16 @@ namespace D3D
float wScale=(fXScale*vpHeight)*invLineHeight;
float hScale=(fYScale*vpHeight)*invLineHeight;
while( *strText )
while(*strText)
{
char c = *strText++;
if( c == ('\n') )
if (c == ('\n'))
{
sx = fStartX;
sy += fYScale*vpHeight;
}
if( c < (' ') )
if (c < (' '))
continue;
c-=32;
@ -347,15 +345,15 @@ namespace D3D
pVertices+=6;
dwNumTriangles += 2;
if( dwNumTriangles * 3 > (MAX_NUM_VERTICES-6) )
if (dwNumTriangles * 3 > (MAX_NUM_VERTICES-6))
{
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
// dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
Renderer::DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
// dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
dwNumTriangles = 0;
}
@ -364,10 +362,10 @@ namespace D3D
// Unlock and render the vertex buffer
m_pVB->Unlock();
if( dwNumTriangles > 0 )
if (dwNumTriangles > 0)
{
// dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
Renderer::DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
// dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
}
RestoreRenderStates();
return S_OK;
@ -386,12 +384,10 @@ namespace D3D
dev->SetVertexShader(0);
dev->SetVertexDeclaration(0);
// dev->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
// dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,coords,sizeof(Q2DVertex));
Renderer::SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
Renderer::DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,coords,sizeof(Q2DVertex));
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex));
RestoreRenderStates();
}
}
} // namespace

View file

@ -112,12 +112,12 @@ struct TabAdvanced : public W32Util::Tab
{
void Init(HWND hDlg)
{
HWND opt = GetDlgItem(hDlg,IDC_DLOPTLEVEL);
ComboBox_AddString(opt,"0: Interpret (slowest, most compatible)");
ComboBox_AddString(opt,"1: Compile lists and decode vertex lists");
// HWND opt = GetDlgItem(hDlg,IDC_DLOPTLEVEL);
// ComboBox_AddString(opt,"0: Interpret (slowest, most compatible)");
// ComboBox_AddString(opt,"1: Compile lists and decode vertex lists");
//ComboBox_AddString(opt,"2: Compile+decode to vbufs and use hw xform");
//ComboBox_AddString(opt,"Recompile to vbuffers and shaders");
ComboBox_SetCurSel(opt,g_Config.iCompileDLsLevel);
// ComboBox_SetCurSel(opt,g_Config.iCompileDLsLevel);
Button_SetCheck(GetDlgItem(hDlg,IDC_OVERLAYSTATS), g_Config.bOverlayStats);
Button_SetCheck(GetDlgItem(hDlg,IDC_WIREFRAME), g_Config.bWireFrame);
@ -158,7 +158,6 @@ struct TabAdvanced : public W32Util::Tab
g_Config.bOverlayStats = Button_GetCheck(GetDlgItem(hDlg,IDC_OVERLAYSTATS)) ? true : false;
g_Config.bWireFrame = Button_GetCheck(GetDlgItem(hDlg,IDC_WIREFRAME)) ? true : false;
g_Config.bDumpTextures = Button_GetCheck(GetDlgItem(hDlg,IDC_TEXDUMP)) ? true : false;
g_Config.iCompileDLsLevel = (int)ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_DLOPTLEVEL));
g_Config.bShowShaderErrors = Button_GetCheck(GetDlgItem(hDlg,IDC_SHOWSHADERERRORS)) ? true : false;
char temp[MAX_PATH];
GetWindowText(GetDlgItem(hDlg,IDC_TEXDUMPPATH), temp, MAX_PATH);
@ -166,26 +165,6 @@ struct TabAdvanced : public W32Util::Tab
}
};
struct TabDebug : public W32Util::Tab
{
void Init(HWND hDlg)
{
}
void Command(HWND hDlg,WPARAM wParam)
{
/*
switch (LOWORD(wParam))
{
default:
break;
}
*/
}
void Apply(HWND hDlg)
{
}
};
struct TabEnhancements : public W32Util::Tab
{
void Init(HWND hDlg)
@ -234,7 +213,6 @@ void DlgSettings_Show(HINSTANCE hInstance, HWND _hParent)
sheet.Add(new TabDirect3D,(LPCTSTR)IDD_SETTINGS,"Direct3D");
sheet.Add(new TabEnhancements,(LPCTSTR)IDD_ENHANCEMENTS,"Enhancements");
sheet.Add(new TabAdvanced,(LPCTSTR)IDD_ADVANCED,"Advanced");
//sheet.Add(new TabDebug,(LPCTSTR)IDD_DEBUGGER,"Debugger");
sheet.Show(hInstance,_hParent,"Graphics Plugin");
g_Config.Save();

View file

@ -20,11 +20,11 @@
#include "Common.h"
#include "D3DShader.h"
const char *GeneratePixelShader();
#define PS_CONST_COLORS 0
#define PS_CONST_KCOLORS 4
#define PS_CONST_CONSTALPHA 8
#define PS_CONST_ALPHAREF 9 // x,y
#define PS_CONST_INDMTXSTART 10
#define PS_CONST_INDSIZE 2
#define PS_CONST_INDSIZE 2
const char *GeneratePixelShader();

View file

@ -24,7 +24,6 @@
#include "BPMemory.h"
#include "XFMemory.h"
PShaderCache::PSCache PShaderCache::pshaders;
//I hope we don't get too many hash collisions :p

View file

@ -39,7 +39,8 @@
float Renderer::m_x,Renderer::m_y,Renderer::m_width, Renderer::m_height, Renderer::xScale,Renderer::yScale;
std::vector<LPDIRECT3DBASETEXTURE9> Renderer::m_Textures;
DWORD Renderer::m_RenderStates[MaxRenderStates];
DWORD Renderer::m_RenderStates[MaxRenderStates+46];
DWORD Renderer::m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
DWORD Renderer::m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
DWORD Renderer::m_FVF;
@ -430,15 +431,3 @@ void Renderer::SetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD V
D3D::dev->SetSamplerState( Sampler, Type, Value );
}
}
void Renderer::DrawPrimitiveUP( D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride )
{
D3D::dev->DrawPrimitiveUP( PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride );
}
void Renderer::DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount )
{
D3D::dev->DrawPrimitive( PrimitiveType, StartVertex, PrimitiveCount );
}

View file

@ -18,29 +18,33 @@
#ifndef __H_RENDER__
#define __H_RENDER__
#include "PluginSpecs_Video.h"
#include <vector>
#include <string>
#include "D3DBase.h"
#include "pluginspecs_video.h"
#include "D3DBase.h"
class Renderer
{
// screen offset
static float m_x,m_y,m_width, m_height,xScale,yScale;
static float m_x;
static float m_y;
static float m_width;
static float m_height;
static float xScale;
static float yScale;
const static int MaxTextureStages = 9;
const static int MaxRenderStates = 210;
const static DWORD MaxTextureTypes = 33;
const static DWORD MaxSamplerSize = 13;
const static DWORD MaxSamplerTypes = 15;
static std::vector<LPDIRECT3DBASETEXTURE9> m_Textures;
static DWORD m_RenderStates[MaxRenderStates];
static DWORD m_RenderStates[MaxRenderStates+46];
static DWORD m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
static DWORD m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
static DWORD m_FVF;
public:
static void Init(SVideoInitialize &_VideoInitialize);
static void Shutdown();
@ -58,64 +62,17 @@ public:
static void SetViewport(float* _Viewport);
static void SetProjection(float* _pProjection, int constantIndex = -1);
// The little status display.
static void AddMessage(const std::string &message, unsigned int ms);
static void ProcessMessages();
static void RenderText(const std::string &text, int left, int top, unsigned int color);
/**
* Assigns a texture to a device stage.
* @param Stage Stage to assign to.
* @param pTexture Texture to be assigned.
*/
// The following are "filtered" versions of the corresponding D3Ddev-> functions.
static void SetTexture( DWORD Stage, IDirect3DBaseTexture9 *pTexture );
/**
* Sets the current vertex stream declaration.
* @param FVF Fixed function vertex type
*/
static void SetFVF( DWORD FVF );
/**
* Sets a single device render-state parameter.
* @param State Device state variable that is being modified.
* @param Value New value for the device render state to be set.
*/
static void SetRenderState( D3DRENDERSTATETYPE State, DWORD Value );
/**
* Sets the state value for the currently assigned texture.
* @param Stage Stage identifier of the texture for which the state value is set.
* @param Type Texture state to set.
* @param Value State value to set.
*/
static void SetTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type,DWORD Value );
/**
* Sets the sampler state value.
* @param Sampler The sampler stage index.
* @param Type Type of the sampler.
* @param Value State value to set.
*/
static void SetSamplerState( DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value );
/**
* Renders data specified by a user memory pointer as a sequence of geometric primitives of the specified type.
* @param PrimitiveType Type of primitive to render.
* @param PrimitiveCount Number of primitives to render.
* @param pVertexStreamZeroData User memory pointer to the vertex data.
* @param VertexStreamZeroStride The number of bytes of data for each vertex.
*/
static void DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount,
const void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
/**
* Renders a sequence of non indexed, geometric primitives of the specified type from the current set of data input streams.
* @param PrimitiveType Type of primitive to render.
* @param StartVertex Index of the first vertex to load.
* @param PrimitiveCount Number of primitives to render.
*/
static void DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
};
#endif // __H_RENDER__

View file

@ -361,39 +361,3 @@ void VertexLoader::RunVertices(int count)
((void (*)())((void*)&m_compiledCode[0]))();
}*/
}
DecodedVArray tempvarray;
namespace VertexLoaderManager
{
void Init()
{
tempvarray.Create(65536*3, 1, 8, 3, 2, 8);
}
void Shutdown()
{
tempvarray.Destroy();
}
int GetVertexSize(int vat)
{
VertexLoader& vtxLoader = g_VertexLoaders[vat];
vtxLoader.Setup();
return vtxLoader.GetVertexSize();
}
void RunVertices(int vat, int primitive, int num_vertices)
{
tempvarray.Reset();
VertexLoader::SetVArray(&tempvarray);
VertexLoader& vtxLoader = g_VertexLoaders[vat];
vtxLoader.Setup();
vtxLoader.PrepareRun();
int vsize = vtxLoader.GetVertexSize();
vtxLoader.RunVertices(num_vertices);
VertexManager::AddVertices(primitive, num_vertices, &tempvarray);
}
}

View file

@ -0,0 +1,56 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "VideoCommon.h"
#include "VertexLoader.h"
#include "VertexManager.h"
DecodedVArray tempvarray;
namespace VertexLoaderManager
{
void Init()
{
tempvarray.Create(65536*3, 1, 8, 3, 2, 8);
}
void Shutdown()
{
tempvarray.Destroy();
}
int GetVertexSize(int vat)
{
VertexLoader& vtxLoader = g_VertexLoaders[vat];
vtxLoader.Setup();
return vtxLoader.GetVertexSize();
}
void RunVertices(int vat, int primitive, int num_vertices)
{
tempvarray.Reset();
VertexLoader::SetVArray(&tempvarray);
VertexLoader& vtxLoader = g_VertexLoaders[vat];
vtxLoader.Setup();
vtxLoader.PrepareRun();
int vsize = vtxLoader.GetVertexSize();
vtxLoader.RunVertices(num_vertices);
VertexManager::AddVertices(primitive, num_vertices, &tempvarray);
}
}

View file

@ -230,12 +230,7 @@ void Flush()
else
{
D3D::dev->SetIndices(0);
// D3D::dev->DrawPrimitiveUP(D3DPT_POINTLIST,
// numVertices,
// fakeVBuffer,
// sizeof(D3DVertex));
Renderer::DrawPrimitiveUP( D3DPT_POINTLIST, numVertices, fakeVBuffer, sizeof(D3DVertex) );
D3D::dev->DrawPrimitiveUP(D3DPT_POINTLIST, numVertices, fakeVBuffer, sizeof(D3DVertex));
}
}
collection = C_NOTHING;

View file

@ -15,8 +15,8 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#pragma once
#ifndef _VERTEXMANAGER_H
#define _VERTEXMANAGER_H
#include "CPMemory.h"
#include "VertexLoader.h"
@ -46,3 +46,5 @@ void AddVertices(int _primitive, int _numVertices, const DecodedVArray *varray);
void Flush();
} // namespace
#endif

View file

@ -764,38 +764,6 @@
RelativePath=".\Src\PixelShaderCache.h"
>
</File>
<File
RelativePath=".\Src\rasterfont.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Src\rasterfont.h"
>
</File>
<File
RelativePath=".\Src\TextureMngr.cpp"
>
@ -912,6 +880,38 @@
RelativePath=".\Src\Logging\Logging.h"
>
</File>
<File
RelativePath=".\Src\rasterfont.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="DebugFast|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\Src\rasterfont.h"
>
</File>
</Filter>
<File
RelativePath=".\Src\Config.cpp"

View file

@ -24,9 +24,12 @@
#include "CPMemory.h"
#include "NativeVertexFormat.h"
#include "NativeVertexWriter.h"
#define COMPILED_CODE_SIZE 4096
u32 s_prevcomponents; // previous state set
#ifdef _WIN32
#define USE_JIT
#endif
@ -56,8 +59,10 @@ class GLVertexFormat : public NativeVertexFormat
public:
GLVertexFormat();
~GLVertexFormat();
virtual void Initialize(const PortableVertexDeclaration &_vtx_decl);
virtual void SetupVertexPointers() const;
virtual void EnableComponents(u32 components);
};
@ -204,3 +209,77 @@ void GLVertexFormat::SetupVertexPointers() const {
}
#endif
}
void GLVertexFormat::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
if (!g_Config.bDisableTexturing) {
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);
}
}
}
else // Disable Texturing
{
for (int i = 0; i < 8; ++i) {
glClientActiveTexture(GL_TEXTURE0 + i);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
// Disable Lighting
// TODO - move to better spot
if (g_Config.bDisableLighting) {
for (int i = 0; i < xfregs.nNumChans; i++)
{
xfregs.colChans[i].alpha.enablelighting = false;
xfregs.colChans[i].color.enablelighting = false;
}
}
s_prevcomponents = components;
}
}

View file

@ -31,7 +31,6 @@ static GLuint s_vboBuffers[0x40] = {0};
static int s_nCurVBOIndex = 0; // current free buffer
static u8 *s_pBaseBufferPointer = NULL;
static std::vector< std::pair<u32, u32> > s_vStoredPrimitives; // every element, mode and count to be passed to glDrawArrays
static u32 s_prevcomponents; // previous state set
static const GLenum c_primitiveType[8] =
{
@ -47,7 +46,6 @@ static const GLenum c_primitiveType[8] =
bool Init()
{
s_prevcomponents = 0;
s_pBaseBufferPointer = (u8*)AllocateMemoryPages(MAX_BUFFER_SIZE);
s_pCurBufferPointer = s_pBaseBufferPointer;
@ -91,7 +89,8 @@ int GetRemainingSize()
void AddVertices(int primitive, int numvertices)
{
_assert_( numvertices > 0 );
_assert_(numvertices > 0);
_assert_(g_nativeVertexFmt != NULL);
ADDSTAT(stats.thisFrame.numPrims, numvertices);
if (s_vStoredPrimitives.size() && s_vStoredPrimitives[s_vStoredPrimitives.size() - 1].first == c_primitiveType[primitive]) {
@ -137,8 +136,8 @@ void Flush()
for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP ) tinfo.hex &= 0x7ff;
if (tinfo.texgentype != XF_TEXGEN_REGULAR ) tinfo.projection = 0;
if (tinfo.texgentype != XF_TEXGEN_EMBOSS_MAP) tinfo.hex &= 0x7ff;
if (tinfo.texgentype != XF_TEXGEN_REGULAR) tinfo.projection = 0;
PRIM_LOG("txgen%d: proj=%d, input=%d, gentype=%d, srcrow=%d, embsrc=%d, emblght=%d, postmtx=%d, postnorm=%d\n",
i, tinfo.projection, tinfo.inputform, tinfo.texgentype, tinfo.sourcerow, tinfo.embosssourceshift, tinfo.embosslightshift,
@ -199,6 +198,7 @@ void Flush()
TextureMngr::EnableTexRECT(i);
}
// if texture is power of two, set to ones (since don't need scaling)
// (the above seems to have changed - we set the width and height here too.
else
{
PixelShaderManager::SetTexDims(i, tentry->w, tentry->h, 0, 0);
@ -225,13 +225,13 @@ void Flush()
}
FRAGMENTSHADER* ps = PixelShaderCache::GetShader();
VERTEXSHADER* vs = VertexShaderCache::GetShader(s_prevcomponents);
VERTEXSHADER* vs = VertexShaderCache::GetShader(g_nativeVertexFmt->m_components);
bool bRestoreBuffers = false;
if (Renderer::GetZBufferTarget()) {
if (bpmem.zmode.updateenable) {
if (!bpmem.blendmode.colorupdate) {
Renderer::SetRenderMode(bpmem.blendmode.alphaupdate?Renderer::RM_ZBufferAlpha:Renderer::RM_ZBufferOnly);
Renderer::SetRenderMode(bpmem.blendmode.alphaupdate ? Renderer::RM_ZBufferAlpha : Renderer::RM_ZBufferOnly);
}
}
else {
@ -298,81 +298,4 @@ void Flush()
ResetBuffer();
}
// This should move into NativeVertexFormat
void EnableComponents(u32 components)
{
if (s_prevcomponents != components) {
if (s_vStoredPrimitives.size() != 0)
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
if (!g_Config.bDisableTexturing) {
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);
}
}
}
else // Disable Texturing
{
for (int i = 0; i < 8; ++i) {
glClientActiveTexture(GL_TEXTURE0 + i);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
// Disable Lighting
// TODO - move to better spot
if (g_Config.bDisableLighting) {
for (int i = 0; i < xfregs.nNumChans; i++)
{
xfregs.colChans[i].alpha.enablelighting = false;
xfregs.colChans[i].color.enablelighting = false;
}
}
s_prevcomponents = components;
}
}
} // namespace