babylon.textureTools.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module BABYLON {
  2. export class TextureTools {
  3. /**
  4. * Uses the GPU to create a copy texture rescaled at a given size
  5. * @param texture Texture to copy from
  6. * @param width Desired width
  7. * @param height Desired height
  8. * @return Generated texture
  9. */
  10. public static CreateResizedCopy(texture: BABYLON.Texture, width: number, height: number): BABYLON.Texture {
  11. let rtt = new BABYLON.RenderTargetTexture(
  12. 'resized' + texture.name,
  13. { width: width, height: height },
  14. scene,
  15. !texture.noMipmap,
  16. true,
  17. texture._texture.type,
  18. false,
  19. texture._samplingMode,
  20. false
  21. );
  22. var scene = texture.getScene();
  23. rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;
  24. rtt.wrapU = texture.wrapU;
  25. rtt.wrapV = texture.wrapV;
  26. rtt.uOffset = texture.uOffset;
  27. rtt.vOffset = texture.vOffset;
  28. rtt.uScale = texture.uScale;
  29. rtt.vScale = texture.vScale;
  30. rtt.uAng = texture.uAng;
  31. rtt.vAng = texture.vAng;
  32. rtt.wAng = texture.wAng;
  33. rtt.coordinatesIndex = texture.coordinatesIndex;
  34. rtt.level = texture.level;
  35. rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;
  36. let passPostProcess = new BABYLON.PassPostProcess("pass", 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, Engine.TEXTURETYPE_UNSIGNED_INT, true);
  37. passPostProcess.updateEffect(null, null, null, null, () => {
  38. passPostProcess.onApply = function (effect) {
  39. effect.setTexture("textureSampler", texture);
  40. }
  41. scene.postProcessManager.directRender([passPostProcess], rtt.getInternalTexture());
  42. scene.getEngine().restoreDefaultFramebuffer();
  43. rtt.disposeFramebufferObjects();
  44. });
  45. return rtt;
  46. }
  47. }
  48. }