COpenGLExtensionHandler.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "IrrCompileConfig.h"
  5. #ifdef _IRR_COMPILE_WITH_OPENGL_
  6. #include "COpenGLExtensionHandler.h"
  7. #include "irrString.h"
  8. #include "SMaterial.h" // for MATERIAL_MAX_TEXTURES
  9. #include "fast_atof.h"
  10. namespace irr
  11. {
  12. namespace video
  13. {
  14. extern bool useCoreContext;
  15. COpenGLExtensionHandler::COpenGLExtensionHandler() :
  16. StencilBuffer(false), MultiTextureExtension(false),
  17. TextureCompressionExtension(false),
  18. MaxSupportedTextures(1), MaxTextureUnits(1), MaxLights(1),
  19. MaxAnisotropy(1), MaxUserClipPlanes(0), MaxAuxBuffers(0),
  20. MaxMultipleRenderTargets(1), MaxIndices(65535),
  21. MaxTextureSize(1), MaxGeometryVerticesOut(0),
  22. MaxTextureLODBias(0.f), Version(0), ShaderLanguageVersion(0),
  23. OcclusionQuerySupport(false)
  24. #ifdef _IRR_OPENGL_USE_EXTPOINTER_
  25. ,pGlActiveTextureARB(0), pGlClientActiveTextureARB(0),
  26. pGlGenProgramsARB(0), pGlGenProgramsNV(0),
  27. pGlBindProgramARB(0), pGlBindProgramNV(0),
  28. pGlDeleteProgramsARB(0), pGlDeleteProgramsNV(0),
  29. pGlProgramStringARB(0), pGlLoadProgramNV(0),
  30. pGlProgramLocalParameter4fvARB(0),
  31. pGlCreateShaderObjectARB(0), pGlShaderSourceARB(0),
  32. pGlCompileShaderARB(0), pGlCreateProgramObjectARB(0), pGlAttachObjectARB(0),
  33. pGlLinkProgramARB(0), pGlUseProgramObjectARB(0), pGlDeleteObjectARB(0),
  34. pGlCreateProgram(0), pGlUseProgram(0),
  35. pGlDeleteProgram(0), pGlDeleteShader(0),
  36. pGlGetAttachedObjectsARB(0), pGlGetAttachedShaders(0),
  37. pGlCreateShader(0), pGlShaderSource(0), pGlCompileShader(0),
  38. pGlAttachShader(0), pGlLinkProgram(0),
  39. pGlGetInfoLogARB(0), pGlGetShaderInfoLog(0), pGlGetProgramInfoLog(0),
  40. pGlGetObjectParameterivARB(0), pGlGetShaderiv(0), pGlGetProgramiv(0),
  41. pGlGetUniformLocationARB(0), pGlGetUniformLocation(0),
  42. pGlUniform1fvARB(0), pGlUniform2fvARB(0), pGlUniform3fvARB(0), pGlUniform4fvARB(0),
  43. pGlUniform1ivARB(0), pGlUniform2ivARB(0), pGlUniform3ivARB(0), pGlUniform4ivARB(0),
  44. pGlUniformMatrix2fvARB(0), pGlUniformMatrix3fvARB(0), pGlUniformMatrix4fvARB(0),
  45. pGlGetActiveUniformARB(0), pGlGetActiveUniform(0),
  46. pGlPointParameterfARB(0), pGlPointParameterfvARB(0),
  47. pGlStencilFuncSeparate(0), pGlStencilOpSeparate(0),
  48. pGlStencilFuncSeparateATI(0), pGlStencilOpSeparateATI(0),
  49. pGlCompressedTexImage2D(0),
  50. // ARB framebuffer object
  51. pGlBindFramebuffer(0), pGlDeleteFramebuffers(0), pGlGenFramebuffers(0),
  52. pGlCheckFramebufferStatus(0), pGlFramebufferTexture2D(0),
  53. pGlBindRenderbuffer(0), pGlDeleteRenderbuffers(0), pGlGenRenderbuffers(0),
  54. pGlRenderbufferStorage(0), pGlFramebufferRenderbuffer(0), pGlGenerateMipmap(0),
  55. // EXT framebuffer object
  56. pGlBindFramebufferEXT(0), pGlDeleteFramebuffersEXT(0), pGlGenFramebuffersEXT(0),
  57. pGlCheckFramebufferStatusEXT(0), pGlFramebufferTexture2DEXT(0),
  58. pGlBindRenderbufferEXT(0), pGlDeleteRenderbuffersEXT(0), pGlGenRenderbuffersEXT(0),
  59. pGlRenderbufferStorageEXT(0), pGlFramebufferRenderbufferEXT(0), pGlGenerateMipmapEXT(0),
  60. // MRTs
  61. pGlDrawBuffersARB(0), pGlDrawBuffersATI(0),
  62. pGlGenBuffersARB(0), pGlBindBufferARB(0), pGlBufferDataARB(0), pGlDeleteBuffersARB(0),
  63. pGlBufferSubDataARB(0), pGlGetBufferSubDataARB(0), pGlMapBufferARB(0), pGlUnmapBufferARB(0),
  64. pGlIsBufferARB(0), pGlGetBufferParameterivARB(0), pGlGetBufferPointervARB(0),
  65. pGlProvokingVertexARB(0), pGlProvokingVertexEXT(0),
  66. pGlColorMaskIndexedEXT(0), pGlEnableIndexedEXT(0), pGlDisableIndexedEXT(0),
  67. pGlBlendFuncIndexedAMD(0), pGlBlendFunciARB(0),
  68. pGlBlendEquationIndexedAMD(0), pGlBlendEquationiARB(0),
  69. pGlProgramParameteriARB(0), pGlProgramParameteriEXT(0),
  70. pGlGenQueriesARB(0), pGlDeleteQueriesARB(0), pGlIsQueryARB(0),
  71. pGlBeginQueryARB(0), pGlEndQueryARB(0), pGlGetQueryivARB(0),
  72. pGlGetQueryObjectivARB(0), pGlGetQueryObjectuivARB(0),
  73. pGlGenOcclusionQueriesNV(0), pGlDeleteOcclusionQueriesNV(0),
  74. pGlIsOcclusionQueryNV(0), pGlBeginOcclusionQueryNV(0),
  75. pGlEndOcclusionQueryNV(0), pGlGetOcclusionQueryivNV(0),
  76. pGlGetOcclusionQueryuivNV(0),
  77. pGlBlendEquationEXT(0), pGlBlendEquation(0)
  78. #if defined(GLX_SGI_swap_control)
  79. ,pGlxSwapIntervalSGI(0)
  80. #endif
  81. #if defined(GLX_EXT_swap_control)
  82. ,pGlxSwapIntervalEXT(0)
  83. #endif
  84. #if defined(WGL_EXT_swap_control)
  85. ,pWglSwapIntervalEXT(0)
  86. #endif
  87. #if defined(GLX_MESA_swap_control)
  88. ,pGlxSwapIntervalMESA(0)
  89. #endif
  90. #endif // _IRR_OPENGL_USE_EXTPOINTER_
  91. {
  92. for (u32 i=0; i<IRR_OpenGL_Feature_Count; ++i)
  93. FeatureAvailable[i]=true;
  94. DimAliasedLine[0]=1.f;
  95. DimAliasedLine[1]=1.f;
  96. DimAliasedPoint[0]=1.f;
  97. DimAliasedPoint[1]=1.f;
  98. DimSmoothedLine[0]=1.f;
  99. DimSmoothedLine[1]=1.f;
  100. DimSmoothedPoint[0]=1.f;
  101. DimSmoothedPoint[1]=1.f;
  102. }
  103. void COpenGLExtensionHandler::dump() const
  104. {
  105. for (u32 i=0; i<IRR_OpenGL_Feature_Count; ++i)
  106. os::Printer::log(OpenGLFeatureStrings[i], FeatureAvailable[i]?" true":" false");
  107. }
  108. void COpenGLExtensionHandler::dumpFramebufferFormats() const
  109. {
  110. #ifdef _IRR_WINDOWS_API_
  111. HDC hdc=wglGetCurrentDC();
  112. core::stringc wglExtensions;
  113. #ifdef WGL_ARB_extensions_string
  114. PFNWGLGETEXTENSIONSSTRINGARBPROC irrGetExtensionsString = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
  115. if (irrGetExtensionsString)
  116. wglExtensions = irrGetExtensionsString(hdc);
  117. #elif defined(WGL_EXT_extensions_string)
  118. PFNWGLGETEXTENSIONSSTRINGEXTPROC irrGetExtensionsString = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("wglGetExtensionsStringEXT");
  119. if (irrGetExtensionsString)
  120. wglExtensions = irrGetExtensionsString(hdc);
  121. #endif
  122. const bool pixel_format_supported = (wglExtensions.find("WGL_ARB_pixel_format") != -1);
  123. const bool multi_sample_supported = ((wglExtensions.find("WGL_ARB_multisample") != -1) ||
  124. (wglExtensions.find("WGL_EXT_multisample") != -1) || (wglExtensions.find("WGL_3DFX_multisample") != -1) );
  125. #ifdef _DEBUG
  126. os::Printer::log("WGL_extensions", wglExtensions);
  127. #endif
  128. #ifdef WGL_ARB_pixel_format
  129. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat_ARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
  130. if (pixel_format_supported && wglChoosePixelFormat_ARB)
  131. {
  132. // This value determines the number of samples used for antialiasing
  133. // My experience is that 8 does not show a big
  134. // improvement over 4, but 4 shows a big improvement
  135. // over 2.
  136. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribiv_ARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
  137. if (wglGetPixelFormatAttribiv_ARB)
  138. {
  139. int vals[128];
  140. int atts[] = {
  141. WGL_NUMBER_PIXEL_FORMATS_ARB,
  142. WGL_DRAW_TO_BITMAP_ARB,
  143. WGL_ACCELERATION_ARB,
  144. WGL_NEED_PALETTE_ARB,
  145. WGL_NEED_SYSTEM_PALETTE_ARB,
  146. WGL_SWAP_LAYER_BUFFERS_ARB,
  147. WGL_SWAP_METHOD_ARB,
  148. WGL_NUMBER_OVERLAYS_ARB,
  149. WGL_NUMBER_UNDERLAYS_ARB,
  150. WGL_TRANSPARENT_ARB,
  151. WGL_TRANSPARENT_RED_VALUE_ARB,
  152. WGL_TRANSPARENT_GREEN_VALUE_ARB,
  153. WGL_TRANSPARENT_BLUE_VALUE_ARB,
  154. WGL_TRANSPARENT_ALPHA_VALUE_ARB,
  155. WGL_TRANSPARENT_INDEX_VALUE_ARB,
  156. WGL_SHARE_DEPTH_ARB,
  157. WGL_SHARE_STENCIL_ARB,
  158. WGL_SHARE_ACCUM_ARB,
  159. WGL_SUPPORT_GDI_ARB,
  160. WGL_SUPPORT_OPENGL_ARB,
  161. WGL_DOUBLE_BUFFER_ARB,
  162. WGL_STEREO_ARB,
  163. WGL_PIXEL_TYPE_ARB,
  164. WGL_COLOR_BITS_ARB,
  165. WGL_RED_BITS_ARB,
  166. WGL_RED_SHIFT_ARB,
  167. WGL_GREEN_BITS_ARB,
  168. WGL_GREEN_SHIFT_ARB,
  169. WGL_BLUE_BITS_ARB,
  170. WGL_BLUE_SHIFT_ARB,
  171. WGL_ALPHA_BITS_ARB,
  172. WGL_ALPHA_SHIFT_ARB,
  173. WGL_ACCUM_BITS_ARB,
  174. WGL_ACCUM_RED_BITS_ARB,
  175. WGL_ACCUM_GREEN_BITS_ARB,
  176. WGL_ACCUM_BLUE_BITS_ARB,
  177. WGL_ACCUM_ALPHA_BITS_ARB,
  178. WGL_DEPTH_BITS_ARB,
  179. WGL_STENCIL_BITS_ARB,
  180. WGL_AUX_BUFFERS_ARB
  181. #ifdef WGL_ARB_render_texture
  182. ,WGL_BIND_TO_TEXTURE_RGB_ARB //40
  183. ,WGL_BIND_TO_TEXTURE_RGBA_ARB
  184. #endif
  185. #ifdef WGL_ARB_pbuffer
  186. ,WGL_DRAW_TO_PBUFFER_ARB //42
  187. ,WGL_MAX_PBUFFER_PIXELS_ARB
  188. ,WGL_MAX_PBUFFER_WIDTH_ARB
  189. ,WGL_MAX_PBUFFER_HEIGHT_ARB
  190. #endif
  191. #ifdef WGL_ARB_framebuffer_sRGB
  192. ,WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB //46
  193. #endif
  194. #ifdef WGL_ARB_multisample
  195. ,WGL_SAMPLES_ARB //47
  196. ,WGL_SAMPLE_BUFFERS_ARB
  197. #endif
  198. #ifdef WGL_EXT_depth_float
  199. ,WGL_DEPTH_FLOAT_EXT //49
  200. #endif
  201. ,0,0,0,0
  202. };
  203. size_t nums = sizeof(atts)/sizeof(int);
  204. const bool depth_float_supported= (wglExtensions.find("WGL_EXT_depth_float") != -1);
  205. if (!depth_float_supported)
  206. {
  207. memmove(&atts[49], &atts[50], (nums-50)*sizeof(int));
  208. nums -= 1;
  209. }
  210. if (!multi_sample_supported)
  211. {
  212. memmove(&atts[47], &atts[49], (nums-49)*sizeof(int));
  213. nums -= 2;
  214. }
  215. const bool framebuffer_sRGB_supported= (wglExtensions.find("WGL_ARB_framebuffer_sRGB") != -1);
  216. if (!framebuffer_sRGB_supported)
  217. {
  218. memmove(&atts[46], &atts[47], (nums-47)*sizeof(int));
  219. nums -= 1;
  220. }
  221. const bool pbuffer_supported = (wglExtensions.find("WGL_ARB_pbuffer") != -1);
  222. if (!pbuffer_supported)
  223. {
  224. memmove(&atts[42], &atts[46], (nums-46)*sizeof(int));
  225. nums -= 4;
  226. }
  227. const bool render_texture_supported = (wglExtensions.find("WGL_ARB_render_texture") != -1);
  228. if (!render_texture_supported)
  229. {
  230. memmove(&atts[40], &atts[42], (nums-42)*sizeof(int));
  231. nums -= 2;
  232. }
  233. wglGetPixelFormatAttribiv_ARB(hdc,0,0,1,atts,vals);
  234. const int count = vals[0];
  235. atts[0]=WGL_DRAW_TO_WINDOW_ARB;
  236. for (int i=1; i<count; ++i)
  237. {
  238. memset(vals,0,sizeof(vals));
  239. #define tmplog(x,y) os::Printer::log(x, core::stringc(y).c_str())
  240. const BOOL res = wglGetPixelFormatAttribiv_ARB(hdc,i,0,nums,atts,vals);
  241. if (FALSE==res)
  242. continue;
  243. tmplog("Pixel format ",i);
  244. u32 j=0;
  245. tmplog("Draw to window " , vals[j]);
  246. tmplog("Draw to bitmap " , vals[++j]);
  247. ++j;
  248. tmplog("Acceleration " , (vals[j]==WGL_NO_ACCELERATION_ARB?"No":
  249. vals[j]==WGL_GENERIC_ACCELERATION_ARB?"Generic":vals[j]==WGL_FULL_ACCELERATION_ARB?"Full":"ERROR"));
  250. tmplog("Need palette " , vals[++j]);
  251. tmplog("Need system palette " , vals[++j]);
  252. tmplog("Swap layer buffers " , vals[++j]);
  253. ++j;
  254. tmplog("Swap method " , (vals[j]==WGL_SWAP_EXCHANGE_ARB?"Exchange":
  255. vals[j]==WGL_SWAP_COPY_ARB?"Copy":vals[j]==WGL_SWAP_UNDEFINED_ARB?"Undefined":"ERROR"));
  256. tmplog("Number of overlays " , vals[++j]);
  257. tmplog("Number of underlays " , vals[++j]);
  258. tmplog("Transparent " , vals[++j]);
  259. tmplog("Transparent red value " , vals[++j]);
  260. tmplog("Transparent green value " , vals[++j]);
  261. tmplog("Transparent blue value " , vals[++j]);
  262. tmplog("Transparent alpha value " , vals[++j]);
  263. tmplog("Transparent index value " , vals[++j]);
  264. tmplog("Share depth " , vals[++j]);
  265. tmplog("Share stencil " , vals[++j]);
  266. tmplog("Share accum " , vals[++j]);
  267. tmplog("Support GDI " , vals[++j]);
  268. tmplog("Support OpenGL " , vals[++j]);
  269. tmplog("Double Buffer " , vals[++j]);
  270. tmplog("Stereo Buffer " , vals[++j]);
  271. tmplog("Pixel type " , vals[++j]);
  272. tmplog("Color bits" , vals[++j]);
  273. tmplog("Red bits " , vals[++j]);
  274. tmplog("Red shift " , vals[++j]);
  275. tmplog("Green bits " , vals[++j]);
  276. tmplog("Green shift " , vals[++j]);
  277. tmplog("Blue bits " , vals[++j]);
  278. tmplog("Blue shift " , vals[++j]);
  279. tmplog("Alpha bits " , vals[++j]);
  280. tmplog("Alpha Shift " , vals[++j]);
  281. tmplog("Accum bits " , vals[++j]);
  282. tmplog("Accum red bits " , vals[++j]);
  283. tmplog("Accum green bits " , vals[++j]);
  284. tmplog("Accum blue bits " , vals[++j]);
  285. tmplog("Accum alpha bits " , vals[++j]);
  286. tmplog("Depth bits " , vals[++j]);
  287. tmplog("Stencil bits " , vals[++j]);
  288. tmplog("Aux buffers " , vals[++j]);
  289. if (render_texture_supported)
  290. {
  291. tmplog("Bind to texture RGB" , vals[++j]);
  292. tmplog("Bind to texture RGBA" , vals[++j]);
  293. }
  294. if (pbuffer_supported)
  295. {
  296. tmplog("Draw to pbuffer" , vals[++j]);
  297. tmplog("Max pbuffer pixels " , vals[++j]);
  298. tmplog("Max pbuffer width" , vals[++j]);
  299. tmplog("Max pbuffer height" , vals[++j]);
  300. }
  301. if (framebuffer_sRGB_supported)
  302. tmplog("Framebuffer sRBG capable" , vals[++j]);
  303. if (multi_sample_supported)
  304. {
  305. tmplog("Samples " , vals[++j]);
  306. tmplog("Sample buffers " , vals[++j]);
  307. }
  308. if (depth_float_supported)
  309. tmplog("Depth float" , vals[++j]);
  310. #undef tmplog
  311. }
  312. }
  313. }
  314. #endif
  315. #elif defined(IRR_LINUX_DEVICE)
  316. #endif
  317. }
  318. void COpenGLExtensionHandler::initExtensions(bool stencilBuffer)
  319. {
  320. const f32 ogl_ver = core::fast_atof(reinterpret_cast<const c8*>(glGetString(GL_VERSION)));
  321. Version = static_cast<u16>(core::floor32(ogl_ver)*100+core::round32(core::fract(ogl_ver)*10.0f));
  322. if ( Version >= 102)
  323. os::Printer::log("OpenGL driver version is 1.2 or better.", ELL_INFORMATION);
  324. else
  325. os::Printer::log("OpenGL driver version is not 1.2 or better.", ELL_WARNING);
  326. {
  327. const char* t = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
  328. size_t len = 0;
  329. c8 *str = 0;
  330. if (t)
  331. {
  332. len = strlen(t);
  333. str = new c8[len+1];
  334. }
  335. c8* p = str;
  336. for (size_t i=0; i<len; ++i)
  337. {
  338. str[i] = static_cast<char>(t[i]);
  339. if (str[i] == ' ')
  340. {
  341. str[i] = 0;
  342. for (u32 j=0; j<IRR_OpenGL_Feature_Count; ++j)
  343. {
  344. if (!strcmp(OpenGLFeatureStrings[j], p))
  345. {
  346. FeatureAvailable[j] = true;
  347. break;
  348. }
  349. }
  350. p = p + strlen(p) + 1;
  351. }
  352. }
  353. delete [] str;
  354. }
  355. MultiTextureExtension = FeatureAvailable[IRR_ARB_multitexture];
  356. TextureCompressionExtension = FeatureAvailable[IRR_ARB_texture_compression];
  357. StencilBuffer=stencilBuffer;
  358. #ifdef _IRR_OPENGL_USE_EXTPOINTER_
  359. #ifdef _IRR_WINDOWS_API_
  360. #define IRR_OGL_LOAD_EXTENSION(x) wglGetProcAddress(reinterpret_cast<const char*>(x))
  361. #elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && !defined(_IRR_COMPILE_WITH_X11_DEVICE_)
  362. #define IRR_OGL_LOAD_EXTENSION(x) SDL_GL_GetProcAddress(reinterpret_cast<const char*>(x))
  363. #else
  364. // Accessing the correct function is quite complex
  365. // All libraries should support the ARB version, however
  366. // since GLX 1.4 the non-ARB version is the official one
  367. // So we have to check the runtime environment and
  368. // choose the proper symbol
  369. // In case you still have problems please enable the
  370. // next line by uncommenting it
  371. // #define _IRR_GETPROCADDRESS_WORKAROUND_
  372. #ifndef _IRR_GETPROCADDRESS_WORKAROUND_
  373. __GLXextFuncPtr (*IRR_OGL_LOAD_EXTENSION_FUNCP)(const GLubyte*)=0;
  374. #ifdef GLX_VERSION_1_4
  375. int major=0,minor=0;
  376. if (glXGetCurrentDisplay())
  377. glXQueryVersion(glXGetCurrentDisplay(), &major, &minor);
  378. if ((major>1) || (minor>3))
  379. IRR_OGL_LOAD_EXTENSION_FUNCP=glXGetProcAddress;
  380. else
  381. #endif
  382. IRR_OGL_LOAD_EXTENSION_FUNCP=glXGetProcAddressARB;
  383. #define IRR_OGL_LOAD_EXTENSION(X) IRR_OGL_LOAD_EXTENSION_FUNCP(reinterpret_cast<const GLubyte*>(X))
  384. #else
  385. #define IRR_OGL_LOAD_EXTENSION(X) glXGetProcAddressARB(reinterpret_cast<const GLubyte*>(X))
  386. #endif // workaround
  387. #endif // Windows, SDL, or Linux
  388. // get multitexturing function pointers
  389. pGlActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) IRR_OGL_LOAD_EXTENSION("glActiveTextureARB");
  390. pGlClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC) IRR_OGL_LOAD_EXTENSION("glClientActiveTextureARB");
  391. // get fragment and vertex program function pointers
  392. pGlGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) IRR_OGL_LOAD_EXTENSION("glGenProgramsARB");
  393. pGlGenProgramsNV = (PFNGLGENPROGRAMSNVPROC) IRR_OGL_LOAD_EXTENSION("glGenProgramsNV");
  394. pGlBindProgramARB = (PFNGLBINDPROGRAMARBPROC) IRR_OGL_LOAD_EXTENSION("glBindProgramARB");
  395. pGlBindProgramNV = (PFNGLBINDPROGRAMNVPROC) IRR_OGL_LOAD_EXTENSION("glBindProgramNV");
  396. pGlProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) IRR_OGL_LOAD_EXTENSION("glProgramStringARB");
  397. pGlLoadProgramNV = (PFNGLLOADPROGRAMNVPROC) IRR_OGL_LOAD_EXTENSION("glLoadProgramNV");
  398. pGlDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) IRR_OGL_LOAD_EXTENSION("glDeleteProgramsARB");
  399. pGlDeleteProgramsNV = (PFNGLDELETEPROGRAMSNVPROC) IRR_OGL_LOAD_EXTENSION("glDeleteProgramsNV");
  400. pGlProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) IRR_OGL_LOAD_EXTENSION("glProgramLocalParameter4fvARB");
  401. pGlCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) IRR_OGL_LOAD_EXTENSION("glCreateShaderObjectARB");
  402. pGlCreateShader = (PFNGLCREATESHADERPROC) IRR_OGL_LOAD_EXTENSION("glCreateShader");
  403. pGlShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) IRR_OGL_LOAD_EXTENSION("glShaderSourceARB");
  404. pGlShaderSource = (PFNGLSHADERSOURCEPROC) IRR_OGL_LOAD_EXTENSION("glShaderSource");
  405. pGlCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) IRR_OGL_LOAD_EXTENSION("glCompileShaderARB");
  406. pGlCompileShader = (PFNGLCOMPILESHADERPROC) IRR_OGL_LOAD_EXTENSION("glCompileShader");
  407. pGlCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) IRR_OGL_LOAD_EXTENSION("glCreateProgramObjectARB");
  408. pGlCreateProgram = (PFNGLCREATEPROGRAMPROC) IRR_OGL_LOAD_EXTENSION("glCreateProgram");
  409. pGlAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) IRR_OGL_LOAD_EXTENSION("glAttachObjectARB");
  410. pGlAttachShader = (PFNGLATTACHSHADERPROC) IRR_OGL_LOAD_EXTENSION("glAttachShader");
  411. pGlLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) IRR_OGL_LOAD_EXTENSION("glLinkProgramARB");
  412. pGlLinkProgram = (PFNGLLINKPROGRAMPROC) IRR_OGL_LOAD_EXTENSION("glLinkProgram");
  413. pGlUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) IRR_OGL_LOAD_EXTENSION("glUseProgramObjectARB");
  414. pGlUseProgram = (PFNGLUSEPROGRAMPROC) IRR_OGL_LOAD_EXTENSION("glUseProgram");
  415. pGlDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) IRR_OGL_LOAD_EXTENSION("glDeleteObjectARB");
  416. pGlDeleteProgram = (PFNGLDELETEPROGRAMPROC) IRR_OGL_LOAD_EXTENSION("glDeleteProgram");
  417. pGlDeleteShader = (PFNGLDELETESHADERPROC) IRR_OGL_LOAD_EXTENSION("glDeleteShader");
  418. pGlGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC) IRR_OGL_LOAD_EXTENSION("glGetAttachedShaders");
  419. pGlGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC) IRR_OGL_LOAD_EXTENSION("glGetAttachedObjectsARB");
  420. pGlGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) IRR_OGL_LOAD_EXTENSION("glGetInfoLogARB");
  421. pGlGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) IRR_OGL_LOAD_EXTENSION("glGetShaderInfoLog");
  422. pGlGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) IRR_OGL_LOAD_EXTENSION("glGetProgramInfoLog");
  423. pGlGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) IRR_OGL_LOAD_EXTENSION("glGetObjectParameterivARB");
  424. pGlGetShaderiv = (PFNGLGETSHADERIVPROC) IRR_OGL_LOAD_EXTENSION("glGetShaderiv");
  425. pGlGetProgramiv = (PFNGLGETPROGRAMIVPROC) IRR_OGL_LOAD_EXTENSION("glGetProgramiv");
  426. pGlGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) IRR_OGL_LOAD_EXTENSION("glGetUniformLocationARB");
  427. pGlGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) IRR_OGL_LOAD_EXTENSION("glGetUniformLocation");
  428. pGlUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform1fvARB");
  429. pGlUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform2fvARB");
  430. pGlUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform3fvARB");
  431. pGlUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform4fvARB");
  432. pGlUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform1ivARB");
  433. pGlUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform2ivARB");
  434. pGlUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform3ivARB");
  435. pGlUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform4ivARB");
  436. pGlUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniformMatrix2fvARB");
  437. pGlUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniformMatrix3fvARB");
  438. pGlUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniformMatrix4fvARB");
  439. pGlGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC) IRR_OGL_LOAD_EXTENSION("glGetActiveUniformARB");
  440. pGlGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC) IRR_OGL_LOAD_EXTENSION("glGetActiveUniform");
  441. // get point parameter extension
  442. pGlPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC) IRR_OGL_LOAD_EXTENSION("glPointParameterfARB");
  443. pGlPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC) IRR_OGL_LOAD_EXTENSION("glPointParameterfvARB");
  444. // get stencil extension
  445. pGlStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC) IRR_OGL_LOAD_EXTENSION("glStencilFuncSeparate");
  446. pGlStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC) IRR_OGL_LOAD_EXTENSION("glStencilOpSeparate");
  447. pGlStencilFuncSeparateATI = (PFNGLSTENCILFUNCSEPARATEATIPROC) IRR_OGL_LOAD_EXTENSION("glStencilFuncSeparateATI");
  448. pGlStencilOpSeparateATI = (PFNGLSTENCILOPSEPARATEATIPROC) IRR_OGL_LOAD_EXTENSION("glStencilOpSeparateATI");
  449. // compressed textures
  450. pGlCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) IRR_OGL_LOAD_EXTENSION("glCompressedTexImage2D");
  451. // ARB FrameBufferObjects
  452. pGlBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) IRR_OGL_LOAD_EXTENSION("glBindFramebuffer");
  453. pGlDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) IRR_OGL_LOAD_EXTENSION("glDeleteFramebuffers");
  454. pGlGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) IRR_OGL_LOAD_EXTENSION("glGenFramebuffers");
  455. pGlCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatus");
  456. pGlFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) IRR_OGL_LOAD_EXTENSION("glFramebufferTexture2D");
  457. pGlBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) IRR_OGL_LOAD_EXTENSION("glBindRenderbuffer");
  458. pGlDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) IRR_OGL_LOAD_EXTENSION("glDeleteRenderbuffers");
  459. pGlGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) IRR_OGL_LOAD_EXTENSION("glGenRenderbuffers");
  460. pGlRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) IRR_OGL_LOAD_EXTENSION("glRenderbufferStorage");
  461. pGlFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) IRR_OGL_LOAD_EXTENSION("glFramebufferRenderbuffer");
  462. pGlGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) IRR_OGL_LOAD_EXTENSION("glGenerateMipmap");
  463. // EXT FrameBufferObjects
  464. pGlBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) IRR_OGL_LOAD_EXTENSION("glBindFramebufferEXT");
  465. pGlDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) IRR_OGL_LOAD_EXTENSION("glDeleteFramebuffersEXT");
  466. pGlGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) IRR_OGL_LOAD_EXTENSION("glGenFramebuffersEXT");
  467. pGlCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatusEXT");
  468. pGlFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) IRR_OGL_LOAD_EXTENSION("glFramebufferTexture2DEXT");
  469. pGlBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) IRR_OGL_LOAD_EXTENSION("glBindRenderbufferEXT");
  470. pGlDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) IRR_OGL_LOAD_EXTENSION("glDeleteRenderbuffersEXT");
  471. pGlGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) IRR_OGL_LOAD_EXTENSION("glGenRenderbuffersEXT");
  472. pGlRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) IRR_OGL_LOAD_EXTENSION("glRenderbufferStorageEXT");
  473. pGlFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) IRR_OGL_LOAD_EXTENSION("glFramebufferRenderbufferEXT");
  474. pGlGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC) IRR_OGL_LOAD_EXTENSION("glGenerateMipmapEXT");
  475. pGlDrawBuffersARB = (PFNGLDRAWBUFFERSARBPROC) IRR_OGL_LOAD_EXTENSION("glDrawBuffersARB");
  476. pGlDrawBuffersATI = (PFNGLDRAWBUFFERSATIPROC) IRR_OGL_LOAD_EXTENSION("glDrawBuffersATI");
  477. // get vertex buffer extension
  478. pGlGenBuffersARB = (PFNGLGENBUFFERSARBPROC) IRR_OGL_LOAD_EXTENSION("glGenBuffersARB");
  479. pGlBindBufferARB = (PFNGLBINDBUFFERARBPROC) IRR_OGL_LOAD_EXTENSION("glBindBufferARB");
  480. pGlBufferDataARB = (PFNGLBUFFERDATAARBPROC) IRR_OGL_LOAD_EXTENSION("glBufferDataARB");
  481. pGlDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) IRR_OGL_LOAD_EXTENSION("glDeleteBuffersARB");
  482. pGlBufferSubDataARB= (PFNGLBUFFERSUBDATAARBPROC) IRR_OGL_LOAD_EXTENSION("glBufferSubDataARB");
  483. pGlGetBufferSubDataARB= (PFNGLGETBUFFERSUBDATAARBPROC)IRR_OGL_LOAD_EXTENSION("glGetBufferSubDataARB");
  484. pGlMapBufferARB= (PFNGLMAPBUFFERARBPROC) IRR_OGL_LOAD_EXTENSION("glMapBufferARB");
  485. pGlUnmapBufferARB= (PFNGLUNMAPBUFFERARBPROC) IRR_OGL_LOAD_EXTENSION("glUnmapBufferARB");
  486. pGlIsBufferARB= (PFNGLISBUFFERARBPROC) IRR_OGL_LOAD_EXTENSION("glIsBufferARB");
  487. pGlGetBufferParameterivARB= (PFNGLGETBUFFERPARAMETERIVARBPROC) IRR_OGL_LOAD_EXTENSION("glGetBufferParameterivARB");
  488. pGlGetBufferPointervARB= (PFNGLGETBUFFERPOINTERVARBPROC) IRR_OGL_LOAD_EXTENSION("glGetBufferPointervARB");
  489. pGlProvokingVertexARB= (PFNGLPROVOKINGVERTEXPROC) IRR_OGL_LOAD_EXTENSION("glProvokingVertex");
  490. pGlProvokingVertexEXT= (PFNGLPROVOKINGVERTEXEXTPROC) IRR_OGL_LOAD_EXTENSION("glProvokingVertexEXT");
  491. pGlColorMaskIndexedEXT= (PFNGLCOLORMASKINDEXEDEXTPROC) IRR_OGL_LOAD_EXTENSION("glColorMaskIndexedEXT");
  492. pGlEnableIndexedEXT= (PFNGLENABLEINDEXEDEXTPROC) IRR_OGL_LOAD_EXTENSION("glEnableIndexedEXT");
  493. pGlDisableIndexedEXT= (PFNGLDISABLEINDEXEDEXTPROC) IRR_OGL_LOAD_EXTENSION("glDisableIndexedEXT");
  494. pGlBlendFuncIndexedAMD= (PFNGLBLENDFUNCINDEXEDAMDPROC) IRR_OGL_LOAD_EXTENSION("glBlendFuncIndexedAMD");
  495. pGlBlendFunciARB= (PFNGLBLENDFUNCIPROC) IRR_OGL_LOAD_EXTENSION("glBlendFunciARB");
  496. pGlBlendEquationIndexedAMD= (PFNGLBLENDEQUATIONINDEXEDAMDPROC) IRR_OGL_LOAD_EXTENSION("glBlendEquationIndexedAMD");
  497. pGlBlendEquationiARB= (PFNGLBLENDEQUATIONIPROC) IRR_OGL_LOAD_EXTENSION("glBlendEquationiARB");
  498. pGlProgramParameteriARB= (PFNGLPROGRAMPARAMETERIARBPROC) IRR_OGL_LOAD_EXTENSION("glProgramParameteriARB");
  499. pGlProgramParameteriEXT= (PFNGLPROGRAMPARAMETERIEXTPROC) IRR_OGL_LOAD_EXTENSION("glProgramParameteriEXT");
  500. // occlusion query
  501. pGlGenQueriesARB = (PFNGLGENQUERIESARBPROC) IRR_OGL_LOAD_EXTENSION("glGenQueriesARB");
  502. pGlDeleteQueriesARB = (PFNGLDELETEQUERIESARBPROC) IRR_OGL_LOAD_EXTENSION("glDeleteQueriesARB");
  503. pGlIsQueryARB = (PFNGLISQUERYARBPROC) IRR_OGL_LOAD_EXTENSION("glIsQueryARB");
  504. pGlBeginQueryARB = (PFNGLBEGINQUERYARBPROC) IRR_OGL_LOAD_EXTENSION("glBeginQueryARB");
  505. pGlEndQueryARB = (PFNGLENDQUERYARBPROC) IRR_OGL_LOAD_EXTENSION("glEndQueryARB");
  506. pGlGetQueryivARB = (PFNGLGETQUERYIVARBPROC) IRR_OGL_LOAD_EXTENSION("glGetQueryivARB");
  507. pGlGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC) IRR_OGL_LOAD_EXTENSION("glGetQueryObjectivARB");
  508. pGlGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC) IRR_OGL_LOAD_EXTENSION("glGetQueryObjectuivARB");
  509. pGlGenOcclusionQueriesNV = (PFNGLGENOCCLUSIONQUERIESNVPROC) IRR_OGL_LOAD_EXTENSION("glGenOcclusionQueriesNV");
  510. pGlDeleteOcclusionQueriesNV = (PFNGLDELETEOCCLUSIONQUERIESNVPROC) IRR_OGL_LOAD_EXTENSION("glDeleteOcclusionQueriesNV");
  511. pGlIsOcclusionQueryNV = (PFNGLISOCCLUSIONQUERYNVPROC) IRR_OGL_LOAD_EXTENSION("glIsOcclusionQueryNV");
  512. pGlBeginOcclusionQueryNV = (PFNGLBEGINOCCLUSIONQUERYNVPROC) IRR_OGL_LOAD_EXTENSION("glBeginOcclusionQueryNV");
  513. pGlEndOcclusionQueryNV = (PFNGLENDOCCLUSIONQUERYNVPROC) IRR_OGL_LOAD_EXTENSION("glEndOcclusionQueryNV");
  514. pGlGetOcclusionQueryivNV = (PFNGLGETOCCLUSIONQUERYIVNVPROC) IRR_OGL_LOAD_EXTENSION("glGetOcclusionQueryivNV");
  515. pGlGetOcclusionQueryuivNV = (PFNGLGETOCCLUSIONQUERYUIVNVPROC) IRR_OGL_LOAD_EXTENSION("glGetOcclusionQueryuivNV");
  516. // blend equation
  517. pGlBlendEquationEXT = (PFNGLBLENDEQUATIONEXTPROC) IRR_OGL_LOAD_EXTENSION("glBlendEquationEXT");
  518. pGlBlendEquation = (PFNGLBLENDEQUATIONPROC) IRR_OGL_LOAD_EXTENSION("glBlendEquation");
  519. // get vsync extension
  520. #if defined(WGL_EXT_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
  521. pWglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) IRR_OGL_LOAD_EXTENSION("wglSwapIntervalEXT");
  522. #endif
  523. #if defined(GLX_SGI_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
  524. pGlxSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)IRR_OGL_LOAD_EXTENSION("glXSwapIntervalSGI");
  525. #endif
  526. #if defined(GLX_EXT_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
  527. pGlxSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)IRR_OGL_LOAD_EXTENSION("glXSwapIntervalEXT");
  528. #endif
  529. #if defined(GLX_MESA_swap_control) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
  530. pGlxSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)IRR_OGL_LOAD_EXTENSION("glXSwapIntervalMESA");
  531. #endif
  532. #endif // use extension pointer
  533. GLint num=0;
  534. // set some properties
  535. #if defined(GL_ARB_multitexture) || defined(GL_VERSION_1_3)
  536. if (Version>102 || FeatureAvailable[IRR_ARB_multitexture])
  537. {
  538. #if defined(GL_MAX_TEXTURE_UNITS)
  539. if (!useCoreContext)
  540. glGetIntegerv(GL_MAX_TEXTURE_UNITS, &num);
  541. #elif defined(GL_MAX_TEXTURE_UNITS_ARB)
  542. glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &num);
  543. #endif
  544. MaxSupportedTextures=static_cast<u8>(num);
  545. }
  546. #endif
  547. #if defined(GL_ARB_vertex_shader) || defined(GL_VERSION_2_0)
  548. if (Version>=200 || FeatureAvailable[IRR_ARB_vertex_shader])
  549. {
  550. num=0;
  551. #if defined(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)
  552. glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &num);
  553. #elif defined(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB)
  554. glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &num);
  555. #endif
  556. MaxSupportedTextures=core::max_(MaxSupportedTextures,static_cast<u8>(num));
  557. }
  558. #endif
  559. if (!useCoreContext)
  560. glGetIntegerv(GL_MAX_LIGHTS, &num);
  561. MaxLights=static_cast<u8>(num);
  562. #ifdef GL_EXT_texture_filter_anisotropic
  563. if (FeatureAvailable[IRR_EXT_texture_filter_anisotropic])
  564. {
  565. glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &num);
  566. MaxAnisotropy=static_cast<u8>(num);
  567. }
  568. #endif
  569. #ifdef GL_VERSION_1_2
  570. if (Version>101)
  571. {
  572. glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &num);
  573. MaxIndices=num;
  574. }
  575. #endif
  576. glGetIntegerv(GL_MAX_TEXTURE_SIZE, &num);
  577. MaxTextureSize=static_cast<u32>(num);
  578. if (queryFeature(EVDF_GEOMETRY_SHADER))
  579. {
  580. #if defined(GL_ARB_geometry_shader4) || defined(GL_EXT_geometry_shader4) || defined(GL_NV_geometry_shader4)
  581. glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &num);
  582. MaxGeometryVerticesOut=static_cast<u32>(num);
  583. #elif defined(GL_NV_geometry_program4)
  584. extGlGetProgramiv(GEOMETRY_PROGRAM_NV, GL_MAX_PROGRAM_OUTPUT_VERTICES_NV, &num);
  585. MaxGeometryVerticesOut=static_cast<u32>(num);
  586. #endif
  587. }
  588. #ifdef GL_EXT_texture_lod_bias
  589. if (FeatureAvailable[IRR_EXT_texture_lod_bias])
  590. glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &MaxTextureLODBias);
  591. #endif
  592. glGetIntegerv(GL_MAX_CLIP_PLANES, &num);
  593. MaxUserClipPlanes=static_cast<u8>(num);
  594. if (!useCoreContext)
  595. glGetIntegerv(GL_AUX_BUFFERS, &num);
  596. MaxAuxBuffers=static_cast<u8>(num);
  597. #ifdef GL_ARB_draw_buffers
  598. if (FeatureAvailable[IRR_ARB_draw_buffers])
  599. {
  600. glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &num);
  601. MaxMultipleRenderTargets = static_cast<u8>(num);
  602. }
  603. #endif
  604. #if defined(GL_ATI_draw_buffers)
  605. #ifdef GL_ARB_draw_buffers
  606. else
  607. #endif
  608. if (FeatureAvailable[IRR_ATI_draw_buffers])
  609. {
  610. glGetIntegerv(GL_MAX_DRAW_BUFFERS_ATI, &num);
  611. MaxMultipleRenderTargets = static_cast<u8>(num);
  612. }
  613. #endif
  614. glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine);
  615. if (!useCoreContext)
  616. glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint);
  617. glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, DimSmoothedLine);
  618. glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, DimSmoothedPoint);
  619. #if defined(GL_ARB_shading_language_100) || defined (GL_VERSION_2_0)
  620. if (FeatureAvailable[IRR_ARB_shading_language_100] || Version>=200)
  621. {
  622. glGetError(); // clean error buffer
  623. #ifdef GL_SHADING_LANGUAGE_VERSION
  624. const GLubyte* shaderVersion = glGetString(GL_SHADING_LANGUAGE_VERSION);
  625. #else
  626. const GLubyte* shaderVersion = glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
  627. #endif
  628. if (glGetError() == GL_INVALID_ENUM)
  629. ShaderLanguageVersion = 100;
  630. else
  631. {
  632. const f32 sl_ver = core::fast_atof(reinterpret_cast<const c8*>(shaderVersion));
  633. ShaderLanguageVersion = static_cast<u16>(core::floor32(sl_ver)*100+core::round32(core::fract(sl_ver)*10.0f));
  634. }
  635. }
  636. #endif
  637. #ifdef _IRR_OPENGL_USE_EXTPOINTER_
  638. if (!pGlActiveTextureARB || !pGlClientActiveTextureARB)
  639. {
  640. MultiTextureExtension = false;
  641. os::Printer::log("Failed to load OpenGL's multitexture extension, proceeding without.", ELL_WARNING);
  642. }
  643. else
  644. #endif
  645. MaxTextureUnits = core::min_(MaxSupportedTextures, static_cast<u8>(MATERIAL_MAX_TEXTURES));
  646. if (MaxTextureUnits < 2)
  647. {
  648. MultiTextureExtension = false;
  649. os::Printer::log("Warning: OpenGL device only has one texture unit. Disabling multitexturing.", ELL_WARNING);
  650. }
  651. #ifdef GL_ARB_occlusion_query
  652. if (FeatureAvailable[IRR_ARB_occlusion_query])
  653. {
  654. extGlGetQueryiv(GL_SAMPLES_PASSED_ARB,GL_QUERY_COUNTER_BITS_ARB,
  655. &num);
  656. OcclusionQuerySupport=(num>0);
  657. }
  658. else
  659. #endif
  660. #ifdef GL_NV_occlusion_query
  661. if (FeatureAvailable[IRR_NV_occlusion_query])
  662. {
  663. glGetIntegerv(GL_PIXEL_COUNTER_BITS_NV, &num);
  664. OcclusionQuerySupport=(num>0);
  665. }
  666. else
  667. #endif
  668. OcclusionQuerySupport=false;
  669. #ifdef _DEBUG
  670. if (FeatureAvailable[IRR_NVX_gpu_memory_info])
  671. {
  672. // undocumented flags, so use the RAW values
  673. GLint val;
  674. glGetIntegerv(0x9047, &val);
  675. os::Printer::log("Dedicated video memory (kB)", core::stringc(val));
  676. glGetIntegerv(0x9048, &val);
  677. os::Printer::log("Total video memory (kB)", core::stringc(val));
  678. glGetIntegerv(0x9049, &val);
  679. os::Printer::log("Available video memory (kB)", core::stringc(val));
  680. }
  681. #ifdef GL_ATI_meminfo
  682. if (FeatureAvailable[IRR_ATI_meminfo])
  683. {
  684. GLint val[4];
  685. glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, val);
  686. os::Printer::log("Free texture memory (kB)", core::stringc(val[0]));
  687. glGetIntegerv(GL_VBO_FREE_MEMORY_ATI, val);
  688. os::Printer::log("Free VBO memory (kB)", core::stringc(val[0]));
  689. glGetIntegerv(GL_RENDERBUFFER_FREE_MEMORY_ATI, val);
  690. os::Printer::log("Free render buffer memory (kB)", core::stringc(val[0]));
  691. }
  692. #endif
  693. #endif
  694. }
  695. bool COpenGLExtensionHandler::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
  696. {
  697. switch (feature)
  698. {
  699. case EVDF_RENDER_TO_TARGET:
  700. return true;
  701. case EVDF_HARDWARE_TL:
  702. return true; // we cannot tell other things
  703. case EVDF_MULTITEXTURE:
  704. return MultiTextureExtension;
  705. case EVDF_BILINEAR_FILTER:
  706. return true;
  707. case EVDF_MIP_MAP:
  708. return true;
  709. case EVDF_MIP_MAP_AUTO_UPDATE:
  710. return FeatureAvailable[IRR_SGIS_generate_mipmap] || FeatureAvailable[IRR_EXT_framebuffer_object] || FeatureAvailable[IRR_ARB_framebuffer_object];
  711. case EVDF_STENCIL_BUFFER:
  712. return StencilBuffer;
  713. case EVDF_VERTEX_SHADER_1_1:
  714. case EVDF_ARB_VERTEX_PROGRAM_1:
  715. return FeatureAvailable[IRR_ARB_vertex_program] || FeatureAvailable[IRR_NV_vertex_program1_1];
  716. case EVDF_PIXEL_SHADER_1_1:
  717. case EVDF_PIXEL_SHADER_1_2:
  718. case EVDF_ARB_FRAGMENT_PROGRAM_1:
  719. return FeatureAvailable[IRR_ARB_fragment_program] || FeatureAvailable[IRR_NV_fragment_program];
  720. case EVDF_PIXEL_SHADER_2_0:
  721. case EVDF_VERTEX_SHADER_2_0:
  722. case EVDF_ARB_GLSL:
  723. return (FeatureAvailable[IRR_ARB_shading_language_100]||Version>=200);
  724. case EVDF_TEXTURE_NSQUARE:
  725. return true; // non-square is always supported
  726. case EVDF_TEXTURE_NPOT:
  727. // Some ATI cards seem to have only SW support in OpenGL 2.0
  728. // drivers if the extension is not exposed, so we skip this
  729. // extra test for now!
  730. // return (FeatureAvailable[IRR_ARB_texture_non_power_of_two]||Version>=200);
  731. return (FeatureAvailable[IRR_ARB_texture_non_power_of_two]);
  732. case EVDF_FRAMEBUFFER_OBJECT:
  733. return FeatureAvailable[IRR_EXT_framebuffer_object] || FeatureAvailable[IRR_ARB_framebuffer_object];
  734. case EVDF_VERTEX_BUFFER_OBJECT:
  735. return FeatureAvailable[IRR_ARB_vertex_buffer_object];
  736. case EVDF_COLOR_MASK:
  737. return true;
  738. case EVDF_ALPHA_TO_COVERAGE:
  739. return FeatureAvailable[IRR_ARB_multisample];
  740. case EVDF_GEOMETRY_SHADER:
  741. return FeatureAvailable[IRR_ARB_geometry_shader4] || FeatureAvailable[IRR_EXT_geometry_shader4] || FeatureAvailable[IRR_NV_geometry_program4] || FeatureAvailable[IRR_NV_geometry_shader4];
  742. case EVDF_MULTIPLE_RENDER_TARGETS:
  743. return FeatureAvailable[IRR_ARB_draw_buffers] || FeatureAvailable[IRR_ATI_draw_buffers];
  744. case EVDF_MRT_BLEND:
  745. case EVDF_MRT_COLOR_MASK:
  746. return FeatureAvailable[IRR_EXT_draw_buffers2];
  747. case EVDF_MRT_BLEND_FUNC:
  748. return FeatureAvailable[IRR_ARB_draw_buffers_blend] || FeatureAvailable[IRR_AMD_draw_buffers_blend];
  749. case EVDF_OCCLUSION_QUERY:
  750. return FeatureAvailable[IRR_ARB_occlusion_query] && OcclusionQuerySupport;
  751. case EVDF_POLYGON_OFFSET:
  752. // both features supported with OpenGL 1.1
  753. return Version>=110;
  754. case EVDF_BLEND_OPERATIONS:
  755. return (Version>=120) || FeatureAvailable[IRR_EXT_blend_minmax] ||
  756. FeatureAvailable[IRR_EXT_blend_subtract] || FeatureAvailable[IRR_EXT_blend_logic_op];
  757. case EVDF_TEXTURE_MATRIX:
  758. return true;
  759. default:
  760. return false;
  761. };
  762. }
  763. }
  764. }
  765. #endif