@@ -97,22 +97,29 @@ export function glTypeToTypedArray(type) {
97
97
98
98
export function getDrawingbufferInfo ( gl ) {
99
99
return {
100
- samples : gl . getParameter ( gl . SAMPLES ) ,
100
+ samples : gl . getParameter ( gl . SAMPLES ) || 1 ,
101
101
depthBits : gl . getParameter ( gl . DEPTH_BITS ) ,
102
+ stencilBits : gl . getParameter ( gl . STENCIL_BITS ) ,
102
103
contextAttributes : gl . getContextAttributes ( ) ,
103
104
} ;
104
105
}
106
+
107
+ function computeDepthStencilSize ( drawingBufferInfo ) {
108
+ const { depthBits, stencilBits} = drawingBufferInfo
109
+ const depthSize = ( depthBits + stencilBits + 7 ) / 8 | 0 ;
110
+ return depthSize === 3 ? 4 : depthSize ;
111
+ }
112
+
105
113
export function computeDrawingbufferSize ( gl , drawingBufferInfo ) {
106
- // this will need to change for hi-color support
107
114
if ( gl . isContextLost ( ) ) {
108
115
return 0 ;
109
116
}
110
- const { samples, depthBits , contextAttributes } = drawingBufferInfo ;
111
- const size = gl . drawingBufferWidth * gl . drawingBufferHeight * 4 || 0 ;
112
- const depth = contextAttributes . depth ? 1 : 0 ;
113
- const stencil = contextAttributes . stencil ? 1 : 0 ;
114
- const depthSize = Math . min ( stencil + depthBits > 16 ? 4 : 2 , 4 ) ;
115
- return size + size * samples + size * depth * depthSize ;
117
+ const { samples} = drawingBufferInfo ;
118
+ // this will need to change for hi-color support
119
+ const colorSize = 4 ;
120
+ const size = gl . drawingBufferWidth * gl . drawingBufferHeight ;
121
+ const depthStencilSize = computeDepthStencilSize ( drawingBufferInfo ) ;
122
+ return size * colorSize + size * samples * colorSize + size * depthStencilSize ;
116
123
}
117
124
118
125
// I know this is not a full check
0 commit comments