interlaced.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. Copyright (C) 2017 numzero, Lobachesky Vitaly <numzer0@yandex.ru>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include "interlaced.h"
  18. #include "client.h"
  19. #include "shader.h"
  20. #include "client/tile.h"
  21. RenderingCoreInterlaced::RenderingCoreInterlaced(
  22. IrrlichtDevice *_device, Client *_client, Hud *_hud)
  23. : RenderingCoreStereo(_device, _client, _hud)
  24. {
  25. initMaterial();
  26. }
  27. void RenderingCoreInterlaced::initMaterial()
  28. {
  29. IShaderSource *s = client->getShaderSource();
  30. mat.UseMipMaps = false;
  31. mat.ZBuffer = false;
  32. mat.ZWriteEnable = false;
  33. u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC, 0);
  34. mat.MaterialType = s->getShaderInfo(shader).material;
  35. for (int k = 0; k < 3; ++k) {
  36. mat.TextureLayer[k].AnisotropicFilter = false;
  37. mat.TextureLayer[k].BilinearFilter = false;
  38. mat.TextureLayer[k].TrilinearFilter = false;
  39. mat.TextureLayer[k].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
  40. mat.TextureLayer[k].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
  41. }
  42. }
  43. void RenderingCoreInterlaced::initTextures()
  44. {
  45. v2u32 image_size{screensize.X, screensize.Y / 2};
  46. left = driver->addRenderTargetTexture(
  47. image_size, "3d_render_left", video::ECF_A8R8G8B8);
  48. right = driver->addRenderTargetTexture(
  49. image_size, "3d_render_right", video::ECF_A8R8G8B8);
  50. mask = driver->addTexture(screensize, "3d_render_mask", video::ECF_A8R8G8B8);
  51. initMask();
  52. mat.TextureLayer[0].Texture = left;
  53. mat.TextureLayer[1].Texture = right;
  54. mat.TextureLayer[2].Texture = mask;
  55. }
  56. void RenderingCoreInterlaced::clearTextures()
  57. {
  58. driver->removeTexture(left);
  59. driver->removeTexture(right);
  60. driver->removeTexture(mask);
  61. }
  62. void RenderingCoreInterlaced::initMask()
  63. {
  64. u8 *data = reinterpret_cast<u8 *>(mask->lock());
  65. for (u32 j = 0; j < screensize.Y; j++) {
  66. u8 val = j % 2 ? 0xff : 0x00;
  67. memset(data, val, 4 * screensize.X);
  68. data += 4 * screensize.X;
  69. }
  70. mask->unlock();
  71. }
  72. void RenderingCoreInterlaced::drawAll()
  73. {
  74. renderBothImages();
  75. merge();
  76. drawHUD();
  77. }
  78. void RenderingCoreInterlaced::merge()
  79. {
  80. static const video::S3DVertex vertices[4] = {
  81. video::S3DVertex(1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
  82. video::SColor(255, 0, 255, 255), 1.0, 0.0),
  83. video::S3DVertex(-1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
  84. video::SColor(255, 255, 0, 255), 0.0, 0.0),
  85. video::S3DVertex(-1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
  86. video::SColor(255, 255, 255, 0), 0.0, 1.0),
  87. video::S3DVertex(1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
  88. video::SColor(255, 255, 255, 255), 1.0, 1.0),
  89. };
  90. static const u16 indices[6] = {0, 1, 2, 2, 3, 0};
  91. driver->setMaterial(mat);
  92. driver->drawVertexPrimitiveList(&vertices, 4, &indices, 2);
  93. }
  94. void RenderingCoreInterlaced::useEye(bool _right)
  95. {
  96. driver->setRenderTarget(_right ? right : left, true, true, skycolor);
  97. RenderingCoreStereo::useEye(_right);
  98. }
  99. void RenderingCoreInterlaced::resetEye()
  100. {
  101. driver->setRenderTarget(nullptr, false, false, skycolor);
  102. RenderingCoreStereo::resetEye();
  103. }