linefix stomped everything :P

This was SVN commit r266.
This commit is contained in:
janwas 2004-05-25 23:16:21 +00:00
parent 2bb064e8d8
commit 6c608edd60
9 changed files with 142 additions and 148 deletions

View File

@ -25,14 +25,17 @@
#include "lib.h"
#include "detect.h"
#include "timer.h"
#ifdef _M_IX86
# include "sysdep/ia32.h"
extern void ia32_get_cpu_info();
#endif
extern int win_get_gfx_card();
extern int win_get_gfx_drv();
#ifdef _WIN32
extern int win_get_gfx_info();
extern int win_get_cpu_info();
#endif
extern "C" int ogl_get_gfx_info();
//
// memory
@ -72,18 +75,30 @@ void get_mem_status()
// graphics card
//
char gfx_card[64] = "unknown";
char gfx_drv[128] = "unknown";
char gfx_card[64] = "";
char gfx_drv_ver[64] = "";
// attempt to detect graphics card without OpenGL (in case ogl init fails,
// or we want more detailed info). gfx_card[] is unchanged on failure.
void get_gfx_info()
{
int ret = -1;
// try platform-specific versions first: they return more
// detailed information, and don't require OpenGL to be ready.
#ifdef _WIN32
win_get_gfx_card();
win_get_gfx_drv();
ret = win_get_gfx_info();
#endif
// success; done.
if(ret == 0)
return;
// the OpenGL version should always work, unless OpenGL isn't ready for use,
// or we were called between glBegin and glEnd.
ogl_get_gfx_info();
}
@ -91,7 +106,7 @@ void get_gfx_info()
// CPU
//
char cpu_type[64] = "unknown"; // processor brand string is 48 chars
char cpu_type[64] = ""; // processor brand string is 48 chars
double cpu_freq = 0.f;
// -1 if detect not yet called, or cannot be determined

View File

@ -36,8 +36,8 @@ extern int get_monitor_size(int& width_mm, int& height_mm);
extern char gfx_card[64]; // default: "unknown"
extern char gfx_drv[128]; // default: "unknown"
extern char gfx_card[64]; // default: ""
extern char gfx_drv_ver[64]; // default: ""
// attempt to detect graphics card without OpenGL (in case ogl init fails,
// or we want more detailed info). gfx_card[] is unchanged on failure.

View File

@ -211,6 +211,22 @@ long round(double x)
return (long)(x + 0.5);
}
// input in [0, 1); convert to u8 range
u8 fp_to_u8(double in)
{
if(!(0 <= in && in < 1.0))
{
debug_warn("clampf not in [0,1)");
return 255;
}
int l = round(in * 255.0);
assert((unsigned int)l <= 255);
return (u8)l;
}
// input in [0, 1); convert to u16 range
u16 fp_to_u16(double in)
{

View File

@ -1,5 +1,6 @@
#include "precompiled.h"
#include "lib.h"
#include "sdl.h"
#include "ogl.h"
#include "detect.h"
@ -77,10 +78,46 @@ bool tex_compression_avail; // S3TC / DXT{1,3,5}
int video_mem; // [MB]; approximate
// gfx_card and gfx_drv_ver are unchanged on failure.
int ogl_get_gfx_info()
{
const char* vendor = (const char*)glGetString(GL_VENDOR);
const char* renderer = (const char*)glGetString(GL_RENDERER);
const char* version = (const char*)glGetString(GL_VERSION);
// can fail if OpenGL not yet initialized,
// or if called between glBegin and glEnd.
if(!vendor || !renderer || !version)
return -1;
strncpy(gfx_card, vendor, sizeof(gfx_card)-1);
// reduce string to "ATI" or "NVIDIA"
if(!strcmp(gfx_card, "ATI Technologies Inc."))
gfx_card[3] = 0;
if(!strcmp(gfx_card, "NVIDIA Corporation"))
gfx_card[6] = 0;
strcat(gfx_card, renderer);
// don't bother cutting off the crap at the end.
// too risky, and too many different strings.
snprintf(gfx_drv_ver, sizeof(gfx_drv_ver), "OpenGL %s", version);
// add "OpenGL" to differentiate this from the real driver version
// (returned by platform-specific detect routines).
return 0;
}
// call after each video mode change
void oglInit()
{
exts = (const char*)glGetString(GL_EXTENSIONS);
if(!exts)
{
debug_warn("oglInit called before OpenGL is ready for use");
}
// import functions
#define FUNC(ret, name, params) *(void**)&name = SDL_GL_GetProcAddress(#name);
@ -100,23 +137,4 @@ void oglInit()
video_mem = (SDL_GetVideoInfo()->video_mem) / 1048576; // [MB]
// TODO: add sizeof(FB)?
// get graphics card name
// .. don't overwrite if e.g. get_gfx_card already called
if(!strcmp(gfx_card, "Unknown"))
{
char* v = (char*)glGetString(GL_VENDOR);
if(v)
strncpy(gfx_card, v, sizeof(gfx_card));
// reduce string to "ATI" or "NVIDIA"
if(!strcmp(gfx_card, "ATI Technologies Inc."))
gfx_card[3] = 0;
if(!strcmp(gfx_card, "NVIDIA Corporation"))
gfx_card[6] = 0;
char* r = (char*)glGetString(GL_RENDERER);
if(r)
strcat(gfx_card, r);
}
}

View File

@ -92,9 +92,18 @@ extern bool oglExtAvail(const char* ext);
// print all OpenGL errors
extern void oglPrintErrors();
// call before using any of the above, and after each mode change
// call before using any of the above, and after each mode change.
//
// fails if OpenGL not ready for use.
extern void oglInit();
// set detect.cpp gfx_card[] and gfx_drv_ver[].
// (called by detect.cpp get_gfx_info()).
//
// fails if OpenGL not ready for use.
// gfx_card and gfx_drv_ver are unchanged on failure.
extern int ogl_get_gfx_info();
#ifdef __cplusplus
}

