VideoCommon.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2008 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #ifdef _WIN32
  6. #include <windows.h>
  7. #endif
  8. #include "Common/CommonTypes.h"
  9. #include "Common/MathUtil.h"
  10. #include "VideoCommon/VideoBackendBase.h"
  11. // These are accurate (disregarding AA modes).
  12. enum
  13. {
  14. EFB_WIDTH = 640,
  15. EFB_HEIGHT = 528,
  16. };
  17. // XFB width is decided by EFB copy operation. The VI can do horizontal
  18. // scaling (TODO: emulate).
  19. const u32 MAX_XFB_WIDTH = EFB_WIDTH;
  20. // Although EFB height is 528, 574-line XFB's can be created either with
  21. // vertical scaling by the EFB copy operation or copying to multiple XFB's
  22. // that are next to each other in memory (TODO: handle that situation).
  23. const u32 MAX_XFB_HEIGHT = 574;
  24. // This structure should only be used to represent a rectangle in EFB
  25. // coordinates, where the origin is at the upper left and the frame dimensions
  26. // are 640 x 528.
  27. typedef MathUtil::Rectangle<int> EFBRectangle;
  28. // This structure should only be used to represent a rectangle in standard target
  29. // coordinates, where the origin is at the lower left and the frame dimensions
  30. // depend on the resolution settings. Use Renderer::ConvertEFBRectangle to
  31. // convert an EFBRectangle to a TargetRectangle.
  32. struct TargetRectangle : public MathUtil::Rectangle<int>
  33. {
  34. #ifdef _WIN32
  35. // Only used by D3D backend.
  36. const RECT *AsRECT() const
  37. {
  38. // The types are binary compatible so this works.
  39. return (const RECT *)this;
  40. }
  41. RECT *AsRECT()
  42. {
  43. // The types are binary compatible so this works.
  44. return (RECT *)this;
  45. }
  46. #endif
  47. };
  48. #ifdef _WIN32
  49. #define PRIM_LOG(...) DEBUG_LOG(VIDEO, __VA_ARGS__)
  50. #else
  51. #define PRIM_LOG(...) DEBUG_LOG(VIDEO, ##__VA_ARGS__)
  52. #endif
  53. // warning: mapping buffer should be disabled to use this
  54. // #define LOG_VTX() DEBUG_LOG(VIDEO, "vtx: %f %f %f, ", ((float*)g_vertex_manager_write_ptr)[-3], ((float*)g_vertex_manager_write_ptr)[-2], ((float*)g_vertex_manager_write_ptr)[-1]);
  55. #define LOG_VTX()
  56. typedef enum
  57. {
  58. API_OPENGL = 1,
  59. API_D3D = 2,
  60. API_NONE = 3
  61. } API_TYPE;
  62. inline u32 RGBA8ToRGBA6ToRGBA8(u32 src)
  63. {
  64. u32 color = src;
  65. color &= 0xFCFCFCFC;
  66. color |= (color >> 6) & 0x03030303;
  67. return color;
  68. }
  69. inline u32 RGBA8ToRGB565ToRGBA8(u32 src)
  70. {
  71. u32 color = (src & 0xF8FCF8);
  72. color |= (color >> 5) & 0x070007;
  73. color |= (color >> 6) & 0x000300;
  74. color |= 0xFF000000;
  75. return color;
  76. }
  77. inline u32 Z24ToZ16ToZ24(u32 src)
  78. {
  79. return (src & 0xFFFF00) | (src >> 16);
  80. }
  81. /* Returns the smallest power of 2 which is greater than or equal to num */
  82. inline u32 MakePow2(u32 num)
  83. {
  84. --num;
  85. num |= num >> 1;
  86. num |= num >> 2;
  87. num |= num >> 4;
  88. num |= num >> 8;
  89. num |= num >> 16;
  90. ++num;
  91. return num;
  92. }
  93. // returns the exponent of the smallest power of two which is greater than val
  94. inline unsigned int GetPow2(unsigned int val)
  95. {
  96. unsigned int ret = 0;
  97. for (; val; val >>= 1)
  98. ++ret;
  99. return ret;
  100. }