Module: dglobal.cpp

class DGlobal
.h

constructorDGlobal()
destructor~DGlobal()
FilterN2Scstring FilterN2S(int n)

Convert OpenGL filter to string

FilterS2Nint FilterS2N(cstring s)

class DPrefs
.h

constructorDPrefs()

Default preferences

destructor~DPrefs()
Resetvoid Reset()

Set default preferences

UseMipMappingbool UseMipMapping()

Returns TRUE if prefs wants to use mipmapping


class DTexturePool
.h

constructorDTexturePool()
destructor~DTexturePool()
Addbool Add(cstring name,DTexture *texture)
FindDTexture *Find(cstring name)

Flat functions
 

ifif(t)cntHits++; else cntMiss++;

qdbg(" hits: %d, misses: %d\n",cntHits,cntMiss);
#endif
return t;
}



/*
 * DGlobal - application-wide structures and settings
 * 10-01-01: Created!
 * NOTES:
 * (C) MarketGraph/RvG
 */

#include <d3/d3.h>
#pragma hdrstop
#include <d3/global.h>
#include <qlib/debug.h>
DEBUG_ENABLE

/*********
* Global *
*********/
DGlobal::DGlobal()
{
  texturePool=new DTexturePool();
}
DGlobal::~DGlobal()
{
  delete texturePool;
}
cstring DGlobal::FilterN2S(int n)
// Convert OpenGL filter to string
{
  switch(n)
  {
    case GL_LINEAR : return "GL_LINEAR";
    case GL_NEAREST: return "GL_NEAREST";
    case GL_LINEAR_MIPMAP_NEAREST : return "GL_LINEAR_MIPMAP_NEAREST";
    case GL_LINEAR_MIPMAP_LINEAR  : return "GL_LINEAR_MIPMAP_LINEAR";
    case GL_NEAREST_MIPMAP_NEAREST: return "GL_NEAREST_MIPMAP_NEAREST";
    case GL_NEAREST_MIPMAP_LINEAR : return "GL_NEAREST_MIPMAP_LINEAR";
    default: qwarn("DGlobal::FilterN2S(%d) unknown",n);
             return "???";
  }
}
int DGlobal::FilterS2N(cstring s)
{
  if(!strcmp(s,"GL_LINEAR"))return GL_LINEAR;
  if(!strcmp(s,"GL_NEAREST"))return GL_NEAREST;
  if(!strcmp(s,"GL_LINEAR_MIPMAP_NEAREST"))return GL_LINEAR_MIPMAP_NEAREST;
  if(!strcmp(s,"GL_LINEAR_MIPMAP_LINEAR"))return GL_LINEAR_MIPMAP_LINEAR;
  if(!strcmp(s,"GL_NEAREST_MIPMAP_NEAREST"))return GL_NEAREST_MIPMAP_NEAREST;
  if(!strcmp(s,"GL_NEAREST_MIPMAP_LINEAR"))return GL_NEAREST_MIPMAP_LINEAR;
  qwarn("DGlobal::FilterS2N(%s) unknown",s);
  return GL_NEAREST;
}

/**************
* Preferences *
**************/
DPrefs::DPrefs()
// Default preferences
{
  Reset();
}
DPrefs::~DPrefs()
{
}

void DPrefs::Reset()
// Set default preferences
{
  minFilter=GL_LINEAR;
  maxFilter=GL_LINEAR;
  wrapS=wrapT=wrapP=wrapQ=DTexture::CLAMP;
  // Default env mode is replace, which means no lighting.
  // To use lighting, use DTexture::MODULATE for example.
  envMode=DTexture::REPLACE;
  flags=0;
}

bool DPrefs::UseMipMapping()
// Returns TRUE if prefs wants to use mipmapping
{
  switch(minFilter)
  {
    case GL_LINEAR_MIPMAP_NEAREST:
    case GL_LINEAR_MIPMAP_LINEAR:
    case GL_NEAREST_MIPMAP_NEAREST:
    case GL_NEAREST_MIPMAP_LINEAR:
      return TRUE;
  }
  return FALSE;
}

/***************
* DTexturePool *
***************/
DTexturePool::DTexturePool()
{
  //map<string,DTexture*> pool;
}
DTexturePool::~DTexturePool()
{
}

bool DTexturePool::Add(cstring name,DTexture *texture)
{
//qdbg("DTexturePool:Add(%s,%p)\n",name,texture);
  pool[(string)name]=texture;
  return TRUE;
}
DTexture *DTexturePool::Find(cstring name)
{
  DTexture *t;
  t=pool[(string)name];
#ifdef OBS
static int cntMiss,cntHits;
qdbg("DTexturePool:Find(%s)=%p\n",name,t);
if(t)cntHits++; else cntMiss++;
qdbg("  hits: %d, misses: %d\n",cntHits,cntMiss);
#endif
  return t;
}