@@ -45,6 +45,36 @@ export class StencilState extends ParameterState {
45
45
{ constant : WebGlConstants . STENCIL_WRITEMASK , returnType : ParameterReturnType . GlUint , changeCommands : [ "stencilMask" , "stencilMaskSeparate" ] } ] ;
46
46
}
47
47
48
+ protected readFromContext ( ) : void {
49
+ super . readFromContext ( ) ;
50
+
51
+ const gl = this . context ;
52
+ const target = WebGlConstants . FRAMEBUFFER . value ;
53
+ const attachment = WebGlConstants . STENCIL_ATTACHMENT . value ;
54
+ const frameBuffer = gl . getParameter ( WebGlConstants . FRAMEBUFFER_BINDING . value ) ;
55
+
56
+ let value = 0 ;
57
+ if ( ! frameBuffer ) {
58
+ value = this . readParameterFromContext ( { constant : WebGlConstants . STENCIL_BITS } ) ;
59
+ }
60
+ else {
61
+ const type = this . context . getFramebufferAttachmentParameter ( target , attachment , WebGlConstants . FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE . value ) ;
62
+ if ( type !== WebGlConstants . NONE . value ) {
63
+ if ( this . contextVersion > 1 ) {
64
+ value = this . context . getFramebufferAttachmentParameter ( target , attachment , WebGlConstants . FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE . value ) ;
65
+ }
66
+ else {
67
+ const storage = this . context . getFramebufferAttachmentParameter ( target , attachment , WebGlConstants . FRAMEBUFFER_ATTACHMENT_OBJECT_NAME . value ) ;
68
+ if ( storage === WebGlConstants . RENDERBUFFER . value ) {
69
+ value = gl . getRenderbufferParameter ( gl . RENDERBUFFER , gl . RENDERBUFFER_STENCIL_SIZE ) ;
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ this . currentState [ WebGlConstants . STENCIL_BITS . name ] = "" + value ;
76
+ }
77
+
48
78
protected isValidChangeCommand ( command : ICommandCapture , stateName : string ) : boolean {
49
79
if ( command . name === "enable" || command . name === "disable" ) {
50
80
return command . commandArguments [ 0 ] === WebGlConstants . STENCIL_TEST . value ;
0 commit comments