C++ (Qt)void СWindow::Draw( ... ){ for (int i = 0; i < mObjects.size(); ++i) { CObjectParam1 * param1 = dynamic_cast<CObjectParam1 *> (mObjects[i]); if (param1) { DrawObjectsParam1(param1); continue; } // то же для CObjectParam2 CObjectParam2 * param2 = dynamic_cast<CObjectParam2 *> (mObjects[i]); if (param2) { DrawObjectsParam2(param2); continue; } // то же для CObjectParam3 ... и.т.д.
C++ (Qt)void СWindow::Draw( ... ){ for (int i = 0; i < mObjects.size(); ++i) { mObjects[i]->Draw(...);}
C++ (Qt)// базовыйstruct CObjectParam { СOpenGLObject * mObject; // рисуемый объект QMatrix4x4 mMatrix; }; // один из наследников struct CObjectParam1 : public CObjectParam { Color mColor;};
C++ (Qt)struct CObjectParam { СOpenGLObject * mObject; QVariantList params; };
C++ (Qt)struct CObjectParam { COpenGLObject * mObject; QVariantList mParams; }; void CWindow::registerParamProcessor( int type, std::function< bool( CObjectParam* o, const QVariant& v ) > f ){ mParamProcessors[ type ] = f;} void CWindow::Draw( ... ){ for (int i = 0; i < mObjects.size(); ++i) { auto& obj = mObjects[i]; for( auto& v : obj->mParams ) { auto f = mParamProcessors[ v.userType() ]; if( !f( obj, v ) ) break; } }}
C++ (Qt)typedef bool CWindow::(*TDrawObject)( CObjectParam * );struct CObjectParam { СOpenGLObject * mObject; QMatrix4x4 mMatrix; TDrawObject mDrawer;};
C++ (Qt)struct CObjectParam{ СOpenGLObject * mObject; // рисуемый объект QMatrix4x4 mMatrix; virtual void draw( CWindow &surface ) const = 0;}; // один из наследников struct CObjectParam1 : public CObjectParam{ Color mColor; virtual void draw( CWindow &surface ) const { surface.DrawObjectsColor( mColor ); }}; struct CObjectParam2 : public CObjectParam{ Texture mTex; virtual void draw( CWindow &surface ) const { surface.DrawObjectsTexture( mTex ); }};
C++ (Qt)void СWindow::Draw( ... ){ for (int i = 0; i < mObjects.size(); ++i) { mObjects[i]->draw( *this ); }}