Quellcode durchsuchen

gpu: replace exit(0) in D3D error checks with lol::Abort().

legacy
Sam Hocevar sam vor 12 Jahren
Ursprung
Commit
48c7070243
10 geänderte Dateien mit 79 neuen und 35 gelöschten Zeilen
  1. +1
    -1
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +32
    -0
      src/debug/debug.h
  4. +22
    -11
      src/gpu/vertexbuffer.cpp
  5. +6
    -3
      src/platform/sdl/sdlapp.cpp
  6. +1
    -11
      src/scene.cpp
  7. +3
    -2
      src/video.cpp
  8. +1
    -1
      test/tutorial/tut01.cpp
  9. +11
    -6
      test/tutorial/tut02.cpp
  10. +1
    -0
      win32/lolcore.vcxproj

+ 1
- 1
src/Makefile.am Datei anzeigen

@@ -2,7 +2,7 @@
noinst_LIBRARIES = liblol.a

liblol_a_SOURCES = \
core.h tiler.cpp tiler.h dict.cpp dict.h \
core.h tiler.cpp tiler.h dict.cpp dict.h debug/debug.h \
audio.cpp audio.h scene.cpp scene.h font.cpp font.h layer.cpp layer.h \
map.cpp map.h entity.cpp entity.h ticker.cpp ticker.h lolgl.h \
tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h log.cpp log.h \


+ 1
- 0
src/core.h Datei anzeigen

@@ -71,6 +71,7 @@ static inline int isnan(float f)
#include "thread/thread.h"

// Static classes
#include "debug/debug.h"
#include "log.h"
#include "platform.h"
#include "video.h"


+ 32
- 0
src/debug/debug.h Datei anzeigen

@@ -0,0 +1,32 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

//
// Debug utilities
// ---------------
//

#if !defined __LOL_DEBUG_H__
#define __LOL_DEBUG_H__

#include "entity.h"

namespace lol
{

static void Abort()
{
*(int *)NULL = 0;
}

} /* namespace lol */

#endif // __LOL_DEBUG_H__


+ 22
- 11
src/gpu/vertexbuffer.cpp Datei anzeigen

@@ -97,7 +97,8 @@ VertexDeclaration::~VertexDeclaration()
D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
# endif

vdecl->Release();
if (FAILED(vdecl->Release()))
Abort();
#else

#endif
@@ -112,7 +113,8 @@ void VertexDeclaration::Bind()
D3DVertexDeclaration *vdecl = (D3DVertexDeclaration *)m_data;
# endif

g_d3ddevice->SetVertexDeclaration(vdecl);
if (FAILED(g_d3ddevice->SetVertexDeclaration(vdecl)))
Abort();
#else
/* FIXME: Nothing to do? */
#endif
@@ -121,11 +123,13 @@ void VertexDeclaration::Bind()
void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count)
{
#if defined _XBOX || defined USE_D3D9
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)))
Abort();
switch (type)
{
case MeshPrimitive::Triangles:
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count);
if (FAILED(g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count)))
Abort();
break;
}
#else
@@ -193,7 +197,10 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1,
/* Now we know the stream index and the element stride */
/* FIXME: precompute most of the crap above! */
if (stream >= 0)
g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride);
{
if (FAILED(g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride)))
Abort();
}
#else
glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo);
ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6,
@@ -334,7 +341,8 @@ void VertexDeclaration::Initialize()
D3DVertexDeclaration *vdecl;
# endif

g_d3ddevice->CreateVertexDeclaration(elements, &vdecl);
if (FAILED(g_d3ddevice->CreateVertexDeclaration(elements, &vdecl)))
Abort();

