mrt.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (C) 2008-2012 Christian Stehno, Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. //! Tests rendering MRTs
  6. static bool testWithDriver(video::E_DRIVER_TYPE driverType)
  7. {
  8. IrrlichtDevice *device = createDevice (driverType, core::dimension2d < u32 > (220, 80));
  9. if (!device)
  10. return true; // No error if device does not exist
  11. video::IVideoDriver* driver = device->getVideoDriver();
  12. // We need at least GLSL 1.10 or HLSL 1.1
  13. // if (driver->getDriverAttributes().getAttributeAsInt("ShaderLanguageVersion")<=100)
  14. // return true;
  15. stabilizeScreenBackground(driver);
  16. logTestString("Testing driver %ls\n", driver->getName());
  17. // write white to first render-texture, green to second, blue to third
  18. const char* const psHLSL =
  19. "struct PS_INPUT\n"\
  20. "{\n"\
  21. " float4 Position : POSITION0;\n"\
  22. "};\n"\
  23. "struct PS_OUTPUT\n"\
  24. "{\n "\
  25. " float4 Color : COLOR0;\n"\
  26. " float4 Normal : COLOR1;\n"\
  27. " float4 Depth : COLOR2;\n"\
  28. "};\n"\
  29. "PS_OUTPUT pixelMain( PS_INPUT Input )\n"\
  30. "{\n"\
  31. " PS_OUTPUT Output;\n"\
  32. " Output.Color = float4(1.0,1.0,1.0,1.0);\n"\
  33. " Output.Normal = float4(0.0,1.0,0.0,1.0);\n"\
  34. " Output.Depth = float4(0.0,0.0,1.0,1.0);\n"\
  35. " return Output;\n"\
  36. "}";
  37. const char* const psGLSL =
  38. "void main(void)\n"\
  39. "{\n"\
  40. " gl_FragData[0] = vec4(1.0,1.0,1.0,1.0);\n"\
  41. " gl_FragData[1] = vec4(0.0,1.0,0.0,1.0);\n"\
  42. " gl_FragData[2] = vec4(0.0,0.0,1.0,1.0);\n"\
  43. "}";
  44. // variable
  45. video::IRenderTarget* renderTarget = 0;
  46. core::array<video::ITexture*> renderTargetTex;
  47. video::ITexture* renderTargetDepth = 0;
  48. const core::dimension2du texsize(64,64);
  49. bool result=true;
  50. s32 newMaterialType = -1;
  51. if (device->getVideoDriver()->getDriverAttributes().getAttributeAsInt("MaxMultipleRenderTargets") > 2)
  52. {
  53. renderTargetTex.set_used(3);
  54. renderTargetTex[0] = driver->addRenderTargetTexture(texsize, "rta", video::ECF_A8R8G8B8);
  55. renderTargetTex[1] = driver->addRenderTargetTexture(texsize, "rtb", video::ECF_A8R8G8B8);
  56. renderTargetTex[2] = driver->addRenderTargetTexture(texsize, "rtc", video::ECF_A8R8G8B8);
  57. renderTargetDepth = driver->addRenderTargetTexture(texsize, "rtd", video::ECF_D16);
  58. renderTarget = driver->addRenderTarget();
  59. renderTarget->setTexture(renderTargetTex, renderTargetDepth);
  60. video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
  61. if (gpu)
  62. {
  63. newMaterialType = gpu->addHighLevelShaderMaterial(
  64. 0, "vertexMain", video::EVST_VS_1_1,
  65. driverType==video::EDT_DIRECT3D9?psHLSL:psGLSL, "pixelMain", video::EPST_PS_1_1);
  66. }
  67. }
  68. // shader creation succeeded
  69. if (newMaterialType!=-1)
  70. {
  71. scene::ISceneNode* node = device->getSceneManager()->addCubeSceneNode();
  72. node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType);
  73. device->getSceneManager()->addCameraSceneNode(0, core::vector3df(0,0,-10));
  74. driver->beginScene(video::ECBF_COLOR, video::SColor(255, 0, 0, 0));
  75. // render
  76. driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0));
  77. device->getSceneManager()->drawAll();
  78. driver->setRenderTargetEx(0, 0, video::SColor(255, 0, 0, 0));
  79. // draw debug rt
  80. driver->draw2DImage(renderTargetTex[0], core::position2d<s32>(0,0));
  81. driver->draw2DImage(renderTargetTex[1], core::position2d<s32>(64,0));
  82. driver->draw2DImage(renderTargetTex[2], core::position2d<s32>(128,0));
  83. driver->endScene();
  84. result = takeScreenshotAndCompareAgainstReference(driver, "-mrt.png");
  85. driver->beginScene(video::ECBF_COLOR, video::SColor(255, 0, 0, 0));
  86. // render
  87. device->getSceneManager()->getActiveCamera()->setPosition(core::vector3df(0,0,-15));
  88. driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0));
  89. device->getSceneManager()->drawAll();
  90. driver->setRenderTargetEx(0, 0, video::SColor(255,0,0,0));
  91. // draw debug rt
  92. driver->draw2DImage(renderTargetTex[0], core::position2d<s32>(0,0));
  93. driver->draw2DImage(renderTargetTex[1], core::position2d<s32>(64,0));
  94. driver->draw2DImage(renderTargetTex[2], core::position2d<s32>(128,0));
  95. driver->endScene();
  96. result &= takeScreenshotAndCompareAgainstReference(driver, "-mrt2.png");
  97. }
  98. device->closeDevice();
  99. device->run();
  100. device->drop();
  101. return result;
  102. }
  103. bool mrt(void)
  104. {
  105. bool result = true;
  106. TestWithAllHWDrivers(testWithDriver);
  107. return result;
  108. }