mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
test(render): a GPU icon set's draw commands: translucent sets draw one blended pass in the opaque pass, LESS_OR_EQUAL with depth written; others an opaque and a translucent pass
This commit is contained in:
1 parent
44c9ed6d5c
commit
9fb39eb6da
1 file changed
+60
@@ -0,0 +1,60 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createIconSet } from '../../data/iconSet.js';
|
||||
import { IconSetPrimitive } from './iconSetPrimitive.js';
|
||||
|
||||
// Node has no WebGL context to report line-width limits.
|
||||
Cesium.ContextLimits._minimumAliasedLineWidth = 1;
|
||||
Cesium.ContextLimits._maximumAliasedLineWidth = 10;
|
||||
|
||||
/** The primitive's draw commands, made without a context: programs stubbed. */
|
||||
function commandsOf(options = {}) {
|
||||
const made = [];
|
||||
const fromCache = Cesium.ShaderProgram.fromCache;
|
||||
Cesium.ShaderProgram.fromCache = ({ fragmentShaderSource }) => {
|
||||
const program = { defines: fragmentShaderSource.defines, destroy() {} };
|
||||
made.push(program);
|
||||
return program;
|
||||
};
|
||||
try {
|
||||
const primitive = new IconSetPrimitive({
|
||||
set: createIconSet(),
|
||||
renderTime: () => Cesium.JulianDate.now(),
|
||||
...options,
|
||||
});
|
||||
primitive._createCommands(undefined);
|
||||
return { primitive, programs: made };
|
||||
} finally {
|
||||
Cesium.ShaderProgram.fromCache = fromCache;
|
||||
}
|
||||
}
|
||||
|
||||
test('a translucent set draws one blended pass in order, as translucent billboards do', () => {
|
||||
const { primitive } = commandsOf({ translucent: () => true });
|
||||
const single = primitive._singleCommand;
|
||||
// In the opaque pass, out of the translucent pass's order-independent blend.
|
||||
assert.equal(single.pass, Cesium.Pass.OPAQUE);
|
||||
const state = single.renderState;
|
||||
// Equal depths pass, so the last row drawn is on top.
|
||||
assert.equal(state.depthTest.enabled, true);
|
||||
assert.equal(state.depthTest.func, Cesium.DepthFunction.LESS_OR_EQUAL);
|
||||
assert.equal(state.depthMask, true);
|
||||
assert.equal(state.blending.enabled, true);
|
||||
// Every fragment drawn: neither pass's alpha split.
|
||||
assert.deepEqual(single.shaderProgram.defines, []);
|
||||
assert.equal(primitive.drawsBlend('translucent'), true);
|
||||
assert.equal(primitive.drawsBlend('additive'), false);
|
||||
});
|
||||
|
||||
test('by default the set draws an opaque pass and a translucent one, and draws no blend itself', () => {
|
||||
const { primitive } = commandsOf();
|
||||
const [opaque, translucent] = primitive._commands;
|
||||
assert.equal(opaque.pass, Cesium.Pass.OPAQUE);
|
||||
assert.deepEqual(opaque.shaderProgram.defines, ['OPAQUE']);
|
||||
assert.equal(opaque.renderState.depthTest.func, Cesium.DepthFunction.LESS);
|
||||
assert.equal(translucent.pass, Cesium.Pass.TRANSLUCENT);
|
||||
assert.deepEqual(translucent.shaderProgram.defines, ['TRANSLUCENT']);
|
||||
assert.equal(translucent.renderState.depthMask, false);
|
||||
assert.equal(primitive.drawsBlend('translucent'), false);
|
||||
});
|
||||
Reference in new issue
Block a user