@@ -8,6 +8,7 @@ import { Program } from "../../webGlObjects/webGlObjects";
88import { IContextInformation } from "../../types/contextInformation" ;
99import { IRenderBufferRecorderData } from "../../recorders/renderBufferRecorder" ;
1010import { IBufferRecorderData } from "../../recorders/bufferRecorder" ;
11+ import { ReadProgramHelper } from "../../utils/readProgramHelper" ;
1112
1213export class DrawCallState extends BaseState {
1314 public static readonly stateName = "DrawCall" ;
@@ -66,24 +67,20 @@ export class DrawCallState extends BaseState {
6667
6768 this . currentState . frameBuffer = this . readFrameBufferFromContext ( ) ;
6869
70+ const programCapture = program . __SPECTOR_Object_CustomData ?
71+ program . __SPECTOR_Object_CustomData :
72+ ReadProgramHelper . getProgramData ( this . context , program ) ;
73+
6974 this . currentState . programStatus = {
70- program : this . getSpectorData ( program ) ,
71- DELETE_STATUS : this . context . getProgramParameter ( program , WebGlConstants . DELETE_STATUS . value ) ,
72- LINK_STATUS : this . context . getProgramParameter ( program , WebGlConstants . LINK_STATUS . value ) ,
73- VALIDATE_STATUS : this . context . getProgramParameter ( program , WebGlConstants . VALIDATE_STATUS . value ) ,
74- RECOMPILABLE : ProgramRecompilerHelper . isBuildableProgram ( program ) ,
75+ ...programCapture . programStatus
7576 } ;
76-
77+ this . currentState . programStatus . program = this . getSpectorData ( program ) ;
78+ this . currentState . programStatus . RECOMPILABLE = ProgramRecompilerHelper . isBuildableProgram ( program ) ;
7779 if ( this . currentState . programStatus . RECOMPILABLE ) {
7880 Program . saveInGlobalStore ( program ) ;
7981 }
8082
81- const shaders = this . context . getAttachedShaders ( program ) ;
82- this . currentState . shaders = [ ] ;
83- for ( const shader of shaders ) {
84- const shaderState = this . readShaderFromContext ( shader ) ;
85- this . currentState . shaders . push ( shaderState ) ;
86- }
83+ this . currentState . shaders = programCapture . shaders ;
8784
8885 const attributes = this . context . getProgramParameter ( program , WebGlConstants . ACTIVE_ATTRIBUTES . value ) ;
8986 this . currentState . attributes = [ ] ;
@@ -256,29 +253,6 @@ export class DrawCallState extends BaseState {
256253 return attachmentState ;
257254 }
258255
259- protected readShaderFromContext ( shader : WebGLShader ) : { } {
260- const source = this . context . getShaderSource ( shader ) ;
261- const spectorData = this . getSpectorData ( shader ) ;
262-
263- const nameInMetadata = ( shader && ( shader as any ) . __SPECTOR_Metadata && ( shader as any ) . __SPECTOR_Metadata . name ) ;
264- let name = nameInMetadata ? ( shader as any ) . __SPECTOR_Metadata . name :
265- this . readNameFromShaderSource ( source ) ;
266-
267- if ( ! name ) {
268- name = ( this . context . getShaderParameter ( shader , WebGlConstants . SHADER_TYPE . value ) === WebGlConstants . FRAGMENT_SHADER . value ) ?
269- "Fragment" : "Vertex" ;
270- }
271-
272- return {
273- shader : spectorData ,
274- COMPILE_STATUS : this . context . getShaderParameter ( shader , WebGlConstants . COMPILE_STATUS . value ) ,
275- DELETE_STATUS : this . context . getShaderParameter ( shader , WebGlConstants . DELETE_STATUS . value ) ,
276- SHADER_TYPE : this . getWebGlConstant ( this . context . getShaderParameter ( shader , WebGlConstants . SHADER_TYPE . value ) ) ,
277- source,
278- name,
279- } ;
280- }
281-
282256 protected readAttributeFromContext ( program : WebGLProgram , activeAttributeIndex : number ) : { } {
283257 const info = this . context . getActiveAttrib ( program , activeAttributeIndex ) ;
284258 const location = this . context . getAttribLocation ( program , info . name ) ;
@@ -544,45 +518,4 @@ export class DrawCallState extends BaseState {
544518 const constant = WebGlConstantsByValue [ value ] ;
545519 return constant ? constant . name : value ;
546520 }
547-
548- // Thx to https://github.com/spite/ShaderEditorExtension/blob/7b9483fdf5c417573906bae4139ca8bc7b8a49ca/src/panel.js#L689
549- // This helps displaying SHADER_NAME used in the extension.
550- private readNameFromShaderSource ( source : string ) : string {
551- try {
552- let name = "" ;
553- let match ;
554-
555- const shaderNameRegex = / # d e f i n e [ \s ] + S H A D E R _ N A M E [ \s ] + ( [ \S ] + ) ( \n | $ ) / gi;
556- match = shaderNameRegex . exec ( source ) ;
557- if ( match !== null ) {
558- if ( match . index === shaderNameRegex . lastIndex ) {
559- shaderNameRegex . lastIndex ++ ;
560- }
561- name = match [ 1 ] ;
562- }
563-
564- if ( name === "" ) {
565- // #define SHADER_NAME_B64 44K344Kn44O844OA44O8
566- // #define SHADER_NAME_B64 8J+YjvCfmIE=
567- const shaderName64Regex = / # d e f i n e [ \s ] + S H A D E R _ N A M E _ B 6 4 [ \s ] + ( [ \S ] + ) ( \n | $ ) / gi;
568- match = shaderName64Regex . exec ( source ) ;
569- if ( match !== null ) {
570- if ( match . index === shaderName64Regex . lastIndex ) {
571- shaderName64Regex . lastIndex ++ ;
572- }
573-
574- name = match [ 1 ] ;
575- }
576-
577- if ( name ) {
578- name = decodeURIComponent ( atob ( name ) ) ;
579- }
580- }
581-
582- return name ;
583- }
584- catch ( e ) {
585- return null ;
586- }
587- }
588521}
0 commit comments