Browse Source

gpu: silently ignore empty vertex and index buffers instead of crashing

and letting the user guess what happened. This doesn't prevent us from
displaying an additional friendly warning later.
legacy
Sam Hocevar sam 12 years ago
parent
commit
1b9facda49
2 changed files with 49 additions and 12 deletions
  1. +24
    -6
      src/gpu/indexbuffer.cpp
  2. +25
    -6
      src/gpu/vertexbuffer.cpp

+ 24
- 6
src/gpu/indexbuffer.cpp View File

@@ -41,6 +41,8 @@ class IndexBufferData
{
friend class IndexBuffer;

size_t m_size;

#if defined USE_D3D9
IDirect3DIndexBuffer9 *m_ibo;
#elif defined _XBOX
@@ -48,7 +50,6 @@ class IndexBufferData
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
GLuint m_ibo;
uint8_t *m_memory;
size_t m_size;
#endif
};

@@ -60,6 +61,9 @@ class IndexBufferData
IndexBuffer::IndexBuffer(size_t size)
: m_data(new IndexBufferData)
{
m_data->m_size = size;
if (!size)
return;
#if defined USE_D3D9 || defined _XBOX
if (FAILED(g_d3ddevice->CreateIndexBuffer(size, D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED,
@@ -68,24 +72,29 @@ IndexBuffer::IndexBuffer(size_t size)
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
glGenBuffers(1, &m_data->m_ibo);
m_data->m_memory = new uint8_t[size];
m_data->m_size = size;
#endif
}

IndexBuffer::~IndexBuffer()
{
if (m_data->m_size)
{
#if defined USE_D3D9 || defined _XBOX
if (FAILED(m_data->m_ibo->Release()))
Abort();
if (FAILED(m_data->m_ibo->Release()))
Abort();
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
glDeleteBuffers(1, &m_data->m_ibo);
delete[] m_data->m_memory;
glDeleteBuffers(1, &m_data->m_ibo);
delete[] m_data->m_memory;
#endif
}
delete m_data;
}

void *IndexBuffer::Lock(size_t offset, size_t size)
{
if (!m_data->m_size)
return NULL;

#if defined USE_D3D9 || defined _XBOX
void *ret;
if (FAILED(m_data->m_ibo->Lock(offset, size, (void **)&ret, 0)))
@@ -98,6 +107,9 @@ void *IndexBuffer::Lock(size_t offset, size_t size)

void IndexBuffer::Unlock()
{
if (!m_data->m_size)
return;

#if defined USE_D3D9 || defined _XBOX
if (FAILED(m_data->m_ibo->Unlock()))
Abort();
@@ -110,6 +122,9 @@ void IndexBuffer::Unlock()

void IndexBuffer::Bind()
{
if (!m_data->m_size)
return;

#if defined USE_D3D9 || defined _XBOX
if (FAILED(g_d3ddevice->SetIndices(m_data->m_ibo)))
Abort();
@@ -123,6 +138,9 @@ void IndexBuffer::Bind()

void IndexBuffer::Unbind()
{
if (!m_data->m_size)
return;

#if defined USE_D3D9 || defined _XBOX
if (FAILED(g_d3ddevice->SetIndices(NULL)))
Abort();


+ 25
- 6
src/gpu/vertexbuffer.cpp View File

@@ -42,6 +42,8 @@ class VertexBufferData
friend class VertexBuffer;
friend class VertexDeclaration;

size_t m_size;

#if defined USE_D3D9
IDirect3DVertexBuffer9 *m_vbo;
#elif defined _XBOX
@@ -49,7 +51,6 @@ class VertexBufferData
#else
GLuint m_vbo;
uint8_t *m_memory;
size_t m_size;
#endif
};

@@ -122,6 +123,9 @@ void VertexDeclaration::Bind()

void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count)
{
if (count <= 0)
return;

#if defined _XBOX || defined USE_D3D9
g_d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
g_d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
@@ -158,6 +162,9 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase,
int vskip, int vcount,
int skip, int count)
{
if (count <= 0)
return;

#if defined _XBOX || defined USE_D3D9
g_d3ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
g_d3ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
@@ -226,6 +233,9 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1,
ShaderAttrib attr11,
ShaderAttrib attr12)
{
if (!vb->m_data->m_size)
return;

#if defined _XBOX || defined USE_D3D9
/* Only the first item is required to know which stream this
* is about; the rest of the information is stored in the
@@ -469,6 +479,9 @@ void VertexDeclaration::AddStream(VertexStreamBase const &s)
VertexBuffer::VertexBuffer(size_t size)
: m_data(new VertexBufferData)
{
m_data->m_size = size;
if (!size)
return;
#if defined USE_D3D9 || defined _XBOX
if (FAILED(g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL,
D3DPOOL_MANAGED, &m_data->m_vbo, NULL)))
@@ -476,24 +489,28 @@ VertexBuffer::VertexBuffer(size_t size)
#elif !defined __CELLOS_LV2__
glGenBuffers(1, &m_data->m_vbo);
m_data->m_memory = new uint8_t[size];
m_data->m_size = size;
#endif
}

VertexBuffer::~VertexBuffer()
{
if (m_data->m_size)
{
#if defined USE_D3D9 || defined _XBOX
if (FAILED(m_data->m_vbo->Release()))
Abort();
if (FAILED(m_data->m_vbo->Release()))
Abort();
#elif !defined __CELLOS_LV2__
glDeleteBuffers(1, &m_data->m_vbo);
delete[] m_data->m_memory;
glDeleteBuffers(1, &m_data->m_vbo);
delete[] m_data->m_memory;
#endif
}
delete m_data;
}

void *VertexBuffer::Lock(size_t offset, size_t size)
{
if (!m_data->m_size)
return NULL;
#if defined USE_D3D9 || defined _XBOX
void *ret;
if (FAILED(m_data->m_vbo->Lock(offset, size, (void **)&ret, 0)))
@@ -506,6 +523,8 @@ void *VertexBuffer::Lock(size_t offset, size_t size)

void VertexBuffer::Unlock()
{
if (!m_data->m_size)
return;
#if defined USE_D3D9 || defined _XBOX
if (FAILED(m_data->m_vbo->Unlock()))
Abort();


Loading…
Cancel
Save