TORCS  1.3.9
The Open Racing Car Simulator
glfeatures.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : glfeatures.cpp
4  created : Wed Jun 1 14:56:31 CET 2005
5  copyright : (C) 2005 by Bernhard Wymann
6  version : $Id$
7 
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 /*
21  Functions to check if features seems to be available and requested by the
22  user. The isAvailable functions should return if a feature is working on
23  the system, the isEnabled feature should check if the user wants to enable
24  it as well.
25  It should NOT check if the features are really working, that is subject
26  to another part eventually.
27 */
28 
29 #include <glfeatures.h>
30 #include <portability.h>
31 
32 /*
33  ----------------------- Texture Compression
34 */
35 
36 
38 static bool compressARBEnabled;
39 
40 // Feature checks, GL_ARB_texture_compression.
41 void checkCompressARBAvailable(bool &result)
42 {
43  // Query if the extension is avaiable at the runtime system (true, if > 0).
44  int compressARB = GfuiGlutExtensionSupported("GL_ARB_texture_compression");
45  // Check if at least one internal format is vailable. This is a workaround for
46  // driver problems and not a bugfix. According to the specification OpenGL should
47  // choose an uncompressed alternate format if it can't provide the requested
48  // compressed one... but it does not on all cards/drivers.
49  if (compressARB) {
50  int numformats;
51  glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &numformats);
52  if (numformats == 0) {
53  compressARB = 0;
54  }
55  }
56 
57  result = (compressARB > 0) ? true : false;
58 }
59 
60 
61 void checkCompressARBEnabled(bool &result)
62 {
63  if (!isCompressARBAvailable()) {
64  // Feature not available, do not use it.
65  result = false;
66  } else {
67  // Feature available, check if the user wants to use it.
68  // TODO: put this enabled/disable stuff in one function (it is used in grsound.cpp as well).
69  const char *tcEnabledStr = GR_ATT_TEXTURECOMPRESSION_ENABLED;
70  const int BUFSIZE = 1024;
71  char fnbuf[BUFSIZE];
72  snprintf(fnbuf, BUFSIZE, "%s%s", GetLocalDir(), GR_PARAM_FILE);
73  void *paramHandle = GfParmReadFile(fnbuf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
75 
76  if (strcmp(optionName, tcEnabledStr) != 0) {
77  result = false;
78  } else {
79  result = true;
80  }
81  GfParmReleaseHandle(paramHandle);
82  }
83 }
84 
85 
87 {
89 }
90 
91 
92 // GL_ARB_texture_compression
94 {
95  return compressARBAvailable;
96 }
97 
98 
100  return compressARBEnabled;
101 }
102 
103 
104 /*
105  ----------------------- Texture downsizing.
106 */
107 static int glTextureMaxSize;
109 
110 
111 void getGLTextureMaxSize(int &result)
112 {
113  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &result);
114  if (result > 16384) {
115  result = 16384;
116  }
117 }
118 
119 
120 void getUserTextureMaxSize(int &result)
121 {
122  const int BUFSIZE = 1024;
123  char fnbuf[BUFSIZE];
124  snprintf(fnbuf, BUFSIZE, "%s%s", GetLocalDir(), GR_PARAM_FILE);
125  void *paramHandle = GfParmReadFile(fnbuf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
126  result = (int) GfParmGetNum(paramHandle, GR_SCT_GLFEATURES, GR_ATT_TEXTURESIZE, (char*)NULL, (tdble) glTextureMaxSize);
127  if (result > glTextureMaxSize) {
128  result = glTextureMaxSize;
129  }
130  GfParmReleaseHandle(paramHandle);
131 }
132 
133 
135 {
137 }
138 
140 {
141  return glTextureMaxSize;
142 }
143 
144 
146 {
147  return userTextureMaxSize;
148 }
149 
150 
151 // Initialize
152 void checkGLFeatures(void) {
157 }
158 
159 
160 
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
Definition: params.cpp:1157
void getUserTextureMaxSize(int &result)
Definition: glfeatures.cpp:120
char * GetLocalDir(void)
Definition: tgf.cpp:231
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
Definition: params.cpp:1834
static bool compressARBEnabled
Definition: glfeatures.cpp:38
void checkGLFeatures(void)
Definition: glfeatures.cpp:152
void getGLTextureMaxSize(int &result)
Definition: glfeatures.cpp:111
#define GR_ATT_TEXTURECOMPRESSION
Definition: graphic.h:53
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
Definition: params.cpp:2311
bool isCompressARBAvailable(void)
Definition: glfeatures.cpp:93
#define GR_ATT_TEXTURECOMPRESSION_DISABLED
Definition: graphic.h:55
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
static int glTextureMaxSize
Definition: glfeatures.cpp:107
#define GFPARM_RMODE_REREAD
reread the parameters from file and release the previous ones
Definition: tgf.h:266
void checkCompressARBAvailable(bool &result)
Definition: glfeatures.cpp:41
void updateUserTextureMaxSize(void)
Definition: glfeatures.cpp:134
void updateCompressARBEnabled(void)
Definition: glfeatures.cpp:86
#define GR_PARAM_FILE
Definition: graphic.h:42
#define GR_ATT_TEXTURESIZE
Definition: graphic.h:61
bool isCompressARBEnabled(void)
Definition: glfeatures.cpp:99
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
Definition: params.cpp:2392
#define GR_SCT_GLFEATURES
Definition: graphic.h:52
static int userTextureMaxSize
Definition: glfeatures.cpp:108
int GfuiGlutExtensionSupported(const char *str)
Definition: screen.cpp:944
#define GFPARM_RMODE_CREAT
Create the file if doesn&#39;t exist.
Definition: tgf.h:267
#define GR_ATT_TEXTURECOMPRESSION_ENABLED
Definition: graphic.h:54
static bool compressARBAvailable
Definition: glfeatures.cpp:37
void checkCompressARBEnabled(bool &result)
Definition: glfeatures.cpp:61