GLuint GLProgramBase::InitializeProgram(std::vector<shaderName> & shaderNames) { for( int i=0; i<shaderNames.size(); i++ ) std::cout << shaderNames[i].second << std::endl; std::vector<GLuint> shaderList; std::vector<shaderName>::iterator it; for( it = shaderNames.begin(); it != shaderNames.end(); it++) { std::string strShader(getFile(it->second.c_str())); shaderList.push_back(CreateShader(it->first,strShader)); } theProgram = CreateProgram(shaderList); std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader); return theProgram; }
bool Skins_Validate( ModelContainer_t *pContainer, int iSkinNumber ) { bool bReturn = true; bool bPREV_bReportImageLoadErrors = g_bReportImageLoadErrors; g_bReportImageLoadErrors = false; bool bCheckMissingMaterials = true;//GetYesNo("Check for materials referenced by model but missing in skinfile(s)?\n\n( Note: This can give false alarms for skins which don't use (eg) \"scarf\" )"); // first, build up a list of all model materials... // StringSet_t MaterialsPresentInModel; for (int iSurface = 0; iSurface < pContainer->iNumSurfaces; iSurface++) { bool bOnOff = GLMModel_SurfaceIsON(pContainer->hModel, iSurface); if (bOnOff) { LPCSTR psMaterial = GLMModel_GetSurfaceShaderName( pContainer->hModel, iSurface); MaterialsPresentInModel.insert(MaterialsPresentInModel.end(),psMaterial); } } // build up a list of shaders used... // StringSet_t UniqueSkinShaders; SkinFileMaterialsMissing_t SkinFileMaterialsMissing; int iThisSkinIndex = 0; for (SkinSets_t::iterator itSkins = pContainer->SkinSets.begin(); itSkins != pContainer->SkinSets.end(); ++itSkins, iThisSkinIndex++) { if (iSkinNumber == iThisSkinIndex || iSkinNumber == -1) { SkinSet_Validate_BuildList(UniqueSkinShaders, itSkins, MaterialsPresentInModel, SkinFileMaterialsMissing); } } // now process the unique list we've just built... // CWaitCursor wait; string strFoundList; string strNotFoundList; int iUniqueIndex = 0; for (StringSet_t::iterator it = UniqueSkinShaders.begin(); it != UniqueSkinShaders.end(); ++it, iUniqueIndex++) { string strShader(*it); StatusMessage(va("Processing shader %d/%d: \"%s\"\n",iUniqueIndex,UniqueSkinShaders.size(),strShader.c_str())); OutputDebugString(va("Unique: \"%s\"... ",strShader.c_str())); int iTextureHandle = Texture_Load(strShader.c_str(), true); // bInhibitStatus GLuint uiGLBind = Texture_GetGLBind( iTextureHandle ); if (uiGLBind == 0) { OutputDebugString("NOT FOUND\n"); strNotFoundList += strShader; strNotFoundList += "\n"; } else { OutputDebugString("found\n"); strFoundList += strShader; strFoundList += "\n"; } } StatusMessage(NULL); // see if we were missing any model materials in these skins... // CString strModelMaterialsMissing; if (SkinFileMaterialsMissing.size()) { for (SkinFileMaterialsMissing_t::iterator itSkinFileMaterialsMissing = SkinFileMaterialsMissing.begin(); itSkinFileMaterialsMissing != SkinFileMaterialsMissing.end(); ++itSkinFileMaterialsMissing) { string strSkinFileName((*itSkinFileMaterialsMissing).first); if (iSkinNumber == -1) { strModelMaterialsMissing += va("\nSkin \"%s\":\n",strSkinFileName.c_str()); } for (EthnicMaterials_t::iterator itSkinFile = (*itSkinFileMaterialsMissing).second.begin(); itSkinFile != (*itSkinFileMaterialsMissing).second.end(); ++itSkinFile) { string strEthnicFileName((*itSkinFile).first); strModelMaterialsMissing += va("Ethnic \"%s\": ",strEthnicFileName.c_str()); StringVector_t& MaterialStrings = (*itSkinFile).second; for (int iMaterial = 0; iMaterial != MaterialStrings.size(); ++iMaterial) { string strMaterial(MaterialStrings[iMaterial]); strModelMaterialsMissing += va("%s\"%s\"",(iMaterial==0)?"":", ",strMaterial.c_str()); } strModelMaterialsMissing += "\n"; } } } if (!strModelMaterialsMissing.IsEmpty()) { if (iSkinNumber == -1) { strModelMaterialsMissing.Insert(0, "One or more skin files are missing some material definitions referenced by this model's currently-active surfaces.\nList follows...\n\n"); } else { strModelMaterialsMissing.Insert(0, "This skin file is missing one or more material definitions referenced by this model's currently-active surfaces.\nList follows...\n\n"); } } if (!strModelMaterialsMissing.IsEmpty()) { if (bCheckMissingMaterials) { WarningBox(va("Summary Part 1: Missing materials\n\n%s",(LPCSTR)strModelMaterialsMissing)); } } // Now output results... // If too many lines to fit on screen (which is now happening), send 'em to notepad instead... // // ( tacky way of counting lines...) CString strTackyCount(strNotFoundList.c_str()); strTackyCount += strFoundList.c_str(); int iLines = strTackyCount.Replace('\n','?'); // :-) #define MAX_BOX_LINES_HERE 50 if (strNotFoundList.empty()) { if (iLines > MAX_BOX_LINES_HERE) { if (GetYesNo(va("All shaders found... :-)\n\nList has > %d entries, send to Notepad?",MAX_BOX_LINES_HERE))) { SendStringToNotepad(va("All shaders found... :-)\n\nList follows:\n\n%s",strFoundList.c_str()),"found_shaders.txt"); } } else { InfoBox(va("All shaders found... :-)\n\nList follows:\n\n%s",strFoundList.c_str())); } } else { if (iLines > MAX_BOX_LINES_HERE) { if (GetYesNo(va("Some missing shader, some found, but list is > %d entries, send to Notepad?",MAX_BOX_LINES_HERE))) { SendStringToNotepad(va("Missing shaders:\n\n%s\n\nFound shaders:\n\n%s",strNotFoundList.c_str(),strFoundList.c_str()),"found_shaders.txt"); } } else { WarningBox(va("Missing shaders:\n\n%s\n\nFound shaders:\n\n%s",strNotFoundList.c_str(),strFoundList.c_str())); } bReturn = false; } g_bReportImageLoadErrors = bPREV_bReportImageLoadErrors; return bReturn; }
static LPCSTR Skins_Parse(string strThisSkinFileName, CGPGroup *pFileGroup, CGPGroup *pParseGroup_Prefs) { LPCSTR psError = NULL; // read any optional surface on/off blocks... // for (int iSurfaceOnOffType = 0; iSurfaceOnOffType<3; iSurfaceOnOffType++) { CGPGroup *pSurfaceParseGroup = NULL; switch (iSurfaceOnOffType) { case 0: pSurfaceParseGroup = pParseGroup_Prefs->FindSubGroup(sSKINKEYWORD_SURFACES_ON); break; case 1: pSurfaceParseGroup = pParseGroup_Prefs->FindSubGroup(sSKINKEYWORD_SURFACES_OFF); break; case 2: pSurfaceParseGroup = pParseGroup_Prefs->FindSubGroup(sSKINKEYWORD_SURFACES_OFFNOCHILDREN); break; default: assert(0); break; } if (pSurfaceParseGroup) { CGPValue *pValue = pSurfaceParseGroup->GetPairs(); while (pValue) { // string str1 = (*it).first; // junk, eg "name1" string str2 = pValue->GetTopValue(); switch (iSurfaceOnOffType) { case 0: CurrentSkinsSurfacePrefs[strThisSkinFileName].vSurfacesOn.push_back(str2); break; case 1: CurrentSkinsSurfacePrefs[strThisSkinFileName].vSurfacesOff.push_back(str2); break; case 2: CurrentSkinsSurfacePrefs[strThisSkinFileName].vSurfacesOffNoChildren.push_back(str2); break; default: assert(0); break; } pValue = pValue->GetNext(); } } } // find all the materials and add them to the skin set... // int iMaterialDeclarationIndex = 0; for (CGPGroup *pMaterialGroup = pFileGroup->GetSubGroups(); pMaterialGroup; pMaterialGroup = pMaterialGroup->GetNext(), iMaterialDeclarationIndex++) { string strKeyWord = pMaterialGroup->GetName(); if (strKeyWord == sSKINKEYWORD_MATERIAL) { string strMaterialName(pMaterialGroup->FindPairValue(sSKINKEYWORD_NAME,"")); if (strMaterialName == "") { psError = va("%s[%d] had no \"%s\" field!\n",sSKINKEYWORD_MATERIAL, iMaterialDeclarationIndex, sSKINKEYWORD_NAME); return psError; } // now iterate through the ethnic group variants of this material... // int iEthnicGroupIndex = 0; for (CGPGroup *pEthnicGroup = pMaterialGroup->GetSubGroups(); pEthnicGroup; pEthnicGroup = pEthnicGroup->GetNext(), iEthnicGroupIndex++) { strKeyWord = pEthnicGroup->GetName(); if (strKeyWord == sSKINKEYWORD_GROUP) { string strEthnicGroupName(pEthnicGroup->FindPairValue(sSKINKEYWORD_NAME,"")); if (strEthnicGroupName == "") { psError = va("%s[%d] %s[%d] had no \"%s\" field!\n",sSKINKEYWORD_MATERIAL, iMaterialDeclarationIndex, sSKINKEYWORD_GROUP, iEthnicGroupIndex, sSKINKEYWORD_NAME); return psError; } // now iterate through the shader variants for this ethnic version of this material... (is anyone reading this...?) // int iAlternateShaderIndex = 0; for (CGPValue *pValue = pEthnicGroup->GetPairs(); pValue; pValue = pValue->GetNext()) { string strField(pValue->GetName()); if (strField != sSKINKEYWORD_NAME) { // ... then it should be a shader... // string strShader(pValue->GetTopValue()); CurrentSkins[strThisSkinFileName][strEthnicGroupName][strMaterialName].push_back(strShader); } } } } } } return psError; }
void HSWDisplay::LoadGraphics() { // We assume here that the current GL context is the one our resources will be associated with. if(GLVersionInfo.MajorVersion == 0) GetGLVersionAndExtensions(GLVersionInfo); if (FrameBuffer == 0) { glGenFramebuffers(1, &FrameBuffer); } if (!pTexture) // To do: Add support for .dds files, which would be significantly smaller than the size of the tga. { size_t textureSize; const uint8_t* TextureData = GetDefaultTexture(textureSize); pTexture = *LoadTextureTga(RenderParams, Sample_Linear | Sample_Clamp, TextureData, (int)textureSize, 255); } if (!pShaderSet) { pShaderSet = *new ShaderSet(); } if(!pVertexShader) { OVR::String strShader((GLVersionInfo.MajorVersion >= 3) ? glsl3Prefix : glsl2Prefix); strShader += SimpleTexturedQuad_vs; pVertexShader = *new VertexShader(&RenderParams, const_cast<char*>(strShader.ToCStr()), strShader.GetLength(), SimpleTexturedQuad_vs_refl, OVR_ARRAY_COUNT(SimpleTexturedQuad_vs_refl)); pShaderSet->SetShader(pVertexShader); } if(!pFragmentShader) { OVR::String strShader((GLVersionInfo.MajorVersion >= 3) ? glsl3Prefix : glsl2Prefix); strShader += SimpleTexturedQuad_ps; pFragmentShader = *new FragmentShader(&RenderParams, const_cast<char*>(strShader.ToCStr()), strShader.GetLength(), SimpleTexturedQuad_ps_refl, OVR_ARRAY_COUNT(SimpleTexturedQuad_ps_refl)); pShaderSet->SetShader(pFragmentShader); } if(!pVB) { pVB = *new Buffer(&RenderParams); pVB->Data(Buffer_Vertex, NULL, 4 * sizeof(HASWVertex)); HASWVertex* pVertices = (HASWVertex*)pVB->Map(0, 4 * sizeof(HASWVertex), Map_Discard); OVR_ASSERT(pVertices); if(pVertices) { const bool flip = ((RenderState.DistortionCaps & ovrDistortionCap_FlipInput) != 0); const float left = -1.0f; // We currently draw this in normalized device coordinates with an stereo translation const float top = -1.1f; // applied as a vertex shader uniform. In the future when we have a more formal graphics const float right = 1.0f; // API abstraction we may move this draw to an overlay layer or to a more formal const float bottom = 0.9f; // model/mesh scheme with a perspective projection. pVertices[0] = HASWVertex(left, top, 0.f, Color(255, 255, 255, 255), 0.f, flip ? 1.f : 0.f); pVertices[1] = HASWVertex(left, bottom, 0.f, Color(255, 255, 255, 255), 0.f, flip ? 0.f : 1.f); pVertices[2] = HASWVertex(right, top, 0.f, Color(255, 255, 255, 255), 1.f, flip ? 1.f : 0.f); pVertices[3] = HASWVertex(right, bottom, 0.f, Color(255, 255, 255, 255), 1.f, flip ? 0.f : 1.f); pVB->Unmap(pVertices); } } // We don't generate the vertex arrays here if (!VAO && GLVersionInfo.SupportsVAO) { OVR_ASSERT(!VAOInitialized); #ifdef OVR_OS_MAC if(GLVersionInfo.WholeVersion >= 302) glGenVertexArrays(1, &VAO); else glGenVertexArraysAPPLE(1, &VAO); #else glGenVertexArrays(1, &VAO); #endif } }