On 28/01/2013 at 08:43, xxxxxxxx wrote:
Hello Yannick,
>>> I've been able to clone a layer shader and init it for render from a CommandData::Execute().
Interesting. Thanks for checking this. I am doing this operation in my ShaderData subclass on
InitRender(). More specifically, the InitRenderStruct that is passed there is passed through to the
layer shader.
This is the complete InitRender() function:
INITRENDERRESULT ShaderLinkData::InitRender(BaseShader\* shader, const InitRenderStruct& irs) {
if (!shader) return INITRENDERRESULT_UNKNOWNERROR;
BaseDocument\* doc = shader->GetDocument();
BaseContainer\* container = shader->GetDataInstance();
if (!container || !doc) return INITRENDERRESULT_UNKNOWNERROR;
// Clone the reference if available.
BaseShader\* reference = this->GetReferenceShaderInstance(shader, container, doc);
if (reference) {
this->iref = (BaseShader\*) reference->GetClone(COPYFLAGS_0, NULL);
if (!this->iref) {
return INITRENDERRESULT_OUTOFMEMORY;
}
INITRENDERRESULT result = this->iref->InitRender(irs);
if (result != INITRENDERRESULT_OK) {
GePrint("ERROR, this->iref->InitRender() returned " + LongToString(result));
}
return result;
}
else {
this->iref = NULL;
}
return INITRENDERRESULT_OK;
}
The GetReferenceShaderInstance() method basically just grabs a shader from a linkfield in the
shaders description. Later in ShaderData::Output(), I use iref->Sample() to output what the
cloned shader would output, but that is just yellow when a layer shader is used as reference
(and the error message from the code above is printed to the console).
Would you like to take a look at the complete source-code? I'd prefer to make it not public, yet.
Thanks!
-Niklas