engine.renderTargetCube.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { InternalTexture, InternalTextureSource } from "../../Materials/Textures/internalTexture.js";
  2. import { Logger } from "../../Misc/logger.js";
  3. import { ThinEngine } from "../thinEngine.js";
  4. ThinEngine.prototype.createRenderTargetCubeTexture = function (size, options) {
  5. const rtWrapper = this._createHardwareRenderTargetWrapper(false, true, size);
  6. const fullOptions = {
  7. generateMipMaps: true,
  8. generateDepthBuffer: true,
  9. generateStencilBuffer: false,
  10. type: 0,
  11. samplingMode: 3,
  12. format: 5,
  13. ...options,
  14. };
  15. fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;
  16. if (fullOptions.type === 1 && !this._caps.textureFloatLinearFiltering) {
  17. // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
  18. fullOptions.samplingMode = 1;
  19. }
  20. else if (fullOptions.type === 2 && !this._caps.textureHalfFloatLinearFiltering) {
  21. // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
  22. fullOptions.samplingMode = 1;
  23. }
  24. const gl = this._gl;
  25. const texture = new InternalTexture(this, InternalTextureSource.RenderTarget);
  26. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
  27. const filters = this._getSamplingParameters(fullOptions.samplingMode, fullOptions.generateMipMaps);
  28. if (fullOptions.type === 1 && !this._caps.textureFloat) {
  29. fullOptions.type = 0;
  30. Logger.Warn("Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type");
  31. }
  32. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);
  33. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);
  34. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  35. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  36. for (let face = 0; face < 6; face++) {
  37. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), size, size, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
  38. }
  39. // Create the framebuffer
  40. const framebuffer = gl.createFramebuffer();
  41. this._bindUnboundFramebuffer(framebuffer);
  42. rtWrapper._depthStencilBuffer = this._setupFramebufferDepthAttachments(fullOptions.generateStencilBuffer, fullOptions.generateDepthBuffer, size, size);
  43. // MipMaps
  44. if (fullOptions.generateMipMaps) {
  45. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  46. }
  47. // Unbind
  48. this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
  49. this._bindUnboundFramebuffer(null);
  50. rtWrapper._framebuffer = framebuffer;
  51. rtWrapper._generateDepthBuffer = fullOptions.generateDepthBuffer;
  52. rtWrapper._generateStencilBuffer = fullOptions.generateStencilBuffer;
  53. texture.width = size;
  54. texture.height = size;
  55. texture.isReady = true;
  56. texture.isCube = true;
  57. texture.samples = 1;
  58. texture.generateMipMaps = fullOptions.generateMipMaps;
  59. texture.samplingMode = fullOptions.samplingMode;
  60. texture.type = fullOptions.type;
  61. texture.format = fullOptions.format;
  62. this._internalTexturesCache.push(texture);
  63. rtWrapper.setTextures(texture);
  64. return rtWrapper;
  65. };
  66. //# sourceMappingURL=engine.renderTargetCube.js.map