gl_state.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <iterator>
  5. #include <glad/glad.h>
  6. #include "common/assert.h"
  7. #include "common/logging/log.h"
  8. #include "video_core/renderer_opengl/gl_state.h"
  9. namespace OpenGL {
  10. using Maxwell = Tegra::Engines::Maxwell3D::Regs;
  11. OpenGLState OpenGLState::cur_state;
  12. bool OpenGLState::s_rgb_used;
  13. namespace {
  14. template <typename T>
  15. bool UpdateValue(T& current_value, const T new_value) {
  16. const bool changed = current_value != new_value;
  17. current_value = new_value;
  18. return changed;
  19. }
  20. template <typename T1, typename T2>
  21. bool UpdateTie(T1 current_value, const T2 new_value) {
  22. const bool changed = current_value != new_value;
  23. current_value = new_value;
  24. return changed;
  25. }
  26. void Enable(GLenum cap, bool enable) {
  27. if (enable) {
  28. glEnable(cap);
  29. } else {
  30. glDisable(cap);
  31. }
  32. }
  33. void Enable(GLenum cap, GLuint index, bool enable) {
  34. if (enable) {
  35. glEnablei(cap, index);
  36. } else {
  37. glDisablei(cap, index);
  38. }
  39. }
  40. void Enable(GLenum cap, bool& current_value, bool new_value) {
  41. if (UpdateValue(current_value, new_value))
  42. Enable(cap, new_value);
  43. }
  44. void Enable(GLenum cap, GLuint index, bool& current_value, bool new_value) {
  45. if (UpdateValue(current_value, new_value))
  46. Enable(cap, index, new_value);
  47. }
  48. } // namespace
  49. OpenGLState::OpenGLState() {
  50. // These all match default OpenGL values
  51. framebuffer_srgb.enabled = false;
  52. multisample_control.alpha_to_coverage = false;
  53. multisample_control.alpha_to_one = false;
  54. cull.enabled = false;
  55. cull.mode = GL_BACK;
  56. cull.front_face = GL_CCW;
  57. depth.test_enabled = false;
  58. depth.test_func = GL_LESS;
  59. depth.write_mask = GL_TRUE;
  60. primitive_restart.enabled = false;
  61. primitive_restart.index = 0;
  62. for (auto& item : color_mask) {
  63. item.red_enabled = GL_TRUE;
  64. item.green_enabled = GL_TRUE;
  65. item.blue_enabled = GL_TRUE;
  66. item.alpha_enabled = GL_TRUE;
  67. }
  68. const auto ResetStencil = [](auto& config) {
  69. config.test_func = GL_ALWAYS;
  70. config.test_ref = 0;
  71. config.test_mask = 0xFFFFFFFF;
  72. config.write_mask = 0xFFFFFFFF;
  73. config.action_depth_fail = GL_KEEP;
  74. config.action_depth_pass = GL_KEEP;
  75. config.action_stencil_fail = GL_KEEP;
  76. };
  77. stencil.test_enabled = false;
  78. ResetStencil(stencil.front);
  79. ResetStencil(stencil.back);
  80. for (auto& item : viewports) {
  81. item.x = 0;
  82. item.y = 0;
  83. item.width = 0;
  84. item.height = 0;
  85. item.depth_range_near = 0.0f;
  86. item.depth_range_far = 1.0f;
  87. item.scissor.enabled = false;
  88. item.scissor.x = 0;
  89. item.scissor.y = 0;
  90. item.scissor.width = 0;
  91. item.scissor.height = 0;
  92. }
  93. for (auto& item : blend) {
  94. item.enabled = true;
  95. item.rgb_equation = GL_FUNC_ADD;
  96. item.a_equation = GL_FUNC_ADD;
  97. item.src_rgb_func = GL_ONE;
  98. item.dst_rgb_func = GL_ZERO;
  99. item.src_a_func = GL_ONE;
  100. item.dst_a_func = GL_ZERO;
  101. }
  102. independant_blend.enabled = false;
  103. blend_color.red = 0.0f;
  104. blend_color.green = 0.0f;
  105. blend_color.blue = 0.0f;
  106. blend_color.alpha = 0.0f;
  107. logic_op.enabled = false;
  108. logic_op.operation = GL_COPY;
  109. for (auto& texture_unit : texture_units) {
  110. texture_unit.Reset();
  111. }
  112. draw.read_framebuffer = 0;
  113. draw.draw_framebuffer = 0;
  114. draw.vertex_array = 0;
  115. draw.shader_program = 0;
  116. draw.program_pipeline = 0;
  117. clip_distance = {};
  118. point.size = 1;
  119. fragment_color_clamp.enabled = false;
  120. depth_clamp.far_plane = false;
  121. depth_clamp.near_plane = false;
  122. polygon_offset.fill_enable = false;
  123. polygon_offset.line_enable = false;
  124. polygon_offset.point_enable = false;
  125. polygon_offset.factor = 0.0f;
  126. polygon_offset.units = 0.0f;
  127. polygon_offset.clamp = 0.0f;
  128. }
  129. void OpenGLState::ApplyDefaultState() {
  130. glEnable(GL_BLEND);
  131. glDisable(GL_FRAMEBUFFER_SRGB);
  132. glDisable(GL_CULL_FACE);
  133. glDisable(GL_DEPTH_TEST);
  134. glDisable(GL_PRIMITIVE_RESTART);
  135. glDisable(GL_STENCIL_TEST);
  136. glDisable(GL_COLOR_LOGIC_OP);
  137. glDisable(GL_SCISSOR_TEST);
  138. }
  139. void OpenGLState::ApplyFramebufferState() const {
  140. if (UpdateValue(cur_state.draw.read_framebuffer, draw.read_framebuffer)) {
  141. glBindFramebuffer(GL_READ_FRAMEBUFFER, draw.read_framebuffer);
  142. }
  143. if (UpdateValue(cur_state.draw.draw_framebuffer, draw.draw_framebuffer)) {
  144. glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw.draw_framebuffer);
  145. }
  146. }
  147. void OpenGLState::ApplyVertexArrayState() const {
  148. if (UpdateValue(cur_state.draw.vertex_array, draw.vertex_array)) {
  149. glBindVertexArray(draw.vertex_array);
  150. }
  151. }
  152. void OpenGLState::ApplyShaderProgram() const {
  153. if (UpdateValue(cur_state.draw.shader_program, draw.shader_program)) {
  154. glUseProgram(draw.shader_program);
  155. }
  156. }
  157. void OpenGLState::ApplyProgramPipeline() const {
  158. if (UpdateValue(cur_state.draw.program_pipeline, draw.program_pipeline)) {
  159. glBindProgramPipeline(draw.program_pipeline);
  160. }
  161. }
  162. void OpenGLState::ApplyClipDistances() const {
  163. for (std::size_t i = 0; i < clip_distance.size(); ++i) {
  164. Enable(GL_CLIP_DISTANCE0 + static_cast<GLenum>(i), cur_state.clip_distance[i],
  165. clip_distance[i]);
  166. }
  167. }
  168. void OpenGLState::ApplyPointSize() const {
  169. if (UpdateValue(cur_state.point.size, point.size)) {
  170. glPointSize(point.size);
  171. }
  172. }
  173. void OpenGLState::ApplyFragmentColorClamp() const {
  174. if (UpdateValue(cur_state.fragment_color_clamp.enabled, fragment_color_clamp.enabled)) {
  175. glClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB,
  176. fragment_color_clamp.enabled ? GL_TRUE : GL_FALSE);
  177. }
  178. }
  179. void OpenGLState::ApplyMultisample() const {
  180. Enable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur_state.multisample_control.alpha_to_coverage,
  181. multisample_control.alpha_to_coverage);
  182. Enable(GL_SAMPLE_ALPHA_TO_ONE, cur_state.multisample_control.alpha_to_one,
  183. multisample_control.alpha_to_one);
  184. }
  185. void OpenGLState::ApplyDepthClamp() const {
  186. if (depth_clamp.far_plane == cur_state.depth_clamp.far_plane &&
  187. depth_clamp.near_plane == cur_state.depth_clamp.near_plane) {
  188. return;
  189. }
  190. cur_state.depth_clamp = depth_clamp;
  191. UNIMPLEMENTED_IF_MSG(depth_clamp.far_plane != depth_clamp.near_plane,
  192. "Unimplemented Depth Clamp Separation!");
  193. Enable(GL_DEPTH_CLAMP, depth_clamp.far_plane || depth_clamp.near_plane);
  194. }
  195. void OpenGLState::ApplySRgb() const {
  196. if (cur_state.framebuffer_srgb.enabled == framebuffer_srgb.enabled)
  197. return;
  198. cur_state.framebuffer_srgb.enabled = framebuffer_srgb.enabled;
  199. if (framebuffer_srgb.enabled) {
  200. // Track if sRGB is used
  201. s_rgb_used = true;
  202. glEnable(GL_FRAMEBUFFER_SRGB);
  203. } else {
  204. glDisable(GL_FRAMEBUFFER_SRGB);
  205. }
  206. }
  207. void OpenGLState::ApplyCulling() const {
  208. Enable(GL_CULL_FACE, cur_state.cull.enabled, cull.enabled);
  209. if (UpdateValue(cur_state.cull.mode, cull.mode)) {
  210. glCullFace(cull.mode);
  211. }
  212. if (UpdateValue(cur_state.cull.front_face, cull.front_face)) {
  213. glFrontFace(cull.front_face);
  214. }
  215. }
  216. void OpenGLState::ApplyColorMask() const {
  217. for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) {
  218. const auto& updated = color_mask[i];
  219. auto& current = cur_state.color_mask[i];
  220. if (updated.red_enabled != current.red_enabled ||
  221. updated.green_enabled != current.green_enabled ||
  222. updated.blue_enabled != current.blue_enabled ||
  223. updated.alpha_enabled != current.alpha_enabled) {
  224. current = updated;
  225. glColorMaski(static_cast<GLuint>(i), updated.red_enabled, updated.green_enabled,
  226. updated.blue_enabled, updated.alpha_enabled);
  227. }
  228. }
  229. }
  230. void OpenGLState::ApplyDepth() const {
  231. Enable(GL_DEPTH_TEST, cur_state.depth.test_enabled, depth.test_enabled);
  232. if (cur_state.depth.test_func != depth.test_func) {
  233. cur_state.depth.test_func = depth.test_func;
  234. glDepthFunc(depth.test_func);
  235. }
  236. if (cur_state.depth.write_mask != depth.write_mask) {
  237. cur_state.depth.write_mask = depth.write_mask;
  238. glDepthMask(depth.write_mask);
  239. }
  240. }
  241. void OpenGLState::ApplyPrimitiveRestart() const {
  242. Enable(GL_PRIMITIVE_RESTART, cur_state.primitive_restart.enabled, primitive_restart.enabled);
  243. if (cur_state.primitive_restart.index != primitive_restart.index) {
  244. cur_state.primitive_restart.index = primitive_restart.index;
  245. glPrimitiveRestartIndex(primitive_restart.index);
  246. }
  247. }
  248. void OpenGLState::ApplyStencilTest() const {
  249. Enable(GL_STENCIL_TEST, cur_state.stencil.test_enabled, stencil.test_enabled);
  250. const auto ConfigStencil = [](GLenum face, const auto& config, auto& current) {
  251. if (current.test_func != config.test_func || current.test_ref != config.test_ref ||
  252. current.test_mask != config.test_mask) {
  253. current.test_func = config.test_func;
  254. current.test_ref = config.test_ref;
  255. current.test_mask = config.test_mask;
  256. glStencilFuncSeparate(face, config.test_func, config.test_ref, config.test_mask);
  257. }
  258. if (current.action_depth_fail != config.action_depth_fail ||
  259. current.action_depth_pass != config.action_depth_pass ||
  260. current.action_stencil_fail != config.action_stencil_fail) {
  261. current.action_depth_fail = config.action_depth_fail;
  262. current.action_depth_pass = config.action_depth_pass;
  263. current.action_stencil_fail = config.action_stencil_fail;
  264. glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail,
  265. config.action_depth_pass);
  266. }
  267. if (current.write_mask != config.write_mask) {
  268. current.write_mask = config.write_mask;
  269. glStencilMaskSeparate(face, config.write_mask);
  270. }
  271. };
  272. ConfigStencil(GL_FRONT, stencil.front, cur_state.stencil.front);
  273. ConfigStencil(GL_BACK, stencil.back, cur_state.stencil.back);
  274. }
  275. void OpenGLState::ApplyViewport() const {
  276. for (GLuint i = 0; i < static_cast<GLuint>(Maxwell::NumViewports); ++i) {
  277. const auto& updated = viewports[i];
  278. auto& current = cur_state.viewports[i];
  279. if (current.x != updated.x || current.y != updated.y || current.width != updated.width ||
  280. current.height != updated.height) {
  281. current.x = updated.x;
  282. current.y = updated.y;
  283. current.width = updated.width;
  284. current.height = updated.height;
  285. glViewportIndexedf(i, static_cast<GLfloat>(updated.x), static_cast<GLfloat>(updated.y),
  286. static_cast<GLfloat>(updated.width),
  287. static_cast<GLfloat>(updated.height));
  288. }
  289. if (current.depth_range_near != updated.depth_range_near ||
  290. current.depth_range_far != updated.depth_range_far) {
  291. current.depth_range_near = updated.depth_range_near;
  292. current.depth_range_far = updated.depth_range_far;
  293. glDepthRangeIndexed(i, updated.depth_range_near, updated.depth_range_far);
  294. }
  295. Enable(GL_SCISSOR_TEST, i, current.scissor.enabled, updated.scissor.enabled);
  296. if (current.scissor.x != updated.scissor.x || current.scissor.y != updated.scissor.y ||
  297. current.scissor.width != updated.scissor.width ||
  298. current.scissor.height != updated.scissor.height) {
  299. current.scissor.x = updated.scissor.x;
  300. current.scissor.y = updated.scissor.y;
  301. current.scissor.width = updated.scissor.width;
  302. current.scissor.height = updated.scissor.height;
  303. glScissorIndexed(i, updated.scissor.x, updated.scissor.y, updated.scissor.width,
  304. updated.scissor.height);
  305. }
  306. }
  307. }
  308. void OpenGLState::ApplyGlobalBlending() const {
  309. const Blend& updated = blend[0];
  310. Blend& current = cur_state.blend[0];
  311. Enable(GL_BLEND, current.enabled, updated.enabled);
  312. if (current.src_rgb_func != updated.src_rgb_func ||
  313. current.dst_rgb_func != updated.dst_rgb_func || current.src_a_func != updated.src_a_func ||
  314. current.dst_a_func != updated.dst_a_func) {
  315. current.src_rgb_func = updated.src_rgb_func;
  316. current.dst_rgb_func = updated.dst_rgb_func;
  317. current.src_a_func = updated.src_a_func;
  318. current.dst_a_func = updated.dst_a_func;
  319. glBlendFuncSeparate(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func,
  320. updated.dst_a_func);
  321. }
  322. if (current.rgb_equation != updated.rgb_equation || current.a_equation != updated.a_equation) {
  323. current.rgb_equation = updated.rgb_equation;
  324. current.a_equation = updated.a_equation;
  325. glBlendEquationSeparate(updated.rgb_equation, updated.a_equation);
  326. }
  327. }
  328. void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) const {
  329. const Blend& updated = blend[target];
  330. Blend& current = cur_state.blend[target];
  331. if (current.enabled != updated.enabled || force) {
  332. current.enabled = updated.enabled;
  333. Enable(GL_BLEND, static_cast<GLuint>(target), updated.enabled);
  334. }
  335. if (UpdateTie(std::tie(current.src_rgb_func, current.dst_rgb_func, current.src_a_func,
  336. current.dst_a_func),
  337. std::tie(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func,
  338. updated.dst_a_func))) {
  339. glBlendFuncSeparatei(static_cast<GLuint>(target), updated.src_rgb_func,
  340. updated.dst_rgb_func, updated.src_a_func, updated.dst_a_func);
  341. }
  342. if (UpdateTie(std::tie(current.rgb_equation, current.a_equation),
  343. std::tie(updated.rgb_equation, updated.a_equation))) {
  344. glBlendEquationSeparatei(static_cast<GLuint>(target), updated.rgb_equation,
  345. updated.a_equation);
  346. }
  347. }
  348. void OpenGLState::ApplyBlending() const {
  349. if (independant_blend.enabled) {
  350. const bool force = independant_blend.enabled != cur_state.independant_blend.enabled;
  351. for (std::size_t target = 0; target < Maxwell::NumRenderTargets; ++target) {
  352. ApplyTargetBlending(target, force);
  353. }
  354. } else {
  355. ApplyGlobalBlending();
  356. }
  357. cur_state.independant_blend.enabled = independant_blend.enabled;
  358. if (UpdateTie(
  359. std::tie(cur_state.blend_color.red, cur_state.blend_color.green,
  360. cur_state.blend_color.blue, cur_state.blend_color.alpha),
  361. std::tie(blend_color.red, blend_color.green, blend_color.blue, blend_color.alpha))) {
  362. glBlendColor(blend_color.red, blend_color.green, blend_color.blue, blend_color.alpha);
  363. }
  364. }
  365. void OpenGLState::ApplyLogicOp() const {
  366. Enable(GL_COLOR_LOGIC_OP, cur_state.logic_op.enabled, logic_op.enabled);
  367. if (UpdateValue(cur_state.logic_op.operation, logic_op.operation)) {
  368. glLogicOp(logic_op.operation);
  369. }
  370. }
  371. void OpenGLState::ApplyPolygonOffset() const {
  372. Enable(GL_POLYGON_OFFSET_FILL, cur_state.polygon_offset.fill_enable,
  373. polygon_offset.fill_enable);
  374. Enable(GL_POLYGON_OFFSET_LINE, cur_state.polygon_offset.line_enable,
  375. polygon_offset.line_enable);
  376. Enable(GL_POLYGON_OFFSET_POINT, cur_state.polygon_offset.point_enable,
  377. polygon_offset.point_enable);
  378. if (UpdateTie(std::tie(cur_state.polygon_offset.factor, cur_state.polygon_offset.units,
  379. cur_state.polygon_offset.clamp),
  380. std::tie(polygon_offset.factor, polygon_offset.units, polygon_offset.clamp))) {
  381. if (GLAD_GL_EXT_polygon_offset_clamp && polygon_offset.clamp != 0) {
  382. glPolygonOffsetClamp(polygon_offset.factor, polygon_offset.units, polygon_offset.clamp);
  383. } else {
  384. UNIMPLEMENTED_IF_MSG(polygon_offset.clamp != 0,
  385. "Unimplemented Depth polygon offset clamp.");
  386. glPolygonOffset(polygon_offset.factor, polygon_offset.units);
  387. }
  388. }
  389. }
  390. void OpenGLState::ApplyTextures() const {
  391. bool has_delta{};
  392. std::size_t first{};
  393. std::size_t last{};
  394. std::array<GLuint, Maxwell::NumTextureSamplers> textures;
  395. for (std::size_t i = 0; i < std::size(texture_units); ++i) {
  396. const auto& texture_unit = texture_units[i];
  397. auto& cur_state_texture_unit = cur_state.texture_units[i];
  398. textures[i] = texture_unit.texture;
  399. if (cur_state_texture_unit.texture == textures[i]) {
  400. continue;
  401. }
  402. cur_state_texture_unit.texture = textures[i];
  403. if (!has_delta) {
  404. first = i;
  405. has_delta = true;
  406. }
  407. last = i;
  408. }
  409. if (has_delta) {
  410. glBindTextures(static_cast<GLuint>(first), static_cast<GLsizei>(last - first + 1),
  411. textures.data() + first);
  412. }
  413. }
  414. void OpenGLState::ApplySamplers() const {
  415. bool has_delta{};
  416. std::size_t first{};
  417. std::size_t last{};
  418. std::array<GLuint, Maxwell::NumTextureSamplers> samplers;
  419. for (std::size_t i = 0; i < std::size(samplers); ++i) {
  420. samplers[i] = texture_units[i].sampler;
  421. if (cur_state.texture_units[i].sampler == texture_units[i].sampler) {
  422. continue;
  423. }
  424. cur_state.texture_units[i].sampler = texture_units[i].sampler;
  425. if (!has_delta) {
  426. first = i;
  427. has_delta = true;
  428. }
  429. last = i;
  430. }
  431. if (has_delta) {
  432. glBindSamplers(static_cast<GLuint>(first), static_cast<GLsizei>(last - first + 1),
  433. samplers.data() + first);
  434. }
  435. }
  436. void OpenGLState::Apply() const {
  437. ApplyFramebufferState();
  438. ApplyVertexArrayState();
  439. ApplyShaderProgram();
  440. ApplyProgramPipeline();
  441. ApplyClipDistances();
  442. ApplyPointSize();
  443. ApplyFragmentColorClamp();
  444. ApplyMultisample();
  445. ApplyDepthClamp();
  446. ApplyColorMask();
  447. ApplyViewport();
  448. ApplyStencilTest();
  449. ApplySRgb();
  450. ApplyCulling();
  451. ApplyDepth();
  452. ApplyPrimitiveRestart();
  453. ApplyBlending();
  454. ApplyLogicOp();
  455. ApplyTextures();
  456. ApplySamplers();
  457. ApplyPolygonOffset();
  458. }
  459. void OpenGLState::EmulateViewportWithScissor() {
  460. auto& current = viewports[0];
  461. if (current.scissor.enabled) {
  462. const GLint left = std::max(current.x, current.scissor.x);
  463. const GLint right =
  464. std::max(current.x + current.width, current.scissor.x + current.scissor.width);
  465. const GLint bottom = std::max(current.y, current.scissor.y);
  466. const GLint top =
  467. std::max(current.y + current.height, current.scissor.y + current.scissor.height);
  468. current.scissor.x = std::max(left, 0);
  469. current.scissor.y = std::max(bottom, 0);
  470. current.scissor.width = std::max(right - left, 0);
  471. current.scissor.height = std::max(top - bottom, 0);
  472. } else {
  473. current.scissor.enabled = true;
  474. current.scissor.x = current.x;
  475. current.scissor.y = current.y;
  476. current.scissor.width = current.width;
  477. current.scissor.height = current.height;
  478. }
  479. }
  480. OpenGLState& OpenGLState::UnbindTexture(GLuint handle) {
  481. for (auto& unit : texture_units) {
  482. if (unit.texture == handle) {
  483. unit.Unbind();
  484. }
  485. }
  486. return *this;
  487. }
  488. OpenGLState& OpenGLState::ResetSampler(GLuint handle) {
  489. for (auto& unit : texture_units) {
  490. if (unit.sampler == handle) {
  491. unit.sampler = 0;
  492. }
  493. }
  494. return *this;
  495. }
  496. OpenGLState& OpenGLState::ResetProgram(GLuint handle) {
  497. if (draw.shader_program == handle) {
  498. draw.shader_program = 0;
  499. }
  500. return *this;
  501. }
  502. OpenGLState& OpenGLState::ResetPipeline(GLuint handle) {
  503. if (draw.program_pipeline == handle) {
  504. draw.program_pipeline = 0;
  505. }
  506. return *this;
  507. }
  508. OpenGLState& OpenGLState::ResetVertexArray(GLuint handle) {
  509. if (draw.vertex_array == handle) {
  510. draw.vertex_array = 0;
  511. }
  512. return *this;
  513. }
  514. OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) {
  515. if (draw.read_framebuffer == handle) {
  516. draw.read_framebuffer = 0;
  517. }
  518. if (draw.draw_framebuffer == handle) {
  519. draw.draw_framebuffer = 0;
  520. }
  521. return *this;
  522. }
  523. } // namespace OpenGL