Architecture 是否在架构上更正纹理/着色器/材质/VB/IB绑定本身?
我正在编写游戏引擎,无法解决什么方法是正确的。 例如,我将向您展示一个材质类 第一种方式:Architecture 是否在架构上更正纹理/着色器/材质/VB/IB绑定本身?,architecture,game-engine,Architecture,Game Engine,我正在编写游戏引擎,无法解决什么方法是正确的。 例如,我将向您展示一个材质类 第一种方式: class Material { public: void Bind(); // bind all that can: uniforms, textures, vertex shader, fragment shader, etc }; // somewhere in scene manager ... material.Bind(); // below is binding all
class Material {
public:
void Bind(); // bind all that can: uniforms, textures, vertex shader, fragment shader, etc
};
// somewhere in scene manager
...
material.Bind();
// below is binding all params and resources that material require from outside
if (material.IsRequireWVP()) glUniform(...);
if (material.IsRequireModelTexture()) glBindTexture(...);
...
第二种方式:
class Material {
public:
TexGLES2Ref GetTexture();
VSGLES2Ref GetVertexShader();
string GetUniformName();
value getUniformValue();
// etc
};
// somewhere in scene manager
...
// bind all resources that material need here
// material has no bind method
glUniform(material->get(....), material->get(...));
if (material.IsRequireWVP()) glUniform(...);
if (material.IsRequireModelTexture()) glBindTexture(...);
...
因为“书不能自己读”我用第二种方法,
但这种方式不如第一种方式舒服,因为如果我需要从许多代码位置绑定材质,那么我必须编写大量代码,因为材质具有通道、制服、纹理等,这就是“循环中循环”。我想象的第一个解决方案是编写函数,比如bindmarterial(Material*Material)代码>在这种情况下“书不会自己读”
但我看到很多使用第一种方式的代码,并且认为使用第一种方式肯定有一些理由。也许编码人员只是拒绝“书本身无法阅读”,而使用对他们来说更舒适的方式
哪种方法更好更正确?
您使用什么方式以及为什么使用?