Sps fixed in all the games tested, code cleanup and reordering
implemented buffer format fall back to allow hardware that don't support lockable formats to run the games with Z peeking disabled, applied as well the patch suggested in issue 1494 please give heavy test to this commit git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4365 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
58df543e6a
commit
19b8e6bc08
|
@ -26,130 +26,25 @@ QUAD simulator
|
||||||
021231 243453
|
021231 243453
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void IndexGenerator::Start(unsigned short *startptr)
|
//Init
|
||||||
{
|
u16 *IndexGenerator::Tptr = 0;
|
||||||
ptr = startptr;
|
u16 *IndexGenerator::Lptr = 0;
|
||||||
index = 0;
|
u16 *IndexGenerator::Pptr = 0;
|
||||||
numPrims = 0;
|
int IndexGenerator::numT = 0;
|
||||||
adds = 0;
|
int IndexGenerator::numL = 0;
|
||||||
indexLen = 0;
|
int IndexGenerator::numP = 0;
|
||||||
onlyLists = true;
|
int IndexGenerator::index = 0;
|
||||||
}
|
int IndexGenerator::Tadds = 0;
|
||||||
|
int IndexGenerator::Ladds = 0;
|
||||||
|
int IndexGenerator::Padds = 0;
|
||||||
|
int IndexGenerator::TindexLen = 0;
|
||||||
|
int IndexGenerator::LindexLen = 0;
|
||||||
|
int IndexGenerator::PindexLen = 0;
|
||||||
|
IndexGenerator::IndexPrimitiveType IndexGenerator::LastTPrimitive = Prim_None;
|
||||||
|
IndexGenerator::IndexPrimitiveType IndexGenerator::LastLPrimitive = Prim_None;
|
||||||
|
bool IndexGenerator::used = false;
|
||||||
|
|
||||||
void IndexGenerator::AddList(int numVerts)
|
void IndexGenerator::Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr)
|
||||||
{
|
|
||||||
int numTris = numVerts / 3;
|
|
||||||
if (numTris <= 0) return;
|
|
||||||
for (int i = 0; i < numTris; i++)
|
|
||||||
{
|
|
||||||
*ptr++ = index+i*3;
|
|
||||||
*ptr++ = index+i*3+1;
|
|
||||||
*ptr++ = index+i*3+2;
|
|
||||||
}
|
|
||||||
indexLen += numVerts;
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numTris;
|
|
||||||
adds++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IndexGenerator::AddStrip(int numVerts)
|
|
||||||
{
|
|
||||||
int numTris = numVerts - 2;
|
|
||||||
if (numTris <= 0) return;
|
|
||||||
bool wind = false;
|
|
||||||
for (int i = 0; i < numTris; i++)
|
|
||||||
{
|
|
||||||
*ptr++ = index+i;
|
|
||||||
*ptr++ = index+i+(wind?2:1);
|
|
||||||
*ptr++ = index+i+(wind?1:2);
|
|
||||||
wind = !wind;
|
|
||||||
}
|
|
||||||
indexLen += numTris * 3;
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numTris;
|
|
||||||
adds++;
|
|
||||||
onlyLists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IndexGenerator::AddLineList(int numVerts)
|
|
||||||
{
|
|
||||||
int numLines= numVerts / 2;
|
|
||||||
if (numLines <= 0) return;
|
|
||||||
for (int i = 0; i < numLines; i++)
|
|
||||||
{
|
|
||||||
*ptr++ = index+i*2;
|
|
||||||
*ptr++ = index+i*2+1;
|
|
||||||
}
|
|
||||||
indexLen += numVerts;
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numLines;
|
|
||||||
adds++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IndexGenerator::AddLineStrip(int numVerts)
|
|
||||||
{
|
|
||||||
int numLines = numVerts - 1;
|
|
||||||
if (numLines <= 0) return;
|
|
||||||
for (int i = 0; i < numLines; i++)
|
|
||||||
{
|
|
||||||
*ptr++ = index+i;
|
|
||||||
*ptr++ = index+i+1;
|
|
||||||
}
|
|
||||||
indexLen += numLines * 2;
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numLines;
|
|
||||||
adds++;
|
|
||||||
onlyLists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IndexGenerator::AddFan(int numVerts)
|
|
||||||
{
|
|
||||||
int numTris = numVerts - 2;
|
|
||||||
if (numTris <= 0) return;
|
|
||||||
for (int i = 0; i < numTris; i++)
|
|
||||||
{
|
|
||||||
*ptr++ = index;
|
|
||||||
*ptr++ = index+i+1;
|
|
||||||
*ptr++ = index+i+2;
|
|
||||||
}
|
|
||||||
indexLen += numTris * 3;
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numTris;
|
|
||||||
adds++;
|
|
||||||
onlyLists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IndexGenerator::AddQuads(int numVerts)
|
|
||||||
{
|
|
||||||
int numTris = (numVerts/4)*2;
|
|
||||||
if (numTris <= 0) return;
|
|
||||||
for (int i = 0; i < numTris / 2; i++)
|
|
||||||
{
|
|
||||||
*ptr++ = index+i*4;
|
|
||||||
*ptr++ = index+i*4+1;
|
|
||||||
*ptr++ = index+i*4+3;
|
|
||||||
*ptr++ = index+i*4+1;
|
|
||||||
*ptr++ = index+i*4+2;
|
|
||||||
*ptr++ = index+i*4+3;
|
|
||||||
}
|
|
||||||
indexLen += numTris * 3;
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numTris;
|
|
||||||
adds++;
|
|
||||||
onlyLists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IndexGenerator::AddPoints(int numVerts)
|
|
||||||
{
|
|
||||||
index += numVerts;
|
|
||||||
numPrims += numVerts;
|
|
||||||
adds++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Init
|
|
||||||
void IndexGenerator2::Start(unsigned short *Triangleptr,unsigned short *Lineptr,unsigned short *Pointptr)
|
|
||||||
{
|
{
|
||||||
Tptr = Triangleptr;
|
Tptr = Triangleptr;
|
||||||
Lptr = Lineptr;
|
Lptr = Lineptr;
|
||||||
|
@ -168,7 +63,7 @@ void IndexGenerator2::Start(unsigned short *Triangleptr,unsigned short *Lineptr,
|
||||||
LastLPrimitive = Prim_None;
|
LastLPrimitive = Prim_None;
|
||||||
}
|
}
|
||||||
// Triangles
|
// Triangles
|
||||||
void IndexGenerator2::AddList(int numVerts)
|
void IndexGenerator::AddList(int numVerts)
|
||||||
{
|
{
|
||||||
int numTris = numVerts / 3;
|
int numTris = numVerts / 3;
|
||||||
if (numTris <= 0) return;
|
if (numTris <= 0) return;
|
||||||
|
@ -185,7 +80,7 @@ void IndexGenerator2::AddList(int numVerts)
|
||||||
LastTPrimitive = Prim_List;
|
LastTPrimitive = Prim_List;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator2::AddStrip(int numVerts)
|
void IndexGenerator::AddStrip(int numVerts)
|
||||||
{
|
{
|
||||||
int numTris = numVerts - 2;
|
int numTris = numVerts - 2;
|
||||||
if (numTris <= 0) return;
|
if (numTris <= 0) return;
|
||||||
|
@ -203,7 +98,7 @@ void IndexGenerator2::AddStrip(int numVerts)
|
||||||
Tadds++;
|
Tadds++;
|
||||||
LastTPrimitive = Prim_Strip;
|
LastTPrimitive = Prim_Strip;
|
||||||
}
|
}
|
||||||
void IndexGenerator2::AddFan(int numVerts)
|
void IndexGenerator::AddFan(int numVerts)
|
||||||
{
|
{
|
||||||
int numTris = numVerts - 2;
|
int numTris = numVerts - 2;
|
||||||
if (numTris <= 0) return;
|
if (numTris <= 0) return;
|
||||||
|
@ -220,7 +115,7 @@ void IndexGenerator2::AddFan(int numVerts)
|
||||||
LastTPrimitive = Prim_Fan;
|
LastTPrimitive = Prim_Fan;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator2::AddQuads(int numVerts)
|
void IndexGenerator::AddQuads(int numVerts)
|
||||||
{
|
{
|
||||||
int numTris = (numVerts/4)*2;
|
int numTris = (numVerts/4)*2;
|
||||||
if (numTris <= 0) return;
|
if (numTris <= 0) return;
|
||||||
|
@ -242,7 +137,7 @@ void IndexGenerator2::AddQuads(int numVerts)
|
||||||
|
|
||||||
|
|
||||||
//Lines
|
//Lines
|
||||||
void IndexGenerator2::AddLineList(int numVerts)
|
void IndexGenerator::AddLineList(int numVerts)
|
||||||
{
|
{
|
||||||
int numLines= numVerts / 2;
|
int numLines= numVerts / 2;
|
||||||
if (numLines <= 0) return;
|
if (numLines <= 0) return;
|
||||||
|
@ -258,7 +153,7 @@ void IndexGenerator2::AddLineList(int numVerts)
|
||||||
LastLPrimitive = Prim_List;
|
LastLPrimitive = Prim_List;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator2::AddLineStrip(int numVerts)
|
void IndexGenerator::AddLineStrip(int numVerts)
|
||||||
{
|
{
|
||||||
int numLines = numVerts - 1;
|
int numLines = numVerts - 1;
|
||||||
if (numLines <= 0) return;
|
if (numLines <= 0) return;
|
||||||
|
@ -277,7 +172,7 @@ void IndexGenerator2::AddLineStrip(int numVerts)
|
||||||
|
|
||||||
|
|
||||||
//Points
|
//Points
|
||||||
void IndexGenerator2::AddPoints(int numVerts)
|
void IndexGenerator::AddPoints(int numVerts)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numVerts; i++)
|
for (int i = 0; i < numVerts; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,58 +20,32 @@
|
||||||
|
|
||||||
#ifndef _INDEXGENERATOR_H
|
#ifndef _INDEXGENERATOR_H
|
||||||
#define _INDEXGENERATOR_H
|
#define _INDEXGENERATOR_H
|
||||||
|
#include "CommonTypes.h"
|
||||||
|
|
||||||
|
|
||||||
class IndexGenerator
|
class IndexGenerator
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
void Start(unsigned short *startptr);
|
|
||||||
void AddList(int numVerts);
|
|
||||||
void AddStrip(int numVerts);
|
|
||||||
void AddLineList(int numVerts);
|
|
||||||
void AddLineStrip(int numVerts);
|
|
||||||
void AddFan(int numVerts);
|
|
||||||
void AddQuads(int numVerts);
|
|
||||||
void AddPoints(int numVerts);
|
|
||||||
int GetNumPrims() {return numPrims;} //returns numprimitives
|
|
||||||
int GetNumVerts() {return index;} //returns numprimitives
|
|
||||||
int GetNumAdds() {return adds;}
|
|
||||||
int GetindexLen() {return indexLen;}
|
|
||||||
bool GetOnlyLists() {return onlyLists;}
|
|
||||||
private:
|
|
||||||
unsigned short *ptr;
|
|
||||||
int numPrims;
|
|
||||||
int index;
|
|
||||||
int adds;
|
|
||||||
int indexLen;
|
|
||||||
bool onlyLists;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IndexGenerator2
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
//Init
|
//Init
|
||||||
void Start(unsigned short *Triangleptr,unsigned short *Lineptr,unsigned short *Pointptr);
|
static void Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr);
|
||||||
//Triangles
|
//Triangles
|
||||||
void AddList(int numVerts);
|
static void AddList(int numVerts);
|
||||||
void AddStrip(int numVerts);
|
static void AddStrip(int numVerts);
|
||||||
void AddFan(int numVerts);
|
static void AddFan(int numVerts);
|
||||||
void AddQuads(int numVerts);
|
static void AddQuads(int numVerts);
|
||||||
//Lines
|
//Lines
|
||||||
void AddLineList(int numVerts);
|
static void AddLineList(int numVerts);
|
||||||
void AddLineStrip(int numVerts);
|
static void AddLineStrip(int numVerts);
|
||||||
//Points
|
//Points
|
||||||
void AddPoints(int numVerts);
|
static void AddPoints(int numVerts);
|
||||||
//Interface
|
//Interface
|
||||||
int GetNumTriangles() {return numT;}
|
static int GetNumTriangles() {used = true; return numT;}
|
||||||
int GetNumLines() {return numL;}
|
static int GetNumLines() {used = true;return numL;}
|
||||||
int GetNumPoints() {return numP;}
|
static int GetNumPoints() {used = true;return numP;}
|
||||||
int GetNumVerts() {return index;} //returns numprimitives
|
static int GetNumVerts() {return index;} //returns numprimitives
|
||||||
int GetNumAdds() {return Tadds + Ladds + Padds;}
|
static int GetNumAdds() {return Tadds + Ladds + Padds;}
|
||||||
int GetTriangleindexLen() {return TindexLen;}
|
static int GetTriangleindexLen() {return TindexLen;}
|
||||||
int GetLineindexLen() {return LindexLen;}
|
static int GetLineindexLen() {return LindexLen;}
|
||||||
int GetPointindexLen() {return PindexLen;}
|
static int GetPointindexLen() {return PindexLen;}
|
||||||
|
|
||||||
enum IndexPrimitiveType
|
enum IndexPrimitiveType
|
||||||
{
|
{
|
||||||
|
@ -81,21 +55,22 @@ public:
|
||||||
Prim_Fan
|
Prim_Fan
|
||||||
} ;
|
} ;
|
||||||
private:
|
private:
|
||||||
unsigned short *Tptr;
|
static u16 *Tptr;
|
||||||
unsigned short *Lptr;
|
static u16 *Lptr;
|
||||||
unsigned short *Pptr;
|
static u16 *Pptr;
|
||||||
int numT;
|
static int numT;
|
||||||
int numL;
|
static int numL;
|
||||||
int numP;
|
static int numP;
|
||||||
int index;
|
static int index;
|
||||||
int Tadds;
|
static int Tadds;
|
||||||
int Ladds;
|
static int Ladds;
|
||||||
int Padds;
|
static int Padds;
|
||||||
int TindexLen;
|
static int TindexLen;
|
||||||
int LindexLen;
|
static int LindexLen;
|
||||||
int PindexLen;
|
static int PindexLen;
|
||||||
IndexPrimitiveType LastTPrimitive;
|
static IndexPrimitiveType LastTPrimitive;
|
||||||
IndexPrimitiveType LastLPrimitive;
|
static IndexPrimitiveType LastLPrimitive;
|
||||||
|
static bool used;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,15 @@ namespace FBManager
|
||||||
static LPDIRECT3DTEXTURE9 s_efb_color_texture;
|
static LPDIRECT3DTEXTURE9 s_efb_color_texture;
|
||||||
static LPDIRECT3DSURFACE9 s_efb_color_surface;
|
static LPDIRECT3DSURFACE9 s_efb_color_surface;
|
||||||
static LPDIRECT3DSURFACE9 s_efb_depth_surface;
|
static LPDIRECT3DSURFACE9 s_efb_depth_surface;
|
||||||
|
static D3DFORMAT s_efb_color_surface_Format;
|
||||||
|
static D3DFORMAT s_efb_depth_surface_Format;
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
#define CHECK(hr) if (FAILED(hr)) { PanicAlert("FAIL: " __FUNCTION__); }
|
#define CHECK(hr) if (FAILED(hr)) { PanicAlert("FAIL: " __FUNCTION__); }
|
||||||
|
|
||||||
LPDIRECT3DSURFACE9 GetEFBColorRTSurface() { return s_efb_color_surface; }
|
LPDIRECT3DSURFACE9 GetEFBColorRTSurface() { return s_efb_color_surface; }
|
||||||
LPDIRECT3DSURFACE9 GetEFBDepthRTSurface() { return s_efb_depth_surface; }
|
LPDIRECT3DSURFACE9 GetEFBDepthRTSurface() { return s_efb_depth_surface; }
|
||||||
|
D3DFORMAT GetEFBDepthRTSurfaceFormat(){return s_efb_depth_surface_Format;}
|
||||||
|
D3DFORMAT GetEFBColorRTSurfaceFormat(){return s_efb_color_surface_Format;}
|
||||||
|
|
||||||
LPDIRECT3DTEXTURE9 GetEFBColorTexture(const EFBRectangle& sourceRc)
|
LPDIRECT3DTEXTURE9 GetEFBColorTexture(const EFBRectangle& sourceRc)
|
||||||
{
|
{
|
||||||
|
@ -44,12 +47,15 @@ LPDIRECT3DTEXTURE9 GetEFBDepthTexture(const EFBRectangle &sourceRc)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Create()
|
void Create()
|
||||||
{
|
{
|
||||||
// Simplest possible setup to start with.
|
// Simplest possible setup to start with.
|
||||||
int target_width = Renderer::GetTargetWidth();
|
int target_width = Renderer::GetTargetWidth();
|
||||||
int target_height = Renderer::GetTargetHeight();
|
int target_height = Renderer::GetTargetHeight();
|
||||||
|
s_efb_color_surface_Format = D3DFMT_A8R8G8B8;
|
||||||
HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
|
HRESULT hr = D3D::dev->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
|
||||||
D3DPOOL_DEFAULT, &s_efb_color_texture, NULL);
|
D3DPOOL_DEFAULT, &s_efb_color_texture, NULL);
|
||||||
CHECK(hr);
|
CHECK(hr);
|
||||||
|
@ -57,22 +63,37 @@ void Create()
|
||||||
hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface);
|
hr = s_efb_color_texture->GetSurfaceLevel(0, &s_efb_color_surface);
|
||||||
CHECK(hr);
|
CHECK(hr);
|
||||||
|
|
||||||
//D3DFMT_D32F_LOCKABLE and D3DFMT_D16_LOCKABLE must be used to peek_z to work, 16 bits is a crapy z buffer and to allow
|
//Select Zbuffer format supported by hadware.
|
||||||
// to read directi as a float we need it to be float so using ...
|
s_efb_depth_surface_Format = D3DFMT_D32F_LOCKABLE;
|
||||||
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, D3DFMT_D32F_LOCKABLE,
|
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, D3DFMT_D32F_LOCKABLE,
|
||||||
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_depth_surface, NULL);
|
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_depth_surface, NULL);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
s_efb_depth_surface_Format = D3DFMT_D16_LOCKABLE;
|
||||||
|
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, D3DFMT_D16_LOCKABLE,
|
||||||
|
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_depth_surface, NULL);
|
||||||
|
if(FAILED(hr))
|
||||||
|
{
|
||||||
|
s_efb_depth_surface_Format = D3DFMT_D24S8;
|
||||||
|
hr = D3D::dev->CreateDepthStencilSurface(target_width, target_height, D3DFMT_D24S8,
|
||||||
|
D3DMULTISAMPLE_NONE, 0, FALSE, &s_efb_depth_surface, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
CHECK(hr);
|
CHECK(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
s_efb_depth_surface->Release();
|
if(s_efb_depth_surface)
|
||||||
|
s_efb_depth_surface->Release();
|
||||||
s_efb_depth_surface = NULL;
|
s_efb_depth_surface = NULL;
|
||||||
|
|
||||||
s_efb_color_surface->Release();
|
if(s_efb_color_surface)
|
||||||
|
s_efb_color_surface->Release();
|
||||||
s_efb_color_surface = NULL;
|
s_efb_color_surface = NULL;
|
||||||
|
|
||||||
s_efb_color_texture->Release();
|
if(s_efb_color_texture)
|
||||||
|
s_efb_color_texture->Release();
|
||||||
s_efb_color_texture = NULL;
|
s_efb_color_texture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ LPDIRECT3DTEXTURE9 GetEFBDepthTexture(const EFBRectangle& sourceRc);
|
||||||
|
|
||||||
LPDIRECT3DSURFACE9 GetEFBColorRTSurface();
|
LPDIRECT3DSURFACE9 GetEFBColorRTSurface();
|
||||||
LPDIRECT3DSURFACE9 GetEFBDepthRTSurface();
|
LPDIRECT3DSURFACE9 GetEFBDepthRTSurface();
|
||||||
|
D3DFORMAT GetEFBDepthRTSurfaceFormat();
|
||||||
|
D3DFORMAT GetEFBColorRTSurfaceFormat();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -440,7 +440,26 @@ void Renderer::SetColorMask()
|
||||||
|
|
||||||
u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
|
u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//Get the working buffer and it's format
|
||||||
|
LPDIRECT3DSURFACE9 pBuffer = (type == PEEK_Z || type == POKE_Z) ?
|
||||||
|
FBManager::GetEFBDepthRTSurface() : FBManager::GetEFBColorRTSurface();
|
||||||
|
D3DLOCKED_RECT drect;
|
||||||
|
|
||||||
|
D3DFORMAT BufferFormat = (type == PEEK_Z || type == POKE_Z) ?
|
||||||
|
FBManager::GetEFBDepthRTSurfaceFormat() : FBManager::GetEFBColorRTSurfaceFormat();
|
||||||
|
//Buffer not found alert
|
||||||
|
if(!pBuffer) {
|
||||||
|
PanicAlert("No %s!", (type == PEEK_Z || type == POKE_Z) ? "Z-Buffer" : "Color EFB");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Z buffer lock not suported: returning
|
||||||
|
if((type == PEEK_Z || type == POKE_Z) && BufferFormat == D3DFMT_D24S8)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
// Get the rectangular target region covered by the EFB pixel.
|
// Get the rectangular target region covered by the EFB pixel.
|
||||||
|
|
||||||
EFBRectangle efbPixelRc;
|
EFBRectangle efbPixelRc;
|
||||||
efbPixelRc.left = x;
|
efbPixelRc.left = x;
|
||||||
efbPixelRc.top = y;
|
efbPixelRc.top = y;
|
||||||
|
@ -456,33 +475,36 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
|
||||||
|
|
||||||
u32 z = 0;
|
u32 z = 0;
|
||||||
float val = 0.0f;
|
float val = 0.0f;
|
||||||
|
|
||||||
LPDIRECT3DSURFACE9 pBuffer = (type == PEEK_Z || type == POKE_Z) ?
|
|
||||||
FBManager::GetEFBDepthRTSurface() : FBManager::GetEFBColorRTSurface();
|
|
||||||
D3DLOCKED_RECT drect;
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
if(!pBuffer) {
|
|
||||||
PanicAlert("No %s!", (type == PEEK_Z || type == POKE_Z) ? "Z-Buffer" : "Color EFB");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
RECT RectToLock;
|
RECT RectToLock;
|
||||||
RectToLock.bottom = targetPixelRc.bottom;
|
RectToLock.bottom = targetPixelRc.bottom;
|
||||||
RectToLock.left = targetPixelRc.left;
|
RectToLock.left = targetPixelRc.left;
|
||||||
RectToLock.right = targetPixelRc.right;
|
RectToLock.right = targetPixelRc.right;
|
||||||
RectToLock.top = targetPixelRc.top;
|
RectToLock.top = targetPixelRc.top;
|
||||||
|
|
||||||
|
//lock the buffer
|
||||||
if((hr = pBuffer->LockRect(&drect, &RectToLock, D3DLOCK_READONLY)) != D3D_OK)
|
if((hr = pBuffer->LockRect(&drect, &RectToLock, D3DLOCK_READONLY)) != D3D_OK)
|
||||||
PanicAlert("ERROR: %s", hr == D3DERR_WASSTILLDRAWING ? "Still drawing" :
|
PanicAlert("ERROR: %s", hr == D3DERR_WASSTILLDRAWING ? "Still drawing" :
|
||||||
hr == D3DERR_INVALIDCALL ? "Invalid call" : "w00t");
|
hr == D3DERR_INVALIDCALL ? "Invalid call" : "w00t");
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case PEEK_Z:
|
case PEEK_Z:
|
||||||
val = ((float *)drect.pBits)[0];
|
{
|
||||||
|
switch (BufferFormat)
|
||||||
|
{
|
||||||
|
case D3DFMT_D32F_LOCKABLE:
|
||||||
|
val = ((float *)drect.pBits)[0];
|
||||||
|
break;
|
||||||
|
case D3DFMT_D16_LOCKABLE:
|
||||||
|
val = ((float)((u16 *)drect.pBits)[0])/((float)0xFFFF);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
val=0;
|
||||||
|
};
|
||||||
// [0.0, 1.0] ==> [0, 0xFFFFFFFF]
|
// [0.0, 1.0] ==> [0, 0xFFFFFFFF]
|
||||||
z = ((u32)(val * 0xffffff));// 0xFFFFFFFF;
|
z = ((u32)(val * 0xffffff));// 0xFFFFFFFF;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case POKE_Z:
|
case POKE_Z:
|
||||||
// TODO: Get that Z value to poke from somewhere
|
// TODO: Get that Z value to poke from somewhere
|
||||||
//((float *)drect.pBits)[0] = val;
|
//((float *)drect.pBits)[0] = val;
|
||||||
|
|
|
@ -48,8 +48,6 @@ extern NativeVertexFormat *g_nativeVertexFmt;
|
||||||
namespace VertexManager
|
namespace VertexManager
|
||||||
{
|
{
|
||||||
|
|
||||||
static IndexGenerator2 indexGen;
|
|
||||||
|
|
||||||
static int lastPrimitive;
|
static int lastPrimitive;
|
||||||
|
|
||||||
static u8 *LocalVBuffer;
|
static u8 *LocalVBuffer;
|
||||||
|
@ -58,6 +56,7 @@ static u16 *LIBuffer;
|
||||||
static u16 *PIBuffer;
|
static u16 *PIBuffer;
|
||||||
#define MAXVBUFFERSIZE 0x50000
|
#define MAXVBUFFERSIZE 0x50000
|
||||||
#define MAXIBUFFERSIZE 0xFFFF
|
#define MAXIBUFFERSIZE 0xFFFF
|
||||||
|
static bool Flushed=false;
|
||||||
|
|
||||||
void CreateDeviceObjects();
|
void CreateDeviceObjects();
|
||||||
void DestroyDeviceObjects();
|
void DestroyDeviceObjects();
|
||||||
|
@ -69,14 +68,14 @@ bool Init()
|
||||||
LIBuffer = new u16[MAXIBUFFERSIZE];
|
LIBuffer = new u16[MAXIBUFFERSIZE];
|
||||||
PIBuffer = new u16[MAXIBUFFERSIZE];
|
PIBuffer = new u16[MAXIBUFFERSIZE];
|
||||||
s_pCurBufferPointer = LocalVBuffer;
|
s_pCurBufferPointer = LocalVBuffer;
|
||||||
indexGen.Start(TIBuffer,LIBuffer,PIBuffer);
|
Flushed=false;
|
||||||
|
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetBuffer()
|
void ResetBuffer()
|
||||||
{
|
{
|
||||||
s_pCurBufferPointer = LocalVBuffer;
|
s_pCurBufferPointer = LocalVBuffer;
|
||||||
indexGen.Start(TIBuffer,LIBuffer,PIBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
|
@ -102,13 +101,13 @@ void AddIndices(int _primitive, int _numVertices)
|
||||||
{
|
{
|
||||||
switch (_primitive)
|
switch (_primitive)
|
||||||
{
|
{
|
||||||
case GX_DRAW_QUADS: indexGen.AddQuads(_numVertices); return;
|
case GX_DRAW_QUADS: IndexGenerator::AddQuads(_numVertices); return;
|
||||||
case GX_DRAW_TRIANGLES: indexGen.AddList(_numVertices); return;
|
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(_numVertices); return;
|
||||||
case GX_DRAW_TRIANGLE_STRIP: indexGen.AddStrip(_numVertices); return;
|
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(_numVertices); return;
|
||||||
case GX_DRAW_TRIANGLE_FAN: indexGen.AddFan(_numVertices); return;
|
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(_numVertices); return;
|
||||||
case GX_DRAW_LINE_STRIP: indexGen.AddLineStrip(_numVertices); return;
|
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(_numVertices); return;
|
||||||
case GX_DRAW_LINES: indexGen.AddLineList(_numVertices); return;
|
case GX_DRAW_LINES: IndexGenerator::AddLineList(_numVertices); return;
|
||||||
case GX_DRAW_POINTS: indexGen.AddPoints(_numVertices); return;
|
case GX_DRAW_POINTS: IndexGenerator::AddPoints(_numVertices); return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,33 +128,38 @@ void AddVertices(int _primitive, int _numVertices)
|
||||||
case GX_DRAW_TRIANGLES:
|
case GX_DRAW_TRIANGLES:
|
||||||
case GX_DRAW_TRIANGLE_STRIP:
|
case GX_DRAW_TRIANGLE_STRIP:
|
||||||
case GX_DRAW_TRIANGLE_FAN:
|
case GX_DRAW_TRIANGLE_FAN:
|
||||||
if(MAXIBUFFERSIZE - indexGen.GetTriangleindexLen() < 2 * _numVertices)
|
if(MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen() < 2 * _numVertices)
|
||||||
Flush();
|
Flush();
|
||||||
break;
|
break;
|
||||||
case GX_DRAW_LINE_STRIP:
|
case GX_DRAW_LINE_STRIP:
|
||||||
case GX_DRAW_LINES:
|
case GX_DRAW_LINES:
|
||||||
if(MAXIBUFFERSIZE - indexGen.GetLineindexLen() < 2 * _numVertices)
|
if(MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen() < 2 * _numVertices)
|
||||||
Flush();
|
Flush();
|
||||||
break;
|
break;
|
||||||
case GX_DRAW_POINTS:
|
case GX_DRAW_POINTS:
|
||||||
if(MAXIBUFFERSIZE - indexGen.GetPointindexLen() < _numVertices)
|
if(MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen() < _numVertices)
|
||||||
Flush();
|
Flush();
|
||||||
break;
|
break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
|
if(Flushed)
|
||||||
|
{
|
||||||
|
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
|
||||||
|
Flushed=false;
|
||||||
|
}
|
||||||
lastPrimitive = _primitive;
|
lastPrimitive = _primitive;
|
||||||
ADDSTAT(stats.thisFrame.numPrims, _numVertices);
|
ADDSTAT(stats.thisFrame.numPrims, _numVertices);
|
||||||
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
||||||
AddIndices(_primitive, _numVertices);
|
AddIndices(_primitive, _numVertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Draw(int numVertices, int stride)
|
inline void Draw(int stride)
|
||||||
{
|
{
|
||||||
if(indexGen.GetNumTriangles() > 0)
|
if(IndexGenerator::GetNumTriangles() > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||||
D3DPT_TRIANGLELIST,
|
D3DPT_TRIANGLELIST,
|
||||||
0, indexGen.GetNumVerts(), indexGen.GetNumTriangles(),
|
0, IndexGenerator::GetNumVerts(), IndexGenerator::GetNumTriangles(),
|
||||||
TIBuffer,
|
TIBuffer,
|
||||||
D3DFMT_INDEX16,
|
D3DFMT_INDEX16,
|
||||||
LocalVBuffer,
|
LocalVBuffer,
|
||||||
|
@ -171,11 +175,11 @@ inline void Draw(int numVertices, int stride)
|
||||||
}
|
}
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if(indexGen.GetNumLines() > 0)
|
if(IndexGenerator::GetNumLines() > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||||
D3DPT_LINELIST,
|
D3DPT_LINELIST,
|
||||||
0, indexGen.GetNumVerts(), indexGen.GetNumLines(),
|
0, IndexGenerator::GetNumVerts(), IndexGenerator::GetNumLines(),
|
||||||
LIBuffer,
|
LIBuffer,
|
||||||
D3DFMT_INDEX16,
|
D3DFMT_INDEX16,
|
||||||
LocalVBuffer,
|
LocalVBuffer,
|
||||||
|
@ -191,11 +195,11 @@ inline void Draw(int numVertices, int stride)
|
||||||
}
|
}
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if(indexGen.GetNumPoints() > 0)
|
if(IndexGenerator::GetNumPoints() > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||||
D3DPT_POINTLIST,
|
D3DPT_POINTLIST,
|
||||||
0, indexGen.GetNumVerts(), indexGen.GetNumPoints(),
|
0, IndexGenerator::GetNumVerts(), IndexGenerator::GetNumPoints(),
|
||||||
PIBuffer,
|
PIBuffer,
|
||||||
D3DFMT_INDEX16,
|
D3DFMT_INDEX16,
|
||||||
LocalVBuffer,
|
LocalVBuffer,
|
||||||
|
@ -216,101 +220,98 @@ inline void Draw(int numVertices, int stride)
|
||||||
void Flush()
|
void Flush()
|
||||||
{
|
{
|
||||||
if (LocalVBuffer == s_pCurBufferPointer) return;
|
if (LocalVBuffer == s_pCurBufferPointer) return;
|
||||||
int numVerts = indexGen.GetNumVerts();
|
if(Flushed) return;
|
||||||
if(numVerts == 0) return;
|
Flushed=true;
|
||||||
|
|
||||||
DVSTARTPROFILE();
|
DVSTARTPROFILE();
|
||||||
|
|
||||||
u32 usedtextures = 0;
|
u32 usedtextures = 0;
|
||||||
|
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
|
||||||
|
if (bpmem.tevorders[i/2].getEnable(i & 1))
|
||||||
|
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bpmem.genMode.numindstages > 0) {
|
||||||
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
|
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
|
||||||
if (bpmem.tevorders[i/2].getEnable(i & 1))
|
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) {
|
||||||
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1);
|
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
|
||||||
}
|
|
||||||
|
|
||||||
if (bpmem.genMode.numindstages > 0) {
|
|
||||||
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
|
|
||||||
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages) {
|
|
||||||
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
u32 nonpow2tex = 0;
|
u32 nonpow2tex = 0;
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (usedtextures & (1 << i)) {
|
||||||
|
FourTexUnits &tex = bpmem.tex[i >> 2];
|
||||||
|
TextureCache::TCacheEntry* tentry = TextureCache::Load(i,
|
||||||
|
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
||||||
|
tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
|
||||||
|
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||||
|
tex.texTlut[i&3].tlut_format);
|
||||||
|
|
||||||
|
if (tentry) {
|
||||||
|
PixelShaderManager::SetTexDims(i, tentry->w, tentry->h, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to load texture\n");});
|
||||||
|
ERROR_LOG(VIDEO, "error loading texture");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PixelShaderManager::SetTexturesUsed(0);
|
||||||
|
|
||||||
|
// set global constants
|
||||||
|
VertexShaderManager::SetConstants();
|
||||||
|
PixelShaderManager::SetConstants();
|
||||||
|
|
||||||
|
if (!PixelShaderCache::SetShader(false))
|
||||||
|
{
|
||||||
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||||
|
goto shader_fail;
|
||||||
|
}
|
||||||
|
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
||||||
|
{
|
||||||
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set vertex shader\n");});
|
||||||
|
goto shader_fail;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int stride = g_nativeVertexFmt->GetVertexStride();
|
||||||
|
g_nativeVertexFmt->SetupVertexPointers();
|
||||||
|
|
||||||
|
Draw(stride);
|
||||||
|
|
||||||
|
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
||||||
|
{
|
||||||
|
DWORD write = 0;
|
||||||
|
if (!PixelShaderCache::SetShader(true))
|
||||||
{
|
{
|
||||||
if (usedtextures & (1 << i)) {
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||||
FourTexUnits &tex = bpmem.tex[i >> 2];
|
goto shader_fail;
|
||||||
TextureCache::TCacheEntry* tentry = TextureCache::Load(i,
|
|
||||||
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
|
||||||
tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1,
|
|
||||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
|
||||||
tex.texTlut[i&3].tlut_format);
|
|
||||||
|
|
||||||
if (tentry) {
|
|
||||||
PixelShaderManager::SetTexDims(i, tentry->w, tentry->h, 0, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to load texture\n");});
|
|
||||||
ERROR_LOG(VIDEO, "error loading texture");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PixelShaderManager::SetTexturesUsed(0);
|
|
||||||
|
|
||||||
int numVertices = indexGen.GetNumVerts();
|
// update alpha only
|
||||||
if (numVertices)
|
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
||||||
{
|
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, false);
|
||||||
// set global constants
|
|
||||||
VertexShaderManager::SetConstants();
|
|
||||||
PixelShaderManager::SetConstants();
|
|
||||||
|
|
||||||
if (!PixelShaderCache::SetShader(false))
|
Draw(stride);
|
||||||
{
|
|
||||||
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
|
||||||
goto shader_fail;
|
|
||||||
}
|
|
||||||
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
|
||||||
{
|
|
||||||
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set vertex shader\n");});
|
|
||||||
goto shader_fail;
|
|
||||||
|
|
||||||
}
|
if (bpmem.blendmode.alphaupdate)
|
||||||
|
write = D3DCOLORWRITEENABLE_ALPHA;
|
||||||
|
if (bpmem.blendmode.colorupdate)
|
||||||
|
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
||||||
|
if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
|
||||||
|
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, true);
|
||||||
|
|
||||||
int stride = g_nativeVertexFmt->GetVertexStride();
|
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
||||||
g_nativeVertexFmt->SetupVertexPointers();
|
}
|
||||||
|
DEBUGGER_PAUSE_AT(NEXT_FLUSH,true);
|
||||||
Draw(numVertices, stride);
|
|
||||||
|
|
||||||
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
|
||||||
{
|
|
||||||
DWORD write = 0;
|
|
||||||
if (!PixelShaderCache::SetShader(true))
|
|
||||||
{
|
|
||||||
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
|
||||||
goto shader_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update alpha only
|
|
||||||
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
|
||||||
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, false);
|
|
||||||
|
|
||||||
Draw(numVertices, stride);
|
|
||||||
|
|
||||||
if (bpmem.blendmode.alphaupdate)
|
|
||||||
write = D3DCOLORWRITEENABLE_ALPHA;
|
|
||||||
if (bpmem.blendmode.colorupdate)
|
|
||||||
write |= D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE;
|
|
||||||
if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
|
|
||||||
D3D::SetRenderState(D3DRS_ALPHABLENDENABLE, true);
|
|
||||||
|
|
||||||
D3D::SetRenderState(D3DRS_COLORWRITEENABLE, write);
|
|
||||||
}
|
|
||||||
DEBUGGER_PAUSE_AT(NEXT_FLUSH,true);
|
|
||||||
|
|
||||||
shader_fail:
|
shader_fail:
|
||||||
ResetBuffer();
|
ResetBuffer();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -46,8 +46,6 @@ extern NativeVertexFormat *g_nativeVertexFmt;
|
||||||
namespace VertexManager
|
namespace VertexManager
|
||||||
{
|
{
|
||||||
|
|
||||||
static IndexGenerator2 indexGen;
|
|
||||||
|
|
||||||
static int lastPrimitive;
|
static int lastPrimitive;
|
||||||
|
|
||||||
static u8 *LocalVBuffer;
|
static u8 *LocalVBuffer;
|
||||||
|
@ -61,7 +59,7 @@ static GLint max_Index_size = 0;
|
||||||
|
|
||||||
static GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0};
|
static GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0};
|
||||||
static int s_nCurVBOIndex = 0; // current free buffer
|
static int s_nCurVBOIndex = 0; // current free buffer
|
||||||
|
static bool Flushed=false;
|
||||||
|
|
||||||
|
|
||||||
bool Init()
|
bool Init()
|
||||||
|
@ -71,11 +69,12 @@ bool Init()
|
||||||
|
|
||||||
if(max_Index_size>MAXIBUFFERSIZE)
|
if(max_Index_size>MAXIBUFFERSIZE)
|
||||||
max_Index_size = MAXIBUFFERSIZE;
|
max_Index_size = MAXIBUFFERSIZE;
|
||||||
|
|
||||||
LocalVBuffer = new u8[MAXVBUFFERSIZE];
|
LocalVBuffer = new u8[MAXVBUFFERSIZE];
|
||||||
TIBuffer = new u16[max_Index_size];
|
TIBuffer = new u16[max_Index_size];
|
||||||
LIBuffer = new u16[max_Index_size];
|
LIBuffer = new u16[max_Index_size];
|
||||||
PIBuffer = new u16[max_Index_size];
|
PIBuffer = new u16[max_Index_size];
|
||||||
|
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
|
||||||
s_pCurBufferPointer = LocalVBuffer;
|
s_pCurBufferPointer = LocalVBuffer;
|
||||||
s_nCurVBOIndex = 0;
|
s_nCurVBOIndex = 0;
|
||||||
glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
|
glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
|
||||||
|
@ -85,8 +84,9 @@ bool Init()
|
||||||
}
|
}
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
g_nativeVertexFmt = NULL;
|
g_nativeVertexFmt = NULL;
|
||||||
|
Flushed=false;
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
indexGen.Start(TIBuffer,LIBuffer,PIBuffer);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,34 +97,31 @@ void Shutdown()
|
||||||
delete [] LIBuffer;
|
delete [] LIBuffer;
|
||||||
delete [] PIBuffer;
|
delete [] PIBuffer;
|
||||||
glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
|
glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
|
||||||
s_nCurVBOIndex = 0;
|
s_nCurVBOIndex = 0;
|
||||||
ResetBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetBuffer()
|
void ResetBuffer()
|
||||||
{
|
{
|
||||||
s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
|
s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
|
||||||
s_pCurBufferPointer = LocalVBuffer;
|
s_pCurBufferPointer = LocalVBuffer;
|
||||||
indexGen.Start(TIBuffer,LIBuffer,PIBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddIndices(int _primitive, int _numVertices)
|
void AddIndices(int primitive, int numVertices)
|
||||||
{
|
{
|
||||||
switch (_primitive)
|
switch (primitive)
|
||||||
{
|
{
|
||||||
case GX_DRAW_QUADS: indexGen.AddQuads(_numVertices); return;
|
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices); break;
|
||||||
case GX_DRAW_TRIANGLES: indexGen.AddList(_numVertices); return;
|
case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices); break;
|
||||||
case GX_DRAW_TRIANGLE_STRIP: indexGen.AddStrip(_numVertices); return;
|
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
|
||||||
case GX_DRAW_TRIANGLE_FAN: indexGen.AddFan(_numVertices); return;
|
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
|
||||||
case GX_DRAW_LINE_STRIP: indexGen.AddLineStrip(_numVertices); return;
|
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVertices); break;
|
||||||
case GX_DRAW_LINES: indexGen.AddLineList(_numVertices); return;
|
case GX_DRAW_LINES: IndexGenerator::AddLineList(numVertices); break;
|
||||||
case GX_DRAW_POINTS: indexGen.AddPoints(_numVertices); return;
|
case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetRemainingSize()
|
int GetRemainingSize()
|
||||||
{
|
{
|
||||||
|
|
||||||
return MAXVBUFFERSIZE - (int)(s_pCurBufferPointer - LocalVBuffer);
|
return MAXVBUFFERSIZE - (int)(s_pCurBufferPointer - LocalVBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,44 +135,48 @@ void AddVertices(int primitive, int numvertices)
|
||||||
case GX_DRAW_TRIANGLES:
|
case GX_DRAW_TRIANGLES:
|
||||||
case GX_DRAW_TRIANGLE_STRIP:
|
case GX_DRAW_TRIANGLE_STRIP:
|
||||||
case GX_DRAW_TRIANGLE_FAN:
|
case GX_DRAW_TRIANGLE_FAN:
|
||||||
if(max_Index_size - indexGen.GetTriangleindexLen() < 2 * numvertices)
|
if(max_Index_size - IndexGenerator::GetTriangleindexLen() < 2 * numvertices)
|
||||||
Flush();
|
Flush();
|
||||||
break;
|
break;
|
||||||
case GX_DRAW_LINE_STRIP:
|
case GX_DRAW_LINE_STRIP:
|
||||||
case GX_DRAW_LINES:
|
case GX_DRAW_LINES:
|
||||||
if(max_Index_size - indexGen.GetLineindexLen() < 2 * numvertices)
|
if(max_Index_size - IndexGenerator::GetLineindexLen() < 2 * numvertices)
|
||||||
Flush();
|
Flush();
|
||||||
break;
|
break;
|
||||||
case GX_DRAW_POINTS:
|
case GX_DRAW_POINTS:
|
||||||
if(max_Index_size - indexGen.GetPointindexLen() < numvertices)
|
if(max_Index_size - IndexGenerator::GetPointindexLen() < numvertices)
|
||||||
Flush();
|
Flush();
|
||||||
break;
|
break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
|
if(Flushed)
|
||||||
|
{
|
||||||
|
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
|
||||||
|
Flushed=false;
|
||||||
|
}
|
||||||
lastPrimitive = primitive;
|
lastPrimitive = primitive;
|
||||||
ADDSTAT(stats.thisFrame.numPrims, numvertices);
|
ADDSTAT(stats.thisFrame.numPrims, numvertices);
|
||||||
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
||||||
AddIndices(primitive, numvertices);
|
AddIndices(primitive, numvertices);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Draw()
|
inline void Draw()
|
||||||
{
|
{
|
||||||
if(indexGen.GetNumTriangles() > 0)
|
if(IndexGenerator::GetNumTriangles() > 0)
|
||||||
{
|
{
|
||||||
glDrawElements(GL_TRIANGLES, indexGen.GetTriangleindexLen(), GL_UNSIGNED_SHORT,TIBuffer);
|
glDrawElements(GL_TRIANGLES, IndexGenerator::GetTriangleindexLen(), GL_UNSIGNED_SHORT,TIBuffer);
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if(indexGen.GetNumLines() > 0)
|
if(IndexGenerator::GetNumLines() > 0)
|
||||||
{
|
{
|
||||||
glDrawElements(GL_LINES, indexGen.GetLineindexLen(), GL_UNSIGNED_SHORT,LIBuffer);
|
glDrawElements(GL_LINES, IndexGenerator::GetLineindexLen(), GL_UNSIGNED_SHORT,LIBuffer);
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if(indexGen.GetNumPoints() > 0)
|
if(IndexGenerator::GetNumPoints() > 0)
|
||||||
{
|
{
|
||||||
glDrawElements(GL_POINTS, indexGen.GetPointindexLen(), GL_UNSIGNED_SHORT,PIBuffer);
|
glDrawElements(GL_POINTS, IndexGenerator::GetPointindexLen(), GL_UNSIGNED_SHORT,PIBuffer);
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,9 +184,8 @@ inline void Draw()
|
||||||
void Flush()
|
void Flush()
|
||||||
{
|
{
|
||||||
if (LocalVBuffer == s_pCurBufferPointer) return;
|
if (LocalVBuffer == s_pCurBufferPointer) return;
|
||||||
int numVerts = indexGen.GetNumVerts();
|
if(Flushed) return;
|
||||||
if(numVerts == 0) return;
|
Flushed=true;
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGens,
|
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGens,
|
||||||
xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op,
|
xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op,
|
||||||
|
@ -302,10 +302,6 @@ void Flush()
|
||||||
if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid);
|
if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid);
|
||||||
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here.
|
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here.
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
|
||||||
PRIM_LOG("");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
// run through vertex groups again to set alpha
|
// run through vertex groups again to set alpha
|
||||||
|
@ -327,7 +323,9 @@ void Flush()
|
||||||
if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
|
if (bpmem.blendmode.blendenable || bpmem.blendmode.subtract)
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
}
|
}
|
||||||
ResetBuffer();
|
s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
|
||||||
|
s_pCurBufferPointer = LocalVBuffer;
|
||||||
|
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
|
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace VertexManager
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void AddIndices(int _primitive, int _numVertices);
|
void AddIndices(int primitive, int numVertices);
|
||||||
void ResetBuffer();
|
void ResetBuffer();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue