fixed kicking of command buffer if it's full when rendering. fixed compile error on windows

This commit is contained in:
Magnus Auvinen 2012-01-03 22:01:37 +01:00
parent 50d872531a
commit 2991f4071e
3 changed files with 40 additions and 20 deletions

View file

@ -49,6 +49,10 @@
#include <windows.h>
#endif
#include "SDL.h"
#ifdef main
#undef main
#endif
void CGraph::Init(float Min, float Max)
{
@ -1690,8 +1694,6 @@ void CClient::InitInterfaces()
m_Friends.Init();
}
#include "SDL.h"
void CClient::Run()
{
m_LocalStartTime = time_get();

View file

@ -67,7 +67,17 @@ void CGraphics_Threaded::FlushVertices()
Cmd.m_pVertices = (CCommandBuffer::SVertex *)m_pCommandBuffer->AllocData(sizeof(CCommandBuffer::SVertex)*NumVerts);
if(Cmd.m_pVertices == 0x0)
return;
{
// kick command buffer and try again
KickCommandBuffer();
Cmd.m_pVertices = (CCommandBuffer::SVertex *)m_pCommandBuffer->AllocData(sizeof(CCommandBuffer::SVertex)*NumVerts);
if(Cmd.m_pVertices == 0x0)
{
dbg_msg("graphics", "failed to allocate data for vertices");
return;
}
}
mem_copy(Cmd.m_pVertices, m_aVertices, sizeof(CCommandBuffer::SVertex)*NumVerts);
m_pCommandBuffer->AddCommand(Cmd);
@ -757,8 +767,8 @@ int CGraphics_Threaded::Init()
m_ScreenHeight = g_Config.m_GfxScreenHeight;
// create command buffers
m_apCommandBuffers[0] = new CCommandBuffer(1024*512, 1024*1024);
m_apCommandBuffers[1] = new CCommandBuffer(1024*512, 1024*1024);
for(int i = 0; i < NUM_CMDBUFFERS; i++)
m_apCommandBuffers[i] = new CCommandBuffer(128*1024, 2*1024*1024);
m_pCommandBuffer = m_apCommandBuffers[0];
// create null texture, will get id=0
@ -779,6 +789,10 @@ void CGraphics_Threaded::Shutdown()
m_pBackend->Shutdown();
delete m_pBackend;
m_pBackend = 0x0;
// delete the command buffers
for(int i = 0; i < NUM_CMDBUFFERS; i++)
delete m_apCommandBuffers[i];
}
void CGraphics_Threaded::Minimize()

View file

@ -46,9 +46,10 @@ class CCommandBuffer
unsigned DataUsed() { return m_Used; }
};
public:
CBuffer m_CmdBuffer;
CBuffer m_DataBuffer;
public:
enum
{
MAX_TEXTURES=1024*4,
@ -251,7 +252,7 @@ public:
}
template<class T>
void AddCommand(const T &Command)
bool AddCommand(const T &Command)
{
// make sure that we don't do something stupid like ->AddCommand(&Cmd);
(void)static_cast<const SCommand *>(&Command);
@ -259,9 +260,10 @@ public:
// allocate and copy the command into the buffer
SCommand *pCmd = (SCommand *)m_CmdBuffer.Alloc(sizeof(Command));
if(!pCmd)
return;
return false;
mem_copy(pCmd, &Command, sizeof(Command));
pCmd->m_Size = sizeof(Command);
return true;
}
SCommand *GetCommand(unsigned *pIndex)
@ -278,7 +280,7 @@ public:
{
m_CmdBuffer.Reset();
m_DataBuffer.Reset();
}
}
};
// interface for the graphics backend
@ -308,19 +310,10 @@ public:
class CGraphics_Threaded : public IEngineGraphics
{
CCommandBuffer::SState m_State;
IGraphicsBackend *m_pBackend;
CCommandBuffer *m_apCommandBuffers[2];
CCommandBuffer *m_pCommandBuffer;
unsigned m_CurrentCommandBuffer;
//
class IStorage *m_pStorage;
class IConsole *m_pConsole;
enum
{
NUM_CMDBUFFERS = 2,
MAX_VERTICES = 32*1024,
MAX_TEXTURES = 1024*4,
@ -328,6 +321,17 @@ class CGraphics_Threaded : public IEngineGraphics
DRAWING_LINES=2
};
CCommandBuffer::SState m_State;
IGraphicsBackend *m_pBackend;
CCommandBuffer *m_apCommandBuffers[NUM_CMDBUFFERS];
CCommandBuffer *m_pCommandBuffer;
unsigned m_CurrentCommandBuffer;
//
class IStorage *m_pStorage;
class IConsole *m_pConsole;
CCommandBuffer::SVertex m_aVertices[MAX_VERTICES];
int m_NumVertices;