mrt.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. const char* const ps1="struct PS_INPUT\n {\n float4 Position : POSITION0;\n };\n\n struct PS_OUTPUT\n {\n float4 Color : COLOR0;\n float4 Normal : COLOR1;\n float4 Depth : COLOR2;\n };\n PS_OUTPUT pixelMain( PS_INPUT Input )\n {\n PS_OUTPUT Output;\n Output.Color = float4(1.0,1.0,1.0,1.0);\n Output.Normal = float4(0.0,1.0,0.0,1.0);\n Output.Depth = float4(0.0,0.0,1.0,1.0);\n return Output;\n }";
  18. const char* const ps2="void main(void)\n {\n gl_FragData[0] = vec4(1.0,1.0,1.0,1.0);\n gl_FragData[1] = vec4(0.0,1.0,0.0,1.0);\n gl_FragData[2] = vec4(0.0,0.0,1.0,1.0);\n }";
  19. // variable
  20. video::ITexture* gbuffer[3];
  21. core::array<video::IRenderTarget> gbufferlist;
  22. const core::dimension2du texsize(64,64);
  23. bool result=true;
  24. s32 newMaterialType = -1;
  25. if (device->getVideoDriver()->getDriverAttributes().getAttributeAsInt("MaxMultipleRenderTargets") > 2)
  26. {
  27. // allocate buffer
  28. gbuffer[0] = driver->addRenderTargetTexture(texsize, "rta", video::ECF_A8R8G8B8);
  29. gbuffer[1] = driver->addRenderTargetTexture(texsize, "rtb", video::ECF_A8R8G8B8);
  30. gbuffer[2] = driver->addRenderTargetTexture(texsize, "rtc", video::ECF_A8R8G8B8);
  31. for( u32 i = 0; i < 3; ++i )
  32. gbufferlist.push_back( video::IRenderTarget(gbuffer[i]) );
  33. video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
  34. if (gpu)
  35. {
  36. newMaterialType = gpu->addHighLevelShaderMaterial(
  37. 0, "vertexMain", video::EVST_VS_1_1,
  38. driverType==video::EDT_DIRECT3D9?ps1:ps2, "pixelMain", video::EPST_PS_1_1);
  39. }
  40. }
  41. // shader creation succeeded
  42. if (newMaterialType!=-1)
  43. {
  44. scene::ISceneNode* node = device->getSceneManager()->addCubeSceneNode();
  45. node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType);
  46. device->getSceneManager()->addCameraSceneNode(0, core::vector3df(0,0,-10));
  47. driver->beginScene (true, true, video::SColor (255, 200, 200, 200));
  48. // render
  49. driver->setRenderTarget( gbufferlist );
  50. device->getSceneManager()->drawAll();
  51. driver->setRenderTarget(0);
  52. // draw debug rt
  53. driver->draw2DImage(gbuffer[0], core::position2d<s32>(0,0));
  54. driver->draw2DImage(gbuffer[1], core::position2d<s32>(64,0));
  55. driver->draw2DImage(gbuffer[2], core::position2d<s32>(128,0));
  56. driver->endScene();
  57. result = takeScreenshotAndCompareAgainstReference(driver, "-mrt.png");
  58. driver->beginScene (true, true, video::SColor (255, 200, 200, 200));
  59. // render
  60. device->getSceneManager()->getActiveCamera()->setPosition(core::vector3df(0,0,-15));
  61. driver->setRenderTarget( gbufferlist );
  62. device->getSceneManager()->drawAll();
  63. driver->setRenderTarget(0);
  64. // draw debug rt
  65. driver->draw2DImage(gbuffer[0], core::position2d<s32>(0,0));
  66. driver->draw2DImage(gbuffer[1], core::position2d<s32>(64,0));
  67. driver->draw2DImage(gbuffer[2], core::position2d<s32>(128,0));
  68. driver->endScene();
  69. result &= takeScreenshotAndCompareAgainstReference(driver, "-mrt2.png");
  70. }
  71. device->closeDevice();
  72. device->run();
  73. device->drop();
  74. return result;
  75. }
  76. bool mrt(void)
  77. {
  78. bool result = true;
  79. TestWithAllHWDrivers(testWithDriver);
  80. return result;
  81. }