m_data = vdecl;
#else
@@ -365,8 +373,9 @@ VertexBuffer::VertexBuffer(size_t size)
: m_data(new VertexBufferData)
{
#if defined USE_D3D9 || defined _XBOX
g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL,
D3DPOOL_MANAGED, &m_data->m_vbo, NULL);
if (FAILED(g_d3ddevice->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, NULL,
D3DPOOL_MANAGED, &m_data->m_vbo, NULL)))
Abort();
new uint8_t[size];
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
glGenBuffers(1, &m_data->m_vbo);
@@ -378,7 +387,8 @@ VertexBuffer::VertexBuffer(size_t size)
VertexBuffer::~VertexBuffer()
{
#if defined USE_D3D9 || defined _XBOX
m_data->m_vbo->Release();
if (FAILED(m_data->m_vbo->Release()))
Abort();
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
glDeleteBuffers(1, &m_data->m_vbo);
delete[] m_data->m_memory;
@@ -390,7 +400,7 @@ void *VertexBuffer::Lock(size_t offset, size_t size)
#if defined USE_D3D9 || defined _XBOX
void *ret;
if (FAILED(m_data->m_vbo->Lock(offset, size, (void **)&ret, 0)))
exit(0);
Abort();
return ret;
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
return m_data->m_memory + offset;
@@ -400,7 +410,8 @@ void *VertexBuffer::Lock(size_t offset, size_t size)
void VertexBuffer::Unlock()
{
#if defined USE_D3D9 || defined _XBOX
m_data->m_vbo->Unlock();
if (FAILED(m_data->m_vbo->Unlock()))
Abort();
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory,


+ 6
- 3
src/platform/sdl/sdlapp.cpp Datei anzeigen

@@ -102,14 +102,17 @@ void SdlApp::Run()
while (!Ticker::Finished())
{
#if defined USE_SDL && defined USE_D3D9
g_d3ddevice->BeginScene();
if (FAILED(g_d3ddevice->BeginScene()))
Abort();
#endif
/* Tick the renderer, show the frame and clamp to desired framerate. */
Ticker::TickDraw();
#if defined USE_SDL
# if defined USE_D3D9
g_d3ddevice->EndScene();
g_d3ddevice->Present(NULL, NULL, NULL, NULL);
if (FAILED(g_d3ddevice->EndScene()))
Abort();
if (FAILED(g_d3ddevice->Present(NULL, NULL, NULL, NULL)))
Abort();
# else
SDL_GL_SwapBuffers();
# endif


+ 1
- 11
src/scene.cpp Datei anzeigen

@@ -18,22 +18,11 @@
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# if defined USE_D3D9
# define FAR
# define NEAR
# include <d3d9.h>
# endif
#endif

#include "core.h"
#include "lolgl.h"

#if defined USE_D3D9
extern IDirect3DDevice9 *g_d3ddevice;
#elif defined _XBOX
extern D3DDevice *g_d3ddevice;
#endif

namespace lol
{

@@ -106,6 +95,7 @@ Scene::~Scene()
for (int i = 0; i < data->nbufs; i++)
delete data->bufs[i];
free(data->bufs);

delete data->m_vdecl;
delete data;
}


+ 3
- 2
src/video.cpp Datei anzeigen

@@ -228,9 +228,10 @@ void Video::Clear()
{
ivec2 size = GetSize();
#if defined USE_D3D9 || defined _XBOX
VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
if (FAILED(VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
| D3DCLEAR_STENCIL,
VideoData::clear_color, 1.0f, 0);
VideoData::clear_color, 1.0f, 0)))
Abort();
#else
glViewport(0, 0, size.x, size.y);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);


+ 1
- 1
test/tutorial/tut01.cpp Datei anzeigen

@@ -86,8 +86,8 @@ public:
}

m_shader->Bind();
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->Bind();
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);
m_vdecl->Unbind();
}


+ 11
- 6
test/tutorial/tut02.cpp Datei anzeigen

@@ -167,9 +167,9 @@ public:
#elif defined _XBOX || defined USE_D3D9
int16_t *indices;
if (FAILED(g_d3ddevice->CreateIndexBuffer(sizeof(m_indices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_ibo, NULL)))
exit(0);
Abort();
if (FAILED(m_ibo->Lock(0, 0, (void **)&indices, 0)))
exit(0);
Abort();
memcpy(indices, m_indices, sizeof(m_indices));
m_ibo->Unlock();
#else
@@ -180,16 +180,21 @@ public:
m_ready = true;
}

Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));

m_shader->Bind();
m_shader->SetUniform(m_mvp, m_matrix);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->SetStream(m_cbo, m_color);
m_vdecl->Bind();

#if defined _XBOX || defined USE_D3D9
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
g_d3ddevice->SetIndices(m_ibo);
g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices));
if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)))
Abort();
if (FAILED(g_d3ddevice->SetIndices(m_ibo)))
Abort();
if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices))))
Abort();
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo);
int size;


+ 1
- 0
win32/lolcore.vcxproj Datei anzeigen

@@ -133,6 +133,7 @@
<ClInclude Include="..\src\debug\record.h" />
<ClInclude Include="..\src\debug\sphere.h" />
<ClInclude Include="..\src\debug\stats.h" />
<ClInclude Include="..\src\debug\debug.h" />
<ClInclude Include="..\src\dict.h" />
<ClInclude Include="..\src\eglapp.h" />
<ClInclude Include="..\src\emitter.h" />


Laden…
Abbrechen
Speichern