| 64 | } |
| 65 | |
| 66 | J2DMaterial* J2DMaterialFactory::create(J2DMaterial* material, int idx, u32 flags, J2DResReference* texRef, J2DResReference* fontRef, |
| 67 | JKRArchive* arc) const |
| 68 | { |
| 69 | u32 stages = countStages(idx); |
| 70 | u32 stageTemp = ((flags & 0x1F0000) >> 16); |
| 71 | u32 stageCount = stages > stageTemp ? stages : stageTemp; |
| 72 | u32 texCount = stageCount <= 8 ? stageCount : 8; |
| 73 | |
| 74 | int indRequired = ((flags & 0x1000000) != 0); |
| 75 | int indBlockNum = (flags & 0x1F0000) ? indRequired : 0; |
| 76 | bool doCreateWithHeap = (flags & 0x1F0000); |
| 77 | u16 tevBlockNum = stageCount; |
| 78 | material->mTevBlock = J2DMaterial::createTevBlock(tevBlockNum, doCreateWithHeap); |
| 79 | material->mIndBlock = J2DMaterial::createIndBlock(indBlockNum, doCreateWithHeap); |
| 80 | material->mIndex = idx; |
| 81 | material->mMaterialMode = getMaterialMode(idx); |
| 82 | material->getColorBlock()->setColorChanNum(newColorChanNum(idx)); |
| 83 | material->getColorBlock()->setCullMode(newCullMode(idx)); |
| 84 | material->getTexGenBlock()->setTexGenNum(newTexGenNum(idx)); |
| 85 | material->getPEBlock()->setAlphaComp(newAlphaComp(idx)); |
| 86 | material->getPEBlock()->setBlend(newBlend(idx)); |
| 87 | material->getPEBlock()->setDither(newDither(idx)); |
| 88 | material->getTevBlock()->setTevStageNum(newTevStageNum(idx)); |
| 89 | material->mMaterialAlphaCalc = getMaterialAlphaCalc(idx); |
| 90 | |
| 91 | // set up textures |
| 92 | JUTResReference resRef; |
| 93 | for (u8 i = 0; i < texCount; i++) { |
| 94 | u16 texNo = newTexNo(idx, i); |
| 95 | s8* texPtr = texRef->getResReference(texNo); |
| 96 | void* timg = nullptr; |
| 97 | |
| 98 | if (texPtr) { |
| 99 | // try getting timg from resource reference |
| 100 | timg = resRef.getResource(texPtr, 'TIMG', arc); |
| 101 | |
| 102 | // if nothing there, try from archive |
| 103 | if (!timg && arc) { |
| 104 | timg = resRef.getResource(texPtr, 'TIMG', nullptr); |
| 105 | } |
| 106 | |
| 107 | // if still nothing there, try from screen data manager |
| 108 | if (!timg && J2DScreen::getDataManage()) { |
| 109 | char texName[260]; |
| 110 | strcpy(texName, texRef->getName(texNo)); |
| 111 | timg = J2DScreen::getDataManage()->get(texName); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | material->getTevBlock()->insertTexture(i, (ResTIMG*)timg); |
| 116 | material->getTevBlock()->setTexNo(i, texNo); |
| 117 | } |
| 118 | |
| 119 | // set up font |
| 120 | u16 fontNo = newFontNo(idx); |
| 121 | material->getTevBlock()->setFontNo(fontNo); |
| 122 | |
| 123 | s8* fontPtr = fontRef->getResReference(material->getTevBlock()->getFontNo()); |
no test coverage detected