yzt
2023-05-26 de4278af2fd46705a40bac58ec01122db6b7f3d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { BoundingRectangle } from "../../Source/Cesium.js";
import { Color } from "../../Source/Cesium.js";
import { ClearCommand } from "../../Source/Cesium.js";
import { Framebuffer } from "../../Source/Cesium.js";
import { RenderState } from "../../Source/Cesium.js";
import { Texture } from "../../Source/Cesium.js";
import createContext from "../createContext.js";
 
describe(
  "Renderer/Clear",
  function () {
    var context;
 
    beforeAll(function () {
      context = createContext();
    });
 
    afterAll(function () {
      context.destroyForSpecs();
    });
 
    it("default clear", function () {
      ClearCommand.ALL.execute(context);
      expect(context).toReadPixels([0, 0, 0, 255]);
    });
 
    it("clears to white", function () {
      ClearCommand.ALL.execute(context);
      expect(context).toReadPixels([0, 0, 0, 255]);
 
      var command = new ClearCommand({
        color: Color.WHITE,
      });
      command.execute(context);
      expect(context).toReadPixels([255, 255, 255, 255]);
    });
 
    it("clears with a color mask", function () {
      ClearCommand.ALL.execute(context);
      expect(context).toReadPixels([0, 0, 0, 255]);
 
      var command = new ClearCommand({
        color: Color.WHITE,
        renderState: RenderState.fromCache({
          colorMask: {
            red: true,
            green: false,
            blue: true,
            alpha: true,
          },
        }),
      });
      command.execute(context);
      expect(context).toReadPixels([255, 0, 255, 255]);
    });
 
    it("clears with scissor test", function () {
      var command = new ClearCommand({
        color: Color.WHITE,
      });
 
      command.execute(context);
      expect(context).toReadPixels([255, 255, 255, 255]);
 
      command.color = Color.BLACK;
      command.renderState = RenderState.fromCache({
        scissorTest: {
          enabled: true,
          rectangle: new BoundingRectangle(),
        },
      });
 
      command.execute(context);
      expect(context).toReadPixels([255, 255, 255, 255]);
 
      command.renderState = RenderState.fromCache({
        scissorTest: {
          enabled: true,
          rectangle: new BoundingRectangle(0, 0, 1, 1),
        },
      });
 
      command.execute(context);
      expect(context).toReadPixels([0, 0, 0, 255]);
    });
 
    it("clears a framebuffer color attachment", function () {
      var colorTexture = new Texture({
        context: context,
        width: 1,
        height: 1,
      });
      var framebuffer = new Framebuffer({
        context: context,
        colorTextures: [colorTexture],
      });
 
      var command = new ClearCommand({
        color: new Color(0.0, 1.0, 0.0, 1.0),
        framebuffer: framebuffer,
      });
      command.execute(context);
 
      expect({
        context: context,
        framebuffer: framebuffer,
      }).toReadPixels([0, 255, 0, 255]);
 
      framebuffer = framebuffer.destroy();
    });
 
    it("fails to read pixels (width)", function () {
      expect(function () {
        expect(
          context.readPixels({
            width: -1,
          })
        ).toEqual([0, 0, 0, 0]);
      }).toThrowDeveloperError();
    });
 
    it("fails to read pixels (height)", function () {
      expect(function () {
        expect(
          context.readPixels({
            height: -1,
          })
        ).toEqual([0, 0, 0, 0]);
      }).toThrowDeveloperError();
    });
  },
  "WebGL"
);