MCPcopy
hub / github.com/regl-project/regl / initElements

Function initElements

lib/elements.js:70–156  ·  view source on GitHub ↗
(
    elements,
    data,
    usage,
    prim,
    count,
    byteLength,
    type)

Source from the content-addressed store, hash-verified

68 }
69
70 function initElements (
71 elements,
72 data,
73 usage,
74 prim,
75 count,
76 byteLength,
77 type) {
78 elements.buffer.bind()
79 var dtype
80 if (data) {
81 var predictedType = type
82 if (!type && (
83 !isTypedArray(data) ||
84 (isNDArrayLike(data) && !isTypedArray(data.data)))) {
85 predictedType = extensions.oes_element_index_uint
86 ? GL_UNSIGNED_INT
87 : GL_UNSIGNED_SHORT
88 }
89 bufferState._initBuffer(
90 elements.buffer,
91 data,
92 usage,
93 predictedType,
94 3)
95 } else {
96 gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, byteLength, usage)
97 elements.buffer.dtype = dtype || GL_UNSIGNED_BYTE
98 elements.buffer.usage = usage
99 elements.buffer.dimension = 3
100 elements.buffer.byteLength = byteLength
101 }
102
103 dtype = type
104 if (!type) {
105 switch (elements.buffer.dtype) {
106 case GL_UNSIGNED_BYTE:
107 case GL_BYTE:
108 dtype = GL_UNSIGNED_BYTE
109 break
110
111 case GL_UNSIGNED_SHORT:
112 case GL_SHORT:
113 dtype = GL_UNSIGNED_SHORT
114 break
115
116 case GL_UNSIGNED_INT:
117 case GL_INT:
118 dtype = GL_UNSIGNED_INT
119 break
120
121 default:
122 check.raise('unsupported type for element array')
123 }
124 elements.buffer.dtype = dtype
125 }
126 elements.type = dtype
127

Callers 2

createElementStreamFunction · 0.85
reglElementsFunction · 0.85

Calls 1

checkFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…