View File

@ -144,8 +144,21 @@ static int Font_reload(Font* f, const char* fn)
int pos; // current position in the file
const char* p = (const char*)file;
// font texture filename: need to prepend the path to the font definition
// file, because the texture is opened separately and the two are usually
// not in a root dir.
char tex_path[PATH_MAX];
strncpy(tex_path, fn, sizeof(tex_path));
char* slash = strrchr(tex_path, '/');
char* tex_filename;
// .. they are in a mount point, no path
if(!slash)
tex_filename = tex_path;
// .. overwrite font definition filename
else
tex_filename = slash+1;
// read header
char tex_filename[PATH_MAX];
int x_stride, y_stride; // glyph spacing in texture
if(sscanf(p, "%s\n%d %d\n%n", tex_filename, &x_stride, &y_stride, &pos) != 3)
{
@ -153,6 +166,7 @@ static int Font_reload(Font* f, const char* fn)
return -1;
}
// read glyph widths
int adv[128];
for(int i = 32; i < 128; i++)
@ -168,7 +182,7 @@ static int Font_reload(Font* f, const char* fn)
mem_free(file);
// load glyph texture
const Handle ht = tex_load(tex_filename);
const Handle ht = tex_load(tex_path);
if(ht <= 0)
return (int)ht;
tex_upload(ht);

View File

