类/结构/联合中的匿名类/结构/联合意味着什么?

时间:2019-04-26 04:28:37

标签: c++ anonymous-class

我正在查看bgfx源代码,发现了吗?

我知道什么是匿名类,但是您必须为其创建一个对象-在这里,开发人员只是在struct中声明它-那么他如何访问它?

struct Uniforms
{
    enum { NumVec4 = 12 }; //Why an enum for one value?

    void init()
    {
        u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, NumVec4);
    }

    void submit()
    {
        bgfx::setUniform(u_params, m_params, NumVec4);
    }

    void destroy()
    {
        bgfx::destroy(u_params);
    }

    union //this union also has no object what does it mean?
    {
        struct//this struct also has no variable
        {
            union
            {
                  float m_mtx[16];
            /* 0*/ struct { float m_mtx0[4]; };
            /* 1*/ struct { float m_mtx1[4]; };
            /* 2*/ struct { float m_mtx2[4]; };
            /* 3*/ struct { float m_mtx3[4]; };
            }; //Why is this union without object?
            /* 4*/ struct { float m_glossiness, m_reflectivity, m_exposure, m_bgType; };
            /* 5*/ struct { float m_metalOrSpec, m_unused5[3]; };
            /* 6*/ struct { float m_doDiffuse, m_doSpecular, m_doDiffuseIbl, m_doSpecularIbl; };
            /* 7*/ struct { float m_cameraPos[3], m_unused7[1]; };
            /* 8*/ struct { float m_rgbDiff[4]; };
            /* 9*/ struct { float m_rgbSpec[4]; };
            /*10*/ struct { float m_lightDir[3], m_unused10[1]; };
            /*11*/ struct { float m_lightCol[3], m_unused11[1]; };
        };

        float m_params[NumVec4*4];
    }; 

    bgfx::UniformHandle u_params;
};

0 个答案:

没有答案