Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualNickie

Posted 29 September 2012 - 10:49 AM

Hmh,
If you have done this to this part I don't see reason why u couldn't do it. I would do it in little complex way using inheritance and base interface for managing certain effects.(I assume effects for d3d9, d3d11 and opengl are different, altough I've been using only d9 and have no idea how are the others working)
Each mesh/node can keep a pointer to a shader, and a data which is gonna be passed. Ahh let me shot you:
class IShaderData{};
class SpecularShaderData : public IShaderData
{
int specular_power;
};
class IShaderEffect{};
class SpecularShaderEffect : public IShaderEffect
{
void SetShaderVariables(IRenderer *r, IShaderData* d)
{
	 r->SetShaderVar("specular_power", reinterpret_cast<SpecularShaderData*>(d)->specular_power);
	 //list here other vars that need to get into the renderer
}
union
{
D3D9ShaderObject * shader9; // renderer would know which one is active and which one to copy
D3D11ShaderObject * shader11;
};
};
class Mesh
{
IShaderEffect * m_peffect;
IShaderData  * m_pdata;
//Vertex data
//...............
//End of vertex data
}
class IRenderer
{
public:
virtual void DrawMesh(Mesh * mesh) = 0;
}
class Renderer9 : public IRenderer
{
public:
virtual void DrawMesh(Mesh * mesh)
{
this->SetActiveShader(mesh->m_pshader); // update the renderer's shader pointer. This one will be used in the rendering process.
mesh->m_pshader->SetShaderVariables(this, m_pdata); // pass the data, the inherited version of the shader would know what to do with it, renderer is requesred because I have tried to keep all direct3d related code in the Renderer class. Everything is done using the interface functions.
//actuall drawing code, like
d3ddevice->SetIndeces();
d3ddevice->DrawIndexedPrimitive();
//end
}
}
The code is written directly here, so don't jugle if something is wrong. My engine's code is something like this.
However I would be happy if someone else have better idea.


Edit: Instead reinterpret_cast -> dynamic_cast

#1Nickie

Posted 29 September 2012 - 10:47 AM

Hmh,
If you have done this to this part I don't see reason why u couldn't do it. I would do it in little complex way using inheritance and base interface for managing certain effects.(I assume effects for d3d9, d3d11 and opengl are different, altough I've been using only d9 and have no idea how are the others working)
Each mesh/node can keep a pointer to a shader, and a data which is gonna be passed. Ahh let me shot you:
class IShaderData{};
class SpecularShaderData : public IShaderData
{
int specular_power;
};
class IShaderEffect{};
class SpecularShaderEffect : public IShaderEffect
{
void SetShaderVariables(IRenderer *r, IShaderData* d)
{
     r->SetShaderVar("specular_power", reinterpret_cast<SpecularShaderData*>(d)->specular_power);
     //list here other vars that need to get into the renderer
}
union
{
D3D9ShaderObject * shader9; // renderer would know which one is active and which one to copy
D3D11ShaderObject * shader11;
};
};
class Mesh
{
IShaderEffect * m_peffect;
IShaderData  * m_pdata;
//Vertex data
//...............
//End of vertex data
}
class IRenderer
{
public:
virtual void DrawMesh(Mesh * mesh) = 0;
}
class Renderer9 : public IRenderer
{
public:
virtual void DrawMesh(Mesh * mesh)
{
this->SetActiveShader(mesh->m_pshader); // update the renderer's shader pointer. This one will be used in the rendering process.
mesh->m_pshader->SetShaderVariables(this, m_pdata); // pass the data, the inherited version of the shader would know what to do with it, renderer is requesred because I have tried to keep all direct3d related code in the Renderer class. Everything is done using the interface functions.
//actuall drawing code, like
d3ddevice->SetIndeces();
d3ddevice->DrawIndexedPrimitive();
//end
}
}
The code is written directly here, so don't jugle if something is wrong. My engine's code is something like this.
However I would be happy if someone else have better idea.

PARTNERS