qtexture_t *WINAPI QERApp_Try_Texture_ForName( const char *name ){ qtexture_t *q; // char f1[1024], f2[1024]; unsigned char *pPixels = NULL; int nWidth, nHeight; // convert the texture name to the standard format we use in qtexture_t const char *stdName = QERApp_CleanTextureName( name ); // use the hash table q = (qtexture_t*)g_hash_table_lookup( g_ShadersTable.m_pfnQTexmap(), stdName ); if ( q ) { return q; } #ifdef QTEXMAP_DEBUG for ( q = g_qeglobals.d_qtextures; q; q = q->next ) { if ( !strcmp( stdName, q->name ) ) { Sys_Printf( "ERROR: %s is not in texture map, but was found in texture list\n" ); return q; } } #endif g_FuncTable.m_pfnLoadImage( name, &pPixels, &nWidth, &nHeight ); if ( !pPixels ) { return NULL; // we failed } else{ Sys_Printf( "LOADED: %s\n", name ); } // instanciate a new qtexture_t // NOTE: when called by a plugin we must make sure we have set Radiant's GL context before binding the texture // we'll be binding the GL texture now // need to check we are using a right GL context // with GL plugins that have their own window, the GL context may be the plugin's, in which case loading textures will bug // g_QglTable.m_pfn_glwidget_make_current (g_QglTable.m_pfn_GetQeglobalsGLWidget ()); q = g_FuncTable.m_pfnLoadTextureRGBA( pPixels, nWidth, nHeight ); if ( !q ) { return NULL; } g_free( pPixels ); strcpy( q->name, name ); // only strip extension if extension there is! if ( q->name[strlen( q->name ) - 4] == '.' ) { q->name[strlen( q->name ) - 4] = '\0'; } // hook into the main qtexture_t list qtexture_t **d_qtextures = g_ShadersTable.m_pfnQTextures(); q->next = *d_qtextures; *d_qtextures = q; // push it in the map g_hash_table_insert( g_ShadersTable.m_pfnQTexmap(), q->name, q ); return q; }
CShader *CShaderArray::Shader_ForTextureName (const char *name) const { #ifdef _DEBUG // check we were given a texture name that fits the qtexture_t naming conventions if (strcmp (name, QERApp_CleanTextureName (name)) != 0) Sys_Printf ("WARNING: texture name %s doesn't fit qtexture_t conventions in CShaderArray::Shader_ForTextureName\n", name); #endif int i; for (i = 0; i < CPtrArray::GetSize (); i++) { CShader *pShader = static_cast < CShader * >(CPtrArray::GetAt (i)); if (strcmp (name, QERApp_CleanTextureName (pShader->getTextureName ())) == 0) return pShader; } return NULL; }
bool CShader::Parse () { char *token = g_ScripLibTable.m_pfnToken (); // the parsing needs to be taken out in another module // Sys_Printf("TODO: CShader::Parse\n"); // token is shader name (full path with a "textures\") // we remove the "textures\" part //setName ((char *) &token[9])); // no we don't setName (token); // name of the qtexture_t we'll use to represent this shader (this one has the "textures\" before) const char *stdName = QERApp_CleanTextureName (token); m_strTextureName = stdName; // FIXME: BC reports stdName is uninitialised? g_ScripLibTable.m_pfnGetToken (true); if (strcmp (token, "{")) return false; else { // we need to read until we hit a balanced } int nMatch = 1; while (nMatch > 0 && g_ScripLibTable.m_pfnGetToken (true)) { if (strcmp (token, "{") == 0) { nMatch++; continue; } else if (strcmp (token, "}") == 0) { nMatch--; continue; } if (nMatch > 1) continue; // ignore layers for now if (strcmpi (token, "qer_nocarve") == 0) { m_nFlags |= QER_NOCARVE; } else if (strcmpi (token, "qer_trans") == 0) { if (g_ScripLibTable.m_pfnGetToken (true)) { m_fTrans = (float) atof (token); } m_nFlags |= QER_TRANS; } else if (strcmpi (token, "qer_editorimage") == 0) { if (g_ScripLibTable.m_pfnGetToken (true)) { // bAddTexture changed to false to allow editorimages in other locations than "textures/" m_strTextureName = QERApp_CleanTextureName (token, false); } } else if (strcmpi (token, "qer_alphafunc") == 0) { if (g_ScripLibTable.m_pfnGetToken (true)) { if(stricmp( token, "greater" ) == 0 ) { m_nAlphaFunc = GL_GREATER; } else if(stricmp( token, "less" ) == 0 ) { m_nAlphaFunc = GL_LESS; } else if(stricmp( token, "gequal" ) == 0 ) { m_nAlphaFunc = GL_GEQUAL; } if( m_nAlphaFunc ) m_nFlags |= QER_ALPHAFUNC; } if (g_ScripLibTable.m_pfnGetToken (true)) { m_fAlphaRef = (float) atof (token); } } else if (strcmpi (token, "cull") == 0) { if (g_ScripLibTable.m_pfnGetToken (true)) { if( stricmp( token, "none" ) == 0 || stricmp( token, "twosided" ) == 0 || stricmp( token, "disable" ) == 0 ) { m_nCull = 2; } else if( stricmp( token, "back" ) == 0 || stricmp( token, "backside" ) == 0 || stricmp( token, "backsided" ) == 0 ) { m_nCull = 1; } if( m_nCull ) m_nFlags |= QER_CULL; } } else if (strcmpi (token, "surfaceparm") == 0) { if (g_ScripLibTable.m_pfnGetToken (true)) { if (strcmpi (token, "fog") == 0) { m_nFlags |= QER_FOG; if (m_fTrans == 1.0f) // has not been explicitly set by qer_trans { m_fTrans = 0.35f; } } else if (strcmpi (token, "nodraw") == 0) { m_nFlags |= QER_NODRAW; } else if (strcmpi (token, "nonsolid") == 0) { m_nFlags |= QER_NONSOLID; } else if (strcmpi (token, "water") == 0) { m_nFlags |= QER_WATER; } else if (strcmpi (token, "lava") == 0) { m_nFlags |= QER_LAVA; } } } } if (nMatch != 0) return false; } return true; }
void CShader::CreateDefault (const char *name) { const char *stdName = QERApp_CleanTextureName (name); m_strTextureName = stdName; setName (name); }