forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderFragment.js
73 lines (65 loc) · 1.99 KB
/
renderFragment.js
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
/*global define*/
define([
'Core/defaultValue',
'Core/PrimitiveType',
'Renderer/Buffer',
'Renderer/BufferUsage',
'Renderer/ClearCommand',
'Renderer/DrawCommand',
'Renderer/RenderState',
'Renderer/ShaderProgram',
'Renderer/VertexArray'
], function(
defaultValue,
PrimitiveType,
Buffer,
BufferUsage,
ClearCommand,
DrawCommand,
RenderState,
ShaderProgram,
VertexArray) {
'use strict';
function renderFragment(context, fs, depth, clear) {
var vs = 'attribute vec4 position; void main() { gl_PointSize = 1.0; gl_Position = position; }';
var sp = ShaderProgram.fromCache({
context : context,
vertexShaderSource : vs,
fragmentShaderSource : fs
});
depth = defaultValue(depth, 0.0);
var va = new VertexArray({
context : context,
attributes : [{
index : sp.vertexAttributes.position.index,
vertexBuffer : Buffer.createVertexBuffer({
context : context,
typedArray : new Float32Array([0.0, 0.0, depth, 1.0]),
usage : BufferUsage.STATIC_DRAW
}),
componentsPerAttribute : 4
}]
});
var rs = RenderState.fromCache({
depthTest : {
enabled : true
}
});
clear = defaultValue(clear, true);
if (clear) {
ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);
}
var command = new DrawCommand({
primitiveType : PrimitiveType.POINTS,
shaderProgram : sp,
vertexArray : va,
renderState : rs
});
command.execute(context);
sp = sp.destroy();
va = va.destroy();
return context.readPixels();
}
return renderFragment;
});