@ -29,8 +29,6 @@
// powrprof is loaded manually - we only need 1 function.
#endif
#include "Tlhelp32.h"
// EnumDisplayDevices is not available on Win95 or NT.
// try to import it manually here; return -1 if not available.
@ -83,8 +81,11 @@ int get_monitor_size(int& width_mm, int& height_mm)
}
int win_get_gfx_card()
static int win_get_gfx_card()
{
if(gfx_card[0] != '\0')
return -1;
// make sure EnumDisplayDevices is available (as pEnumDisplayDevicesA)
if(import_EnumDisplayDevices() < 0)
return -1;
@ -98,13 +99,15 @@ int win_get_gfx_card()
}
/*
get ogl client DLL name
enum loaded dlls
ogl must be running; ambiguous (need to eliminate MCD and opengl32.dll)
*/
// no .dll appended
// get the name of the OpenGL driver DLL (used to determine driver version).
//
// the current implementation doens't
// doesn't require OpenGL to be initialized, but
//
// an alternative would be to enumerate all DLLs loaded into the process,
// and check for a glBegin export. this requires OpenGL to be initialized,
// though - the DLLs aren't loaded at startup. it'd also be a bit of work
// to sort out MCD, ICD, and opengl32.dll.
static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len)
{
int ret = -1;
@ -121,9 +124,16 @@ static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len)
HKEY hkClass;
if(RegOpenKeyEx(hkOglDrivers, key_name, 0, KEY_QUERY_VALUE, &hkClass) == 0)
{
DWORD size = (DWORD)max_name_len;
DWORD size = (DWORD)max_name_len-5; // -5 for ".dll"
if(RegQueryValueEx(hkClass, "Dll", 0, 0, (LPBYTE)ogl_drv_name, &size) == 0)
{
// add .dll to filename, if necessary
char* ext = strrchr(ogl_drv_name, '.');
if(!ext || stricmp(ext, ".dll") != 0)
strcat(ogl_drv_name, ".dll");
ret = 0; // success
}
RegCloseKey(hkClass);
}
@ -137,11 +147,14 @@ static int get_ogl_drv_name(char* const ogl_drv_name, const size_t max_name_len)
// split out so we can return on failure, instead of goto
// method: http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/009679.html
int win_get_gfx_drv()
int win_get_gfx_drv_ver()
{
if(gfx_drv_ver[0] != '\0')
return -1;
/* want ogl icd, instead of 2d driver */
// note: getting the 2d driver name can be done with EnumDisplaySettings,
// but we want the actual OpenGL driver. see discussion linked above;
// the summary is, 2d driver version may differ from the OpenGL driver.
char ogl_drv_name[MAX_PATH];
CHECK_ERR(get_ogl_drv_name(ogl_drv_name, sizeof(ogl_drv_name)));
@ -171,7 +184,7 @@ int win_get_gfx_drv()
uint ver_len;
if(VerQueryValue(buf, subblock, (void**)&ver, &ver_len))
{
strncpy(gfx_drv, ver, sizeof(gfx_drv)-1);
strncpy(gfx_drv_ver, ver, sizeof(gfx_drv_ver)-1);
ret = 0; // success
}
}
@ -181,6 +194,13 @@ int win_get_gfx_drv()
return ret;
}
int win_get_gfx_info()
{
win_get_gfx_card();
win_get_gfx_drv_ver();
return 0;
}
int win_get_cpu_info()
{

View File

@ -94,7 +94,7 @@ static int write_sys_info()
fprintf(f, "%lu MB RAM; %lu MB free\n", tot_mem/MB, avl_mem/MB);
// .. graphics card
fprintf(f, "%s\n", gfx_card);
fprintf(f, "%s\n", gfx_drv);
fprintf(f, "%s\n", gfx_drv_ver);
// .. network name / ips
char hostname[100]; // possibly nodename != hostname
gethostname(hostname, sizeof(hostname));
@ -480,7 +480,7 @@ if(argc < 2)
#endif
font = font_load("verdana.fnt");
font = font_load("fonts/verdana.fnt");
// set renderer options from command line options - NOVBO must be set before opening the renderer
g_Renderer.SetOption(CRenderer::OPT_NOVBO,g_NoGLVBO);

View File

@ -155,105 +155,7 @@ bool terr_handler(const SDL_Event& ev)
g_Camera.m_Orientation.RotateY(DEGTORAD(-45));
g_Camera.m_Orientation.Translate (100, 150, -100);
break;
/* case 'L':
g_HillShading = !g_HillShading;
break;
// tile selection
case SDLK_DOWN:
if(++SelTX > 15)
if(SelPX == g_Terrain.GetPatchesPerSide()-1)
SelTX = 15;
else
SelTX = 0, SelPX++;
break;
case SDLK_UP:
if(--SelTX < 0)
if(SelPX == 0)
SelTX = 0;
else
SelTX = 15, SelPX--;
break;
case SDLK_RIGHT:
if(++SelTY > 15)
if(SelPY == g_Terrain.GetPatchesPerSide()-1)
SelTY = 15;
else
SelTY = 0, SelPY++;
break;
case SDLK_LEFT:
if(--SelTY < 0)
if(SelPY == 0)
SelTY = 0;
else
SelTY = 15, SelPY--;
break;
case SDLK_KP0:
{
CMiniPatch *MPatch = &g_Terrain.GetPatch(SelPY, SelPX)->m_MiniPatches[SelTY][SelTX];
/*if (!MPatch->Tex2)
{
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
}
else
{
MPatch->Tex2 = 0;
MPatch->m_AlphaMap = 0;
}*/
break;
}
/*case SDLK_KP1:
{
CMiniPatch *MPatch = &g_Terrain.GetPatch(SelPY, SelPX)->m_MiniPatches[SelTY][SelTX];
g_BaseTexCounter++;
if (g_BaseTexCounter > 4)
g_BaseTexCounter = 0;
MPatch->Tex1 = BaseTexs[g_BaseTexCounter];
break;
}
case SDLK_KP2:
{
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
if (MPatch->Tex2)
{
g_SecTexCounter++;
if (g_SecTexCounter > 4)
g_SecTexCounter = 0;
MPatch->Tex2 = BaseTexs[g_SecTexCounter];
}
break;
}
case SDLK_KP3:
{
CMiniPatch *MPatch = &g_Terrain.m_Patches[SelPY][SelPX].m_MiniPatches[SelTY][SelTX];
if (MPatch->m_AlphaMap)
{
g_TransTexCounter++;
if (g_TransTexCounter >= NUM_ALPHA_MAPS)
g_TransTexCounter = 0;
MPatch->m_AlphaMap = AlphaMaps[g_TransTexCounter];
}
break;
}*/
//}
}
return false;