what is the third parameter of BL_Shader.setSource ?

I was looking at some of this pretty confusing apply-my-shader codes. And I stumbled over a call to BL_Shader.setSource(vertexProgram, fragmentProgram).

But the BGE tells me there is a third parameter. Does anyone know what that parameter is? how is it called and what it is good for.

From my experiments it looks like:
False: setSource on all materials
True: setSource on current material only
But this is very weak empirical data.

Any idea?

In the setSource C++ code it is an integer named “apply” which gets evaluated to “mUse = apply!=0;”
That is used in BL_Shader.cpp in

bool BL_Shader::Ok()const
    return (mShader !=0 && mOk && mUse);

In BL_Shader::Update, KX_BlenderMaterial::setShaderData, KX_BlenderMaterial::Activate and KX_BlenderMaterial::UsesLighting that method is used. Mostly to check if the shader is OK and can be used.

So if you set that parameter to 0, it gets evaluated to False, Shader::Ok returns False when called and you probably shouldn’t see the shader working.

It’s a simple switch if the shader should actually be used or not.

Thanks Urfoex, for looking that up!

I will check this with a bit more detail as the outcome is a bit strange. And the parameter makes no real sense. Who would set shaders without applying them. “apply” is not really something that tells what it does. So we need the hard way :wink: -> deep investigation.

it looks like a dirty hack (which explains the missing documentation):

		if ( LinkProgram() ) {
			glUseProgramObjectARB( mShader );
			mUse = apply!=0;

It sets the shader for OpenGL, but then it tells the bge not to use it. This is strange.

setAttrib() ignores mOk at all and sets the shader too. I do not know what this call is used for. The doc says it sets an attribute location value. What is an “attribute location value” and why does this code set the shader (again)?

SetProg() (Non-python) sets the shader too, but cares the mOk flag.