some fixes for point rendering
This commit is contained in:
parent
a5e34dd5cb
commit
8e9bbdeb2f
File diff suppressed because it is too large
Load Diff
|
@ -36,375 +36,383 @@ const u32 MAX_VBUFFER_COUNT = 2;
|
||||||
inline void DumpBadShaders()
|
inline void DumpBadShaders()
|
||||||
{
|
{
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
// TODO: Reimplement!
|
// TODO: Reimplement!
|
||||||
/* std::string error_shaders;
|
/* std::string error_shaders;
|
||||||
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
||||||
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
||||||
char filename[512] = "bad_shader_combo_0.txt";
|
char filename[512] = "bad_shader_combo_0.txt";
|
||||||
int which = 0;
|
int which = 0;
|
||||||
while (File::Exists(filename))
|
while (File::Exists(filename))
|
||||||
{
|
{
|
||||||
which++;
|
which++;
|
||||||
sprintf(filename, "bad_shader_combo_%i.txt", which);
|
sprintf(filename, "bad_shader_combo_%i.txt", which);
|
||||||
}
|
}
|
||||||
File::WriteStringToFile(true, error_shaders, filename);
|
File::WriteStringToFile(true, error_shaders, filename);
|
||||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to %s", filename);*/
|
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to %s", filename);*/
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::CreateDeviceObjects()
|
void VertexManager::CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
m_buffers_count = 0;
|
m_buffers_count = 0;
|
||||||
m_vertex_buffers = NULL;
|
m_vertex_buffers = NULL;
|
||||||
m_index_buffers = NULL;
|
m_index_buffers = NULL;
|
||||||
D3DCAPS9 DeviceCaps = D3D::GetCaps();
|
D3DCAPS9 DeviceCaps = D3D::GetCaps();
|
||||||
u32 devicevMaxBufferSize = DeviceCaps.MaxPrimitiveCount * 3 * DeviceCaps.MaxStreamStride;
|
u32 devicevMaxBufferSize = DeviceCaps.MaxPrimitiveCount * 3 * DeviceCaps.MaxStreamStride;
|
||||||
//Calculate Device Dependant size
|
//Calculate Device Dependant size
|
||||||
m_vertex_buffer_size = (VBUFFER_SIZE > devicevMaxBufferSize) ? devicevMaxBufferSize : VBUFFER_SIZE;
|
m_vertex_buffer_size = (VBUFFER_SIZE > devicevMaxBufferSize) ? devicevMaxBufferSize : VBUFFER_SIZE;
|
||||||
m_index_buffer_size = (IBUFFER_SIZE > DeviceCaps.MaxVertexIndex) ? DeviceCaps.MaxVertexIndex : IBUFFER_SIZE;
|
m_index_buffer_size = (IBUFFER_SIZE > DeviceCaps.MaxVertexIndex) ? DeviceCaps.MaxVertexIndex : IBUFFER_SIZE;
|
||||||
//if device caps are not enough for Vbuffer fall back to vertex arrays
|
//if device caps are not enough for Vbuffer fall back to vertex arrays
|
||||||
if (m_index_buffer_size < MAXIBUFFERSIZE || m_vertex_buffer_size < MAXVBUFFERSIZE) return;
|
if (m_index_buffer_size < MAXIBUFFERSIZE || m_vertex_buffer_size < MAXVBUFFERSIZE) return;
|
||||||
|
|
||||||
m_vertex_buffers = new LPDIRECT3DVERTEXBUFFER9[MAX_VBUFFER_COUNT];
|
m_vertex_buffers = new LPDIRECT3DVERTEXBUFFER9[MAX_VBUFFER_COUNT];
|
||||||
m_index_buffers = new LPDIRECT3DINDEXBUFFER9[MAX_VBUFFER_COUNT];
|
m_index_buffers = new LPDIRECT3DINDEXBUFFER9[MAX_VBUFFER_COUNT];
|
||||||
|
|
||||||
bool Fail = false;
|
bool Fail = false;
|
||||||
for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++)
|
for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++)
|
||||||
{
|
{
|
||||||
m_vertex_buffers[m_current_vertex_buffer] = NULL;
|
m_vertex_buffers[m_current_vertex_buffer] = NULL;
|
||||||
m_index_buffers[m_current_vertex_buffer] = NULL;
|
m_index_buffers[m_current_vertex_buffer] = NULL;
|
||||||
}
|
}
|
||||||
for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++)
|
for (m_current_vertex_buffer = 0; m_current_vertex_buffer < MAX_VBUFFER_COUNT; m_current_vertex_buffer++)
|
||||||
{
|
{
|
||||||
if(FAILED( D3D::dev->CreateVertexBuffer( m_vertex_buffer_size, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_vertex_buffers[m_current_vertex_buffer], NULL ) ) )
|
if(FAILED( D3D::dev->CreateVertexBuffer( m_vertex_buffer_size, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_vertex_buffers[m_current_vertex_buffer], NULL ) ) )
|
||||||
{
|
{
|
||||||
Fail = true;
|
Fail = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( FAILED( D3D::dev->CreateIndexBuffer( m_index_buffer_size * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_index_buffers[m_current_vertex_buffer], NULL ) ) )
|
if( FAILED( D3D::dev->CreateIndexBuffer( m_index_buffer_size * sizeof(u16), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_index_buffers[m_current_vertex_buffer], NULL ) ) )
|
||||||
{
|
{
|
||||||
Fail = true;
|
Fail = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_buffers_count = m_current_vertex_buffer;
|
m_buffers_count = m_current_vertex_buffer;
|
||||||
m_current_vertex_buffer = 0;
|
m_current_vertex_buffer = 0;
|
||||||
m_current_index_buffer = 0;
|
m_current_index_buffer = 0;
|
||||||
m_index_buffer_cursor = m_index_buffer_size;
|
m_index_buffer_cursor = m_index_buffer_size;
|
||||||
m_vertex_buffer_cursor = m_vertex_buffer_size;
|
m_vertex_buffer_cursor = m_vertex_buffer_size;
|
||||||
m_current_stride = 0;
|
m_current_stride = 0;
|
||||||
if (Fail)
|
if (Fail)
|
||||||
{
|
{
|
||||||
m_buffers_count--;
|
m_buffers_count--;
|
||||||
if (m_buffers_count < 2)
|
if (m_buffers_count < 2)
|
||||||
{
|
{
|
||||||
//Error creating Vertex buffers. clean and fall to Vertex arrays
|
//Error creating Vertex buffers. clean and fall to Vertex arrays
|
||||||
m_buffers_count = MAX_VBUFFER_COUNT;
|
m_buffers_count = MAX_VBUFFER_COUNT;
|
||||||
DestroyDeviceObjects();
|
DestroyDeviceObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void VertexManager::DestroyDeviceObjects()
|
void VertexManager::DestroyDeviceObjects()
|
||||||
{
|
{
|
||||||
D3D::SetStreamSource( 0, NULL, 0, 0);
|
D3D::SetStreamSource( 0, NULL, 0, 0);
|
||||||
D3D::SetIndices(NULL);
|
D3D::SetIndices(NULL);
|
||||||
for (int i = 0; i < MAX_VBUFFER_COUNT; i++)
|
for (int i = 0; i < MAX_VBUFFER_COUNT; i++)
|
||||||
{
|
{
|
||||||
if(m_vertex_buffers)
|
if(m_vertex_buffers)
|
||||||
{
|
{
|
||||||
if (m_vertex_buffers[i])
|
if (m_vertex_buffers[i])
|
||||||
{
|
{
|
||||||
m_vertex_buffers[i]->Release();
|
m_vertex_buffers[i]->Release();
|
||||||
m_vertex_buffers[i] = NULL;
|
m_vertex_buffers[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_index_buffers[i])
|
if (m_index_buffers[i])
|
||||||
{
|
{
|
||||||
m_index_buffers[i]->Release();
|
m_index_buffers[i]->Release();
|
||||||
m_index_buffers[i] = NULL;
|
m_index_buffers[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(m_vertex_buffers)
|
if(m_vertex_buffers)
|
||||||
delete [] m_vertex_buffers;
|
delete [] m_vertex_buffers;
|
||||||
if(m_index_buffers)
|
if(m_index_buffers)
|
||||||
delete [] m_index_buffers;
|
delete [] m_index_buffers;
|
||||||
m_vertex_buffers = NULL;
|
m_vertex_buffers = NULL;
|
||||||
m_index_buffers = NULL;
|
m_index_buffers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::PrepareDrawBuffers(u32 stride)
|
void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||||
{
|
{
|
||||||
if (!m_buffers_count)
|
if (!m_buffers_count)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
u8* pVertices;
|
u8* pVertices;
|
||||||
u16* pIndices;
|
u16* pIndices;
|
||||||
int datasize = IndexGenerator::GetNumVerts() * stride;
|
int datasize = IndexGenerator::GetNumVerts() * stride;
|
||||||
int TdataSize = IndexGenerator::GetTriangleindexLen();
|
int TdataSize = IndexGenerator::GetTriangleindexLen();
|
||||||
int LDataSize = IndexGenerator::GetLineindexLen();
|
int LDataSize = IndexGenerator::GetLineindexLen();
|
||||||
int PDataSize = IndexGenerator::GetPointindexLen();
|
int IndexDataSize = TdataSize + LDataSize;
|
||||||
int IndexDataSize = TdataSize + LDataSize;
|
if(IndexDataSize)
|
||||||
DWORD LockMode = D3DLOCK_NOOVERWRITE;
|
{
|
||||||
m_vertex_buffer_cursor--;
|
DWORD LockMode = D3DLOCK_NOOVERWRITE;
|
||||||
m_vertex_buffer_cursor = m_vertex_buffer_cursor - (m_vertex_buffer_cursor % stride) + stride;
|
m_vertex_buffer_cursor--;
|
||||||
if (m_vertex_buffer_cursor > m_vertex_buffer_size - datasize)
|
m_vertex_buffer_cursor = m_vertex_buffer_cursor - (m_vertex_buffer_cursor % stride) + stride;
|
||||||
{
|
if (m_vertex_buffer_cursor > m_vertex_buffer_size - datasize)
|
||||||
LockMode = D3DLOCK_DISCARD;
|
{
|
||||||
m_vertex_buffer_cursor = 0;
|
LockMode = D3DLOCK_DISCARD;
|
||||||
m_current_vertex_buffer = (m_current_vertex_buffer + 1) % m_buffers_count;
|
m_vertex_buffer_cursor = 0;
|
||||||
}
|
m_current_vertex_buffer = (m_current_vertex_buffer + 1) % m_buffers_count;
|
||||||
if(FAILED(m_vertex_buffers[m_current_vertex_buffer]->Lock(m_vertex_buffer_cursor, datasize,(VOID**)(&pVertices), LockMode)))
|
}
|
||||||
{
|
if(FAILED(m_vertex_buffers[m_current_vertex_buffer]->Lock(m_vertex_buffer_cursor, datasize,(VOID**)(&pVertices), LockMode)))
|
||||||
DestroyDeviceObjects();
|
{
|
||||||
return;
|
DestroyDeviceObjects();
|
||||||
}
|
return;
|
||||||
memcpy(pVertices, s_pBaseBufferPointer, datasize);
|
}
|
||||||
m_vertex_buffers[m_current_vertex_buffer]->Unlock();
|
memcpy(pVertices, s_pBaseBufferPointer, datasize);
|
||||||
|
m_vertex_buffers[m_current_vertex_buffer]->Unlock();
|
||||||
|
|
||||||
LockMode = D3DLOCK_NOOVERWRITE;
|
LockMode = D3DLOCK_NOOVERWRITE;
|
||||||
if (m_index_buffer_cursor > m_index_buffer_size - IndexDataSize)
|
if (m_index_buffer_cursor > m_index_buffer_size - IndexDataSize)
|
||||||
{
|
{
|
||||||
LockMode = D3DLOCK_DISCARD;
|
LockMode = D3DLOCK_DISCARD;
|
||||||
m_index_buffer_cursor = 0;
|
m_index_buffer_cursor = 0;
|
||||||
m_current_index_buffer = (m_current_index_buffer + 1) % m_buffers_count;
|
m_current_index_buffer = (m_current_index_buffer + 1) % m_buffers_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(FAILED(m_index_buffers[m_current_index_buffer]->Lock(m_index_buffer_cursor * sizeof(u16), IndexDataSize * sizeof(u16), (VOID**)(&pIndices), LockMode )))
|
if(FAILED(m_index_buffers[m_current_index_buffer]->Lock(m_index_buffer_cursor * sizeof(u16), IndexDataSize * sizeof(u16), (VOID**)(&pIndices), LockMode )))
|
||||||
{
|
{
|
||||||
DestroyDeviceObjects();
|
DestroyDeviceObjects();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(TdataSize)
|
if(TdataSize)
|
||||||
{
|
{
|
||||||
memcpy(pIndices, GetTriangleIndexBuffer(), TdataSize * sizeof(u16));
|
memcpy(pIndices, GetTriangleIndexBuffer(), TdataSize * sizeof(u16));
|
||||||
pIndices += TdataSize;
|
pIndices += TdataSize;
|
||||||
}
|
}
|
||||||
if(LDataSize)
|
if(LDataSize)
|
||||||
{
|
{
|
||||||
memcpy(pIndices, GetLineIndexBuffer(), LDataSize * sizeof(u16));
|
memcpy(pIndices, GetLineIndexBuffer(), LDataSize * sizeof(u16));
|
||||||
pIndices += LDataSize;
|
pIndices += LDataSize;
|
||||||
}
|
}
|
||||||
m_index_buffers[m_current_index_buffer]->Unlock();
|
m_index_buffers[m_current_index_buffer]->Unlock();
|
||||||
if(m_current_stride != stride || m_vertex_buffer_cursor == 0)
|
}
|
||||||
{
|
if(m_current_stride != stride || m_vertex_buffer_cursor == 0)
|
||||||
m_current_stride = stride;
|
{
|
||||||
D3D::SetStreamSource( 0, m_vertex_buffers[m_current_vertex_buffer], 0, stride);
|
m_current_stride = stride;
|
||||||
}
|
D3D::SetStreamSource( 0, m_vertex_buffers[m_current_vertex_buffer], 0, m_current_stride);
|
||||||
if (m_index_buffer_cursor == 0)
|
}
|
||||||
{
|
if (m_index_buffer_cursor == 0)
|
||||||
D3D::SetIndices(m_index_buffers[m_current_index_buffer]);
|
{
|
||||||
}
|
D3D::SetIndices(m_index_buffers[m_current_index_buffer]);
|
||||||
|
}
|
||||||
|
|
||||||
ADDSTAT(stats.thisFrame.bytesVertexStreamed, datasize);
|
ADDSTAT(stats.thisFrame.bytesVertexStreamed, datasize);
|
||||||
ADDSTAT(stats.thisFrame.bytesIndexStreamed, IndexDataSize);
|
ADDSTAT(stats.thisFrame.bytesIndexStreamed, IndexDataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::DrawVertexBuffer(int stride)
|
void VertexManager::DrawVertexBuffer(int stride)
|
||||||
{
|
{
|
||||||
int triangles = IndexGenerator::GetNumTriangles();
|
int triangles = IndexGenerator::GetNumTriangles();
|
||||||
int lines = IndexGenerator::GetNumLines();
|
int lines = IndexGenerator::GetNumLines();
|
||||||
int points = IndexGenerator::GetNumPoints();
|
int points = IndexGenerator::GetNumPoints();
|
||||||
int numverts = IndexGenerator::GetNumVerts();
|
int numverts = IndexGenerator::GetNumVerts();
|
||||||
int StartIndex = m_index_buffer_cursor;
|
int StartIndex = m_index_buffer_cursor;
|
||||||
int basevertex = m_vertex_buffer_cursor / stride;
|
int basevertex = m_vertex_buffer_cursor / stride;
|
||||||
if (triangles > 0)
|
if (triangles > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
||||||
D3DPT_TRIANGLELIST,
|
D3DPT_TRIANGLELIST,
|
||||||
basevertex,
|
basevertex,
|
||||||
0,
|
0,
|
||||||
numverts,
|
numverts,
|
||||||
StartIndex,
|
StartIndex,
|
||||||
triangles)))
|
triangles)))
|
||||||
{
|
{
|
||||||
DumpBadShaders();
|
DumpBadShaders();
|
||||||
}
|
}
|
||||||
StartIndex += IndexGenerator::GetTriangleindexLen();
|
StartIndex += IndexGenerator::GetTriangleindexLen();
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if (lines > 0)
|
if (lines > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
if (FAILED(D3D::dev->DrawIndexedPrimitive(
|
||||||
D3DPT_LINELIST,
|
D3DPT_LINELIST,
|
||||||
basevertex,
|
basevertex,
|
||||||
0,
|
0,
|
||||||
numverts,
|
numverts,
|
||||||
StartIndex,
|
StartIndex,
|
||||||
IndexGenerator::GetNumLines())))
|
IndexGenerator::GetNumLines())))
|
||||||
{
|
{
|
||||||
DumpBadShaders();
|
DumpBadShaders();
|
||||||
}
|
}
|
||||||
StartIndex += IndexGenerator::GetLineindexLen();
|
StartIndex += IndexGenerator::GetLineindexLen();
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if (points > 0)
|
if (points > 0)
|
||||||
{
|
{
|
||||||
//DrawIndexedPrimitive does not support point list so we have to draw the points one by one
|
//DrawIndexedPrimitive does not support point list so we have to draw them using DrawPrimitive
|
||||||
for (int i = 0; i < points; i++)
|
u16* PointIndexBuffer = GetPointIndexBuffer();
|
||||||
{
|
int i = 0;
|
||||||
if (FAILED(D3D::dev->DrawPrimitive(
|
do
|
||||||
D3DPT_POINTLIST,
|
{
|
||||||
basevertex + GetPointIndexBuffer()[i],
|
int count = i + 1;
|
||||||
1)))
|
while (count < points && PointIndexBuffer[count - 1] + 1 == PointIndexBuffer[count])
|
||||||
{
|
{
|
||||||
DumpBadShaders();
|
count++;
|
||||||
}
|
}
|
||||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
if (FAILED(D3D::dev->DrawPrimitive(
|
||||||
}
|
D3DPT_POINTLIST,
|
||||||
|
basevertex + PointIndexBuffer[i],
|
||||||
|
count - i)))
|
||||||
}
|
{
|
||||||
|
DumpBadShaders();
|
||||||
|
}
|
||||||
|
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||||
|
i = count;
|
||||||
|
} while (i < points);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::DrawVertexArray(int stride)
|
void VertexManager::DrawVertexArray(int stride)
|
||||||
{
|
{
|
||||||
int triangles = IndexGenerator::GetNumTriangles();
|
int triangles = IndexGenerator::GetNumTriangles();
|
||||||
int lines = IndexGenerator::GetNumLines();
|
int lines = IndexGenerator::GetNumLines();
|
||||||
int points = IndexGenerator::GetNumPoints();
|
int points = IndexGenerator::GetNumPoints();
|
||||||
int numverts = IndexGenerator::GetNumVerts();
|
int numverts = IndexGenerator::GetNumVerts();
|
||||||
if (triangles > 0)
|
if (triangles > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||||
D3DPT_TRIANGLELIST,
|
D3DPT_TRIANGLELIST,
|
||||||
0, numverts, triangles,
|
0, numverts, triangles,
|
||||||
GetTriangleIndexBuffer(),
|
GetTriangleIndexBuffer(),
|
||||||
D3DFMT_INDEX16,
|
D3DFMT_INDEX16,
|
||||||
s_pBaseBufferPointer,
|
s_pBaseBufferPointer,
|
||||||
stride)))
|
stride)))
|
||||||
{
|
{
|
||||||
DumpBadShaders();
|
DumpBadShaders();
|
||||||
}
|
}
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if (lines > 0)
|
if (lines > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||||
D3DPT_LINELIST,
|
D3DPT_LINELIST,
|
||||||
0, numverts, lines,
|
0, numverts, lines,
|
||||||
GetLineIndexBuffer(),
|
GetLineIndexBuffer(),
|
||||||
D3DFMT_INDEX16,
|
D3DFMT_INDEX16,
|
||||||
s_pBaseBufferPointer,
|
s_pBaseBufferPointer,
|
||||||
stride)))
|
stride)))
|
||||||
{
|
{
|
||||||
DumpBadShaders();
|
DumpBadShaders();
|
||||||
}
|
}
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if (points > 0)
|
if (points > 0)
|
||||||
{
|
{
|
||||||
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
||||||
D3DPT_POINTLIST,
|
D3DPT_POINTLIST,
|
||||||
0, numverts, points,
|
0, numverts, points,
|
||||||
GetPointIndexBuffer(),
|
GetPointIndexBuffer(),
|
||||||
D3DFMT_INDEX16,
|
D3DFMT_INDEX16,
|
||||||
s_pBaseBufferPointer,
|
s_pBaseBufferPointer,
|
||||||
stride)))
|
stride)))
|
||||||
{
|
{
|
||||||
DumpBadShaders();
|
DumpBadShaders();
|
||||||
}
|
}
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::vFlush()
|
void VertexManager::vFlush()
|
||||||
{
|
{
|
||||||
u32 usedtextures = 0;
|
u32 usedtextures = 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.tevorders[i / 2].getEnable(i & 1))
|
||||||
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1);
|
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1);
|
||||||
|
|
||||||
if (bpmem.genMode.numindstages > 0)
|
if (bpmem.genMode.numindstages > 0)
|
||||||
for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1; ++i)
|
for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1; ++i)
|
||||||
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages)
|
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages)
|
||||||
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
|
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 8; i++)
|
for (unsigned int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
if (usedtextures & (1 << i))
|
if (usedtextures & (1 << i))
|
||||||
{
|
{
|
||||||
g_renderer->SetSamplerState(i & 3, i >> 2);
|
g_renderer->SetSamplerState(i & 3, i >> 2);
|
||||||
FourTexUnits &tex = bpmem.tex[i >> 2];
|
FourTexUnits &tex = bpmem.tex[i >> 2];
|
||||||
TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
|
TextureCache::TCacheEntryBase* tentry = TextureCache::Load(i,
|
||||||
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
||||||
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
||||||
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
||||||
tex.texTlut[i&3].tlut_format,
|
tex.texTlut[i&3].tlut_format,
|
||||||
(tex.texMode0[i&3].min_filter & 3),
|
(tex.texMode0[i&3].min_filter & 3),
|
||||||
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
(tex.texMode1[i&3].max_lod + 0xf) / 0x10,
|
||||||
tex.texImage1[i&3].image_type);
|
tex.texImage1[i&3].image_type);
|
||||||
|
|
||||||
if (tentry)
|
if (tentry)
|
||||||
{
|
{
|
||||||
// 0s are probably for no manual wrapping needed.
|
// 0s are probably for no manual wrapping needed.
|
||||||
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ERROR_LOG(VIDEO, "Error loading texture");
|
ERROR_LOG(VIDEO, "Error loading texture");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set global constants
|
// set global constants
|
||||||
VertexShaderManager::SetConstants();
|
VertexShaderManager::SetConstants();
|
||||||
PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components);
|
PixelShaderManager::SetConstants(g_nativeVertexFmt->m_components);
|
||||||
u32 stride = g_nativeVertexFmt->GetVertexStride();
|
u32 stride = g_nativeVertexFmt->GetVertexStride();
|
||||||
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
|
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
|
||||||
bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||||
bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
||||||
DSTALPHA_MODE AlphaMode = useDualSource ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE;
|
DSTALPHA_MODE AlphaMode = useDualSource ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE;
|
||||||
|
|
||||||
if (!PixelShaderCache::SetShader(AlphaMode ,g_nativeVertexFmt->m_components))
|
if (!PixelShaderCache::SetShader(AlphaMode ,g_nativeVertexFmt->m_components))
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||||
goto shader_fail;
|
goto shader_fail;
|
||||||
}
|
}
|
||||||
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set vertex shader\n");});
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set vertex shader\n");});
|
||||||
goto shader_fail;
|
goto shader_fail;
|
||||||
|
|
||||||
}
|
}
|
||||||
PrepareDrawBuffers(stride);
|
PrepareDrawBuffers(stride);
|
||||||
g_nativeVertexFmt->SetupVertexPointers();
|
g_nativeVertexFmt->SetupVertexPointers();
|
||||||
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
|
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
|
||||||
if(m_buffers_count)
|
if(m_buffers_count)
|
||||||
{
|
{
|
||||||
DrawVertexBuffer(stride);
|
DrawVertexBuffer(stride);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawVertexArray(stride);
|
DrawVertexArray(stride);
|
||||||
}
|
}
|
||||||
g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
|
g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
|
||||||
if (useDstAlpha && !useDualSource)
|
if (useDstAlpha && !useDualSource)
|
||||||
{
|
{
|
||||||
if (!PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS, g_nativeVertexFmt->m_components))
|
if (!PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS, g_nativeVertexFmt->m_components))
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||||
goto shader_fail;
|
goto shader_fail;
|
||||||
}
|
}
|
||||||
// update alpha only
|
// update alpha only
|
||||||
g_renderer->ApplyState(true);
|
g_renderer->ApplyState(true);
|
||||||
if(m_buffers_count)
|
if(m_buffers_count)
|
||||||
{
|
{
|
||||||
DrawVertexBuffer(stride);
|
DrawVertexBuffer(stride);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawVertexArray(stride);
|
DrawVertexArray(stride);
|
||||||
}
|
}
|
||||||
g_renderer->RestoreState();
|
g_renderer->RestoreState();
|
||||||
}
|
}
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
|
||||||
|
|
||||||
shader_fail:
|
shader_fail:
|
||||||
if(m_buffers_count)
|
if(m_buffers_count)
|
||||||
{
|
{
|
||||||
m_index_buffer_cursor += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
|
m_index_buffer_cursor += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
|
||||||
m_vertex_buffer_cursor += IndexGenerator::GetNumVerts() * stride;
|
m_vertex_buffer_cursor += IndexGenerator::GetNumVerts() * stride;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue