1
0
forked from 0ad/0ad

sysdep: add restrict keyword (placebo if not supported)

gfx: extern "C"-ed
wtime, util, win, wdbg_sym: minor / commenting only
wdetect: don't skip gfx_card detect if buffer already filled
glext_funcs: remove obsolete defs

detect: call both OpenGL and platform-specific gfx_card detect; cleanup
vendor name to remove copyright/Inc crap

ogl: remove some variables that don't belong. moved vendor cleanup to
detect. moved S3TC emu code to ogl_tex

This was SVN commit r2905.
This commit is contained in:
janwas 2005-10-12 04:22:44 +00:00
parent 990e343ae6
commit ece006f43e
11 changed files with 59 additions and 157 deletions

View File

@ -92,26 +92,30 @@ int gfx_mem = -1; // [MiB]; approximate
// or we want more detailed info). gfx_card[] is unchanged on failure.
void get_gfx_info()
{
int ret = -1;
// TODO: add sizeof(FB)?
gfx_mem = (SDL_GetVideoInfo()->video_mem) / 1048576; // [MiB]
// TODO: add sizeof(FB)?
// try platform-specific versions first: they return more
// try platform-specific version: they return more
// detailed information, and don't require OpenGL to be ready.
#if OS_WIN
ret = win_get_gfx_info();
if(win_get_gfx_info() < 0)
#endif
{
// 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();
}
// 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();
// remove crap from vendor names. (don't dare touch the model name -
// it's too risky, there are too many different strings)
#define SHORTEN(what, chars_to_keep)\
if(!strncmp(gfx_card, what, ARRAY_SIZE(what)-1))\
memmove(gfx_card+chars_to_keep, gfx_card+ARRAY_SIZE(what)-1, strlen(gfx_card)-(ARRAY_SIZE(what)-1)+1);
SHORTEN("ATI Technologies Inc.", 3);
SHORTEN("NVIDIA Corporation", 6);
SHORTEN("S3 Graphics", 2); // EnumDisplayDevices
SHORTEN("S3 Graphics, Incorporated", 2); // GL_VENDOR
#undef SHORTEN
}
@ -148,9 +152,6 @@ void cpu_init()
ia32_init();
#endif
// If you ever want to catch a particular allocation:
//_CrtSetBreakAlloc(187);
// no longer set 24 bit (float) precision by default: for
// very long game uptimes (> 1 day; e.g. dedicated server),
// we need full precision when calculating the time.

View File

