Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

143 строки
3.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. #if defined _XBOX
  12. # include <xtl.h>
  13. # undef near /* Fuck Microsoft */
  14. # undef far /* Fuck Microsoft again */
  15. #elif defined _WIN32
  16. # if defined USE_D3D9
  17. # include <d3d9.h>
  18. # endif
  19. # define WIN32_LEAN_AND_MEAN
  20. # include <windows.h>
  21. # undef near /* Fuck Microsoft */
  22. # undef far /* Fuck Microsoft again */
  23. #endif
  24. #include "lolgl.h"
  25. namespace lol
  26. {
  27. class VideoData
  28. {
  29. friend class Video;
  30. private:
  31. static DebugRenderMode render_mode;
  32. };
  33. DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;
  34. /*
  35. * Public Video class
  36. */
  37. void Video::Setup(ivec2 size)
  38. {
  39. g_renderer = new Renderer(size);
  40. g_scene = new Scene(size);
  41. /* Initialise reasonable scene default properties */
  42. SetDebugRenderMode(DebugRenderMode::Default);
  43. }
  44. void Video::SetDebugRenderMode(DebugRenderMode d)
  45. {
  46. switch(d)
  47. {
  48. //All these modes are handled in the shaders.
  49. case DebugRenderMode::Default:
  50. case DebugRenderMode::Flat:
  51. case DebugRenderMode::Lighting:
  52. case DebugRenderMode::Normal:
  53. case DebugRenderMode::UV:
  54. {
  55. #if defined USE_D3D9 || defined _XBOX
  56. #elif defined HAVE_GLES_2X
  57. #elif defined USE_GLEW || defined HAVE_GL_2X
  58. glEnable(GL_CULL_FACE);
  59. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  60. #endif
  61. break;
  62. }
  63. case DebugRenderMode::Wireframe:
  64. {
  65. #if defined USE_D3D9 || defined _XBOX
  66. #elif defined HAVE_GLES_2X
  67. #elif defined USE_GLEW || defined HAVE_GL_2X
  68. glDisable(GL_CULL_FACE);
  69. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  70. #endif
  71. break;
  72. }
  73. default:
  74. return; /* Unknown render mode */
  75. }
  76. VideoData::render_mode = d;
  77. }
  78. DebugRenderMode Video::GetDebugRenderMode()
  79. {
  80. return VideoData::render_mode;
  81. }
  82. void Video::Destroy()
  83. {
  84. delete g_scene;
  85. g_scene = nullptr;
  86. delete g_renderer;
  87. g_renderer = nullptr;
  88. }
  89. void Video::Capture(uint32_t *buffer)
  90. {
  91. #if defined USE_D3D9 || defined _XBOX
  92. /* TODO */
  93. #elif defined USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLEX_2X
  94. GLint v[4];
  95. glGetIntegerv(GL_VIEWPORT, v);
  96. int width = v[2], height = v[3];
  97. # if defined HAVE_GL_2X
  98. glPixelStorei(GL_PACK_ROW_LENGTH, 0);
  99. # endif
  100. glPixelStorei(GL_PACK_ALIGNMENT, 1);
  101. # if defined GL_BGRA
  102. glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
  103. # else
  104. glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  105. # endif
  106. for (int j = 0; j < height / 2; j++)
  107. for (int i = 0; i < width; i++)
  108. {
  109. uint32_t tmp = buffer[j * width + i];
  110. buffer[j * width + i] = buffer[(height - j - 1) * width + i];
  111. buffer[(height - j - 1) * width + i] = tmp;
  112. }
  113. #endif
  114. }
  115. ivec2 Video::GetSize()
  116. {
  117. ibox2 viewport = g_renderer->GetViewport();
  118. return viewport.B - viewport.A;
  119. }
  120. } /* namespace lol */