💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

773 lines
20 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "gl/shader-input.hpp"
  20. #include "gl/texture-1d.hpp"
  21. #include "gl/texture-2d.hpp"
  22. #include "gl/texture-3d.hpp"
  23. #include "gl/texture-cube.hpp"
  24. #include <glad/glad.h>
  25. namespace gl {
  26. shader_input::shader_input(shader_program* program, std::size_t input_index, int gl_uniform_location, const std::string& name, shader_variable_type data_type, std::size_t element_count, int texture_unit):
  27. program(program),
  28. input_index(input_index),
  29. gl_uniform_location(gl_uniform_location),
  30. name(name),
  31. data_type(data_type),
  32. element_count(element_count),
  33. texture_unit(texture_unit)
  34. {}
  35. shader_input::~shader_input()
  36. {}
  37. bool shader_input::upload(const bool& value) const
  38. {
  39. if (gl_uniform_location == -1)
  40. return false;
  41. glUniform1i(gl_uniform_location, static_cast<GLint>(value));
  42. return true;
  43. }
  44. bool shader_input::upload(const bool2& value) const
  45. {
  46. if (gl_uniform_location == -1)
  47. return false;
  48. const GLint values[] = {value[0], value[1]};
  49. glUniform2iv(gl_uniform_location, 1, values);
  50. return true;
  51. }
  52. bool shader_input::upload(const bool3& value) const
  53. {
  54. if (gl_uniform_location == -1)
  55. return false;
  56. const GLint values[] = {value[0], value[1], value[2]};
  57. glUniform3iv(gl_uniform_location, 1, values);
  58. return true;
  59. }
  60. bool shader_input::upload(const bool4& value) const
  61. {
  62. if (gl_uniform_location == -1)
  63. return false;
  64. const GLint values[] = {value[0], value[1], value[2], value[3]};
  65. glUniform4iv(gl_uniform_location, 1, values);
  66. return true;
  67. }
  68. bool shader_input::upload(const int& value) const
  69. {
  70. if (gl_uniform_location == -1)
  71. return false;
  72. glUniform1i(gl_uniform_location, value);
  73. return true;
  74. }
  75. bool shader_input::upload(const int2& value) const
  76. {
  77. if (gl_uniform_location == -1)
  78. return false;
  79. glUniform2iv(gl_uniform_location, 1, value.data());
  80. return true;
  81. }
  82. bool shader_input::upload(const int3& value) const
  83. {
  84. if (gl_uniform_location == -1)
  85. return false;
  86. glUniform3iv(gl_uniform_location, 1, value.data());
  87. return true;
  88. }
  89. bool shader_input::upload(const int4& value) const
  90. {
  91. if (gl_uniform_location == -1)
  92. return false;
  93. glUniform4iv(gl_uniform_location, 1, value.data());
  94. return true;
  95. }
  96. bool shader_input::upload(const unsigned int& value) const
  97. {
  98. if (gl_uniform_location == -1)
  99. return false;
  100. glUniform1ui(gl_uniform_location, value);
  101. return true;
  102. }
  103. bool shader_input::upload(const uint2& value) const
  104. {
  105. if (gl_uniform_location == -1)
  106. return false;
  107. glUniform2uiv(gl_uniform_location, 1, value.data());
  108. return true;
  109. }
  110. bool shader_input::upload(const uint3& value) const
  111. {
  112. if (gl_uniform_location == -1)
  113. return false;
  114. glUniform3uiv(gl_uniform_location, 1, value.data());
  115. return true;
  116. }
  117. bool shader_input::upload(const uint4& value) const
  118. {
  119. if (gl_uniform_location == -1)
  120. return false;
  121. glUniform4uiv(gl_uniform_location, 1, value.data());
  122. return true;
  123. }
  124. bool shader_input::upload(const float& value) const
  125. {
  126. if (gl_uniform_location == -1)
  127. return false;
  128. glUniform1f(gl_uniform_location, value);
  129. return true;
  130. }
  131. bool shader_input::upload(const float2& value) const
  132. {
  133. if (gl_uniform_location == -1)
  134. return false;
  135. glUniform2fv(gl_uniform_location, 1, value.data());
  136. return true;
  137. }
  138. bool shader_input::upload(const float3& value) const
  139. {
  140. if (gl_uniform_location == -1)
  141. return false;
  142. glUniform3fv(gl_uniform_location, 1, value.data());
  143. return true;
  144. }
  145. bool shader_input::upload(const float4& value) const
  146. {
  147. if (gl_uniform_location == -1)
  148. return false;
  149. glUniform4fv(gl_uniform_location, 1, value.data());
  150. return true;
  151. }
  152. bool shader_input::upload(const float2x2& value) const
  153. {
  154. if (gl_uniform_location == -1)
  155. return false;
  156. glUniformMatrix2fv(gl_uniform_location, 1, GL_FALSE, value[0].data());
  157. return true;
  158. }
  159. bool shader_input::upload(const float3x3& value) const
  160. {
  161. if (gl_uniform_location == -1)
  162. return false;
  163. glUniformMatrix3fv(gl_uniform_location, 1, GL_FALSE, value[0].data());
  164. return true;
  165. }
  166. bool shader_input::upload(const float4x4& value) const
  167. {
  168. if (gl_uniform_location == -1)
  169. return false;
  170. glUniformMatrix4fv(gl_uniform_location, 1, GL_FALSE, value[0].data());
  171. return true;
  172. }
  173. bool shader_input::upload(const texture_1d* value) const
  174. {
  175. if (gl_uniform_location == -1)
  176. return false;
  177. // Bind texture to a texture unit reserved by this shader input
  178. glActiveTexture(GL_TEXTURE0 + texture_unit);
  179. glBindTexture(GL_TEXTURE_1D, value->gl_texture_id);
  180. // Upload texture unit index to shader
  181. glUniform1i(gl_uniform_location, texture_unit);
  182. return true;
  183. }
  184. bool shader_input::upload(const texture_2d* value) const
  185. {
  186. if (gl_uniform_location == -1)
  187. return false;
  188. // Bind texture to a texture unit reserved by this shader input
  189. glActiveTexture(GL_TEXTURE0 + texture_unit);
  190. glBindTexture(GL_TEXTURE_2D, value->gl_texture_id);
  191. // Upload texture unit index to shader
  192. glUniform1i(gl_uniform_location, texture_unit);
  193. return true;
  194. }
  195. bool shader_input::upload(const texture_3d* value) const
  196. {
  197. if (gl_uniform_location == -1)
  198. return false;
  199. // Bind texture to a texture unit reserved by this shader input
  200. glActiveTexture(GL_TEXTURE0 + texture_unit);
  201. glBindTexture(GL_TEXTURE_3D, value->gl_texture_id);
  202. // Upload texture unit index to shader
  203. glUniform1i(gl_uniform_location, texture_unit);
  204. return true;
  205. }
  206. bool shader_input::upload(const texture_cube* value) const
  207. {
  208. if (gl_uniform_location == -1)
  209. return false;
  210. // Bind texture to a texture unit reserved by this shader input
  211. glActiveTexture(GL_TEXTURE0 + texture_unit);
  212. glBindTexture(GL_TEXTURE_CUBE_MAP, value->gl_texture_id);
  213. // Upload texture unit index to shader
  214. glUniform1i(gl_uniform_location, texture_unit);
  215. return true;
  216. }
  217. bool shader_input::upload(std::size_t index, const bool& value) const
  218. {
  219. if (gl_uniform_location == -1)
  220. return false;
  221. glUniform1i(gl_uniform_location + static_cast<int>(index), static_cast<GLint>(value));
  222. return true;
  223. }
  224. bool shader_input::upload(std::size_t index, const bool2& value) const
  225. {
  226. if (gl_uniform_location == -1)
  227. return false;
  228. const GLint values[] = {value[0], value[1]};
  229. glUniform2iv(gl_uniform_location + static_cast<int>(index), 1, values);
  230. return true;
  231. }
  232. bool shader_input::upload(std::size_t index, const bool3& value) const
  233. {
  234. if (gl_uniform_location == -1)
  235. return false;
  236. const GLint values[] = {value[0], value[1], value[3]};
  237. glUniform3iv(gl_uniform_location + static_cast<int>(index), 1, values);
  238. return true;
  239. }
  240. bool shader_input::upload(std::size_t index, const bool4& value) const
  241. {
  242. if (gl_uniform_location == -1)
  243. return false;
  244. const GLint values[] = {value[0], value[1], value[3], value[4]};
  245. glUniform4iv(gl_uniform_location + static_cast<int>(index), 1, values);
  246. return true;
  247. }
  248. bool shader_input::upload(std::size_t index, const int& value) const
  249. {
  250. if (gl_uniform_location == -1)
  251. return false;
  252. glUniform1i(gl_uniform_location + static_cast<int>(index), value);
  253. return true;
  254. }
  255. bool shader_input::upload(std::size_t index, const int2& value) const
  256. {
  257. if (gl_uniform_location == -1)
  258. return false;
  259. glUniform2iv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  260. return true;
  261. }
  262. bool shader_input::upload(std::size_t index, const int3& value) const
  263. {
  264. if (gl_uniform_location == -1)
  265. return false;
  266. glUniform3iv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  267. return true;
  268. }
  269. bool shader_input::upload(std::size_t index, const int4& value) const
  270. {
  271. if (gl_uniform_location == -1)
  272. return false;
  273. glUniform4iv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  274. return true;
  275. }
  276. bool shader_input::upload(std::size_t index, const unsigned int& value) const
  277. {
  278. if (gl_uniform_location == -1)
  279. return false;
  280. glUniform1ui(gl_uniform_location + static_cast<int>(index), value);
  281. return true;
  282. }
  283. bool shader_input::upload(std::size_t index, const uint2& value) const
  284. {
  285. if (gl_uniform_location == -1)
  286. return false;
  287. glUniform2uiv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  288. return true;
  289. }
  290. bool shader_input::upload(std::size_t index, const uint3& value) const
  291. {
  292. if (gl_uniform_location == -1)
  293. return false;
  294. glUniform3uiv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  295. return true;
  296. }
  297. bool shader_input::upload(std::size_t index, const uint4& value) const
  298. {
  299. if (gl_uniform_location == -1)
  300. return false;
  301. glUniform4uiv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  302. return true;
  303. }
  304. bool shader_input::upload(std::size_t index, const float& value) const
  305. {
  306. if (gl_uniform_location == -1)
  307. return false;
  308. glUniform1f(gl_uniform_location + static_cast<int>(index), value);
  309. return true;
  310. }
  311. bool shader_input::upload(std::size_t index, const float2& value) const
  312. {
  313. if (gl_uniform_location == -1)
  314. return false;
  315. glUniform2fv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  316. return true;
  317. }
  318. bool shader_input::upload(std::size_t index, const float3& value) const
  319. {
  320. if (gl_uniform_location == -1)
  321. return false;
  322. glUniform3fv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  323. return true;
  324. }
  325. bool shader_input::upload(std::size_t index, const float4& value) const
  326. {
  327. if (gl_uniform_location == -1)
  328. return false;
  329. glUniform4fv(gl_uniform_location + static_cast<int>(index), 1, value.data());
  330. return true;
  331. }
  332. bool shader_input::upload(std::size_t index, const float2x2& value) const
  333. {
  334. if (gl_uniform_location == -1)
  335. return false;
  336. glUniformMatrix2fv(gl_uniform_location + static_cast<int>(index) * 2, 1, GL_FALSE, value[0].data());
  337. return true;
  338. }
  339. bool shader_input::upload(std::size_t index, const float3x3& value) const
  340. {
  341. if (gl_uniform_location == -1)
  342. return false;
  343. glUniformMatrix3fv(gl_uniform_location + static_cast<int>(index) * 3, 1, GL_FALSE, value[0].data());
  344. return true;
  345. }
  346. bool shader_input::upload(std::size_t index, const float4x4& value) const
  347. {
  348. if (gl_uniform_location == -1)
  349. return false;
  350. glUniformMatrix4fv(gl_uniform_location + static_cast<int>(index) * 4, 1, GL_FALSE, value[0].data());
  351. return true;
  352. }
  353. bool shader_input::upload(std::size_t index, const texture_1d* value) const
  354. {
  355. if (gl_uniform_location == -1)
  356. return false;
  357. // Bind texture to a texture unit reserved by this shader input
  358. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index));
  359. glBindTexture(GL_TEXTURE_1D, value->gl_texture_id);
  360. // Upload texture unit index to shader
  361. glUniform1i(gl_uniform_location + static_cast<int>(index), texture_unit + static_cast<int>(index));
  362. return true;
  363. }
  364. bool shader_input::upload(std::size_t index, const texture_2d* value) const
  365. {
  366. if (gl_uniform_location == -1)
  367. return false;
  368. // Bind texture to a texture unit reserved by this shader input
  369. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index));
  370. glBindTexture(GL_TEXTURE_2D, value->gl_texture_id);
  371. // Upload texture unit index to shader
  372. glUniform1i(gl_uniform_location + static_cast<int>(index), texture_unit + static_cast<int>(index));
  373. return true;
  374. }
  375. bool shader_input::upload(std::size_t index, const texture_3d* value) const
  376. {
  377. if (gl_uniform_location == -1)
  378. return false;
  379. // Bind texture to a texture unit reserved by this shader input
  380. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index));
  381. glBindTexture(GL_TEXTURE_3D, value->gl_texture_id);
  382. // Upload texture unit index to shader
  383. glUniform1i(gl_uniform_location + static_cast<int>(index), texture_unit + static_cast<int>(index));
  384. return true;
  385. }
  386. bool shader_input::upload(std::size_t index, const texture_cube* value) const
  387. {
  388. if (gl_uniform_location == -1)
  389. return false;
  390. // Bind texture to a texture unit reserved by this shader input
  391. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index));
  392. glBindTexture(GL_TEXTURE_CUBE_MAP, value->gl_texture_id);
  393. // Upload texture unit index to shader
  394. glUniform1i(gl_uniform_location + static_cast<int>(index), texture_unit + static_cast<int>(index));
  395. return true;
  396. }
  397. bool shader_input::upload(std::size_t index, const bool* values, std::size_t count) const
  398. {
  399. if (gl_uniform_location == -1)
  400. return false;
  401. int* int_values = new int[count];
  402. for (std::size_t i = 0; i < count; ++i)
  403. int_values[i] = values[i];
  404. glUniform1iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &(*int_values));
  405. delete[] int_values;
  406. return true;
  407. }
  408. bool shader_input::upload(std::size_t index, const bool2* values, std::size_t count) const
  409. {
  410. if (gl_uniform_location == -1)
  411. return false;
  412. int2* int2_values = new int2[count];
  413. for (std::size_t i = 0; i < count; ++i)
  414. int2_values[i] = {values[i][0], values[i][1]};
  415. glUniform2iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &((*int2_values)[0]));
  416. delete[] int2_values;
  417. return true;
  418. }
  419. bool shader_input::upload(std::size_t index, const bool3* values, std::size_t count) const
  420. {
  421. if (gl_uniform_location == -1)
  422. return false;
  423. int3* int3_values = new int3[count];
  424. for (std::size_t i = 0; i < count; ++i)
  425. int3_values[i] = {values[i][0], values[i][1], values[i][2]};
  426. glUniform3iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &((*int3_values)[0]));
  427. delete[] int3_values;
  428. return true;
  429. }
  430. bool shader_input::upload(std::size_t index, const bool4* values, std::size_t count) const
  431. {
  432. if (gl_uniform_location == -1)
  433. return false;
  434. int4* int4_values = new int4[count];
  435. for (std::size_t i = 0; i < count; ++i)
  436. int4_values[i] = {values[i][0], values[i][1], values[i][2], values[i][3]};
  437. glUniform4iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &((*int4_values)[0]));
  438. delete[] int4_values;
  439. return true;
  440. }
  441. bool shader_input::upload(std::size_t index, const int* values, std::size_t count) const
  442. {
  443. if (gl_uniform_location == -1)
  444. return false;
  445. glUniform1iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &(*values));
  446. return true;
  447. }
  448. bool shader_input::upload(std::size_t index, const int2* values, std::size_t count) const
  449. {
  450. if (gl_uniform_location == -1)
  451. return false;
  452. glUniform2iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  453. return true;
  454. }
  455. bool shader_input::upload(std::size_t index, const int3* values, std::size_t count) const
  456. {
  457. if (gl_uniform_location == -1)
  458. return false;
  459. glUniform3iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  460. return true;
  461. }
  462. bool shader_input::upload(std::size_t index, const int4* values, std::size_t count) const
  463. {
  464. if (gl_uniform_location == -1)
  465. return false;
  466. glUniform4iv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  467. return true;
  468. }
  469. bool shader_input::upload(std::size_t index, const unsigned int* values, std::size_t count) const
  470. {
  471. if (gl_uniform_location == -1)
  472. return false;
  473. glUniform1uiv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &(*values));
  474. return true;
  475. }
  476. bool shader_input::upload(std::size_t index, const uint2* values, std::size_t count) const
  477. {
  478. if (gl_uniform_location == -1)
  479. return false;
  480. glUniform2uiv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  481. return true;
  482. }
  483. bool shader_input::upload(std::size_t index, const uint3* values, std::size_t count) const
  484. {
  485. if (gl_uniform_location == -1)
  486. return false;
  487. glUniform3uiv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  488. return true;
  489. }
  490. bool shader_input::upload(std::size_t index, const uint4* values, std::size_t count) const
  491. {
  492. if (gl_uniform_location == -1)
  493. return false;
  494. glUniform4uiv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  495. return true;
  496. }
  497. bool shader_input::upload(std::size_t index, const float* values, std::size_t count) const
  498. {
  499. if (gl_uniform_location == -1)
  500. return false;
  501. glUniform1fv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), &(*values));
  502. return true;
  503. }
  504. bool shader_input::upload(std::size_t index, const float2* values, std::size_t count) const
  505. {
  506. if (gl_uniform_location == -1)
  507. return false;
  508. glUniform2fv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  509. return true;
  510. }
  511. bool shader_input::upload(std::size_t index, const float3* values, std::size_t count) const
  512. {
  513. if (gl_uniform_location == -1)
  514. return false;
  515. glUniform3fv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  516. return true;
  517. }
  518. bool shader_input::upload(std::size_t index, const float4* values, std::size_t count) const
  519. {
  520. if (gl_uniform_location == -1)
  521. return false;
  522. glUniform4fv(gl_uniform_location + static_cast<int>(index), static_cast<GLsizei>(count), (*values).data());
  523. return true;
  524. }
  525. bool shader_input::upload(std::size_t index, const float2x2* values, std::size_t count) const
  526. {
  527. if (gl_uniform_location == -1)
  528. return false;
  529. glUniformMatrix2fv(gl_uniform_location + static_cast<int>(index) * 2, static_cast<GLsizei>(count), GL_FALSE, (*values)[0].data());
  530. return true;
  531. }
  532. bool shader_input::upload(std::size_t index, const float3x3* values, std::size_t count) const
  533. {
  534. if (gl_uniform_location == -1)
  535. return false;
  536. glUniformMatrix3fv(gl_uniform_location + static_cast<int>(index) * 3, static_cast<GLsizei>(count), GL_FALSE, (*values)[0].data());
  537. return true;
  538. }
  539. bool shader_input::upload(std::size_t index, const float4x4* values, std::size_t count) const
  540. {
  541. if (gl_uniform_location == -1)
  542. return false;
  543. glUniformMatrix4fv(gl_uniform_location + static_cast<int>(index) * 4, static_cast<GLsizei>(count), GL_FALSE, (*values)[0].data());
  544. return true;
  545. }
  546. bool shader_input::upload(std::size_t index, const texture_1d** values, std::size_t count) const
  547. {
  548. if (gl_uniform_location == -1)
  549. return false;
  550. for (std::size_t i = 0; i < count; ++i)
  551. {
  552. // Bind texture to a texture unit reserved by this shader input
  553. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index + i));
  554. glBindTexture(GL_TEXTURE_1D, values[i]->gl_texture_id);
  555. // Upload texture unit index to shader
  556. glUniform1i(gl_uniform_location + static_cast<int>(index + i), texture_unit + static_cast<int>(index + i));
  557. }
  558. return true;
  559. }
  560. bool shader_input::upload(std::size_t index, const texture_2d** values, std::size_t count) const
  561. {
  562. if (gl_uniform_location == -1)
  563. return false;
  564. for (std::size_t i = 0; i < count; ++i)
  565. {
  566. // Bind texture to a texture unit reserved by this shader input
  567. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index + i));
  568. glBindTexture(GL_TEXTURE_2D, values[i]->gl_texture_id);
  569. // Upload texture unit index to shader
  570. glUniform1i(gl_uniform_location + static_cast<int>(index + i), texture_unit + static_cast<int>(index + i));
  571. }
  572. return true;
  573. }
  574. bool shader_input::upload(std::size_t index, const texture_3d** values, std::size_t count) const
  575. {
  576. if (gl_uniform_location == -1)
  577. return false;
  578. for (std::size_t i = 0; i < count; ++i)
  579. {
  580. // Bind texture to a texture unit reserved by this shader input
  581. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index + i));
  582. glBindTexture(GL_TEXTURE_3D, values[i]->gl_texture_id);
  583. // Upload texture unit index to shader
  584. glUniform1i(gl_uniform_location + static_cast<int>(index + i), texture_unit + static_cast<int>(index + i));
  585. }
  586. return true;
  587. }
  588. bool shader_input::upload(std::size_t index, const texture_cube** values, std::size_t count) const
  589. {
  590. if (gl_uniform_location == -1)
  591. return false;
  592. for (std::size_t i = 0; i < count; ++i)
  593. {
  594. // Bind texture to a texture unit reserved by this shader input
  595. glActiveTexture(GL_TEXTURE0 + texture_unit + static_cast<int>(index + i));
  596. glBindTexture(GL_TEXTURE_CUBE_MAP, values[i]->gl_texture_id);
  597. // Upload texture unit index to shader
  598. glUniform1i(gl_uniform_location + static_cast<int>(index + i), texture_unit + static_cast<int>(index + i));
  599. }
  600. return true;
  601. }
  602. } // namespace gl