@ -2,11 +2,6 @@
#if OS_WIN
# include <GL/wglext.h>
#endif
/*
typedef void* HDC;
typedef void* HGLRC;
typedef void* HPBUFFERARB;
*/
/*

View File

@ -234,6 +234,9 @@ const char* oglHaveExtensions(int dummy, ...)
static void importExtensionFunctions()
{
// It should be safe to load the ARB function pointers even if the
// extension isn't advertised, since we won't actually use them without
// checking for the extension.
#define FUNC(ret, name, params) *(void**)&name = SDL_GL_GetProcAddress(#name);
#define FUNC2(ret, nameARB, nameCore, version, params) \
nameARB = NULL; \
@ -244,9 +247,6 @@ static void importExtensionFunctions()
#include "glext_funcs.h"
#undef FUNC2
#undef FUNC
// It should be safe to load the ARB function pointers even if the
// extension isn't advertised, since we won't actually use them without
// checking for the extension.
}
@ -329,8 +329,6 @@ void oglSquelchError(GLenum err_to_ignore)
int ogl_max_tex_size = -1; // [pixels]
int ogl_max_tex_units = -1; // limit on GL_TEXTUREn
int ogl_max_VAR_elements = -1; // GF2: 64K; GF3: 1M
int ogl_tex_compression_supported = -1; // S3TC / DXT{1,3,5}
// gfx_card and gfx_drv_ver are unchanged on failure.
@ -339,64 +337,20 @@ 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;
strcpy_s(gfx_card, sizeof(gfx_card), vendor);
// 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_s(gfx_card, sizeof(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).
snprintf(gfx_card, ARRAY_SIZE(gfx_card), "%s %s", vendor, renderer);
// add "OpenGL" to differentiate this from the real driver version
// (returned by platform-specific detect routines).
snprintf(gfx_drv_ver, ARRAY_SIZE(gfx_drv_ver), "OpenGL %s", version);
return 0;
}
static void CALL_CONV emulate_glCompressedTexImage2D(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid*);
static void detectFeatures()
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &ogl_max_tex_size);
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ogl_max_tex_units);
// make sure value remains -1 if not supported
if(oglHaveExtension("GL_NV_vertex_array_range"))
glGetIntegerv(GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV, &ogl_max_VAR_elements);
ogl_tex_compression_supported = oglHaveExtensions(0, "GL_ARB_texture_compression", "GL_EXT_texture_compression_s3tc", 0) == 0;
// TODO: GL_S3_s3tc? It uses different enumerants (GL_RGB_S3TC etc), so the
// texture loading code would need to be changed; and it is not clear whether
// it supports the full range of DXT1/3/5. (There seems to be no specification;
// and many header files don't have GL_RGBA_DXT5_S3TC, suggesting that the
// drivers don't all support that.)
if(!ogl_tex_compression_supported)
{
// If there's no hardware support for compressed textures, do the
// decompression in software (but first let the user know it's probably not
// going to be very fast).
DISPLAY_ERROR(L"Performance warning: your graphics card does not support compressed textures. The game will try to continue anyway, but may be slower than expected. Please try updating your graphics drivers; if that doesn't help, please try upgrading your hardware.");
// TODO: i18n
glCompressedTexImage2DARB = emulate_glCompressedTexImage2D;
// Leave ogl_tex_compression_supported == 0, so that it indicates the presence
// of hardware-supported texture compression.
}
}
// call after each video mode change, since thereafter extension functions
// may have changed [address].
void oglInit()
@ -406,9 +360,7 @@ void oglInit()
// time-critical) than centralizing the 'OpenGL is ready' check.
exts = (const char*)glGetString(GL_EXTENSIONS);
if(!exts)
{
debug_warn("oglInit called before OpenGL is ready for use");
}
have_12 = oglHaveVersion("1.2");
have_13 = oglHaveVersion("1.3");
have_14 = oglHaveVersion("1.4");
@ -416,64 +368,6 @@ void oglInit()
importExtensionFunctions();
detectFeatures();
}
uint ogl_dxt_from_fmt(GLenum fmt)
{
switch(fmt)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
return 1;
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
return DXT1A;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
return 3;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
return 5;
default:
return 0;
}
}
// Software emulation of compressed-texture support, for really old
// cards/drivers that can't do it (but which do support everything else
// we strictly require). They probably don't have enough VRAM for all the
// textures, and are slow anyway, so it's not going to be a pleasant way
// of playing; but at least it's better than nothing.
static void CALL_CONV emulate_glCompressedTexImage2D(
GLenum target_, GLint level_, GLenum int_fmt,
GLsizei w, GLsizei h, GLint border,
GLsizei data_size, const GLvoid* data)
{
debug_assert(border == 0); // not supported by glCompressedTexImage2D
// S3TC format info
const uint dxt = ogl_dxt_from_fmt(int_fmt);
debug_assert(dxt != 0 && "invalid internal format");
const uint s3tc_bpp = (dxt == 3 || dxt == 5)? 8 : 4;
const size_t s3tc_size = round_up(w,4)*round_up(h,4)*s3tc_bpp/8;
debug_assert(s3tc_size == (size_t)data_size);
// decompress DDS to RGB[A]
Tex t;
const uint flags = dxt;
(void)tex_wrap((uint)w, (uint)h, s3tc_bpp, flags, (void*)data, &t);
(void)tex_transform_to(&t, flags & ~TEX_DXT);
// uncompressed RGB[A] format info
u8* const uc_data = tex_get_data(&t);
GLenum uc_fmt = GL_RGB;
GLint uc_int_fmt = GL_RGB8;
if(dxt != 1)
{
uc_fmt = GL_RGBA;
uc_int_fmt = GL_RGBA8;
}
glTexImage2D(target_, level_, uc_int_fmt, w, h, 0, uc_fmt, GL_UNSIGNED_BYTE, uc_data);
(void)tex_free(&t);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &ogl_max_tex_size);
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ogl_max_tex_units);
}

View File

@ -14,7 +14,7 @@ extern "C" {
// bring in the platform's OpenGL headers (with fixes, if necessary)
//
#ifdef __APPLE__
#if OS_MACOSX || OS_MAC
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
#else
@ -31,18 +31,20 @@ extern "C" {
#define REAL_GL_1_3
#endif
// this must come after GL/gl.h include, so we can't combine the
// including GL/glext.h.
#undef GL_GLEXT_PROTOTYPES
#ifdef __APPLE__
#if OS_MACOSX || OS_MAC
# include <OpenGL/glext.h>
#else
# include <GL/glext.h>
# if OS_WIN
# include <GL/wglext.h>
# define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
# endif
#endif
#define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
//
// extensions
@ -89,13 +91,11 @@ extern const char* oglExtList(void);
//
// limit / feature detect
// implementation limits / feature detect
//
extern int ogl_max_tex_size; // [pixels]
extern int ogl_max_tex_units; // limit on GL_TEXTUREn
extern int ogl_max_VAR_elements; // GF2: 64K; GF3: 1M
extern int ogl_tex_compression_supported; // S3TC / DXT{1,3,5}
// set detect.cpp gfx_card[] and gfx_drv_ver[].
// (called by detect.cpp get_gfx_info()).
@ -136,9 +136,6 @@ extern void oglSquelchError(GLenum err_to_ignore);
extern void oglInit(void);
// internal use only:
extern uint ogl_dxt_from_fmt(GLenum fmt);
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,9 @@
#ifndef GFX_H__
#define GFX_H__
#ifdef __cplusplus
extern "C" {
#endif
// useful for choosing a video mode.
// if we fail, outputs are unchanged (assumed initialized to defaults)
@ -22,4 +25,8 @@ extern int gfx_mem; // [MiB]; approximate
// or we want more detailed info). gfx_card[] is unchanged on failure.
extern void get_gfx_info(void);
#ifdef __cplusplus
}
#endif
#endif // #ifndef GFX_H__

View File

@ -46,6 +46,15 @@ extern void* alloca(size_t size);
# define finite __finite
#endif
// restrict
#if HAVE_C99
// .. already available
#else
// .. unsupported
# define restrict
#endif
//
// output

View File

@ -130,6 +130,7 @@ static WORD machine;
static int sym_init()
{
// bail if already initialized (there's nothing to do).
// don't use pthread_once because we need to return success/error code.
static uintptr_t already_initialized = 0;
if(!CAS(&already_initialized, 0, 1))
return 0;

View File

@ -259,9 +259,6 @@ static int dll_list_add(const char* name)
static int win_get_gfx_card()
{
if(gfx_card[0] != '\0')
return -1;
// make sure EnumDisplayDevices is available (as pEnumDisplayDevicesA)
if(import_EnumDisplayDevices() >= 0)
{

View File

@ -336,6 +336,8 @@ static int CALLBACK error_dialog_proc(HWND hDlg, unsigned int msg, WPARAM wParam
{
case IDC_COPY:
{
// (allocating on the stack would be easier+safer, but this is
// too big.)
const size_t max_chars = 128*KiB;
wchar_t* buf = (wchar_t*)malloc(max_chars*sizeof(wchar_t));
if(buf)
@ -499,7 +501,7 @@ wchar_t* clipboard_get()
if(text)
{
SIZE_T size = GlobalSize(hMem);
wchar_t* copy = (wchar_t*)malloc(size);
wchar_t* copy = (wchar_t*)malloc(size); // unavoidable
if(copy)
{
wcscpy(copy, text);

View File

@ -242,7 +242,7 @@ static int choose_impl()
{
// compare QPC freq to CPU clock freq - can't rule out HPET,
// because its frequency isn't known (it's at least 10 MHz).
double freq_dist = fabs(cpu_freq / qpc_freq - 1.0);
double freq_dist = fabs(cpu_freq/qpc_freq - 1.0);
safe = freq_dist > 0.05;
// safe if freqs not within 5% (i.e. it doesn't use TSC)
}
@ -528,9 +528,9 @@ static void calibrate_lk()
typedef RingBuf<double, 8> SampleBuf;
static SampleBuf samples;
if(fabs(hrt_est_freq / hrt_nominal_freq - 1.0) < 0.10)
// only add to buffer if within 10% of nominal
// (don't want to pollute buffer with flukes / incorrect results)
// only add to buffer if within 10% of nominal
// (don't want to pollute buffer with flukes / incorrect results)
if(fabs(hrt_est_freq/hrt_nominal_freq - 1.0) < 0.10)
{
samples.push_back(hrt_est_freq);

View File

@ -36,8 +36,7 @@ void WriteSystemInfo()
{
TIMER(write_sys_info);
get_gfx_info();
// get_cpu_info already called during init - see call site
// get_cpu_info and get_gfx_info already called during init - see call site
get_snd_info();
get_mem_status();