webgpuDepthCullingState.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { Nullable } from "../../types";
  2. import { WebGPUCacheRenderPipeline } from "./webgpuCacheRenderPipeline";
  3. import { DepthCullingState } from "../../States/depthCullingState";
  4. /**
  5. * @hidden
  6. **/
  7. export class WebGPUDepthCullingState extends DepthCullingState {
  8. private _cache: WebGPUCacheRenderPipeline;
  9. /**
  10. * Initializes the state.
  11. */
  12. public constructor(cache: WebGPUCacheRenderPipeline) {
  13. super(false);
  14. this._cache = cache;
  15. this.reset();
  16. }
  17. public get zOffset(): number {
  18. return this._zOffset;
  19. }
  20. public set zOffset(value: number) {
  21. if (this._zOffset === value) {
  22. return;
  23. }
  24. this._zOffset = value;
  25. this._isZOffsetDirty = true;
  26. this._cache.setDepthBiasSlopeScale(value);
  27. }
  28. public get cullFace(): Nullable<number> {
  29. return this._cullFace;
  30. }
  31. public set cullFace(value: Nullable<number>) {
  32. if (this._cullFace === value) {
  33. return;
  34. }
  35. this._cullFace = value;
  36. this._isCullFaceDirty = true;
  37. this._cache.setCullFace(value ?? 1);
  38. }
  39. public get cull(): Nullable<boolean> {
  40. return this._cull;
  41. }
  42. public set cull(value: Nullable<boolean>) {
  43. if (this._cull === value) {
  44. return;
  45. }
  46. this._cull = value;
  47. this._isCullDirty = true;
  48. this._cache.setCullEnabled(!!value);
  49. }
  50. public get depthFunc(): Nullable<number> {
  51. return this._depthFunc;
  52. }
  53. public set depthFunc(value: Nullable<number>) {
  54. if (this._depthFunc === value) {
  55. return;
  56. }
  57. this._depthFunc = value;
  58. this._isDepthFuncDirty = true;
  59. this._cache.setDepthCompare(value);
  60. }
  61. public get depthMask(): boolean {
  62. return this._depthMask;
  63. }
  64. public set depthMask(value: boolean) {
  65. if (this._depthMask === value) {
  66. return;
  67. }
  68. this._depthMask = value;
  69. this._isDepthMaskDirty = true;
  70. this._cache.setDepthWriteEnabled(value);
  71. }
  72. public get depthTest(): boolean {
  73. return this._depthTest;
  74. }
  75. public set depthTest(value: boolean) {
  76. if (this._depthTest === value) {
  77. return;
  78. }
  79. this._depthTest = value;
  80. this._isDepthTestDirty = true;
  81. this._cache.setDepthTestEnabled(value);
  82. }
  83. public get frontFace(): Nullable<number> {
  84. return this._frontFace;
  85. }
  86. public set frontFace(value: Nullable<number>) {
  87. if (this._frontFace === value) {
  88. return;
  89. }
  90. this._frontFace = value;
  91. this._isFrontFaceDirty = true;
  92. this._cache.setFrontFace(value ?? 2);
  93. }
  94. public reset() {
  95. super.reset();
  96. this._cache.resetDepthCullingState();
  97. }
  98. public apply(gl: WebGLRenderingContext) {
  99. // nothing to do
  100. }
  101. }