Shader.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. /**
  2. * Copyright (c) 2006-2021 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])
  41. : love::graphics::Shader(stages)
  42. , program(0)
  43. , builtinUniforms()
  44. , builtinUniformInfo()
  45. {
  46. // load shader source and create program object
  47. loadVolatile();
  48. }
  49. Shader::~Shader()
  50. {
  51. unloadVolatile();
  52. for (const auto &p : uniforms)
  53. {
  54. // Allocated with malloc().
  55. if (p.second.data != nullptr)
  56. free(p.second.data);
  57. if (p.second.baseType == UNIFORM_SAMPLER || p.second.baseType == UNIFORM_STORAGETEXTURE)
  58. {
  59. for (int i = 0; i < p.second.count; i++)
  60. {
  61. if (p.second.textures[i] != nullptr)
  62. p.second.textures[i]->release();
  63. }
  64. delete[] p.second.textures;
  65. }
  66. else if (isBuffer(p.second.baseType))
  67. {
  68. for (int i = 0; i < p.second.count; i++)
  69. {
  70. if (p.second.buffers[i] != nullptr)
  71. p.second.buffers[i]->release();
  72. }
  73. delete[] p.second.buffers;
  74. }
  75. }
  76. }
  77. void Shader::mapActiveUniforms()
  78. {
  79. // Built-in uniform locations default to -1 (nonexistent.)
  80. for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
  81. {
  82. builtinUniforms[i] = -1;
  83. builtinUniformInfo[i] = nullptr;
  84. }
  85. GLint activeprogram = 0;
  86. glGetIntegerv(GL_CURRENT_PROGRAM, &activeprogram);
  87. gl.useProgram(program);
  88. GLint numuniforms;
  89. glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numuniforms);
  90. GLchar cname[256];
  91. const GLint bufsize = (GLint) (sizeof(cname) / sizeof(GLchar));
  92. std::map<std::string, UniformInfo> olduniforms = uniforms;
  93. uniforms.clear();
  94. for (int uindex = 0; uindex < numuniforms; uindex++)
  95. {
  96. GLsizei namelen = 0;
  97. GLenum gltype = 0;
  98. UniformInfo u = {};
  99. glGetActiveUniform(program, (GLuint) uindex, bufsize, &namelen, &u.count, &gltype, cname);
  100. u.name = std::string(cname, (size_t) namelen);
  101. u.location = glGetUniformLocation(program, u.name.c_str());
  102. u.access = ACCESS_READ;
  103. computeUniformTypeInfo(gltype, u);
  104. // glGetActiveUniform appends "[0]" to the end of array uniform names...
  105. if (u.name.length() > 3)
  106. {
  107. size_t findpos = u.name.find("[0]");
  108. if (findpos != std::string::npos && findpos == u.name.length() - 3)
  109. u.name.erase(u.name.length() - 3);
  110. }
  111. // If this is a built-in (LOVE-created) uniform, store the location.
  112. BuiltinUniform builtin = BUILTIN_MAX_ENUM;
  113. if (getConstant(u.name.c_str(), builtin))
  114. builtinUniforms[int(builtin)] = u.location;
  115. if (u.location == -1)
  116. continue;
  117. if ((u.baseType == UNIFORM_SAMPLER && builtin != BUILTIN_TEXTURE_MAIN) || u.baseType == UNIFORM_TEXELBUFFER)
  118. {
  119. TextureUnit unit;
  120. unit.type = u.textureType;
  121. unit.active = true;
  122. if (u.baseType == UNIFORM_TEXELBUFFER)
  123. {
  124. unit.isTexelBuffer = true;
  125. unit.texture = gl.getDefaultTexelBuffer();
  126. }
  127. else
  128. {
  129. unit.isTexelBuffer = false;
  130. unit.texture = gl.getDefaultTexture(u.textureType, u.dataBaseType);
  131. }
  132. for (int i = 0; i < u.count; i++)
  133. textureUnits.push_back(unit);
  134. }
  135. else if (u.baseType == UNIFORM_STORAGETEXTURE)
  136. {
  137. const auto reflectionit = validationReflection.storageTextures.find(u.name);
  138. if (reflectionit != validationReflection.storageTextures.end())
  139. {
  140. u.storageTextureFormat = reflectionit->second.format;
  141. u.access = reflectionit->second.access;
  142. }
  143. else
  144. {
  145. // No reflection info - maybe glslang was better at detecting
  146. // dead code than the driver's compiler?
  147. continue;
  148. }
  149. StorageTextureBinding binding = {};
  150. binding.gltexture = gl.getDefaultTexture(u.textureType, u.dataBaseType);
  151. binding.type = u.textureType;
  152. if ((u.access & (ACCESS_READ | ACCESS_WRITE)) != 0)
  153. binding.access = GL_READ_WRITE;
  154. else if ((u.access & ACCESS_WRITE) != 0)
  155. binding.access = GL_WRITE_ONLY;
  156. else if ((u.access & ACCESS_READ) != 0)
  157. binding.access = GL_READ_ONLY;
  158. bool sRGB = false;
  159. auto fmt = OpenGL::convertPixelFormat(u.storageTextureFormat, false, sRGB);
  160. binding.internalFormat = fmt.internalformat;
  161. for (int i = 0; i < u.count; i++)
  162. storageTextureBindings.push_back(binding);
  163. }
  164. // Make sure previously set uniform data is preserved, and shader-
  165. // initialized values are retrieved.
  166. auto oldu = olduniforms.find(u.name);
  167. if (oldu != olduniforms.end())
  168. {
  169. u.data = oldu->second.data;
  170. u.dataSize = oldu->second.dataSize;
  171. u.textures = oldu->second.textures;
  172. updateUniform(&u, u.count, true);
  173. }
  174. else
  175. {
  176. u.dataSize = 0;
  177. switch (u.baseType)
  178. {
  179. case UNIFORM_FLOAT:
  180. u.dataSize = sizeof(float) * u.components * u.count;
  181. u.data = malloc(u.dataSize);
  182. break;
  183. case UNIFORM_INT:
  184. case UNIFORM_BOOL:
  185. case UNIFORM_SAMPLER:
  186. case UNIFORM_STORAGETEXTURE:
  187. case UNIFORM_TEXELBUFFER:
  188. u.dataSize = sizeof(int) * u.components * u.count;
  189. u.data = malloc(u.dataSize);
  190. break;
  191. case UNIFORM_UINT:
  192. u.dataSize = sizeof(unsigned int) * u.components * u.count;
  193. u.data = malloc(u.dataSize);
  194. break;
  195. case UNIFORM_MATRIX:
  196. u.dataSize = sizeof(float) * ((size_t)u.matrix.rows * u.matrix.columns) * u.count;
  197. u.data = malloc(u.dataSize);
  198. break;
  199. default:
  200. break;
  201. }
  202. if (u.dataSize > 0)
  203. {
  204. memset(u.data, 0, u.dataSize);
  205. if (u.baseType == UNIFORM_SAMPLER || u.baseType == UNIFORM_TEXELBUFFER)
  206. {
  207. int startunit = (int) textureUnits.size() - u.count;
  208. if (builtin == BUILTIN_TEXTURE_MAIN)
  209. startunit = 0;
  210. for (int i = 0; i < u.count; i++)
  211. u.ints[i] = startunit + i;
  212. glUniform1iv(u.location, u.count, u.ints);
  213. if (u.baseType == UNIFORM_TEXELBUFFER)
  214. {
  215. u.buffers = new love::graphics::Buffer*[u.count];
  216. memset(u.buffers, 0, sizeof(Buffer *) * u.count);
  217. }
  218. else
  219. {
  220. u.textures = new love::graphics::Texture*[u.count];
  221. memset(u.textures, 0, sizeof(Texture *) * u.count);
  222. }
  223. }
  224. else if (u.baseType == UNIFORM_STORAGETEXTURE)
  225. {
  226. int startbinding = (int) storageTextureBindings.size() - u.count;
  227. for (int i = 0; i < u.count; i++)
  228. u.ints[i] = startbinding + i;
  229. glUniform1iv(u.location, u.count, u.ints);
  230. u.textures = new love::graphics::Texture*[u.count];
  231. memset(u.textures, 0, sizeof(Texture *) * u.count);
  232. }
  233. }
  234. size_t offset = 0;
  235. // Store any shader-initialized values in our own memory.
  236. for (int i = 0; i < u.count; i++)
  237. {
  238. GLint location = u.location;
  239. if (u.count > 1)
  240. {
  241. std::ostringstream ss;
  242. ss << i;
  243. std::string indexname = u.name + "[" + ss.str() + "]";
  244. location = glGetUniformLocation(program, indexname.c_str());
  245. }
  246. if (location == -1)
  247. continue;
  248. switch (u.baseType)
  249. {
  250. case UNIFORM_FLOAT:
  251. glGetUniformfv(program, location, &u.floats[offset]);
  252. offset += u.components;
  253. break;
  254. case UNIFORM_INT:
  255. case UNIFORM_BOOL:
  256. glGetUniformiv(program, location, &u.ints[offset]);
  257. offset += u.components;
  258. break;
  259. case UNIFORM_UINT:
  260. glGetUniformuiv(program, location, &u.uints[offset]);
  261. offset += u.components;
  262. break;
  263. case UNIFORM_MATRIX:
  264. glGetUniformfv(program, location, &u.floats[offset]);
  265. offset += (size_t)u.matrix.rows * u.matrix.columns;
  266. break;
  267. default:
  268. break;
  269. }
  270. }
  271. }
  272. uniforms[u.name] = u;
  273. if (builtin != BUILTIN_MAX_ENUM)
  274. builtinUniformInfo[(int)builtin] = &uniforms[u.name];
  275. if (u.baseType == UNIFORM_SAMPLER || u.baseType == UNIFORM_STORAGETEXTURE)
  276. {
  277. // Make sure all stored textures have their Volatiles loaded before
  278. // the sendTextures call, since it calls getHandle().
  279. for (int i = 0; i < u.count; i++)
  280. {
  281. if (u.textures[i] == nullptr)
  282. continue;
  283. Volatile *v = dynamic_cast<Volatile *>(u.textures[i]);
  284. if (v != nullptr)
  285. v->loadVolatile();
  286. }
  287. sendTextures(&u, u.textures, u.count, true);
  288. }
  289. else if (u.baseType == UNIFORM_TEXELBUFFER)
  290. {
  291. for (int i = 0; i < u.count; i++)
  292. {
  293. if (u.buffers[i] == nullptr)
  294. continue;
  295. Volatile *v = dynamic_cast<Volatile *>(u.buffers[i]);
  296. if (v != nullptr)
  297. v->loadVolatile();
  298. }
  299. sendBuffers(&u, u.buffers, u.count, true);
  300. }
  301. }
  302. if (gl.isBufferUsageSupported(BUFFERUSAGE_SHADER_STORAGE))
  303. {
  304. GLint numstoragebuffers = 0;
  305. glGetProgramInterfaceiv(program, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numstoragebuffers);
  306. char namebuffer[2048] = { '\0' };
  307. int nextstoragebufferbinding = 0;
  308. for (int sindex = 0; sindex < numstoragebuffers; sindex++)
  309. {
  310. UniformInfo u = {};
  311. u.baseType = UNIFORM_STORAGEBUFFER;
  312. u.access = ACCESS_READ;
  313. GLsizei namelength = 0;
  314. glGetProgramResourceName(program, GL_SHADER_STORAGE_BLOCK, sindex, 2048, &namelength, namebuffer);
  315. u.name = std::string(namebuffer, namelength);
  316. u.count = 1;
  317. const auto reflectionit = validationReflection.storageBuffers.find(u.name);
  318. if (reflectionit != validationReflection.storageBuffers.end())
  319. {
  320. u.bufferStride = reflectionit->second.stride;
  321. u.bufferMemberCount = reflectionit->second.memberCount;
  322. u.access = reflectionit->second.access;
  323. }
  324. else
  325. {
  326. // No reflection info - maybe glslang was better at detecting
  327. // dead code than the driver's compiler?
  328. continue;
  329. }
  330. // Make sure previously set uniform data is preserved, and shader-
  331. // initialized values are retrieved.
  332. auto oldu = olduniforms.find(u.name);
  333. if (oldu != olduniforms.end())
  334. {
  335. u.data = oldu->second.data;
  336. u.dataSize = oldu->second.dataSize;
  337. u.buffers = oldu->second.buffers;
  338. }
  339. else
  340. {
  341. u.dataSize = sizeof(int) * 1;
  342. u.data = malloc(u.dataSize);
  343. u.ints[0] = -1;
  344. u.buffers = new love::graphics::Buffer * [u.count];
  345. memset(u.buffers, 0, sizeof(Buffer*)* u.count);
  346. }
  347. // Unlike local uniforms and attributes, OpenGL doesn't auto-assign storage
  348. // block bindings if they're unspecified in the shader. So we overwrite them
  349. // regardless, here.
  350. u.ints[0] = nextstoragebufferbinding++;
  351. glShaderStorageBlockBinding(program, sindex, u.ints[0]);
  352. BufferBinding binding;
  353. binding.bindingindex = u.ints[0];
  354. binding.buffer = gl.getDefaultStorageBuffer();
  355. if (binding.bindingindex >= 0)
  356. {
  357. int activeindex = (int)activeStorageBufferBindings.size();
  358. activeStorageBufferBindings.push_back(binding);
  359. auto p = std::make_pair(activeindex, -1);
  360. if (u.access & ACCESS_WRITE)
  361. {
  362. p.second = (int)activeWritableStorageBuffers.size();
  363. activeWritableStorageBuffers.push_back(u.buffers[0]);
  364. }
  365. storageBufferBindingIndexToActiveBinding[binding.bindingindex] = p;
  366. }
  367. uniforms[u.name] = u;
  368. for (int i = 0; i < u.count; i++)
  369. {
  370. if (u.buffers[i] == nullptr)
  371. continue;
  372. Volatile* v = dynamic_cast<Volatile*>(u.buffers[i]);
  373. if (v != nullptr)
  374. v->loadVolatile();
  375. }
  376. sendBuffers(&u, u.buffers, u.count, true);
  377. }
  378. }
  379. // Make sure uniforms that existed before but don't exist anymore are
  380. // cleaned up. This theoretically shouldn't happen, but...
  381. for (const auto &p : olduniforms)
  382. {
  383. if (uniforms.find(p.first) == uniforms.end())
  384. {
  385. if (p.second.data != nullptr)
  386. free(p.second.data);
  387. if (p.second.baseType == UNIFORM_SAMPLER || p.second.baseType == UNIFORM_STORAGETEXTURE)
  388. {
  389. for (int i = 0; i < p.second.count; i++)
  390. {
  391. if (p.second.textures[i] != nullptr)
  392. p.second.textures[i]->release();
  393. }
  394. delete[] p.second.textures;
  395. }
  396. else if (isBuffer(p.second.baseType))
  397. {
  398. for (int i = 0; i < p.second.count; i++)
  399. {
  400. if (p.second.buffers[i] != nullptr)
  401. p.second.buffers[i]->release();
  402. }
  403. delete[] p.second.buffers;
  404. }
  405. }
  406. }
  407. gl.useProgram(activeprogram);
  408. }
  409. bool Shader::loadVolatile()
  410. {
  411. OpenGL::TempDebugGroup debuggroup("Shader load");
  412. // zero out active texture list
  413. textureUnits.clear();
  414. textureUnits.push_back(TextureUnit());
  415. activeStorageBufferBindings.clear();
  416. storageBufferBindingIndexToActiveBinding.resize(gl.getMaxShaderStorageBufferBindings(), std::make_pair(-1, -1));
  417. activeStorageBufferBindings.clear();
  418. activeWritableStorageBuffers.clear();
  419. for (const auto &stage : stages)
  420. {
  421. if (stage.get() != nullptr)
  422. ((ShaderStage*)stage.get())->loadVolatile();
  423. }
  424. program = glCreateProgram();
  425. if (program == 0)
  426. throw love::Exception("Cannot create shader program object.");
  427. for (const auto &stage : stages)
  428. {
  429. if (stage.get() != nullptr)
  430. glAttachShader(program, (GLuint) stage->getHandle());
  431. }
  432. // Bind generic vertex attribute indices to names in the shader.
  433. for (int i = 0; i < int(ATTRIB_MAX_ENUM); i++)
  434. {
  435. const char *name = nullptr;
  436. if (graphics::getConstant((BuiltinVertexAttribute) i, name))
  437. glBindAttribLocation(program, i, (const GLchar *) name);
  438. }
  439. glLinkProgram(program);
  440. GLint status;
  441. glGetProgramiv(program, GL_LINK_STATUS, &status);
  442. if (status == GL_FALSE)
  443. {
  444. std::string warnings = getProgramWarnings();
  445. glDeleteProgram(program);
  446. program = 0;
  447. throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
  448. }
  449. // Get all active uniform variables in this shader from OpenGL.
  450. mapActiveUniforms();
  451. if (current == this)
  452. {
  453. // make sure glUseProgram gets called.
  454. current = nullptr;
  455. attach();
  456. }
  457. return true;
  458. }
  459. void Shader::unloadVolatile()
  460. {
  461. if (program != 0)
  462. {
  463. if (current == this)
  464. gl.useProgram(0);
  465. glDeleteProgram(program);
  466. program = 0;
  467. }
  468. // active texture list is probably invalid, clear it
  469. textureUnits.clear();
  470. textureUnits.push_back(TextureUnit());
  471. attributes.clear();
  472. // And the locations of any built-in uniform variables.
  473. for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
  474. builtinUniforms[i] = -1;
  475. }
  476. std::string Shader::getProgramWarnings() const
  477. {
  478. GLint strsize, nullpos;
  479. glGetProgramiv(program, GL_INFO_LOG_LENGTH, &strsize);
  480. if (strsize == 0)
  481. return "";
  482. char *tempstr = new char[strsize];
  483. // be extra sure that the error string will be 0-terminated
  484. memset(tempstr, '\0', strsize);
  485. glGetProgramInfoLog(program, strsize, &nullpos, tempstr);
  486. tempstr[nullpos] = '\0';
  487. std::string warnings(tempstr);
  488. delete[] tempstr;
  489. return warnings;
  490. }
  491. std::string Shader::getWarnings() const
  492. {
  493. std::string warnings;
  494. const char *stagestr;
  495. for (const auto &stage : stages)
  496. {
  497. if (stage.get() == nullptr)
  498. continue;
  499. const std::string &stagewarnings = stage->getWarnings();
  500. if (ShaderStage::getConstant(stage->getStageType(), stagestr))
  501. warnings += std::string(stagestr) + std::string(" shader:\n") + stagewarnings;
  502. }
  503. warnings += getProgramWarnings();
  504. return warnings;
  505. }
  506. void Shader::attach()
  507. {
  508. if (current != this)
  509. {
  510. Graphics::flushBatchedDrawsGlobal();
  511. gl.useProgram(program);
  512. current = this;
  513. // retain/release happens in Graphics::setShader.
  514. // Make sure all textures are bound to their respective texture units.
  515. for (int i = 0; i < (int) textureUnits.size(); i++)
  516. {
  517. const TextureUnit &unit = textureUnits[i];
  518. if (unit.active)
  519. {
  520. if (unit.isTexelBuffer)
  521. gl.bindBufferTextureToUnit(unit.texture, i, false, false);
  522. else
  523. gl.bindTextureToUnit(unit.type, unit.texture, i, false, false);
  524. }
  525. }
  526. for (size_t i = 0; i < storageTextureBindings.size(); i++)
  527. {
  528. const auto &binding = storageTextureBindings[i];
  529. glBindImageTexture((GLuint) i, binding.gltexture, 0, GL_TRUE, 0, binding.access, binding.internalFormat);
  530. }
  531. for (auto bufferbinding : activeStorageBufferBindings)
  532. gl.bindIndexedBuffer(bufferbinding.buffer, BUFFERUSAGE_SHADER_STORAGE, bufferbinding.bindingindex);
  533. // send any pending uniforms to the shader program.
  534. for (const auto &p : pendingUniformUpdates)
  535. updateUniform(p.first, p.second, true);
  536. pendingUniformUpdates.clear();
  537. }
  538. }
  539. const Shader::UniformInfo *Shader::getUniformInfo(const std::string &name) const
  540. {
  541. const auto it = uniforms.find(name);
  542. if (it == uniforms.end())
  543. return nullptr;
  544. return &(it->second);
  545. }
  546. const Shader::UniformInfo *Shader::getUniformInfo(BuiltinUniform builtin) const
  547. {
  548. return builtinUniformInfo[(int)builtin];
  549. }
  550. void Shader::updateUniform(const UniformInfo *info, int count)
  551. {
  552. updateUniform(info, count, false);
  553. }
  554. void Shader::updateUniform(const UniformInfo *info, int count, bool internalupdate)
  555. {
  556. if (current != this && !internalupdate)
  557. {
  558. pendingUniformUpdates.push_back(std::make_pair(info, count));
  559. return;
  560. }
  561. if (!internalupdate)
  562. flushBatchedDraws();
  563. int location = info->location;
  564. UniformType type = info->baseType;
  565. if (type == UNIFORM_FLOAT)
  566. {
  567. switch (info->components)
  568. {
  569. case 1:
  570. glUniform1fv(location, count, info->floats);
  571. break;
  572. case 2:
  573. glUniform2fv(location, count, info->floats);
  574. break;
  575. case 3:
  576. glUniform3fv(location, count, info->floats);
  577. break;
  578. case 4:
  579. glUniform4fv(location, count, info->floats);
  580. break;
  581. }
  582. }
  583. else if (type == UNIFORM_INT || type == UNIFORM_BOOL || type == UNIFORM_SAMPLER || type == UNIFORM_STORAGETEXTURE || type == UNIFORM_TEXELBUFFER)
  584. {
  585. switch (info->components)
  586. {
  587. case 1:
  588. glUniform1iv(location, count, info->ints);
  589. break;
  590. case 2:
  591. glUniform2iv(location, count, info->ints);
  592. break;
  593. case 3:
  594. glUniform3iv(location, count, info->ints);
  595. break;
  596. case 4:
  597. glUniform4iv(location, count, info->ints);
  598. break;
  599. }
  600. }
  601. else if (type == UNIFORM_UINT)
  602. {
  603. switch (info->components)
  604. {
  605. case 1:
  606. glUniform1uiv(location, count, info->uints);
  607. break;
  608. case 2:
  609. glUniform2uiv(location, count, info->uints);
  610. break;
  611. case 3:
  612. glUniform3uiv(location, count, info->uints);
  613. break;
  614. case 4:
  615. glUniform4uiv(location, count, info->uints);
  616. break;
  617. }
  618. }
  619. else if (type == UNIFORM_MATRIX)
  620. {
  621. int columns = info->matrix.columns;
  622. int rows = info->matrix.rows;
  623. if (columns == 2 && rows == 2)
  624. glUniformMatrix2fv(location, count, GL_FALSE, info->floats);
  625. else if (columns == 3 && rows == 3)
  626. glUniformMatrix3fv(location, count, GL_FALSE, info->floats);
  627. else if (columns == 4 && rows == 4)
  628. glUniformMatrix4fv(location, count, GL_FALSE, info->floats);
  629. else if (columns == 2 && rows == 3)
  630. glUniformMatrix2x3fv(location, count, GL_FALSE, info->floats);
  631. else if (columns == 2 && rows == 4)
  632. glUniformMatrix2x4fv(location, count, GL_FALSE, info->floats);
  633. else if (columns == 3 && rows == 2)
  634. glUniformMatrix3x2fv(location, count, GL_FALSE, info->floats);
  635. else if (columns == 3 && rows == 4)
  636. glUniformMatrix3x4fv(location, count, GL_FALSE, info->floats);
  637. else if (columns == 4 && rows == 2)
  638. glUniformMatrix4x2fv(location, count, GL_FALSE, info->floats);
  639. else if (columns == 4 && rows == 3)
  640. glUniformMatrix4x3fv(location, count, GL_FALSE, info->floats);
  641. }
  642. }
  643. void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count)
  644. {
  645. Shader::sendTextures(info, textures, count, false);
  646. }
  647. void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **textures, int count, bool internalUpdate)
  648. {
  649. bool issampler = info->baseType == UNIFORM_SAMPLER;
  650. bool isstoragetex = info->baseType == UNIFORM_STORAGETEXTURE;
  651. if (!issampler && !isstoragetex)
  652. return;
  653. bool shaderactive = current == this;
  654. if (!internalUpdate && shaderactive)
  655. flushBatchedDraws();
  656. count = std::min(count, info->count);
  657. // Bind the textures to the texture units.
  658. for (int i = 0; i < count; i++)
  659. {
  660. love::graphics::Texture *tex = textures[i];
  661. if (tex != nullptr)
  662. {
  663. if (!validateTexture(info, tex, internalUpdate))
  664. continue;
  665. tex->retain();
  666. }
  667. if (info->textures[i] != nullptr)
  668. info->textures[i]->release();
  669. info->textures[i] = tex;
  670. if (isstoragetex)
  671. {
  672. GLuint gltex = 0;
  673. if (tex != nullptr)
  674. gltex = (GLuint) tex->getHandle();
  675. else
  676. gltex = gl.getDefaultTexture(info->textureType, info->dataBaseType);
  677. int bindingindex = info->ints[i];
  678. auto &binding = storageTextureBindings[bindingindex];
  679. binding.texture = tex;
  680. binding.gltexture = gltex;
  681. if (shaderactive)
  682. glBindImageTexture(bindingindex, binding.gltexture, 0, GL_TRUE, 0, binding.access, binding.internalFormat);
  683. }
  684. else
  685. {
  686. GLuint gltex = 0;
  687. if (textures[i] != nullptr)
  688. gltex = (GLuint) tex->getHandle();
  689. else
  690. gltex = gl.getDefaultTexture(info->textureType, info->dataBaseType);
  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->getProjection();
  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. GLint location = builtinUniforms[BUILTIN_UNIFORMS_PER_DRAW];
  839. if (location >= 0)
  840. glUniform4fv(location, 13, (const GLfloat *) &data);
  841. }
  842. int Shader::getUniformTypeComponents(GLenum type) const
  843. {
  844. switch (type)
  845. {
  846. case GL_INT:
  847. case GL_UNSIGNED_INT:
  848. case GL_FLOAT:
  849. case GL_BOOL:
  850. return 1;
  851. case GL_INT_VEC2:
  852. case GL_UNSIGNED_INT_VEC2:
  853. case GL_FLOAT_VEC2:
  854. case GL_FLOAT_MAT2:
  855. case GL_BOOL_VEC2:
  856. return 2;
  857. case GL_INT_VEC3:
  858. case GL_UNSIGNED_INT_VEC3:
  859. case GL_FLOAT_VEC3:
  860. case GL_FLOAT_MAT3:
  861. case GL_BOOL_VEC3:
  862. return 3;
  863. case GL_INT_VEC4:
  864. case GL_UNSIGNED_INT_VEC4:
  865. case GL_FLOAT_VEC4:
  866. case GL_FLOAT_MAT4:
  867. case GL_BOOL_VEC4:
  868. return 4;
  869. default:
  870. return 1;
  871. }
  872. }
  873. Shader::MatrixSize Shader::getMatrixSize(GLenum type) const
  874. {
  875. MatrixSize m;
  876. switch (type)
  877. {
  878. case GL_FLOAT_MAT2:
  879. m.columns = m.rows = 2;
  880. break;
  881. case GL_FLOAT_MAT3:
  882. m.columns = m.rows = 3;
  883. break;
  884. case GL_FLOAT_MAT4:
  885. m.columns = m.rows = 4;
  886. break;
  887. case GL_FLOAT_MAT2x3:
  888. m.columns = 2;
  889. m.rows = 3;
  890. break;
  891. case GL_FLOAT_MAT2x4:
  892. m.columns = 2;
  893. m.rows = 4;
  894. break;
  895. case GL_FLOAT_MAT3x2:
  896. m.columns = 3;
  897. m.rows = 2;
  898. break;
  899. case GL_FLOAT_MAT3x4:
  900. m.columns = 3;
  901. m.rows = 4;
  902. break;
  903. case GL_FLOAT_MAT4x2:
  904. m.columns = 4;
  905. m.rows = 2;
  906. break;
  907. case GL_FLOAT_MAT4x3:
  908. m.columns = 4;
  909. m.rows = 3;
  910. break;
  911. default:
  912. m.columns = m.rows = 0;
  913. break;
  914. }
  915. return m;
  916. }
  917. void Shader::computeUniformTypeInfo(GLenum type, UniformInfo &u)
  918. {
  919. u.isDepthSampler = false;
  920. u.components = getUniformTypeComponents(type);
  921. u.baseType = UNIFORM_UNKNOWN;
  922. switch (type)
  923. {
  924. case GL_INT:
  925. case GL_INT_VEC2:
  926. case GL_INT_VEC3:
  927. case GL_INT_VEC4:
  928. u.baseType = UNIFORM_INT;
  929. u.dataBaseType = DATA_BASETYPE_INT;
  930. break;
  931. case GL_UNSIGNED_INT:
  932. case GL_UNSIGNED_INT_VEC2:
  933. case GL_UNSIGNED_INT_VEC3:
  934. case GL_UNSIGNED_INT_VEC4:
  935. u.baseType = UNIFORM_UINT;
  936. u.dataBaseType = DATA_BASETYPE_UINT;
  937. break;
  938. case GL_FLOAT:
  939. case GL_FLOAT_VEC2:
  940. case GL_FLOAT_VEC3:
  941. case GL_FLOAT_VEC4:
  942. u.baseType = UNIFORM_FLOAT;
  943. u.dataBaseType = DATA_BASETYPE_FLOAT;
  944. break;
  945. case GL_FLOAT_MAT2:
  946. case GL_FLOAT_MAT3:
  947. case GL_FLOAT_MAT4:
  948. case GL_FLOAT_MAT2x3:
  949. case GL_FLOAT_MAT2x4:
  950. case GL_FLOAT_MAT3x2:
  951. case GL_FLOAT_MAT3x4:
  952. case GL_FLOAT_MAT4x2:
  953. case GL_FLOAT_MAT4x3:
  954. u.baseType = UNIFORM_MATRIX;
  955. u.dataBaseType = DATA_BASETYPE_FLOAT;
  956. u.matrix = getMatrixSize(type);
  957. break;
  958. case GL_BOOL:
  959. case GL_BOOL_VEC2:
  960. case GL_BOOL_VEC3:
  961. case GL_BOOL_VEC4:
  962. u.baseType = UNIFORM_BOOL;
  963. u.dataBaseType = DATA_BASETYPE_BOOL;
  964. break;
  965. case GL_SAMPLER_2D:
  966. u.baseType = UNIFORM_SAMPLER;
  967. u.dataBaseType = DATA_BASETYPE_FLOAT;
  968. u.textureType = TEXTURE_2D;
  969. break;
  970. case GL_SAMPLER_2D_SHADOW:
  971. u.baseType = UNIFORM_SAMPLER;
  972. u.dataBaseType = DATA_BASETYPE_FLOAT;
  973. u.textureType = TEXTURE_2D;
  974. u.isDepthSampler = true;
  975. break;
  976. case GL_INT_SAMPLER_2D:
  977. u.baseType = UNIFORM_SAMPLER;
  978. u.dataBaseType = DATA_BASETYPE_INT;
  979. u.textureType = TEXTURE_2D;
  980. break;
  981. case GL_UNSIGNED_INT_SAMPLER_2D:
  982. u.baseType = UNIFORM_SAMPLER;
  983. u.dataBaseType = DATA_BASETYPE_UINT;
  984. u.textureType = TEXTURE_2D;
  985. break;
  986. case GL_SAMPLER_2D_ARRAY:
  987. u.baseType = UNIFORM_SAMPLER;
  988. u.dataBaseType = DATA_BASETYPE_FLOAT;
  989. u.textureType = TEXTURE_2D_ARRAY;
  990. break;
  991. case GL_SAMPLER_2D_ARRAY_SHADOW:
  992. u.baseType = UNIFORM_SAMPLER;
  993. u.dataBaseType = DATA_BASETYPE_FLOAT;
  994. u.textureType = TEXTURE_2D_ARRAY;
  995. u.isDepthSampler = true;
  996. break;
  997. case GL_INT_SAMPLER_2D_ARRAY:
  998. u.baseType = UNIFORM_SAMPLER;
  999. u.dataBaseType = DATA_BASETYPE_INT;
  1000. u.textureType = TEXTURE_2D_ARRAY;
  1001. break;
  1002. case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
  1003. u.baseType = UNIFORM_SAMPLER;
  1004. u.dataBaseType = DATA_BASETYPE_UINT;
  1005. u.textureType = TEXTURE_2D_ARRAY;
  1006. break;
  1007. case GL_SAMPLER_3D:
  1008. u.baseType = UNIFORM_SAMPLER;
  1009. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1010. u.textureType = TEXTURE_VOLUME;
  1011. break;
  1012. case GL_INT_SAMPLER_3D:
  1013. u.baseType = UNIFORM_SAMPLER;
  1014. u.dataBaseType = DATA_BASETYPE_INT;
  1015. u.textureType = TEXTURE_VOLUME;
  1016. break;
  1017. case GL_UNSIGNED_INT_SAMPLER_3D:
  1018. u.baseType = UNIFORM_SAMPLER;
  1019. u.dataBaseType = DATA_BASETYPE_UINT;
  1020. u.textureType = TEXTURE_VOLUME;
  1021. break;
  1022. case GL_SAMPLER_CUBE:
  1023. u.baseType = UNIFORM_SAMPLER;
  1024. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1025. u.textureType = TEXTURE_CUBE;
  1026. break;
  1027. case GL_SAMPLER_CUBE_SHADOW:
  1028. u.baseType = UNIFORM_SAMPLER;
  1029. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1030. u.textureType = TEXTURE_CUBE;
  1031. u.isDepthSampler = true;
  1032. break;
  1033. case GL_INT_SAMPLER_CUBE:
  1034. u.baseType = UNIFORM_SAMPLER;
  1035. u.dataBaseType = DATA_BASETYPE_INT;
  1036. u.textureType = TEXTURE_CUBE;
  1037. break;
  1038. case GL_UNSIGNED_INT_SAMPLER_CUBE:
  1039. u.baseType = UNIFORM_SAMPLER;
  1040. u.dataBaseType = DATA_BASETYPE_UINT;
  1041. u.textureType = TEXTURE_CUBE;
  1042. break;
  1043. case GL_SAMPLER_BUFFER:
  1044. u.baseType = UNIFORM_TEXELBUFFER;
  1045. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1046. break;
  1047. case GL_INT_SAMPLER_BUFFER:
  1048. u.baseType = UNIFORM_TEXELBUFFER;
  1049. u.dataBaseType = DATA_BASETYPE_INT;
  1050. break;
  1051. case GL_UNSIGNED_INT_SAMPLER_BUFFER:
  1052. u.baseType = UNIFORM_TEXELBUFFER;
  1053. u.dataBaseType = DATA_BASETYPE_UINT;
  1054. break;
  1055. case GL_IMAGE_2D:
  1056. u.baseType = UNIFORM_STORAGETEXTURE;
  1057. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1058. u.textureType = TEXTURE_2D;
  1059. break;
  1060. case GL_INT_IMAGE_2D:
  1061. u.baseType = UNIFORM_STORAGETEXTURE;
  1062. u.dataBaseType = DATA_BASETYPE_INT;
  1063. u.textureType = TEXTURE_2D;
  1064. break;
  1065. case GL_UNSIGNED_INT_IMAGE_2D:
  1066. u.baseType = UNIFORM_STORAGETEXTURE;
  1067. u.dataBaseType = DATA_BASETYPE_UINT;
  1068. u.textureType = TEXTURE_2D;
  1069. break;
  1070. case GL_IMAGE_2D_ARRAY:
  1071. u.baseType = UNIFORM_STORAGETEXTURE;
  1072. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1073. u.textureType = TEXTURE_2D_ARRAY;
  1074. break;
  1075. case GL_INT_IMAGE_2D_ARRAY:
  1076. u.baseType = UNIFORM_STORAGETEXTURE;
  1077. u.dataBaseType = DATA_BASETYPE_INT;
  1078. u.textureType = TEXTURE_2D_ARRAY;
  1079. break;
  1080. case GL_UNSIGNED_INT_IMAGE_2D_ARRAY:
  1081. u.baseType = UNIFORM_STORAGETEXTURE;
  1082. u.dataBaseType = DATA_BASETYPE_UINT;
  1083. u.textureType = TEXTURE_2D_ARRAY;
  1084. break;
  1085. case GL_IMAGE_3D:
  1086. u.baseType = UNIFORM_STORAGETEXTURE;
  1087. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1088. u.textureType = TEXTURE_VOLUME;
  1089. break;
  1090. case GL_INT_IMAGE_3D:
  1091. u.baseType = UNIFORM_STORAGETEXTURE;
  1092. u.dataBaseType = DATA_BASETYPE_INT;
  1093. u.textureType = TEXTURE_VOLUME;
  1094. break;
  1095. case GL_UNSIGNED_INT_IMAGE_3D:
  1096. u.baseType = UNIFORM_STORAGETEXTURE;
  1097. u.dataBaseType = DATA_BASETYPE_UINT;
  1098. u.textureType = TEXTURE_VOLUME;
  1099. break;
  1100. case GL_IMAGE_CUBE:
  1101. u.baseType = UNIFORM_STORAGETEXTURE;
  1102. u.dataBaseType = DATA_BASETYPE_FLOAT;
  1103. u.textureType = TEXTURE_CUBE;
  1104. break;
  1105. case GL_INT_IMAGE_CUBE:
  1106. u.baseType = UNIFORM_STORAGETEXTURE;
  1107. u.dataBaseType = DATA_BASETYPE_INT;
  1108. u.textureType = TEXTURE_CUBE;
  1109. break;
  1110. case GL_UNSIGNED_INT_IMAGE_CUBE:
  1111. u.baseType = UNIFORM_STORAGETEXTURE;
  1112. u.dataBaseType = DATA_BASETYPE_UINT;
  1113. u.textureType = TEXTURE_CUBE;
  1114. break;
  1115. default:
  1116. break;
  1117. }
  1118. }
  1119. } // opengl
  1120. } // graphics
  1121. } // love