@@ -14,10 +14,12 @@ class ShaderCache {
1414 var sourceFile : String ;
1515 public var keepSource : Bool ;
1616 var mode : ShaderCacheMode ;
17+ var dirty = true ;
18+ public var allowSave = true ;
1719
18- inline static var VERSION_KEY_WORD = " VERSION" ;
19- inline static var VERSION = 1 ;
20- inline static var MODE_KEY_WORD = " MODE" ;
20+ public static var VERSION_KEY_WORD = " VERSION" ;
21+ public static var VERSION = 1 ;
22+ public static var MODE_KEY_WORD = " MODE" ;
2123
2224 public function new ( file : String , ? outputFile : String , mode = Base64 ) {
2325 this .file = file ;
@@ -26,16 +28,17 @@ class ShaderCache {
2628 sourceFile = file + " .source" ;
2729 }
2830
31+ @:deprecated (" use allowSave = false" )
2932 public function disableSave () {
30- outputFile = null ;
33+ allowSave = false ;
3134 }
3235
3336 public function initEmpty () {
3437 data = [];
3538 sources = [];
3639 }
3740
38- function load () {
41+ public function load () {
3942 data = new Map ();
4043 try loadFile (file ) catch ( e : Dynamic ) {};
4144 if ( outputFile != file ) try loadFile (outputFile ) catch ( e : Dynamic ) {};
@@ -54,8 +57,13 @@ class ShaderCache {
5457 var curPos = cache .position ;
5558 if ( ! hasVersion )
5659 cache .position = curPos = 0 ;
57- else
58- cache .readInt32 ();
60+ else {
61+ var version = cache .readInt32 ();
62+ if (version != VERSION ) {
63+ trace (' Shader cache version $version , expected $VERSION , skipping' );
64+ return ;
65+ }
66+ }
5967
6068 var hasMode = cache .readString (MODE_KEY_WORD .length ) == MODE_KEY_WORD ;
6169 var mode = Base64 ;
@@ -135,7 +143,8 @@ class ShaderCache {
135143
136144 var saveTimer : haxe. Timer ;
137145 public function saveCompiledShader ( source : String , bytes : haxe.io. Bytes , ? configurationKey = " " , ? saveToFile = true ) {
138- if ( outputFile == null )
146+ dirty = true ;
147+ if ( ! allowSave )
139148 return ;
140149 if ( data == null ) load ();
141150 var key = configurationKey + haxe.crypto. Md5 .encode (source );
@@ -156,7 +165,10 @@ class ShaderCache {
156165 }, 100 );
157166 }
158167
159- function save () {
168+ public function save () {
169+ if ( ! dirty )
170+ return ;
171+ dirty = false ;
160172 var out = new haxe.io. BytesOutput ();
161173 var keys = Lambda .array ({ iterator : data .keys });
162174 keys .sort (Reflect .compare );
0 commit comments