BsRenderTargetEx.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsRenderTargetEx.h"
  4. #include "BsScriptShaderParameter.generated.h"
  5. namespace bs
  6. {
  7. UINT32 RenderTargetEx::getWidth(const SPtr<RenderTarget>& thisPtr)
  8. {
  9. return thisPtr->getProperties().width;
  10. }
  11. UINT32 RenderTargetEx::getHeight(const SPtr<RenderTarget>& thisPtr)
  12. {
  13. return thisPtr->getProperties().height;
  14. }
  15. bool RenderTargetEx::getGammaCorrection(const SPtr<RenderTarget>& thisPtr)
  16. {
  17. return thisPtr->getProperties().hwGamma;
  18. }
  19. INT32 RenderTargetEx::getPriority(const SPtr<RenderTarget>& thisPtr)
  20. {
  21. return thisPtr->getProperties().priority;
  22. }
  23. void RenderTargetEx::setPriority(const SPtr<RenderTarget>& thisPtr, INT32 priority)
  24. {
  25. thisPtr->setPriority(priority);
  26. }
  27. UINT32 RenderTargetEx::getSampleCount(const SPtr<RenderTarget>& thisPtr)
  28. {
  29. return thisPtr->getProperties().multisampleCount;
  30. }
  31. SPtr<RenderTexture> RenderTextureEx::create(PixelFormat format, int width, int height, int numSamples, bool gammaCorrection, bool createDepth, PixelFormat depthStencilFormat)
  32. {
  33. TEXTURE_DESC texDesc;
  34. texDesc.type = TEX_TYPE_2D;
  35. texDesc.width = width;
  36. texDesc.height = height;
  37. texDesc.format = format;
  38. texDesc.hwGamma = gammaCorrection;
  39. texDesc.numSamples = numSamples;
  40. return RenderTexture::create(texDesc, createDepth, depthStencilFormat);
  41. }
  42. SPtr<RenderTexture> RenderTextureEx::create(const HTexture& colorSurface)
  43. {
  44. return create(Vector<HTexture>{ colorSurface }, HTexture());
  45. }
  46. SPtr<RenderTexture> RenderTextureEx::create(const HTexture& colorSurface, const HTexture& depthStencilSurface)
  47. {
  48. return create(Vector<HTexture>{ colorSurface }, depthStencilSurface);
  49. }
  50. SPtr<RenderTexture> RenderTextureEx::create(const Vector<HTexture>& colorSurface)
  51. {
  52. return create(Vector<HTexture>{ colorSurface }, HTexture());
  53. }
  54. SPtr<RenderTexture> RenderTextureEx::create(const Vector<HTexture>& colorSurfaces, const HTexture& depthStencilSurface)
  55. {
  56. RENDER_SURFACE_DESC depthStencilSurfaceDesc;
  57. if (depthStencilSurface != nullptr)
  58. {
  59. depthStencilSurfaceDesc.face = 0;
  60. depthStencilSurfaceDesc.mipLevel = 0;
  61. depthStencilSurfaceDesc.numFaces = 1;
  62. if (!depthStencilSurface.isLoaded())
  63. {
  64. LOGERR("Render texture must be created using a fully loaded texture.");
  65. }
  66. else
  67. depthStencilSurfaceDesc.texture = depthStencilSurface;
  68. }
  69. UINT32 numSurfaces = std::min((UINT32)colorSurfaces.size(), (UINT32)BS_MAX_MULTIPLE_RENDER_TARGETS);
  70. RENDER_TEXTURE_DESC desc;
  71. for (UINT32 i = 0; i < numSurfaces; i++)
  72. {
  73. RENDER_SURFACE_DESC surfaceDesc;
  74. surfaceDesc.face = 0;
  75. surfaceDesc.mipLevel = 0;
  76. surfaceDesc.numFaces = 1;
  77. if (!colorSurfaces[i].isLoaded())
  78. {
  79. LOGERR("Render texture must be created using a fully loaded texture.");
  80. }
  81. else
  82. surfaceDesc.texture = colorSurfaces[i];
  83. desc.colorSurfaces[i] = surfaceDesc;
  84. }
  85. desc.depthStencilSurface = depthStencilSurfaceDesc;
  86. return RenderTexture::create(desc);
  87. }
  88. Vector<HTexture> RenderTextureEx::getColorSurfaces(const SPtr<RenderTexture>& thisPtr)
  89. {
  90. UINT32 numColorSurfaces = BS_MAX_MULTIPLE_RENDER_TARGETS;
  91. Vector<HTexture> output;
  92. output.reserve(numColorSurfaces);
  93. for (UINT32 i = 0; i < numColorSurfaces; i++)
  94. {
  95. HTexture colorTex = thisPtr->getColorTexture(i);
  96. if (colorTex != nullptr)
  97. output.push_back(colorTex);
  98. }
  99. return output;
  100. }
  101. HTexture RenderTextureEx::getColorSurface(const SPtr<RenderTexture>& thisPtr)
  102. {
  103. return thisPtr->getColorTexture(0);
  104. }
  105. HTexture RenderTextureEx::getDepthStencilSurface(const SPtr<RenderTexture>& thisPtr)
  106. {
  107. return thisPtr->getDepthStencilTexture();
  108. }
  109. }