1 module ecs_utils.gfx.config; 2 3 import bindbc.sdl; 4 5 import bubel.ecs.std; 6 7 import ecs_utils.gfx.material; 8 import ecs_utils.gfx.mesh; 9 import ecs_utils.gfx.texture; 10 11 //import mutils.serializer.json; 12 13 extern(C): 14 15 enum LayerType 16 { 17 normal, 18 sorted 19 } 20 21 import bubel.ecs.vector; 22 23 static struct GfxConfig 24 { 25 extern(C): 26 __gshared: 27 Vector!LayerType layers; 28 //Vector!Mesh meshes; 29 //Vector!Material materials; 30 Mesh[] meshes; 31 Material[] materials; 32 33 static bool load(const (char)[] path) nothrow 34 { 35 struct LoadData 36 { 37 struct Str 38 { 39 @("malloc") string str; 40 } 41 42 @("malloc") Str[] materials; 43 @("malloc") Str[] meshes; 44 int inter; 45 46 void dispose() nothrow 47 { 48 /*if(blend_mode)Mallocator.instance.dispose(cast(char[])blend_mode); 49 if(vertex)Mallocator.instance.dispose(cast(char[])vertex); 50 if(fragment)Mallocator.instance.dispose(cast(char[])fragment);*/ 51 } 52 } 53 54 char[] cpath = (cast(char*)alloca(path.length+1))[0..path.length+1]; 55 cpath[0..$-1] = path[0..$]; 56 cpath[$-1] = 0; 57 58 SDL_RWops* file = SDL_RWFromFile(cpath.ptr,"r"); 59 if(file) 60 { 61 size_t size = cast(size_t)SDL_RWsize(file); 62 char[] buffer = Mallocator.makeArray!char(size); 63 SDL_RWread(file,buffer.ptr,size,1); 64 65 LoadData load_data; 66 scope(exit)load_data.dispose(); 67 68 /*JSONSerializer serializer = Mallocator.make!JSONSerializer; 69 scope(exit)Mallocator.dispose(serializer); 70 serializer.serialize!(Load.yes, true)(load_data,buffer);*/ 71 72 //if(__ecs_used_backend == Backend.opengl) 73 { 74 meshes = Mallocator.makeArray!Mesh(load_data.meshes.length); 75 foreach(i,ref mesh; meshes) 76 { 77 mesh.load(load_data.meshes[i].str); 78 mesh.uploadData(); 79 } 80 } 81 82 materials = Mallocator.makeArray!Material(load_data.materials.length); 83 foreach(i,ref material; materials) 84 { 85 material.create(); 86 material.load(load_data.materials[i].str); 87 material.compile(); 88 } 89 90 SDL_RWclose(file); 91 load_data.dispose(); 92 return true; 93 } 94 else return false; 95 } 96 97 static int addLayer(LayerType type) 98 { 99 layers.add(type); 100 return cast(int)(layers.length-1); 101 } 102 }