Shader.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. /**
  2. * Copyright (c) 2006-2023 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "common/config.h"
  22. #include "Shader.h"
  23. #include "ShaderStage.h"
  24. #include "Graphics.h"
  25. #include "graphics/vertex.h"
  26. // C++
  27. #include <algorithm>
  28. #include <limits>
  29. #include <sstream>
  30. namespace love
  31. {
  32. namespace graphics
  33. {
  34. namespace opengl
  35. {
  36. static bool isBuffer(Shader::UniformType utype)
  37. {
  38. return utype == Shader::UNIFORM_TEXELBUFFER || utype == Shader::UNIFORM_STORAGEBUFFER;
  39. }
  40. Shader::Shader(StrongRef<love::graphics::ShaderStage> stages[SHADERSTAGE_MAX_ENUM], const CompileOptions &options)
  41. : love::graphics::Shader(stages, options)
  42. , program(0)
  43. , splitUniformsPerDraw(false)
  44. , builtinUniforms()
  45. , builtinUniformInfo()
  46. {
  47. // load shader source and create program object
  48. loadVolatile();
  49. }
  50. Shader::~Shader()
  51. {
  52. unloadVolatile();
  53. for (const auto &p : uniforms)
  54. {
  55. // Allocated with malloc().
  56. if (p.second.data != nullptr)
  57. free(p.second.data);
  58. if (p.second.baseType == UNIFORM_SAMPLER || p.second.baseType == UNIFORM_STORAGETEXTURE)
  59. {
  60. for (int i = 0; i < p.second.count; i++)
  61. {
  62. if (p.second.textures[i] != nullptr)
  63. p.second.textures[i]->release();
  64. }
  65. delete[] p.second.textures;
  66. }
  67. else if (isBuffer(p.second.baseType))
  68. {
  69. for (int i = 0; i < p.second.count; i++)
  70. {
  71. if (p.second.buffers[i] != nullptr)
  72. p.second.buffers[i]->release();
  73. }
  74. delete[] p.second.buffers;
  75. }
  76. }
  77. }
  78. void Shader::mapActiveUniforms()
  79. {
  80. // Built-in uniform locations default to -1 (nonexistent.)
  81. for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
  82. {
  83. builtinUniforms[i] = -1;
  84. builtinUniformInfo[i] = nullptr;
  85. }
  86. GLint activeprogram = 0;
  87. glGetIntegerv(GL_CURRENT_PROGRAM, &activeprogram);
  88. gl.useProgram(program);
  89. GLint numuniforms;
  90. glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numuniforms);
  91. GLchar cname[256];
  92. const GLint bufsize = (GLint) (sizeof(cname) / sizeof(GLchar));
  93. std::map<std::string, UniformInfo> olduniforms = uniforms;
  94. uniforms.clear();
  95. auto gfx = Module::getInstance<love::graphics::Graphics>(Module::M_GRAPHICS);
  96. for (int uindex = 0; uindex < numuniforms; uindex++)
  97. {
  98. GLsizei namelen = 0;
  99. GLenum gltype = 0;
  100. UniformInfo u = {};
  101. glGetActiveUniform(program, (GLuint) uindex, bufsize, &namelen, &u.count, &gltype, cname);
  102. u.name = std::string(cname, (size_t) namelen);
  103. u.location = glGetUniformLocation(program, u.name.c_str());
  104. u.access = ACCESS_READ;
  105. computeUniformTypeInfo(gltype, u);
  106. // glGetActiveUniform appends "[0]" to the end of array uniform names...
  107. if (u.name.length() > 3)
  108. {
  109. size_t findpos = u.name.find("[0]");
  110. if (findpos != std::string::npos && findpos == u.name.length() - 3)
  111. u.name.erase(u.name.length() - 3);
  112. }
  113. // If this is a built-in (LOVE-created) uniform, store the location.
  114. BuiltinUniform builtin = BUILTIN_MAX_ENUM;
  115. if (getConstant(u.name.c_str(), builtin))
  116. builtinUniforms[int(builtin)] = u.location;
  117. if (u.location == -1)
  118. continue;
  119. if (!fillUniformReflectionData(u))
  120. continue;
  121. if ((u.baseType == UNIFORM_SAMPLER && builtin != BUILTIN_TEXTURE_MAIN) || u.baseType == UNIFORM_TEXELBUFFER)
  122. {
  123. TextureUnit unit;
  124. unit.type = u.textureType;
  125. unit.active = true;
  126. if (u.baseType == UNIFORM_TEXELBUFFER)
  127. {
  128. unit.isTexelBuffer = true;
  129. unit.texture = gl.getDefaultTexelBuffer();
  130. }
  131. else
  132. {
  133. unit.isTexelBuffer = false;
  134. unit.texture = 0; // Handled below.
  135. }
  136. for (int i = 0; i < u.count; i++)
  137. textureUnits.push_back(unit);
  138. }
  139. else if (u.baseType == UNIFORM_STORAGETEXTURE)
  140. {
  141. StorageTextureBinding binding = {};
  142. binding.gltexture = 0; // Handled below.
  143. binding.type = u.textureType;
  144. if ((u.access & (ACCESS_READ | ACCESS_WRITE)) != 0)
  145. binding.access = GL_READ_WRITE;
  146. else if ((u.access & ACCESS_WRITE) != 0)
  147. binding.access = GL_WRITE_ONLY;
  148. else if ((u.access & ACCESS_READ) != 0)
  149. binding.access = GL_READ_ONLY;
  150. auto fmt = OpenGL::convertPixelFormat(u.storageTextureFormat, false);
  151. binding.internalFormat = fmt.internalformat;
  152. for (int i = 0; i < u.count; i++)
  153. storageTextureBindings.push_back(binding);
  154. }
  155. // Make sure previously set uniform data is preserved, and shader-
  156. // initialized values are retrieved.
  157. auto oldu = olduniforms.find(u.name);
  158. if (oldu != olduniforms.end())
  159. {
  160. u.data = oldu->second.data;
  161. u.dataSize = oldu->second.dataSize;
  162. u.textures = oldu->second.textures;
  163. updateUniform(&u, u.count, true);
  164. }
  165. else
  166. {
  167. u.dataSize = 0;
  168. switch (u.baseType)
  169. {
  170. case UNIFORM_FLOAT:
  171. u.dataSize = sizeof(float) * u.components * u.count;
  172. u.data = malloc(u.dataSize);
  173. break;
  174. case UNIFORM_INT:
  175. case UNIFORM_BOOL:
  176. case UNIFORM_SAMPLER:
  177. case UNIFORM_STORAGETEXTURE:
  178. case UNIFORM_TEXELBUFFER:
  179. u.dataSize = sizeof(int) * u.components * u.count;
  180. u.data = malloc(u.dataSize);
  181. break;
  182. case UNIFORM_UINT:
  183. u.dataSize = sizeof(unsigned int) * u.components * u.count;
  184. u.data = malloc(u.dataSize);
  185. break;
  186. case UNIFORM_MATRIX:
  187. u.dataSize = sizeof(float) * ((size_t)u.matrix.rows * u.matrix.columns) * u.count;
  188. u.data = malloc(u.dataSize);
  189. break;
  190. default:
  191. break;
  192. }
  193. if (u.dataSize > 0)
  194. {
  195. memset(u.data, 0, u.dataSize);
  196. if (u.baseType == UNIFORM_SAMPLER || u.baseType == UNIFORM_TEXELBUFFER)
  197. {
  198. int startunit = (int) textureUnits.size() - u.count;
  199. if (builtin == BUILTIN_TEXTURE_MAIN)
  200. startunit = 0;
  201. for (int i = 0; i < u.count; i++)
  202. u.ints[i] = startunit + i;
  203. glUniform1iv(u.location, u.count, u.ints);
  204. if (u.baseType == UNIFORM_TEXELBUFFER)
  205. {
  206. u.buffers = new love::graphics::Buffer*[u.count];
  207. memset(u.buffers, 0, sizeof(Buffer *) * u.count);
  208. }
  209. else
  210. {
  211. u.textures = new love::graphics::Texture*[u.count];
  212. auto *tex = gfx->getDefaultTexture(u.textureType, u.dataBaseType);
  213. for (int i = 0; i < u.count; i++)
  214. {
  215. tex->retain();
  216. u.textures[i] = tex;
  217. }
  218. }
  219. }
  220. else if (u.baseType == UNIFORM_STORAGETEXTURE)
  221. {
  222. int startbinding = (int) storageTextureBindings.size() - u.count;
  223. for (int i = 0; i < u.count; i++)
  224. u.ints[i] = startbinding + i;
  225. glUniform1iv(u.location, u.count, u.ints);
  226. u.textures = new love::graphics::Texture*[u.count];
  227. if ((u.access & ACCESS_WRITE) != 0)
  228. {
  229. memset(u.textures, 0, sizeof(Texture *) * u.count);
  230. }
  231. else
  232. {
  233. auto *tex = gfx->getDefaultTexture(u.textureType, u.dataBaseType);
  234. for (int i = 0; i < u.count; i++)
  235. {
  236. tex->retain();
  237. u.textures[i] = tex;
  238. }
  239. }
  240. }
  241. }
  242. size_t offset = 0;
  243. // Store any shader-initialized values in our own memory.
  244. for (int i = 0; i < u.count; i++)
  245. {
  246. GLint location = u.location;
  247. if (u.count > 1)
  248. {
  249. std::ostringstream ss;
  250. ss << i;
  251. std::string indexname = u.name + "[" + ss.str() + "]";
  252. location = glGetUniformLocation(program, indexname.c_str());
  253. }
  254. if (location == -1)
  255. continue;
  256. switch (u.baseType)
  257. {
  258. case UNIFORM_FLOAT:
  259. glGetUniformfv(program, location, &u.floats[offset]);
  260. offset += u.components;
  261. break;
  262. case UNIFORM_INT:
  263. case UNIFORM_BOOL:
  264. glGetUniformiv(program, location, &u.ints[offset]);
  265. offset += u.components;
  266. break;
  267. case UNIFORM_UINT:
  268. glGetUniformuiv(program, location, &u.uints[offset]);
  269. offset += u.components;
  270. break;
  271. case UNIFORM_MATRIX:
  272. glGetUniformfv(program, location, &u.floats[offset]);
  273. offset += (size_t)u.matrix.rows * u.matrix.columns;
  274. break;
  275. default:
  276. break;
  277. }
  278. }
  279. }
  280. uniforms[u.name] = u;
  281. if (builtin != BUILTIN_MAX_ENUM)
  282. builtinUniformInfo[(int)builtin] = &uniforms[u.name];
  283. if (u.baseType == UNIFORM_SAMPLER || u.baseType == UNIFORM_STORAGETEXTURE)
  284. {
  285. // Make sure all stored textures have their Volatiles loaded before
  286. // the sendTextures call, since it calls getHandle().
  287. for (int i = 0; i < u.count; i++)
  288. {
  289. if (u.textures[i] == nullptr)
  290. continue;
  291. Volatile *v = dynamic_cast<Volatile *>(u.textures[i]);
  292. if (v != nullptr)
  293. v->loadVolatile();
  294. }
  295. sendTextures(&u, u.textures, u.count, true);
  296. }
  297. else if (u.baseType == UNIFORM_TEXELBUFFER)
  298. {
  299. for (int i = 0; i < u.count; i++)
  300. {
  301. if (u.buffers[i] == nullptr)
  302. continue;
  303. Volatile *v = dynamic_cast<Volatile *>(u.buffers[i]);
  304. if (v != nullptr)
  305. v->loadVolatile();
  306. }
  307. sendBuffers(&u, u.buffers, u.count, true);
  308. }
  309. }
  310. if (gl.isBufferUsageSupported(BUFFERUSAGE_SHADER_STORAGE))
  311. {
  312. GLint numstoragebuffers = 0;
  313. glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numstoragebuffers);
  314. char namebuffer[2048] = { '\0' };
  315. int nextstoragebufferbinding = 0;
  316. for (int sindex = 0; sindex < numstoragebuffers; sindex++)
  317. {
  318. UniformInfo u = {};
  319. u.baseType = UNIFORM_STORAGEBUFFER;
  320. u.access = ACCESS_READ;
  321. GLsizei namelength = 0;
  322. glGetProgramResourceName(program, GL_SHADER_STORAGE_BLOCK, sindex, 2048, &namelength, namebuffer);
  323. u.name = std::string(namebuffer, namelength);
  324. u.count = 1;
  325. if (!fillUniformReflectionData(u))
  326. continue;
  327. // Make sure previously set uniform data is preserved, and shader-
  328. // initialized values are retrieved.
  329. auto oldu = olduniforms.find(u.name);
  330. if (oldu != olduniforms.end())
  331. {
  332. u.data = oldu->second.data;
  333. u.dataSize = oldu->second.dataSize;
  334. u.buffers = oldu->second.buffers;
  335. }
  336. else
  337. {
  338. u.dataSize = sizeof(int) * 1;
  339. u.data = malloc(u.dataSize);
  340. u.ints[0] = -1;
  341. u.buffers = new love::graphics::Buffer * [u.count];
  342. memset(u.buffers, 0, sizeof(Buffer*)* u.count);
  343. }
  344. // Unlike local uniforms and attributes, OpenGL doesn't auto-assign storage
  345. // block bindings if they're unspecified in the shader. So we overwrite them
  346. // regardless, here.
  347. u.ints[0] = nextstoragebufferbinding++;
  348. glShaderStorageBlockBinding(program, sindex, u.ints[0]);
  349. BufferBinding binding;
  350. binding.bindingindex = u.ints[0];
  351. binding.buffer = gl.getDefaultStorageBuffer();
  352. if (binding.bindingindex >= 0)
  353. {
  354. int activeindex = (int)activeStorageBufferBindings.size();
  355. activeStorageBufferBindings.push_back(binding);
  356. auto p = std::make_pair(activeindex, -1);
  357. if (u.access & ACCESS_WRITE)
  358. {
  359. p.second = (int)activeWritableStorageBuffers.size();
  360. activeWritableStorageBuffers.push_back(u.buffers[0]);
  361. }
  362. storageBufferBindingIndexToActiveBinding[binding.bindingindex] = p;
  363. }
  364. uniforms[u.name] = u;
  365. for (int i = 0; i < u.count; i++)
  366. {
  367. if (u.buffers[i] == nullptr)
  368. continue;
  369. Volatile* v = dynamic_cast<Volatile*>(u.buffers[i]);
  370. if (v != nullptr)
  371. v->loadVolatile();
  372. }
  373. sendBuffers(&u, u.buffers, u.count, true);
  374. }
  375. }
  376. // Make sure uniforms that existed before but don't exist anymore are
  377. // cleaned up. This theoretically shouldn't happen, but...
  378. for (const auto &p : olduniforms)
  379. {
  380. if (uniforms.find(p.first) == uniforms.end())
  381. {
  382. if (p.second.data != nullptr)
  383. free(p.second.data);
  384. if (p.second.baseType == UNIFORM_SAMPLER || p.second.baseType == UNIFORM_STORAGETEXTURE)
  385. {
  386. for (int i = 0; i < p.second.count; i++)
  387. {
  388. if (p.second.textures[i] != nullptr)
  389. p.second.textures[i]->release();
  390. }
  391. delete[] p.second.textures;
  392. }
  393. else if (isBuffer(p.second.baseType))
  394. {
  395. for (int i = 0; i < p.second.count; i++)
  396. {
  397. if (p.second.buffers[i] != nullptr)
  398. p.second.buffers[i]->release();
  399. }
  400. delete[] p.second.buffers;
  401. }
  402. }
  403. }
  404. gl.useProgram(activeprogram);
  405. }
  406. bool Shader::loadVolatile()
  407. {
  408. OpenGL::TempDebugGroup debuggroup("Shader load");
  409. // love::graphics::Shader sets up the shader code-side of this.
  410. auto gfx = Module::getInstance<love::graphics::Graphics>(Module::M_GRAPHICS);
  411. if (gfx != nullptr)
  412. splitUniformsPerDraw = !gfx->getCapabilities().features[Graphics::FEATURE_PIXEL_SHADER_HIGHP];
  413. // zero out active texture list
  414. textureUnits.clear();
  415. textureUnits.push_back(TextureUnit());
  416. activeStorageBufferBindings.clear();
  417. storageBufferBindingIndexToActiveBinding.resize(gl.getMaxShaderStorageBufferBindings(), std::make_pair(-1, -1));
  418. activeStorageBufferBindings.clear();
  419. activeWritableStorageBuffers.clear();
  420. for (const auto &stage : stages)
  421. {
  422. if (stage.get() != nullptr)
  423. ((ShaderStage*)stage.get())->loadVolatile();
  424. }
  425. program = glCreateProgram();
  426. if (program == 0)
  427. throw love::Exception("Cannot create shader program object.");
  428. if (!debugName.empty() && (GLAD_VERSION_4_3 || GLAD_ES_VERSION_3_2))
  429. glObjectLabel(GL_PROGRAM, program, -1, debugName.c_str());
  430. for (const auto &stage : stages)
  431. {
  432. if (stage.get() != nullptr)
  433. glAttachShader(program, (GLuint) stage->getHandle());
  434. }
  435. // Bind generic vertex attribute indices to names in the shader.
  436. for (int i = 0; i < int(ATTRIB_MAX_ENUM); i++)
  437. {
  438. const char *name = nullptr;
  439. if (graphics::getConstant((BuiltinVertexAttribute) i, name))
  440. glBindAttribLocation(program, i, (const GLchar *) name);
  441. }
  442. glLinkProgram(program);
  443. GLint status;
  444. glGetProgramiv(program, GL_LINK_STATUS, &status);
  445. if (status == GL_FALSE)
  446. {
  447. std::string warnings = getProgramWarnings();
  448. glDeleteProgram(program);
  449. program = 0;
  450. throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
  451. }
  452. // Get all active uniform variables in this shader from OpenGL.
  453. mapActiveUniforms();
  454. if (current == this)
  455. {
  456. // make sure glUseProgram gets called.
  457. current = nullptr;
  458. attach();
  459. }
  460. return true;
  461. }
  462. void Shader::unloadVolatile()
  463. {
  464. if (program != 0)
  465. {
  466. if (current == this)
  467. gl.useProgram(0);
  468. glDeleteProgram(program);
  469. program = 0;
  470. }
  471. // active texture list is probably invalid, clear it
  472. textureUnits.clear();
  473. textureUnits.push_back(TextureUnit());
  474. attributes.clear();
  475. // And the locations of any built-in uniform variables.
  476. for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
  477. builtinUniforms[i] = -1;
  478. }
  479. std::string Shader::getProgramWarnings() const
  480. {
  481. GLint strsize, nullpos;
  482. glGetProgramiv(program, GL_INFO_LOG_LENGTH, &strsize);
  483. if (strsize == 0)
  484. return "";
  485. char *tempstr = new char[strsize];
  486. // be extra sure that the error string will be 0-terminated
  487. memset(tempstr, '\0', strsize);
  488. glGetProgramInfoLog(program, strsize, &nullpos, tempstr);
  489. tempstr[nullpos] = '\0';
  490. std::string warnings(tempstr);
  491. delete[] tempstr;
  492. return warnings;
  493. }
  494. std::string Shader::getWarnings() const
  495. {
  496. std::string warnings;
  497. const char *stagestr;
  498. for (const auto &stage : stages)
  499. {
  500. if (stage.get() == nullptr)
  501. continue;
  502. const std::string &stagewarnings = stage->getWarnings();
  503. if (ShaderStage::getConstant(stage->getStageType(), stagestr))
  504. warnings += std::string(stagestr) + std::string(" shader:\n") + stagewarnings;
  505. }
  506. warnings += getProgramWarnings();
  507. return warnings;
  508. }
  509. void Shader::attach()
  510. {
  511. if (current != this)
  512. {
  513. Graphics::flushBatchedDrawsGlobal();
  514. gl.useProgram(program);
  515. current = this;
  516. // retain/release happens in Graphics::setShader.
  517. // Make sure all textures are bound to their respective texture units.
  518. for (int i = 0; i < (int) textureUnits.size(); i++)
  519. {
  520. const TextureUnit &unit = textureUnits[i];
  521. if (unit.active)
  522. {
  523. if (unit.isTexelBuffer)
  524. gl.bindBufferTextureToUnit(unit.texture, i, false, false);
  525. else
  526. gl.bindTextureToUnit(unit.type, unit.texture, i, false, false);
  527. }
  528. }
  529. for (size_t i = 0; i < storageTextureBindings.size(); i++)
  530. {
  531. const auto &binding = storageTextureBindings[i];
  532. glBindImageTexture((GLuint) i, binding.gltexture, 0, GL_TRUE, 0, binding.access, binding.internalFormat);
  533. }
  534. for (auto bufferbinding : activeStorageBufferBindings)
  535. gl.bindIndexedBuffer(bufferbinding.buffer, BUFFERUSAGE_SHADER_STORAGE, bufferbinding.bindingindex);
  536. // send any pending uniforms to the shader program.
  537. for (const auto &p : pendingUniformUpdates)
  538. updateUniform(p.first, p.second, true);
  539. pendingUniformUpdates.clear();
  540. }
  541. }
  542. const Shader::UniformInfo *Shader::getUniformInfo(const std::string &name) const
  543. {
  544. const auto it = uniforms.find(name);
  545. if (it == uniforms.end())
  546. return nullptr;
  547. return &(it->second);
  548. }
  549. const Shader::UniformInfo *Shader::getUniformInfo(BuiltinUniform builtin) const
  550. {
  551. return builtinUniformInfo[(int)builtin];
  552. }
  553. void Shader::updateUniform(const UniformInfo *info, int count)
  554. {
  555. updateUniform(info, count, false);
  556. }
  557. void Shader::updateUniform(const UniformInfo *info, int count, bool internalupdate)
  558. {
  559. if (current != this && !internalupdate)
  560. {
  561. pendingUniformUpdates.push_back(std::make_pair(info, count));
  562. return;
  563. }
  564. if (!internalupdate)
  565. flushBatchedDraws();
  566. int location = info->location;
  567. UniformType type = info->baseType;
  568. if (type == UNIFORM_FLOAT)
  569. {
  570. switch (info->components)
  571. {
  572. case 1:
  573. glUniform1fv(location, count, info->floats);
  574. break;
  575. case 2:
  576. glUniform2fv(location, count, info->floats);
  577. break;
  578. case 3:
  579. glUniform3fv(location, count, info->floats);
  580. break;
  581. case 4:
  582. glUniform4fv(location, count, info->floats);
  583. break;
  584. }
  585. }
  586. else if (type == UNIFORM_INT || type == UNIFORM_BOOL || type == UNIFORM_SAMPLER || type == UNIFORM_STORAGETEXTURE || type == UNIFORM_TEXELBUFFER)
  587. {
  588. switch (info->components)
  589. {
  590. case 1:
  591. glUniform1iv(location, count, info->ints);
  592. break;
  593. case 2:
  594. glUniform2iv(location, count, info->ints);
  595. break;
  596. case 3:
  597. glUniform3iv(location, count, info->ints);
  598. break;
  599. case 4:
  600. glUniform4iv(location, count, info->ints);
  601. break;
  602. }
  603. }
  604. else if (type == UNIFORM_UINT)
  605. {
  606. switch (info->components)
  607. {
  608. case 1:
  609. glUniform1uiv(location, count, info->uints);
  610. break;
  611. case 2:
  612. glUniform2uiv(location, count, info->uints);
  613. break;
  614. case 3:
  615. glUniform3uiv(location, count, info->uints);
  616. break;
  617. case 4:
  618. glUniform4uiv(location, count, info->uints);
  619. break;
  620. }
  621. }
  622. else if (type == UNIFORM_MATRIX)
  623. {
  624. int columns = info->matrix.columns;
  625. int rows = info->matrix.rows;
  626. if (columns == 2 && rows == 2)
  627. glUniformMatrix2fv(location, count, GL_FALSE, info->floats);
  628. else if (columns == 3 && rows == 3)
  629. glUniformMatrix3fv(location, count, GL_FALSE, info->floats);
  630. else if (columns == 4 && rows == 4)
  631. glUniformMatrix4fv(location, count, GL_FALSE, info->floats);
  632. else if (columns == 2 && rows == 3)
  633. glUniformMatrix2x3fv(location, count, GL_FALSE, info->floats);
  634. else if (columns == 2 && rows == 4)
  635. glUniformMatrix2x4fv(location, count, GL_FALSE, info->floats);
  636. else if (columns == 3 && rows == 2)
  637. glUniformMatrix3x2fv(location, count, GL_FALSE, info->floats);
  638. else if (columns == 3 && rows == 4)
  639. glUniformMatrix3x4fv(location, count, GL_FALSE, info->floats);
  640. else if (columns == 4 && rows == 2)
  641. glUniformMatrix4x2fv(location, count, GL_FALSE, info->floats);
  642. else if (columns == 4 && rows == 3)
  643. glUniformMatrix4x3fv(location, count, GL_FALSE, info->floats);
  644. }
  645. }
  646. void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count)
  647. {
  648. Shader::sendTextures(info, textures, count, false);
  649. }
  650. void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count, bool internalUpdate)
  651. {
  652. bool issampler = info->baseType == UNIFORM_SAMPLER;
  653. bool isstoragetex = info->baseType == UNIFORM_STORAGETEXTURE;
  654. if (!issampler && !isstoragetex)
  655. return;
  656. bool shaderactive = current == this;
  657. if (!internalUpdate && shaderactive)
  658. flushBatchedDraws();
  659. count = std::min(count, info->count);
  660. // Bind the textures to the texture units.
  661. for (int i = 0; i < count; i++)
  662. {
  663. love::graphics::Texture *tex = textures[i];
  664. if (tex != nullptr)
  665. {
  666. if (!validateTexture(info, tex, internalUpdate))
  667. continue;
  668. }
  669. else
  670. {
  671. auto gfx = Module::getInstance<love::graphics::Graphics>(Module::M_GRAPHICS);
  672. tex = gfx->getDefaultTexture(info->textureType, info->dataBaseType);
  673. }
  674. tex->retain();
  675. if (info->textures[i] != nullptr)
  676. info->textures[i]->release();
  677. info->textures[i] = tex;
  678. if (isstoragetex)
  679. {
  680. GLuint gltex = (GLuint) tex->getHandle();
  681. int bindingindex = info->ints[i];
  682. auto &binding = storageTextureBindings[bindingindex];
  683. binding.texture = tex;
  684. binding.gltexture = gltex;
  685. if (shaderactive)
  686. glBindImageTexture(bindingindex, binding.gltexture, 0, GL_TRUE, 0, binding.access, binding.internalFormat);
  687. }
  688. else
  689. {
  690. GLuint gltex = (GLuint) tex->getHandle();
  691. int texunit = info->ints[i];
  692. if (shaderactive)
  693. gl.bindTextureToUnit(info->textureType, gltex, texunit, false, false);
  694. // Store texture id so it can be re-bound to the texture unit later.
  695. textureUnits[texunit].texture = gltex;
  696. }
  697. }
  698. }
  699. void Shader::sendBuffers(const UniformInfo *info, love::graphics::Buffer **buffers, int count)
  700. {
  701. Shader::sendBuffers(info, buffers, count, false);
  702. }
  703. void Shader::sendBuffers(const UniformInfo *info, love::graphics::Buffer **buffers, int count, bool internalUpdate)
  704. {
  705. bool texelbinding = info->baseType == UNIFORM_TEXELBUFFER;
  706. bool storagebinding = info->baseType == UNIFORM_STORAGEBUFFER;
  707. if (!texelbinding && !storagebinding)
  708. return;
  709. bool shaderactive = current == this;
  710. if (!internalUpdate && shaderactive)
  711. flushBatchedDraws();
  712. count = std::min(count, info->count);
  713. // Bind the textures to the texture units.
  714. for (int i = 0; i < count; i++)
  715. {
  716. love::graphics::Buffer *buffer = buffers[i];
  717. if (buffer != nullptr)
  718. {
  719. if (!validateBuffer(info, buffer, internalUpdate))
  720. continue;
  721. buffer->retain();
  722. }
  723. if (info->buffers[i] != nullptr)
  724. info->buffers[i]->release();
  725. info->buffers[i] = buffer;
  726. if (texelbinding)
  727. {
  728. GLuint gltex = 0;
  729. if (buffer != nullptr)
  730. gltex = (GLuint) buffer->getTexelBufferHandle();
  731. else
  732. gltex = gl.getDefaultTexelBuffer();
  733. int texunit = info->ints[i];
  734. if (shaderactive)
  735. gl.bindBufferTextureToUnit(gltex, texunit, false, false);
  736. // Store texture id so it can be re-bound to the texture unit later.
  737. textureUnits[texunit].texture = gltex;
  738. }
  739. else if (storagebinding)
  740. {
  741. int bindingindex = info->ints[i];
  742. GLuint glbuffer = 0;
  743. if (buffer != nullptr)
  744. glbuffer = (GLuint) buffer->getHandle();
  745. else
  746. glbuffer = gl.getDefaultStorageBuffer();
  747. if (shaderactive)
  748. gl.bindIndexedBuffer(glbuffer, BUFFERUSAGE_SHADER_STORAGE, bindingindex);
  749. auto activeindex = storageBufferBindingIndexToActiveBinding[bindingindex];
  750. if (activeindex.first >= 0)
  751. activeStorageBufferBindings[activeindex.first].buffer = glbuffer;
  752. if (activeindex.second >= 0)
  753. activeWritableStorageBuffers[activeindex.second] = buffer;
  754. }
  755. }
  756. }
  757. void Shader::flushBatchedDraws() const
  758. {
  759. if (current == this)
  760. Graphics::flushBatchedDrawsGlobal();
  761. }
  762. bool Shader::hasUniform(const std::string &name) const
  763. {
  764. return uniforms.find(name) != uniforms.end();
  765. }
  766. ptrdiff_t Shader::getHandle() const
  767. {
  768. return program;
  769. }
  770. int Shader::getVertexAttributeIndex(const std::string &name)
  771. {
  772. auto it = attributes.find(name);
  773. if (it != attributes.end())
  774. return it->second;
  775. GLint location = glGetAttribLocation(program, name.c_str());
  776. attributes[name] = location;
  777. return location;
  778. }
  779. void Shader::setVideoTextures(love::graphics::Texture *ytexture, love::graphics::Texture *cbtexture, love::graphics::Texture *crtexture)
  780. {
  781. const BuiltinUniform builtins[3] = {
  782. BUILTIN_TEXTURE_VIDEO_Y,
  783. BUILTIN_TEXTURE_VIDEO_CB,
  784. BUILTIN_TEXTURE_VIDEO_CR,
  785. };
  786. love::graphics::Texture *textures[3] = {ytexture, cbtexture, crtexture};
  787. for (int i = 0; i < 3; i++)
  788. {
  789. const UniformInfo *info = builtinUniformInfo[builtins[i]];
  790. if (info != nullptr)
  791. sendTextures(info, &textures[i], 1, true);
  792. }
  793. }
  794. void Shader::updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW, int viewportH)
  795. {
  796. if (current != this)
  797. return;
  798. BuiltinUniformData data;
  799. data.transformMatrix = gfx->getTransform();
  800. data.projectionMatrix = gfx->getDeviceProjection();
  801. // The normal matrix is the transpose of the inverse of the rotation portion
  802. // (top-left 3x3) of the transform matrix.
  803. {
  804. Matrix3 normalmatrix = Matrix3(data.transformMatrix).transposedInverse();
  805. const float *e = normalmatrix.getElements();
  806. for (int i = 0; i < 3; i++)
  807. {
  808. data.normalMatrix[i].x = e[i * 3 + 0];
  809. data.normalMatrix[i].y = e[i * 3 + 1];
  810. data.normalMatrix[i].z = e[i * 3 + 2];
  811. data.normalMatrix[i].w = 0.0f;
  812. }
  813. }
  814. // Store DPI scale in an unused component of another vector.
  815. data.normalMatrix[0].w = (float) gfx->getCurrentDPIScale();
  816. // Same with point size.
  817. data.normalMatrix[1].w = gfx->getPointSize();
  818. data.screenSizeParams.x = viewportW;
  819. data.screenSizeParams.y = viewportH;
  820. // The shader does pixcoord.y = gl_FragCoord.y * params.z + params.w.
  821. // This lets us flip pixcoord.y when needed, to be consistent (drawing
  822. // with no RT active makes the pixel coordinates y-flipped.)
  823. if (gfx->isRenderTargetActive())
  824. {
  825. // No flipping: pixcoord.y = gl_FragCoord.y * 1.0 + 0.0.
  826. data.screenSizeParams.z = 1.0f;
  827. data.screenSizeParams.w = 0.0f;
  828. }
  829. else
  830. {
  831. // gl_FragCoord.y is flipped when drawing to the screen, so we
  832. // un-flip: pixcoord.y = gl_FragCoord.y * -1.0 + height.
  833. data.screenSizeParams.z = -1.0f;
  834. data.screenSizeParams.w = viewportH;
  835. }
  836. data.constantColor = gfx->getColor();
  837. gammaCorrectColor(data.constantColor);
  838. // This branch is to avoid always declaring the whole array as highp in the
  839. // vertex shader and mediump in the pixel shader for love's default shaders,
  840. // on systems that don't support highp in pixel shaders. The default shaders
  841. // use the transform matrices in vertex shaders and screen size params in
  842. // pixel shaders. If there's a single array containing both and each shader
  843. // stage declares a different precision, that's a compile error.
  844. if (splitUniformsPerDraw)
  845. {
  846. GLint location = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW];
  847. if (location >= 0)
  848. glUniform4fv(location, 12, (const GLfloat *) &data);
  849. GLint location2 = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW_2];
  850. if (location2 >= 0)
  851. glUniform4fv(location2, 1, (const GLfloat *) &data.screenSizeParams);
  852. }
  853. else
  854. {
  855. GLint location = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW];
  856. if (location >= 0)
  857. glUniform4fv(location, 13, (const GLfloat *) &data);
  858. }
  859. }
  860. int Shader::getUniformTypeComponents(GLenum type) const
  861. {
  862. switch (type)
  863. {
  864. case GL_INT:
  865. case GL_UNSIGNED_INT:
  866. case GL_FLOAT:
  867. case GL_BOOL:
  868. return 1;
  869. case GL_INT_VEC2:
  870. case GL_UNSIGNED_INT_VEC2:
  871. case GL_FLOAT_VEC2:
  872. case GL_FLOAT_MAT2:
  873. case GL_BOOL_VEC2:
  874. return 2;
  875. case GL_INT_VEC3:
  876. case GL_UNSIGNED_INT_VEC3:
  877. case GL_FLOAT_VEC3:
  878. case GL_FLOAT_MAT3:
  879. case GL_BOOL_VEC3:
  880. return 3;
  881. case GL_INT_VEC4:
  882. case GL_UNSIGNED_INT_VEC4:
  883. case GL_FLOAT_VEC4:
  884. case GL_FLOAT_MAT4:
  885. case GL_BOOL_VEC4:
  886. return 4;
  887. default:
  888. return 1;
  889. }
  890. }
  891. Shader::MatrixSize Shader::getMatrixSize(GLenum type) const
  892. {
  893. MatrixSize m;
  894. switch (type)
  895. {
  896. case GL_FLOAT_MAT2:
  897. m.columns = m.rows = 2;
  898. break;
  899. case GL_FLOAT_MAT3:
  900. m.columns = m.rows = 3;
  901. break;
  902. case GL_FLOAT_MAT4:
  903. m.columns = m.rows = 4;
  904. break;
  905. case GL_FLOAT_MAT2x3:
  906. m.columns = 2;
  907. m.rows = 3;
  908. break;
  909. case GL_FLOAT_MAT2x4:
  910. m.columns = 2;
  911. m.rows = 4;
  912. break;
  913. case GL_FLOAT_MAT3x2:
  914. m.columns = 3;
  915. m.rows = 2;
  916. break;
  917. case GL_FLOAT_MAT3x4:
  918. m.columns = 3;
  919. m.rows = 4;
  920. break;
  921. case GL_FLOAT_MAT4x2:
  922. m.columns = 4;
  923. m.rows = 2;
  924. break;
  925. case GL_FLOAT_MAT4x3:
  926. m.columns = 4;
  927. m.rows = 3;
  928. break;
  929. default:
  930. m.columns = m.rows = 0;
  931. break;
  932. }
  933. return m;
  934. }
  935. void Shader::computeUniformTypeInfo(GLenum type, UniformInfo &u)
  936. {
  937. u.isDepthSampler = false;
  938. u.components = getUniformTypeComponents(type);
  939. u.baseType = UNIFORM_UNKNOWN;
  940. switch (type)
  941. {
  942. case GL_INT:
  943. case GL_INT_VEC2:
  944. case GL_INT_VEC3:
  945. case GL_INT_VEC4:
  946. u.baseType = UNIFORM_INT;
  947. u.dataBaseType = DATA_BASETYPE_INT;
  948. break;
  949. case GL_UNSIGNED_INT:
  950. case GL_UNSIGNED_INT_VEC2:
  951. case GL_UNSIGNED_INT_VEC3:
  952. case GL_UNSIGNED_INT_VEC4:
  953. u.baseType = UNIFORM_UINT;
  954. u.dataBaseType = DATA_BASETYPE_UINT;
  955. break;
  956. case GL_FLOAT:
  957. case GL_FLOAT_VEC2:
  958. case GL_FLOAT_VEC3:
  959. case GL_FLOAT_VEC4:
  960. u.baseType = UNIFORM_FLOAT;
  961. u.dataBaseType = DATA_BASETYPE_FLOAT;
  962. break;
  963. case GL_FLOAT_MAT2:
  964. case GL_FLOAT_MAT3:
  965. case GL_FLOAT_MAT4:
  966. case GL_FLOAT_MAT2x3:
  967. case GL_FLOAT_MAT2x4:
  968. case GL_FLOAT_MAT3x2:
  969. case GL_FLOAT_MAT3x4:
  970. case GL_FLOAT_MAT4x2:
  971. case GL_FLOAT_MAT4x3:
  972. u.baseType = UNIFORM_MATRIX;
  973. u.dataBaseType = DATA_BASETYPE_FLOAT;
  974. u.matrix = getMatrixSize(type);
  975. break;
  976. case GL_BOOL:
  977. case GL_BOOL_VEC2:
  978. case GL_BOOL_VEC3:
  979. case GL_BOOL_VEC4:
  980. u.baseType = UNIFORM_BOOL;
  981. u.dataBaseType = DATA_BASETYPE_BOOL;
  982. break;
  983. case GL_SAMPLER_2D:
  984. u.baseType = UNIFORM_SAMPLER;
  985. u.dataBaseType = DATA_BASETYPE_FLOAT;
  986. u.textureType = TEXTURE_2D;
  987. break;
  988. case GL_SAMPLER_2D_SHADOW:
  989. u.baseType = UNIFORM_SAMPLER;
  990. u.dataBaseType = DATA_BASETYPE_FLOAT;
  991. u.textureType = TEXTURE_2D;
  992. u.isDepthSampler = true;
  993. break;
  994. case GL_INT_SAMPLER_2D:
  995. u.baseType = UNIFORM_SAMPLER;
  996. u.dataBaseType = DATA_BASETYPE_INT;
  997. u.textureType = TEXTURE_2D;
  998. break;
  999. case GL_UNSIGNED_INT_SAMPLER_2D:
  1000. u.baseType = UNIFORM_SAMPLER;
  1001. u.dataBaseType = DATA_BASETYPE_UINT;
  1002. u.textureType = TEXTURE_2D;
  1003. break;
  1004. case GL_SAMPLER_2D_ARRAY:
  1005. u.baseType = UNIFORM_SAMPLER;
  1006. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1007. u.textureType = TEXTURE_2D_ARRAY;
  1008. break;
  1009. case GL_SAMPLER_2D_ARRAY_SHADOW:
  1010. u.baseType = UNIFORM_SAMPLER;
  1011. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1012. u.textureType = TEXTURE_2D_ARRAY;
  1013. u.isDepthSampler = true;
  1014. break;
  1015. case GL_INT_SAMPLER_2D_ARRAY:
  1016. u.baseType = UNIFORM_SAMPLER;
  1017. u.dataBaseType = DATA_BASETYPE_INT;
  1018. u.textureType = TEXTURE_2D_ARRAY;
  1019. break;
  1020. case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
  1021. u.baseType = UNIFORM_SAMPLER;
  1022. u.dataBaseType = DATA_BASETYPE_UINT;
  1023. u.textureType = TEXTURE_2D_ARRAY;
  1024. break;
  1025. case GL_SAMPLER_3D:
  1026. u.baseType = UNIFORM_SAMPLER;
  1027. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1028. u.textureType = TEXTURE_VOLUME;
  1029. break;
  1030. case GL_INT_SAMPLER_3D:
  1031. u.baseType = UNIFORM_SAMPLER;
  1032. u.dataBaseType = DATA_BASETYPE_INT;
  1033. u.textureType = TEXTURE_VOLUME;
  1034. break;
  1035. case GL_UNSIGNED_INT_SAMPLER_3D:
  1036. u.baseType = UNIFORM_SAMPLER;
  1037. u.dataBaseType = DATA_BASETYPE_UINT;
  1038. u.textureType = TEXTURE_VOLUME;
  1039. break;
  1040. case GL_SAMPLER_CUBE:
  1041. u.baseType = UNIFORM_SAMPLER;
  1042. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1043. u.textureType = TEXTURE_CUBE;
  1044. break;
  1045. case GL_SAMPLER_CUBE_SHADOW:
  1046. u.baseType = UNIFORM_SAMPLER;
  1047. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1048. u.textureType = TEXTURE_CUBE;
  1049. u.isDepthSampler = true;
  1050. break;
  1051. case GL_INT_SAMPLER_CUBE:
  1052. u.baseType = UNIFORM_SAMPLER;
  1053. u.dataBaseType = DATA_BASETYPE_INT;
  1054. u.textureType = TEXTURE_CUBE;
  1055. break;
  1056. case GL_UNSIGNED_INT_SAMPLER_CUBE:
  1057. u.baseType = UNIFORM_SAMPLER;
  1058. u.dataBaseType = DATA_BASETYPE_UINT;
  1059. u.textureType = TEXTURE_CUBE;
  1060. break;
  1061. case GL_SAMPLER_BUFFER:
  1062. u.baseType = UNIFORM_TEXELBUFFER;
  1063. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1064. break;
  1065. case GL_INT_SAMPLER_BUFFER:
  1066. u.baseType = UNIFORM_TEXELBUFFER;
  1067. u.dataBaseType = DATA_BASETYPE_INT;
  1068. break;
  1069. case GL_UNSIGNED_INT_SAMPLER_BUFFER:
  1070. u.baseType = UNIFORM_TEXELBUFFER;
  1071. u.dataBaseType = DATA_BASETYPE_UINT;
  1072. break;
  1073. case GL_IMAGE_2D:
  1074. u.baseType = UNIFORM_STORAGETEXTURE;
  1075. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1076. u.textureType = TEXTURE_2D;
  1077. break;
  1078. case GL_INT_IMAGE_2D:
  1079. u.baseType = UNIFORM_STORAGETEXTURE;
  1080. u.dataBaseType = DATA_BASETYPE_INT;
  1081. u.textureType = TEXTURE_2D;
  1082. break;
  1083. case GL_UNSIGNED_INT_IMAGE_2D:
  1084. u.baseType = UNIFORM_STORAGETEXTURE;
  1085. u.dataBaseType = DATA_BASETYPE_UINT;
  1086. u.textureType = TEXTURE_2D;
  1087. break;
  1088. case GL_IMAGE_2D_ARRAY:
  1089. u.baseType = UNIFORM_STORAGETEXTURE;
  1090. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1091. u.textureType = TEXTURE_2D_ARRAY;
  1092. break;
  1093. case GL_INT_IMAGE_2D_ARRAY:
  1094. u.baseType = UNIFORM_STORAGETEXTURE;
  1095. u.dataBaseType = DATA_BASETYPE_INT;
  1096. u.textureType = TEXTURE_2D_ARRAY;
  1097. break;
  1098. case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
  1099. u.baseType = UNIFORM_STORAGETEXTURE;
  1100. u.dataBaseType = DATA_BASETYPE_UINT;
  1101. u.textureType = TEXTURE_2D_ARRAY;
  1102. break;
  1103. case GL_IMAGE_3D:
  1104. u.baseType = UNIFORM_STORAGETEXTURE;
  1105. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1106. u.textureType = TEXTURE_VOLUME;
  1107. break;
  1108. case GL_INT_IMAGE_3D:
  1109. u.baseType = UNIFORM_STORAGETEXTURE;
  1110. u.dataBaseType = DATA_BASETYPE_INT;
  1111. u.textureType = TEXTURE_VOLUME;
  1112. break;
  1113. case GL_UNSIGNED_INT_IMAGE_3D:
  1114. u.baseType = UNIFORM_STORAGETEXTURE;
  1115. u.dataBaseType = DATA_BASETYPE_UINT;
  1116. u.textureType = TEXTURE_VOLUME;
  1117. break;
  1118. case GL_IMAGE_CUBE:
  1119. u.baseType = UNIFORM_STORAGETEXTURE;
  1120. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1121. u.textureType = TEXTURE_CUBE;
  1122. break;
  1123. case GL_INT_IMAGE_CUBE:
  1124. u.baseType = UNIFORM_STORAGETEXTURE;
  1125. u.dataBaseType = DATA_BASETYPE_INT;
  1126. u.textureType = TEXTURE_CUBE;
  1127. break;
  1128. case GL_UNSIGNED_INT_IMAGE_CUBE:
  1129. u.baseType = UNIFORM_STORAGETEXTURE;
  1130. u.dataBaseType = DATA_BASETYPE_UINT;
  1131. u.textureType = TEXTURE_CUBE;
  1132. break;
  1133. default:
  1134. break;
  1135. }
  1136. }
  1137. } // opengl
  1138. } // graphics
  1139. } // love