void MLevel::createFX(MShaderRef * vertexShaderRef, MShaderRef * pixelShaderRef, unsigned int * FXId) { MRenderingContext * render = MEngine::getInstance()->getRenderingContext(); unsigned int i; unsigned int size = m_FXManager.getFXRefsNumber(); for(i=0; i<size; i++) { MFXRef * FXRef = (MFXRef *)m_FXManager.getFXRef(i); if((FXRef->getVertexShaderRef() == vertexShaderRef) && (FXRef->getPixelShaderRef() == pixelShaderRef)) { *FXId = FXRef->getFXId(); return; } } render->createFX(FXId, vertexShaderRef->getShaderId(), pixelShaderRef->getShaderId()); m_FXManager.addFXRef(*FXId, vertexShaderRef, pixelShaderRef); }
void MShaderRef::update(void) { MEngine * engine = MEngine::getInstance(); MLevel * level = engine->getLevel(); MRenderingContext * render = engine->getRenderingContext(); char * text = readTextFile(getFilename()); if(text) { // gen shader if null if(m_shaderId == 0) { switch(m_type) { case M_SHADER_VERTEX: render->createVertexShader(&m_shaderId); break; case M_SHADER_PIXEL: render->createPixelShader(&m_shaderId); break; } } // send shader source render->sendShaderSource(m_shaderId, text); SAFE_FREE(text); MFXManager * FXManager = level->getFXManager(); unsigned int i; unsigned int size = FXManager->getFXRefsNumber(); for(i=0; i<size; i++) { MFXRef * FXRef = FXManager->getFXRef(i); if((FXRef->getPixelShaderRef() == this) || (FXRef->getVertexShaderRef() == this)) { unsigned int FXId = FXRef->getFXId(); render->updateFX(FXId); } } } }