| 1671 | } |
| 1672 | |
| 1673 | void GLSLCompiler::translateFunction(glsl::astFunction *function) { |
| 1674 | if (function->isPrototype) |
| 1675 | return; // only generate bytecode for "real deals"? |
| 1676 | |
| 1677 | m_func.push_back(Function()); |
| 1678 | Function& func = m_func[m_func.size()-1]; |
| 1679 | |
| 1680 | func.Arguments.clear(); |
| 1681 | |
| 1682 | std::vector<ag::Type> argTypes; |
| 1683 | std::vector<std::string> argNames; |
| 1684 | for (size_t i = 0; i < function->parameters.size(); i++) { |
| 1685 | glsl::astFunctionParameter* param = function->parameters[i]; |
| 1686 | |
| 1687 | Variable pdata; |
| 1688 | pdata.ID = i; |
| 1689 | pdata.Name = param->name; |
| 1690 | |
| 1691 | if (param->baseType->builtin) |
| 1692 | pdata.Type = kTypes[((glsl::astBuiltin*)param->baseType)->type]; |
| 1693 | else |
| 1694 | pdata.Type = ((glsl::astStruct*)param->baseType)->name; |
| 1695 | |
| 1696 | ag::Type btype = m_convertBaseType(pdata.Type); |
| 1697 | if (btype == ag::Type::Void) |
| 1698 | btype = ag::Type::Object; |
| 1699 | |
| 1700 | switch (param->storage) { |
| 1701 | case glsl::kConst: pdata.Storage = Variable::StorageType::Constant; break; |
| 1702 | case glsl::kIn: pdata.Storage = Variable::StorageType::In; break; |
| 1703 | case glsl::kOut: pdata.Storage = Variable::StorageType::Out; break; |
| 1704 | case glsl::kAttribute: pdata.Storage = Variable::StorageType::Attribute; break; |
| 1705 | case glsl::kUniform: pdata.Storage = Variable::StorageType::Uniform; break; |
| 1706 | case glsl::kVarying: pdata.Storage = Variable::StorageType::Varying; break; |
| 1707 | case glsl::kBuffer: pdata.Storage = Variable::StorageType::Buffer; break; |
| 1708 | case glsl::kShared: pdata.Storage = Variable::StorageType::Shared; break; |
| 1709 | } |
| 1710 | |
| 1711 | argTypes.push_back(btype); |
| 1712 | argNames.push_back(pdata.Type); |
| 1713 | |
| 1714 | // TODO: arrays? |
| 1715 | // param->isArray |
| 1716 | |
| 1717 | func.Arguments.push_back(pdata); |
| 1718 | } |
| 1719 | |
| 1720 | func.ID = m_gen.Function.Create(function->name, function->parameters.size(), argTypes, argNames); |
| 1721 | func.Name = m_currentFunction = function->name; |
| 1722 | |
| 1723 | if (function->returnType->builtin) |
| 1724 | func.ReturnType = kTypes[((glsl::astBuiltin*)function->returnType)->type]; |
| 1725 | else |
| 1726 | func.ReturnType = ((glsl::astStruct*)function->returnType)->name; |
| 1727 | |
| 1728 | m_curFuncData = &func; |
| 1729 | |
| 1730 | m_gen.Function.SetCurrent(func.ID); |