I've made some more reading.
The "Irrlicht function" you are talking about is addHighLevelShaderMaterial / FromFiles.. right?
I've taken another look at the code, and it seems it loads the shader files, adds some #define lines and adds the options passed.
If you take a look at the code, assuming it's being called like:
Code: Select all
char* files[2];
char options[512];
files[0] = "Resources/shaders/water/atmosphere.glsl";
files[1] = "Resources/shaders/water/ocean.glsl";
sprintf(options, "#define %sSEA_CONTRIB\n#define %sSUN_CONTRIB\n#define %sSKY_CONTRIB\n#define %sCLOUDS\n#define %sHARDWARE_ANISTROPIC_FILTERING\n",
seaContrib ? "" : "NO_", sunContrib ? "" : "NO_", skyContrib ? "" : "NO_", cloudLayer ? "" : "NO_", manualFilter ? "NO_" : "");
render = new Program(2, files, options);
Variable `contents` is a 4 cell array, last 2 induces (2,3) holds the shader data read by `textFileRead`, and 2 first induces (0, 1) holds the options and the definitions of vertex / fragment.
With the above information, we can assume this:
1. Since Irrlicht call's `glCreateShader` and `glAttachShader` automatically when calling `addHighLevelShaderMaterial ` (we need that at the first if condition) we can "forget" them.
2. We know`glShaderSource` requires a char* array, which is parameter named "string" which contains the shader code it self. Here:
http://www.opengl.org/sdk/docs/man/xhtm ... Source.xml
3. We know that `contents` is being passed to `glShaderSource` as parameter "string", and we also know that the size of `contents` (4) is being passed to parameter "length" which should be the size of parameter "string".
4. So everything is correct by now. However, in Irrlicht, parameter "count" is being hard-coded to 1 as in:
Code: Select all
Driver->extGlShaderSource(shaderHandle, 1, &shader, NULL);
From `COpenGLSLMaterialRenderer.cpp`.
This requires us to pass a 1-cell array to parameter "string", meaning I should merge `contents` to one (char*) variable, delimiting each cell from `contents` array with a line break. Right?
Could you elaborate more on "glBindAttribLocation"?
If I made some wrong assumptions please let me know! And sorry for that very-long-too-obvious-post, I just like to lay down information as it is in steps so it's easier to understand