简体   繁体   English

这是什么C ++函数声明

[英]What is this C++ Function Declaration

Im new to C++ and what im working on the docs tell me to look at the example code only it doesnt explain anything so im trying to decipher it. 我是C ++的新手,在文档上工作的内容告诉我看示例代码,只是它没有解释任何内容,因此我试图对其进行解密。

i came a across this declaration of a function but i dont fully understand it. 我遇到了这个函数的声明,但我不完全理解。

just the first function 只是第一个功能

i get underneath part what i dont get is after the MHWRender::MPxShaderOverride(obj) and then it starts as a list of arguments(or what its called i dont know) 我在MHWRender :: MPxShaderOverride(obj)之后得到了我没有得到的部分,然后它开始作为参数列表(或者它叫什么我不知道)

and i guess where i would find what the specified inputs would be. 我猜我会在哪里找到指定的输入。

again i have no idea what this is doing so im a bit lost in how to explain it. 再次,我不知道这是怎么回事,所以我在如何解释它上有些迷失。

full code can be found here: http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_hw_phong_shader_2hw_phong_shader_8cpp_example_html 完整的代码可以在这里找到: http : //help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_hw_phong_shader_2hw_phong_shader_8cpp_example_html

    hwPhongShaderOverride(const MObject& obj)
: MHWRender::MPxShaderOverride(obj)
, fShaderNode(NULL)
, fTextureData(NULL)
, fDrawUsingShader(true) // Disabling this will use fixed-function which only has an OpenGL implementation
, fShaderBound(false)
, fTexture(NULL)
, fInColorPass(false)
, fColorShaderInstance(NULL)
, fInShadowPass(false)
, fShadowShaderInstance(NULL)
, fTransparency(0.0f)
{
    // Create a shader instance to use for drawing
    //
    if (fDrawUsingShader)
    {
        createShaderInstance();
    }
    fAmbient[0] = fAmbient[1] = fAmbient[2] = 0.0f;
    fDiffuse[0] = fDiffuse[1] = fDiffuse[2] = fDiffuse[3] = 0.0f;
    fSpecular[0] = fSpecular[1] = fSpecular[2] = 0.0f;
    fShininess[0] = fShininess[1] = fShininess[2] = 500.0f;
}

// override blend state when there is blending
static const MHWRender::MBlendState *sBlendState;

// Current hwPhongShader node associated with the shader override.
// Updated during doDG() time.
hwPhongShader *fShaderNode;
// Shader inputs values including transparency
float fTransparency;
float fAmbient[3];
float fDiffuse[4];
float fSpecular[3];
float fShininess[3];

// Temporary system buffer for creating textures
unsigned char* fTextureData;

// Pass tracking
bool fInColorPass;
bool fInShadowPass;

// Draw with texture or shader flag
bool fDrawUsingShader;
// VP2 texture
MHWRender::MTexture *fTexture;
// VP2 color shader
MHWRender::MShaderInstance *fColorShaderInstance;
// VP2 shadow shader
MHWRender::MShaderInstance *fShadowShaderInstance;
mutable bool fShaderBound;

This is a class constructor. 这是一个类构造函数。 The class is named hwPhongShaderOverrideMObject , and it derives from MHWRender::MPxShaderOverride , eg: 该类名为hwPhongShaderOverrideMObject ,它是从MHWRender::MPxShaderOverride ,例如:

class hwPhongShaderOverrideMObject : public MHWRender::MPxShaderOverride
{
    ...
};

hwPhongShaderOverride(const MObject& obj) specifies that this constructor takes one argument as input, a const reference to a MObject instance. hwPhongShaderOverride(const MObject& obj)指定此构造函数采用一个参数作为输入,即对MObject实例的const引用。 The constructor is being declared and implemented inline inside the class declaration itself, rather than being implemented separately from its declaration. 构造函数是在类声明本身内部内联声明和实现的,而不是与其声明分开实现的。 Both approaches are allowed in C++. 两种方法都可以在C ++中使用。

Everything between : and { is the initialization list for the constructor. :{之间的所有内容都是构造函数的初始化列表 It initializes members of the class. 它初始化类的成员。

: begins the initialization list. :开始初始化列表。

MHWRender::MPxShaderOverride(obj) is passing the input object to the base class constructor. MHWRender::MPxShaderOverride(obj)将输入对象传递给基类构造函数。 Base classes must always be constructed first. 必须始终首先构造基类。

, fShaderNode(NULL) is initializing the fShaderNode member to NULL. , fShaderNode(NULL)正在将fShaderNode成员初始化为NULL。

, fTextureData(NULL) is initializing the fTextureData member to NULL. , fTextureData(NULL)正在将fTextureData成员初始化为NULL。

And so on until { is reached to end the initialization list. 依此类推,直到到达{以结束初始化列表。 Then the body of the constructor is entered, like any other function, after the class members have been initialized first. 然后,在初始化类成员之后,像其他任何函数一样,输入构造函数的主体

Below is a constructor. 下面是一个构造函数。

hwPhongShaderOverride(const MObject& obj)
: MHWRender::MPxShaderOverride(obj)
, fShaderNode(NULL)
, fTextureData(NULL)
, fDrawUsingShader(true) // Disabling this will use fixed-function which only has an OpenGL implementation
, fShaderBound(false)
, fTexture(NULL)
, fInColorPass(false)
, fColorShaderInstance(NULL)
, fInShadowPass(false)
, fShadowShaderInstance(NULL)
, fTransparency(0.0f)
{
    // Create a shader instance to use for drawing
    //
    if (fDrawUsingShader)
    {
        createShaderInstance();
    }
    fAmbient[0] = fAmbient[1] = fAmbient[2] = 0.0f;
    fDiffuse[0] = fDiffuse[1] = fDiffuse[2] = fDiffuse[3] = 0.0f;
    fSpecular[0] = fSpecular[1] = fSpecular[2] = 0.0f;
    fShininess[0] = fShininess[1] = fShininess[2] = 500.0f;
}

It is using an initializer list to initialize its member variables by calling their constructors. 它使用初始化程序列表通过调用其构造函数来初始化其成员变量。 hwPhongShaderOverride inherits from MHWRender::MPxShaderOverride , so it calls MHWRender::MPxShaderOverride 's constructor as the first element in the initializer list (ie, MHWRender::MPxShaderOverride(obj) . hwPhongShaderOverride继承自MHWRender::MPxShaderOverride ,因此它将MHWRender::MPxShaderOverride的构造函数称为初始化列表中的第一个元素(即MHWRender::MPxShaderOverride(obj)

You can toggle fDrawUsingShader to create an instance of a shader (as seen in the body of the constructor). 您可以切换fDrawUsingShader来创建着色器的实例(如在构造函数主体中所示)。 After that it adds some initial values to the four arrays fAmbient , fDiffuse , fSpecular , and fShininess . 之后,它将向四个数组fAmbientfDiffusefSpecularfShininess添加一些初始值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM