//--------------------------------------------------------------------------- vector<const Function*> Environment::getFunction(const string& identifier) { assert(hasFunction(identifier)); vector<const Function*> result; for(auto& iter : functions) if(iter->getName() == identifier) result.push_back(iter.get()); if(parent!=nullptr) { auto parentResult = parent->getFunction(identifier); result.insert(result.end(), parentResult.begin(), parentResult.end()); } return result; }
PythonScript::PythonScript( MyCanvas * canvas, const std::string & filename ) : m_canvas( canvas ), m_filename( filename ), m_pyModule( 0 ) { // Initialize python context. vgUI::python::Context::getInstance()->setCanvas( canvas ); vgUI::python::Context::getInstance()->setBasicManipulator( canvas ); // Initialize the python interpreter. Py_Initialize(); // Import the script, and if successfull, performs some initializations. if( import() ) { PyRun_SimpleString("import vgUI"); // Calls the initialisation callback, if present. if( hasFunction(m_pyModule, "init") ) { CurWorkDir cwd( m_filename.parent_path() ); PyRun_SimpleString( "script.init(vgUI.Context.getInstance())" ); } // Installs the refresh callback, if a refresh method has been defined.. if( hasFunction(m_pyModule, "refresh") ) { // Installs the callback that will call the script. m_refreshCallback.reset( new vgd::event::TimerCallback() ); m_refreshCallback->setFrequency( 25 ); m_refreshCallback->setExecutionDuration( vgd::basic::TimeDuration() ); m_refreshCallback->setApplyFunctor( vgd::makeShp( new Refresher(this) ) ); m_canvas->getTimerEventProcessor()->add( m_refreshCallback ); } } }
bool Transpiler::translate(const ShaderDesc& shaderDesc, Shader *shader) { auto state = Transpiler {}; if (shaderDesc.type == ShaderType::Vertex) { state.mType = Transpiler::Type::Vertex; } else if (shaderDesc.type == ShaderType::Geometry) { state.mType = Transpiler::Type::Geometry; } else if (shaderDesc.type == ShaderType::Pixel) { state.mType = Transpiler::Type::Pixel; } else { decaf_abort("Unexpected shader type"); } spv::ExecutionModel spvExecModel; if (shaderDesc.type == ShaderType::Vertex) { spvExecModel = spv::ExecutionModel::ExecutionModelVertex; } else if (shaderDesc.type == ShaderType::Geometry) { spvExecModel = spv::ExecutionModel::ExecutionModelGeometry; } else if (shaderDesc.type == ShaderType::Pixel) { spvExecModel = spv::ExecutionModel::ExecutionModelFragment; } else { decaf_abort("Unexpected shader type"); } auto spvGen = ShaderSpvBuilder(spvExecModel); spvGen.setSourceFile("none"); state.mSpv = &spvGen; state.mDesc = &shaderDesc; state.mBinary = shaderDesc.binary; state.mAluInstPreferVector = shaderDesc.aluInstPreferVector; if (shaderDesc.type == ShaderType::Vertex) { auto &vsDesc = *reinterpret_cast<const VertexShaderDesc*>(&shaderDesc); state.mTexInput = vsDesc.texDims; spvGen.setDescriptorSetIdx(0); Transpiler::writeVertexProlog(spvGen, vsDesc); } else if (shaderDesc.type == ShaderType::Geometry) { auto &gsDesc = *reinterpret_cast<const GeometryShaderDesc*>(&shaderDesc); state.mTexInput = gsDesc.texDims; spvGen.setDescriptorSetIdx(1); Transpiler::writeGeometryProlog(spvGen, gsDesc); } else if (shaderDesc.type == ShaderType::Pixel) { auto &psDesc = *reinterpret_cast<const PixelShaderDesc*>(&shaderDesc); state.mTexInput = psDesc.texDims; spvGen.setDescriptorSetIdx(2); Transpiler::writePixelProlog(spvGen, psDesc); } state.translate(); spvGen.makeReturn(true); if (shaderDesc.type != ShaderType::Vertex) { if (spvGen.hasFunction("fs_main")) { decaf_abort("Non-vertex-shader called into a FS function, wat?"); } } if (shaderDesc.type == ShaderType::Vertex) { auto& vsDesc = *reinterpret_cast<const VertexShaderDesc*>(&shaderDesc); auto vsShader = reinterpret_cast<VertexShader*>(shader); if (spvGen.hasFunction("fs_main")) { auto fsFunc = spvGen.getFunction("fs_main"); spvGen.setBuildPoint(fsFunc->getEntryBlock()); auto fsState = Transpiler {}; fsState.mSpv = &spvGen; fsState.mDesc = &shaderDesc; fsState.mType = ShaderParser::Type::Fetch; fsState.mBinary = vsDesc.fsBinary; fsState.mAluInstPreferVector = vsDesc.aluInstPreferVector; fsState.translate(); spvGen.makeReturn(true); // Copy the FS attribute buffer stuff over. We check to make sure that // the vertex shader didn't also try to read stuff (this would be an error). decaf_check(state.mVsInputAttribs.size() == 0); state.mVsInputBuffers = fsState.mVsInputBuffers; state.mVsInputAttribs = fsState.mVsInputAttribs; } // For each exported parameter, we need to exports the semantics for // later matching up by the pixel shaders int numExports = spvGen.getNumParamExports(); for (auto i = 0; i < numExports; ++i) { uint32_t semanticId; // TODO: This should probably be moved into the actual export generation // code instead of being calculated later and assuming the order of the // exports matches up with the code... if ((i & 3) == 0) { semanticId = vsDesc.regs.spi_vs_out_ids[i >> 2].SEMANTIC_0(); } else if ((i & 3) == 1) {