00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLEXT/GLStateExtension.h>
00022 #include <graph/OptionsDisplay.h>
00023 #include <common/DefinesString.h>
00024 #include <common/Logger.h>
00025 #include <common/Defines.h>
00026
00027 bool GLStateExtension::hasHardwareShadows_ = false;
00028 bool GLStateExtension::hasMultiTex_ = false;
00029 bool GLStateExtension::hasCubeMap_ = false;
00030 bool GLStateExtension::hasSphereMap_ = false;
00031 bool GLStateExtension::hasVBO_ = false;
00032 bool GLStateExtension::hasHardwareMipmaps_ = false;
00033 bool GLStateExtension::envCombine_ = false;
00034 bool GLStateExtension::noTexSubImage_ = false;
00035 bool GLStateExtension::hasBlendColor_ = false;
00036 bool GLStateExtension::hasShaders_ = false;
00037 bool GLStateExtension::hasFBO_ = false;
00038 bool GLStateExtension::hasDrawRangeElements_ = false;
00039 int GLStateExtension::textureUnits_ = 0;
00040 int GLStateExtension::maxElementVertices_ = 0;
00041 int GLStateExtension::maxElementIndices_ = 0;
00042
00043 void GLStateExtension::setup()
00044 {
00045 GLenum err = glewInit();
00046 if (GLEW_OK != err)
00047 {
00048 S3D::dialogExit("GLEW", (const char *) glewGetErrorString(err));
00049 }
00050 Logger::log(S3D::formatStringBuffer("GLEW VERSION:%s", glewGetString(GLEW_VERSION)));
00051
00052 bool vertexRangeExceeded = false;
00053 if (!OptionsDisplay::instance()->getNoGLExt())
00054 {
00055 if (!OptionsDisplay::instance()->getNoGLDrawElements())
00056 {
00057 if (GLEW_EXT_draw_range_elements)
00058 {
00059 GLint maxElementIndices;
00060 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxElementIndices);
00061 maxElementIndices_ = maxElementIndices;
00062
00063 GLint maxElementVertices;
00064 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxElementVertices);
00065 maxElementVertices_ = maxElementVertices;
00066
00067 if (maxElementIndices_ < 16000 ||
00068 maxElementVertices_ < 128000)
00069 {
00070 vertexRangeExceeded = true;
00071 }
00072 else
00073 {
00074 hasDrawRangeElements_ = true;
00075
00076 if (!OptionsDisplay::instance()->getNoVBO())
00077 {
00078 if (GLEW_ARB_vertex_buffer_object)
00079 {
00080 hasVBO_ = true;
00081 }
00082 }
00083 }
00084 }
00085 }
00086
00087 if (!OptionsDisplay::instance()->getNoGLMultiTex())
00088 {
00089 if (GLEW_ARB_multitexture)
00090 {
00091 GLint textureUnits;
00092 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &textureUnits);
00093 textureUnits_ = textureUnits;
00094 hasMultiTex_ = true;
00095 }
00096 }
00097
00098 if (!OptionsDisplay::instance()->getNoGLEnvCombine())
00099 {
00100 envCombine_ = (GLEW_ARB_texture_env_combine == GL_TRUE);
00101 }
00102
00103 if (!OptionsDisplay::instance()->getNoGLCubeMap())
00104 {
00105 hasCubeMap_ = (GLEW_EXT_texture_cube_map == GL_TRUE ||
00106 GLEW_ARB_texture_cube_map == GL_TRUE);
00107 }
00108
00109 if (!OptionsDisplay::instance()->getNoGLSphereMap())
00110 {
00111 hasSphereMap_ = true;
00112 }
00113
00114 if (!OptionsDisplay::instance()->getNoGLHardwareMipmaps())
00115 {
00116 hasHardwareMipmaps_ = GLEW_SGIS_generate_mipmap == GL_TRUE;
00117 }
00118
00119 if (GLEW_EXT_blend_color)
00120 {
00121 hasBlendColor_ = true;
00122 }
00123
00124 {
00125 if (GLEW_EXT_framebuffer_object)
00126 {
00127 hasFBO_ = true;
00128 }
00129 }
00130 if (!OptionsDisplay::instance()->getNoGLShaders())
00131 {
00132 hasShaders_ =
00133 GLEW_ARB_fragment_shader &&
00134 GLEW_ARB_shader_objects &&
00135 GLEW_ARB_vertex_shader &&
00136 (textureUnits_ >=4 );
00137 }
00138 if (!OptionsDisplay::instance()->getNoGLShadows() &&
00139 hasShaders_)
00140 {
00141 if (GLEW_EXT_framebuffer_object &&
00142 GLEW_ARB_shadow &&
00143 GLEW_ARB_depth_texture &&
00144 GLEW_ARB_multitexture)
00145 {
00146 hasHardwareShadows_ = true;
00147 }
00148 }
00149 }
00150
00151 noTexSubImage_ = OptionsDisplay::instance()->getNoGLTexSubImage();
00152
00153 Logger::log(S3D::formatStringBuffer("GL_VENDOR:%s", glGetString(GL_VENDOR)));
00154 Logger::log(S3D::formatStringBuffer("GL_RENDERER:%s", glGetString(GL_RENDERER)));
00155 Logger::log(S3D::formatStringBuffer("GL_VERSION:%s", glGetString(GL_VERSION)));
00156 Logger::log(S3D::formatStringBuffer("GL_EXTENSIONS:%s", glGetString(GL_EXTENSIONS)));
00157 Logger::log(S3D::formatStringBuffer("TEXTURE UNITS: %s (%i units)",
00158 (hasMultiTex()?"On":"Off"),textureUnits_));
00159 Logger::log(S3D::formatStringBuffer("VERTEX BUFFER OBJECT:%s",
00160 (hasVBO()?"On":"Off")));
00161 Logger::log(S3D::formatStringBuffer("DRAW RANGE ELEMENTS:%s%s",
00162 (hasDrawRangeElements()?"On":"Off"),
00163 (vertexRangeExceeded?" (DISABLED DUE TO MAX_ELEMENTS)":"")));
00164 Logger::log(S3D::formatStringBuffer("GL_MAX_ELEMENTS_VERTICES:%i",
00165 getMaxElementVertices()));
00166 Logger::log(S3D::formatStringBuffer("GL_MAX_ELEMENTS_INDICES:%i",
00167 getMaxElementIndices()));
00168 Logger::log(S3D::formatStringBuffer("FRAME BUFFER OBJECT:%s",
00169 (hasFBO()?"On":"Off")));
00170 Logger::log(S3D::formatStringBuffer("SHADERS:%s",
00171 (!hasShaders_?"Off":"On")));
00172 Logger::log(S3D::formatStringBuffer("ENV COMBINE:%s",
00173 (envCombine_?"On":"Off")));
00174 Logger::log(S3D::formatStringBuffer("CUBE MAP:%s",
00175 (hasCubeMap_?"On":"Off")));
00176 Logger::log(S3D::formatStringBuffer("HW MIP MAPS:%s",
00177 (hasHardwareMipmaps_?"On":"Off")));
00178 Logger::log(S3D::formatStringBuffer("HW SHADOWS:%s",
00179 (hasHardwareShadows_?"On":"Off")));
00180 Logger::log(S3D::formatStringBuffer("BLEND COLOR:%s",
00181 (hasBlendColor_?"On":"Off")));
00182 }