gfxGLDevice.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gfx/gl/gfxGLDevice.h"
  24. #include "platform/platformGL.h"
  25. #include "gfx/gfxCubemap.h"
  26. #include "gfx/gl/screenshotGL.h"
  27. #include "gfx/gfxDrawUtil.h"
  28. #include "gfx/gl/gfxGLEnumTranslate.h"
  29. #include "gfx/gl/gfxGLVertexBuffer.h"
  30. #include "gfx/gl/gfxGLPrimitiveBuffer.h"
  31. #include "gfx/gl/gfxGLTextureTarget.h"
  32. #include "gfx/gl/gfxGLTextureManager.h"
  33. #include "gfx/gl/gfxGLTextureObject.h"
  34. #include "gfx/gl/gfxGLCubemap.h"
  35. #include "gfx/gl/gfxGLCardProfiler.h"
  36. #include "gfx/gl/gfxGLWindowTarget.h"
  37. #include "platform/platformDlibrary.h"
  38. #include "gfx/gl/gfxGLShader.h"
  39. #include "gfx/primBuilder.h"
  40. #include "console/console.h"
  41. #include "gfx/gl/gfxGLOcclusionQuery.h"
  42. #include "materials/shaderData.h"
  43. #include "gfx/gl/gfxGLStateCache.h"
  44. #include "gfx/gl/gfxGLVertexAttribLocation.h"
  45. #include "gfx/gl/gfxGLVertexDecl.h"
  46. #include "shaderGen/shaderGen.h"
  47. #include "gfxGLUtils.h"
  48. GFXAdapter::CreateDeviceInstanceDelegate GFXGLDevice::mCreateDeviceInstance(GFXGLDevice::createInstance);
  49. GFXDevice *GFXGLDevice::createInstance( U32 adapterIndex )
  50. {
  51. return new GFXGLDevice(adapterIndex);
  52. }
  53. namespace GL
  54. {
  55. extern void gglPerformBinds();
  56. extern void gglPerformExtensionBinds(void *context);
  57. }
  58. void loadGLCore()
  59. {
  60. static bool coreLoaded = false; // Guess what this is for.
  61. if(coreLoaded)
  62. return;
  63. coreLoaded = true;
  64. // Make sure we've got our GL bindings.
  65. GL::gglPerformBinds();
  66. }
  67. void loadGLExtensions(void *context)
  68. {
  69. static bool extensionsLoaded = false;
  70. if(extensionsLoaded)
  71. return;
  72. extensionsLoaded = true;
  73. GL::gglPerformExtensionBinds(context);
  74. }
  75. void STDCALL glDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
  76. const GLchar *message, const void *userParam)
  77. {
  78. // JTH [11/24/2016]: This is a temporary fix so that we do not get spammed for redundant fbo changes.
  79. // This only happens on Intel cards. This should be looked into sometime in the near future.
  80. if (dStrStartsWith(message, "API_ID_REDUNDANT_FBO"))
  81. return;
  82. if (severity == GL_DEBUG_SEVERITY_HIGH)
  83. Con::errorf("OPENGL: %s", message);
  84. else if (severity == GL_DEBUG_SEVERITY_MEDIUM)
  85. Con::warnf("OPENGL: %s", message);
  86. else if (severity == GL_DEBUG_SEVERITY_LOW)
  87. Con::printf("OPENGL: %s", message);
  88. }
  89. void STDCALL glAmdDebugCallback(GLuint id, GLenum category, GLenum severity, GLsizei length,
  90. const GLchar* message, GLvoid* userParam)
  91. {
  92. if (severity == GL_DEBUG_SEVERITY_HIGH)
  93. Con::errorf("AMDOPENGL: %s", message);
  94. else if (severity == GL_DEBUG_SEVERITY_MEDIUM)
  95. Con::warnf("AMDOPENGL: %s", message);
  96. else if (severity == GL_DEBUG_SEVERITY_LOW)
  97. Con::printf("AMDOPENGL: %s", message);
  98. }
  99. void GFXGLDevice::initGLState()
  100. {
  101. // We don't currently need to sync device state with a known good place because we are
  102. // going to set everything in GFXGLStateBlock, but if we change our GFXGLStateBlock strategy, this may
  103. // need to happen.
  104. // Deal with the card profiler here when we know we have a valid context.
  105. mCardProfiler = new GFXGLCardProfiler();
  106. mCardProfiler->init();
  107. glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (GLint*)&mMaxShaderTextures);
  108. // JTH: Needs removed, ffp
  109. //glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint*)&mMaxFFTextures);
  110. glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, (GLint*)&mMaxTRColors);
  111. mMaxTRColors = getMin( mMaxTRColors, (U32)(GFXTextureTarget::MaxRenderSlotId-1) );
  112. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  113. // [JTH 5/6/2016] GLSL 1.50 is really SM 4.0
  114. // Setting mPixelShaderVersion to 3.0 will allow Advanced Lighting to run.
  115. mPixelShaderVersion = 3.0;
  116. // Set capability extensions.
  117. mCapabilities.anisotropicFiltering = mCardProfiler->queryProfile("GL_EXT_texture_filter_anisotropic");
  118. mCapabilities.bufferStorage = mCardProfiler->queryProfile("GL_ARB_buffer_storage");
  119. mCapabilities.textureStorage = mCardProfiler->queryProfile("GL_ARB_texture_storage");
  120. mCapabilities.copyImage = mCardProfiler->queryProfile("GL_ARB_copy_image");
  121. mCapabilities.vertexAttributeBinding = mCardProfiler->queryProfile("GL_ARB_vertex_attrib_binding");
  122. mCapabilities.khrDebug = mCardProfiler->queryProfile("GL_KHR_debug");
  123. mCapabilities.extDebugMarker = mCardProfiler->queryProfile("GL_EXT_debug_marker");
  124. String vendorStr = (const char*)glGetString( GL_VENDOR );
  125. if( vendorStr.find("NVIDIA", 0, String::NoCase | String::Left) != String::NPos)
  126. mUseGlMap = false;
  127. // Workaround for all Mac's, has a problem using glMap* with volatile buffers
  128. #ifdef TORQUE_OS_MAC
  129. mUseGlMap = false;
  130. #endif
  131. #if TORQUE_DEBUG
  132. if( gglHasExtension(ARB_debug_output) )
  133. {
  134. glEnable(GL_DEBUG_OUTPUT);
  135. glDebugMessageCallbackARB(glDebugCallback, NULL);
  136. glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  137. GLuint unusedIds = 0;
  138. glDebugMessageControlARB(GL_DONT_CARE,
  139. GL_DONT_CARE,
  140. GL_DONT_CARE,
  141. 0,
  142. &unusedIds,
  143. GL_TRUE);
  144. }
  145. else if(gglHasExtension(AMD_debug_output))
  146. {
  147. glEnable(GL_DEBUG_OUTPUT);
  148. glDebugMessageCallbackAMD(glAmdDebugCallback, NULL);
  149. //glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  150. GLuint unusedIds = 0;
  151. glDebugMessageEnableAMD(GL_DONT_CARE, GL_DONT_CARE, 0,&unusedIds, GL_TRUE);
  152. }
  153. #endif
  154. PlatformGL::setVSync(smDisableVSync ? 0 : 1);
  155. //install vsync callback
  156. Con::NotifyDelegate clbk(this, &GFXGLDevice::vsyncCallback);
  157. Con::addVariableNotify("$pref::Video::disableVerticalSync", clbk);
  158. //OpenGL 3 need a binded VAO for render
  159. GLuint vao;
  160. glGenVertexArrays(1, &vao);
  161. glBindVertexArray(vao);
  162. //enable sRGB
  163. glEnable(GL_FRAMEBUFFER_SRGB);
  164. }
  165. void GFXGLDevice::vsyncCallback()
  166. {
  167. PlatformGL::setVSync(smDisableVSync ? 0 : 1);
  168. }
  169. GFXGLDevice::GFXGLDevice(U32 adapterIndex) :
  170. mAdapterIndex(adapterIndex),
  171. mNeedUpdateVertexAttrib(false),
  172. mCurrentPB(NULL),
  173. mDrawInstancesCount(0),
  174. mCurrentShader( NULL ),
  175. m_mCurrentWorld(true),
  176. m_mCurrentView(true),
  177. mContext(NULL),
  178. mPixelFormat(NULL),
  179. mPixelShaderVersion(0.0f),
  180. mMaxShaderTextures(2),
  181. mMaxFFTextures(2),
  182. mMaxTRColors(1),
  183. mClip(0, 0, 0, 0),
  184. mWindowRT(NULL),
  185. mUseGlMap(true)
  186. {
  187. for(int i = 0; i < VERTEX_STREAM_COUNT; ++i)
  188. {
  189. mCurrentVB[i] = NULL;
  190. mCurrentVB_Divisor[i] = 0;
  191. }
  192. // Initiailize capabilities to false.
  193. memset(&mCapabilities, 0, sizeof(GLCapabilities));
  194. loadGLCore();
  195. GFXGLEnumTranslate::init();
  196. GFXVertexColor::setSwizzle( &Swizzles::rgba );
  197. // OpenGL have native RGB, no need swizzle
  198. mDeviceSwizzle32 = &Swizzles::rgba;
  199. mDeviceSwizzle24 = &Swizzles::rgb;
  200. mTextureManager = new GFXGLTextureManager();
  201. gScreenShot = new ScreenShotGL();
  202. for(U32 i = 0; i < TEXTURE_STAGE_COUNT; i++)
  203. mActiveTextureType[i] = GL_ZERO;
  204. mNumVertexStream = 2;
  205. mSupportsAnisotropic = false;
  206. for(int i = 0; i < GS_COUNT; ++i)
  207. mModelViewProjSC[i] = NULL;
  208. mOpenglStateCache = new GFXGLStateCache;
  209. }
  210. GFXGLDevice::~GFXGLDevice()
  211. {
  212. mCurrentStateBlock = NULL;
  213. for(int i = 0; i < VERTEX_STREAM_COUNT; ++i)
  214. mCurrentVB[i] = NULL;
  215. mCurrentPB = NULL;
  216. for(U32 i = 0; i < mVolatileVBs.size(); i++)
  217. mVolatileVBs[i] = NULL;
  218. for(U32 i = 0; i < mVolatilePBs.size(); i++)
  219. mVolatilePBs[i] = NULL;
  220. // Clear out our current texture references
  221. for (U32 i = 0; i < TEXTURE_STAGE_COUNT; i++)
  222. {
  223. mCurrentTexture[i] = NULL;
  224. mNewTexture[i] = NULL;
  225. mCurrentCubemap[i] = NULL;
  226. mNewCubemap[i] = NULL;
  227. }
  228. mRTStack.clear();
  229. mCurrentRT = NULL;
  230. if( mTextureManager )
  231. {
  232. mTextureManager->zombify();
  233. mTextureManager->kill();
  234. }
  235. GFXResource* walk = mResourceListHead;
  236. while(walk)
  237. {
  238. walk->zombify();
  239. walk = walk->getNextResource();
  240. }
  241. if( mCardProfiler )
  242. SAFE_DELETE( mCardProfiler );
  243. SAFE_DELETE( gScreenShot );
  244. SAFE_DELETE( mOpenglStateCache );
  245. }
  246. void GFXGLDevice::zombify()
  247. {
  248. mTextureManager->zombify();
  249. for(int i = 0; i < VERTEX_STREAM_COUNT; ++i)
  250. if(mCurrentVB[i])
  251. mCurrentVB[i]->finish();
  252. if(mCurrentPB)
  253. mCurrentPB->finish();
  254. //mVolatileVBs.clear();
  255. //mVolatilePBs.clear();
  256. GFXResource* walk = mResourceListHead;
  257. while(walk)
  258. {
  259. walk->zombify();
  260. walk = walk->getNextResource();
  261. }
  262. }
  263. void GFXGLDevice::resurrect()
  264. {
  265. GFXResource* walk = mResourceListHead;
  266. while(walk)
  267. {
  268. walk->resurrect();
  269. walk = walk->getNextResource();
  270. }
  271. for(int i = 0; i < VERTEX_STREAM_COUNT; ++i)
  272. if(mCurrentVB[i])
  273. mCurrentVB[i]->prepare();
  274. if(mCurrentPB)
  275. mCurrentPB->prepare();
  276. mTextureManager->resurrect();
  277. }
  278. GFXVertexBuffer* GFXGLDevice::findVolatileVBO(U32 numVerts, const GFXVertexFormat *vertexFormat, U32 vertSize)
  279. {
  280. PROFILE_SCOPE(GFXGLDevice_findVBPool);
  281. for(U32 i = 0; i < mVolatileVBs.size(); i++)
  282. if ( mVolatileVBs[i]->mNumVerts >= numVerts &&
  283. mVolatileVBs[i]->mVertexFormat.isEqual( *vertexFormat ) &&
  284. mVolatileVBs[i]->mVertexSize == vertSize &&
  285. mVolatileVBs[i]->getRefCount() == 1 )
  286. return mVolatileVBs[i];
  287. // No existing VB, so create one
  288. PROFILE_SCOPE(GFXGLDevice_createVBPool);
  289. StrongRefPtr<GFXGLVertexBuffer> buf(new GFXGLVertexBuffer(GFX, numVerts, vertexFormat, vertSize, GFXBufferTypeVolatile));
  290. buf->registerResourceWithDevice(this);
  291. mVolatileVBs.push_back(buf);
  292. return buf.getPointer();
  293. }
  294. GFXPrimitiveBuffer* GFXGLDevice::findVolatilePBO(U32 numIndices, U32 numPrimitives)
  295. {
  296. for(U32 i = 0; i < mVolatilePBs.size(); i++)
  297. if((mVolatilePBs[i]->mIndexCount >= numIndices) && (mVolatilePBs[i]->getRefCount() == 1))
  298. return mVolatilePBs[i];
  299. // No existing PB, so create one
  300. StrongRefPtr<GFXGLPrimitiveBuffer> buf(new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, GFXBufferTypeVolatile));
  301. buf->registerResourceWithDevice(this);
  302. mVolatilePBs.push_back(buf);
  303. return buf.getPointer();
  304. }
  305. GFXVertexBuffer *GFXGLDevice::allocVertexBuffer( U32 numVerts,
  306. const GFXVertexFormat *vertexFormat,
  307. U32 vertSize,
  308. GFXBufferType bufferType,
  309. void* data )
  310. {
  311. PROFILE_SCOPE(GFXGLDevice_allocVertexBuffer);
  312. if(bufferType == GFXBufferTypeVolatile)
  313. return findVolatileVBO(numVerts, vertexFormat, vertSize);
  314. GFXGLVertexBuffer* buf = new GFXGLVertexBuffer( GFX, numVerts, vertexFormat, vertSize, bufferType );
  315. buf->registerResourceWithDevice(this);
  316. if(data)
  317. {
  318. void* dest;
  319. buf->lock(0, numVerts, &dest);
  320. dMemcpy(dest, data, vertSize * numVerts);
  321. buf->unlock();
  322. }
  323. return buf;
  324. }
  325. GFXPrimitiveBuffer *GFXGLDevice::allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void* data )
  326. {
  327. GFXPrimitiveBuffer* buf;
  328. if(bufferType == GFXBufferTypeVolatile)
  329. {
  330. buf = findVolatilePBO(numIndices, numPrimitives);
  331. }
  332. else
  333. {
  334. buf = new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
  335. buf->registerResourceWithDevice(this);
  336. }
  337. if(data)
  338. {
  339. void* dest;
  340. buf->lock(0, numIndices, &dest);
  341. dMemcpy(dest, data, sizeof(U16) * numIndices);
  342. buf->unlock();
  343. }
  344. return buf;
  345. }
  346. void GFXGLDevice::setVertexStream( U32 stream, GFXVertexBuffer *buffer )
  347. {
  348. AssertFatal(stream <= 1, "GFXGLDevice::setVertexStream only support 2 stream (0: data, 1: instancing)");
  349. //if(mCurrentVB[stream] != buffer)
  350. {
  351. // Reset the state the old VB required, then set the state the new VB requires.
  352. if( mCurrentVB[stream] )
  353. {
  354. mCurrentVB[stream]->finish();
  355. }
  356. mCurrentVB[stream] = static_cast<GFXGLVertexBuffer*>( buffer );
  357. mNeedUpdateVertexAttrib = true;
  358. }
  359. }
  360. void GFXGLDevice::setVertexStreamFrequency( U32 stream, U32 frequency )
  361. {
  362. if( stream == 0 )
  363. {
  364. mCurrentVB_Divisor[stream] = 0; // non instanced, is vertex buffer
  365. mDrawInstancesCount = frequency; // instances count
  366. }
  367. else
  368. {
  369. AssertFatal(frequency <= 1, "GFXGLDevice::setVertexStreamFrequency only support 0/1 for this stream" );
  370. if( stream == 1 && frequency == 1 )
  371. mCurrentVB_Divisor[stream] = 1; // instances data need a frequency of 1
  372. else
  373. mCurrentVB_Divisor[stream] = 0;
  374. }
  375. mNeedUpdateVertexAttrib = true;
  376. }
  377. GFXCubemap* GFXGLDevice::createCubemap()
  378. {
  379. GFXGLCubemap* cube = new GFXGLCubemap();
  380. cube->registerResourceWithDevice(this);
  381. return cube;
  382. };
  383. GFXCubemapArray *GFXGLDevice::createCubemapArray()
  384. {
  385. GFXGLCubemapArray* cubeArray = new GFXGLCubemapArray();
  386. cubeArray->registerResourceWithDevice(this);
  387. return cubeArray;
  388. }
  389. void GFXGLDevice::endSceneInternal()
  390. {
  391. // nothing to do for opengl
  392. mCanCurrentlyRender = false;
  393. }
  394. void GFXGLDevice::copyResource(GFXTextureObject* pDst, GFXCubemap* pSrc, const U32 face)
  395. {
  396. AssertFatal(pDst, "GFXGLDevice::copyResource: Destination texture is null");
  397. AssertFatal(pSrc, "GFXGLDevice::copyResource: Source cubemap is null");
  398. GFXGLTextureObject* gGLDst = static_cast<GFXGLTextureObject*>(pDst);
  399. GFXGLCubemap* pGLSrc = static_cast<GFXGLCubemap*>(pSrc);
  400. const GFXFormat format = pGLSrc->getFormat();
  401. const bool isCompressed = ImageUtil::isCompressedFormat(format);
  402. const U32 mipLevels = pGLSrc->getMipMapLevels();
  403. const U32 texSize = pGLSrc->getSize();
  404. //set up pbo if we don't have copyImage support
  405. if (!GFXGL->mCapabilities.copyImage)
  406. {
  407. const GLuint pbo = gGLDst->getBuffer();
  408. glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
  409. //allocate data
  410. glBufferData(GL_PIXEL_PACK_BUFFER, texSize * texSize * GFXFormat_getByteSize(format), NULL, GL_STREAM_COPY);
  411. }
  412. for (U32 mip = 0; mip < mipLevels; mip++)
  413. {
  414. const U32 mipSize = texSize >> mip;
  415. if (GFXGL->mCapabilities.copyImage)
  416. {
  417. glCopyImageSubData(pGLSrc->mCubemap, GL_TEXTURE_CUBE_MAP, mip, 0, 0, face, gGLDst->getHandle(), GL_TEXTURE_2D, mip, 0, 0, 0, mipSize, mipSize, 1);
  418. }
  419. else
  420. {
  421. //pbo id
  422. const GLuint pbo = gGLDst->getBuffer();
  423. //copy source texture data to pbo
  424. glBindTexture(GL_TEXTURE_CUBE_MAP, pGLSrc->mCubemap);
  425. glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
  426. if (isCompressed)
  427. glGetCompressedTexImage(GFXGLFaceType[face], mip, NULL);
  428. else
  429. glGetTexImage(GFXGLFaceType[face], mip, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL);
  430. glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
  431. glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
  432. //copy data from pbo to destination
  433. glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
  434. glBindTexture(gGLDst->getBinding(), gGLDst->getHandle());
  435. if (isCompressed)
  436. {
  437. const U32 mipDataSize = getCompressedSurfaceSize(format, pGLSrc->getSize(), pGLSrc->getSize(), 0);
  438. glCompressedTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], mipDataSize, NULL);
  439. }
  440. else
  441. {
  442. glTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL);
  443. }
  444. glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
  445. glBindTexture(gGLDst->getBinding(), 0);
  446. }
  447. }
  448. }
  449. void GFXGLDevice::clear(U32 flags, const LinearColorF& color, F32 z, U32 stencil)
  450. {
  451. // Make sure we have flushed our render target state.
  452. _updateRenderTargets();
  453. bool writeAllColors = true;
  454. bool zwrite = true;
  455. bool writeAllStencil = true;
  456. const GFXStateBlockDesc *desc = NULL;
  457. if (mCurrentGLStateBlock)
  458. {
  459. desc = &mCurrentGLStateBlock->getDesc();
  460. zwrite = desc->zWriteEnable;
  461. writeAllColors = desc->colorWriteRed && desc->colorWriteGreen && desc->colorWriteBlue && desc->colorWriteAlpha;
  462. writeAllStencil = desc->stencilWriteMask == 0xFFFFFFFF;
  463. }
  464. glColorMask(true, true, true, true);
  465. glDepthMask(true);
  466. glStencilMask(0xFFFFFFFF);
  467. glClearColor(color.red, color.green, color.blue, color.alpha);
  468. glClearDepth(z);
  469. glClearStencil(stencil);
  470. GLbitfield clearflags = 0;
  471. clearflags |= (flags & GFXClearTarget) ? GL_COLOR_BUFFER_BIT : 0;
  472. clearflags |= (flags & GFXClearZBuffer) ? GL_DEPTH_BUFFER_BIT : 0;
  473. clearflags |= (flags & GFXClearStencil) ? GL_STENCIL_BUFFER_BIT : 0;
  474. glClear(clearflags);
  475. if(!writeAllColors)
  476. glColorMask(desc->colorWriteRed, desc->colorWriteGreen, desc->colorWriteBlue, desc->colorWriteAlpha);
  477. if(!zwrite)
  478. glDepthMask(false);
  479. if(!writeAllStencil)
  480. glStencilMask(desc->stencilWriteMask);
  481. }
  482. void GFXGLDevice::clearColorAttachment(const U32 attachment, const LinearColorF& color)
  483. {
  484. const GLfloat clearColor[4] = { color.red, color.green, color.blue, color.alpha };
  485. glClearBufferfv(GL_COLOR, attachment, clearColor);
  486. }
  487. // Given a primitive type and a number of primitives, return the number of indexes/vertexes used.
  488. inline GLsizei GFXGLDevice::primCountToIndexCount(GFXPrimitiveType primType, U32 primitiveCount)
  489. {
  490. switch (primType)
  491. {
  492. case GFXPointList :
  493. return primitiveCount;
  494. break;
  495. case GFXLineList :
  496. return primitiveCount * 2;
  497. break;
  498. case GFXLineStrip :
  499. return primitiveCount + 1;
  500. break;
  501. case GFXTriangleList :
  502. return primitiveCount * 3;
  503. break;
  504. case GFXTriangleStrip :
  505. return 2 + primitiveCount;
  506. break;
  507. default:
  508. AssertFatal(false, "GFXGLDevice::primCountToIndexCount - unrecognized prim type");
  509. break;
  510. }
  511. return 0;
  512. }
  513. GFXVertexDecl* GFXGLDevice::allocVertexDecl( const GFXVertexFormat *vertexFormat )
  514. {
  515. PROFILE_SCOPE(GFXGLDevice_allocVertexDecl);
  516. typedef Map<void*, GFXGLVertexDecl> GFXGLVertexDeclMap;
  517. static GFXGLVertexDeclMap declMap;
  518. GFXGLVertexDeclMap::Iterator itr = declMap.find( (void*)vertexFormat->getDescription().c_str() ); // description string are interned, safe to use c_str()
  519. if(itr != declMap.end())
  520. return &itr->value;
  521. GFXGLVertexDecl &decl = declMap[(void*)vertexFormat->getDescription().c_str()];
  522. decl.init(vertexFormat);
  523. return &decl;
  524. }
  525. void GFXGLDevice::setVertexDecl( const GFXVertexDecl *decl )
  526. {
  527. static_cast<const GFXGLVertexDecl*>(decl)->prepareVertexFormat();
  528. }
  529. inline void GFXGLDevice::preDrawPrimitive()
  530. {
  531. if( mStateDirty )
  532. {
  533. updateStates();
  534. }
  535. if(mCurrentShaderConstBuffer)
  536. setShaderConstBufferInternal(mCurrentShaderConstBuffer);
  537. if( mNeedUpdateVertexAttrib )
  538. {
  539. AssertFatal(mCurrVertexDecl, "");
  540. const GFXGLVertexDecl* decl = static_cast<const GFXGLVertexDecl*>(mCurrVertexDecl);
  541. for(int i = 0; i < getNumVertexStreams(); ++i)
  542. {
  543. if(mCurrentVB[i])
  544. {
  545. mCurrentVB[i]->prepare(i, mCurrentVB_Divisor[i]); // GL_ARB_vertex_attrib_binding
  546. decl->prepareBuffer_old( i, mCurrentVB[i]->mBuffer, mCurrentVB_Divisor[i] ); // old vertex buffer/format
  547. }
  548. }
  549. decl->updateActiveVertexAttrib( GFXGL->getOpenglCache()->getCacheVertexAttribActive() );
  550. }
  551. mNeedUpdateVertexAttrib = false;
  552. }
  553. inline void GFXGLDevice::postDrawPrimitive(U32 primitiveCount)
  554. {
  555. mDeviceStatistics.mDrawCalls++;
  556. mDeviceStatistics.mPolyCount += primitiveCount;
  557. }
  558. void GFXGLDevice::drawPrimitive( GFXPrimitiveType primType, U32 vertexStart, U32 primitiveCount )
  559. {
  560. preDrawPrimitive();
  561. if(mCurrentVB[0])
  562. vertexStart += mCurrentVB[0]->mBufferVertexOffset;
  563. if(mDrawInstancesCount)
  564. glDrawArraysInstanced(GFXGLPrimType[primType], vertexStart, primCountToIndexCount(primType, primitiveCount), mDrawInstancesCount);
  565. else
  566. glDrawArrays(GFXGLPrimType[primType], vertexStart, primCountToIndexCount(primType, primitiveCount));
  567. postDrawPrimitive(primitiveCount);
  568. }
  569. void GFXGLDevice::drawIndexedPrimitive( GFXPrimitiveType primType,
  570. U32 startVertex,
  571. U32 minIndex,
  572. U32 numVerts,
  573. U32 startIndex,
  574. U32 primitiveCount )
  575. {
  576. preDrawPrimitive();
  577. U16* buf = (U16*)static_cast<GFXGLPrimitiveBuffer*>(mCurrentPrimitiveBuffer.getPointer())->getBuffer() + startIndex + mCurrentPrimitiveBuffer->mVolatileStart;
  578. const U32 baseVertex = mCurrentVB[0]->mBufferVertexOffset + startVertex;
  579. if(mDrawInstancesCount)
  580. glDrawElementsInstancedBaseVertex(GFXGLPrimType[primType], primCountToIndexCount(primType, primitiveCount), GL_UNSIGNED_SHORT, buf, mDrawInstancesCount, baseVertex);
  581. else
  582. glDrawElementsBaseVertex(GFXGLPrimType[primType], primCountToIndexCount(primType, primitiveCount), GL_UNSIGNED_SHORT, buf, baseVertex);
  583. postDrawPrimitive(primitiveCount);
  584. }
  585. void GFXGLDevice::setPB(GFXGLPrimitiveBuffer* pb)
  586. {
  587. if(mCurrentPB)
  588. mCurrentPB->finish();
  589. mCurrentPB = pb;
  590. }
  591. void GFXGLDevice::setLightInternal(U32 lightStage, const GFXLightInfo light, bool lightEnable)
  592. {
  593. // ONLY NEEDED ON FFP
  594. }
  595. void GFXGLDevice::setLightMaterialInternal(const GFXLightMaterial mat)
  596. {
  597. // ONLY NEEDED ON FFP
  598. }
  599. void GFXGLDevice::setGlobalAmbientInternal(LinearColorF color)
  600. {
  601. // ONLY NEEDED ON FFP
  602. }
  603. void GFXGLDevice::setTextureInternal(U32 textureUnit, const GFXTextureObject*texture)
  604. {
  605. GFXGLTextureObject *tex = static_cast<GFXGLTextureObject*>(const_cast<GFXTextureObject*>(texture));
  606. if (tex)
  607. {
  608. mActiveTextureType[textureUnit] = tex->getBinding();
  609. tex->bind(textureUnit);
  610. }
  611. else if(mActiveTextureType[textureUnit] != GL_ZERO)
  612. {
  613. glActiveTexture(GL_TEXTURE0 + textureUnit);
  614. glBindTexture(mActiveTextureType[textureUnit], 0);
  615. getOpenglCache()->setCacheBindedTex(textureUnit, mActiveTextureType[textureUnit], 0);
  616. mActiveTextureType[textureUnit] = GL_ZERO;
  617. }
  618. }
  619. void GFXGLDevice::setCubemapInternal(U32 textureUnit, const GFXGLCubemap* texture)
  620. {
  621. if(texture)
  622. {
  623. mActiveTextureType[textureUnit] = GL_TEXTURE_CUBE_MAP;
  624. texture->bind(textureUnit);
  625. }
  626. else if(mActiveTextureType[textureUnit] != GL_ZERO)
  627. {
  628. glActiveTexture(GL_TEXTURE0 + textureUnit);
  629. glBindTexture(mActiveTextureType[textureUnit], 0);
  630. getOpenglCache()->setCacheBindedTex(textureUnit, mActiveTextureType[textureUnit], 0);
  631. mActiveTextureType[textureUnit] = GL_ZERO;
  632. }
  633. }
  634. void GFXGLDevice::setCubemapArrayInternal(U32 textureUnit, const GFXGLCubemapArray* texture)
  635. {
  636. if (texture)
  637. {
  638. mActiveTextureType[textureUnit] = GL_TEXTURE_CUBE_MAP_ARRAY_ARB;
  639. texture->bind(textureUnit);
  640. }
  641. else if (mActiveTextureType[textureUnit] != GL_ZERO)
  642. {
  643. glActiveTexture(GL_TEXTURE0 + textureUnit);
  644. glBindTexture(mActiveTextureType[textureUnit], 0);
  645. getOpenglCache()->setCacheBindedTex(textureUnit, mActiveTextureType[textureUnit], 0);
  646. mActiveTextureType[textureUnit] = GL_ZERO;
  647. }
  648. }
  649. void GFXGLDevice::setMatrix( GFXMatrixType mtype, const MatrixF &mat )
  650. {
  651. // ONLY NEEDED ON FFP
  652. }
  653. void GFXGLDevice::setClipRect( const RectI &inRect )
  654. {
  655. AssertFatal(mCurrentRT.isValid(), "GFXGLDevice::setClipRect - must have a render target set to do any rendering operations!");
  656. // Clip the rect against the renderable size.
  657. Point2I size = mCurrentRT->getSize();
  658. RectI maxRect(Point2I(0,0), size);
  659. mClip = inRect;
  660. mClip.intersect(maxRect);
  661. // Create projection matrix. See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/ortho.html
  662. const F32 left = mClip.point.x;
  663. const F32 right = mClip.point.x + mClip.extent.x;
  664. const F32 bottom = mClip.extent.y;
  665. const F32 top = 0.0f;
  666. const F32 nearPlane = 0.0f;
  667. const F32 farPlane = 1.0f;
  668. const F32 tx = -(right + left)/(right - left);
  669. const F32 ty = -(top + bottom)/(top - bottom);
  670. const F32 tz = -(farPlane + nearPlane)/(farPlane - nearPlane);
  671. static Point4F pt;
  672. pt.set(2.0f / (right - left), 0.0f, 0.0f, 0.0f);
  673. mProjectionMatrix.setColumn(0, pt);
  674. pt.set(0.0f, 2.0f/(top - bottom), 0.0f, 0.0f);
  675. mProjectionMatrix.setColumn(1, pt);
  676. pt.set(0.0f, 0.0f, -2.0f/(farPlane - nearPlane), 0.0f);
  677. mProjectionMatrix.setColumn(2, pt);
  678. pt.set(tx, ty, tz, 1.0f);
  679. mProjectionMatrix.setColumn(3, pt);
  680. // Translate projection matrix.
  681. static MatrixF translate(true);
  682. pt.set(0.0f, -mClip.point.y, 0.0f, 1.0f);
  683. translate.setColumn(3, pt);
  684. mProjectionMatrix *= translate;
  685. setMatrix(GFXMatrixProjection, mProjectionMatrix);
  686. MatrixF mTempMatrix(true);
  687. setViewMatrix( mTempMatrix );
  688. setWorldMatrix( mTempMatrix );
  689. // Set the viewport to the clip rect
  690. RectI viewport(mClip.point.x, mClip.point.y, mClip.extent.x, mClip.extent.y);
  691. setViewport(viewport);
  692. }
  693. /// Creates a state block object based on the desc passed in. This object
  694. /// represents an immutable state.
  695. GFXStateBlockRef GFXGLDevice::createStateBlockInternal(const GFXStateBlockDesc& desc)
  696. {
  697. return GFXStateBlockRef(new GFXGLStateBlock(desc));
  698. }
  699. /// Activates a stateblock
  700. void GFXGLDevice::setStateBlockInternal(GFXStateBlock* block, bool force)
  701. {
  702. AssertFatal(dynamic_cast<GFXGLStateBlock*>(block), "GFXGLDevice::setStateBlockInternal - Incorrect stateblock type for this device!");
  703. GFXGLStateBlock* glBlock = static_cast<GFXGLStateBlock*>(block);
  704. GFXGLStateBlock* glCurrent = static_cast<GFXGLStateBlock*>(mCurrentStateBlock.getPointer());
  705. if (force)
  706. glCurrent = NULL;
  707. glBlock->activate(glCurrent); // Doesn't use current yet.
  708. mCurrentGLStateBlock = glBlock;
  709. }
  710. //------------------------------------------------------------------------------
  711. GFXTextureTarget * GFXGLDevice::allocRenderToTextureTarget(bool genMips)
  712. {
  713. GFXGLTextureTarget *targ = new GFXGLTextureTarget(genMips);
  714. targ->registerResourceWithDevice(this);
  715. return targ;
  716. }
  717. GFXFence * GFXGLDevice::createFence()
  718. {
  719. GFXFence* fence = _createPlatformSpecificFence();
  720. if(!fence)
  721. fence = new GFXGeneralFence( this );
  722. fence->registerResourceWithDevice(this);
  723. return fence;
  724. }
  725. GFXOcclusionQuery* GFXGLDevice::createOcclusionQuery()
  726. {
  727. GFXOcclusionQuery *query = new GFXGLOcclusionQuery( this );
  728. query->registerResourceWithDevice(this);
  729. return query;
  730. }
  731. void GFXGLDevice::setupGenericShaders( GenericShaderType type )
  732. {
  733. AssertFatal(type != GSTargetRestore, "");
  734. if( mGenericShader[GSColor] == NULL )
  735. {
  736. ShaderData *shaderData;
  737. shaderData = new ShaderData();
  738. shaderData->setField("OGLVertexShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/colorV.glsl"));
  739. shaderData->setField("OGLPixelShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/colorP.glsl"));
  740. shaderData->setField("pixVersion", "2.0");
  741. shaderData->registerObject();
  742. mGenericShader[GSColor] = shaderData->getShader();
  743. mGenericShaderBuffer[GSColor] = mGenericShader[GSColor]->allocConstBuffer();
  744. mModelViewProjSC[GSColor] = mGenericShader[GSColor]->getShaderConstHandle( "$modelView" );
  745. Sim::getRootGroup()->addObject(shaderData);
  746. shaderData = new ShaderData();
  747. shaderData->setField("OGLVertexShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/modColorTextureV.glsl"));
  748. shaderData->setField("OGLPixelShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/modColorTextureP.glsl"));
  749. shaderData->setSamplerName("$diffuseMap", 0);
  750. shaderData->setField("pixVersion", "2.0");
  751. shaderData->registerObject();
  752. mGenericShader[GSModColorTexture] = shaderData->getShader();
  753. mGenericShaderBuffer[GSModColorTexture] = mGenericShader[GSModColorTexture]->allocConstBuffer();
  754. mModelViewProjSC[GSModColorTexture] = mGenericShader[GSModColorTexture]->getShaderConstHandle( "$modelView" );
  755. Sim::getRootGroup()->addObject(shaderData);
  756. shaderData = new ShaderData();
  757. shaderData->setField("OGLVertexShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/addColorTextureV.glsl"));
  758. shaderData->setField("OGLPixelShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/addColorTextureP.glsl"));
  759. shaderData->setSamplerName("$diffuseMap", 0);
  760. shaderData->setField("pixVersion", "2.0");
  761. shaderData->registerObject();
  762. mGenericShader[GSAddColorTexture] = shaderData->getShader();
  763. mGenericShaderBuffer[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->allocConstBuffer();
  764. mModelViewProjSC[GSAddColorTexture] = mGenericShader[GSAddColorTexture]->getShaderConstHandle( "$modelView" );
  765. Sim::getRootGroup()->addObject(shaderData);
  766. shaderData = new ShaderData();
  767. shaderData->setField("OGLVertexShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/textureV.glsl"));
  768. shaderData->setField("OGLPixelShaderFile", ShaderGen::smCommonShaderPath + String("/fixedFunction/gl/textureP.glsl"));
  769. shaderData->setSamplerName("$diffuseMap", 0);
  770. shaderData->setField("pixVersion", "2.0");
  771. shaderData->registerObject();
  772. mGenericShader[GSTexture] = shaderData->getShader();
  773. mGenericShaderBuffer[GSTexture] = mGenericShader[GSTexture]->allocConstBuffer();
  774. mModelViewProjSC[GSTexture] = mGenericShader[GSTexture]->getShaderConstHandle( "$modelView" );
  775. Sim::getRootGroup()->addObject(shaderData);
  776. }
  777. MatrixF tempMatrix = mProjectionMatrix * mViewMatrix * mWorldMatrix[mWorldStackSize];
  778. mGenericShaderBuffer[type]->setSafe(mModelViewProjSC[type], tempMatrix);
  779. setShader( mGenericShader[type] );
  780. setShaderConstBuffer( mGenericShaderBuffer[type] );
  781. }
  782. GFXShader* GFXGLDevice::createShader()
  783. {
  784. GFXGLShader* shader = new GFXGLShader();
  785. shader->registerResourceWithDevice( this );
  786. return shader;
  787. }
  788. void GFXGLDevice::setShader(GFXShader *shader, bool force)
  789. {
  790. if(mCurrentShader == shader && !force)
  791. return;
  792. if ( shader )
  793. {
  794. GFXGLShader *glShader = static_cast<GFXGLShader*>( shader );
  795. glShader->useProgram();
  796. mCurrentShader = shader;
  797. }
  798. else
  799. {
  800. setupGenericShaders();
  801. }
  802. }
  803. void GFXGLDevice::setShaderConstBufferInternal(GFXShaderConstBuffer* buffer)
  804. {
  805. PROFILE_SCOPE(GFXGLDevice_setShaderConstBufferInternal);
  806. static_cast<GFXGLShaderConstBuffer*>(buffer)->activate();
  807. }
  808. U32 GFXGLDevice::getNumSamplers() const
  809. {
  810. return getMin((U32)TEXTURE_STAGE_COUNT,mPixelShaderVersion > 0.001f ? mMaxShaderTextures : mMaxFFTextures);
  811. }
  812. GFXTextureObject* GFXGLDevice::getDefaultDepthTex() const
  813. {
  814. if(mWindowRT && mWindowRT->getPointer())
  815. return static_cast<GFXGLWindowTarget*>( mWindowRT->getPointer() )->mBackBufferDepthTex.getPointer();
  816. return NULL;
  817. }
  818. U32 GFXGLDevice::getNumRenderTargets() const
  819. {
  820. return mMaxTRColors;
  821. }
  822. void GFXGLDevice::_updateRenderTargets()
  823. {
  824. if ( mRTDirty || mCurrentRT->isPendingState() )
  825. {
  826. if ( mRTDeactivate )
  827. {
  828. mRTDeactivate->deactivate();
  829. mRTDeactivate = NULL;
  830. }
  831. // NOTE: The render target changes is not really accurate
  832. // as the GFXTextureTarget supports MRT internally. So when
  833. // we activate a GFXTarget it could result in multiple calls
  834. // to SetRenderTarget on the actual device.
  835. mDeviceStatistics.mRenderTargetChanges++;
  836. GFXGLTextureTarget *tex = dynamic_cast<GFXGLTextureTarget*>( mCurrentRT.getPointer() );
  837. if ( tex )
  838. {
  839. tex->applyState();
  840. tex->makeActive();
  841. }
  842. else
  843. {
  844. GFXGLWindowTarget *win = dynamic_cast<GFXGLWindowTarget*>( mCurrentRT.getPointer() );
  845. AssertFatal( win != NULL,
  846. "GFXGLDevice::_updateRenderTargets() - invalid target subclass passed!" );
  847. win->makeActive();
  848. if( win->mContext != static_cast<GFXGLDevice*>(GFX)->mContext )
  849. {
  850. mRTDirty = false;
  851. GFX->updateStates(true);
  852. }
  853. }
  854. mRTDirty = false;
  855. }
  856. if ( mViewportDirty )
  857. {
  858. glViewport( mViewport.point.x, mViewport.point.y, mViewport.extent.x, mViewport.extent.y );
  859. mViewportDirty = false;
  860. }
  861. }
  862. GFXFormat GFXGLDevice::selectSupportedFormat( GFXTextureProfile* profile,
  863. const Vector<GFXFormat>& formats,
  864. bool texture,
  865. bool mustblend,
  866. bool mustfilter )
  867. {
  868. for(U32 i = 0; i < formats.size(); i++)
  869. {
  870. // Single channel textures are not supported by FBOs.
  871. if(profile->testFlag(GFXTextureProfile::RenderTarget) && (formats[i] == GFXFormatA8 || formats[i] == GFXFormatL8 || formats[i] == GFXFormatL16))
  872. continue;
  873. if(GFXGLTextureInternalFormat[formats[i]] == GL_ZERO)
  874. continue;
  875. return formats[i];
  876. }
  877. return GFXFormatR8G8B8A8;
  878. }
  879. U32 GFXGLDevice::getTotalVideoMemory_GL_EXT()
  880. {
  881. // Source: http://www.opengl.org/registry/specs/ATI/meminfo.txt
  882. if( gglHasExtension(ATI_meminfo) )
  883. {
  884. GLint mem[4] = {0};
  885. glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, mem); // Retrieve the texture pool
  886. /* With mem[0] i get only the total memory free in the pool in KB
  887. *
  888. * mem[0] - total memory free in the pool
  889. * mem[1] - largest available free block in the pool
  890. * mem[2] - total auxiliary memory free
  891. * mem[3] - largest auxiliary free block
  892. */
  893. return mem[0] / 1024;
  894. }
  895. //source http://www.opengl.org/registry/specs/NVX/gpu_memory_info.txt
  896. else if( gglHasExtension(NVX_gpu_memory_info) )
  897. {
  898. GLint mem = 0;
  899. glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &mem);
  900. return mem / 1024;
  901. }
  902. // TODO OPENGL, add supprt for INTEL cards.
  903. return 0;
  904. }
  905. //
  906. // Register this device with GFXInit
  907. //
  908. class GFXGLRegisterDevice
  909. {
  910. public:
  911. GFXGLRegisterDevice()
  912. {
  913. GFXInit::getRegisterDeviceSignal().notify(&GFXGLDevice::enumerateAdapters);
  914. }
  915. };
  916. static GFXGLRegisterDevice pGLRegisterDevice;
  917. DefineEngineFunction(cycleResources, void, (),, "")
  918. {
  919. static_cast<GFXGLDevice*>(GFX)->zombify();
  920. static_cast<GFXGLDevice*>(GFX)->resurrect();
  921. }