Skip to content

Commit

Permalink
ArxGame: Abort if not enough texture units are available. (fixes bug #…
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Mar 16, 2012
1 parent 978f982 commit 011029e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
35 changes: 26 additions & 9 deletions src/core/ArxGame.cpp
Expand Up @@ -226,8 +226,7 @@ INTERACTIVE_OBJ * CAMERACONTROLLER=NULL;
INTERACTIVE_OBJ *lastCAMERACONTROLLER=NULL;

// ArxGame constructor. Sets attributes for the app.
ArxGame::ArxGame() : wasResized(false) {
}
ArxGame::ArxGame() : wasResized(false) { }

ArxGame::~ArxGame() {
}
Expand Down Expand Up @@ -279,6 +278,7 @@ bool ArxGame::initWindow(RenderWindow * window) {
m_MainWindow = window;

if(!m_MainWindow->initFramework()) {
m_MainWindow = NULL;
return false;
}

Expand Down Expand Up @@ -318,6 +318,12 @@ bool ArxGame::initWindow(RenderWindow * window) {
return false;
}

if(GRenderer == NULL) {
// We could not initialize all resources in onRendererInit().
m_MainWindow = NULL;
return false;
}

if(!m_MainWindow->IsFullScreen() && config.video.resolution != Vec2i::ZERO) {
config.video.resolution = mode.resolution;
}
Expand Down Expand Up @@ -544,7 +550,7 @@ void ArxGame::OnToggleFullscreen(const Window & window) {
void ArxGame::Run() {

BeforeRun();

while(m_RunLoop) {

m_MainWindow->tick();
Expand Down Expand Up @@ -2254,8 +2260,8 @@ void ArxGame::GoFor2DFX()
}


bool ArxGame::InitDeviceObjects()
{
bool ArxGame::InitDeviceObjects() {
// Enable Z-buffering RenderState
GRenderer->SetRenderState(Renderer::DepthTest, true);

Expand Down Expand Up @@ -2288,8 +2294,7 @@ bool ArxGame::InitDeviceObjects()
VertexBuffer<TexturedVertex> * vb = GRenderer->createVertexBufferTL(4000, Renderer::Stream);
pDynamicVertexBuffer_TLVERTEX = new CircularVertexBuffer<TexturedVertex>(vb);

if(pMenu)
{
if(pMenu) {
pMenu->bReInitAll=true;
}

Expand All @@ -2313,17 +2318,30 @@ bool ArxGame::FinalCleanup() {

void ArxGame::onRendererInit(RenderWindow & window) {

arx_assert(GRenderer == NULL);

GRenderer = window.getRenderer();

if(GRenderer->GetTextureStageCount() < 3) {
LogError << "Arx Libertatis needs at least 3 texture units,"
<< " but only " << GRenderer->GetTextureStageCount() << " are available";
GRenderer = NULL;
return;
}

InitDeviceObjects();

// The app is ready to go
m_bReady = true;

}

void ArxGame::onRendererShutdown(RenderWindow &) {

if(GRenderer == NULL) {
// onRendererInit() failed
return;
}

m_bReady = false;

GRenderer->ReleaseAllTextures();
Expand All @@ -2341,5 +2359,4 @@ void ArxGame::onRendererShutdown(RenderWindow &) {
EERIE_PORTAL_ReleaseOnlyVertexBuffer();

GRenderer = NULL;

}
11 changes: 6 additions & 5 deletions src/graphics/d3d9/D3D9Renderer.cpp
Expand Up @@ -236,11 +236,12 @@ void D3D9Renderer::Initialize() {

///////////////////////////////////////////////////////////////////////////
// Texture stages...

m_TextureStages.resize(deviceCaps.MaxTextureBlendStages, 0);
for(size_t i = 0; i < m_TextureStages.size(); ++i)
m_TextureStages[i] = new D3D9TextureStage(i);


m_TextureStages.resize(deviceCaps.MaxTextureBlendStages, NULL);
for(size_t i = 0; i < m_TextureStages.size(); ++i) {
m_TextureStages[i] = new D3D9TextureStage(i);
}

resetStates();

// Clear screen
Expand Down
8 changes: 3 additions & 5 deletions src/graphics/opengl/OpenGLRenderer.cpp
Expand Up @@ -149,12 +149,10 @@ void OpenGLRenderer::reinit() {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);

// number of conventional fixed-function texture units
GLint texunits = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texunits); // number of conventional fixed-function units
if(texunits < 3) {
LogWarning << "Number of available texture units is too low: " << texunits;
}
m_TextureStages.resize(texunits);
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texunits);
m_TextureStages.resize(texunits, NULL);
for(size_t i = 0; i < m_TextureStages.size(); ++i) {
m_TextureStages[i] = new GLTextureStage(this, i);
}
Expand Down

0 comments on commit 011029e

Please sign in to comment.