Because I've finished up with university I've got a lot more free time to experiment and test out some ideas.
I've been working on a material loading system and I've also written a new data loader, and today I've managed to get them both working together and drawing a 2D picture.
What I have are materials defined as such:
The loader will tokenise the file, splitting it by NAME, OPEN_BLOCK, CLOSE_BLOCK, OPERATOR and TERMINATE, it will ignore // markers up until the end of a line and /* markers up until the next */ found (For comments).
Once the tokens have been found the compiler runs over the list; when it finds a name it stores it in a temp buffer, if it then finds an open_block then it creates a new block with the name in the temp buffer, clears the temp buffer and enters the block for adding children.
When it finds the = operator, the stored name becomes a keyword for the current block, it then expects the next name to be a value and converts it to int, double, bool or quoted-string depending on the input string. Every entry ends with a ; termination.
I definitely think this is the way to write file-parsers, my original system did a top-down, single-pass compile but error handling was difficult, because the token system has an expected pattern (Blocks must come after name, end block must close block, operator must have name then a terminate) I am able to report the line that the error happened and describe the error, so large data files can be written and error reported to the developer.
The material system compiles shaders and writes the uniforms for the shaders and loads up to 8 PNG textures with parameters, a Graphics Driver singleton class managers the current active material, so when you change material it will check "Is this material already in use?" if it is, then do nothing, otherwise bind the material's textures and shader. This removes the need for tracking shader and texture bindings (Expensive in OpenGL).
The plan is, build a system that organises objects with no transparency (solids) by material and mesh, so when you draw it the system will only change material and vertex array objects as it needs to, hopefully giving some awesome performance for scenes with many materials and many objects.
I've been working on a material loading system and I've also written a new data loader, and today I've managed to get them both working together and drawing a 2D picture.
What I have are materials defined as such:
Code:
type = "solid";
shader {
vertex = "screen.vsh";
geometry = "screen.gsh";
fragment = "default.fsh";
}
texture0 {
file = "default.png";
}
uniforms {
uniform_texture0 = 0;
uniform_alpha = 0.5;
}
Once the tokens have been found the compiler runs over the list; when it finds a name it stores it in a temp buffer, if it then finds an open_block then it creates a new block with the name in the temp buffer, clears the temp buffer and enters the block for adding children.
When it finds the = operator, the stored name becomes a keyword for the current block, it then expects the next name to be a value and converts it to int, double, bool or quoted-string depending on the input string. Every entry ends with a ; termination.
I definitely think this is the way to write file-parsers, my original system did a top-down, single-pass compile but error handling was difficult, because the token system has an expected pattern (Blocks must come after name, end block must close block, operator must have name then a terminate) I am able to report the line that the error happened and describe the error, so large data files can be written and error reported to the developer.
The material system compiles shaders and writes the uniforms for the shaders and loads up to 8 PNG textures with parameters, a Graphics Driver singleton class managers the current active material, so when you change material it will check "Is this material already in use?" if it is, then do nothing, otherwise bind the material's textures and shader. This removes the need for tracking shader and texture bindings (Expensive in OpenGL).
The plan is, build a system that organises objects with no transparency (solids) by material and mesh, so when you draw it the system will only change material and vertex array objects as it needs to, hopefully giving some awesome performance for scenes with many materials and many objects.